Skip to content

Commit 56e29e5

Browse files
Support file secrets for env
1 parent af6e1ca commit 56e29e5

1 file changed

Lines changed: 20 additions & 8 deletions

File tree

  • internal/app/traefik-github-oauth-server

internal/app/traefik-github-oauth-server/config.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,28 @@ type Config struct {
1919
GithubOauthScopes []string
2020
}
2121

22-
func envWithDefault(key string, defaultValue string) string {
22+
func envString(key string) string {
2323
value := os.Getenv(key)
24+
if strings.HasSuffix(key, "_FILE") && value != "" {
25+
content, err := os.ReadFile(value)
26+
if err != nil {
27+
return ""
28+
}
29+
return strings.TrimSpace(string(content))
30+
}
31+
return value
32+
}
33+
34+
func envWithDefault(key string, defaultValue string) string {
35+
value := envString(key)
2436
if value == "" {
2537
return defaultValue
2638
}
2739
return value
2840
}
2941

3042
func githubOauthScopeConfigs() []string {
31-
scopesFromEnv := os.Getenv("GITHUB_OAUTH_SCOPES")
43+
scopesFromEnv := envString("GITHUB_OAUTH_SCOPES")
3244
if scopesFromEnv != "" {
3345
return strings.Split(scopesFromEnv, ",")
3446
}
@@ -38,13 +50,13 @@ func githubOauthScopeConfigs() []string {
3850

3951
func NewConfigFromEnv() *Config {
4052
return &Config{
41-
ApiBaseURL: os.Getenv("API_BASE_URL"),
42-
ApiSecretKey: os.Getenv("API_SECRET_KEY"),
43-
ServerAddress: os.Getenv("SERVER_ADDRESS"),
44-
DebugMode: cast.ToBool(os.Getenv("DEBUG_MODE")),
53+
ApiBaseURL: envString("API_BASE_URL"),
54+
ApiSecretKey: envString("API_SECRET_KEY"),
55+
ServerAddress: envString("SERVER_ADDRESS"),
56+
DebugMode: cast.ToBool(envString("DEBUG_MODE")),
4557
LogLevel: envWithDefault("LOG_LEVEL", "INFO"),
46-
GitHubOAuthClientID: os.Getenv("GITHUB_OAUTH_CLIENT_ID"),
47-
GitHubOAuthClientSecret: os.Getenv("GITHUB_OAUTH_CLIENT_SECRET"),
58+
GitHubOAuthClientID: envString("GITHUB_OAUTH_CLIENT_ID"),
59+
GitHubOAuthClientSecret: envString("GITHUB_OAUTH_CLIENT_SECRET"),
4860
GithubOauthScopes: githubOauthScopeConfigs(),
4961
}
5062
}

0 commit comments

Comments
 (0)