Skip to content

Commit

Permalink
fix: fixes disable cache flow
Browse files Browse the repository at this point in the history
Signed-off-by: Nilekh Chaudhari <1626598+nilekhc@users.noreply.github.com>
  • Loading branch information
nilekhc committed Oct 28, 2023
1 parent 3eb381c commit 982e2ba
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions constraint/pkg/client/drivers/rego/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ func externalDataBuiltin(d *Driver) func(bctx rego.BuiltinContext, regorequest *

prepareResponse.Idempotent = true
for _, k := range regoReq.Keys {
if d.providerResponseCache == nil {
// external data response cache is not enabled, add key to call provider
providerRequestKeys = append(providerRequestKeys, k)
continue
}

cachedResponse, err := d.providerResponseCache.Get(
externaldata.CacheKey{
ProviderName: regoReq.ProviderName,
Expand Down Expand Up @@ -70,19 +76,22 @@ func externalDataBuiltin(d *Driver) func(bctx rego.BuiltinContext, regorequest *
return externaldata.HandleError(statusCode, err)
}

for _, item := range externaldataResponse.Response.Items {
d.providerResponseCache.Upsert(
externaldata.CacheKey{
ProviderName: regoReq.ProviderName,
Key: item.Key,
},
externaldata.CacheValue{
Received: time.Now().Unix(),
Value: item.Value,
Error: item.Error,
Idempotent: externaldataResponse.Response.Idempotent,
},
)
// update provider response cache if it is enabled
if d.providerResponseCache != nil {

Check failure on line 80 in constraint/pkg/client/drivers/rego/builtin.go

View workflow job for this annotation

GitHub Actions / Lint

File is not `gofmt`-ed with `-s` (gofmt)
for _, item := range externaldataResponse.Response.Items {
d.providerResponseCache.Upsert(
externaldata.CacheKey{
ProviderName: regoReq.ProviderName,
Key: item.Key,
},
externaldata.CacheValue{
Received: time.Now().Unix(),
Value: item.Value,
Error: item.Error,
Idempotent: externaldataResponse.Response.Idempotent,
},
)
}
}

// we are taking conservative approach here, if any of the response is not idempotent
Expand Down

0 comments on commit 982e2ba

Please sign in to comment.