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

cmd: adds env var backups to command flags #6508

Merged

Conversation

colinjlacy
Copy link
Contributor

As requested in issue 4277, this branch adds environment variable backups to command flags found in the cmd package.

Why the changes in this PR are needed?

As documented in #4277 there are certain situations where explicit command flag values don't make the most sense, and it instead makes more sense to set environment variables that set command flag values as a backup, if the flags themselves aren't explicitly set.

What are the changes in this PR?

For each command flag in the cmd package, a new environment variable is made available following the format OPA_<cmd-name>_<flag-name>, in all uppercase letters. The value set by the environment variable will only be used if there was no command flag value set in the execution of the command in question.

Notes to assist PR review:

This can be tested by setting any environment variable value that corresponds to an existing command flag, e.g. OPA_FMT_WRITE=true for the fmt command.

Further comments:

fixes #4277

Copy link

netlify bot commented Jan 1, 2024

Deploy Preview for openpolicyagent ready!

Name Link
🔨 Latest commit b76157b
🔍 Latest deploy log https://app.netlify.com/sites/openpolicyagent/deploys/65b5243f38180e000887d538
😎 Deploy Preview https://deploy-preview-6508--openpolicyagent.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Member

@anderseknert anderseknert left a comment

Choose a reason for hiding this comment

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

Looks great! Just a few comments / questions.

cmd/internal/env/env_test.go Outdated Show resolved Hide resolved
cmd/internal/env/env_test.go Outdated Show resolved Hide resolved
cmd/internal/env/env_test.go Outdated Show resolved Hide resolved
cmd/internal/env/env_test.go Show resolved Hide resolved
@colinjlacy colinjlacy marked this pull request as ready for review January 18, 2024 11:36
Copy link
Member

@anderseknert anderseknert left a comment

Choose a reason for hiding this comment

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

Thanks! Just a single nit to address left.

cmd/internal/env/env_test.go Outdated Show resolved Hide resolved
cmd/internal/env/env_test.go Show resolved Hide resolved
anderseknert
anderseknert previously approved these changes Jan 22, 2024
Copy link
Member

@anderseknert anderseknert left a comment

Choose a reason for hiding this comment

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

Thanks, Colin! 😃

@johanfylling
Copy link
Contributor

johanfylling commented Jan 25, 2024

Thanks four you contribution @colinjlacy! 😃
Before we can have this merged, would you please resolve the current conflicts on your branch, and squash your commits?

Signed-off-by: Colin Lacy <colinjlacy@gmail.com>
@colinjlacy
Copy link
Contributor Author

@johanfylling sorry for the delay, I was traveling all week. Conflicts resolved and commits squashed. Thanks!

Copy link
Contributor

@johanfylling johanfylling left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution! 😃

@johanfylling johanfylling merged commit 4bfae4e into open-policy-agent:main Jan 29, 2024
25 checks passed
@colinjlacy colinjlacy deleted the issue-4277-env-var-cmd-flags branch January 29, 2024 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Configurable command flags through environment variables
3 participants