@@ -38,6 +38,12 @@ func externalDataBuiltin(d *Driver) func(bctx rego.BuiltinContext, regorequest *
38
38
39
39
prepareResponse .Idempotent = true
40
40
for _ , k := range regoReq .Keys {
41
+ if d .providerResponseCache == nil {
42
+ // external data response cache is not enabled, add key to call provider
43
+ providerRequestKeys = append (providerRequestKeys , k )
44
+ continue
45
+ }
46
+
41
47
cachedResponse , err := d .providerResponseCache .Get (
42
48
externaldata.CacheKey {
43
49
ProviderName : regoReq .ProviderName ,
@@ -70,19 +76,22 @@ func externalDataBuiltin(d *Driver) func(bctx rego.BuiltinContext, regorequest *
70
76
return externaldata .HandleError (statusCode , err )
71
77
}
72
78
73
- for _ , item := range externaldataResponse .Response .Items {
74
- d .providerResponseCache .Upsert (
75
- externaldata.CacheKey {
76
- ProviderName : regoReq .ProviderName ,
77
- Key : item .Key ,
78
- },
79
- externaldata.CacheValue {
80
- Received : time .Now ().Unix (),
81
- Value : item .Value ,
82
- Error : item .Error ,
83
- Idempotent : externaldataResponse .Response .Idempotent ,
84
- },
85
- )
79
+ // update provider response cache if it is enabled
80
+ if d .providerResponseCache != nil {
81
+ for _ , item := range externaldataResponse .Response .Items {
82
+ d .providerResponseCache .Upsert (
83
+ externaldata.CacheKey {
84
+ ProviderName : regoReq .ProviderName ,
85
+ Key : item .Key ,
86
+ },
87
+ externaldata.CacheValue {
88
+ Received : time .Now ().Unix (),
89
+ Value : item .Value ,
90
+ Error : item .Error ,
91
+ Idempotent : externaldataResponse .Response .Idempotent ,
92
+ },
93
+ )
94
+ }
86
95
}
87
96
88
97
// we are taking conservative approach here, if any of the response is not idempotent
0 commit comments