2019-10-27 21:45:07 +00:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
module AppTypes.Configuration where
|
|
|
|
|
|
|
|
import qualified Data.Text as T
|
|
|
|
|
2021-07-12 11:29:40 +00:00
|
|
|
import Data.Yaml as Y
|
2019-10-27 21:45:07 +00:00
|
|
|
|
|
|
|
import Options.Applicative as O
|
|
|
|
|
|
|
|
data ServerConfig = ServerConfig
|
2021-07-12 11:29:40 +00:00
|
|
|
{ configDbHost :: T.Text
|
|
|
|
, configDbPort :: Word
|
|
|
|
, configDbName :: T.Text
|
|
|
|
, configDbUser :: T.Text
|
|
|
|
, configDbPasswd :: T.Text
|
|
|
|
, configCurrencySymbol :: T.Text
|
|
|
|
, configCurrencyFraction :: Word
|
|
|
|
, configListenPort :: Word
|
|
|
|
, configListenHost :: T.Text
|
2020-04-18 22:49:30 +00:00
|
|
|
-- , configMaxConnectionsPerClient :: Word
|
2022-02-20 20:02:50 +00:00
|
|
|
-- , configBlockRegistration :: Bool
|
2021-07-12 11:29:40 +00:00
|
|
|
, configSendmailPath :: FilePath
|
2023-07-07 22:16:05 +00:00
|
|
|
, configJWTSecret :: T.Text
|
2019-10-27 21:45:07 +00:00
|
|
|
}
|
|
|
|
deriving (Show)
|
|
|
|
|
2021-07-12 11:29:40 +00:00
|
|
|
instance FromJSON ServerConfig where
|
|
|
|
parseJSON (Object m) = ServerConfig
|
2019-10-27 21:45:07 +00:00
|
|
|
<$> m .: "db_host"
|
|
|
|
<*> m .: "db_port"
|
|
|
|
<*> m .: "db_name"
|
|
|
|
<*> m .: "db_user"
|
|
|
|
<*> m .: "db_passwd"
|
|
|
|
<*> m .: "currency"
|
2021-07-12 11:29:40 +00:00
|
|
|
<*> m .: "currency_fraction"
|
2019-10-27 21:45:07 +00:00
|
|
|
<*> m .: "listen_port"
|
|
|
|
<*> m .:? "listen_host" .!= "127.0.0.1"
|
2020-04-18 22:49:30 +00:00
|
|
|
-- <*> m .:? "max_connections_per_client" .!= 10
|
2022-02-20 20:02:50 +00:00
|
|
|
-- <*> m .: "block_registration"
|
2021-07-12 11:29:40 +00:00
|
|
|
<*> m .: "sendmail_path"
|
2023-07-07 22:16:05 +00:00
|
|
|
<*> m .: "jwt_secret"
|
2022-02-20 20:02:50 +00:00
|
|
|
parseJSON _ = error "Can not parse configuration"
|
2019-10-27 21:45:07 +00:00
|
|
|
|
2020-05-16 14:12:49 +00:00
|
|
|
data Options = Options
|
2019-10-27 21:45:07 +00:00
|
|
|
{ optConfigLocation :: T.Text
|
2020-05-16 14:12:49 +00:00
|
|
|
, optMigrationLocation :: T.Text
|
2019-10-27 21:45:07 +00:00
|
|
|
}
|
|
|
|
deriving (Show)
|
|
|
|
|
|
|
|
options :: O.Parser Options
|
|
|
|
options = Options
|
|
|
|
<$> strOption
|
|
|
|
( long "configuration"
|
|
|
|
<> short 'c'
|
|
|
|
<> metavar "FILEPATH"
|
|
|
|
<> help "Location of the configuration YAML-file"
|
|
|
|
)
|
2020-05-16 14:12:49 +00:00
|
|
|
<*> strOption
|
|
|
|
( long "migration-dir"
|
|
|
|
<> short 'm'
|
|
|
|
<> metavar "DIRPATH"
|
|
|
|
<> help "Location of the migration scripts folder"
|
|
|
|
<> value "./migration_scripts"
|
|
|
|
<> showDefault
|
|
|
|
)
|