-
Notifications
You must be signed in to change notification settings - Fork 25.7k
Update policy parser to allow static methods for entitlement creation #121706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Pinging @elastic/es-core-infra (Team:Core/Infra) |
|
@elasticmachine run elasticsearch-ci/part-3-entitlements |
rjernst
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, a couple thoughts
| try { | ||
| return (Entitlement) entitlementConstructor.newInstance(parameterValues); | ||
| if (entitlementConstructor != null) { | ||
| return (Entitlement) entitlementConstructor.newInstance(parameterValues); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be simpler to keep a MethodHandle and invoke that? Then there would be no difference between the ctor and static method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a quick prototype of this, but it adds additional complexity for error handling, and doesn't save much in lookup. I'm still open to this, but think I would want to do it as a different PR where we look at simplifying the entirety of the method a bit more.
| Policy expected = new Policy( | ||
| "test-policy.yaml", | ||
| List.of(new Scope("entitlement-module-name", List.of(new FileEntitlement("test/path/to/file", "read_write")))) | ||
| List.of(new Scope("entitlement-module-name", List.of(FileEntitlement.create("test/path/to/file", "read_write")))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably worth having explicit test(s) that check the behavior when eg a ctor and method are both annotated, similar to ManyConstructorsEntitlement already here. ie let's not rely on FileEntitlement, let's have explicit tests for this feature of the parser.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add these.
rjernst
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
| ); | ||
| } | ||
|
|
||
| public void testMultipleMethodsAnnotated() throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also have a error test for a non-static method having the annotation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! Good call.
|
@elasticmachine run elasticsearch-ci/part-1-entitlements |
ldematte
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 2
GH status for the CI is "stuck", CI actually passed, I think you are free to merge 👍
…elastic#121706) This updates the PolicyParser to allow static methods to have an ExternalEntitlement annotation. This removes a limitation where constructors cannot properly support type-erasure with different types of data structures for internal entitlement generation and external entitlement generation (for example List<Object> from the parser and List<SomeData> from an internal builder). We continue to enforce that only one constructor/method may be annotated with ExternalEntitlement per Entitlement class.
…elastic#121706) This updates the PolicyParser to allow static methods to have an ExternalEntitlement annotation. This removes a limitation where constructors cannot properly support type-erasure with different types of data structures for internal entitlement generation and external entitlement generation (for example List<Object> from the parser and List<SomeData> from an internal builder). We continue to enforce that only one constructor/method may be annotated with ExternalEntitlement per Entitlement class.
…elastic#121706) This updates the PolicyParser to allow static methods to have an ExternalEntitlement annotation. This removes a limitation where constructors cannot properly support type-erasure with different types of data structures for internal entitlement generation and external entitlement generation (for example List<Object> from the parser and List<SomeData> from an internal builder). We continue to enforce that only one constructor/method may be annotated with ExternalEntitlement per Entitlement class.
…#121706) (#121796) This updates the PolicyParser to allow static methods to have an ExternalEntitlement annotation. This removes a limitation where constructors cannot properly support type-erasure with different types of data structures for internal entitlement generation and external entitlement generation (for example List<Object> from the parser and List<SomeData> from an internal builder). We continue to enforce that only one constructor/method may be annotated with ExternalEntitlement per Entitlement class.
…#121706) (#121797) This updates the PolicyParser to allow static methods to have an ExternalEntitlement annotation. This removes a limitation where constructors cannot properly support type-erasure with different types of data structures for internal entitlement generation and external entitlement generation (for example List<Object> from the parser and List<SomeData> from an internal builder). We continue to enforce that only one constructor/method may be annotated with ExternalEntitlement per Entitlement class.
…#121706) (#121795) This updates the PolicyParser to allow static methods to have an ExternalEntitlement annotation. This removes a limitation where constructors cannot properly support type-erasure with different types of data structures for internal entitlement generation and external entitlement generation (for example List<Object> from the parser and List<SomeData> from an internal builder). We continue to enforce that only one constructor/method may be annotated with ExternalEntitlement per Entitlement class.
This updates the
PolicyParserto allow static methods to have anExternalEntitlementannotation. This removes a limitation where constructors cannot properly support type-erasure with different types of data structures for internal entitlement generation and external entitlement generation (for exampleList<Object>from the parser andList<SomeData>from an internal builder). We continue to enforce that only one constructor/method may be annotated withExternalEntitlementperEntitlementclass.For testing I converted
FileEntitlementto use a static method for the policy parser as this is going to be replaced byFilesEntitlementin the near future.