From a64686fab61b481319a04916602bd243c9396dc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Cruz?= Date: Fri, 21 Aug 2020 16:42:37 +0100 Subject: [PATCH] testing: Fix govet errors --- agent/consul/acl.go | 2 +- agent/consul/acl_endpoint.go | 12 +++--------- agent/consul/acl_replication_types.go | 10 +++++++--- agent/consul/config_replication.go | 3 ++- agent/consul/federation_state_replication.go | 6 ++++-- agent/consul/leader_federation_state_ae.go | 2 +- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/agent/consul/acl.go b/agent/consul/acl.go index 9161fd78e..49b18d47c 100644 --- a/agent/consul/acl.go +++ b/agent/consul/acl.go @@ -2143,7 +2143,7 @@ func vetNodeTxnOp(op *structs.TxnNodeOp, rule acl.Authorizer) error { var authzContext acl.AuthorizerContext op.FillAuthzContext(&authzContext) - if rule != nil && rule.NodeWrite(op.Node.Node, &authzContext) != acl.Allow { + if rule.NodeWrite(op.Node.Node, &authzContext) != acl.Allow { return acl.ErrPermissionDenied } diff --git a/agent/consul/acl_endpoint.go b/agent/consul/acl_endpoint.go index 11d29a884..ccc9e1b2a 100644 --- a/agent/consul/acl_endpoint.go +++ b/agent/consul/acl_endpoint.go @@ -1225,9 +1225,7 @@ func (a *ACL) PolicyDelete(args *structs.ACLPolicyDeleteRequest, reply *string) return respErr } - if policy != nil { - *reply = policy.Name - } + *reply = policy.Name return nil } @@ -1692,9 +1690,7 @@ func (a *ACL) RoleDelete(args *structs.ACLRoleDeleteRequest, reply *string) erro return respErr } - if role != nil { - *reply = role.Name - } + *reply = role.Name return nil } @@ -2525,9 +2521,7 @@ func (a *ACL) Logout(args *structs.ACLLogoutRequest, reply *bool) error { } // Purge the identity from the cache to prevent using the previous definition of the identity - if token != nil { - a.srv.acls.cache.RemoveIdentity(tokenSecretCacheID(token.SecretID)) - } + a.srv.acls.cache.RemoveIdentity(tokenSecretCacheID(token.SecretID)) if respErr, ok := resp.(error); ok { return respErr diff --git a/agent/consul/acl_replication_types.go b/agent/consul/acl_replication_types.go index a238244cf..c1e29d818 100644 --- a/agent/consul/acl_replication_types.go +++ b/agent/consul/acl_replication_types.go @@ -229,7 +229,8 @@ func (r *aclPolicyReplicator) UpdateLocalBatch(ctx context.Context, srv *Server, if err != nil { return err } - if respErr, ok := resp.(error); ok && err != nil { + + if respErr, ok := resp.(error); ok { return respErr } @@ -336,9 +337,11 @@ func (r *aclRoleReplicator) DeleteLocalBatch(srv *Server, batch []string) error if err != nil { return err } - if respErr, ok := resp.(error); ok && err != nil { + + if respErr, ok := resp.(error); ok { return respErr } + return nil } @@ -364,7 +367,8 @@ func (r *aclRoleReplicator) UpdateLocalBatch(ctx context.Context, srv *Server, s if err != nil { return err } - if respErr, ok := resp.(error); ok && err != nil { + + if respErr, ok := resp.(error); ok { return respErr } diff --git a/agent/consul/config_replication.go b/agent/consul/config_replication.go index 691bcc430..3562859b1 100644 --- a/agent/consul/config_replication.go +++ b/agent/consul/config_replication.go @@ -79,7 +79,8 @@ func (s *Server) reconcileLocalConfig(ctx context.Context, configs []structs.Con if err != nil { return false, fmt.Errorf("Failed to apply config %s: %v", op, err) } - if respErr, ok := resp.(error); ok && err != nil { + + if respErr, ok := resp.(error); ok { return false, fmt.Errorf("Failed to apply config %s: %v", op, respErr) } diff --git a/agent/consul/federation_state_replication.go b/agent/consul/federation_state_replication.go index ac6bc640e..52af2f5dc 100644 --- a/agent/consul/federation_state_replication.go +++ b/agent/consul/federation_state_replication.go @@ -158,7 +158,8 @@ func (r *FederationStateReplicator) PerformDeletions(ctx context.Context, deleti if err != nil { return false, err } - if respErr, ok := resp.(error); ok && err != nil { + + if respErr, ok := resp.(error); ok { return false, respErr } @@ -202,7 +203,8 @@ func (r *FederationStateReplicator) PerformUpdates(ctx context.Context, updatesR if err != nil { return false, err } - if respErr, ok := resp.(error); ok && err != nil { + + if respErr, ok := resp.(error); ok { return false, respErr } diff --git a/agent/consul/leader_federation_state_ae.go b/agent/consul/leader_federation_state_ae.go index 4254e61a3..4e5a8a45b 100644 --- a/agent/consul/leader_federation_state_ae.go +++ b/agent/consul/leader_federation_state_ae.go @@ -219,7 +219,7 @@ func (s *Server) pruneStaleFederationStates() error { if err != nil { return fmt.Errorf("Failed to delete federation state %s: %v", dc, err) } - if respErr, ok := resp.(error); ok && err != nil { + if respErr, ok := resp.(error); ok { return fmt.Errorf("Failed to delete federation state %s: %v", dc, respErr) } }