rpc: add errNotFound to all Get queries

Any query that returns a list of items is not part of this commit.
pull/12110/head
Daniel Nephin 2022-01-25 18:41:15 -05:00
parent 4b33bdf396
commit 8a6e75ac81
5 changed files with 24 additions and 16 deletions

View File

@ -322,6 +322,9 @@ func (a *ACL) TokenRead(args *structs.ACLTokenGetRequest, reply *structs.ACLToke
reply.Index, reply.Token = index, token reply.Index, reply.Token = index, token
reply.SourceDatacenter = args.Datacenter reply.SourceDatacenter = args.Datacenter
if token == nil {
return errNotFound
}
return nil return nil
}) })
} }
@ -1045,6 +1048,9 @@ func (a *ACL) PolicyRead(args *structs.ACLPolicyGetRequest, reply *structs.ACLPo
} }
reply.Index, reply.Policy = index, policy reply.Index, reply.Policy = index, policy
if policy == nil {
return errNotFound
}
return nil return nil
}) })
} }
@ -1428,6 +1434,9 @@ func (a *ACL) RoleRead(args *structs.ACLRoleGetRequest, reply *structs.ACLRoleRe
} }
reply.Index, reply.Role = index, role reply.Index, reply.Role = index, role
if role == nil {
return errNotFound
}
return nil return nil
}) })
} }
@ -1795,12 +1804,14 @@ func (a *ACL) BindingRuleRead(args *structs.ACLBindingRuleGetRequest, reply *str
return a.srv.blockingQuery(&args.QueryOptions, &reply.QueryMeta, return a.srv.blockingQuery(&args.QueryOptions, &reply.QueryMeta,
func(ws memdb.WatchSet, state *state.Store) error { func(ws memdb.WatchSet, state *state.Store) error {
index, rule, err := state.ACLBindingRuleGetByID(ws, args.BindingRuleID, &args.EnterpriseMeta) index, rule, err := state.ACLBindingRuleGetByID(ws, args.BindingRuleID, &args.EnterpriseMeta)
if err != nil { if err != nil {
return err return err
} }
reply.Index, reply.BindingRule = index, rule reply.Index, reply.BindingRule = index, rule
if rule == nil {
return errNotFound
}
return nil return nil
}) })
} }
@ -2052,16 +2063,16 @@ func (a *ACL) AuthMethodRead(args *structs.ACLAuthMethodGetRequest, reply *struc
return a.srv.blockingQuery(&args.QueryOptions, &reply.QueryMeta, return a.srv.blockingQuery(&args.QueryOptions, &reply.QueryMeta,
func(ws memdb.WatchSet, state *state.Store) error { func(ws memdb.WatchSet, state *state.Store) error {
index, method, err := state.ACLAuthMethodGetByName(ws, args.AuthMethodName, &args.EnterpriseMeta) index, method, err := state.ACLAuthMethodGetByName(ws, args.AuthMethodName, &args.EnterpriseMeta)
if err != nil { if err != nil {
return err return err
} }
if method != nil { reply.Index, reply.AuthMethod = index, method
_ = a.enterpriseAuthMethodTypeValidation(method.Type) if method == nil {
return errNotFound
} }
reply.Index, reply.AuthMethod = index, method _ = a.enterpriseAuthMethodTypeValidation(method.Type)
return nil return nil
}) })
} }

View File

@ -267,6 +267,7 @@ func (c *Coordinate) Node(args *structs.NodeSpecificRequest, reply *structs.Inde
}) })
} }
reply.Index, reply.Coordinates = index, coords reply.Index, reply.Coordinates = index, coords
return nil return nil
}) })
} }

View File

@ -124,7 +124,7 @@ func (c *FederationState) Get(args *structs.FederationStateQuery, reply *structs
reply.Index = index reply.Index = index
if fedState == nil { if fedState == nil {
return nil return errNotFound
} }
reply.State = fedState reply.State = fedState

View File

@ -160,18 +160,13 @@ func (k *KVS) Get(args *structs.KeyRequest, reply *structs.IndexedDirEntries) er
} }
if ent == nil { if ent == nil {
// Must provide non-zero index to prevent blocking reply.Index = index
// Index 1 is impossible anyways (due to Raft internals)
if index == 0 {
reply.Index = 1
} else {
reply.Index = index
}
reply.Entries = nil reply.Entries = nil
} else { return errNotFound
reply.Index = ent.ModifyIndex
reply.Entries = structs.DirEntries{ent}
} }
reply.Index = ent.ModifyIndex
reply.Entries = structs.DirEntries{ent}
return nil return nil
}) })
} }

View File

@ -198,6 +198,7 @@ func (s *Session) Get(args *structs.SessionSpecificRequest,
reply.Sessions = structs.Sessions{session} reply.Sessions = structs.Sessions{session}
} else { } else {
reply.Sessions = nil reply.Sessions = nil
return errNotFound
} }
s.srv.filterACLWithAuthorizer(authz, reply) s.srv.filterACLWithAuthorizer(authz, reply)
return nil return nil