Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
/coder-v1-cliPublic archive

Commit0156dd0

Browse files
authored
Cleanup (#179)
1 parentb92aaf0 commit0156dd0

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() {builtinpopd>/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"Buildingcoder-cli for$GOOS-$GOARCH..."
14+
echo"--- buildingcoder-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
gotest ./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
gotest$(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 (cClient)newHTTPClient() (*http.Client,error) {
2929
jar,err:=cookiejar.New(nil)
3030
iferr!=nil {
3131
returnnil,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
DevURLIDstring`json:"url_id"`
2121
}
2222

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

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

43-
typecreateDevURLRequeststruct {
33+
// CreateDevURLReq defines the request parameters for creating a new DevURL.
34+
typeCreateDevURLReqstruct {
4435
EnvIDstring`json:"environment_id"`
4536
Portint`json:"port"`
4637
Accessstring`json:"access"`
4738
Namestring`json:"name"`
4839
}
4940

50-
// InsertDevURL inserts a new devurl for the authenticated user.
51-
func (cClient)InsertDevURL(ctx context.Context,envIDstring,portint,name,accessstring)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-
iferr!=nil {
61-
returnerr
62-
}
63-
deferfunc() {_=resp.Body.Close() }()// Best effort. Likely connection drop.
64-
65-
ifresp.StatusCode!=http.StatusOK {
66-
returnbodyError(resp)
67-
}
68-
69-
returnnil
41+
// CreateDevURL inserts a new devurl for the authenticated user.
42+
func (cClient)CreateDevURL(ctx context.Context,envIDstring,reqCreateDevURLReq)error {
43+
returnc.requestBody(ctx,http.MethodPost,"/api/environments/"+envID+"/devurls",req,nil)
7044
}
7145

72-
typeupdateDevURLRequestcreateDevURLRequest
73-
74-
// UpdateDevURL updates an existing devurl for the authenticated user.
75-
func (cClient)UpdateDevURL(ctx context.Context,envID,urlIDstring,portint,name,accessstring)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-
iferr!=nil {
85-
returnerr
86-
}
87-
deferfunc() {_=resp.Body.Close() }()// Best effort. Likefly connection drop.
88-
89-
ifresp.StatusCode!=http.StatusOK {
90-
returnbodyError(resp)
91-
}
46+
// PutDevURLReq defines the request parameters for overwriting a DevURL.
47+
typePutDevURLReqCreateDevURLReq
9248

93-
returnnil
49+
// PutDevURL updates an existing devurl for the authenticated user.
50+
func (cClient)PutDevURL(ctx context.Context,envID,urlIDstring,reqPutDevURLReq)error {
51+
returnc.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
varErrAuthentication=xerrors.New("invalid authentication")
1919

20-
//APIError is the expected payload format for our errors.
21-
typeAPIErrorstruct {
22-
ErrAPIErrorMsg`json:"error"`
20+
//apiError is the expected payload format for our errors.
21+
typeapiErrorstruct {
22+
ErrapiErrorMsg`json:"error"`
2323
}
2424

25-
//APIErrorMsg contains the rich error information returned by API errors.
26-
typeAPIErrorMsgstruct {
25+
//apiErrorMsg contains the rich error information returned by API errors.
26+
typeapiErrorMsgstruct {
2727
Msgstring`json:"msg"`
2828
}
2929

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

3535
func (e*HTTPError)Error()string {
36-
varmsgAPIError
36+
varmsgapiError
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 thedump.
38+
// return the response URL with thestatus.
3939
iferr:=json.NewDecoder(e.Response.Body).Decode(&msg);err!=nil||msg.Err.Msg=="" {
4040
returnfmt.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
typeOrganizationstruct {
11-
IDstring`json:"id"`
12-
Namestring`json:"name"`
13-
Members []OrganizationUser`json:"members"`
11+
IDstring`json:"id"`
12+
Namestring`json:"name"`
13+
Descriptionstring`json:"description"`
14+
Defaultbool`json:"default"`
15+
Members []OrganizationUser`json:"members"`
16+
EnvironmentCountint`json:"environment_count"`
17+
ResourceNamespacestring`json:"resource_namespace"`
18+
CreatedAt time.Time`json:"created_at"`
19+
UpdatedAt time.Time`json:"updated_at"`
20+
AutoOffThresholdDuration`json:"auto_off_threshold"`
21+
CPUProvisioningRatefloat32`json:"cpu_provisioning_rate"`
22+
MemoryProvisioningRatefloat32`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.

‎coder-sdk/secrets.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
)
88

99
// Secret describes a Coder secret.
10+
//
11+
// Deprecated: Coder Secrets will be removed from Coder Enterprise in a future release.
1012
typeSecretstruct {
1113
IDstring`json:"id" table:"-"`
1214
Namestring`json:"name" table:"Name"`
@@ -17,7 +19,9 @@ type Secret struct {
1719
}
1820

1921
// Secrets gets all secrets for the given user.
20-
func (c*Client)Secrets(ctx context.Context,userIDstring) ([]Secret,error) {
22+
//
23+
// Deprecated: Coder Secrets will be removed from Coder Enterprise in a future release.
24+
func (cClient)Secrets(ctx context.Context,userIDstring) ([]Secret,error) {
2125
varsecrets []Secret
2226
iferr:=c.requestBody(ctx,http.MethodGet,"/api/users/"+userID+"/secrets",nil,&secrets);err!=nil {
2327
returnnil,err
@@ -26,7 +30,9 @@ func (c *Client) Secrets(ctx context.Context, userID string) ([]Secret, error) {
2630
}
2731

2832
// SecretWithValueByName gets the Coder secret with its value by its name.
29-
func (c*Client)SecretWithValueByName(ctx context.Context,name,userIDstring) (*Secret,error) {
33+
//
34+
// Deprecated: Coder Secrets will be removed from Coder Enterprise in a future release.
35+
func (cClient)SecretWithValueByName(ctx context.Context,name,userIDstring) (*Secret,error) {
3036
// Lookup the secret from the name.
3137
s,err:=c.SecretByName(ctx,name,userID)
3238
iferr!=nil {
@@ -43,7 +49,9 @@ func (c *Client) SecretWithValueByName(ctx context.Context, name, userID string)
4349
}
4450

4551
// SecretWithValueByID gets the Coder secret with its value by the secret_id.
46-
func (c*Client)SecretWithValueByID(ctx context.Context,id,userIDstring) (*Secret,error) {
52+
//
53+
// Deprecated: Coder Secrets will be removed from Coder Enterprise in a future release.
54+
func (cClient)SecretWithValueByID(ctx context.Context,id,userIDstring) (*Secret,error) {
4755
varsecretSecret
4856
iferr:=c.requestBody(ctx,http.MethodGet,"/api/users/"+userID+"/secrets/"+id,nil,&secret);err!=nil {
4957
returnnil,err
@@ -52,7 +60,9 @@ func (c *Client) SecretWithValueByID(ctx context.Context, id, userID string) (*S
5260
}
5361

5462
// SecretByName gets a secret object by name.
55-
func (c*Client)SecretByName(ctx context.Context,name,userIDstring) (*Secret,error) {
63+
//
64+
// Deprecated: Coder Secrets will be removed from Coder Enterprise in a future release.
65+
func (cClient)SecretByName(ctx context.Context,name,userIDstring) (*Secret,error) {
5666
secrets,err:=c.Secrets(ctx,userID)
5767
iferr!=nil {
5868
returnnil,err
@@ -66,19 +76,25 @@ func (c *Client) SecretByName(ctx context.Context, name, userID string) (*Secret
6676
}
6777

6878
// InsertSecretReq describes the request body for creating a new secret.
79+
//
80+
// Deprecated: Coder Secrets will be removed from Coder Enterprise in a future release.
6981
typeInsertSecretReqstruct {
7082
Namestring`json:"name"`
7183
Valuestring`json:"value"`
7284
Descriptionstring`json:"description"`
7385
}
7486

7587
// InsertSecret adds a new secret for the authed user.
76-
func (c*Client)InsertSecret(ctx context.Context,user*User,reqInsertSecretReq)error {
77-
returnc.requestBody(ctx,http.MethodPost,"/api/users/"+user.ID+"/secrets",req,nil)
88+
//
89+
// Deprecated: Coder Secrets will be removed from Coder Enterprise in a future release.
90+
func (cClient)InsertSecret(ctx context.Context,userIDstring,reqInsertSecretReq)error {
91+
returnc.requestBody(ctx,http.MethodPost,"/api/users/"+userID+"/secrets",req,nil)
7892
}
7993

8094
// DeleteSecretByName deletes the authenticated users secret with the given name.
81-
func (c*Client)DeleteSecretByName(ctx context.Context,name,userIDstring)error {
95+
//
96+
// Deprecated: Coder Secrets will be removed from Coder Enterprise in a future release.
97+
func (cClient)DeleteSecretByName(ctx context.Context,name,userIDstring)error {
8298
// Lookup the secret by name to get the ID.
8399
secret,err:=c.SecretByName(ctx,name,userID)
84100
iferr!=nil {

‎docs/coder_envs_create.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub
2828
-h, --help help for create
2929
-i, --image string name of the image to base the environment off of.
3030
-m, --memory float32 GB of RAM an environment should be provisioned with.
31-
-o, --org stringID of the organization the environment should be created under.
31+
-o, --org stringname of the organization the environment should be created under.
3232
-t, --tag string tag of the image the environment will be based off of. (default "latest")
3333
```
3434

‎internal/cmd/configssh.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func configSSHCmd() *cobra.Command {
3737
}
3838

3939
funcconfigSSH(configpath*string,remove*bool)func(cmd*cobra.Command,_ []string)error {
40-
startToken:="# ------------START-CODER-ENTERPRISE-----------"
40+
conststartToken="# ------------START-CODER-ENTERPRISE-----------"
4141
startMessage:=`# The following has been auto-generated by "coder config-ssh"
4242
# to make accessing your Coder Enterprise environments easier.
4343
#
@@ -46,7 +46,7 @@ func configSSH(configpath *string, remove *bool) func(cmd *cobra.Command, _ []st
4646
# coder config-ssh --remove
4747
#
4848
# You should not hand-edit this section, unless you are deleting it.`
49-
endToken:="# ------------END-CODER-ENTERPRISE------------"
49+
constendToken="# ------------END-CODER-ENTERPRISE------------"
5050

5151
returnfunc(cmd*cobra.Command,_ []string)error {
5252
ctx:=cmd.Context()

‎internal/cmd/envs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub
230230
returnnil
231231
},
232232
}
233-
cmd.Flags().StringVarP(&org,"org","o","","ID of the organization the environment should be created under.")
233+
cmd.Flags().StringVarP(&org,"org","o","","name of the organization the environment should be created under.")
234234
cmd.Flags().StringVarP(&tag,"tag","t",defaultImgTag,"tag of the image the environment will be based off of.")
235235
cmd.Flags().Float32VarP(&cpu,"cpu","c",0,"number of cpu cores the environment should be provisioned with.")
236236
cmd.Flags().Float32VarP(&memory,"memory","m",0,"GB of RAM an environment should be provisioned with.")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp