summaryrefslogtreecommitdiff
path: root/fig-monitor-bullfrog/src/Fig/Monitor/Bullfrog
diff options
context:
space:
mode:
Diffstat (limited to 'fig-monitor-bullfrog/src/Fig/Monitor/Bullfrog')
-rw-r--r--fig-monitor-bullfrog/src/Fig/Monitor/Bullfrog/Utils.hs29
1 files changed, 29 insertions, 0 deletions
diff --git a/fig-monitor-bullfrog/src/Fig/Monitor/Bullfrog/Utils.hs b/fig-monitor-bullfrog/src/Fig/Monitor/Bullfrog/Utils.hs
new file mode 100644
index 0000000..b0ae02b
--- /dev/null
+++ b/fig-monitor-bullfrog/src/Fig/Monitor/Bullfrog/Utils.hs
@@ -0,0 +1,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