-
Notifications
You must be signed in to change notification settings - Fork 43
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
rule_type create
: Add option to create multiple rule types at once or read all filed in directory
#748
Conversation
This changes the rule_type create command to be able to take an array of files and create each of them. The intent is to provide a more agile way of using this tool instead of having to do multiple command invocations.
This makes things simpler since we now can pass a directory
rule_type create
: Add option to create multiple rule types at once or read all filed in directory
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.
Some questions, but in general LGTM, feel free to merge
return nil | ||
}, | ||
} | ||
|
||
func validateFilesArg(files []string) 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.
Would this be already useful in util?
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.
Maybe. I plan to migrate policy creation to a similar pattern. Mind if I move this in that PR instead?
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.
sure, whatever is easier for you
|
||
if fi.IsDir() { | ||
// expand directory | ||
err := filepath.Walk(f, func(path string, info fs.FileInfo, err error) 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.
the stdlib documentation seems to suggest that WalkDir
might be faster, but at the same time I don't think it matters for our use-case
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 know it's late, I apparently forgot to hit "submit"... anyway, all my questions were advisory rather than blocking anyway.)
if err != nil { | ||
return fmt.Errorf("error getting grpc connection: %w", err) | ||
} |
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.
(non-blocking curiousity) Why remove util.ExitNicelyOnError
? We seem to use it in a bunch of places.
if files == nil { | ||
return fmt.Errorf("error: file must be set") | ||
} |
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.
Do you want to check len(files) > 0
?
This changes the rule_type create command to be able to take an array of files
and create each of them. The intent is to provide a more agile way of using this
tool instead of having to do multiple command invocations.
If the passed argument is a directory, it'll read all the files in the directory and create rules out of it.