]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Prelude/Config.hs
Merge branch 'dev-cbor' into dev
[gargantext.git] / src / Gargantext / Prelude / Config.hs
1 {-|
2 Module : Gargantext.Prelude.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.Prelude.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_datafilepath :: !FilePath
28
29 , _gc_frame_write_url :: !Text
30 , _gc_frame_calc_url :: !Text
31
32 , _gc_frame_searx_url :: !Text
33 , _gc_frame_istex_url :: !Text
34 }
35 deriving (Generic, Show)
36
37 makeLenses ''GargConfig
38
39 readConfig :: FilePath -> IO GargConfig
40 readConfig fp = do
41 ini <- readIniFile fp
42 let ini'' = case ini of
43 Left e -> panic (pack $ "No ini file error" <> show e)
44 Right ini' -> ini'
45
46 let val x = case (lookupValue (pack "gargantext") (pack x) ini'') of
47 Left _ -> panic (pack $ "no" <> x)
48 Right p' -> p'
49
50 pure $ GargConfig (val "MASTER_USER")
51 (val "SECRET_KEY")
52 (cs $ val "DATA_FILEPATH")
53 (val "FRAME_WRITE_URL")
54 (val "FRAME_CALC_URL")
55 (val "FRAME_SEARX_URL")
56 (val "FRAME_ISTEX_URL")
57
58 defaultConfig :: GargConfig
59 defaultConfig = GargConfig "gargantua"
60 "secret"
61 "data"
62 "https://frame_write.url"
63 "https://frame_calc.url"
64 "https://frame_searx.url"
65 "https://frame_istex.url"