-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0fb36ac
add env vars struct
carole-lavillonniere cfc0f3c
centralize env vars in integ tests
carole-lavillonniere 12a18d0
address comments
carole-lavillonniere ab4e8ed
remove comments
carole-lavillonniere 7a2457c
rename LOCALSTACK_ env vars to LSTK_
carole-lavillonniere 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
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 @@ | ||
| export LOCALSTACK_AUTH_TOKEN=ls-... | ||
| # Authentication token (optional - will trigger device flow login if not set) | ||
| export LSTK_AUTH_TOKEN=ls-... | ||
|
|
||
| # Force file-based keyring backend (instead of system keychain) | ||
| # export KEYRING=file | ||
| # | ||
| export LOCALSTACK_API_ENDPOINT=https://api.staging.aws.localstack.cloud | ||
| export LOCALSTACK_WEB_APP_URL=https://app.staging.aws.localstack.cloud | ||
| # API endpoint (defaults to https://api.localstack.cloud) | ||
| export LSTK_API_ENDPOINT=https://api.staging.aws.localstack.cloud | ||
|
|
||
| # Web app URL (defaults to https://app.localstack.cloud) | ||
| export LSTK_WEB_APP_URL=https://app.staging.aws.localstack.cloud | ||
|
|
||
| # Force file-based keyring backend instead of system keychain (optional) | ||
| # export LSTK_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
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("LSTK") | ||
| 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
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,60 @@ | ||
| package env | ||
|
|
||
| import ( | ||
| "os" | ||
| "strings" | ||
| "testing" | ||
| ) | ||
|
|
||
| type Key string | ||
|
|
||
| const ( | ||
| AuthToken Key = "LSTK_AUTH_TOKEN" | ||
| APIEndpoint Key = "LSTK_API_ENDPOINT" | ||
| Keyring Key = "LSTK_KEYRING" | ||
| CI Key = "CI" | ||
| ) | ||
|
|
||
| func Get(key Key) string { | ||
| return os.Getenv(string(key)) | ||
| } | ||
|
|
||
| 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 | ||
| } | ||
|
|
||
| type Environ []string | ||
|
|
||
| func Without(keys ...Key) Environ { | ||
| return Environ(os.Environ()).Without(keys...) | ||
| } | ||
|
|
||
| func With(key Key, value string) Environ { | ||
| return Environ(os.Environ()).With(key, value) | ||
| } | ||
|
|
||
| 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 | ||
| } | ||
|
|
||
| func (e Environ) With(key Key, value string) Environ { | ||
| return append(e, string(key)+"="+value) | ||
|
Comment on lines
+58
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure 🔧 Suggested fix func (e Environ) With(key Key, value string) Environ {
- return append(e, string(key)+"="+value)
+ e = e.Without(key)
+ return append(e, string(key)+"="+value)
}🤖 Prompt for AI Agents |
||
| } | ||
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.