feat(core): subject condition set CLI CRUD #78
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds CRUD for subject condition sets, with the JSON relation of
[]*policy.SubjectSets
passed via a string flag or found in a.json
file with the filepath/name provided in a flag on CREATE, and validation that only one is provided at once. On UPDATE, only a JSON string is allowed.There is an open
pflags
issue (since 2022) which is the library under Cobra's flags implementation which affects the Subject Condition Sets (SCSs) flag API: spf13/pflag#370.Unfortunately, this issue means we cannot allow a slice of individual SCSs passed via CLI as we do with
--label
where each individual label passed with--label
populates a[]string
of alllabels
. In this case, if we attempt--subject-set <single subject set json>
to populate a[]string
where each index is a JSON string for a single SCS, we get an errorflag: parse error on line 1, column 3: bare " in non-quoted-field
. Because of this, we must expect all SCSs being created via JSON in the CLI to already be joined into the single array and passed as a single string flag--subject-sets <json array of all subject sets in the SCS>
.There is already support added in this PR for reading from a JSON file to create the SCS, and any time there is JSON in the CLI it is likely it will be added via script instead of manually.
See new issue around admin UX of testing Subject Condition Sets before creating.
Note
This PR was going to introduce reading Subject Sets from a YAML file as well, but yaml struct tags are not generated in the proto-built types. If this is needed, it should be discussed further and separately how the platform could expose YAML tags so consumers do not reimplement them repeatedly and potentially mistakenly. Perhaps a new proto plugin could be utilized.