Skip to content

Commit

Permalink
Merge pull request #322 from snyk/feat/vu-env-config
Browse files Browse the repository at this point in the history
feat: allow loading config vars from env
  • Loading branch information
jgresty authored Jan 15, 2024
2 parents eb415aa + 4fda5a6 commit fd117ef
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions vervet-underground/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config

import (
"fmt"
"strings"

"github.com/snyk/vervet/v5"
"github.com/spf13/viper"
Expand Down Expand Up @@ -94,10 +95,20 @@ func setDefaults() {
viper.SetDefault("storage.type", StorageTypeMemory)
}

// loadEnv sets up the config store to load values from environment variables,
// these will take precedent over values defined in config files.
func loadEnv() {
viper.SetEnvPrefix("SNYK")
// Set nested values, eg SNYK_STORAGE_S3_REGION=
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.AutomaticEnv()
}

// Load returns a ServerConfig instance loaded from the given paths to a JSON
// config file.
func Load(configPaths ...string) (*ServerConfig, error) {
setDefaults()
loadEnv()

for i, c := range configPaths {
if i == 0 {
Expand Down

0 comments on commit fd117ef

Please sign in to comment.