ca: Add CARoots.Active method

Which will be used in the next commit.
This commit is contained in:
Daniel Nephin 2021-11-28 14:11:03 -05:00 committed by Daniel Nephin
parent 5f5720837b
commit a5d9b1d322
2 changed files with 15 additions and 11 deletions

View File

@ -252,18 +252,8 @@ func caRootsTxn(tx ReadTxn, ws memdb.WatchSet) (uint64, structs.CARoots, error)
func (s *Store) CARootActive(ws memdb.WatchSet) (uint64, *structs.CARoot, error) { func (s *Store) CARootActive(ws memdb.WatchSet) (uint64, *structs.CARoot, error) {
// Get all the roots since there should never be that many and just // Get all the roots since there should never be that many and just
// do the filtering in this method. // do the filtering in this method.
var result *structs.CARoot
idx, roots, err := s.CARoots(ws) idx, roots, err := s.CARoots(ws)
if err == nil { return idx, roots.Active(), err
for _, r := range roots {
if r.Active {
result = r
break
}
}
}
return idx, result, err
} }
// CARootSetCAS sets the current CA root state using a check-and-set operation. // CARootSetCAS sets the current CA root state using a check-and-set operation.

View File

@ -145,6 +145,20 @@ func (c *CARoot) Clone() *CARoot {
// CARoots is a list of CARoot structures. // CARoots is a list of CARoot structures.
type CARoots []*CARoot type CARoots []*CARoot
// Active returns the single CARoot that is marked as active, or nil if there
// is no active root (ex: when they are no roots).
func (c CARoots) Active() *CARoot {
if c == nil {
return nil
}
for _, r := range c {
if r.Active {
return r
}
}
return nil
}
// CASignRequest is the request for signing a service certificate. // CASignRequest is the request for signing a service certificate.
type CASignRequest struct { type CASignRequest struct {
// Datacenter is the target for this request. // Datacenter is the target for this request.