diff --git a/acl/authorizer.go b/acl/authorizer.go index 937d861129dc..f9c522ed9038 100644 --- a/acl/authorizer.go +++ b/acl/authorizer.go @@ -205,7 +205,7 @@ type AllowAuthorizer struct { // ACLReadAllowed checks for permission to list all the ACLs func (a AllowAuthorizer) ACLReadAllowed(ctx *AuthorizerContext) error { - if a.Authorizer.ACLRead(ctx) != Allow { + if a.ACLRead(ctx) != Allow { return PermissionDeniedByACLUnnamed(a, ctx, ResourceACL, AccessRead) } return nil @@ -213,7 +213,7 @@ func (a AllowAuthorizer) ACLReadAllowed(ctx *AuthorizerContext) error { // ACLWriteAllowed checks for permission to manipulate ACLs func (a AllowAuthorizer) ACLWriteAllowed(ctx *AuthorizerContext) error { - if a.Authorizer.ACLWrite(ctx) != Allow { + if a.ACLWrite(ctx) != Allow { return PermissionDeniedByACLUnnamed(a, ctx, ResourceACL, AccessWrite) } return nil @@ -222,7 +222,7 @@ func (a AllowAuthorizer) ACLWriteAllowed(ctx *AuthorizerContext) error { // AgentReadAllowed checks for permission to read from agent endpoints for a // given node. func (a AllowAuthorizer) AgentReadAllowed(name string, ctx *AuthorizerContext) error { - if a.Authorizer.AgentRead(name, ctx) != Allow { + if a.AgentRead(name, ctx) != Allow { return PermissionDeniedByACL(a, ctx, ResourceAgent, AccessRead, name) } return nil @@ -231,7 +231,7 @@ func (a AllowAuthorizer) AgentReadAllowed(name string, ctx *AuthorizerContext) e // AgentWriteAllowed checks for permission to make changes via agent endpoints // for a given node. func (a AllowAuthorizer) AgentWriteAllowed(name string, ctx *AuthorizerContext) error { - if a.Authorizer.AgentWrite(name, ctx) != Allow { + if a.AgentWrite(name, ctx) != Allow { return PermissionDeniedByACL(a, ctx, ResourceAgent, AccessWrite, name) } return nil @@ -239,7 +239,7 @@ func (a AllowAuthorizer) AgentWriteAllowed(name string, ctx *AuthorizerContext) // EventReadAllowed determines if a specific event can be queried. func (a AllowAuthorizer) EventReadAllowed(name string, ctx *AuthorizerContext) error { - if a.Authorizer.EventRead(name, ctx) != Allow { + if a.EventRead(name, ctx) != Allow { return PermissionDeniedByACL(a, ctx, ResourceEvent, AccessRead, name) } return nil @@ -247,7 +247,7 @@ func (a AllowAuthorizer) EventReadAllowed(name string, ctx *AuthorizerContext) e // EventWriteAllowed determines if a specific event may be fired. func (a AllowAuthorizer) EventWriteAllowed(name string, ctx *AuthorizerContext) error { - if a.Authorizer.EventWrite(name, ctx) != Allow { + if a.EventWrite(name, ctx) != Allow { return PermissionDeniedByACL(a, ctx, ResourceEvent, AccessWrite, name) } return nil @@ -255,7 +255,7 @@ func (a AllowAuthorizer) EventWriteAllowed(name string, ctx *AuthorizerContext) // IntentionReadAllowed determines if a specific intention can be read. func (a AllowAuthorizer) IntentionReadAllowed(name string, ctx *AuthorizerContext) error { - if a.Authorizer.IntentionRead(name, ctx) != Allow { + if a.IntentionRead(name, ctx) != Allow { return PermissionDeniedByACL(a, ctx, ResourceIntention, AccessRead, name) } return nil @@ -264,7 +264,7 @@ func (a AllowAuthorizer) IntentionReadAllowed(name string, ctx *AuthorizerContex // IntentionWriteAllowed determines if a specific intention can be // created, modified, or deleted. func (a AllowAuthorizer) IntentionWriteAllowed(name string, ctx *AuthorizerContext) error { - if a.Authorizer.IntentionWrite(name, ctx) != Allow { + if a.IntentionWrite(name, ctx) != Allow { return PermissionDeniedByACL(a, ctx, ResourceIntention, AccessWrite, name) } return nil @@ -272,7 +272,7 @@ func (a AllowAuthorizer) IntentionWriteAllowed(name string, ctx *AuthorizerConte // TrafficPermissionsReadAllowed determines if specific traffic permissions can be read. func (a AllowAuthorizer) TrafficPermissionsReadAllowed(name string, ctx *AuthorizerContext) error { - if a.Authorizer.TrafficPermissionsRead(name, ctx) != Allow { + if a.TrafficPermissionsRead(name, ctx) != Allow { return PermissionDeniedByACL(a, ctx, ResourceIntention, AccessRead, name) } return nil @@ -281,7 +281,7 @@ func (a AllowAuthorizer) TrafficPermissionsReadAllowed(name string, ctx *Authori // TrafficPermissionsWriteAllowed determines if specific traffic permissions can be // created, modified, or deleted. func (a AllowAuthorizer) TrafficPermissionsWriteAllowed(name string, ctx *AuthorizerContext) error { - if a.Authorizer.TrafficPermissionsWrite(name, ctx) != Allow { + if a.TrafficPermissionsWrite(name, ctx) != Allow { return PermissionDeniedByACL(a, ctx, ResourceIntention, AccessWrite, name) } return nil @@ -289,7 +289,7 @@ func (a AllowAuthorizer) TrafficPermissionsWriteAllowed(name string, ctx *Author // KeyListAllowed checks for permission to list keys under a prefix func (a AllowAuthorizer) KeyListAllowed(name string, ctx *AuthorizerContext) error { - if a.Authorizer.KeyList(name, ctx) != Allow { + if a.KeyList(name, ctx) != Allow { return PermissionDeniedByACL(a, ctx, ResourceKey, AccessList, name) } return nil @@ -297,7 +297,7 @@ func (a AllowAuthorizer) KeyListAllowed(name string, ctx *AuthorizerContext) err // KeyReadAllowed checks for permission to read a given key func (a AllowAuthorizer) KeyReadAllowed(name string, ctx *AuthorizerContext) error { - if a.Authorizer.KeyRead(name, ctx) != Allow { + if a.KeyRead(name, ctx) != Allow { return PermissionDeniedByACL(a, ctx, ResourceKey, AccessRead, name) } return nil @@ -305,7 +305,7 @@ func (a AllowAuthorizer) KeyReadAllowed(name string, ctx *AuthorizerContext) err // KeyWriteAllowed checks for permission to write a given key func (a AllowAuthorizer) KeyWriteAllowed(name string, ctx *AuthorizerContext) error { - if a.Authorizer.KeyWrite(name, ctx) != Allow { + if a.KeyWrite(name, ctx) != Allow { return PermissionDeniedByACL(a, ctx, ResourceKey, AccessWrite, name) } return nil @@ -315,7 +315,7 @@ func (a AllowAuthorizer) KeyWriteAllowed(name string, ctx *AuthorizerContext) er // entire key prefix. This means there must be no sub-policies // that deny a write. func (a AllowAuthorizer) KeyWritePrefixAllowed(name string, ctx *AuthorizerContext) error { - if a.Authorizer.KeyWritePrefix(name, ctx) != Allow { + if a.KeyWritePrefix(name, ctx) != Allow { // TODO(acl-error-enhancements) revisit this message; we may need to do some extra plumbing inside of KeyWritePrefix to // return properly detailed information. return PermissionDeniedByACL(a, ctx, ResourceKey, AccessWrite, name) @@ -326,7 +326,7 @@ func (a AllowAuthorizer) KeyWritePrefixAllowed(name string, ctx *AuthorizerConte // KeyringReadAllowed determines if the encryption keyring used in // the gossip layer can be read. func (a AllowAuthorizer) KeyringReadAllowed(ctx *AuthorizerContext) error { - if a.Authorizer.KeyringRead(ctx) != Allow { + if a.KeyringRead(ctx) != Allow { return PermissionDeniedByACLUnnamed(a, ctx, ResourceKeyring, AccessRead) } return nil @@ -334,7 +334,7 @@ func (a AllowAuthorizer) KeyringReadAllowed(ctx *AuthorizerContext) error { // KeyringWriteAllowed determines if the keyring can be manipulated func (a AllowAuthorizer) KeyringWriteAllowed(ctx *AuthorizerContext) error { - if a.Authorizer.KeyringWrite(ctx) != Allow { + if a.KeyringWrite(ctx) != Allow { return PermissionDeniedByACLUnnamed(a, ctx, ResourceKeyring, AccessWrite) } return nil @@ -343,7 +343,7 @@ func (a AllowAuthorizer) KeyringWriteAllowed(ctx *AuthorizerContext) error { // MeshReadAllowed determines if the read-only Consul mesh functions // can be used. func (a AllowAuthorizer) MeshReadAllowed(ctx *AuthorizerContext) error { - if a.Authorizer.MeshRead(ctx) != Allow { + if a.MeshRead(ctx) != Allow { return PermissionDeniedByACLUnnamed(a, ctx, ResourceMesh, AccessRead) } return nil @@ -352,7 +352,7 @@ func (a AllowAuthorizer) MeshReadAllowed(ctx *AuthorizerContext) error { // MeshWriteAllowed determines if the state-changing Consul mesh // functions can be used. func (a AllowAuthorizer) MeshWriteAllowed(ctx *AuthorizerContext) error { - if a.Authorizer.MeshWrite(ctx) != Allow { + if a.MeshWrite(ctx) != Allow { return PermissionDeniedByACLUnnamed(a, ctx, ResourceMesh, AccessWrite) } return nil @@ -361,7 +361,7 @@ func (a AllowAuthorizer) MeshWriteAllowed(ctx *AuthorizerContext) error { // PeeringReadAllowed determines if the read-only Consul peering functions // can be used. func (a AllowAuthorizer) PeeringReadAllowed(ctx *AuthorizerContext) error { - if a.Authorizer.PeeringRead(ctx) != Allow { + if a.PeeringRead(ctx) != Allow { return PermissionDeniedByACLUnnamed(a, ctx, ResourcePeering, AccessRead) } return nil @@ -370,7 +370,7 @@ func (a AllowAuthorizer) PeeringReadAllowed(ctx *AuthorizerContext) error { // PeeringWriteAllowed determines if the state-changing Consul peering // functions can be used. func (a AllowAuthorizer) PeeringWriteAllowed(ctx *AuthorizerContext) error { - if a.Authorizer.PeeringWrite(ctx) != Allow { + if a.PeeringWrite(ctx) != Allow { return PermissionDeniedByACLUnnamed(a, ctx, ResourcePeering, AccessWrite) } return nil @@ -378,7 +378,7 @@ func (a AllowAuthorizer) PeeringWriteAllowed(ctx *AuthorizerContext) error { // NodeReadAllowed checks for permission to read (discover) a given node. func (a AllowAuthorizer) NodeReadAllowed(name string, ctx *AuthorizerContext) error { - if a.Authorizer.NodeRead(name, ctx) != Allow { + if a.NodeRead(name, ctx) != Allow { return PermissionDeniedByACL(a, ctx, ResourceNode, AccessRead, name) } return nil @@ -386,7 +386,7 @@ func (a AllowAuthorizer) NodeReadAllowed(name string, ctx *AuthorizerContext) er // NodeReadAllAllowed checks for permission to read (discover) all nodes. func (a AllowAuthorizer) NodeReadAllAllowed(ctx *AuthorizerContext) error { - if a.Authorizer.NodeReadAll(ctx) != Allow { + if a.NodeReadAll(ctx) != Allow { // This is only used to gate certain UI functions right now (e.g metrics) return PermissionDeniedByACL(a, ctx, ResourceNode, AccessRead, "all nodes") } @@ -396,7 +396,7 @@ func (a AllowAuthorizer) NodeReadAllAllowed(ctx *AuthorizerContext) error { // NodeWriteAllowed checks for permission to create or update (register) a // given node. func (a AllowAuthorizer) NodeWriteAllowed(name string, ctx *AuthorizerContext) error { - if a.Authorizer.NodeWrite(name, ctx) != Allow { + if a.NodeWrite(name, ctx) != Allow { return PermissionDeniedByACL(a, ctx, ResourceNode, AccessWrite, name) } return nil @@ -405,7 +405,7 @@ func (a AllowAuthorizer) NodeWriteAllowed(name string, ctx *AuthorizerContext) e // OperatorReadAllowed determines if the read-only Consul operator functions // can be used. func (a AllowAuthorizer) OperatorReadAllowed(ctx *AuthorizerContext) error { - if a.Authorizer.OperatorRead(ctx) != Allow { + if a.OperatorRead(ctx) != Allow { return PermissionDeniedByACLUnnamed(a, ctx, ResourceOperator, AccessRead) } return nil @@ -414,7 +414,7 @@ func (a AllowAuthorizer) OperatorReadAllowed(ctx *AuthorizerContext) error { // OperatorWriteAllowed determines if the state-changing Consul operator // functions can be used. func (a AllowAuthorizer) OperatorWriteAllowed(ctx *AuthorizerContext) error { - if a.Authorizer.OperatorWrite(ctx) != Allow { + if a.OperatorWrite(ctx) != Allow { return PermissionDeniedByACLUnnamed(a, ctx, ResourceOperator, AccessWrite) } return nil @@ -423,7 +423,7 @@ func (a AllowAuthorizer) OperatorWriteAllowed(ctx *AuthorizerContext) error { // PreparedQueryReadAllowed determines if a specific prepared query can be read // to show its contents (this is not used for execution). func (a AllowAuthorizer) PreparedQueryReadAllowed(name string, ctx *AuthorizerContext) error { - if a.Authorizer.PreparedQueryRead(name, ctx) != Allow { + if a.PreparedQueryRead(name, ctx) != Allow { return PermissionDeniedByACL(a, ctx, ResourceQuery, AccessRead, name) } return nil @@ -432,7 +432,7 @@ func (a AllowAuthorizer) PreparedQueryReadAllowed(name string, ctx *AuthorizerCo // PreparedQueryWriteAllowed determines if a specific prepared query can be // created, modified, or deleted. func (a AllowAuthorizer) PreparedQueryWriteAllowed(name string, ctx *AuthorizerContext) error { - if a.Authorizer.PreparedQueryWrite(name, ctx) != Allow { + if a.PreparedQueryWrite(name, ctx) != Allow { return PermissionDeniedByACL(a, ctx, ResourceQuery, AccessWrite, name) } return nil @@ -440,7 +440,7 @@ func (a AllowAuthorizer) PreparedQueryWriteAllowed(name string, ctx *AuthorizerC // ServiceReadAllowed checks for permission to read a given service func (a AllowAuthorizer) ServiceReadAllowed(name string, ctx *AuthorizerContext) error { - if a.Authorizer.ServiceRead(name, ctx) != Allow { + if a.ServiceRead(name, ctx) != Allow { return PermissionDeniedByACL(a, ctx, ResourceService, AccessRead, name) } return nil @@ -448,7 +448,7 @@ func (a AllowAuthorizer) ServiceReadAllowed(name string, ctx *AuthorizerContext) // ServiceReadAllAllowed checks for permission to read all services func (a AllowAuthorizer) ServiceReadAllAllowed(ctx *AuthorizerContext) error { - if a.Authorizer.ServiceReadAll(ctx) != Allow { + if a.ServiceReadAll(ctx) != Allow { // This is only used to gate certain UI functions right now (e.g metrics) return PermissionDeniedByACL(a, ctx, ResourceService, AccessRead, "all services") // read } @@ -457,7 +457,7 @@ func (a AllowAuthorizer) ServiceReadAllAllowed(ctx *AuthorizerContext) error { // ServiceReadPrefixAllowed checks for permission to read services within the given prefix func (a AllowAuthorizer) ServiceReadPrefixAllowed(prefix string, ctx *AuthorizerContext) error { - if a.Authorizer.ServiceReadPrefix(prefix, ctx) != Allow { + if a.ServiceReadPrefix(prefix, ctx) != Allow { return PermissionDeniedByACL(a, ctx, ResourceService, AccessRead, prefix) // read } return nil @@ -466,7 +466,7 @@ func (a AllowAuthorizer) ServiceReadPrefixAllowed(prefix string, ctx *Authorizer // ServiceWriteAllowed checks for permission to create or update a given // service func (a AllowAuthorizer) ServiceWriteAllowed(name string, ctx *AuthorizerContext) error { - if a.Authorizer.ServiceWrite(name, ctx) != Allow { + if a.ServiceWrite(name, ctx) != Allow { return PermissionDeniedByACL(a, ctx, ResourceService, AccessWrite, name) } return nil @@ -474,7 +474,7 @@ func (a AllowAuthorizer) ServiceWriteAllowed(name string, ctx *AuthorizerContext // ServiceWriteAnyAllowed checks for write permission on any service func (a AllowAuthorizer) ServiceWriteAnyAllowed(ctx *AuthorizerContext) error { - if a.Authorizer.ServiceWriteAny(ctx) != Allow { + if a.ServiceWriteAny(ctx) != Allow { return PermissionDeniedByACL(a, ctx, ResourceService, AccessWrite, "any service") } return nil @@ -482,7 +482,7 @@ func (a AllowAuthorizer) ServiceWriteAnyAllowed(ctx *AuthorizerContext) error { // SessionReadAllowed checks for permission to read sessions for a given node. func (a AllowAuthorizer) SessionReadAllowed(name string, ctx *AuthorizerContext) error { - if a.Authorizer.SessionRead(name, ctx) != Allow { + if a.SessionRead(name, ctx) != Allow { return PermissionDeniedByACL(a, ctx, ResourceSession, AccessRead, name) } return nil @@ -491,7 +491,7 @@ func (a AllowAuthorizer) SessionReadAllowed(name string, ctx *AuthorizerContext) // SessionWriteAllowed checks for permission to create sessions for a given // node. func (a AllowAuthorizer) SessionWriteAllowed(name string, ctx *AuthorizerContext) error { - if a.Authorizer.SessionWrite(name, ctx) != Allow { + if a.SessionWrite(name, ctx) != Allow { return PermissionDeniedByACL(a, ctx, ResourceSession, AccessWrite, name) } return nil @@ -499,7 +499,7 @@ func (a AllowAuthorizer) SessionWriteAllowed(name string, ctx *AuthorizerContext // SnapshotAllowed checks for permission to take and restore snapshots. func (a AllowAuthorizer) SnapshotAllowed(ctx *AuthorizerContext) error { - if a.Authorizer.Snapshot(ctx) != Allow { + if a.Snapshot(ctx) != Allow { // Implementation of this currently just checks acl write return PermissionDeniedByACLUnnamed(a, ctx, ResourceACL, AccessWrite) } diff --git a/acl/policy.go b/acl/policy.go index 54eb4e658799..b699df0398b1 100644 --- a/acl/policy.go +++ b/acl/policy.go @@ -197,7 +197,7 @@ func (pr *PolicyRules) Validate(conf *Config) error { if !isPolicyValid(kp.Policy, true) { return fmt.Errorf("Invalid key policy: %#v", kp) } - if err := kp.EnterpriseRule.Validate(kp.Policy, conf); err != nil { + if err := kp.Validate(kp.Policy, conf); err != nil { return fmt.Errorf("Invalid key enterprise policy: %#v, got error: %v", kp, err) } } @@ -205,7 +205,7 @@ func (pr *PolicyRules) Validate(conf *Config) error { if !isPolicyValid(kp.Policy, true) { return fmt.Errorf("Invalid key_prefix policy: %#v", kp) } - if err := kp.EnterpriseRule.Validate(kp.Policy, conf); err != nil { + if err := kp.Validate(kp.Policy, conf); err != nil { return fmt.Errorf("Invalid key_prefix enterprise policy: %#v, got error: %v", kp, err) } } @@ -215,7 +215,7 @@ func (pr *PolicyRules) Validate(conf *Config) error { if !isPolicyValid(np.Policy, false) { return fmt.Errorf("Invalid node policy: %#v", np) } - if err := np.EnterpriseRule.Validate(np.Policy, conf); err != nil { + if err := np.Validate(np.Policy, conf); err != nil { return fmt.Errorf("Invalid node enterprise policy: %#v, got error: %v", np, err) } } @@ -223,7 +223,7 @@ func (pr *PolicyRules) Validate(conf *Config) error { if !isPolicyValid(np.Policy, false) { return fmt.Errorf("Invalid node_prefix policy: %#v", np) } - if err := np.EnterpriseRule.Validate(np.Policy, conf); err != nil { + if err := np.Validate(np.Policy, conf); err != nil { return fmt.Errorf("Invalid node_prefix enterprise policy: %#v, got error: %v", np, err) } } @@ -236,7 +236,7 @@ func (pr *PolicyRules) Validate(conf *Config) error { if sp.Intentions != "" && !isPolicyValid(sp.Intentions, false) { return fmt.Errorf("Invalid service intentions policy: %#v", sp) } - if err := sp.EnterpriseRule.Validate(sp.Policy, conf); err != nil { + if err := sp.Validate(sp.Policy, conf); err != nil { return fmt.Errorf("Invalid service enterprise policy: %#v, got error: %v", sp, err) } } @@ -247,7 +247,7 @@ func (pr *PolicyRules) Validate(conf *Config) error { if sp.Intentions != "" && !isPolicyValid(sp.Intentions, false) { return fmt.Errorf("Invalid service_prefix intentions policy: %#v", sp) } - if err := sp.EnterpriseRule.Validate(sp.Policy, conf); err != nil { + if err := sp.Validate(sp.Policy, conf); err != nil { return fmt.Errorf("Invalid service_prefix enterprise policy: %#v, got error: %v", sp, err) } } diff --git a/acl/policy_authorizer.go b/acl/policy_authorizer.go index 16ffa743f95e..8d31c9a9e5a6 100644 --- a/acl/policy_authorizer.go +++ b/acl/policy_authorizer.go @@ -362,7 +362,7 @@ func newPolicyAuthorizerFromRules(rules *PolicyRules, ent *Config) (*policyAutho preparedQueryRules: radix.New(), } - p.enterprisePolicyAuthorizer.init(ent) + p.init(ent) if err := p.loadRules(rules); err != nil { return nil, err @@ -610,7 +610,7 @@ func (p *policyAuthorizer) KeyWrite(key string, entCtx *AuthorizerContext) Enfor if rule, ok := getPolicy(key, p.keyRules); ok { decision := enforce(rule.access, AccessWrite) if decision == Allow { - return defaultIsAllow(p.enterprisePolicyAuthorizer.enforce(&rule.EnterpriseRule, entCtx)) + return defaultIsAllow(p.enforce(&rule.EnterpriseRule, entCtx)) } return decision } diff --git a/command/acl/agenttokens/agent_tokens.go b/command/acl/agenttokens/agent_tokens.go index 8aca79e5d006..2e668066dc4a 100644 --- a/command/acl/agenttokens/agent_tokens.go +++ b/command/acl/agenttokens/agent_tokens.go @@ -67,7 +67,7 @@ func (c *cmd) Run(args []string) int { case "dns": _, err = client.Agent().UpdateDNSToken(token, nil) default: - c.UI.Error(fmt.Sprintf("Unknown token type")) + c.UI.Error("Unknown token type") return 1 } diff --git a/command/acl/authmethod/create/authmethod_create.go b/command/acl/authmethod/create/authmethod_create.go index 17f328d2b8be..863f9c269d37 100644 --- a/command/acl/authmethod/create/authmethod_create.go +++ b/command/acl/authmethod/create/authmethod_create.go @@ -152,11 +152,11 @@ func (c *cmd) Run(args []string) int { } if c.authMethodType == "" { - c.UI.Error(fmt.Sprintf("Missing required '-type' flag")) + c.UI.Error("Missing required '-type' flag") c.UI.Error(c.Help()) return 1 } else if c.name == "" { - c.UI.Error(fmt.Sprintf("Missing required '-name' flag")) + c.UI.Error("Missing required '-name' flag") c.UI.Error(c.Help()) return 1 } @@ -185,7 +185,7 @@ func (c *cmd) Run(args []string) int { if c.config != "" { if c.k8sHost != "" || c.k8sCACert != "" || c.k8sServiceAccountJWT != "" { - c.UI.Error(fmt.Sprintf("Cannot use command line arguments with '-config' flags")) + c.UI.Error("Cannot use command line arguments with '-config' flags") return 1 } data, err := helpers.LoadDataSource(c.config, c.testStdin) @@ -203,13 +203,13 @@ func (c *cmd) Run(args []string) int { if c.authMethodType == "kubernetes" { if c.k8sHost == "" { - c.UI.Error(fmt.Sprintf("Missing required '-kubernetes-host' flag")) + c.UI.Error("Missing required '-kubernetes-host' flag") return 1 } else if c.k8sCACert == "" { - c.UI.Error(fmt.Sprintf("Missing required '-kubernetes-ca-cert' flag")) + c.UI.Error("Missing required '-kubernetes-ca-cert' flag") return 1 } else if c.k8sServiceAccountJWT == "" { - c.UI.Error(fmt.Sprintf("Missing required '-kubernetes-service-account-jwt' flag")) + c.UI.Error("Missing required '-kubernetes-service-account-jwt' flag") return 1 } @@ -218,7 +218,7 @@ func (c *cmd) Run(args []string) int { c.UI.Error(fmt.Sprintf("Invalid '-kubernetes-ca-cert' value: %v", err)) return 1 } else if c.k8sCACert == "" { - c.UI.Error(fmt.Sprintf("Kubernetes CA Cert is empty")) + c.UI.Error("Kubernetes CA Cert is empty") return 1 } diff --git a/command/acl/authmethod/delete/authmethod_delete.go b/command/acl/authmethod/delete/authmethod_delete.go index e3ccd0efdd01..2ff8704ede28 100644 --- a/command/acl/authmethod/delete/authmethod_delete.go +++ b/command/acl/authmethod/delete/authmethod_delete.go @@ -49,7 +49,7 @@ func (c *cmd) Run(args []string) int { } if c.name == "" { - c.UI.Error(fmt.Sprintf("Must specify the -name parameter")) + c.UI.Error("Must specify the -name parameter") return 1 } diff --git a/command/acl/authmethod/delete/authmethod_delete_test.go b/command/acl/authmethod/delete/authmethod_delete_test.go index fc513fde7ebd..da0acfacc24b 100644 --- a/command/acl/authmethod/delete/authmethod_delete_test.go +++ b/command/acl/authmethod/delete/authmethod_delete_test.go @@ -4,7 +4,6 @@ package authmethoddelete import ( - "fmt" "strings" "testing" @@ -117,7 +116,7 @@ func TestAuthMethodDeleteCommand(t *testing.T) { require.Empty(t, ui.ErrorWriter.String()) output := ui.OutputWriter.String() - require.Contains(t, output, fmt.Sprintf("deleted successfully")) + require.Contains(t, output, "deleted successfully") require.Contains(t, output, name) method, _, err := client.ACL().AuthMethodRead( diff --git a/command/acl/authmethod/read/authmethod_read.go b/command/acl/authmethod/read/authmethod_read.go index 72d3a6f18163..41eaca82fa14 100644 --- a/command/acl/authmethod/read/authmethod_read.go +++ b/command/acl/authmethod/read/authmethod_read.go @@ -69,7 +69,7 @@ func (c *cmd) Run(args []string) int { } if c.name == "" { - c.UI.Error(fmt.Sprintf("Must specify the -name parameter")) + c.UI.Error("Must specify the -name parameter") return 1 } diff --git a/command/acl/authmethod/update/authmethod_update.go b/command/acl/authmethod/update/authmethod_update.go index 1c5422e88dea..b32bd42b2161 100644 --- a/command/acl/authmethod/update/authmethod_update.go +++ b/command/acl/authmethod/update/authmethod_update.go @@ -156,7 +156,7 @@ func (c *cmd) Run(args []string) int { } if c.name == "" { - c.UI.Error(fmt.Sprintf("Cannot update an auth method without specifying the -name parameter")) + c.UI.Error("Cannot update an auth method without specifying the -name parameter") return 1 } @@ -182,7 +182,7 @@ func (c *cmd) Run(args []string) int { c.UI.Error(fmt.Sprintf("Invalid '-kubernetes-ca-cert' value: %v", err)) return 1 } else if c.k8sCACert == "" { - c.UI.Error(fmt.Sprintf("Kubernetes CA Cert is empty")) + c.UI.Error("Kubernetes CA Cert is empty") return 1 } } @@ -207,7 +207,7 @@ func (c *cmd) Run(args []string) int { if c.config != "" { if c.k8sHost != "" || c.k8sCACert != "" || c.k8sServiceAccountJWT != "" { - c.UI.Error(fmt.Sprintf("Cannot use command line arguments with '-config' flag")) + c.UI.Error("Cannot use command line arguments with '-config' flag") return 1 } data, err := helpers.LoadDataSource(c.config, c.testStdin) @@ -223,13 +223,13 @@ func (c *cmd) Run(args []string) int { if currentAuthMethod.Type == "kubernetes" { if c.k8sHost == "" { - c.UI.Error(fmt.Sprintf("Missing required '-kubernetes-host' flag")) + c.UI.Error("Missing required '-kubernetes-host' flag") return 1 } else if c.k8sCACert == "" { - c.UI.Error(fmt.Sprintf("Missing required '-kubernetes-ca-cert' flag")) + c.UI.Error("Missing required '-kubernetes-ca-cert' flag") return 1 } else if c.k8sServiceAccountJWT == "" { - c.UI.Error(fmt.Sprintf("Missing required '-kubernetes-service-account-jwt' flag")) + c.UI.Error("Missing required '-kubernetes-service-account-jwt' flag") return 1 } @@ -260,7 +260,7 @@ func (c *cmd) Run(args []string) int { } if c.config != "" { if c.k8sHost != "" || c.k8sCACert != "" || c.k8sServiceAccountJWT != "" { - c.UI.Error(fmt.Sprintf("Cannot use command line arguments with '-config' flag")) + c.UI.Error("Cannot use command line arguments with '-config' flag") return 1 } data, err := helpers.LoadDataSource(c.config, c.testStdin) diff --git a/command/acl/bindingrule/delete/bindingrule_delete.go b/command/acl/bindingrule/delete/bindingrule_delete.go index 3fc02d788b4b..77b3e6f24280 100644 --- a/command/acl/bindingrule/delete/bindingrule_delete.go +++ b/command/acl/bindingrule/delete/bindingrule_delete.go @@ -53,7 +53,7 @@ func (c *cmd) Run(args []string) int { } if c.ruleID == "" { - c.UI.Error(fmt.Sprintf("Must specify the -id parameter")) + c.UI.Error("Must specify the -id parameter") return 1 } diff --git a/command/acl/bindingrule/delete/bindingrule_delete_test.go b/command/acl/bindingrule/delete/bindingrule_delete_test.go index 9655fbb101a4..4f79871963e0 100644 --- a/command/acl/bindingrule/delete/bindingrule_delete_test.go +++ b/command/acl/bindingrule/delete/bindingrule_delete_test.go @@ -4,7 +4,6 @@ package bindingruledelete import ( - "fmt" "strings" "testing" @@ -129,7 +128,7 @@ func TestBindingRuleDeleteCommand(t *testing.T) { require.Empty(t, ui.ErrorWriter.String()) output := ui.OutputWriter.String() - require.Contains(t, output, fmt.Sprintf("deleted successfully")) + require.Contains(t, output, "deleted successfully") require.Contains(t, output, id) rule, _, err := client.ACL().BindingRuleRead( @@ -157,7 +156,7 @@ func TestBindingRuleDeleteCommand(t *testing.T) { require.Empty(t, ui.ErrorWriter.String()) output := ui.OutputWriter.String() - require.Contains(t, output, fmt.Sprintf("deleted successfully")) + require.Contains(t, output, "deleted successfully") require.Contains(t, output, id) rule, _, err := client.ACL().BindingRuleRead( diff --git a/command/acl/bindingrule/read/bindingrule_read.go b/command/acl/bindingrule/read/bindingrule_read.go index 0ff55bd4ac2b..8a5c8c69e209 100644 --- a/command/acl/bindingrule/read/bindingrule_read.go +++ b/command/acl/bindingrule/read/bindingrule_read.go @@ -72,7 +72,7 @@ func (c *cmd) Run(args []string) int { } if c.ruleID == "" { - c.UI.Error(fmt.Sprintf("Must specify the -id parameter.")) + c.UI.Error("Must specify the -id parameter.") return 1 } diff --git a/command/acl/bindingrule/read/bindingrule_read_test.go b/command/acl/bindingrule/read/bindingrule_read_test.go index 4a324edf2317..2746ca86109c 100644 --- a/command/acl/bindingrule/read/bindingrule_read_test.go +++ b/command/acl/bindingrule/read/bindingrule_read_test.go @@ -4,7 +4,6 @@ package bindingruleread import ( - "fmt" "strings" "testing" @@ -124,7 +123,7 @@ func TestBindingRuleReadCommand(t *testing.T) { require.Empty(t, ui.ErrorWriter.String()) output := ui.OutputWriter.String() - require.Contains(t, output, fmt.Sprintf("test rule")) + require.Contains(t, output, "test rule") require.Contains(t, output, id) }) @@ -145,7 +144,7 @@ func TestBindingRuleReadCommand(t *testing.T) { require.Empty(t, ui.ErrorWriter.String()) output := ui.OutputWriter.String() - require.Contains(t, output, fmt.Sprintf("test rule")) + require.Contains(t, output, "test rule") require.Contains(t, output, id) }) @@ -167,7 +166,7 @@ func TestBindingRuleReadCommand(t *testing.T) { require.Empty(t, ui.ErrorWriter.String()) output := ui.OutputWriter.String() - require.Contains(t, output, fmt.Sprintf("test rule")) + require.Contains(t, output, "test rule") require.Contains(t, output, id) }) } diff --git a/command/acl/policy/create/policy_create.go b/command/acl/policy/create/policy_create.go index a172b17fbb1a..0b9f5bb88203 100644 --- a/command/acl/policy/create/policy_create.go +++ b/command/acl/policy/create/policy_create.go @@ -71,7 +71,7 @@ func (c *cmd) Run(args []string) int { } if c.name == "" { - c.UI.Error(fmt.Sprintf("Missing required '-name' flag")) + c.UI.Error("Missing required '-name' flag") c.UI.Error(c.Help()) return 1 } diff --git a/command/acl/policy/delete/policy_delete.go b/command/acl/policy/delete/policy_delete.go index 63c02a47ddd2..f6b5358a3e63 100644 --- a/command/acl/policy/delete/policy_delete.go +++ b/command/acl/policy/delete/policy_delete.go @@ -48,7 +48,7 @@ func (c *cmd) Run(args []string) int { } if c.policyID == "" && c.policyName == "" { - c.UI.Error(fmt.Sprintf("Must specify either the -id or -name parameters")) + c.UI.Error("Must specify either the -id or -name parameters") return 1 } diff --git a/command/acl/policy/delete/policy_delete_test.go b/command/acl/policy/delete/policy_delete_test.go index 33f121db981f..e0286662e2d8 100644 --- a/command/acl/policy/delete/policy_delete_test.go +++ b/command/acl/policy/delete/policy_delete_test.go @@ -4,7 +4,6 @@ package policydelete import ( - "fmt" "strings" "testing" @@ -66,7 +65,7 @@ func TestPolicyDeleteCommand(t *testing.T) { assert.Empty(t, ui.ErrorWriter.String()) output := ui.OutputWriter.String() - assert.Contains(t, output, fmt.Sprintf("deleted successfully")) + assert.Contains(t, output, "deleted successfully") assert.Contains(t, output, policy.ID) _, _, err = client.ACL().PolicyRead( diff --git a/command/acl/policy/read/policy_read.go b/command/acl/policy/read/policy_read.go index 36f1e6534079..bb825da237d8 100644 --- a/command/acl/policy/read/policy_read.go +++ b/command/acl/policy/read/policy_read.go @@ -61,7 +61,7 @@ func (c *cmd) Run(args []string) int { } if c.policyID == "" && c.policyName == "" { - c.UI.Error(fmt.Sprintf("Must specify either the -id or -name parameters")) + c.UI.Error("Must specify either the -id or -name parameters") return 1 } diff --git a/command/acl/policy/read/policy_read_test.go b/command/acl/policy/read/policy_read_test.go index 70036457cebb..864013099e38 100644 --- a/command/acl/policy/read/policy_read_test.go +++ b/command/acl/policy/read/policy_read_test.go @@ -5,7 +5,6 @@ package policyread import ( "encoding/json" - "fmt" "strings" "testing" @@ -67,7 +66,7 @@ func TestPolicyReadCommand(t *testing.T) { assert.Empty(t, ui.ErrorWriter.String()) output := ui.OutputWriter.String() - assert.Contains(t, output, fmt.Sprintf("test-policy")) + assert.Contains(t, output, "test-policy") assert.Contains(t, output, policy.ID) // Test querying by name field @@ -83,7 +82,7 @@ func TestPolicyReadCommand(t *testing.T) { assert.Empty(t, ui.ErrorWriter.String()) output = ui.OutputWriter.String() - assert.Contains(t, output, fmt.Sprintf("test-policy")) + assert.Contains(t, output, "test-policy") assert.Contains(t, output, policy.ID) // Test querying non-existent policy @@ -141,7 +140,7 @@ func TestPolicyReadCommand_JSON(t *testing.T) { assert.Empty(t, ui.ErrorWriter.String()) output := ui.OutputWriter.String() - assert.Contains(t, output, fmt.Sprintf("test-policy")) + assert.Contains(t, output, "test-policy") assert.Contains(t, output, policy.ID) var jsonOutput json.RawMessage diff --git a/command/acl/policy/update/policy_update.go b/command/acl/policy/update/policy_update.go index 60b634073613..29ed05efc948 100644 --- a/command/acl/policy/update/policy_update.go +++ b/command/acl/policy/update/policy_update.go @@ -94,7 +94,7 @@ func (c *cmd) Run(args []string) int { c.flags.Visit(c.checkSet) if c.policyID == "" && c.name == "" { - c.UI.Error(fmt.Sprintf("Must specify either the -id or -name parameters")) + c.UI.Error("Must specify either the -id or -name parameters") return 1 } diff --git a/command/acl/role/delete/role_delete.go b/command/acl/role/delete/role_delete.go index aaac306f01b2..846b9b42c188 100644 --- a/command/acl/role/delete/role_delete.go +++ b/command/acl/role/delete/role_delete.go @@ -48,7 +48,7 @@ func (c *cmd) Run(args []string) int { } if c.roleID == "" && c.roleName == "" { - c.UI.Error(fmt.Sprintf("Must specify the -id or -name parameters")) + c.UI.Error("Must specify the -id or -name parameters") return 1 } diff --git a/command/acl/role/delete/role_delete_test.go b/command/acl/role/delete/role_delete_test.go index 61897ca24557..b820f94a764e 100644 --- a/command/acl/role/delete/role_delete_test.go +++ b/command/acl/role/delete/role_delete_test.go @@ -4,7 +4,6 @@ package roledelete import ( - "fmt" "strings" "testing" @@ -87,7 +86,7 @@ func TestRoleDeleteCommand(t *testing.T) { require.Empty(t, ui.ErrorWriter.String()) output := ui.OutputWriter.String() - require.Contains(t, output, fmt.Sprintf("deleted successfully")) + require.Contains(t, output, "deleted successfully") require.Contains(t, output, role.ID) role, _, err = client.ACL().RoleRead( @@ -127,7 +126,7 @@ func TestRoleDeleteCommand(t *testing.T) { require.Empty(t, ui.ErrorWriter.String()) output := ui.OutputWriter.String() - require.Contains(t, output, fmt.Sprintf("deleted successfully")) + require.Contains(t, output, "deleted successfully") require.Contains(t, output, role.ID) role, _, err = client.ACL().RoleRead( diff --git a/command/acl/role/read/role_read.go b/command/acl/role/read/role_read.go index 027aaa80019f..ea0b0d9259eb 100644 --- a/command/acl/role/read/role_read.go +++ b/command/acl/role/read/role_read.go @@ -61,7 +61,7 @@ func (c *cmd) Run(args []string) int { } if c.roleID == "" && c.roleName == "" { - c.UI.Error(fmt.Sprintf("Must specify either the -id or -name parameters")) + c.UI.Error("Must specify either the -id or -name parameters") return 1 } diff --git a/command/acl/role/read/role_read_test.go b/command/acl/role/read/role_read_test.go index bef1fab26016..964bd88b9a45 100644 --- a/command/acl/role/read/role_read_test.go +++ b/command/acl/role/read/role_read_test.go @@ -5,7 +5,6 @@ package roleread import ( "encoding/json" - "fmt" "strings" "testing" @@ -123,7 +122,7 @@ func TestRoleReadCommand(t *testing.T) { require.Empty(t, ui.ErrorWriter.String()) output := ui.OutputWriter.String() - require.Contains(t, output, fmt.Sprintf("test-role")) + require.Contains(t, output, "test-role") require.Contains(t, output, role.ID) }) @@ -156,7 +155,7 @@ func TestRoleReadCommand(t *testing.T) { require.Empty(t, ui.ErrorWriter.String()) output := ui.OutputWriter.String() - require.Contains(t, output, fmt.Sprintf("test-role")) + require.Contains(t, output, "test-role") require.Contains(t, output, role.ID) }) @@ -189,7 +188,7 @@ func TestRoleReadCommand(t *testing.T) { require.Empty(t, ui.ErrorWriter.String()) output := ui.OutputWriter.String() - require.Contains(t, output, fmt.Sprintf("test-role")) + require.Contains(t, output, "test-role") require.Contains(t, output, role.ID) }) } @@ -245,7 +244,7 @@ func TestRoleReadCommand_JSON(t *testing.T) { require.Empty(t, ui.ErrorWriter.String()) output := ui.OutputWriter.String() - require.Contains(t, output, fmt.Sprintf("test-role")) + require.Contains(t, output, "test-role") require.Contains(t, output, role.ID) var jsonOutput json.RawMessage diff --git a/command/acl/role/update/role_update.go b/command/acl/role/update/role_update.go index fa1ac4176fa3..14f0e0849b09 100644 --- a/command/acl/role/update/role_update.go +++ b/command/acl/role/update/role_update.go @@ -98,7 +98,7 @@ func (c *cmd) Run(args []string) int { } if c.roleID == "" { - c.UI.Error(fmt.Sprintf("Cannot update a role without specifying the -id parameter")) + c.UI.Error("Cannot update a role without specifying the -id parameter") return 1 } diff --git a/command/acl/templatedpolicy/formatter.go b/command/acl/templatedpolicy/formatter.go index e71b52a37550..18e50970df74 100644 --- a/command/acl/templatedpolicy/formatter.go +++ b/command/acl/templatedpolicy/formatter.go @@ -94,13 +94,13 @@ func (f *prettyFormatter) FormatTemplatedPolicy(templatedPolicy api.ACLTemplated func noRequiredVariablesOutput(buffer *bytes.Buffer, templateName string) { buffer.WriteString(" None\n") buffer.WriteString("Example usage:\n") - buffer.WriteString(fmt.Sprintf("%sconsul acl token create -templated-policy %s\n", WhitespaceIndent, templateName)) + fmt.Fprintf(buffer, "%sconsul acl token create -templated-policy %s\n", WhitespaceIndent, templateName) } func nameRequiredVariableOutput(buffer *bytes.Buffer, templateName, description, exampleName string) { - buffer.WriteString(fmt.Sprintf("\n%sName: String - Required - %s.\n", WhitespaceIndent, description)) + fmt.Fprintf(buffer, "\n%sName: String - Required - %s.\n", WhitespaceIndent, description) buffer.WriteString("Example usage:\n") - buffer.WriteString(fmt.Sprintf("%sconsul acl token create -templated-policy %s -var name:%s\n", WhitespaceIndent, templateName, exampleName)) + fmt.Fprintf(buffer, "%sconsul acl token create -templated-policy %s -var name:%s\n", WhitespaceIndent, templateName, exampleName) } func (f *prettyFormatter) FormatTemplatedPolicyList(policies map[string]api.ACLTemplatedPolicyResponse) (string, error) { diff --git a/command/acl/templatedpolicy/preview/templated_policy_preview.go b/command/acl/templatedpolicy/preview/templated_policy_preview.go index c2dc706f9007..f85fc92ae6e4 100644 --- a/command/acl/templatedpolicy/preview/templated_policy_preview.go +++ b/command/acl/templatedpolicy/preview/templated_policy_preview.go @@ -78,7 +78,7 @@ func (c *cmd) Run(args []string) int { return 1 } - if !(len(parsedTemplatedPolicies) == 1) { + if len(parsedTemplatedPolicies) != 1 { c.UI.Error("Can only preview a single templated policy at a time.") return 1 } diff --git a/command/acl/token/delete/token_delete_test.go b/command/acl/token/delete/token_delete_test.go index 29c1fe292d60..f9f0ffa84de8 100644 --- a/command/acl/token/delete/token_delete_test.go +++ b/command/acl/token/delete/token_delete_test.go @@ -4,7 +4,6 @@ package tokendelete import ( - "fmt" "strings" "testing" @@ -66,7 +65,7 @@ func TestTokenDeleteCommand(t *testing.T) { assert.Empty(t, ui.ErrorWriter.String()) output := ui.OutputWriter.String() - assert.Contains(t, output, fmt.Sprintf("deleted successfully")) + assert.Contains(t, output, "deleted successfully") assert.Contains(t, output, token.AccessorID) _, _, err = client.ACL().TokenRead( diff --git a/command/acl/token/formatter.go b/command/acl/token/formatter.go index 5325d285dbbb..bcb75e2b2a97 100644 --- a/command/acl/token/formatter.go +++ b/command/acl/token/formatter.go @@ -172,9 +172,9 @@ func (f *prettyFormatter) FormatTokenExpanded(token *api.ACLTokenExpanded) (stri buffer.WriteString("\n\n") } - if len(token.ACLToken.Policies) > 0 { + if len(token.Policies) > 0 { buffer.WriteString("Policies:\n") - for _, policyLink := range token.ACLToken.Policies { + for _, policyLink := range token.Policies { formatPolicy(policies[policyLink.ID], WHITESPACE_2) } } @@ -190,9 +190,9 @@ func (f *prettyFormatter) FormatTokenExpanded(token *api.ACLTokenExpanded) (stri policy := identity.SyntheticPolicy(&entMeta) displaySyntheticPolicy(policy, &buffer, indent) } - if len(token.ACLToken.ServiceIdentities) > 0 { + if len(token.ServiceIdentities) > 0 { buffer.WriteString("Service Identities:\n") - for _, svcIdentity := range token.ACLToken.ServiceIdentities { + for _, svcIdentity := range token.ServiceIdentities { formatServiceIdentity(svcIdentity, WHITESPACE_2) } } @@ -203,9 +203,9 @@ func (f *prettyFormatter) FormatTokenExpanded(token *api.ACLTokenExpanded) (stri policy := identity.SyntheticPolicy(&entMeta) displaySyntheticPolicy(policy, &buffer, indent) } - if len(token.ACLToken.NodeIdentities) > 0 { + if len(token.NodeIdentities) > 0 { buffer.WriteString("Node Identities:\n") - for _, nodeIdentity := range token.ACLToken.NodeIdentities { + for _, nodeIdentity := range token.NodeIdentities { formatNodeIdentity(nodeIdentity, WHITESPACE_2) } } @@ -230,10 +230,10 @@ func (f *prettyFormatter) FormatTokenExpanded(token *api.ACLTokenExpanded) (stri policy, _ := tp.SyntheticPolicy(&entMeta) displaySyntheticPolicy(policy, &buffer, indent) } - if len(token.ACLToken.TemplatedPolicies) > 0 { + if len(token.TemplatedPolicies) > 0 { buffer.WriteString("Templated Policies:\n") - for _, templatedPolicy := range token.ACLToken.TemplatedPolicies { + for _, templatedPolicy := range token.TemplatedPolicies { formatTemplatedPolicy(templatedPolicy, WHITESPACE_2) } } @@ -264,9 +264,9 @@ func (f *prettyFormatter) FormatTokenExpanded(token *api.ACLTokenExpanded) (stri } } } - if len(token.ACLToken.Roles) > 0 { + if len(token.Roles) > 0 { buffer.WriteString("Roles:\n") - for _, roleLink := range token.ACLToken.Roles { + for _, roleLink := range token.Roles { role := roles[roleLink.ID] formatRole(role, WHITESPACE_2) } @@ -303,7 +303,7 @@ func (f *prettyFormatter) FormatTokenExpanded(token *api.ACLTokenExpanded) (stri } func displaySyntheticPolicy(policy *structs.ACLPolicy, buffer *bytes.Buffer, indent string) { - buffer.WriteString(fmt.Sprintf(indent+WHITESPACE_2+"Description: %s\n", policy.Description)) + fmt.Fprintf(buffer, indent+WHITESPACE_2+"Description: %s\n", policy.Description) buffer.WriteString(indent + WHITESPACE_2 + "Rules:") buffer.WriteString(strings.ReplaceAll(policy.Rules, "\n", "\n"+indent+WHITESPACE_4)) buffer.WriteString("\n\n") diff --git a/command/acl/token/read/token_read_test.go b/command/acl/token/read/token_read_test.go index 69df72e72917..e793971f1c08 100644 --- a/command/acl/token/read/token_read_test.go +++ b/command/acl/token/read/token_read_test.go @@ -5,7 +5,6 @@ package tokenread import ( "encoding/json" - "fmt" "strings" "testing" @@ -68,7 +67,7 @@ func TestTokenReadCommand_Pretty(t *testing.T) { assert.Empty(t, ui.ErrorWriter.String()) output := ui.OutputWriter.String() - assert.Contains(t, output, fmt.Sprintf("test")) + assert.Contains(t, output, "test") assert.Contains(t, output, token.AccessorID) assert.Contains(t, output, token.SecretID) } @@ -162,7 +161,7 @@ func TestTokenReadCommand_Self(t *testing.T) { assert.Empty(t, ui.ErrorWriter.String()) output := ui.OutputWriter.String() - assert.Contains(t, output, fmt.Sprintf("test")) + assert.Contains(t, output, "test") assert.Contains(t, output, token.AccessorID) assert.Contains(t, output, token.SecretID) } diff --git a/command/catalog/list/nodes/catalog_list_nodes.go b/command/catalog/list/nodes/catalog_list_nodes.go index 1d1f3912f225..4388d753f77f 100644 --- a/command/catalog/list/nodes/catalog_list_nodes.go +++ b/command/catalog/list/nodes/catalog_list_nodes.go @@ -144,9 +144,7 @@ func (c *cmd) Run(args []string) int { // printNodes accepts a list of nodes and prints information in a tabular // format about the nodes. func printNodes(nodes []*api.Node, detailed bool) (string, error) { - var result []string - - result = detailedNodes(nodes, detailed) + var result []string = detailedNodes(nodes, detailed) return columnize.Format(result, &columnize.Config{Delim: string([]byte{0x1f})}), nil } diff --git a/command/cli/cli.go b/command/cli/cli.go index a0bb5d78ddf7..3a0362206131 100644 --- a/command/cli/cli.go +++ b/command/cli/cli.go @@ -33,11 +33,11 @@ type BasicUI struct { } func (b *BasicUI) Stdout() io.Writer { - return b.BasicUi.Writer + return b.Writer } func (b *BasicUI) Stderr() io.Writer { - return b.BasicUi.ErrorWriter + return b.ErrorWriter } func (b *BasicUI) HeaderOutput(s string) { diff --git a/command/config/config.go b/command/config/config.go index ed54954cbeb9..d6391d9629f9 100644 --- a/command/config/config.go +++ b/command/config/config.go @@ -95,7 +95,7 @@ func KindSpecificWriteWarning(reqEntry api.ConfigEntry) string { return WarningProxyDefaultsPermissiveMTLS } case *api.MeshConfigEntry: - if req.AllowEnablingPermissiveMutualTLS == true { + if req.AllowEnablingPermissiveMutualTLS { return WarningMeshAllowEnablingPermissiveMutualTLS } } diff --git a/command/connect/envoy/envoy.go b/command/connect/envoy/envoy.go index b7520cbacde4..30ca5d2882cd 100644 --- a/command/connect/envoy/envoy.go +++ b/command/connect/envoy/envoy.go @@ -633,7 +633,7 @@ func (c *cmd) templateArgs() (*BootstrapTplArgs, error) { if err != nil { return nil, err } - caPEM = strings.Replace(strings.Join(pems, ""), "\n", "\\n", -1) + caPEM = strings.ReplaceAll(strings.Join(pems, ""), "\n", "\\n") return &BootstrapTplArgs{ GRPC: xdsAddr, diff --git a/command/connect/envoy/envoy_test.go b/command/connect/envoy/envoy_test.go index 64fd46c15883..e4c71fde6760 100644 --- a/command/connect/envoy/envoy_test.go +++ b/command/connect/envoy/envoy_test.go @@ -142,7 +142,7 @@ func TestGenerateConfig(t *testing.T) { require.NoError(t, err) rootPEM := string(b) - rootPEM = strings.Replace(rootPEM, "\n", "\\n", -1) + rootPEM = strings.ReplaceAll(rootPEM, "\n", "\\n") b, err = os.ReadFile("../../../test/ca_path/cert1.crt") require.NoError(t, err) @@ -151,7 +151,7 @@ func TestGenerateConfig(t *testing.T) { b, err = os.ReadFile("../../../test/ca_path/cert2.crt") require.NoError(t, err) pathPEM += string(b) - pathPEM = strings.Replace(pathPEM, "\n", "\\n", -1) + pathPEM = strings.ReplaceAll(pathPEM, "\n", "\\n") cases := []generateConfigTestCase{ { diff --git a/command/connect/envoy/flags.go b/command/connect/envoy/flags.go index 9e5f1629b7e9..59222805c1e1 100644 --- a/command/connect/envoy/flags.go +++ b/command/connect/envoy/flags.go @@ -86,7 +86,7 @@ func (s *ServiceAddressMapValue) String() string { buf := new(strings.Builder) for k, v := range s.value { addr := net.JoinHostPort(v.Address, strconv.Itoa(v.Port)) - buf.WriteString(fmt.Sprintf("%v=%v,", k, addr)) + fmt.Fprintf(buf, "%v=%v,", k, addr) } return buf.String() } diff --git a/command/connect/proxy/proxy.go b/command/connect/proxy/proxy.go index 840a27fc6a7c..4bd806540704 100644 --- a/command/connect/proxy/proxy.go +++ b/command/connect/proxy/proxy.go @@ -121,7 +121,7 @@ func (c *cmd) Run(args []string) int { return 1 } if len(c.flags.Args()) > 0 { - c.UI.Error(fmt.Sprintf("Should have no non-flag arguments.")) + c.UI.Error("Should have no non-flag arguments.") return 1 } @@ -351,7 +351,7 @@ func (c *cmd) configWatcher(client *api.Client) (proxyImpl.ConfigWatcher, error) listener.BindPort = port listener.LocalServiceAddress = c.serviceAddr } else { - c.UI.Info(fmt.Sprintf(" Public listener: Disabled")) + c.UI.Info(" Public listener: Disabled") } return proxyImpl.NewStaticConfigWatcher(&proxyImpl.Config{ diff --git a/command/connect/redirecttraffic/redirect_traffic.go b/command/connect/redirecttraffic/redirect_traffic.go index 8a597696b7f0..ed2046e1a193 100644 --- a/command/connect/redirecttraffic/redirect_traffic.go +++ b/command/connect/redirecttraffic/redirect_traffic.go @@ -248,21 +248,13 @@ func (c *cmd) generateConfigFromFlags() (iptables.Config, error) { } } - for _, port := range c.excludeInboundPorts { - cfg.ExcludeInboundPorts = append(cfg.ExcludeInboundPorts, port) - } + cfg.ExcludeInboundPorts = append(cfg.ExcludeInboundPorts, c.excludeInboundPorts...) - for _, port := range c.excludeOutboundPorts { - cfg.ExcludeOutboundPorts = append(cfg.ExcludeOutboundPorts, port) - } + cfg.ExcludeOutboundPorts = append(cfg.ExcludeOutboundPorts, c.excludeOutboundPorts...) - for _, cidr := range c.excludeOutboundCIDRs { - cfg.ExcludeOutboundCIDRs = append(cfg.ExcludeOutboundCIDRs, cidr) - } + cfg.ExcludeOutboundCIDRs = append(cfg.ExcludeOutboundCIDRs, c.excludeOutboundCIDRs...) - for _, uid := range c.excludeUIDs { - cfg.ExcludeUIDs = append(cfg.ExcludeUIDs, uid) - } + cfg.ExcludeUIDs = append(cfg.ExcludeUIDs, c.excludeUIDs...) return cfg, nil } diff --git a/command/exec/exec.go b/command/exec/exec.go index 53026a6f8c87..7e108448cce4 100644 --- a/command/exec/exec.go +++ b/command/exec/exec.go @@ -158,7 +158,7 @@ func (c *cmd) Run(args []string) int { } defer c.destroyData() if c.conf.verbose { - c.UI.Info(fmt.Sprintf("Uploaded remote execution spec")) + c.UI.Info("Uploaded remote execution spec") } // Wait for replication. This is done so that when the event is diff --git a/command/flags/flag_slice_value_test.go b/command/flags/flag_slice_value_test.go index 24187f3f4183..573466f35006 100644 --- a/command/flags/flag_slice_value_test.go +++ b/command/flags/flag_slice_value_test.go @@ -11,8 +11,7 @@ import ( func TestAppendSliceValue_implements(t *testing.T) { t.Parallel() - var raw interface{} - raw = new(AppendSliceValue) + var raw interface{} = new(AppendSliceValue) if _, ok := raw.(flag.Value); !ok { t.Fatalf("AppendSliceValue should be a Value") } diff --git a/command/intention/check/check.go b/command/intention/check/check.go index dce63c75bc06..ca593fda05ad 100644 --- a/command/intention/check/check.go +++ b/command/intention/check/check.go @@ -45,7 +45,7 @@ func (c *cmd) Run(args []string) int { args = c.flags.Args() if len(args) != 2 { - c.UI.Error(fmt.Sprintf("Error: command requires exactly two arguments: src and dst")) + c.UI.Error("Error: command requires exactly two arguments: src and dst") return 2 } diff --git a/command/intention/delete/delete.go b/command/intention/delete/delete.go index a58ee163e687..85f75b87cf28 100644 --- a/command/intention/delete/delete.go +++ b/command/intention/delete/delete.go @@ -71,7 +71,7 @@ func (c *cmd) Run(args []string) int { return 1 } - c.UI.Output(fmt.Sprintf("Intention deleted.")) + c.UI.Output("Intention deleted.") return 0 } diff --git a/command/intention/list/intention_list.go b/command/intention/list/intention_list.go index 408f9d8dcd09..8c69e9c8cc51 100644 --- a/command/intention/list/intention_list.go +++ b/command/intention/list/intention_list.go @@ -53,7 +53,7 @@ func (c *cmd) Run(args []string) int { } if len(ixns) == 0 { - c.UI.Error(fmt.Sprintf("There are no intentions.")) + c.UI.Error("There are no intentions.") return 2 } diff --git a/command/intention/match/match.go b/command/intention/match/match.go index ee115a7b1ad8..2c5d45ca2046 100644 --- a/command/intention/match/match.go +++ b/command/intention/match/match.go @@ -54,12 +54,12 @@ func (c *cmd) Run(args []string) int { args = c.flags.Args() if len(args) != 1 { - c.UI.Error(fmt.Sprintf("Error: command requires exactly one argument: src or dst")) + c.UI.Error("Error: command requires exactly one argument: src or dst") return 1 } if c.flagSource && c.flagDestination { - c.UI.Error(fmt.Sprintf("Error: only one of -source or -destination may be specified")) + c.UI.Error("Error: only one of -source or -destination may be specified") return 1 } diff --git a/command/keygen/keygen.go b/command/keygen/keygen.go index e2907bda0c0d..725a4e03005f 100644 --- a/command/keygen/keygen.go +++ b/command/keygen/keygen.go @@ -42,7 +42,7 @@ func (c *cmd) Run(args []string) int { return 1 } if n != 32 { - c.UI.Error(fmt.Sprintf("Couldn't read enough entropy. Generate more entropy!")) + c.UI.Error("Couldn't read enough entropy. Generate more entropy!") return 1 } diff --git a/command/keyring/keyring.go b/command/keyring/keyring.go index 0e4756f6191f..4dcd4272bbad 100644 --- a/command/keyring/keyring.go +++ b/command/keyring/keyring.go @@ -214,7 +214,7 @@ func poolName(dc string, wan bool, partition, segment string) string { func formatMessages(messages map[string]string) string { b := new(strings.Builder) for from, msg := range messages { - b.WriteString(fmt.Sprintf(" ===> %s: %s\n", from, msg)) + fmt.Fprintf(b, " ===> %s: %s\n", from, msg) } return b.String() } @@ -222,7 +222,7 @@ func formatMessages(messages map[string]string) string { func formatKeys(keys map[string]int, total int) string { b := new(strings.Builder) for key, num := range keys { - b.WriteString(fmt.Sprintf(" %s [%d/%d]\n", key, num, total)) + fmt.Fprintf(b, " %s [%d/%d]\n", key, num, total) } return b.String() } diff --git a/command/kv/get/kv_get.go b/command/kv/get/kv_get.go index 4abf0251751e..4ca5e0e7386a 100644 --- a/command/kv/get/kv_get.go +++ b/command/kv/get/kv_get.go @@ -89,7 +89,7 @@ func (c *cmd) Run(args []string) int { // If the key is empty and we are not doing a recursive or key-based lookup, // this is an error. - if key == "" && !(c.recurse || c.keys) { + if key == "" && (!c.recurse && !c.keys) { c.UI.Error("Error! Missing KEY argument") return 1 } @@ -124,7 +124,7 @@ func (c *cmd) Run(args []string) int { c.UI.Info("") } } else { - c.UI.Info(fmt.Sprintf("%s", pair.Key)) + c.UI.Info(pair.Key) } } return 0 diff --git a/command/lock/lock.go b/command/lock/lock.go index a662babe041f..5fb588b5e2b7 100644 --- a/command/lock/lock.go +++ b/command/lock/lock.go @@ -122,7 +122,7 @@ func (c *cmd) run(args []string, lu **LockUnlock) int { // Check the limit if c.limit <= 0 { - c.UI.Error(fmt.Sprintf("Lock holder limit must be positive")) + c.UI.Error("Lock holder limit must be positive") return 1 } diff --git a/command/login/login.go b/command/login/login.go index 0ab523785292..419e8258bdc6 100644 --- a/command/login/login.go +++ b/command/login/login.go @@ -77,16 +77,16 @@ func (c *cmd) Run(args []string) int { return 1 } if len(c.flags.Args()) > 0 { - c.UI.Error(fmt.Sprintf("Should have no non-flag arguments.")) + c.UI.Error("Should have no non-flag arguments.") return 1 } if c.authMethodName == "" { - c.UI.Error(fmt.Sprintf("Missing required '-method' flag")) + c.UI.Error("Missing required '-method' flag") return 1 } if c.tokenSinkFile == "" { - c.UI.Error(fmt.Sprintf("Missing required '-token-sink-file' flag")) + c.UI.Error("Missing required '-token-sink-file' flag") return 1 } diff --git a/command/logout/logout.go b/command/logout/logout.go index 35365f446954..1590ccba2f5d 100644 --- a/command/logout/logout.go +++ b/command/logout/logout.go @@ -38,7 +38,7 @@ func (c *cmd) Run(args []string) int { return 1 } if len(c.flags.Args()) > 0 { - c.UI.Error(fmt.Sprintf("Should have no non-flag arguments.")) + c.UI.Error("Should have no non-flag arguments.") return 1 } diff --git a/command/operator/autopilot/state/formatter.go b/command/operator/autopilot/state/formatter.go index 11cec09c6a16..7ee50a5ccc1b 100644 --- a/command/operator/autopilot/state/formatter.go +++ b/command/operator/autopilot/state/formatter.go @@ -50,7 +50,7 @@ type prettyFormatter struct { func outputStringSlice(buffer *bytes.Buffer, indent string, values []string) { for _, val := range values { - buffer.WriteString(fmt.Sprintf("%s%s\n", indent, val)) + fmt.Fprintf(buffer, "%s%s\n", indent, val) } } @@ -96,7 +96,7 @@ func formatServer(srv *api.AutopilotServer) string { buffer.WriteString(fmt.Sprintf(" Read Replica: %t\n", srv.ReadReplica)) } if len(srv.Meta) > 0 { - buffer.WriteString(fmt.Sprintf(" Meta\n")) + buffer.WriteString(" Meta\n") var outputs []mapOutput for k, v := range srv.Meta { outputs = append(outputs, mapOutput{key: k, value: fmt.Sprintf(" %q: %q\n", k, v)}) diff --git a/command/peering/exportedservices/exported_services.go b/command/peering/exportedservices/exported_services.go index d075257b33cc..8d3d6b65db16 100644 --- a/command/peering/exportedservices/exported_services.go +++ b/command/peering/exportedservices/exported_services.go @@ -115,15 +115,15 @@ func formatExportedServices(services []structs.ServiceID) string { result := make([]string, 0, len(services)+1) - if services[0].EnterpriseMeta.ToEnterprisePolicyMeta() != nil { + if services[0].ToEnterprisePolicyMeta() != nil { result = append(result, "Partition\x1fNamespace\x1fService Name") } for _, svc := range services { - if svc.EnterpriseMeta.ToEnterprisePolicyMeta() == nil { + if svc.ToEnterprisePolicyMeta() == nil { result = append(result, svc.ID) } else { - result = append(result, fmt.Sprintf("%s\x1f%s\x1f%s", svc.EnterpriseMeta.PartitionOrDefault(), svc.EnterpriseMeta.NamespaceOrDefault(), svc.ID)) + result = append(result, fmt.Sprintf("%s\x1f%s\x1f%s", svc.PartitionOrDefault(), svc.NamespaceOrDefault(), svc.ID)) } } diff --git a/command/peering/list/list.go b/command/peering/list/list.go index 10e85d9b582f..467ccecca904 100644 --- a/command/peering/list/list.go +++ b/command/peering/list/list.go @@ -88,7 +88,7 @@ func (c *cmd) Run(args []string) int { } if len(res) == 0 { - c.UI.Info(fmt.Sprintf("There are no peering connections.")) + c.UI.Info("There are no peering connections.") return 0 } diff --git a/command/resource/client/client.go b/command/resource/client/client.go index c1ff9a1dec4e..454ebfc75537 100644 --- a/command/resource/client/client.go +++ b/command/resource/client/client.go @@ -569,9 +569,7 @@ func (c *Client) Headers() http.Header { ret := make(http.Header) for k, v := range c.headers { - for _, val := range v { - ret[k] = append(ret[k], val) - } + ret[k] = append(ret[k], v...) } return ret @@ -993,6 +991,6 @@ func generateUnexpectedResponseCodeError(resp *http.Response) error { io.Copy(&buf, resp.Body) CloseResponseBody(resp) - trimmed := strings.TrimSpace(string(buf.Bytes())) + trimmed := strings.TrimSpace(buf.String()) return StatusError{Code: resp.StatusCode, Body: trimmed} } diff --git a/command/resource/delete-grpc/delete.go b/command/resource/delete-grpc/delete.go index c924a6bb9dc3..9a63dee0ee08 100644 --- a/command/resource/delete-grpc/delete.go +++ b/command/resource/delete-grpc/delete.go @@ -61,7 +61,7 @@ func (c *cmd) Run(args []string) int { // collect resource type, name and tenancy if c.flags.Lookup("f").Value.String() != "" { if c.filePath == "" { - c.UI.Error(fmt.Sprintf("Please provide an input file with resource definition")) + c.UI.Error("Please provide an input file with resource definition") return 1 } parsedResource, err := resource.ParseResourceFromFile(c.filePath) diff --git a/command/resource/delete/delete.go b/command/resource/delete/delete.go index bbe2d0413945..039834c64a41 100644 --- a/command/resource/delete/delete.go +++ b/command/resource/delete/delete.go @@ -81,7 +81,7 @@ func (c *cmd) Run(args []string) int { Token: c.http.Token(), } } else { - c.UI.Error(fmt.Sprintf("Please provide an input file with resource definition")) + c.UI.Error("Please provide an input file with resource definition") return 1 } } else { diff --git a/command/resource/helper.go b/command/resource/helper.go index 69a06d9cc1a7..5199e34cb0fa 100644 --- a/command/resource/helper.go +++ b/command/resource/helper.go @@ -272,9 +272,9 @@ func (resource *Resource) List(gvk *GVK, q *client.QueryOptions) (*ListResponse, func InferTypeFromResourceType(resourceType string) (*pbresource.Type, error) { s := strings.Split(resourceType, ".") - switch length := len(s); { + switch length := len(s); length { // only kind is provided - case length == 1: + case 1: kindToGVKMap := BuildKindToGVKMap() kind := strings.ToLower(s[0]) switch len(kindToGVKMap[kind]) { @@ -294,7 +294,7 @@ func InferTypeFromResourceType(resourceType string) (*pbresource.Type, error) { default: return nil, fmt.Errorf("The shorthand name has conflicts %v, please use the full name", kindToGVKMap[s[0]]) } - case length == 3: + case 3: return &pbresource.Type{ Group: s[0], GroupVersion: s[1], diff --git a/command/resource/list-grpc/list.go b/command/resource/list-grpc/list.go index eea7621b9eff..68b6a85cbf49 100644 --- a/command/resource/list-grpc/list.go +++ b/command/resource/list-grpc/list.go @@ -65,7 +65,7 @@ func (c *cmd) Run(args []string) int { // collect resource type, name and tenancy if c.flags.Lookup("f").Value.String() != "" { if c.filePath == "" { - c.UI.Error(fmt.Sprintf("Please provide an input file with resource definition")) + c.UI.Error("Please provide an input file with resource definition") return 1 } parsedResource, err := resource.ParseResourceFromFile(c.filePath) diff --git a/command/resource/list/list.go b/command/resource/list/list.go index 86e5fd875fc0..dbb64390e8a2 100644 --- a/command/resource/list/list.go +++ b/command/resource/list/list.go @@ -81,7 +81,7 @@ func (c *cmd) Run(args []string) int { RequireConsistent: !c.http.Stale(), } } else { - c.UI.Error(fmt.Sprintf("Please provide an input file with resource definition")) + c.UI.Error("Please provide an input file with resource definition") return 1 } } else { diff --git a/command/resource/read-grpc/read.go b/command/resource/read-grpc/read.go index c681074ba708..75846aacb491 100644 --- a/command/resource/read-grpc/read.go +++ b/command/resource/read-grpc/read.go @@ -62,7 +62,7 @@ func (c *cmd) Run(args []string) int { // collect resource type, name and tenancy if c.flags.Lookup("f").Value.String() != "" { if c.filePath == "" { - c.UI.Error(fmt.Sprintf("Please provide an input file with resource definition")) + c.UI.Error("Please provide an input file with resource definition") return 1 } parsedResource, err := resource.ParseResourceFromFile(c.filePath) diff --git a/command/resource/read/read.go b/command/resource/read/read.go index 14c38c45f48e..398a30e9e580 100644 --- a/command/resource/read/read.go +++ b/command/resource/read/read.go @@ -83,7 +83,7 @@ func (c *cmd) Run(args []string) int { RequireConsistent: !c.http.Stale(), } } else { - c.UI.Error(fmt.Sprintf("Please provide an input file with resource definition")) + c.UI.Error("Please provide an input file with resource definition") return 1 } } else { diff --git a/command/services/export/export.go b/command/services/export/export.go index 49a575660200..eae19fba6bd0 100644 --- a/command/services/export/export.go +++ b/command/services/export/export.go @@ -104,7 +104,7 @@ func (c *cmd) Run(args []string) int { c.UI.Error(fmt.Sprintf("Error writing config entry: %s", err)) return 1 } else if !ok { - c.UI.Error(fmt.Sprintf("Config entry was changed during update. Please try again")) + c.UI.Error("Config entry was changed during update. Please try again") return 1 } diff --git a/command/snapshot/inspect/formatter_test.go b/command/snapshot/inspect/formatter_test.go index 48b8d1da4d96..4942a872eb01 100644 --- a/command/snapshot/inspect/formatter_test.go +++ b/command/snapshot/inspect/formatter_test.go @@ -4,7 +4,6 @@ package inspect import ( - "fmt" "testing" "github.com/stretchr/testify/require" @@ -46,7 +45,7 @@ func TestFormat(t *testing.T) { actual, err := formatter.Format(&info) require.NoError(t, err) - gName := fmt.Sprintf("%s", fmtName) + gName := fmtName expected := golden(t, gName, actual) require.Equal(t, expected, actual) diff --git a/command/version/formatter_test.go b/command/version/formatter_test.go index 45e4019dfb5c..ae36d172be7b 100644 --- a/command/version/formatter_test.go +++ b/command/version/formatter_test.go @@ -5,7 +5,6 @@ package version import ( "flag" - "fmt" "os" "path/filepath" "testing" @@ -60,7 +59,7 @@ func TestFormat(t *testing.T) { actual, err := formatter.Format(&info) require.NoError(t, err) - gName := fmt.Sprintf("%s", fmtName) + gName := fmtName expected := golden(t, gName, actual) require.Equal(t, expected, actual) diff --git a/connect/certgen/certgen.go b/connect/certgen/certgen.go index 509e7f8df4f3..65509230f7e3 100644 --- a/connect/certgen/certgen.go +++ b/connect/certgen/certgen.go @@ -47,8 +47,8 @@ func main() { var numCAs = 2 var services = []string{"web", "db", "cache"} var outDir string - var keyType string = "ec" - var keyBits int = 256 + var keyType = "ec" + var keyBits = 256 flag.StringVar(&outDir, "out-dir", "", "REQUIRED: the dir to write certificates to") diff --git a/internal/controller/controllertest/builder.go b/internal/controller/controllertest/builder.go index 8754ad355200..5d594202c8fc 100644 --- a/internal/controller/controllertest/builder.go +++ b/internal/controller/controllertest/builder.go @@ -46,9 +46,7 @@ func (b *Builder) WithResourceRegisterFns(registerFns ...func(resource.Registry) // WithControllerRegisterFns allows configuring a set of controllers that should be registered // with the controller manager and executed during Run. func (b *Builder) WithControllerRegisterFns(registerFns ...func(*controller.Manager)) *Builder { - for _, registerFn := range registerFns { - b.controllerRegisterFns = append(b.controllerRegisterFns, registerFn) - } + b.controllerRegisterFns = append(b.controllerRegisterFns, registerFns...) return b } diff --git a/internal/resource/decode_test.go b/internal/resource/decode_test.go index 9df601c901c9..f0bd58ceba27 100644 --- a/internal/resource/decode_test.go +++ b/internal/resource/decode_test.go @@ -53,9 +53,9 @@ func TestGetDecodedResource(t *testing.T) { require.NotNil(t, got) // Clone generated fields over. - res.Id.Uid = got.Resource.Id.Uid - res.Version = got.Resource.Version - res.Generation = got.Resource.Generation + res.Id.Uid = got.Id.Uid + res.Version = got.Version + res.Generation = got.Generation // Clone defaulted fields over data.Genre = pbdemo.Genre_GENRE_DISCO diff --git a/internal/resource/protoc-gen-deepcopy/internal/generate/generate.go b/internal/resource/protoc-gen-deepcopy/internal/generate/generate.go index afa8dda7f621..2aa2ae4e9b1e 100644 --- a/internal/resource/protoc-gen-deepcopy/internal/generate/generate.go +++ b/internal/resource/protoc-gen-deepcopy/internal/generate/generate.go @@ -10,7 +10,7 @@ import ( func Generate(gen *protogen.Plugin) error { for _, file := range gen.Files { - if file.Generate != true { + if !file.Generate { continue } if len(file.Messages) == 0 { diff --git a/internal/resource/protoc-gen-json-shim/internal/generate/generate.go b/internal/resource/protoc-gen-json-shim/internal/generate/generate.go index 1c02c5df4ac8..d18f3441e6de 100644 --- a/internal/resource/protoc-gen-json-shim/internal/generate/generate.go +++ b/internal/resource/protoc-gen-json-shim/internal/generate/generate.go @@ -13,7 +13,7 @@ import ( func Generate(gen *protogen.Plugin) error { for _, file := range gen.Files { - if file.Generate != true { + if !file.Generate { continue } if len(file.Messages) == 0 { @@ -62,9 +62,9 @@ func Generate(gen *protogen.Plugin) error { func FileName(file *protogen.File) string { fname := path.Base(file.Proto.GetName()) - fname = strings.Replace(fname, ".proto", "", -1) - fname = strings.Replace(fname, "-", "_", -1) - fname = strings.Replace(fname, ".", "_", -1) + fname = strings.ReplaceAll(fname, ".proto", "") + fname = strings.ReplaceAll(fname, "-", "_") + fname = strings.ReplaceAll(fname, ".", "_") return toCamelInitCase(fname, true) } diff --git a/lib/hoststats/cpu_test.go b/lib/hoststats/cpu_test.go index dcc1df9aab50..aa6f648d72d3 100644 --- a/lib/hoststats/cpu_test.go +++ b/lib/hoststats/cpu_test.go @@ -24,7 +24,7 @@ func TestHostStats_CPU(t *testing.T) { // Collect twice so we can calculate percents we need to generate some work // so that the cpu values change hs.collect() - for begin := time.Now(); time.Now().Sub(begin) < 100*time.Millisecond; { + for begin := time.Now(); time.Since(begin) < 100*time.Millisecond; { } hs.collect() stats := hs.Stats() diff --git a/lib/template/hil.go b/lib/template/hil.go index 502f10d258b2..a53e95570dc4 100644 --- a/lib/template/hil.go +++ b/lib/template/hil.go @@ -14,7 +14,7 @@ import ( // InterpolateHIL processes the string as if it were HIL and interpolates only // the provided string->string map as possible variables. func InterpolateHIL(s string, vars map[string]string, lowercase bool) (string, error) { - if strings.Index(s, "${") == -1 { + if !strings.Contains(s, "${") { // Skip going to the trouble of parsing something that has no HIL. return s, nil } diff --git a/proto/private/pbservice/convert_test.go b/proto/private/pbservice/convert_test.go index 5b3c97680ef6..0e07c4d5506d 100644 --- a/proto/private/pbservice/convert_test.go +++ b/proto/private/pbservice/convert_test.go @@ -69,12 +69,12 @@ func assertEqual(t *testing.T, x, y interface{}) { // practice they are constrained to 32 bits, and the protobuf types use (u)int32. // The structs types use (u)int64 for any fields that require 64 bits. func randUint32(i *uint, c fuzz.Continue) { - *i = uint(c.Rand.Uint32()) + *i = uint(c.Uint32()) } // see randUint32 func randInt32(i *int, c fuzz.Continue) { - *i = int(c.Rand.Int31()) + *i = int(c.Int31()) } // randStructsConnectProxyConfig is a custom fuzzer function which skips @@ -108,21 +108,21 @@ func randStructsUpstream(u *structs.Upstream, c fuzz.Continue) { // The random data does not contain any ints (or float32) because protobuf // converts them to float64, which will cause the test to fail. func randInterface(m *interface{}, c fuzz.Continue) { - switch c.Rand.Intn(6) { + switch c.Intn(6) { case 0: *m = nil case 1: *m = c.RandBool() case 2: - *m = c.Rand.Float64() + *m = c.Float64() case 3: *m = c.RandString() case 4: - *m = []interface{}{c.RandString(), c.RandBool(), nil, c.Rand.Float64()} + *m = []interface{}{c.RandString(), c.RandBool(), nil, c.Float64()} case 5: *m = map[string]interface{}{ c.RandString(): c.RandString(), - c.RandString(): c.Rand.Float64(), + c.RandString(): c.Float64(), c.RandString(): nil, } } diff --git a/snapshot/snapshot_test.go b/snapshot/snapshot_test.go index 4e9701360dfa..35dcab0aa681 100644 --- a/snapshot/snapshot_test.go +++ b/snapshot/snapshot_test.go @@ -108,10 +108,7 @@ func makeRaft(t *testing.T, dir string) (*raft.Raft, *MockFSM) { } timeout := time.After(10 * time.Second) - for { - if raft.Leader() != "" { - break - } + for raft.Leader() == "" { select { case <-raft.LeaderCh(): diff --git a/testrpc/wait.go b/testrpc/wait.go index b75331045393..3a61eb888485 100644 --- a/testrpc/wait.go +++ b/testrpc/wait.go @@ -38,7 +38,7 @@ func WaitForLeader(t *testing.T, rpc rpcFn, dc string, options ...waitOption) { if err := rpc(context.Background(), "Catalog.ListNodes", args, &out); err != nil { r.Fatalf("Catalog.ListNodes failed: %v", err) } - if !out.QueryMeta.KnownLeader { + if !out.KnownLeader { r.Fatalf("No leader") } if out.Index < 2 { @@ -96,7 +96,7 @@ func WaitUntilNoLeader(t *testing.T, rpc rpcFn, dc string, options ...waitOption if err := rpc(context.Background(), "Catalog.ListNodes", args, &out); err == nil { r.Fatalf("It still has a leader: %#v", out) } - if out.QueryMeta.KnownLeader { + if out.KnownLeader { r.Fatalf("Has still a leader") } })