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

Commit 0156dd0

Browse files
authored
Cleanup (#179)
1 parent b92aaf0 commit 0156dd0

File tree

16 files changed

+115
-121
lines changed

16 files changed

+115
-121
lines changed

ci/steps/build.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ pushd() { builtin pushd "$@" >/dev/null; }
55
popd() { builtin popd >/dev/null; }
66

77
set -euo pipefail
8-
cd "$(dirname "$0")"
8+
9+
cd "$(git rev-parse --show-toplevel)/ci/steps"
910

1011
tag=$(git describe --tags)
1112

1213
build() {
13-
echo "Building coder-cli for $GOOS-$GOARCH..."
14+
echo "--- building coder-cli for $GOOS-$GOARCH"
1415

1516
tmpdir=$(mktemp -d)
1617
go build -ldflags "-X cdr.dev/coder-cli/internal/version.Version=${tag}" -o "$tmpdir/coder" ../../cmd/coder
@@ -29,9 +30,15 @@ build() {
2930
tar -czf "$artifact" coder
3031
;;
3132
"darwin")
33+
if [[ ${CI-} ]]; then
3234
artifact="coder-cli-$GOOS-$GOARCH.zip"
3335
gon -log-level debug ./gon.json
3436
mv coder.zip $artifact
37+
else
38+
artifact="coder-cli-$GOOS-$GOARCH.tar.gz"
39+
tar -czf "$artifact" coder
40+
echo "--- warning: not in ci, skipping signed release of darwin"
41+
fi
3542
;;
3643
esac
3744
popd
@@ -46,8 +53,8 @@ build() {
4653
if [[ "$(uname)" == "Darwin" ]]; then
4754
CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 build
4855
else
49-
echo "Warning: Darwin builds don't work on Linux."
50-
echo "Please use an OSX machine to build Darwin tars."
56+
echo "--- warning: Darwin builds don't work on Linux."
57+
echo "--- please use an OSX machine to build Darwin tars."
5158
fi
5259

5360
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 build

ci/steps/fmt.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
set -euo pipefail
44

5-
echo "Formatting..."
5+
cd "$(git rev-parse --show-toplevel)"
66

7+
echo "--- formatting"
78
go mod tidy
89
gofmt -w -s .
910
goimports -w "-local=$$(go list -m)" .

ci/steps/gendocs.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
set -euo pipefail
44

5-
echo "Generating docs..."
6-
7-
cd "$(dirname "$0")"
8-
cd ../../
5+
cd "$(git rev-parse --show-toplevel)"
96

7+
echo "--- regenerating documentation"
108
rm -rf ./docs
119
mkdir ./docs
1210
go run ./cmd/coder gen-docs ./docs

ci/steps/integration.sh

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@
22

33
set -eo pipefail
44

5-
log() {
6-
echo "--- $@"
7-
}
8-
95
cd "$(git rev-parse --show-toplevel)"
106

11-
log "building integration test image"
7+
echo "--- building integration test image"
128
docker build -f ./ci/integration/Dockerfile -t coder-cli-integration:latest .
139

14-
log "starting integration tests"
10+
echo "--- starting integration tests"
1511
go test ./ci/integration -count=1

ci/steps/lint.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
set -euo pipefail
44

5-
echo "Linting..."
6-
7-
cd "$(dirname "$0")"
8-
cd ../../
5+
cd "$(git rev-parse --show-toplevel)"
96

107
echo "--- golangci-lint"
118
golangci-lint run -c .golangci.yml

ci/steps/unit_test.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@ set -euo pipefail
44

55
cd "$(git rev-parse --show-toplevel)"
66

7-
echo "--- go test..."
8-
7+
echo "--- running unit tests"
98
go test $(go list ./... | grep -v pkg/tcli | grep -v ci/integration | grep -v coder-sdk)

coder-sdk/client.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,20 @@ type Client struct {
2525
// WARNING: If the caller sets a custom transport to set TLS settings or a custom CA, the default
2626
// pool will not be used and it might result in a new dns lookup/tls session/socket begin
2727
// established each time.
28-
func (c *Client) newHTTPClient() (*http.Client, error) {
28+
func (c Client) newHTTPClient() (*http.Client, error) {
2929
jar, err := cookiejar.New(nil)
3030
if err != nil {
3131
return nil, err
3232
}
3333

34-
jar.SetCookies(c.BaseURL, []*http.Cookie{
35-
{
36-
Name: "session_token",
37-
Value: c.Token,
38-
MaxAge: 86400,
39-
Path: "/",
40-
HttpOnly: true,
41-
Secure: c.BaseURL.Scheme == "https",
42-
},
43-
})
34+
jar.SetCookies(c.BaseURL, []*http.Cookie{{
35+
Name: "session_token",
36+
Value: c.Token,
37+
MaxAge: 86400,
38+
Path: "/",
39+
HttpOnly: true,
40+
Secure: c.BaseURL.Scheme == "https",
41+
}})
4442

4543
return &http.Client{Jar: jar}, nil
4644
}

coder-sdk/devurl.go

Lines changed: 14 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -20,75 +20,33 @@ type delDevURLRequest struct {
2020
DevURLID string `json:"url_id"`
2121
}
2222

23-
// DelDevURL deletes the specified devurl.
24-
func (c Client) DelDevURL(ctx context.Context, envID, urlID string) error {
23+
// DeleteDevURL deletes the specified devurl.
24+
func (c Client) DeleteDevURL(ctx context.Context, envID, urlID string) error {
2525
reqURL := fmt.Sprintf("/api/environments/%s/devurls/%s", envID, urlID)
2626

27-
resp, err := c.request(ctx, http.MethodDelete, reqURL, delDevURLRequest{
27+
return c.requestBody(ctx, http.MethodDelete, reqURL, delDevURLRequest{
2828
EnvID: envID,
2929
DevURLID: urlID,
30-
})
31-
if err != nil {
32-
return err
33-
}
34-
defer func() { _ = resp.Body.Close() }() // Best effort. Likely connection drop.
35-
36-
if resp.StatusCode != http.StatusOK {
37-
return bodyError(resp)
38-
}
39-
40-
return nil
30+
}, nil)
4131
}
4232

43-
type createDevURLRequest struct {
33+
// CreateDevURLReq defines the request parameters for creating a new DevURL.
34+
type CreateDevURLReq struct {
4435
EnvID string `json:"environment_id"`
4536
Port int `json:"port"`
4637
Access string `json:"access"`
4738
Name string `json:"name"`
4839
}
4940

50-
// InsertDevURL inserts a new devurl for the authenticated user.
51-
func (c Client) InsertDevURL(ctx context.Context, envID string, port int, name, access string) error {
52-
reqURL := fmt.Sprintf("/api/environments/%s/devurls", envID)
53-
54-
resp, err := c.request(ctx, http.MethodPost, reqURL, createDevURLRequest{
55-
EnvID: envID,
56-
Port: port,
57-
Access: access,
58-
Name: name,
59-
})
60-
if err != nil {
61-
return err
62-
}
63-
defer func() { _ = resp.Body.Close() }() // Best effort. Likely connection drop.
64-
65-
if resp.StatusCode != http.StatusOK {
66-
return bodyError(resp)
67-
}
68-
69-
return nil
41+
// CreateDevURL inserts a new devurl for the authenticated user.
42+
func (c Client) CreateDevURL(ctx context.Context, envID string, req CreateDevURLReq) error {
43+
return c.requestBody(ctx, http.MethodPost, "/api/environments/"+envID+"/devurls", req, nil)
7044
}
7145

72-
type updateDevURLRequest createDevURLRequest
73-
74-
// UpdateDevURL updates an existing devurl for the authenticated user.
75-
func (c Client) UpdateDevURL(ctx context.Context, envID, urlID string, port int, name, access string) error {
76-
reqURL := fmt.Sprintf("/api/environments/%s/devurls/%s", envID, urlID)
77-
78-
resp, err := c.request(ctx, http.MethodPut, reqURL, updateDevURLRequest{
79-
EnvID: envID,
80-
Port: port,
81-
Access: access,
82-
Name: name,
83-
})
84-
if err != nil {
85-
return err
86-
}
87-
defer func() { _ = resp.Body.Close() }() // Best effort. Likefly connection drop.
88-
89-
if resp.StatusCode != http.StatusOK {
90-
return bodyError(resp)
91-
}
46+
// PutDevURLReq defines the request parameters for overwriting a DevURL.
47+
type PutDevURLReq CreateDevURLReq
9248

93-
return nil
49+
// PutDevURL updates an existing devurl for the authenticated user.
50+
func (c Client) PutDevURL(ctx context.Context, envID, urlID string, req PutDevURLReq) error {
51+
return c.requestBody(ctx, http.MethodPut, "/api/environments/"+envID+"/devurls/"+urlID, req, nil)
9452
}

coder-sdk/error.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ var ErrPermissions = xerrors.New("insufficient permissions")
1717
// ErrAuthentication describes the error case in which the requester has invalid authentication.
1818
var ErrAuthentication = xerrors.New("invalid authentication")
1919

20-
// APIError is the expected payload format for our errors.
21-
type APIError struct {
22-
Err APIErrorMsg `json:"error"`
20+
// apiError is the expected payload format for our errors.
21+
type apiError struct {
22+
Err apiErrorMsg `json:"error"`
2323
}
2424

25-
// APIErrorMsg contains the rich error information returned by API errors.
26-
type APIErrorMsg struct {
25+
// apiErrorMsg contains the rich error information returned by API errors.
26+
type apiErrorMsg struct {
2727
Msg string `json:"msg"`
2828
}
2929

@@ -33,9 +33,9 @@ type HTTPError struct {
3333
}
3434

3535
func (e *HTTPError) Error() string {
36-
var msg APIError
36+
var msg apiError
3737
// Try to decode the payload as an error, if it fails or if there is no error message,
38-
// return the response URL with the dump.
38+
// return the response URL with the status.
3939
if err := json.NewDecoder(e.Response.Body).Decode(&msg); err != nil || msg.Err.Msg == "" {
4040
return fmt.Sprintf("%s: %d %s", e.Request.URL, e.StatusCode, e.Status)
4141
}

coder-sdk/org.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,18 @@ import (
88

99
// Organization describes an Organization in Coder.
1010
type Organization struct {
11-
ID string `json:"id"`
12-
Name string `json:"name"`
13-
Members []OrganizationUser `json:"members"`
11+
ID string `json:"id"`
12+
Name string `json:"name"`
13+
Description string `json:"description"`
14+
Default bool `json:"default"`
15+
Members []OrganizationUser `json:"members"`
16+
EnvironmentCount int `json:"environment_count"`
17+
ResourceNamespace string `json:"resource_namespace"`
18+
CreatedAt time.Time `json:"created_at"`
19+
UpdatedAt time.Time `json:"updated_at"`
20+
AutoOffThreshold Duration `json:"auto_off_threshold"`
21+
CPUProvisioningRate float32 `json:"cpu_provisioning_rate"`
22+
MemoryProvisioningRate float32 `json:"memory_provisioning_rate"`
1423
}
1524

1625
// OrganizationUser user wraps the basic User type and adds data specific to the user's membership of an organization.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy