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

Commit89b4b36

Browse files
committed
Add stricter linter rules
1 parentcfdde80 commit89b4b36

File tree

19 files changed

+135
-29
lines changed

19 files changed

+135
-29
lines changed

‎.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
ci/bin
33
cmd/coder/coder
44
ci/integration/bin
5-
ci/integration/env.sh
5+
ci/integration/env.sh
6+
coder-sdk/env.sh

‎.golangci.yml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,33 @@ linters-settings:
1414
funcs:# Run `go tool vet help printf` to see available settings for `printf` analyzer.
1515
-(cdr.dev/coder-cli/pkg/clog).Tipf
1616
-(cdr.dev/coder-cli/pkg/clog).Hintf
17-
-(cdr.dev/coder-cli/pkg/clog).Causef
17+
-(cdr.dev/coder-cli/pkg/clog).Causef
18+
linters:
19+
disable-all:true
20+
enable:
21+
-megacheck
22+
-govet
23+
-golint
24+
-goconst
25+
-gocognit
26+
-nestif
27+
-misspell
28+
-unparam
29+
-unused
30+
-bodyclose
31+
-deadcode
32+
-depguard
33+
-dogsled
34+
-errcheck
35+
-unconvert
36+
-unparam
37+
-varcheck
38+
-whitespace
39+
-structcheck
40+
-stylecheck
41+
-typecheck
42+
-noctx
43+
-nolintlint
44+
-rowserrcheck
45+
-scopelint
46+
-goprintffuncname

‎ci/integration/devurls_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,4 @@ func TestDevURLCLI(t *testing.T) {
7676
// c.Run(ctx, `coder urls ls env1 -o json | jq -c '.[] | select( .name == "foobar")'`).Assert(t,
7777
// tcli.Error(),
7878
// jsonUnmarshals(&durl))
79-
8079
}

‎ci/integration/envs_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"github.com/google/go-cmp/cmp"
1818
)
1919

