Skip to content

feat: Add workspace proxy enterprise cli commands #7123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add primary access url
  • Loading branch information
Emyrk committed Apr 17, 2023
commit 9fc8078e5ddc6952ff36c7f33c4eb78efc9a208e
21 changes: 18 additions & 3 deletions enterprise/cli/workspaceproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"net"
"net/http"
"net/http/pprof"
"net/url"
"os/signal"
"regexp"
rpprof "runtime/pprof"
Expand Down Expand Up @@ -107,6 +106,7 @@ func (r *RootCmd) proxyServer() *clibase.Cmd {
YAML: "externalWorkspaceProxy",
}
proxySessionToken clibase.String
primaryAccessURL clibase.URL
)
opts.Add(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't these be added to the regular config struct, and then the primary server can filter them out?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We talked on discord. I think the best move here is to autogenerate the Deployment struct from the Options. Then we can create all the options in 1 place, and filter them.

I will do this in another branch, this is ok for now here just to get a cmd working.

Follow up PRs will make the workspace proxy creation/register experience better.

// Options only for external workspace proxies
Expand All @@ -122,6 +122,18 @@ func (r *RootCmd) proxyServer() *clibase.Cmd {
Group: &externalProxyOptionGroup,
Hidden: false,
},

clibase.Option{
Name: "Coderd (Primary) Access URL",
Description: "URL to communicate with coderd. This should match the access URL of the Coder deployment.",
Flag: "primary-access-url",
Env: "CODER_PRIMARY_ACCESS_URL",
YAML: "primaryAccessURL",
Default: "",
Value: &primaryAccessURL,
Group: &externalProxyOptionGroup,
Hidden: false,
},
)

client := new(codersdk.Client)
Expand All @@ -137,6 +149,10 @@ func (r *RootCmd) proxyServer() *clibase.Cmd {
r.InitClient(client),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this just be a proxysdk client that we construct in the handler?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was honestly just using this for the version checking.

),
Handler: func(inv *clibase.Invocation) error {
if !(primaryAccessURL.Scheme == "http" || primaryAccessURL.Scheme == "https") {
return xerrors.Errorf("primary access URL must be http or https: url=%s", primaryAccessURL)
}

var closers closers
// Main command context for managing cancellation of running
// services.
Expand Down Expand Up @@ -255,11 +271,10 @@ func (r *RootCmd) proxyServer() *clibase.Cmd {
closers.Add(closeFunc)
}

pu, _ := url.Parse("http://localhost:3000")
proxy, err := wsproxy.New(&wsproxy.Options{
Logger: logger,
// TODO: PrimaryAccessURL
PrimaryAccessURL: pu,
PrimaryAccessURL: primaryAccessURL.Value(),
AccessURL: cfg.AccessURL.Value(),
AppHostname: appHostname,
AppHostnameRegex: appHostnameRegex,
Expand Down