Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Validate wsp and cemanager schemes match #294

Merged
merged 1 commit into from
Mar 17, 2021
Merged
Changes from all commits
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
32 changes: 23 additions & 9 deletions internal/cmd/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ coder providers create my-provider --hostname=https://provider.example.com --clu
return err
}

version, err := client.APIVersion(ctx)
if err != nil {
return xerrors.Errorf("get application version: %w", err)
}

cemanagerURL := client.BaseURL()
ingressHost, err := url.Parse(hostname)
if err != nil {
return xerrors.Errorf("parse hostname: %w", err)
}

if cemanagerURL.Scheme != ingressHost.Scheme {
return xerrors.Errorf("Coder access url and hostname must have matching protocols: coder access url: %s, workspace provider hostname: %s", cemanagerURL.String(), ingressHost.String())
}
Comment on lines +66 to +67
Copy link
Contributor

Choose a reason for hiding this comment

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

this is a good candidate for a clog.Error with more multi-line detail


// ExactArgs(1) ensures our name value can't panic on an out of bounds.
createReq := &coder.CreateWorkspaceProviderReq{
Name: args[0],
Expand All @@ -64,15 +79,12 @@ coder providers create my-provider --hostname=https://provider.example.com --clu
return xerrors.Errorf("create workspace provider: %w", err)
}

cemanagerURL := client.BaseURL()
ingressHost, err := url.Parse(hostname)
if err != nil {
return xerrors.Errorf("parse hostname: %w", err)
}

version, err := client.APIVersion(ctx)
if err != nil {
return xerrors.Errorf("get application version: %w", err)
var sslNote string
if ingressHost.Scheme == "https" {
sslNote = `
NOTE: Since the hostname provided is using https you must ensure the deployment
has a valid SSL certificate. See https://coder.com/docs/guides/ssl-certificates
for more information.`
}

clog.LogSuccess(fmt.Sprintf(`
Expand All @@ -93,9 +105,11 @@ helm upgrade coder-workspace-provider coder/workspace-provider \
--install \
--force \
--set envproxy.token=`+wp.EnvproxyToken+` \
--set envproxy.accessURL=`+ingressHost.String()+` \
--set ingress.host=`+ingressHost.Hostname()+` \
--set envproxy.clusterAddress=`+clusterAddress+` \
--set cemanager.accessURL=`+cemanagerURL.String()+`
`+sslNote+`

WARNING: The 'envproxy.token' is a secret value that authenticates the workspace provider,
make sure not to share this token or make it public.
Expand Down