github.imxd.top/hashicorp/consul@v1.4.5/agent/proxycfg/snapshot.go (about) 1 package proxycfg 2 3 import ( 4 "github.com/hashicorp/consul/agent/structs" 5 "github.com/mitchellh/copystructure" 6 ) 7 8 // ConfigSnapshot captures all the resulting config needed for a proxy instance. 9 // It is meant to be point-in-time coherent and is used to deliver the current 10 // config state to observers who need it to be pushed in (e.g. XDS server). 11 type ConfigSnapshot struct { 12 ProxyID string 13 Address string 14 Port int 15 Proxy structs.ConnectProxyConfig 16 Roots *structs.IndexedCARoots 17 Leaf *structs.IssuedCert 18 UpstreamEndpoints map[string]structs.CheckServiceNodes 19 20 // Skip intentions for now as we don't push those down yet, just pre-warm them. 21 } 22 23 // Valid returns whether or not the snapshot has all required fields filled yet. 24 func (s *ConfigSnapshot) Valid() bool { 25 return s.Roots != nil && s.Leaf != nil 26 } 27 28 // Clone makes a deep copy of the snapshot we can send to other goroutines 29 // without worrying that they will racily read or mutate shared maps etc. 30 func (s *ConfigSnapshot) Clone() (*ConfigSnapshot, error) { 31 snapCopy, err := copystructure.Copy(s) 32 if err != nil { 33 return nil, err 34 } 35 return snapCopy.(*ConfigSnapshot), nil 36 }