open-policy-agent / open-policy-agent/frameworks
Driver interface `AddConstraint` improvement
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 127
- Forks
- 61
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 13
Description
overview
At the moment, AddConstraint's definition (docs) states:
// AddConstraint adds a Constraint to Driver for a particular Template. Future
// calls to Query may reference the added Constraint. Replaces the existing
// Constraint if it already exists.
AddConstraint(ctx context.Context, constraint *unstructured.Unstructured) error
However, if no Template has already been added, via AddTemplate, the behavior is undefined. At present, the rego driver "fails silently":
solutions
- Define the behavior and enforce it. Update the docs and if the targets is not found err out with some helpful error like
TemplateNotFound
targets, found := ...
if not found, error
- Modify the signature of
AddConstraintto also include the Template that we want to associate the Constraint with. This approach would probably require some rethinking or regrokking of the flow for both AddTemplate and AddConstraint so it may actually be more work than value.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the AddConstraint implementation in constraint/pkg/client/drivers/rego/driver.go at the linked lines, then trace how AddTemplate associates templates and constraints. Resolve whether a missing Template should produce a helpful error or require a signature change, and update the interface documentation and behavior so the undefined case is explicit.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100