Skip to content

Commit

Permalink
Bind all config explicitly
Browse files Browse the repository at this point in the history
This will be revertable when spf13/viper#761 is resolved.
  • Loading branch information
Charles Labourier committed May 14, 2020
1 parent 63d6000 commit 0e4dedc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
11 changes: 5 additions & 6 deletions internal/config/config_test.go
Expand Up @@ -78,11 +78,10 @@ func TestInitiate(t *testing.T) {
os.Setenv("SLACK_THAT_WORKSPACE", "42born2code")
os.Setenv("POSTGRES_PASSWORD", "changeme")

defer os.Unsetenv("INTRA_APP_ID")
defer os.Unsetenv("INTRA_APP_SECRET")
defer os.Unsetenv("INTRA_WEBHOOKS")
defer os.Unsetenv("SLACK_THAT_WORKSPACE")
defer os.Unsetenv("POSTGRES_PASSWORD")
// Testing unmarshalling of not required env var fields
os.Setenv("POSTGRES_HOST", "testinghost")

defer os.Clearenv()

expected := Configuration{
Environment: "development",
Expand Down Expand Up @@ -118,7 +117,7 @@ func TestInitiate(t *testing.T) {
Enabled: false,
},
Postgres: Database{
Host: "localhost",
Host: "testinghost",
Port: "5432",
DB: "postgres",
User: "postgres",
Expand Down
38 changes: 38 additions & 0 deletions internal/config/load.go
Expand Up @@ -77,6 +77,44 @@ func bindEnv() {
log.Debugf("bound '%s' to '%s'", env, config)
}

// Workaround until unmarshal is supported for unbound environmental variables
// See github issue: https://github.com/spf13/viper/issues/761
logBinding("environment", "ENVIRONMENT")
logBinding("service", "SERVICE")

logBinding("email_suffix", "EMAIL_SUFFIX")

logBinding("warn_before", "WARN_BEFORE")

logBinding("timeout", "TIMEOUT")

logBinding("postgres.host", "POSTGRES_HOST")
logBinding("postgres.port", "POSTGRES_PORT")
logBinding("postgres.db", "POSTGRES_DB")
logBinding("postgres.user", "POSTGRES_USER")

logBinding("slack_that.url", "SLACK_THAT_URL")
logBinding("slack_that.username", "SLACK_THAT_USERNAME")

logBinding("rabbitmq.host", "RABBITMQ_HOST")
logBinding("rabbitmq.port", "RABBITMQ_PORT")
logBinding("rabbitmq.vhost", "RABBITMQ_VHOST")
logBinding("rabbitmq.user", "RABBITMQ_USER")
logBinding("rabbitmq.password", "RABBITMQ_PASSWORD")
logBinding("rabbitmq.queue", "RABBITMQ_QUEUE")

logBinding("log_level", "LOG_LEVEL")

logBinding("logstash.host", "LOGSTASH_HOST")
logBinding("logstash.port", "LOGSTASH_PORT")
logBinding("logstash.protocol", "LOGSTASH_PROTOCOL")
logBinding("logstash.levels", "LOGSTASH_LEVELS")
logBinding("logstash.enabled", "LOGSTASH_ENABLED")

logBinding("sentry.levels", "SENTRY_LEVELS")
logBinding("sentry.enabled", "SENTRY_ENABLED")
// End workaround

logBinding("sentry.dsn", "SENTRY_DSN")

logBinding("postgres.password", "POSTGRES_PASSWORD")
Expand Down

0 comments on commit 0e4dedc

Please sign in to comment.