Skip to content

cmd: adds env var backups to command flags#6508

Merged
johanfylling merged 2 commits intoopen-policy-agent:mainfrom
colinjlacy:issue-4277-env-var-cmd-flags
Jan 29, 2024
Merged

cmd: adds env var backups to command flags#6508
johanfylling merged 2 commits intoopen-policy-agent:mainfrom
colinjlacy:issue-4277-env-var-cmd-flags

Conversation

@colinjlacy
Copy link
Copy Markdown
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

@netlify
Copy link
Copy Markdown

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
Copy Markdown
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.

Comment thread cmd/internal/env/env_test.go Outdated
Comment thread cmd/internal/env/env_test.go Outdated
Comment thread cmd/internal/env/env_test.go Outdated
Comment thread cmd/internal/env/env_test.go
@colinjlacy colinjlacy force-pushed the issue-4277-env-var-cmd-flags branch from 23387c3 to 99321ac Compare January 17, 2024 12:40
@colinjlacy colinjlacy marked this pull request as ready for review January 18, 2024 11:36
Copy link
Copy Markdown
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.

Comment thread cmd/internal/env/env_test.go Outdated
Comment thread cmd/internal/env/env_test.go
anderseknert
anderseknert previously approved these changes Jan 22, 2024
Copy link
Copy Markdown
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! 😃

@colinjlacy colinjlacy force-pushed the issue-4277-env-var-cmd-flags branch from b997f94 to 97abd98 Compare January 22, 2024 21:04
@johanfylling
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
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! 😃

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