aboutsummaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorNiall Sheridan <nsheridan@gmail.com>2016-08-27 21:34:53 +0100
committerNiall Sheridan <nsheridan@gmail.com>2016-08-27 21:34:53 +0100
commit0424ea77d6c09624f35c291a68dde60ea9ca8453 (patch)
treefaa0ddda5b5e9e95993bc0af744d3d65c064c731 /server
parent921818bca208f0c70e85ec670074cb3905cbbc82 (diff)
Allow setting some config from environment
Diffstat (limited to 'server')
-rw-r--r--server/config/config.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/server/config/config.go b/server/config/config.go
index f1341c1..3587e9f 100644
--- a/server/config/config.go
+++ b/server/config/config.go
@@ -3,6 +3,8 @@ package config
import (
"errors"
"io"
+ "os"
+ "strconv"
"github.com/hashicorp/go-multierror"
"github.com/spf13/viper"
@@ -82,6 +84,28 @@ func verifyConfig(u *unmarshalled) error {
return err
}
+func setFromEnv(u *unmarshalled) {
+ port, err := strconv.Atoi(os.Getenv("PORT"))
+ if err == nil {
+ u.Server[0].Port = port
+ }
+ if os.Getenv("DATASTORE") != "" {
+ u.Server[0].Datastore = os.Getenv("DATASTORE")
+ }
+ if os.Getenv("OAUTH_CLIENT_ID") != "" {
+ u.Auth[0].OauthClientID = os.Getenv("OAUTH_CLIENT_ID")
+ }
+ if os.Getenv("OAUTH_CLIENT_SECRET") != "" {
+ u.Auth[0].OauthClientSecret = os.Getenv("OAUTH_CLIENT_SECRET")
+ }
+ if os.Getenv("CSRF_SECRET") != "" {
+ u.Server[0].CSRFSecret = os.Getenv("CSRF_SECRET")
+ }
+ if os.Getenv("COOKIE_SECRET") != "" {
+ u.Server[0].CookieSecret = os.Getenv("COOKIE_SECRET")
+ }
+}
+
// ReadConfig parses a JSON configuration file into a Config struct.
func ReadConfig(r io.Reader) (*Config, error) {
u := &unmarshalled{}
@@ -93,6 +117,7 @@ func ReadConfig(r io.Reader) (*Config, error) {
if err := v.Unmarshal(u); err != nil {
return nil, err
}
+ setFromEnv(u)
if err := verifyConfig(u); err != nil {
return nil, err
}