Skip to content

Commit dbef0bf

Browse files
authored
fix: golangci-lint staticcheck errors (#22640)
* fix: golangci-lint staticcheck errors * fix: remove unused imports
1 parent f9ada9b commit dbef0bf

File tree

73 files changed

+176
-205
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+176
-205
lines changed

acl/authorizer.go

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,15 @@ type AllowAuthorizer struct {
205205

206206
// ACLReadAllowed checks for permission to list all the ACLs
207207
func (a AllowAuthorizer) ACLReadAllowed(ctx *AuthorizerContext) error {
208-
if a.Authorizer.ACLRead(ctx) != Allow {
208+
if a.ACLRead(ctx) != Allow {
209209
return PermissionDeniedByACLUnnamed(a, ctx, ResourceACL, AccessRead)
210210
}
211211
return nil
212212
}
213213

214214
// ACLWriteAllowed checks for permission to manipulate ACLs
215215
func (a AllowAuthorizer) ACLWriteAllowed(ctx *AuthorizerContext) error {
216-
if a.Authorizer.ACLWrite(ctx) != Allow {
216+
if a.ACLWrite(ctx) != Allow {
217217
return PermissionDeniedByACLUnnamed(a, ctx, ResourceACL, AccessWrite)
218218
}
219219
return nil
@@ -222,7 +222,7 @@ func (a AllowAuthorizer) ACLWriteAllowed(ctx *AuthorizerContext) error {
222222
// AgentReadAllowed checks for permission to read from agent endpoints for a
223223
// given node.
224224
func (a AllowAuthorizer) AgentReadAllowed(name string, ctx *AuthorizerContext) error {
225-
if a.Authorizer.AgentRead(name, ctx) != Allow {
225+
if a.AgentRead(name, ctx) != Allow {
226226
return PermissionDeniedByACL(a, ctx, ResourceAgent, AccessRead, name)
227227
}
228228
return nil
@@ -231,31 +231,31 @@ func (a AllowAuthorizer) AgentReadAllowed(name string, ctx *AuthorizerContext) e
231231
// AgentWriteAllowed checks for permission to make changes via agent endpoints
232232
// for a given node.
233233
func (a AllowAuthorizer) AgentWriteAllowed(name string, ctx *AuthorizerContext) error {
234-
if a.Authorizer.AgentWrite(name, ctx) != Allow {
234+
if a.AgentWrite(name, ctx) != Allow {
235235
return PermissionDeniedByACL(a, ctx, ResourceAgent, AccessWrite, name)
236236
}
237237
return nil
238238
}
239239

240240
// EventReadAllowed determines if a specific event can be queried.
241241
func (a AllowAuthorizer) EventReadAllowed(name string, ctx *AuthorizerContext) error {
242-
if a.Authorizer.EventRead(name, ctx) != Allow {
242+
if a.EventRead(name, ctx) != Allow {
243243
return PermissionDeniedByACL(a, ctx, ResourceEvent, AccessRead, name)
244244
}
245245
return nil
246246
}
247247

248248
// EventWriteAllowed determines if a specific event may be fired.
249249
func (a AllowAuthorizer) EventWriteAllowed(name string, ctx *AuthorizerContext) error {
250-
if a.Authorizer.EventWrite(name, ctx) != Allow {
250+
if a.EventWrite(name, ctx) != Allow {
251251
return PermissionDeniedByACL(a, ctx, ResourceEvent, AccessWrite, name)
252252
}
253253
return nil
254254
}
255255

256256
// IntentionReadAllowed determines if a specific intention can be read.
257257
func (a AllowAuthorizer) IntentionReadAllowed(name string, ctx *AuthorizerContext) error {
258-
if a.Authorizer.IntentionRead(name, ctx) != Allow {
258+
if a.IntentionRead(name, ctx) != Allow {
259259
return PermissionDeniedByACL(a, ctx, ResourceIntention, AccessRead, name)
260260
}
261261
return nil
@@ -264,15 +264,15 @@ func (a AllowAuthorizer) IntentionReadAllowed(name string, ctx *AuthorizerContex
264264
// IntentionWriteAllowed determines if a specific intention can be
265265
// created, modified, or deleted.
266266
func (a AllowAuthorizer) IntentionWriteAllowed(name string, ctx *AuthorizerContext) error {
267-
if a.Authorizer.IntentionWrite(name, ctx) != Allow {
267+
if a.IntentionWrite(name, ctx) != Allow {
268268
return PermissionDeniedByACL(a, ctx, ResourceIntention, AccessWrite, name)
269269
}
270270
return nil
271271
}
272272

273273
// TrafficPermissionsReadAllowed determines if specific traffic permissions can be read.
274274
func (a AllowAuthorizer) TrafficPermissionsReadAllowed(name string, ctx *AuthorizerContext) error {
275-
if a.Authorizer.TrafficPermissionsRead(name, ctx) != Allow {
275+
if a.TrafficPermissionsRead(name, ctx) != Allow {
276276
return PermissionDeniedByACL(a, ctx, ResourceIntention, AccessRead, name)
277277
}
278278
return nil
@@ -281,31 +281,31 @@ func (a AllowAuthorizer) TrafficPermissionsReadAllowed(name string, ctx *Authori
281281
// TrafficPermissionsWriteAllowed determines if specific traffic permissions can be
282282
// created, modified, or deleted.
283283
func (a AllowAuthorizer) TrafficPermissionsWriteAllowed(name string, ctx *AuthorizerContext) error {
284-
if a.Authorizer.TrafficPermissionsWrite(name, ctx) != Allow {
284+
if a.TrafficPermissionsWrite(name, ctx) != Allow {
285285
return PermissionDeniedByACL(a, ctx, ResourceIntention, AccessWrite, name)
286286
}
287287
return nil
288288
}
289289

290290
// KeyListAllowed checks for permission to list keys under a prefix
291291
func (a AllowAuthorizer) KeyListAllowed(name string, ctx *AuthorizerContext) error {
292-
if a.Authorizer.KeyList(name, ctx) != Allow {
292+
if a.KeyList(name, ctx) != Allow {
293293
return PermissionDeniedByACL(a, ctx, ResourceKey, AccessList, name)
294294
}
295295
return nil
296296
}
297297

298298
// KeyReadAllowed checks for permission to read a given key
299299
func (a AllowAuthorizer) KeyReadAllowed(name string, ctx *AuthorizerContext) error {
300-
if a.Authorizer.KeyRead(name, ctx) != Allow {
300+
if a.KeyRead(name, ctx) != Allow {
301301
return PermissionDeniedByACL(a, ctx, ResourceKey, AccessRead, name)
302302
}
303303
return nil
304304
}
305305

306306
// KeyWriteAllowed checks for permission to write a given key
307307
func (a AllowAuthorizer) KeyWriteAllowed(name string, ctx *AuthorizerContext) error {
308-
if a.Authorizer.KeyWrite(name, ctx) != Allow {
308+
if a.KeyWrite(name, ctx) != Allow {
309309
return PermissionDeniedByACL(a, ctx, ResourceKey, AccessWrite, name)
310310
}
311311
return nil
@@ -315,7 +315,7 @@ func (a AllowAuthorizer) KeyWriteAllowed(name string, ctx *AuthorizerContext) er
315315
// entire key prefix. This means there must be no sub-policies
316316
// that deny a write.
317317
func (a AllowAuthorizer) KeyWritePrefixAllowed(name string, ctx *AuthorizerContext) error {
318-
if a.Authorizer.KeyWritePrefix(name, ctx) != Allow {
318+
if a.KeyWritePrefix(name, ctx) != Allow {
319319
// TODO(acl-error-enhancements) revisit this message; we may need to do some extra plumbing inside of KeyWritePrefix to
320320
// return properly detailed information.
321321
return PermissionDeniedByACL(a, ctx, ResourceKey, AccessWrite, name)
@@ -326,15 +326,15 @@ func (a AllowAuthorizer) KeyWritePrefixAllowed(name string, ctx *AuthorizerConte
326326
// KeyringReadAllowed determines if the encryption keyring used in
327327
// the gossip layer can be read.
328328
func (a AllowAuthorizer) KeyringReadAllowed(ctx *AuthorizerContext) error {
329-
if a.Authorizer.KeyringRead(ctx) != Allow {
329+
if a.KeyringRead(ctx) != Allow {
330330
return PermissionDeniedByACLUnnamed(a, ctx, ResourceKeyring, AccessRead)
331331
}
332332
return nil
333333
}
334334

335335
// KeyringWriteAllowed determines if the keyring can be manipulated
336336
func (a AllowAuthorizer) KeyringWriteAllowed(ctx *AuthorizerContext) error {
337-
if a.Authorizer.KeyringWrite(ctx) != Allow {
337+
if a.KeyringWrite(ctx) != Allow {
338338
return PermissionDeniedByACLUnnamed(a, ctx, ResourceKeyring, AccessWrite)
339339
}
340340
return nil
@@ -343,7 +343,7 @@ func (a AllowAuthorizer) KeyringWriteAllowed(ctx *AuthorizerContext) error {
343343
// MeshReadAllowed determines if the read-only Consul mesh functions
344344
// can be used.
345345
func (a AllowAuthorizer) MeshReadAllowed(ctx *AuthorizerContext) error {
346-
if a.Authorizer.MeshRead(ctx) != Allow {
346+
if a.MeshRead(ctx) != Allow {
347347
return PermissionDeniedByACLUnnamed(a, ctx, ResourceMesh, AccessRead)
348348
}
349349
return nil
@@ -352,7 +352,7 @@ func (a AllowAuthorizer) MeshReadAllowed(ctx *AuthorizerContext) error {
352352
// MeshWriteAllowed determines if the state-changing Consul mesh
353353
// functions can be used.
354354
func (a AllowAuthorizer) MeshWriteAllowed(ctx *AuthorizerContext) error {
355-
if a.Authorizer.MeshWrite(ctx) != Allow {
355+
if a.MeshWrite(ctx) != Allow {
356356
return PermissionDeniedByACLUnnamed(a, ctx, ResourceMesh, AccessWrite)
357357
}
358358
return nil
@@ -361,7 +361,7 @@ func (a AllowAuthorizer) MeshWriteAllowed(ctx *AuthorizerContext) error {
361361
// PeeringReadAllowed determines if the read-only Consul peering functions
362362
// can be used.
363363
func (a AllowAuthorizer) PeeringReadAllowed(ctx *AuthorizerContext) error {
364-
if a.Authorizer.PeeringRead(ctx) != Allow {
364+
if a.PeeringRead(ctx) != Allow {
365365
return PermissionDeniedByACLUnnamed(a, ctx, ResourcePeering, AccessRead)
366366
}
367367
return nil
@@ -370,23 +370,23 @@ func (a AllowAuthorizer) PeeringReadAllowed(ctx *AuthorizerContext) error {
370370
// PeeringWriteAllowed determines if the state-changing Consul peering
371371
// functions can be used.
372372
func (a AllowAuthorizer) PeeringWriteAllowed(ctx *AuthorizerContext) error {
373-
if a.Authorizer.PeeringWrite(ctx) != Allow {
373+
if a.PeeringWrite(ctx) != Allow {
374374
return PermissionDeniedByACLUnnamed(a, ctx, ResourcePeering, AccessWrite)
375375
}
376376
return nil
377377
}
378378

379379
// NodeReadAllowed checks for permission to read (discover) a given node.
380380
func (a AllowAuthorizer) NodeReadAllowed(name string, ctx *AuthorizerContext) error {
381-
if a.Authorizer.NodeRead(name, ctx) != Allow {
381+
if a.NodeRead(name, ctx) != Allow {
382382
return PermissionDeniedByACL(a, ctx, ResourceNode, AccessRead, name)
383383
}
384384
return nil
385385
}
386386

387387
// NodeReadAllAllowed checks for permission to read (discover) all nodes.
388388
func (a AllowAuthorizer) NodeReadAllAllowed(ctx *AuthorizerContext) error {
389-
if a.Authorizer.NodeReadAll(ctx) != Allow {
389+
if a.NodeReadAll(ctx) != Allow {
390390
// This is only used to gate certain UI functions right now (e.g metrics)
391391
return PermissionDeniedByACL(a, ctx, ResourceNode, AccessRead, "all nodes")
392392
}
@@ -396,7 +396,7 @@ func (a AllowAuthorizer) NodeReadAllAllowed(ctx *AuthorizerContext) error {
396396
// NodeWriteAllowed checks for permission to create or update (register) a
397397
// given node.
398398
func (a AllowAuthorizer) NodeWriteAllowed(name string, ctx *AuthorizerContext) error {
399-
if a.Authorizer.NodeWrite(name, ctx) != Allow {
399+
if a.NodeWrite(name, ctx) != Allow {
400400
return PermissionDeniedByACL(a, ctx, ResourceNode, AccessWrite, name)
401401
}
402402
return nil
@@ -405,7 +405,7 @@ func (a AllowAuthorizer) NodeWriteAllowed(name string, ctx *AuthorizerContext) e
405405
// OperatorReadAllowed determines if the read-only Consul operator functions
406406
// can be used.
407407
func (a AllowAuthorizer) OperatorReadAllowed(ctx *AuthorizerContext) error {
408-
if a.Authorizer.OperatorRead(ctx) != Allow {
408+
if a.OperatorRead(ctx) != Allow {
409409
return PermissionDeniedByACLUnnamed(a, ctx, ResourceOperator, AccessRead)
410410
}
411411
return nil
@@ -414,7 +414,7 @@ func (a AllowAuthorizer) OperatorReadAllowed(ctx *AuthorizerContext) error {
414414
// OperatorWriteAllowed determines if the state-changing Consul operator
415415
// functions can be used.
416416
func (a AllowAuthorizer) OperatorWriteAllowed(ctx *AuthorizerContext) error {
417-
if a.Authorizer.OperatorWrite(ctx) != Allow {
417+
if a.OperatorWrite(ctx) != Allow {
418418
return PermissionDeniedByACLUnnamed(a, ctx, ResourceOperator, AccessWrite)
419419
}
420420
return nil
@@ -423,7 +423,7 @@ func (a AllowAuthorizer) OperatorWriteAllowed(ctx *AuthorizerContext) error {
423423
// PreparedQueryReadAllowed determines if a specific prepared query can be read
424424
// to show its contents (this is not used for execution).
425425
func (a AllowAuthorizer) PreparedQueryReadAllowed(name string, ctx *AuthorizerContext) error {
426-
if a.Authorizer.PreparedQueryRead(name, ctx) != Allow {
426+
if a.PreparedQueryRead(name, ctx) != Allow {
427427
return PermissionDeniedByACL(a, ctx, ResourceQuery, AccessRead, name)
428428
}
429429
return nil
@@ -432,23 +432,23 @@ func (a AllowAuthorizer) PreparedQueryReadAllowed(name string, ctx *AuthorizerCo
432432
// PreparedQueryWriteAllowed determines if a specific prepared query can be
433433
// created, modified, or deleted.
434434
func (a AllowAuthorizer) PreparedQueryWriteAllowed(name string, ctx *AuthorizerContext) error {
435-
if a.Authorizer.PreparedQueryWrite(name, ctx) != Allow {
435+
if a.PreparedQueryWrite(name, ctx) != Allow {
436436
return PermissionDeniedByACL(a, ctx, ResourceQuery, AccessWrite, name)
437437
}
438438
return nil
439439
}
440440

441441
// ServiceReadAllowed checks for permission to read a given service
442442
func (a AllowAuthorizer) ServiceReadAllowed(name string, ctx *AuthorizerContext) error {
443-
if a.Authorizer.ServiceRead(name, ctx) != Allow {
443+
if a.ServiceRead(name, ctx) != Allow {
444444
return PermissionDeniedByACL(a, ctx, ResourceService, AccessRead, name)
445445
}
446446
return nil
447447
}
448448

449449
// ServiceReadAllAllowed checks for permission to read all services
450450
func (a AllowAuthorizer) ServiceReadAllAllowed(ctx *AuthorizerContext) error {
451-
if a.Authorizer.ServiceReadAll(ctx) != Allow {
451+
if a.ServiceReadAll(ctx) != Allow {
452452
// This is only used to gate certain UI functions right now (e.g metrics)
453453
return PermissionDeniedByACL(a, ctx, ResourceService, AccessRead, "all services") // read
454454
}
@@ -457,7 +457,7 @@ func (a AllowAuthorizer) ServiceReadAllAllowed(ctx *AuthorizerContext) error {
457457

458458
// ServiceReadPrefixAllowed checks for permission to read services within the given prefix
459459
func (a AllowAuthorizer) ServiceReadPrefixAllowed(prefix string, ctx *AuthorizerContext) error {
460-
if a.Authorizer.ServiceReadPrefix(prefix, ctx) != Allow {
460+
if a.ServiceReadPrefix(prefix, ctx) != Allow {
461461
return PermissionDeniedByACL(a, ctx, ResourceService, AccessRead, prefix) // read
462462
}
463463
return nil
@@ -466,23 +466,23 @@ func (a AllowAuthorizer) ServiceReadPrefixAllowed(prefix string, ctx *Authorizer
466466
// ServiceWriteAllowed checks for permission to create or update a given
467467
// service
468468
func (a AllowAuthorizer) ServiceWriteAllowed(name string, ctx *AuthorizerContext) error {
469-
if a.Authorizer.ServiceWrite(name, ctx) != Allow {
469+
if a.ServiceWrite(name, ctx) != Allow {
470470
return PermissionDeniedByACL(a, ctx, ResourceService, AccessWrite, name)
471471
}
472472
return nil
473473
}
474474

475475
// ServiceWriteAnyAllowed checks for write permission on any service
476476
func (a AllowAuthorizer) ServiceWriteAnyAllowed(ctx *AuthorizerContext) error {
477-
if a.Authorizer.ServiceWriteAny(ctx) != Allow {
477+
if a.ServiceWriteAny(ctx) != Allow {
478478
return PermissionDeniedByACL(a, ctx, ResourceService, AccessWrite, "any service")
479479
}
480480
return nil
481481
}
482482

483483
// SessionReadAllowed checks for permission to read sessions for a given node.
484484
func (a AllowAuthorizer) SessionReadAllowed(name string, ctx *AuthorizerContext) error {
485-
if a.Authorizer.SessionRead(name, ctx) != Allow {
485+
if a.SessionRead(name, ctx) != Allow {
486486
return PermissionDeniedByACL(a, ctx, ResourceSession, AccessRead, name)
487487
}
488488
return nil
@@ -491,15 +491,15 @@ func (a AllowAuthorizer) SessionReadAllowed(name string, ctx *AuthorizerContext)
491491
// SessionWriteAllowed checks for permission to create sessions for a given
492492
// node.
493493
func (a AllowAuthorizer) SessionWriteAllowed(name string, ctx *AuthorizerContext) error {
494-
if a.Authorizer.SessionWrite(name, ctx) != Allow {
494+
if a.SessionWrite(name, ctx) != Allow {
495495
return PermissionDeniedByACL(a, ctx, ResourceSession, AccessWrite, name)
496496
}
497497
return nil
498498
}
499499

500500
// SnapshotAllowed checks for permission to take and restore snapshots.
501501
func (a AllowAuthorizer) SnapshotAllowed(ctx *AuthorizerContext) error {
502-
if a.Authorizer.Snapshot(ctx) != Allow {
502+
if a.Snapshot(ctx) != Allow {
503503
// Implementation of this currently just checks acl write
504504
return PermissionDeniedByACLUnnamed(a, ctx, ResourceACL, AccessWrite)
505505
}

acl/policy.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,15 @@ func (pr *PolicyRules) Validate(conf *Config) error {
197197
if !isPolicyValid(kp.Policy, true) {
198198
return fmt.Errorf("Invalid key policy: %#v", kp)
199199
}
200-
if err := kp.EnterpriseRule.Validate(kp.Policy, conf); err != nil {
200+
if err := kp.Validate(kp.Policy, conf); err != nil {
201201
return fmt.Errorf("Invalid key enterprise policy: %#v, got error: %v", kp, err)
202202
}
203203
}
204204
for _, kp := range pr.KeyPrefixes {
205205
if !isPolicyValid(kp.Policy, true) {
206206
return fmt.Errorf("Invalid key_prefix policy: %#v", kp)
207207
}
208-
if err := kp.EnterpriseRule.Validate(kp.Policy, conf); err != nil {
208+
if err := kp.Validate(kp.Policy, conf); err != nil {
209209
return fmt.Errorf("Invalid key_prefix enterprise policy: %#v, got error: %v", kp, err)
210210
}
211211
}
@@ -215,15 +215,15 @@ func (pr *PolicyRules) Validate(conf *Config) error {
215215
if !isPolicyValid(np.Policy, false) {
216216
return fmt.Errorf("Invalid node policy: %#v", np)
217217
}
218-
if err := np.EnterpriseRule.Validate(np.Policy, conf); err != nil {
218+
if err := np.Validate(np.Policy, conf); err != nil {
219219
return fmt.Errorf("Invalid node enterprise policy: %#v, got error: %v", np, err)
220220
}
221221
}
222222
for _, np := range pr.NodePrefixes {
223223
if !isPolicyValid(np.Policy, false) {
224224
return fmt.Errorf("Invalid node_prefix policy: %#v", np)
225225
}
226-
if err := np.EnterpriseRule.Validate(np.Policy, conf); err != nil {
226+
if err := np.Validate(np.Policy, conf); err != nil {
227227
return fmt.Errorf("Invalid node_prefix enterprise policy: %#v, got error: %v", np, err)
228228
}
229229
}
@@ -236,7 +236,7 @@ func (pr *PolicyRules) Validate(conf *Config) error {
236236
if sp.Intentions != "" && !isPolicyValid(sp.Intentions, false) {
237237
return fmt.Errorf("Invalid service intentions policy: %#v", sp)
238238
}
239-
if err := sp.EnterpriseRule.Validate(sp.Policy, conf); err != nil {
239+
if err := sp.Validate(sp.Policy, conf); err != nil {
240240
return fmt.Errorf("Invalid service enterprise policy: %#v, got error: %v", sp, err)
241241
}
242242
}
@@ -247,7 +247,7 @@ func (pr *PolicyRules) Validate(conf *Config) error {
247247
if sp.Intentions != "" && !isPolicyValid(sp.Intentions, false) {
248248
return fmt.Errorf("Invalid service_prefix intentions policy: %#v", sp)
249249
}
250-
if err := sp.EnterpriseRule.Validate(sp.Policy, conf); err != nil {
250+
if err := sp.Validate(sp.Policy, conf); err != nil {
251251
return fmt.Errorf("Invalid service_prefix enterprise policy: %#v, got error: %v", sp, err)
252252
}
253253
}

acl/policy_authorizer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ func newPolicyAuthorizerFromRules(rules *PolicyRules, ent *Config) (*policyAutho
362362
preparedQueryRules: radix.New(),
363363
}
364364

365-
p.enterprisePolicyAuthorizer.init(ent)
365+
p.init(ent)
366366

367367
if err := p.loadRules(rules); err != nil {
368368
return nil, err
@@ -610,7 +610,7 @@ func (p *policyAuthorizer) KeyWrite(key string, entCtx *AuthorizerContext) Enfor
610610
if rule, ok := getPolicy(key, p.keyRules); ok {
611611
decision := enforce(rule.access, AccessWrite)
612612
if decision == Allow {
613-
return defaultIsAllow(p.enterprisePolicyAuthorizer.enforce(&rule.EnterpriseRule, entCtx))
613+
return defaultIsAllow(p.enforce(&rule.EnterpriseRule, entCtx))
614614
}
615615
return decision
616616
}

command/acl/agenttokens/agent_tokens.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (c *cmd) Run(args []string) int {
6767
case "dns":
6868
_, err = client.Agent().UpdateDNSToken(token, nil)
6969
default:
70-
c.UI.Error(fmt.Sprintf("Unknown token type"))
70+
c.UI.Error("Unknown token type")
7171
return 1
7272
}
7373

0 commit comments

Comments
 (0)