-
Notifications
You must be signed in to change notification settings - Fork 32
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
validate image
: Allow custom Rego variables with new --extra
flag
#1474
Conversation
validate image
: Allow custom Rego variables with new --extra
flag
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1474 +/- ##
==========================================
+ Coverage 80.46% 80.59% +0.12%
==========================================
Files 67 66 -1
Lines 4782 4761 -21
==========================================
- Hits 3848 3837 -11
+ Misses 934 924 -10
Flags with carried forward coverage won't be shown. Click here to find out more.
|
cmd/validate/image.go
Outdated
@@ -393,6 +444,10 @@ func validateImageCmd(validate imageValidationFunc) *cobra.Command { | |||
a RFC3339 formatted value, e.g. 2022-11-18T00:00:00Z. | |||
`)) | |||
|
|||
cmd.Flags().StringSliceVar(&data.extra, "extra", data.extra, hd.Doc(` |
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.
The name "extra" feels not quite specific enough. Something like this perhaps:
cmd.Flags().StringSliceVar(&data.extra, "extra", data.extra, hd.Doc(` | |
cmd.Flags().StringSliceVarP(&data.extraRuleData, "extra-rule-data", "e", data.extraRuleData, hd.Doc(` |
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.
Changed it to your suggestion, but open to other ideas as well. I know we floated override
or override-rule-data
as well.
Let's get some test coverage. |
(Wrong button sorry..) |
75cb590
to
3956707
Compare
06702c1
to
634af83
Compare
@simonbaird I added a unit and acceptance test for the positive case. Had to get a bit hacky for the unit test to work correctly. |
2f0a2f8
to
ab1c07e
Compare
…a flag Signed-off-by: Mark Bestavros <[email protected]>
cmd/validate/image_test.go
Outdated
@@ -673,6 +674,104 @@ configuration: | |||
assert.NoError(t, err) | |||
} | |||
|
|||
func Test_ValidateImageCommandExtraData(t *testing.T) { | |||
validate := func(_ context.Context, component app.SnapshotComponent, _ policy.Policy, _ bool) (*output.Output, error) { |
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.
There is a compile error on this line:
validate := func(_ context.Context, component app.SnapshotComponent, _ policy.Policy, _ bool) (*output.Output, error) { | |
validate := func(_ context.Context, component app.SnapshotComponent, _ policy.Policy, _ []evaluator.Evaluator, _ bool) (*output.Output, error) { |
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 looks like @mbestavros did a rebase that brought in the change in the signature for the validate function. I have questions...
- The only CI check failing right now is the linter. How did "Checks / Test" pass?!
- Why was the linter complaining about this line before when it was obviously correct at the time?
Signed-off-by: Mark Bestavros <[email protected]>
validate image
: Allow custom Rego variables with new --extra
flagvalidate image
: Allow custom Rego variables with new --extra
flag
This PR adds a new option,
--extra
, to theec validate image
command. This argument allows users to inject additional variables into the Rego rule data per source. Syntax is simple:--extra key=value
. The flag can also be used multiple times.This is an evolution of the idea that @lcarva proposed in #1277.
Here's an example output from
ec validate image
with--extra var=value
:This still needs tests added, but it appears to be functional, as seen above.