From 8a6e75ac815a5bdfd9fdbd3528c985d5fdde9c1b Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Tue, 25 Jan 2022 18:41:15 -0500 Subject: [PATCH] rpc: add errNotFound to all Get queries Any query that returns a list of items is not part of this commit. --- agent/consul/acl_endpoint.go | 21 ++++++++++++++++----- agent/consul/coordinate_endpoint.go | 1 + agent/consul/federation_state_endpoint.go | 2 +- agent/consul/kvs_endpoint.go | 15 +++++---------- agent/consul/session_endpoint.go | 1 + 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/agent/consul/acl_endpoint.go b/agent/consul/acl_endpoint.go index 13799c3182..d19836466f 100644 --- a/agent/consul/acl_endpoint.go +++ b/agent/consul/acl_endpoint.go @@ -322,6 +322,9 @@ func (a *ACL) TokenRead(args *structs.ACLTokenGetRequest, reply *structs.ACLToke reply.Index, reply.Token = index, token reply.SourceDatacenter = args.Datacenter + if token == nil { + return errNotFound + } return nil }) } @@ -1045,6 +1048,9 @@ func (a *ACL) PolicyRead(args *structs.ACLPolicyGetRequest, reply *structs.ACLPo } reply.Index, reply.Policy = index, policy + if policy == nil { + return errNotFound + } return nil }) } @@ -1428,6 +1434,9 @@ func (a *ACL) RoleRead(args *structs.ACLRoleGetRequest, reply *structs.ACLRoleRe } reply.Index, reply.Role = index, role + if role == nil { + return errNotFound + } return nil }) } @@ -1795,12 +1804,14 @@ func (a *ACL) BindingRuleRead(args *structs.ACLBindingRuleGetRequest, reply *str return a.srv.blockingQuery(&args.QueryOptions, &reply.QueryMeta, func(ws memdb.WatchSet, state *state.Store) error { index, rule, err := state.ACLBindingRuleGetByID(ws, args.BindingRuleID, &args.EnterpriseMeta) - if err != nil { return err } reply.Index, reply.BindingRule = index, rule + if rule == nil { + return errNotFound + } return nil }) } @@ -2052,16 +2063,16 @@ func (a *ACL) AuthMethodRead(args *structs.ACLAuthMethodGetRequest, reply *struc return a.srv.blockingQuery(&args.QueryOptions, &reply.QueryMeta, func(ws memdb.WatchSet, state *state.Store) error { index, method, err := state.ACLAuthMethodGetByName(ws, args.AuthMethodName, &args.EnterpriseMeta) - if err != nil { return err } - if method != nil { - _ = a.enterpriseAuthMethodTypeValidation(method.Type) + reply.Index, reply.AuthMethod = index, method + if method == nil { + return errNotFound } - reply.Index, reply.AuthMethod = index, method + _ = a.enterpriseAuthMethodTypeValidation(method.Type) return nil }) } diff --git a/agent/consul/coordinate_endpoint.go b/agent/consul/coordinate_endpoint.go index b35d8b2609..26aaa8536f 100644 --- a/agent/consul/coordinate_endpoint.go +++ b/agent/consul/coordinate_endpoint.go @@ -267,6 +267,7 @@ func (c *Coordinate) Node(args *structs.NodeSpecificRequest, reply *structs.Inde }) } reply.Index, reply.Coordinates = index, coords + return nil }) } diff --git a/agent/consul/federation_state_endpoint.go b/agent/consul/federation_state_endpoint.go index da1171a8b7..ac02ee469a 100644 --- a/agent/consul/federation_state_endpoint.go +++ b/agent/consul/federation_state_endpoint.go @@ -124,7 +124,7 @@ func (c *FederationState) Get(args *structs.FederationStateQuery, reply *structs reply.Index = index if fedState == nil { - return nil + return errNotFound } reply.State = fedState diff --git a/agent/consul/kvs_endpoint.go b/agent/consul/kvs_endpoint.go index 2023ea1ea7..9befae5d6a 100644 --- a/agent/consul/kvs_endpoint.go +++ b/agent/consul/kvs_endpoint.go @@ -160,18 +160,13 @@ func (k *KVS) Get(args *structs.KeyRequest, reply *structs.IndexedDirEntries) er } if ent == nil { - // Must provide non-zero index to prevent blocking - // Index 1 is impossible anyways (due to Raft internals) - if index == 0 { - reply.Index = 1 - } else { - reply.Index = index - } + reply.Index = index reply.Entries = nil - } else { - reply.Index = ent.ModifyIndex - reply.Entries = structs.DirEntries{ent} + return errNotFound } + + reply.Index = ent.ModifyIndex + reply.Entries = structs.DirEntries{ent} return nil }) } diff --git a/agent/consul/session_endpoint.go b/agent/consul/session_endpoint.go index ae39a6fc54..bb65938fef 100644 --- a/agent/consul/session_endpoint.go +++ b/agent/consul/session_endpoint.go @@ -198,6 +198,7 @@ func (s *Session) Get(args *structs.SessionSpecificRequest, reply.Sessions = structs.Sessions{session} } else { reply.Sessions = nil + return errNotFound } s.srv.filterACLWithAuthorizer(authz, reply) return nil