Skip to content

Commit 2ca2a77

Browse files
committed
fix gocritic linter
Signed-off-by: Tim Ramlot <[email protected]>
1 parent c72a218 commit 2ca2a77

File tree

6 files changed

+16
-14
lines changed

6 files changed

+16
-14
lines changed

.golangci.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ linters:
88
- linters:
99
- errchkjson
1010
- forbidigo
11-
- gocritic
1211
- gosec
1312
- govet
1413
- musttag

pkg/agent/config.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -750,14 +750,15 @@ func validateCredsAndCreateClient(log logr.Logger, flagCredentialsPath, flagClie
750750
break
751751
}
752752

753-
if flagClientID != "" && flagPrivateKeyPath != "" {
753+
switch {
754+
case flagClientID != "" && flagPrivateKeyPath != "":
754755
// If --client-id and --private-key-path are passed, then
755756
// --credentials-file is ignored.
756757
creds = &client.VenafiSvcAccountCredentials{
757758
ClientID: flagClientID,
758759
PrivateKeyFile: flagPrivateKeyPath,
759760
}
760-
} else if flagCredentialsPath != "" {
761+
case flagCredentialsPath != "":
761762
credsBytes, err := readCredentialsFile(flagCredentialsPath)
762763
if err != nil {
763764
errs = multierror.Append(errs, multierror.Prefix(err, "credentials file:"))
@@ -768,7 +769,7 @@ func validateCredsAndCreateClient(log logr.Logger, flagCredentialsPath, flagClie
768769
errs = multierror.Append(errs, multierror.Prefix(err, "credentials file:"))
769770
break // Don't continue with the client since creds is invalid.
770771
}
771-
} else {
772+
default:
772773
return nil, fmt.Errorf("programmer mistake: --client-id and --private-key-path or --credentials-file must have been provided")
773774
}
774775

pkg/client/client_venafi_cloud.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ type (
7171
}
7272

7373
accessTokenInformation struct {
74-
AccessToken string `json:"access_token"` //base 64 encoded token
74+
AccessToken string `json:"access_token"` // base 64 encoded token
7575
Type string `json:"token_type"` // always be “bearer” for now
7676
ExpiresIn int64 `json:"expires_in"` // number of seconds after which the access token will expire
7777
}

pkg/datagatherer/k8s/dynamic.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ func (g *DataGathererDynamic) Fetch() (interface{}, int, error) {
329329
fetchNamespaces = []string{metav1.NamespaceAll}
330330
}
331331

332-
//delete expired items from the cache
332+
// delete expired items from the cache
333333
g.cache.DeleteExpired()
334334
for _, item := range g.cache.Items() {
335335
// filter cache items by namespace

pkg/datagatherer/k8s/dynamic_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ func TestDynamicGatherer_Fetch(t *testing.T) {
678678
},
679679
})
680680
require.NoError(t, err)
681-
//start test Informer
681+
// start test Informer
682682
factory.Start(ctx.Done())
683683
k8scache.WaitForCacheSync(ctx.Done(), testInformer.HasSynced)
684684

@@ -996,7 +996,7 @@ func TestDynamicGathererNativeResources_Fetch(t *testing.T) {
996996
})
997997
require.NoError(t, err)
998998

999-
//start test Informer
999+
// start test Informer
10001000
factory.Start(ctx.Done())
10011001
k8scache.WaitForCacheSync(ctx.Done(), testInformer.HasSynced)
10021002
dgd := dg.(*DataGathererDynamic)

pkg/testutil/envtest.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,16 +206,17 @@ func FakeVenafiCloud(t *testing.T) (_ *httptest.Server, _ *x509.Certificate, set
206206
_, _ = w.Write([]byte(`{"error":"expected header 'Authorization: Bearer VALID_ACCESS_TOKEN' or 'tppl-api-key: VALID_API_KEY', but got Authorization=` + r.Header.Get("Authorization") + ` and tppl-api-key=` + r.Header.Get("Tppl-Api-Key")))
207207
return
208208
}
209-
if r.URL.Path == "/v1/tlspk/upload/clusterdata/no" {
209+
switch r.URL.Path {
210+
case "/v1/tlspk/upload/clusterdata/no":
210211
if r.URL.Query().Get("name") != "test cluster name" {
211212
w.WriteHeader(http.StatusBadRequest)
212213
_, _ = w.Write([]byte(`{"error":"unexpected name query param in the test server: ` + r.URL.Query().Get("name") + `, expected: 'test cluster name'"}`))
213214
return
214215
}
215216
_, _ = w.Write([]byte(`{"status":"ok","organization":"756db001-280e-11ee-84fb-991f3177e2d0"}`))
216-
} else if r.URL.Path == "/v1/useraccounts" {
217+
case "/v1/useraccounts":
217218
_, _ = w.Write([]byte(`{"user": {"username": "user","id": "76a126f0-280e-11ee-84fb-991f3177e2d0"}}`))
218-
} else {
219+
default:
219220
w.WriteHeader(http.StatusInternalServerError)
220221
_, _ = w.Write([]byte(`{"error":"unexpected path in the test server","path":"` + r.URL.Path + `"}`))
221222
}
@@ -236,15 +237,16 @@ func FakeTPP(t testing.TB) (*httptest.Server, *x509.Certificate) {
236237

237238
accessToken := strings.TrimPrefix(r.Header.Get("Authorization"), "Bearer ")
238239

239-
if r.URL.Path == "/vedsdk/Identity/Self" {
240+
switch r.URL.Path {
241+
case "/vedsdk/Identity/Self":
240242
if accessToken != "VALID_ACCESS_TOKEN" {
241243
w.WriteHeader(http.StatusUnauthorized)
242244
return
243245
}
244246
_, _ = w.Write([]byte(`{"Identities":[{"Name":"TEST"}]}`))
245-
} else if r.URL.Path == "/vedsdk/certificates/checkpolicy" {
247+
case "/vedsdk/certificates/checkpolicy":
246248
_, _ = w.Write([]byte(`{"Policy":{"Subject":{"Organization":{"Value": "test-org"}}}}`))
247-
} else {
249+
default:
248250
w.WriteHeader(http.StatusInternalServerError)
249251
_, _ = w.Write([]byte(`{"error":"unexpected path in the test server","path":"` + r.URL.Path + `"}`))
250252
}

0 commit comments

Comments
 (0)