Skip to content

Commit

Permalink
rpc: add errNotFound to all Get queries
Browse files Browse the repository at this point in the history
Any query that returns a list of items is not part of this commit.
  • Loading branch information
dnephin committed Feb 15, 2022
1 parent 4b33bdf commit 8a6e75a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 16 deletions.
21 changes: 16 additions & 5 deletions agent/consul/acl_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
Expand Down Expand Up @@ -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
})
}
Expand Down Expand Up @@ -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
})
}
Expand Down Expand Up @@ -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
})
}
Expand Down Expand Up @@ -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
})
}
Expand Down
1 change: 1 addition & 0 deletions agent/consul/coordinate_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ func (c *Coordinate) Node(args *structs.NodeSpecificRequest, reply *structs.Inde
})
}
reply.Index, reply.Coordinates = index, coords

return nil
})
}
2 changes: 1 addition & 1 deletion agent/consul/federation_state_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 5 additions & 10 deletions agent/consul/kvs_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
Expand Down
1 change: 1 addition & 0 deletions agent/consul/session_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8a6e75a

Please sign in to comment.