github.com/DerekStrickland/consul@v1.4.5/agent/cache-types/intention_match.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 IntentionMatchName = "intention-match" 12 13 // IntentionMatch supports fetching the intentions via match queries. 14 type IntentionMatch struct { 15 RPC RPC 16 } 17 18 func (c *IntentionMatch) Fetch(opts cache.FetchOptions, req cache.Request) (cache.FetchResult, error) { 19 var result cache.FetchResult 20 21 // The request should be an IntentionQueryRequest. 22 reqReal, ok := req.(*structs.IntentionQueryRequest) 23 if !ok { 24 return result, fmt.Errorf( 25 "Internal cache failure: request wrong type: %T", req) 26 } 27 28 // Set the minimum query index to our current index so we block 29 reqReal.MinQueryIndex = opts.MinIndex 30 reqReal.MaxQueryTime = opts.Timeout 31 32 // Fetch 33 var reply structs.IndexedIntentionMatches 34 if err := c.RPC.RPC("Intention.Match", reqReal, &reply); err != nil { 35 return result, err 36 } 37 38 result.Value = &reply 39 result.Index = reply.Index 40 return result, nil 41 } 42 43 func (c *IntentionMatch) SupportsBlocking() bool { 44 return true 45 }