Skip to content
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

fix: trace-ebpf flag output #632

Merged
merged 3 commits into from
Apr 9, 2021
Merged

Conversation

krol3
Copy link
Contributor

@krol3 krol3 commented Mar 18, 2021

Related issue #560

  • Using switch and validateOutputFormatValue method to validate the default output format values("table", "table-verbose", "json", "gob","gotemplate=").

@krol3 krol3 force-pushed the issue-560-flag branch 3 times, most recently from 2e47521 to 4fc14ce Compare March 18, 2021 04:52
@simar7 simar7 self-requested a review March 18, 2021 18:02
@@ -175,16 +175,24 @@ Use this flag multiple times to choose multiple capture options
outputParts := strings.SplitN(o, ":", 2)
numParts := len(outputParts)
if numParts == 1 {
if !validateOutputFormatValue(outputParts[0]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of validating when we get inside prepareOutput it will be easier to validate outside, prior to reaching here. So I suggest that before we call prepareOutput we can pass c.StringSlice(output) to another function that can validate all types of possible inputs that can be passed to --output flag.

This will keep the abstraction of prepareOutput to assume the inputs it receives are valid and also make it easier to read and test as it will have less branches. Furthermore testing will be simplified as well as we can just test both functions individually.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regarding validation, I don't think that preparer functions should have validation logic. the XXXConfig struct already has the validation logic

func (cfg OutputConfig) Validate() error {
so we should just use it whenever is needed.

also I think other configs should follow this pattern. wdyt @simar7 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @simar7 . I used the Validate() method and removed the other method that I created.

} else if outputParts[0] == "out-file" {
err := res.Validate()
if err != nil {
return res, fmt.Errorf("%s. Valid format values: 'table', 'table-verbose', 'json', 'gob' or 'gotemplate='. Use '--output help' for more info.", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think this error string should be returned in Validate() itself.

Copy link
Contributor

@grantseltzer grantseltzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nit from me, otherwise this looks good! Will merge after that small change.

Thanks @krol3!

@grantseltzer
Copy link
Contributor

@krol3 once #688 merges you'll need to rebase in order to fix the build, then i'll merge this

@simar7
Copy link
Member

simar7 commented Apr 8, 2021

@krol3 looks like there's a few compile time issues. If you fix those and tests pass, we can merge this in as the rest of the code is good.

@grantseltzer grantseltzer merged commit 2317a86 into aquasecurity:main Apr 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants