open-policy-agent/frameworks

[local.Driver] Add methods AddCachedData and RemoveCachedData

willbeason opened this issue · 2 comments

Proposed signatures:

func (d *Driver) AddCachedData(ctx context.Context, obj interface{}) error
func (d *Driver) RemoveCachedData(ctx context.Context, obj interface{}) error

Under the hood these call PutData and DeleteData - AddInventory just allows Driver to choose where to store the data (note that the path string argument is missing).

This should have a corresponding change in Gatekeeper - you may find it helpful to replace gatekeeper's dependency on frameworks with your local repo to figure this out.

For the purposes of this issue, it's fine to cast the data argument passed to client.AddData and return an error if it isn't the correct type. This will break client.testHandler - just use an Unstructured and pick fields that work similarly to how the client.targetData type works. Other than constructing an Unstructured instead of a targetData, this shouldn't require test code to change significantly.

Oh, and "AddInventory" and "RemoveInventory" has to take interface{} and not Unstructured.

Per discussion, "AddCachedData" and "RemoveCachedData" are a better choice since it maps on to our general notion of "cached data" for referential constraints, whereas "inventory" is more of an implementation detail specific to a particular Driver's implementaiton.