zgo-backend/src/Config.hs

72 lines
1.7 KiB
Haskell
Raw Normal View History

2022-07-12 21:08:27 +00:00
{-# LANGUAGE OverloadedStrings #-}
module Config where
import qualified Data.ByteString as BS
import Data.Configurator
import Data.SecureMem
import qualified Data.Text as T
2023-01-24 19:54:21 +00:00
import Network.Socket (PortNumber)
2022-07-12 21:08:27 +00:00
data Config =
Config
{ c_dbHost :: String
, c_dbName :: T.Text
, c_dbUser :: T.Text
, c_dbPassword :: T.Text
, c_passkey :: SecureMem
, c_nodeAddress :: T.Text
, c_nodeUser :: BS.ByteString
, c_nodePwd :: BS.ByteString
, c_port :: Int
, c_useTls :: Bool
, c_certificate :: String
, c_key :: String
2023-01-24 19:27:32 +00:00
, c_smtpHost :: String
2023-01-24 19:54:21 +00:00
, c_smtpPort :: Integer
2023-01-24 19:27:32 +00:00
, c_smtpUser :: String
, c_smtpPwd :: String
2023-06-20 12:54:24 +00:00
, c_confirmations :: Integer
2022-07-12 21:08:27 +00:00
}
deriving (Eq, Show)
loadZGoConfig :: Worth FilePath -> IO Config
loadZGoConfig path = do
config <- load [path]
dbHost <- require config "dbHost"
dbName <- require config "dbName"
dbUser <- require config "dbUser"
dbPassword <- require config "dbPassword"
nodeAddress <- require config "nodeAddress"
nodeUser <- require config "nodeUser"
nodePwd <- require config "nodePassword"
passkey <- secureMemFromByteString <$> require config "passkey"
port <- require config "port"
useTls <- require config "tls"
cert <- require config "certificate"
key <- require config "key"
2023-01-24 19:27:32 +00:00
mailHost <- require config "smtpHost"
mailPort <- require config "smtpPort"
mailUser <- require config "smtpUser"
mailPwd <- require config "smtpPwd"
2023-06-20 12:54:24 +00:00
conf <- require config "confirmations"
2022-07-12 21:08:27 +00:00
return $
Config
dbHost
dbName
dbUser
dbPassword
passkey
nodeAddress
nodeUser
nodePwd
port
useTls
cert
key
2023-01-24 19:27:32 +00:00
mailHost
mailPort
mailUser
mailPwd
2023-06-20 12:54:24 +00:00
conf