From 6b28887857dabb10ecb56028da657bb422228aa7 Mon Sep 17 00:00:00 2001 From: Charlie Moog Date: Wed, 4 Nov 2020 18:11:38 -0600 Subject: [PATCH 1/6] Cleanup --- ci/steps/build.sh | 15 +++++++++++---- ci/steps/fmt.sh | 3 ++- ci/steps/gendocs.sh | 6 ++---- ci/steps/integration.sh | 8 ++------ ci/steps/lint.sh | 5 +---- ci/steps/unit_test.sh | 3 +-- coder-sdk/client.go | 18 ++++++++---------- coder-sdk/error.go | 14 +++++++------- internal/cmd/configssh.go | 4 ++-- internal/cmd/envs.go | 2 +- 10 files changed, 37 insertions(+), 41 deletions(-) diff --git a/ci/steps/build.sh b/ci/steps/build.sh index 8d7f5315..0017f2b5 100755 --- a/ci/steps/build.sh +++ b/ci/steps/build.sh @@ -5,12 +5,13 @@ pushd() { builtin pushd "$@" >/dev/null; } popd() { builtin popd >/dev/null; } set -euo pipefail -cd "$(dirname "$0")" + +cd "$(git rev-parse --show-toplevel)/ci/steps" tag=$(git describe --tags) build() { - echo "Building coder-cli for $GOOS-$GOARCH..." + echo "--- building coder-cli for $GOOS-$GOARCH" tmpdir=$(mktemp -d) go build -ldflags "-X cdr.dev/coder-cli/internal/version.Version=${tag}" -o "$tmpdir/coder" ../../cmd/coder @@ -29,9 +30,15 @@ build() { tar -czf "$artifact" coder ;; "darwin") + if [[ ${CI-} ]]; then artifact="coder-cli-$GOOS-$GOARCH.zip" gon -log-level debug ./gon.json mv coder.zip $artifact + else + artifact="coder-cli-$GOOS-$GOARCH.tar.gz" + tar -czf "$artifact" coder + echo "--- warning: not in ci, skipping signed release of darwin" + fi ;; esac popd @@ -46,8 +53,8 @@ build() { if [[ "$(uname)" == "Darwin" ]]; then CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 build else - echo "Warning: Darwin builds don't work on Linux." - echo "Please use an OSX machine to build Darwin tars." + echo "--- warning: Darwin builds don't work on Linux." + echo "--- please use an OSX machine to build Darwin tars." fi CGO_ENABLED=0 GOOS=linux GOARCH=amd64 build diff --git a/ci/steps/fmt.sh b/ci/steps/fmt.sh index c202dab9..6c3f7a88 100755 --- a/ci/steps/fmt.sh +++ b/ci/steps/fmt.sh @@ -2,8 +2,9 @@ set -euo pipefail -echo "Formatting..." +cd "$(git rev-parse --show-toplevel)" +echo "--- formatting" go mod tidy gofmt -w -s . goimports -w "-local=$$(go list -m)" . diff --git a/ci/steps/gendocs.sh b/ci/steps/gendocs.sh index cc397e4f..d4cb8413 100755 --- a/ci/steps/gendocs.sh +++ b/ci/steps/gendocs.sh @@ -2,11 +2,9 @@ set -euo pipefail -echo "Generating docs..." - -cd "$(dirname "$0")" -cd ../../ +cd "$(git rev-parse --show-toplevel)" +echo "--- regenerating documentation" rm -rf ./docs mkdir ./docs go run ./cmd/coder gen-docs ./docs diff --git a/ci/steps/integration.sh b/ci/steps/integration.sh index 1ef04178..6f82475c 100755 --- a/ci/steps/integration.sh +++ b/ci/steps/integration.sh @@ -2,14 +2,10 @@ set -eo pipefail -log() { - echo "--- $@" -} - cd "$(git rev-parse --show-toplevel)" -log "building integration test image" +echo "--- building integration test image" docker build -f ./ci/integration/Dockerfile -t coder-cli-integration:latest . -log "starting integration tests" +echo "--- starting integration tests" go test ./ci/integration -count=1 diff --git a/ci/steps/lint.sh b/ci/steps/lint.sh index dcb2acaa..5a766fb5 100755 --- a/ci/steps/lint.sh +++ b/ci/steps/lint.sh @@ -2,10 +2,7 @@ set -euo pipefail -echo "Linting..." - -cd "$(dirname "$0")" -cd ../../ +cd "$(git rev-parse --show-toplevel)" echo "--- golangci-lint" golangci-lint run -c .golangci.yml diff --git a/ci/steps/unit_test.sh b/ci/steps/unit_test.sh index 68bd23a2..1692a10a 100755 --- a/ci/steps/unit_test.sh +++ b/ci/steps/unit_test.sh @@ -4,6 +4,5 @@ set -euo pipefail cd "$(git rev-parse --show-toplevel)" -echo "--- go test..." - +echo "--- running unit tests" go test $(go list ./... | grep -v pkg/tcli | grep -v ci/integration | grep -v coder-sdk) diff --git a/coder-sdk/client.go b/coder-sdk/client.go index 8076c517..d5b4691c 100644 --- a/coder-sdk/client.go +++ b/coder-sdk/client.go @@ -31,16 +31,14 @@ func (c *Client) newHTTPClient() (*http.Client, error) { return nil, err } - jar.SetCookies(c.BaseURL, []*http.Cookie{ - { - Name: "session_token", - Value: c.Token, - MaxAge: 86400, - Path: "/", - HttpOnly: true, - Secure: c.BaseURL.Scheme == "https", - }, - }) + jar.SetCookies(c.BaseURL, []*http.Cookie{{ + Name: "session_token", + Value: c.Token, + MaxAge: 86400, + Path: "/", + HttpOnly: true, + Secure: c.BaseURL.Scheme == "https", + }}) return &http.Client{Jar: jar}, nil } diff --git a/coder-sdk/error.go b/coder-sdk/error.go index bdbef50f..d0dbf447 100644 --- a/coder-sdk/error.go +++ b/coder-sdk/error.go @@ -17,13 +17,13 @@ var ErrPermissions = xerrors.New("insufficient permissions") // ErrAuthentication describes the error case in which the requester has invalid authentication. var ErrAuthentication = xerrors.New("invalid authentication") -// APIError is the expected payload format for our errors. -type APIError struct { - Err APIErrorMsg `json:"error"` +// apiError is the expected payload format for our errors. +type apiError struct { + Err apiErrorMsg `json:"error"` } -// APIErrorMsg contains the rich error information returned by API errors. -type APIErrorMsg struct { +// apiErrorMsg contains the rich error information returned by API errors. +type apiErrorMsg struct { Msg string `json:"msg"` } @@ -33,9 +33,9 @@ type HTTPError struct { } func (e *HTTPError) Error() string { - var msg APIError + var msg apiError // Try to decode the payload as an error, if it fails or if there is no error message, - // return the response URL with the dump. + // return the response URL with the status. if err := json.NewDecoder(e.Response.Body).Decode(&msg); err != nil || msg.Err.Msg == "" { return fmt.Sprintf("%s: %d %s", e.Request.URL, e.StatusCode, e.Status) } diff --git a/internal/cmd/configssh.go b/internal/cmd/configssh.go index dae47fde..50f6c3bd 100644 --- a/internal/cmd/configssh.go +++ b/internal/cmd/configssh.go @@ -37,7 +37,7 @@ func configSSHCmd() *cobra.Command { } func configSSH(configpath *string, remove *bool) func(cmd *cobra.Command, _ []string) error { - startToken := "# ------------START-CODER-ENTERPRISE-----------" + const startToken = "# ------------START-CODER-ENTERPRISE-----------" startMessage := `# The following has been auto-generated by "coder config-ssh" # to make accessing your Coder Enterprise environments easier. # @@ -46,7 +46,7 @@ func configSSH(configpath *string, remove *bool) func(cmd *cobra.Command, _ []st # coder config-ssh --remove # # You should not hand-edit this section, unless you are deleting it.` - endToken := "# ------------END-CODER-ENTERPRISE------------" + const endToken = "# ------------END-CODER-ENTERPRISE------------" return func(cmd *cobra.Command, _ []string) error { ctx := cmd.Context() diff --git a/internal/cmd/envs.go b/internal/cmd/envs.go index a35fa6ed..e12e9d35 100644 --- a/internal/cmd/envs.go +++ b/internal/cmd/envs.go @@ -230,7 +230,7 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub return nil }, } - cmd.Flags().StringVarP(&org, "org", "o", "", "ID of the organization the environment should be created under.") + cmd.Flags().StringVarP(&org, "org", "o", "", "name of the organization the environment should be created under.") cmd.Flags().StringVarP(&tag, "tag", "t", defaultImgTag, "tag of the image the environment will be based off of.") cmd.Flags().Float32VarP(&cpu, "cpu", "c", 0, "number of cpu cores the environment should be provisioned with.") cmd.Flags().Float32VarP(&memory, "memory", "m", 0, "GB of RAM an environment should be provisioned with.") From 1de8561ac81161ffae9b02a6dc872e49770e7052 Mon Sep 17 00:00:00 2001 From: Charlie Moog Date: Wed, 4 Nov 2020 18:16:01 -0600 Subject: [PATCH 2/6] fixup! Cleanup --- docs/coder_envs_create.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/coder_envs_create.md b/docs/coder_envs_create.md index 67c2cb8c..96b6048b 100644 --- a/docs/coder_envs_create.md +++ b/docs/coder_envs_create.md @@ -28,7 +28,7 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub -h, --help help for create -i, --image string name of the image to base the environment off of. -m, --memory float32 GB of RAM an environment should be provisioned with. - -o, --org string ID of the organization the environment should be created under. + -o, --org string name of the organization the environment should be created under. -t, --tag string tag of the image the environment will be based off of. (default "latest") ``` From 9389adbbdb351ebca12094a2c5eb925407c0d145 Mon Sep 17 00:00:00 2001 From: Charlie Moog Date: Wed, 4 Nov 2020 19:56:10 -0600 Subject: [PATCH 3/6] fixup! Cleanup --- coder-sdk/client.go | 2 +- coder-sdk/secrets.go | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/coder-sdk/client.go b/coder-sdk/client.go index d5b4691c..8f512e05 100644 --- a/coder-sdk/client.go +++ b/coder-sdk/client.go @@ -25,7 +25,7 @@ type Client struct { // WARNING: If the caller sets a custom transport to set TLS settings or a custom CA, the default // pool will not be used and it might result in a new dns lookup/tls session/socket begin // established each time. -func (c *Client) newHTTPClient() (*http.Client, error) { +func (c Client) newHTTPClient() (*http.Client, error) { jar, err := cookiejar.New(nil) if err != nil { return nil, err diff --git a/coder-sdk/secrets.go b/coder-sdk/secrets.go index 9043091d..00ba2f0d 100644 --- a/coder-sdk/secrets.go +++ b/coder-sdk/secrets.go @@ -17,7 +17,7 @@ type Secret struct { } // Secrets gets all secrets for the given user. -func (c *Client) Secrets(ctx context.Context, userID string) ([]Secret, error) { +func (c Client) Secrets(ctx context.Context, userID string) ([]Secret, error) { var secrets []Secret if err := c.requestBody(ctx, http.MethodGet, "/api/users/"+userID+"/secrets", nil, &secrets); err != nil { return nil, err @@ -26,7 +26,7 @@ func (c *Client) Secrets(ctx context.Context, userID string) ([]Secret, error) { } // SecretWithValueByName gets the Coder secret with its value by its name. -func (c *Client) SecretWithValueByName(ctx context.Context, name, userID string) (*Secret, error) { +func (c Client) SecretWithValueByName(ctx context.Context, name, userID string) (*Secret, error) { // Lookup the secret from the name. s, err := c.SecretByName(ctx, name, userID) if err != nil { @@ -43,7 +43,7 @@ func (c *Client) SecretWithValueByName(ctx context.Context, name, userID string) } // SecretWithValueByID gets the Coder secret with its value by the secret_id. -func (c *Client) SecretWithValueByID(ctx context.Context, id, userID string) (*Secret, error) { +func (c Client) SecretWithValueByID(ctx context.Context, id, userID string) (*Secret, error) { var secret Secret if err := c.requestBody(ctx, http.MethodGet, "/api/users/"+userID+"/secrets/"+id, nil, &secret); err != nil { return nil, err @@ -52,7 +52,7 @@ func (c *Client) SecretWithValueByID(ctx context.Context, id, userID string) (*S } // SecretByName gets a secret object by name. -func (c *Client) SecretByName(ctx context.Context, name, userID string) (*Secret, error) { +func (c Client) SecretByName(ctx context.Context, name, userID string) (*Secret, error) { secrets, err := c.Secrets(ctx, userID) if err != nil { return nil, err @@ -73,12 +73,12 @@ type InsertSecretReq struct { } // InsertSecret adds a new secret for the authed user. -func (c *Client) InsertSecret(ctx context.Context, user *User, req InsertSecretReq) error { +func (c Client) InsertSecret(ctx context.Context, user *User, req InsertSecretReq) error { return c.requestBody(ctx, http.MethodPost, "/api/users/"+user.ID+"/secrets", req, nil) } // DeleteSecretByName deletes the authenticated users secret with the given name. -func (c *Client) DeleteSecretByName(ctx context.Context, name, userID string) error { +func (c Client) DeleteSecretByName(ctx context.Context, name, userID string) error { // Lookup the secret by name to get the ID. secret, err := c.SecretByName(ctx, name, userID) if err != nil { From 6f878a3970e7611584385e9c18f2e8a8ffd64bd9 Mon Sep 17 00:00:00 2001 From: Charlie Moog Date: Wed, 4 Nov 2020 20:04:50 -0600 Subject: [PATCH 4/6] fixup! Cleanup --- coder-sdk/secrets.go | 20 ++++++++++++++++++-- internal/cmd/secrets.go | 6 +++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/coder-sdk/secrets.go b/coder-sdk/secrets.go index 00ba2f0d..a7f94f59 100644 --- a/coder-sdk/secrets.go +++ b/coder-sdk/secrets.go @@ -7,6 +7,8 @@ import ( ) // Secret describes a Coder secret. +// +// Deprecated: Coder Secrets will be removed from Coder Enterprise in a future release. type Secret struct { ID string `json:"id" table:"-"` Name string `json:"name" table:"Name"` @@ -17,6 +19,8 @@ type Secret struct { } // Secrets gets all secrets for the given user. +// +// Deprecated: Coder Secrets will be removed from Coder Enterprise in a future release. func (c Client) Secrets(ctx context.Context, userID string) ([]Secret, error) { var secrets []Secret if err := c.requestBody(ctx, http.MethodGet, "/api/users/"+userID+"/secrets", nil, &secrets); err != nil { @@ -26,6 +30,8 @@ func (c Client) Secrets(ctx context.Context, userID string) ([]Secret, error) { } // SecretWithValueByName gets the Coder secret with its value by its name. +// +// Deprecated: Coder Secrets will be removed from Coder Enterprise in a future release. func (c Client) SecretWithValueByName(ctx context.Context, name, userID string) (*Secret, error) { // Lookup the secret from the name. s, err := c.SecretByName(ctx, name, userID) @@ -43,6 +49,8 @@ func (c Client) SecretWithValueByName(ctx context.Context, name, userID string) } // SecretWithValueByID gets the Coder secret with its value by the secret_id. +// +// Deprecated: Coder Secrets will be removed from Coder Enterprise in a future release. func (c Client) SecretWithValueByID(ctx context.Context, id, userID string) (*Secret, error) { var secret Secret if err := c.requestBody(ctx, http.MethodGet, "/api/users/"+userID+"/secrets/"+id, nil, &secret); err != nil { @@ -52,6 +60,8 @@ func (c Client) SecretWithValueByID(ctx context.Context, id, userID string) (*Se } // SecretByName gets a secret object by name. +// +// Deprecated: Coder Secrets will be removed from Coder Enterprise in a future release. func (c Client) SecretByName(ctx context.Context, name, userID string) (*Secret, error) { secrets, err := c.Secrets(ctx, userID) if err != nil { @@ -66,6 +76,8 @@ func (c Client) SecretByName(ctx context.Context, name, userID string) (*Secret, } // InsertSecretReq describes the request body for creating a new secret. +// +// Deprecated: Coder Secrets will be removed from Coder Enterprise in a future release. type InsertSecretReq struct { Name string `json:"name"` Value string `json:"value"` @@ -73,11 +85,15 @@ type InsertSecretReq struct { } // InsertSecret adds a new secret for the authed user. -func (c Client) InsertSecret(ctx context.Context, user *User, req InsertSecretReq) error { - return c.requestBody(ctx, http.MethodPost, "/api/users/"+user.ID+"/secrets", req, nil) +// +// Deprecated: Coder Secrets will be removed from Coder Enterprise in a future release. +func (c Client) InsertSecret(ctx context.Context, userID string, req InsertSecretReq) error { + return c.requestBody(ctx, http.MethodPost, "/api/users/"+userID+"/secrets", req, nil) } // DeleteSecretByName deletes the authenticated users secret with the given name. +// +// Deprecated: Coder Secrets will be removed from Coder Enterprise in a future release. func (c Client) DeleteSecretByName(ctx context.Context, name, userID string) error { // Lookup the secret by name to get the ID. secret, err := c.SecretByName(ctx, name, userID) diff --git a/internal/cmd/secrets.go b/internal/cmd/secrets.go index 41e38443..4a8d7468 100644 --- a/internal/cmd/secrets.go +++ b/internal/cmd/secrets.go @@ -128,7 +128,8 @@ coder secrets create aws-credentials --from-file ./credentials.json`, if err != nil { return xerrors.Errorf("get user %q by email: %w", *userEmail, err) } - err = client.InsertSecret(ctx, user, coder.InsertSecretReq{ + //nolint:staticcheck + err = client.InsertSecret(ctx, user.ID, coder.InsertSecretReq{ Name: name, Value: value, Description: description, @@ -160,6 +161,7 @@ func listSecretsCmd(userEmail *string) func(cmd *cobra.Command, _ []string) erro return xerrors.Errorf("get user %q by email: %w", *userEmail, err) } + //nolint:staticcheck secrets, err := client.Secrets(ctx, user.ID) if err != nil { return xerrors.Errorf("get secrets: %w", err) @@ -197,6 +199,7 @@ func viewSecretCmd(userEmail *string) func(cmd *cobra.Command, args []string) er return xerrors.Errorf("get user %q by email: %w", *userEmail, err) } + //nolint:staticcheck secret, err := client.SecretWithValueByName(ctx, name, user.ID) if err != nil { return xerrors.Errorf("get secret by name: %w", err) @@ -224,6 +227,7 @@ func removeSecretsCmd(userEmail *string) func(c *cobra.Command, args []string) e errorSeen := false for _, n := range args { + //nolint:staticcheck err := client.DeleteSecretByName(ctx, n, user.ID) if err != nil { clog.Log(clog.Error( From 55802062237a9a2127cbeab3f934b92c573d338e Mon Sep 17 00:00:00 2001 From: Charlie Moog Date: Wed, 4 Nov 2020 21:41:02 -0600 Subject: [PATCH 5/6] fixup! Cleanup --- coder-sdk/devurl.go | 70 +++++++++----------------------------------- internal/cmd/urls.go | 33 ++++++++++++++------- 2 files changed, 36 insertions(+), 67 deletions(-) diff --git a/coder-sdk/devurl.go b/coder-sdk/devurl.go index a288d418..580fdb03 100644 --- a/coder-sdk/devurl.go +++ b/coder-sdk/devurl.go @@ -20,75 +20,33 @@ type delDevURLRequest struct { DevURLID string `json:"url_id"` } -// DelDevURL deletes the specified devurl. -func (c Client) DelDevURL(ctx context.Context, envID, urlID string) error { +// DeleteDevURL deletes the specified devurl. +func (c Client) DeleteDevURL(ctx context.Context, envID, urlID string) error { reqURL := fmt.Sprintf("/api/environments/%s/devurls/%s", envID, urlID) - resp, err := c.request(ctx, http.MethodDelete, reqURL, delDevURLRequest{ + return c.requestBody(ctx, http.MethodDelete, reqURL, delDevURLRequest{ EnvID: envID, DevURLID: urlID, - }) - if err != nil { - return err - } - defer func() { _ = resp.Body.Close() }() // Best effort. Likely connection drop. - - if resp.StatusCode != http.StatusOK { - return bodyError(resp) - } - - return nil + }, nil) } -type createDevURLRequest struct { +// CreateDevURLReq defines the request parameters for creating a new DevURL. +type CreateDevURLReq struct { EnvID string `json:"environment_id"` Port int `json:"port"` Access string `json:"access"` Name string `json:"name"` } -// InsertDevURL inserts a new devurl for the authenticated user. -func (c Client) InsertDevURL(ctx context.Context, envID string, port int, name, access string) error { - reqURL := fmt.Sprintf("/api/environments/%s/devurls", envID) - - resp, err := c.request(ctx, http.MethodPost, reqURL, createDevURLRequest{ - EnvID: envID, - Port: port, - Access: access, - Name: name, - }) - if err != nil { - return err - } - defer func() { _ = resp.Body.Close() }() // Best effort. Likely connection drop. - - if resp.StatusCode != http.StatusOK { - return bodyError(resp) - } - - return nil +// CreateDevURL inserts a new devurl for the authenticated user. +func (c Client) CreateDevURL(ctx context.Context, envID string, req CreateDevURLReq) error { + return c.requestBody(ctx, http.MethodPost, "/api/environments/"+envID+"/devurls", req, nil) } -type updateDevURLRequest createDevURLRequest - -// UpdateDevURL updates an existing devurl for the authenticated user. -func (c Client) UpdateDevURL(ctx context.Context, envID, urlID string, port int, name, access string) error { - reqURL := fmt.Sprintf("/api/environments/%s/devurls/%s", envID, urlID) - - resp, err := c.request(ctx, http.MethodPut, reqURL, updateDevURLRequest{ - EnvID: envID, - Port: port, - Access: access, - Name: name, - }) - if err != nil { - return err - } - defer func() { _ = resp.Body.Close() }() // Best effort. Likefly connection drop. - - if resp.StatusCode != http.StatusOK { - return bodyError(resp) - } +// PutDevURLReq defines the request parameters for overwriting a DevURL. +type PutDevURLReq CreateDevURLReq - return nil +// PutDevURL updates an existing devurl for the authenticated user. +func (c Client) PutDevURL(ctx context.Context, envID, urlID string, req PutDevURLReq) error { + return c.requestBody(ctx, http.MethodPut, "/api/environments/"+envID+"/devurls/"+urlID, req, nil) } diff --git a/internal/cmd/urls.go b/internal/cmd/urls.go index 26e5d5bd..b885d5d7 100644 --- a/internal/cmd/urls.go +++ b/internal/cmd/urls.go @@ -92,8 +92,13 @@ func accessLevelIsValid(level string) bool { func listDevURLsCmd(outputFmt *string) func(cmd *cobra.Command, args []string) error { return func(cmd *cobra.Command, args []string) error { ctx := cmd.Context() + client, err := newClient(ctx) + if err != nil { + return err + } envName := args[0] - devURLs, err := urlList(ctx, envName) + + devURLs, err := urlList(ctx, client, envName) if err != nil { return err } @@ -162,7 +167,7 @@ func createDevURLCmd() *cobra.Command { return err } - urls, err := urlList(ctx, envName) + urls, err := urlList(ctx, client, envName) if err != nil { return err } @@ -170,13 +175,23 @@ func createDevURLCmd() *cobra.Command { urlID, found := devURLID(portNum, urls) if found { clog.LogInfo(fmt.Sprintf("updating devurl for port %v", port)) - err := client.UpdateDevURL(ctx, env.ID, urlID, portNum, urlname, access) + err := client.PutDevURL(ctx, env.ID, urlID, coder.PutDevURLReq{ + Port: portNum, + Name: urlname, + Access: access, + EnvID: env.ID, + }) if err != nil { return xerrors.Errorf("update DevURL: %w", err) } } else { clog.LogInfo(fmt.Sprintf("Adding devurl for port %v", port)) - err := client.InsertDevURL(ctx, env.ID, portNum, urlname, access) + err := client.CreateDevURL(ctx, env.ID, coder.CreateDevURLReq{ + Port: portNum, + Name: urlname, + Access: access, + EnvID: env.ID, + }) if err != nil { return xerrors.Errorf("insert DevURL: %w", err) } @@ -231,7 +246,7 @@ func removeDevURL(cmd *cobra.Command, args []string) error { return err } - urls, err := urlList(ctx, envName) + urls, err := urlList(ctx, client, envName) if err != nil { return err } @@ -243,18 +258,14 @@ func removeDevURL(cmd *cobra.Command, args []string) error { return xerrors.Errorf("No devurl found for port %v", port) } - if err := client.DelDevURL(ctx, env.ID, urlID); err != nil { + if err := client.DeleteDevURL(ctx, env.ID, urlID); err != nil { return xerrors.Errorf("delete DevURL: %w", err) } return nil } // urlList returns the list of active devURLs from the cemanager. -func urlList(ctx context.Context, envName string) ([]DevURL, error) { - client, err := newClient(ctx) - if err != nil { - return nil, err - } +func urlList(ctx context.Context, client *coder.Client, envName string) ([]DevURL, error) { env, err := findEnv(ctx, client, envName, coder.Me) if err != nil { return nil, err From 5e6df2d2a5fffebc7f6145cc36ebb57c50c6a971 Mon Sep 17 00:00:00 2001 From: Charlie Moog Date: Thu, 5 Nov 2020 10:20:50 -0600 Subject: [PATCH 6/6] fixup! Cleanup --- coder-sdk/org.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/coder-sdk/org.go b/coder-sdk/org.go index d42235ae..a4b4d7ed 100644 --- a/coder-sdk/org.go +++ b/coder-sdk/org.go @@ -8,9 +8,18 @@ import ( // Organization describes an Organization in Coder. type Organization struct { - ID string `json:"id"` - Name string `json:"name"` - Members []OrganizationUser `json:"members"` + ID string `json:"id"` + Name string `json:"name"` + Description string `json:"description"` + Default bool `json:"default"` + Members []OrganizationUser `json:"members"` + EnvironmentCount int `json:"environment_count"` + ResourceNamespace string `json:"resource_namespace"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + AutoOffThreshold Duration `json:"auto_off_threshold"` + CPUProvisioningRate float32 `json:"cpu_provisioning_rate"` + MemoryProvisioningRate float32 `json:"memory_provisioning_rate"` } // OrganizationUser user wraps the basic User type and adds data specific to the user's membership of an organization.