summaryrefslogtreecommitdiff
path: root/fig-monitor-bullfrog/src/Fig/Monitor/Bullfrog/Utils.hs
blob: b0ae02b4b2a3bf0a786bfded0f3aa7afd47b723d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{-# Language ApplicativeDo #-}

module Fig.Monitor.Bullfrog.Utils
  ( FigMonitorBullfrogException(..)
  , Config(..)
  , loadConfig
  ) where

import Fig.Prelude

import qualified Toml

newtype FigMonitorBullfrogException = FigMonitorBullfrogException Text
  deriving (Show, Eq, Ord)
instance Exception FigMonitorBullfrogException

newtype Config = Config
  { authToken :: Text
  } deriving (Show, Eq, Ord)

configCodec :: Toml.TomlCodec Config
configCodec = do
  authToken <- Toml.text "auth_token" Toml..= (\a -> a.authToken)
  pure $ Config{..}

loadConfig :: FilePath -> IO Config
loadConfig path = Toml.decodeFileEither configCodec path >>= \case
  Left err -> throwM . FigMonitorBullfrogException $ tshow err
  Right config -> pure config