]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Prelude/Config.hs
[FIX] merge
[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 Prelude (read)
17 import System.IO (FilePath)
18 import Data.Ini (readIniFile, lookupValue)
19 import Data.Either.Extra (Either(Left, Right))
20 import Gargantext.Prelude
21 import Data.Text (Text, pack)
22 import GHC.Generics (Generic)
23 import Control.Lens (makeLenses)
24
25
26 data GargConfig = GargConfig { _gc_masteruser :: !Text
27 , _gc_secretkey :: !Text
28 , _gc_datafilepath :: !FilePath
29
30 , _gc_frame_write_url :: !Text
31 , _gc_frame_calc_url :: !Text
32
33 , _gc_frame_searx_url :: !Text
34 , _gc_frame_istex_url :: !Text
35
36 , _gc_max_docs_scrapers :: !Integer
37 }
38 deriving (Generic, Show)
39
40 makeLenses ''GargConfig
41
42 readConfig :: FilePath -> IO GargConfig
43 readConfig fp = do
44 ini <- readIniFile fp
45 let ini'' = case ini of
46 Left e -> panic (pack $ "gargantext.ini not found" <> show e)
47 Right ini' -> ini'
48
49 let val x = case (lookupValue (pack "gargantext") (pack x) ini'') of
50 Left _ -> panic (pack $ "ERROR: add " <> x <> " to your gargantext.ini")
51 Right p' -> p'
52
53 pure $ GargConfig (val "MASTER_USER")
54 (val "SECRET_KEY")
55 (cs $ val "DATA_FILEPATH")
56 (val "FRAME_WRITE_URL")
57 (val "FRAME_CALC_URL")
58 (val "FRAME_SEARX_URL")
59 (val "FRAME_ISTEX_URL")
60 (read $ cs $ val "MAX_DOCS_SCRAPERS")
61
62 defaultConfig :: GargConfig
63 defaultConfig = GargConfig "gargantua"
64 "secret"
65 "data"
66 "https://frame_write.url"
67 "https://frame_calc.url"
68 "https://frame_searx.url"
69 "https://frame_istex.url"
70 1000