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))
21 import GHC.Generics (Generic)
22 import Control.Lens (makeLenses)
24 import Gargantext.Prelude
27 -- | strip a given character from end of string
28 stripRight :: Char -> T.Text -> T.Text
29 stripRight c s = if T.last s == c then stripRight c (T.take (T.length s - 1) s) else s
31 data GargConfig = GargConfig { _gc_url :: !T.Text
32 , _gc_url_backend_api :: !T.Text
34 , _gc_masteruser :: !T.Text
35 , _gc_secretkey :: !T.Text
37 , _gc_datafilepath :: !FilePath
38 , _gc_repofilepath :: !FilePath
40 , _gc_frame_write_url :: !T.Text
41 , _gc_frame_calc_url :: !T.Text
43 , _gc_frame_searx_url :: !T.Text
44 , _gc_frame_istex_url :: !T.Text
46 , _gc_max_docs_scrapers :: !Integer
48 deriving (Generic, Show)
50 makeLenses ''GargConfig
52 readConfig :: FilePath -> IO GargConfig
55 let ini'' = case ini of
56 Left e -> panic (T.pack $ "gargantext.ini not found" <> show e)
59 let val x = case (lookupValue (T.pack "gargantext") (T.pack x) ini'') of
60 Left _ -> panic (T.pack $ "ERROR: add " <> x <> " to your gargantext.ini")
63 pure $ GargConfig (stripRight '/' $ val "URL")
64 (stripRight '/' $ val "URL_BACKEND_API")
67 (cs $ val "DATA_FILEPATH")
68 (cs $ val "REPO_FILEPATH")
69 (stripRight '/' $ val "FRAME_WRITE_URL")
70 (stripRight '/' $ val "FRAME_CALC_URL")
71 (stripRight '/' $ val "FRAME_SEARX_URL")
72 (stripRight '/' $ val "FRAME_ISTEX_URL")
73 (read $ cs $ val "MAX_DOCS_SCRAPERS")
76 defaultConfig :: GargConfig
77 defaultConfig = GargConfig "https://localhost"
78 "https://localhost:8008/api/v1.0"
83 "https://frame_write.url"
84 "https://frame_calc.url"
85 "https://frame_searx.url"
86 "https://frame_istex.url"