20-
funccleanupClient(t*testing.T,ctx context.Context)*coder.Client {
20+
funccleanupClient(ctx context.Context,t*testing.T)*coder.Client {
2121
creds:=login(ctx,t)
2222

2323
u,err:=url.Parse(creds.url)
@@ -41,7 +41,7 @@ func TestEnvsCLI(t *testing.T) {
4141

4242
run(t,"coder-cli-env-tests",func(t*testing.T,ctx context.Context,c*tcli.ContainerRunner) {
4343
headlessLogin(ctx,t,c)
44-
client:=cleanupClient(t,ctx)
44+
client:=cleanupClient(ctx,t)
4545

4646
// Minimum args not received.
4747
c.Run(ctx,"coder envs create").Assert(t,
@@ -101,7 +101,7 @@ func TestEnvsCLI(t *testing.T) {
101101

102102
run(t,"coder-cli-env-edit-tests",func(t*testing.T,ctx context.Context,c*tcli.ContainerRunner) {
103103
headlessLogin(ctx,t,c)
104-
client:=cleanupClient(t,ctx)
104+
client:=cleanupClient(ctx,t)
105105

106106
name:=randString(10)
107107
c.Run(ctx,fmt.Sprintf("coder envs create %s --image ubuntu --follow",name)).Assert(t,

‎ci/integration/integration_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ func TestCoderCLI(t *testing.T) {
8080
tcli.Error(),
8181
)
8282
})
83-
8483
}
8584

8685
varseededRand=rand.New(rand.NewSource(time.Now().UnixNano()))

‎ci/steps/unit_test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ cd "$(git rev-parse --show-toplevel)"
66

77
echo"--- go test..."
88

9-
gotest$(go list ./...| grep -v pkg/tcli| grep -v ci/integration)
9+
gotest$(go list ./...| grep -v pkg/tcli| grep -v ci/integration| grep -v coder-sdk)

‎coder-sdk/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ type ConfigOAuth struct {
5858

5959
func (cClient)SiteConfigAuth(ctx context.Context) (*ConfigAuth,error) {
6060
varconfConfigAuth
61-
iferr:=c.requestBody(ctx,http.MethodGet,"/api/auth/config",nil,&c);err!=nil {
61+
iferr:=c.requestBody(ctx,http.MethodGet,"/api/auth/config",nil,&conf);err!=nil {
6262
returnnil,err
6363
}
6464
return&conf,nil
@@ -117,5 +117,5 @@ func (c Client) SiteConfigExtensionMarketplace(ctx context.Context) (*ConfigExte
117117
}
118118

119119
func (cClient)PutSiteConfigExtensionMarketplace(ctx context.Context,reqConfigExtensionMarketplace)error {
120-
returnc.requestBody(ctx,http.MethodGet,"/api/extensions/config",req,nil)
120+
returnc.requestBody(ctx,http.MethodPut,"/api/extensions/config",req,nil)
121121
}

‎coder-sdk/config_test.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package coder_test
2+
3+
import (
4+
"context"
5+
"net/url"
6+
"os"
7+
"testing"
8+
"time"
9+
10+
"cdr.dev/coder-cli/coder-sdk"
11+
"cdr.dev/slog"
12+
"cdr.dev/slog/sloggers/slogtest"
13+
"cdr.dev/slog/sloggers/slogtest/assert"
14+
)
15+
16+
funcnewClient(t*testing.T)*coder.Client {
17+
token:=os.Getenv("CODER_TOKEN")
18+
iftoken=="" {
19+
slogtest.Fatal(t,`"CODER_TOKEN" env var is empty`)
20+
}
21+
raw:=os.Getenv("CODER_URL")
22+
u,err:=url.Parse(raw)
23+
iferr!=nil {
24+
slogtest.Fatal(t,`"CODER_URL" env var is invalid`,slog.Error(err))
25+
}
26+
27+
return&coder.Client{
28+
BaseURL:u,
29+
Token:token,
30+
}
31+
}
32+
33+
funcTestConfig(t*testing.T) {
34+
t.Parallel()
35+
ctx,cancel:=context.WithTimeout(context.Background(),5*time.Minute)
36+
defercancel()
37+
38+
client:=newClient(t)
39+
40+
version,err:=client.APIVersion(ctx)
41+
assert.Success(t,"get api version",err)
42+
slogtest.Info(t,"got api version",slog.F("version",version))
43+
44+
authConfig,err:=client.SiteConfigAuth(ctx)
45+
assert.Success(t,"auth config",err)
46+
slogtest.Info(t,"got site auth config",slog.F("config",authConfig))
47+
48+
oauthConf,err:=client.SiteConfigOAuth(ctx)
49+
assert.Success(t,"auth config",err)
50+
slogtest.Info(t,"got site oauth config",slog.F("config",oauthConf))
51+
52+
putOAuth:=&coder.ConfigOAuth{
53+
GitHub: coder.ConfigOAuthGitHub{
54+
BaseURL:"github.com",
55+
ClientID:"fake client id",
56+
ClientSecret:"fake secrets",
57+
},
58+
}
59+
60+
err=client.PutSiteConfigOAuth(ctx,*putOAuth)
61+
assert.Success(t,"put site oauth",err)
62+
63+
oauthConf,err=client.SiteConfigOAuth(ctx)
64+
assert.Success(t,"auth config",err)
65+
assert.Equal(t,"oauth was updated",putOAuth,oauthConf)
66+
}

‎coder-sdk/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Package coder provides simple APIs for integrating Go applications with Coder Enterprise.
2+
package coder

‎coder-sdk/secrets.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,10 @@ func (c *Client) DeleteSecretByName(ctx context.Context, name, userID string) er
8787
// Delete the secret.
8888
// NOTE: This is racy, but acceptable. If the secret is gone or the permission changed since we looked up the id,
8989
// the call will simply fail and surface the error to the user.
90-
if_,err:=c.request(ctx,http.MethodDelete,"/api/users/"+userID+"/secrets/"+secret.ID,nil);err!=nil {
90+
resp,err:=c.request(ctx,http.MethodDelete,"/api/users/"+userID+"/secrets/"+secret.ID,nil)
91+
iferr!=nil {
9192
returnerr
9293
}
94+
deferresp.Body.Close()
9395
returnnil
9496
}

‎coder-sdk/version.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ func (c Client) APIVersion(ctx context.Context) (string, error) {
1212
iferr!=nil {
1313
return"",err
1414
}
15+
deferresp.Body.Close()
1516

1617
version:=resp.Header.Get(coderVersionHeaderKey)
1718
ifversion=="" {

‎internal/cmd/auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func newClient(ctx context.Context) (*coder.Client, error) {
4444

4545
u,err:=url.Parse(rawURL)
4646
iferr!=nil {
47-
returnnil,xerrors.Errorf("url malformed: %w tryruning\"coder login\" with a valid URL",err)
47+
returnnil,xerrors.Errorf("url malformed: %w tryrunning\"coder login\" with a valid URL",err)
4848
}
4949

5050
c:=&coder.Client{

‎internal/cmd/configssh.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func writeSSHKey(ctx context.Context, client *coder.Client, privateKeyPath strin
153153
funcmakeNewConfigs(userNamestring,envs []coder.Environment,startToken,startMsg,endToken,privateKeyFilepathstring) (string,error) {
154154
hostname,err:=configuredHostname()
155155
iferr!=nil {
156-
return"",nil
156+
return"",err
157157
}
158158

159159
newConfig:=fmt.Sprintf("\n%s\n%s\n\n",startToken,startMsg)

‎internal/cmd/envs.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ func envsCmd() *cobra.Command {
3838
returncmd
3939
}
4040

41+
const (
42+
humanOutput="human"
43+
jsonOutput="json"
44+
)
45+
4146
funclsEnvsCommand(user*string)*cobra.Command {
4247
varoutputFmtstring
4348

@@ -61,14 +66,14 @@ func lsEnvsCommand(user *string) *cobra.Command {
6166
}
6267

6368
switchoutputFmt {
64-
case"human":
69+
casehumanOutput:
6570
err:=tablewriter.WriteTable(len(envs),func(iint)interface{} {
6671
returnenvs[i]
6772
})
6873
iferr!=nil {
6974
returnxerrors.Errorf("write table: %w",err)
7075
}
71-
case"json":
76+
casejsonOutput:
7277
err:=json.NewEncoder(os.Stdout).Encode(envs)
7378
iferr!=nil {
7479
returnxerrors.Errorf("write environments as JSON: %w",err)
@@ -80,7 +85,7 @@ func lsEnvsCommand(user *string) *cobra.Command {
8085
},
8186
}
8287

83-
cmd.Flags().StringVarP(&outputFmt,"output","o","human","human | json")
88+
cmd.Flags().StringVarP(&outputFmt,"output","o",humanOutput,"human | json")
8489

8590
returncmd
8691
}

‎internal/cmd/shell.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func runCommand(ctx context.Context, envName, command string, args []string) err
166166
iferr!=nil {
167167
varcloseErr websocket.CloseError
168168
ifxerrors.As(err,&closeErr) {
169-
returnnetworkErr(client,env)
169+
returnnetworkErr(env)
170170
}
171171
returnxerrors.Errorf("start remote command: %w",err)
172172
}
@@ -200,14 +200,14 @@ func runCommand(ctx context.Context, envName, command string, args []string) err
200200
iferr:=process.Wait();err!=nil {
201201
varcloseErr websocket.CloseError
202202
ifxerrors.Is(err,ctx.Err())||xerrors.As(err,&closeErr) {
203-
returnnetworkErr(client,env)
203+
returnnetworkErr(env)
204204
}
205205
returnerr
206206
}
207207
returnnil
208208
}
209209

210-
funcnetworkErr(client*coder.Client,env*coder.Environment)error {
210+
funcnetworkErr(env*coder.Environment)error {
211211
ifenv.LatestStat.ContainerStatus!=coder.EnvironmentOn {
212212
returnclog.Fatal(
213213
"environment is not running",

‎internal/cmd/urls.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func urlCmd() *cobra.Command {
3131
ValidArgsFunction:getEnvsForCompletion(coder.Me),
3232
RunE:listDevURLsCmd(&outputFmt),
3333
}
34-
lsCmd.Flags().StringVarP(&outputFmt,"output","o","human","human|json")
34+
lsCmd.Flags().StringVarP(&outputFmt,"output","o",humanOutput,"human|json")
3535

3636
rmCmd:=&cobra.Command{
3737
Use:"rm [environment_name] [port]",
@@ -99,7 +99,7 @@ func listDevURLsCmd(outputFmt *string) func(cmd *cobra.Command, args []string) e
9999
}
100100

101101
switch*outputFmt {
102-
case"human":
102+
casehumanOutput:
103103
iflen(devURLs)<1 {
104104
clog.LogInfo(fmt.Sprintf("no devURLs found for environment %q",envName))
105105
returnnil
@@ -110,7 +110,7 @@ func listDevURLsCmd(outputFmt *string) func(cmd *cobra.Command, args []string) e
110110
iferr!=nil {
111111
returnxerrors.Errorf("write table: %w",err)
112112
}
113-
case"json":
113+
casejsonOutput:
114114
iferr:=json.NewEncoder(os.Stdout).Encode(devURLs);err!=nil {
115115
returnxerrors.Errorf("encode DevURLs as json: %w",err)
116116
}
@@ -263,7 +263,12 @@ func urlList(ctx context.Context, envName string) ([]DevURL, error) {
263263
reqString:="%s/api/environments/%s/devurls?session_token=%s"
264264
reqURL:=fmt.Sprintf(reqString,client.BaseURL,env.ID,client.Token)
265265

266-
resp,err:=http.Get(reqURL)
266+
req,err:=http.NewRequestWithContext(ctx,http.MethodGet,reqURL,nil)
267+
iferr!=nil {
268+
returnnil,err
269+
}
270+
271+
resp,err:=http.DefaultClient.Do(req)
267272
iferr!=nil {
268273
returnnil,err
269274
}

‎internal/cmd/users.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func usersCmd() *cobra.Command {
2323
coder users ls -o json | jq .[] | jq -r .email`,
2424
RunE:listUsers(&outputFmt),
2525
}
26-
lsCmd.Flags().StringVarP(&outputFmt,"output","o","human","human | json")
26+
lsCmd.Flags().StringVarP(&outputFmt,"output","o",humanOutput,"human | json")
2727

2828
cmd.AddCommand(lsCmd)
2929
returncmd
@@ -43,7 +43,7 @@ func listUsers(outputFmt *string) func(cmd *cobra.Command, args []string) error
4343
}
4444

4545
switch*outputFmt {
46-
case"human":
46+
casehumanOutput:
4747
// For each element, return the user.
4848
each:=func(iint)interface{} {returnusers[i] }
4949
iferr:=tablewriter.WriteTable(len(users),each);err!=nil {

‎internal/sync/eventcache.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ func (cache eventCache) SequentialEvents() []timedEvent {
4040
// Include files that have deleted here.
4141
// It's unclear whether they're files or folders.
4242
r=append(r,ev)
43-
4443
}
4544
returnr
4645
}
@@ -58,7 +57,6 @@ func (cache eventCache) ConcurrentEvents() []timedEvent {
5857
continue
5958
}
6059
r=append(r,ev)
61-
6260
}
6361
returnr
6462
}

‎internal/x/xterminal/terminal.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func ResizeEvents(ctx context.Context, termFD uintptr) chan ResizeEvent {
6262
signal.Notify(sigChan,unix.SIGWINCH)
6363
defersignal.Stop(sigChan)
6464

65-
// Emit aninital signal event to make sure the server receives our current window size.
65+
// Emit aninitial signal event to make sure the server receives our current window size.
6666
select {
6767
case<-ctx.Done():
6868
return
@@ -87,7 +87,6 @@ func ResizeEvents(ctx context.Context, termFD uintptr) chan ResizeEvent {
8787
return
8888
caseevents<-event:
8989
}
90-
9190
}
9291
}
9392
}()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp