diff --git a/app/routes_test.go b/app/routes_test.go index 2fd5f64..b356233 100644 --- a/app/routes_test.go +++ b/app/routes_test.go @@ -17,12 +17,17 @@ import ( const connstr = "file:ent_tests?mode=memory&_fk=1" var conf = &config.Config{ - Port: 3005, - AppName: "pcmt-test", - LiveMode: true, - DevelMode: false, - SessionCookieName: "sessionz", - SessionCookieSecret: "secret", + Port: 3005, + AppName: "pcmt-test", + LiveMode: true, + DevelMode: false, + Session: struct { + CookieName string + CookieSecret string + }{ + CookieName: "sessionz", + CookieSecret: "secret", + }, } var ( diff --git a/app/settings/settings.go b/app/settings/settings.go index 150a902..6acdd20 100644 --- a/app/settings/settings.go +++ b/app/settings/settings.go @@ -38,8 +38,8 @@ func (s *Settings) Consolidate(conf *config.Config, host *string, port *int, dev s.SetAppName(conf.AppName) s.SetIsLive(conf.LiveMode) s.SetIsDevel(conf.DevelMode) - s.SetSessionCookieName(conf.SessionCookieName) - s.SetSessionCookieSecret(conf.SessionCookieSecret) + s.SetSessionCookieName(conf.Session.CookieName) + s.SetSessionCookieSecret(conf.Session.CookieSecret) log.Debug("checking flag overrides") diff --git a/config/config.go b/config/config.go index 14cf1a0..91d2a87 100644 --- a/config/config.go +++ b/config/config.go @@ -11,14 +11,23 @@ import ( "github.com/philandstuff/dhall-golang/v6" ) +type session struct { + CookieName string + CookieSecret string +} + type Config struct { - Host string - Port int - AppName string - LiveMode bool - DevelMode bool - SessionCookieName string - SessionCookieSecret string + Host string + Port int + AppName string + LiveMode bool + DevelMode bool + Session session + Registration struct{ Allowed bool } + Logger struct { + Json bool //nolint:revive + Fmt string + } } func LoadConfig(conf string, isPath bool) (*Config, error) { diff --git a/config/config_test.go b/config/config_test.go index ce7c19b..268947a 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -39,7 +39,7 @@ func TestConfig(t *testing.T) { conf: ` let ConfigSchema = https://git.dotya.ml/mirre-mt/pcmt/raw/branch/development/config/schema/package.dhall - sha256:ad7ba86d5d388a99b7543faa0e4c81ba1d9b78fa6c32fdaf4ac4477089d177be + sha256:c82b0904c261d442e5765c2f47d76ad53c3c3ed16ace1b33416cedf98f2f5df0 ? https://git.dotya.ml/mirre-mt/pcmt/raw/branch/development/config/schema/package.dhall let Config = ConfigSchema.Schema @@ -57,7 +57,7 @@ func TestConfig(t *testing.T) { conf: ` let ConfigSchema = https://git.dotya.ml/mirre-mt/pcmt/raw/branch/development/config/schema/package.dhall - sha256:ad7ba86d5d388a99b7543faa0e4c81ba1d9b78fa6c32fdaf4ac4477089d177be + sha256:c82b0904c261d442e5765c2f47d76ad53c3c3ed16ace1b33416cedf98f2f5df0 ? https://git.dotya.ml/mirre-mt/pcmt/raw/branch/development/config/schema/package.dhall let Config = ConfigSchema.Schema diff --git a/config/schema/package.dhall b/config/schema/package.dhall index 8c01f97..a75cd6a 100644 --- a/config/schema/package.dhall +++ b/config/schema/package.dhall @@ -1,10 +1,10 @@ { Schema = ./schema.dhall - sha256:1e8d4a3e16af1fa5b9b602a62c59440b933652c04b695095651ee04194b97138 + sha256:3269ff2c6eba9856b819f3e7fccd44f2745fdff9d02498e6f0a1474ce650af17 ? ./schema.dhall , Schema/validate = ./validate.dhall - sha256:eb0df6eb95180f502ec1fbdf62ba6010e2cfc82b3dfe75163fa686d98c31eb6b + sha256:9e327f316fce0ced3598e14020a8a1ee3bd603a7817cb9e62ceddac3ece10e76 ? ./validate.dhall , Prelude = ./prelude.dhall diff --git a/config/schema/schema.dhall b/config/schema/schema.dhall index f82d01b..f4c2d24 100644 --- a/config/schema/schema.dhall +++ b/config/schema/schema.dhall @@ -6,8 +6,9 @@ let Schema = , AppName : Text , LiveMode : Bool , DevelMode : Bool - , SessionCookieName : Optional Text - , SessionCookieSecret : Optional Text + , Session : { CookieName : Optional Text, CookieSecret : Text } + , Logger : { Json : Bool, Fmt : Optional Text } + , Registration : { Allowed : Bool } } , default = -- | have sane defaults. @@ -16,8 +17,9 @@ let Schema = , AppName = "pcmt" , LiveMode = False , DevelMode = False - , SessionCookieName = None Text - , SessionCookieSecret = None Text + , Session = { CookieName = None Text, CookieSecret = "secretz" } + , Logger = { Json = True, Fmt = None Text } + , Registration.Allowed = True } } diff --git a/config/schema/validate.dhall b/config/schema/validate.dhall index f31da79..c4fa365 100644 --- a/config/schema/validate.dhall +++ b/config/schema/validate.dhall @@ -5,7 +5,7 @@ let Prelude = let Schema = ./schema.dhall - sha256:1e8d4a3e16af1fa5b9b602a62c59440b933652c04b695095651ee04194b97138 + sha256:3269ff2c6eba9856b819f3e7fccd44f2745fdff9d02498e6f0a1474ce650af17 ? ./schema.dhall let Schema/validate diff --git a/config/testconfigs/1.dhall b/config/testconfigs/1.dhall index a1fdc69..ad57fdf 100644 --- a/config/testconfigs/1.dhall +++ b/config/testconfigs/1.dhall @@ -1,6 +1,7 @@ let ConfigSchema = - https://git.dotya.ml/mirre-mt/pcmt/raw/branch/development/config/schema/package.dhall - sha256:ad7ba86d5d388a99b7543faa0e4c81ba1d9b78fa6c32fdaf4ac4477089d177be + https://git.dotya.ml/mirre-mt/pcmt/raw/branch/development/config/schema/package.dhall + sha256:c82b0904c261d442e5765c2f47d76ad53c3c3ed16ace1b33416cedf98f2f5df0 + ? https://git.dotya.ml/mirre-mt/pcmt/raw/branch/development/config/schema/package.dhall let Config = ConfigSchema.Schema diff --git a/config/testconfigs/2.dhall b/config/testconfigs/2.dhall index 624a527..13f70d0 100644 --- a/config/testconfigs/2.dhall +++ b/config/testconfigs/2.dhall @@ -1,6 +1,7 @@ let ConfigSchema = - https://git.dotya.ml/mirre-mt/pcmt/raw/branch/development/config/schema/package.dhall - sha256:ad7ba86d5d388a99b7543faa0e4c81ba1d9b78fa6c32fdaf4ac4477089d177be + https://git.dotya.ml/mirre-mt/pcmt/raw/branch/development/config/schema/package.dhall + sha256:c82b0904c261d442e5765c2f47d76ad53c3c3ed16ace1b33416cedf98f2f5df0 + ? https://git.dotya.ml/mirre-mt/pcmt/raw/branch/development/config/schema/package.dhall let Config = ConfigSchema.Schema diff --git a/exampleConfig.dhall b/exampleConfig.dhall index bac4ff6..8ddd37a 100644 --- a/exampleConfig.dhall +++ b/exampleConfig.dhall @@ -1,7 +1,8 @@ -{- import config schema that is integrity-check protected -} +{- import config schema that is integrity-check protected (with a fallback) -} let ConfigSchema = - https://git.dotya.ml/mirre-mt/pcmt/raw/branch/development/config/schema/package.dhall - sha256:ad7ba86d5d388a99b7543faa0e4c81ba1d9b78fa6c32fdaf4ac4477089d177be + https://git.dotya.ml/mirre-mt/pcmt/raw/branch/development/config/schema/package.dhall + sha256:c82b0904c261d442e5765c2f47d76ad53c3c3ed16ace1b33416cedf98f2f5df0 + ? https://git.dotya.ml/mirre-mt/pcmt/raw/branch/development/config/schema/package.dhall let Config = ConfigSchema.Schema