-
Notifications
You must be signed in to change notification settings - Fork 0
Centralize env vars with Viper #39
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
Open
carole-lavillonniere
wants to merge
3
commits into
main
Choose a base branch
from
carole/drg-529
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+142
−82
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,11 @@ | ||
| # Authentication token (optional - will trigger device flow login if not set) | ||
| export LOCALSTACK_AUTH_TOKEN=ls-... | ||
|
|
||
| # Force file-based keyring backend (instead of system keychain) | ||
| # export KEYRING=file | ||
| # | ||
| # API endpoint (defaults to https://api.localstack.cloud) | ||
| export LOCALSTACK_API_ENDPOINT=https://api.staging.aws.localstack.cloud | ||
|
|
||
| # Web app URL (defaults to https://app.localstack.cloud) | ||
| export LOCALSTACK_WEB_APP_URL=https://app.staging.aws.localstack.cloud | ||
|
|
||
| # Force file-based keyring backend instead of system keychain (optional) | ||
| # export LOCALSTACK_KEYRING=file |
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package env | ||
|
|
||
| import ( | ||
| "strings" | ||
|
|
||
| "github.com/spf13/viper" | ||
| ) | ||
|
|
||
| type Env struct { | ||
| AuthToken string | ||
| APIEndpoint string | ||
| WebAppURL string | ||
| Keyring string | ||
| } | ||
|
|
||
| var Vars = &Env{} | ||
|
|
||
| // Init initializes environment variable configuration | ||
| func Init() { | ||
| viper.SetEnvPrefix("LOCALSTACK") | ||
| viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) | ||
| viper.AutomaticEnv() | ||
|
|
||
| viper.SetDefault("api_endpoint", "https://api.localstack.cloud") | ||
| viper.SetDefault("web_app_url", "https://app.localstack.cloud") | ||
|
|
||
| Vars = &Env{ | ||
| AuthToken: viper.GetString("auth_token"), | ||
| APIEndpoint: viper.GetString("api_endpoint"), | ||
| WebAppURL: viper.GetString("web_app_url"), | ||
| Keyring: viper.GetString("keyring"), | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package env | ||
|
|
||
| import ( | ||
| "os" | ||
| "strings" | ||
| "testing" | ||
| ) | ||
|
|
||
| // Key is a declared environment variable name. | ||
| type Key string | ||
|
|
||
| const ( | ||
| AuthToken Key = "LOCALSTACK_AUTH_TOKEN" | ||
| APIEndpoint Key = "LOCALSTACK_API_ENDPOINT" | ||
| Keyring Key = "LOCALSTACK_KEYRING" | ||
| CI Key = "CI" | ||
| ) | ||
|
|
||
| // Get returns the value of the given environment variable. | ||
| func Get(key Key) string { | ||
| return os.Getenv(string(key)) | ||
| } | ||
|
|
||
| // Require returns the value of the given environment variable, failing the test if it is not set. | ||
| func Require(t testing.TB, key Key) string { | ||
| t.Helper() | ||
| v := os.Getenv(string(key)) | ||
| if v == "" { | ||
| t.Fatalf("%s must be set to run this test", key) | ||
| } | ||
| return v | ||
| } | ||
|
|
||
| // Environ is a slice of "KEY=value" environment variable strings. | ||
| type Environ []string | ||
|
|
||
| // Without returns the current process environment excluding the given keys. | ||
| func Without(keys ...Key) Environ { | ||
| return Environ(os.Environ()).Without(keys...) | ||
| } | ||
|
|
||
| // With returns the current process environment with key=value appended. | ||
| func With(key Key, value string) Environ { | ||
| return Environ(os.Environ()).With(key, value) | ||
| } | ||
|
|
||
| // Without returns a copy of e excluding any variable whose key matches one of the given keys. | ||
| func (e Environ) Without(keys ...Key) Environ { | ||
| var result Environ | ||
| for _, entry := range e { | ||
| excluded := false | ||
| for _, key := range keys { | ||
| if strings.HasPrefix(entry, string(key)+"=") { | ||
| excluded = true | ||
| break | ||
| } | ||
| } | ||
| if !excluded { | ||
| result = append(result, entry) | ||
| } | ||
| } | ||
| return result | ||
| } | ||
|
|
||
| // With returns a copy of e with key=value appended. | ||
| func (e Environ) With(key Key, value string) Environ { | ||
| return append(e, string(key)+"="+value) | ||
| } |
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.