github.com/DerekStrickland/consul@v1.4.5/agent/cache-types/connect_ca_root.go (about) 1 package cachetype 2 3 import ( 4 "fmt" 5 6 "github.com/hashicorp/consul/agent/cache" 7 "github.com/hashicorp/consul/agent/structs" 8 ) 9 10 // Recommended name for registration. 11 const ConnectCARootName = "connect-ca-root" 12 13 // ConnectCARoot supports fetching the Connect CA roots. This is a 14 // straightforward cache type since it only has to block on the given 15 // index and return the data. 16 type ConnectCARoot struct { 17 RPC RPC 18 } 19 20 func (c *ConnectCARoot) Fetch(opts cache.FetchOptions, req cache.Request) (cache.FetchResult, error) { 21 var result cache.FetchResult 22 23 // The request should be a DCSpecificRequest. 24 reqReal, ok := req.(*structs.DCSpecificRequest) 25 if !ok { 26 return result, fmt.Errorf( 27 "Internal cache failure: request wrong type: %T", req) 28 } 29 30 // Set the minimum query index to our current index so we block 31 reqReal.QueryOptions.MinQueryIndex = opts.MinIndex 32 reqReal.QueryOptions.MaxQueryTime = opts.Timeout 33 34 // Fetch 35 var reply structs.IndexedCARoots 36 if err := c.RPC.RPC("ConnectCA.Roots", reqReal, &reply); err != nil { 37 return result, err 38 } 39 40 result.Value = &reply 41 result.Index = reply.QueryMeta.Index 42 return result, nil 43 } 44 45 func (c *ConnectCARoot) SupportsBlocking() bool { 46 return true 47 }