2023-04-13 00:07:08 +02:00
|
|
|
-- 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;65565> range.
|
|
|
|
Prelude.Natural.lessThanEqual 1 c.Port
|
|
|
|
&& Prelude.Natural.lessThanEqual c.Port 65565
|
|
|
|
}
|
|
|
|
|
|
|
|
in expected === actual
|
|
|
|
|
|
|
|
let nuconf = NuConfig::{ LiveMode = True, DevelMode = True }
|
|
|
|
|
|
|
|
let _ =
|
|
|
|
-- | validate the configuration.
|
|
|
|
assert : NuConfig/validate nuconf
|
|
|
|
|
|
|
|
let Config =
|
|
|
|
-- | define configuration schema.
|
2023-05-02 00:04:04 +02:00
|
|
|
{ Host : Text
|
|
|
|
, Port : Natural
|
2023-04-13 00:07:08 +02:00
|
|
|
, AppName : Text
|
|
|
|
, LiveMode : Bool
|
|
|
|
, DevelMode : Bool
|
2023-04-23 19:23:00 +02:00
|
|
|
, SessionCookieName : Text
|
|
|
|
, SessionCookieSecret : Text
|
2023-04-13 00:07:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2023-05-02 00:04:04 +02:00
|
|
|
= { Host = ""
|
|
|
|
, Port = 3000
|
2023-04-13 00:07:08 +02:00
|
|
|
, AppName = "pcmt"
|
|
|
|
, LiveMode = False
|
|
|
|
, DevelMode = False
|
2023-04-23 19:23:00 +02:00
|
|
|
, SessionCookieName = "sessionz"
|
|
|
|
, SessionCookieSecret = "secret"
|
2023-04-13 00:07:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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;65565> range.
|
|
|
|
Prelude.Natural.lessThanEqual 1 config.Port
|
|
|
|
&& Prelude.Natural.lessThanEqual config.Port 65565
|
|
|
|
}
|
|
|
|
|
|
|
|
in expected === actual
|
|
|
|
|
|
|
|
let _ =
|
|
|
|
-- | validate the configuration.
|
|
|
|
assert : Config/validate conf
|
|
|
|
|
2023-04-23 19:23:00 +02:00
|
|
|
in conf
|