diff options
author | Niall Sheridan <nsheridan@gmail.com> | 2016-04-18 22:11:39 +0100 |
---|---|---|
committer | Niall Sheridan <nsheridan@gmail.com> | 2016-04-18 22:11:39 +0100 |
commit | 884013090b1b56b207f644393865c6057c9999ca (patch) | |
tree | 92d94820d0e131bc8385a7ca6540a96336b4e963 /server/config |
Initial commit
Diffstat (limited to 'server/config')
-rw-r--r-- | server/config/config.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/server/config/config.go b/server/config/config.go new file mode 100644 index 0000000..b65d171 --- /dev/null +++ b/server/config/config.go @@ -0,0 +1,51 @@ +package config + +import "github.com/spf13/viper" + +// Config holds the values from the json config file. +type Config struct { + Server Server `mapstructure:"server"` + Auth Auth `mapstructure:"auth"` + SSH SSH `mapstructure:"ssh"` +} + +// Server holds the configuration specific to the web server and sessions. +type Server struct { + UseTLS bool `mapstructure:"use_tls"` + TLSKey string `mapstructure:"tls_key"` + TLSCert string `mapstructure:"tls_cert"` + Port int `mapstructure:"port"` + CookieSecret string `mapstructure:"cookie_secret"` +} + +// Auth holds the configuration specific to the OAuth provider. +type Auth struct { + OauthClientID string `mapstructure:"oauth_client_id"` + OauthClientSecret string `mapstructure:"oauth_client_secret"` + OauthCallbackURL string `mapstructure:"oauth_callback_url"` + Provider string `mapstructure:"provider"` + GoogleOpts map[string]interface{} `mapstructure:"google_opts"` + JWTSigningKey string `mapstructure:"jwt_signing_key"` +} + +// SSH holds the configuration specific to signing ssh keys. +type SSH struct { + SigningKey string `mapstructure:"signing_key"` + Principals []string `mapstructure:"principals"` + MaxAge string `mapstructure:"max_age"` + Permissions []string `mapstructure:"permissions"` +} + +// ReadConfig parses a JSON configuration file into a Config struct. +func ReadConfig(filename string) (*Config, error) { + config := &Config{} + v := viper.New() + v.SetConfigFile(filename) + if err := v.ReadInConfig(); err != nil { + return nil, err + } + if err := v.Unmarshal(config); err != nil { + return nil, err + } + return config, nil +} |