-
Notifications
You must be signed in to change notification settings - Fork 19
Improve Policy syntax and behavior for required TypeInstance injection #452
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
fc70259 to
73ac57d
Compare
86dcf11 to
a699b9b
Compare
mszostok
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.
We need to decided how we will merge that. I see quite a lot of places where we will have conflicts with #450 😄 We need to reserver some time for that.
BTW Nice test coverage 👍
| return string(bytes), nil | ||
| } | ||
|
|
||
| // HubClient defines Hub client which is able to find TypeInstance Type references. |
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.
tbh I really don't like that those functions landed in types.go. IMO in types.go we should have types definition and max. simple functions associated with a given types, just helpers. As described in PR
Fetch TypeInstance metadata in PolicyEnforcedClient based just on ID
Personally, I think that it will be more readable in my opinion. I know that here it's tightly coupled with given Type which is a plus and it can be used as a part of API but for me it's a bit messy when Types, "business logic" and validation is in single file.
But of course this is just academic discussion and definitely I will not block that from being merged as you did a great job. Maybe later we can discuss our approach in dev team.
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.
As discussed, I will convert the ValidateTypeInstanceMetadata method to a function in a separate package. I will keep validation methods as they are right now.
This change will be introduced in a follow-up pull request, which is #458.
| out = append(out, &graphql.RequiredTypeInstanceReference{ | ||
| ID: item.ID, | ||
| Description: item.Description, |
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.
WDYT about resolving that TypeRef already here?
Currently after applying:
cat > /tmp/aws-policy.yaml << ENDOFFILE
rules:
- interface:
path: cap.interface.containerization.kubernetes.deploy
oneOf:
- implementationConstraints:
path: cap.implementation.aws.containerization.rke2.deploy
inject:
requiredTypeInstances:
- id: "e7f9f8ee-2217-4704-af34-2610727ec567"
typeRef:
path: "cap.type.aws.auth.credentials"
revision: "0.1.0"
- interface:
path: cap.*
oneOf:
- implementationConstraints:
requires:
- path: "cap.core.type.platform.kubernetes"
- implementationConstraints: {}
ENDOFFILE
capact policy apply -f /tmp/aws-policy.yamlWe get:
$ capact pol get
rules:
- interface:
path: cap.interface.containerization.kubernetes.deploy
oneOf:
- implementationConstraints:
path: cap.implementation.aws.containerization.rke2.deploy
inject:
requiredTypeInstances:
- id: e7f9f8ee-2217-4704-af34-2610727ec567
- interface:
path: cap.*
oneOf:
- implementationConstraints:
requires:
- path: cap.core.type.platform.kubernetes
- implementationConstraints: {}but IMO it will be nice to see the typeRef too, as we resolve it anyway
Description
Changes proposed in this pull request:
Update syntax for injecting required Type Instances
requiredTypeInstancesfieldinject.typeInstancestoinject.requiredTypeInstancesElegant syntax comparison table (inspired by this PR):
remove apiVersion from Policy (as Policy is strictly versioned with Engine component, as the Policy shape is defined in GraphQL API)
Fix printing
nullfor Policy management commands in CLITo do (in a follow-up pull request):
requires.aliaswhen TypeInstances are not injectedTesting
Engine
No additional testing needed as TypeInstance injection is covered by integration tests. See the test setup Global Policy for changes.
CLI
Run:
Related issue(s)
#438