From 9e5a1e1d458ebf60cf692c5f58651aa182d4518d Mon Sep 17 00:00:00 2001 From: Niall Sheridan Date: Mon, 9 May 2016 22:21:04 +0100 Subject: Placeholder for database config. --- server/config/config.go | 16 ++++++++++--- server/config/config_test.go | 15 ++++++++++++ testdata/config.go | 56 ++++++++++++++++++++++++++------------------ 3 files changed, 61 insertions(+), 26 deletions(-) diff --git a/server/config/config.go b/server/config/config.go index 21fba94..3d12665 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -8,9 +8,10 @@ import ( // 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 Server `mapstructure:"server"` + Auth Auth `mapstructure:"auth"` + SSH SSH `mapstructure:"ssh"` + Database Database `mapstructure:"database"` } // Server holds the configuration specific to the web server and sessions. @@ -22,6 +23,15 @@ type Server struct { CookieSecret string `mapstructure:"cookie_secret"` } +// Database holds the configuration specific to database functions. +type Database struct { + DbType string `mapstructure:"dbtype"` + Host string `mapstructure:"host"` + User string `mapstructure:"user"` + Password string `mapstructure:"password"` + DB string `mapstructure:"db"` +} + // Auth holds the configuration specific to the OAuth provider. type Auth struct { OauthClientID string `mapstructure:"oauth_client_id"` diff --git a/server/config/config_test.go b/server/config/config_test.go index 70436d5..f97961a 100644 --- a/server/config/config_test.go +++ b/server/config/config_test.go @@ -58,3 +58,18 @@ func TestSSHConfig(t *testing.T) { } a.Equal(d.Hours(), float64(720)) } + +func TestDatabaseConfig(t *testing.T) { + a := assert.New(t) + c, err := ReadConfig(bytes.NewBuffer(testdata.Database)) + if err != nil { + t.Fatal(err) + } + d := c.Database + a.IsType(d, Database{}) + a.Equal(d.User, "user") + a.Equal(d.Password, "password") + a.Equal(d.Host, "localhost") + a.Equal(d.DbType, "mongo") + a.Equal(d.DB, "dbname") +} diff --git a/testdata/config.go b/testdata/config.go index ef5fdac..ca856a8 100644 --- a/testdata/config.go +++ b/testdata/config.go @@ -1,33 +1,43 @@ package testdata var ServerConfig = []byte(`{ -"server": { - "use_tls": true, - "tls_key": "server.key", - "tls_cert": "server.crt", - "port": 443, - "cookie_secret": "supersecret" - } + "server": { + "use_tls": true, + "tls_key": "server.key", + "tls_cert": "server.crt", + "port": 443, + "cookie_secret": "supersecret" + } }`) var AuthConfig = []byte(`{ - "auth": { - "provider": "google", - "oauth_client_id": "client_id", - "oauth_client_secret": "secret", - "oauth_callback_url": "https://sshca.example.com/auth/callback", - "provider_opts": { - "domain": "example.com" - }, - "jwt_signing_key": "supersecret" - } + "auth": { + "provider": "google", + "oauth_client_id": "client_id", + "oauth_client_secret": "secret", + "oauth_callback_url": "https://sshca.example.com/auth/callback", + "provider_opts": { + "domain": "example.com" + }, + "jwt_signing_key": "supersecret" + } }`) var SSHConfig = []byte(`{ - "ssh": { - "signing_key": "signing_key", - "additional_principals": ["ec2-user", "ubuntu"], - "max_age": "720h", - "permissions": ["permit-pty", "permit-X11-forwarding", "permit-port-forwarding", "permit-user-rc"] - } + "ssh": { + "signing_key": "signing_key", + "additional_principals": ["ec2-user", "ubuntu"], + "max_age": "720h", + "permissions": ["permit-pty", "permit-X11-forwarding", "permit-port-forwarding", "permit-user-rc"] + } +}`) + +var Database = []byte(`{ + "database": { + "host": "localhost", + "user": "user", + "password": "password", + "db": "dbname", + "dbtype": "mongo" + } }`) -- cgit v1.2.3