]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Config.hs
[CLEAN] Instances HyperData (WIP)
[gargantext.git] / src / Gargantext / Config.hs
1 {-|
2 Module : Gargantext.Config
3 Description : Textmining Collaborative Platform
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
8 Portability : POSIX
9
10 -}
11
12 {-# LANGUAGE TemplateHaskell #-}
13
14 module Gargantext.Config where
15
16 import System.IO (FilePath)
17 import Data.Ini (readIniFile, lookupValue)
18 import Data.Either.Extra (Either(Left, Right))
19 import Gargantext.Prelude
20 import Data.Text (Text, pack)
21 import GHC.Generics (Generic)
22 import Control.Lens (makeLenses)
23
24
25 data GargConfig = GargConfig { _gc_masteruser :: Text
26 , _gc_secretkey :: Text
27 , _gc_frame_write_url :: Text
28 , _gc_frame_calc_url :: Text
29 }
30 deriving (Generic)
31
32 makeLenses ''GargConfig
33
34
35 readConfig :: FilePath -> IO GargConfig
36 readConfig fp = do
37 ini <- readIniFile fp
38 let ini'' = case ini of
39 Left e -> panic (pack $ "No ini file error" <> show e)
40 Right ini' -> ini'
41
42 let val x = case (lookupValue (pack "gargantext") (pack x) ini'') of
43 Left _ -> panic (pack $ "no" <> x)
44 Right p' -> p'
45
46 pure $ GargConfig (val "MASTER_USER")
47 (val "SECRET_KEY")
48 (val "FRAME_WRITE_URL")
49 (val "FRAME_CALC_URL")
50
51 defaultConfig :: GargConfig
52 defaultConfig = GargConfig "gargantua" "secret" "https://frame_write.url" "https://frame_calc.url"