Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit c9be4a5

Browse files
authored
Merge pull request #24 from keybase/david/golangci-lint
Add golangci-lint for more linting goodness
2 parents 785de08 + a6d0b58 commit c9be4a5

8 files changed

Lines changed: 42 additions & 12 deletions

File tree

.circleci/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ jobs:
2424
- run: go get golang.org/x/tools/cmd/goimports
2525
- run: "! goimports ./... 2>&1 | read"
2626
- run: "! go mod tidy ./... 2>&1 | read"
27+
- run: go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.17.1
28+
- run: "! golangci-lint 2>&1 | read"
2729
workflows:
2830
version: 2
2931
build:

.golangci.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
linters-settings:
2+
gocritic:
3+
disabled-checks:
4+
- ifElseChain
5+
- elseif
6+
7+
linters:
8+
enable:
9+
- gofmt
10+
- gocritic
11+
- unconvert
12+
- goconst
13+
- gocyclo
14+
- misspell
15+
- unparam
16+
- golint

.pre-commit-config.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
repos:
22
- repo: https://github.com/keybase/pre-commit-golang
3-
rev: b8194ff9d85455a702480677ada13ac4dbe94146
3+
rev: 314766a2c26b7f32641addbdb0e7e451320ff1f0
44
hooks:
55
- id: go-fmt
66
- id: go-vet
77
- id: go-lint
8+
- id: golangci-lint
89
- repo: https://github.com/troian/pre-commit-golang
910
rev: ab57c5db44bbeeae1031a2e9c2889367f8387d59
1011
hooks:
@@ -13,3 +14,7 @@ repos:
1314
rev: f16f18866390cba642e8af6073ed59504aeada5c
1415
hooks:
1516
- id: go-mod-tidy
17+
- repo: https://github.com/golangci/golangci-lint
18+
rev: v1.17.1
19+
hooks:
20+
- id: golangci-lint

src/cmd/keybaseca/keybaseca.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func backupAction(c *cli.Context) error {
9898
return err
9999
}
100100
if response != "yes" {
101-
return fmt.Errorf("Did not get confirmation of key export, aborting...")
101+
return fmt.Errorf("Did not get confirmation of key export, aborting")
102102
}
103103

104104
conf, err := loadServerConfig()
@@ -118,12 +118,11 @@ func backupAction(c *cli.Context) error {
118118

119119
// The action for the `keybaseca generate` subcommand
120120
func generateAction(c *cli.Context) error {
121-
conf, err := loadServerConfigAndWriteClientConfig()
121+
conf, err := loadServerConfig()
122122
if err != nil {
123123
return err
124124
}
125125
captureControlCToDeleteClientConfig(conf)
126-
defer deleteClientConfig(conf)
127126
err = sshutils.Generate(conf, c.Bool("overwrite-existing-key") || os.Getenv("FORCE_WRITE") == "true")
128127
if err != nil {
129128
return fmt.Errorf("Failed to generate a new key: %v", err)
@@ -138,12 +137,11 @@ func serviceAction(c *cli.Context) error {
138137
return err
139138
}
140139
captureControlCToDeleteClientConfig(conf)
141-
defer deleteClientConfig(conf)
142140
err = bot.StartBot(conf)
143141
if err != nil {
144142
return fmt.Errorf("CA chatbot crashed: %v", err)
145143
}
146-
return nil
144+
return deleteClientConfig(conf)
147145
}
148146

149147
// The action for the `keybaseca sign` subcommand

src/cmd/kssh/kssh.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,14 @@ func getConfig(botname string) (kssh.ConfigFile, error) {
246246
// No specified bot and no default bot, fallback and load all the configs
247247
configs, botnames, err := kssh.LoadConfigs()
248248
if err != nil {
249-
return empty, fmt.Errorf("Failed to load config file(s): %v\n", err)
249+
return empty, fmt.Errorf("Failed to load config file(s): %v", err)
250250
}
251-
if len(configs) == 0 {
251+
switch len(configs) {
252+
case 0:
252253
return empty, fmt.Errorf("Did not find any config files in KBFS (is `keybaseca service` running?)")
253-
} else if len(configs) == 1 {
254+
case 1:
254255
return configs[0], nil
255-
} else {
256+
default:
256257
noDefaultTeamMessage := fmt.Sprintf("Found %v config files (%s). No default bot is configured. \n"+
257258
"Either specify a team via `kssh --bot cabotname` or set a default bot via `kssh --set-default-bot cabotname`", len(configs), strings.Join(botnames, ", "))
258259
return empty, fmt.Errorf(noDefaultTeamMessage)

src/cmd/kssh/kssh_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func BenchmarkLoadConfigs(b *testing.B) {
4949
b.ResetTimer()
5050

5151
for n := 0; n < b.N; n++ {
52-
getConfig("")
52+
_, err := getConfig("")
53+
require.NoError(b, err)
5354
}
5455
}

src/keybaseca/config/config.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,11 @@ func validatePath(path string) error {
101101
if err != nil {
102102
return fmt.Errorf("path is not writable: %v", err)
103103
}
104-
constants.GetDefaultKBFSOperationsStruct().KBFSDelete(path)
104+
105+
err = constants.GetDefaultKBFSOperationsStruct().KBFSDelete(path)
106+
if err != nil {
107+
return fmt.Errorf("failed to delete temp file: %v", err)
108+
}
105109
return nil
106110
}
107111
_, err := os.Stat(path)

src/keybaseca/sshutils/sshutils.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ func ProcessSignatureRequest(conf config.Config, sr shared.SignatureRequest) (re
9292
log.Log(conf, fmt.Sprintf("Processing SignatureRequest from user=%s on device='%s' keyID:%s, principals:%s, expiration:%s, pubkey:%s",
9393
sr.Username, sr.DeviceName, keyID, principals, conf.GetKeyExpiration(), sr.SSHPublicKey))
9494
signature, err := SignKey(conf.GetCAKeyLocation(), keyID, principals, conf.GetKeyExpiration(), sr.SSHPublicKey)
95+
if err != nil {
96+
return
97+
}
9598

9699
return shared.SignatureResponse{SignedKey: signature, UUID: sr.UUID}, nil
97100
}

0 commit comments

Comments
 (0)