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
12 {-# LANGUAGE TemplateHaskell #-}
14 module Gargantext.Prelude.Config where
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)
26 data GargConfig = GargConfig { _gc_masteruser :: !Text
27 , _gc_secretkey :: !Text
28 , _gc_datafilepath :: !FilePath
30 , _gc_frame_write_url :: !Text
31 , _gc_frame_calc_url :: !Text
33 , _gc_frame_searx_url :: !Text
34 , _gc_frame_istex_url :: !Text
36 , _gc_max_docs_scrapers :: !Integer
38 deriving (Generic, Show)
40 makeLenses ''GargConfig
42 readConfig :: FilePath -> IO GargConfig
45 let ini'' = case ini of
46 Left e -> panic (pack $ "gargantext.ini not found" <> show e)
49 let val x = case (lookupValue (pack "gargantext") (pack x) ini'') of
50 Left _ -> panic (pack $ "ERROR: add " <> x <> " to your gargantext.ini")
53 pure $ GargConfig (val "MASTER_USER")
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")
62 defaultConfig :: GargConfig
63 defaultConfig = GargConfig "gargantua"
66 "https://frame_write.url"
67 "https://frame_calc.url"
68 "https://frame_searx.url"
69 "https://frame_istex.url"