Fix environment variable parsing, alias Terraform provider OAuth environment variables, and fix typo#49
Open
SVHawk13 wants to merge 3 commits intocontabo:mainfrom
Open
Fix environment variable parsing, alias Terraform provider OAuth environment variables, and fix typo#49SVHawk13 wants to merge 3 commits intocontabo:mainfrom
SVHawk13 wants to merge 3 commits intocontabo:mainfrom
Conversation
Adds support for CNTB_OAUTH2_CLIENT_ID, CNTB_OAUTH2_PASS, and CNTB_OAUTH2_TOKEN_URL environment variables to match the docs for the Terraform provider while maintaining backward compatibility with the existing environment variable names.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR improves environment variable parsing and consistency. It additionally fixes a minor typo:
Fix OAuth environment variable parsing on Linux
Issue: The CLI was using
viper.AutomaticEnv()without a key replacer. This caused configuration keys with dashes to be converted to environment variable names that are not compatible with Linux shells such as Bash (for example,oauth2-clientidbecomesCNTB_OAUTH2-CLIENTID).Changes:
strings.NewReplacer("-", "_")to translate dashes in configuration keys to underscores whenviper.AutomaticEnvmaps them to environment variable names.Improve consistency with Terraform provider
Issue: The CLI uses configuration keys that map to environment variable names that differ from the environment variable names used by the Contabo Terraform provider. For example, the Terraform provider uses
CNTB_OAUTH2_PASSwhilecntbusesCNTB_OAUTH2_PASSWORD. This makes configuration inconsistent between Terraform workflows and CLI workflows.Changes:
fmtEnvKeyshelper function to format environment variable names consistently for use withviper.BindEnv.viper.BindEnvfor consistency with the Terraform provider. The CLI now accepts both the environment variable names generated byviper.AutomaticEnvand the environment variable names used by the Terraform provider. The environment variable names fromviper.AutomaticEnvtake precedence, followed by the aliased names in definition order. For example,CNTB_OAUTH2_PASSWORDandCNTB_OAUTH2_PASSare now both valid environment variables. IfCNTB_OAUTH2_PASSWORDandCNTB_OAUTH2_PASSare both set, the value ofCNTB_OAUTH2_PASSWORDis used.Fix a minor typo
Corrected "oauth2" misspelled as "oauht2".
Testing
The follow have been manually tested locally on Fedora 43:
oauth2-clientid,oauth2-client-secret,oauth2-tokenurl,oauth2-user, andoauth2-passwordare set to the value of the environment variable that corresponds to the transformed configuration key name, such as the configuration keyoauth2-clientidmapping to the environment variable nameCNTB_OAUTH2_CLIENTID.viper.AutomaticEnv.viper.AutomaticEnvtake precedence over the aliased environment variables names.