From a5d9b1d32264de932902806a3ecc7fc5a7669210 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Sun, 28 Nov 2021 14:11:03 -0500 Subject: [PATCH] ca: Add CARoots.Active method Which will be used in the next commit. --- agent/consul/state/connect_ca.go | 12 +----------- agent/structs/connect_ca.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/agent/consul/state/connect_ca.go b/agent/consul/state/connect_ca.go index 0b35d03934..156c79f463 100644 --- a/agent/consul/state/connect_ca.go +++ b/agent/consul/state/connect_ca.go @@ -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) { // Get all the roots since there should never be that many and just // do the filtering in this method. - var result *structs.CARoot idx, roots, err := s.CARoots(ws) - if err == nil { - for _, r := range roots { - if r.Active { - result = r - break - } - } - } - - return idx, result, err + return idx, roots.Active(), err } // CARootSetCAS sets the current CA root state using a check-and-set operation. diff --git a/agent/structs/connect_ca.go b/agent/structs/connect_ca.go index 9da766d757..a556df0745 100644 --- a/agent/structs/connect_ca.go +++ b/agent/structs/connect_ca.go @@ -145,6 +145,20 @@ func (c *CARoot) Clone() *CARoot { // CARoots is a list of CARoot structures. 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. type CASignRequest struct { // Datacenter is the target for this request.