-
Notifications
You must be signed in to change notification settings - Fork 21
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
🐛 Load provider flags from environment variables #4847
Conversation
This change allows `cnquery` to load all provider flags via environment variables. For instance, if a provider exposes a flag named `foo`, the user can export the environment variable `MONDOO_FOO` to provide a value. The trick here was to switch loading the flag values from `cobra` to `viper`, since we already ran `viper.BindPFlag()` inside the command `PreRun`, we can now use `viper.Get()` directly. Signed-off-by: Salim Afiune Maya <[email protected]>
78f0767
to
dd3bcd5
Compare
switch flag.Type { | ||
case plugin.FlagType_Bool: | ||
v, err := cmd.Flags().GetBool(flag.Long) |
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 we need a bind equivalent somewhere? Like in https://github.com/mondoohq/cnspec/blob/main/apps/cnspec/cmd/scan.go#L105
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 already have it for all flags inside a provider. Though you're pointing to cnspec code so I'm assuming you want to know if this will work there. I can test, but this is working for cnquery.
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 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.
Perfecto. Then lets do it.
This change allows
cnquery
to load all provider flags via environment variables. For instance, if a provider exposes a flag namedfoo
, the user can export the environment variableMONDOO_FOO
to provide a value.The trick here was to switch loading the flag values from
cobra
toviper
, since we already ranviper.BindPFlag()
inside the commandPreRun
, we can now useviper.Get()
directly.