Add support for generic policy iteration when authorizing a request#85
Conversation
a03f59f to
1845891
Compare
This function is identical to PolicySet.IsAuthorized(), but allows a generic iterator of (PolicyID, *Policy) tuples to be passed. This allows for flexibility at the callsite if the caller wants to use some other data structure to hold on to a map of PolicyIDs to *Policy. Note: an All() method is also added to PolicySet which returns an iterator over the internal policy map. Signed-off-by: Patrick Jakubowski <patrick.jakubowski@strongdm.com>
…dule. Signed-off-by: Patrick Jakubowski <patrick.jakubowski@strongdm.com>
1845891 to
4b1e2a3
Compare
Signed-off-by: Patrick Jakubowski <patrick.jakubowski@strongdm.com>
b5b1822 to
adc25f6
Compare
…uthorized() Signed-off-by: Patrick Jakubowski <patrick.jakubowski@strongdm.com>
Signed-off-by: Patrick Jakubowski <patrick.jakubowski@strongdm.com>
Signed-off-by: Patrick Jakubowski <patrick.jakubowski@strongdm.com>
| # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go | ||
|
|
||
| name: Go | ||
| name: Verify |
There was a problem hiding this comment.
I combined build_and_test.yml and golangci-lint.yml (we weren't getting much value out of the parallelism anyway) and switched to using go-version-file so that we only have to update the Go version in one place.
| internalast.Permit().When(internalast.Long(42).ContainsAny(internalast.Long(43))), | ||
| }, | ||
| { | ||
| "opContainsIsEmpty", |
There was a problem hiding this comment.
This is an unrelated change that I made in order to get test coverage back up to 100%
| Conditions: []ast.ConditionType{{Condition: ast.ConditionWhen, Body: ast.NodeTypeHasTag{BinaryNode: ast.BinaryNode{Left: ast.NodeValue{Value: types.Long(42)}, Right: ast.NodeValue{Value: types.String("key")}}}}}}, | ||
| }, | ||
| { | ||
| "opIsEmpty", |
There was a problem hiding this comment.
More test coverage improvements
| NodeTypeExtensionCall{}.isNode() | ||
| NodeTypeIfThenElse{}.isNode() | ||
| NodeTypeLike{}.isNode() | ||
| NodeTypeIsEmpty{}.isNode() |
There was a problem hiding this comment.
More unrelated test improvements.
|
|
||
| p := ast.Permit().PrincipalEq(types.NewEntityUID("Foo::Bar", "Baz")) | ||
| expected := `{ | ||
| t.Run("roundtrip", func(t *testing.T) { |
There was a problem hiding this comment.
More unrelated changes to get test coverage to 100%
…rator as well Signed-off-by: Patrick Jakubowski <patrick.jakubowski@strongdm.com>
philhassey
left a comment
There was a problem hiding this comment.
Let's chat a bit about my comments and see what changes we want. Overall looks good!
Also, add some dummy statements to otherwise empty functions so that they're counted for code coverage purposes. Signed-off-by: Patrick Jakubowski <patrick.jakubowski@strongdm.com>
33e4a70 to
2f5728b
Compare
… method rather than a bare iter.Seq2 Signed-off-by: Patrick Jakubowski <patrick.jakubowski@strongdm.com>
… Authorize() Signed-off-by: Patrick Jakubowski <patrick.jakubowski@strongdm.com>
Signed-off-by: Patrick Jakubowski <patrick.jakubowski@strongdm.com>
371baa0 to
3bd0436
Compare
Signed-off-by: Patrick Jakubowski <patrick.jakubowski@strongdm.com>
3bd0436 to
680ff11
Compare
…rary Signed-off-by: Patrick Jakubowski <patrick.jakubowski@strongdm.com>
…n of golang.org/x/exp that introduces constraints Signed-off-by: Patrick Jakubowski <patrick.jakubowski@strongdm.com>
680ff11 to
f06dc9d
Compare
philhassey
left a comment
There was a problem hiding this comment.
LGTM, with allowance for some brief bike-shedding
Issue #, if available:
Description of changes: Adds a new top-level
Authorize()function which accepts a generic iterator of policies.This functionality supersedes the existing
PolicySet.IsAuthorized()method (which is now implemented in terms ofAuthorize()) and allows for more exotic policy injection a la theEntityGetterinterface. This means that policy can be lazily loaded from an external source and passed to theAuthorize()function via the iterator or policy sets can be combined for authorization without having toClone()them into a newPolicySet.Authorize()can only be called from packages built using Go 1.23 or later.Also, several other types have gotten some iterator love:
types.EntityUIDSetgets anAll()method that returns an iterator over the entity UIDstypes.Setgets anAll()method that returns an iterator over theValues in the settypes.Recordgets three new methods that return iterators:All(),Keys(), andValues()which behave similarly tomaps.All(),maps.Keys(), andmaps.Values().types.PolicySetgets anAll()method that returns an iterator over thePolicyIDs and*Policys in thePolicySet.