Skip to content

Commit

Permalink
Config using env vars
Browse files Browse the repository at this point in the history
Allow setting directory API key and scim password/token using
environment variables.
  • Loading branch information
ronenh committed Jul 1, 2024
1 parent 8b24663 commit e49a8ae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
.vscode/

go.work.sum
/dist
/.ext
dist/
.ext/
.dev/

# Helm package
scim-*.*.*.tgz
Expand Down
7 changes: 6 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func NewConfig(configPath string, log *zerolog.Logger, certsGenerator *certs.Gen
v.AddConfigPath(".")
v.SetConfigFile(file)
v.SetEnvPrefix("ASERTO_SCIM")
v.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))

// Set defaults.
v.SetDefault("server.listen_address", ":8080")
Expand All @@ -102,6 +102,11 @@ func NewConfig(configPath string, log *zerolog.Logger, certsGenerator *certs.Gen
v.SetDefault("scim.group_object_type", "group")
v.SetDefault("scim.group_member_relation", "member")

// Allow setting via env vars.
v.SetDefault("directory.api_key", "")
v.SetDefault("server.auth.basic.password", "")
v.SetDefault("server.auth.bearer.token", "")

configExists, err := fileExists(file)
if err != nil {
return nil, errors.Wrapf(err, "filesystem error")
Expand Down

0 comments on commit e49a8ae

Please sign in to comment.