diff --git a/.gitignore b/.gitignore index 0fef018..b8994fe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ # main binary pcmt +# dev config. +/config.dhall + # air tmp dir /tmp diff --git a/config.dhall b/config.dhall deleted file mode 100644 index a1768cb..0000000 --- a/config.dhall +++ /dev/null @@ -1,95 +0,0 @@ --- convenience funcs for validation. -let Prelude = - https://prelude.dhall-lang.org/v20.2.0/package.dhall - sha256:a6036bc38d883450598d1de7c98ead113196fe2db02e9733855668b18096f07b - -let NuConfig = - -- | define a configuration schema. - { Type = - { Port : Natural - , AppName : Text - , LiveMode : Bool - , DevelMode : Bool - , LoginCookieName : Optional Text - } - , default = - { Port = 3000 - , AppName = "pcmt" - , LiveMode = False - , DevelMode = False - , LoginCookieName = None Text - } - } - -let NuConfig/validate - : NuConfig.Type -> Type - = - -- | define validation. - \(c : NuConfig.Type) -> - let expected = { validPort = True } - - let actual = - { validPort = - -- | make sure port number belongs to the <1;65535> range. - Prelude.Natural.lessThanEqual 1 c.Port - && Prelude.Natural.lessThanEqual c.Port 65535 - } - - in expected === actual - -let nuconf = NuConfig::{ LiveMode = True, DevelMode = True } - -let _ = - -- | validate the configuration. - assert : NuConfig/validate nuconf - -let Config = - -- | define configuration schema. - { Host : Text - , Port : Natural - , AppName : Text - , LiveMode : Bool - , DevelMode : Bool - , SessionCookieName : Text - , SessionCookieSecret : Text - } - -let defconf - -- | a full default configuration. - -- | TODO: have this reside on the Internet and import it similar to how - -- | the Dhall Prelude is imported. - : Config - = { Host = "" - , Port = 3000 - , AppName = "pcmt" - , LiveMode = False - , DevelMode = False - , SessionCookieName = "sessionz" - , SessionCookieSecret = "secret" - } - -let conf - : Config - = defconf // { LiveMode = True, DevelMode = False } - -let Config/validate - : Config -> Type - = - -- | define validation. - \(config : Config) -> - let expected = { validPort = True } - - let actual = - { validPort = - -- | make sure port number belongs to the <1;65535> range. - Prelude.Natural.lessThanEqual 1 config.Port - && Prelude.Natural.lessThanEqual config.Port 65535 - } - - in expected === actual - -let _ = - -- | validate the configuration. - assert : Config/validate conf - -in conf diff --git a/exampleConfig.dhall b/exampleConfig.dhall new file mode 100644 index 0000000..bac4ff6 --- /dev/null +++ b/exampleConfig.dhall @@ -0,0 +1,22 @@ +{- import config schema that is integrity-check protected -} +let ConfigSchema = + https://git.dotya.ml/mirre-mt/pcmt/raw/branch/development/config/schema/package.dhall + sha256:ad7ba86d5d388a99b7543faa0e4c81ba1d9b78fa6c32fdaf4ac4477089d177be + +let Config = ConfigSchema.Schema + +let c = + {- below we allow overriding config values using env vars -} + Config::{ + , Host = env:PCMT_HOST as Text ? Config.default.Host + , LiveMode = env:PCMT_LIVE ? True + , DevelMode = env:PCMT_DEVEL ? True + } + +let _ = + {- validate that the above adheres to the config schema and contains valid + entries (not everything gets validated though). + -} + assert : ConfigSchema.Schema/validate c + +in c