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
42 , _gc_frame_visio_url :: !T.Text
44 , _gc_frame_searx_url :: !T.Text
45 , _gc_frame_istex_url :: !T.Text
47 , _gc_max_docs_scrapers :: !Integer
49 deriving (Generic, Show)
51 makeLenses ''GargConfig
53 readConfig :: FilePath -> IO GargConfig
56 let ini'' = case ini of
57 Left e -> panic (T.pack $ "gargantext.ini not found" <> show e)
60 let val x = case (lookupValue (T.pack "gargantext") (T.pack x) ini'') of
61 Left _ -> panic (T.pack $ "ERROR: add " <> x <> " to your gargantext.ini")
64 pure $ GargConfig (stripRight '/' $ val "URL")
65 (stripRight '/' $ val "URL_BACKEND_API")
68 (cs $ val "DATA_FILEPATH")
69 (cs $ val "REPO_FILEPATH")
70 (stripRight '/' $ val "FRAME_WRITE_URL")
71 (stripRight '/' $ val "FRAME_CALC_URL")
72 (stripRight '/' $ val "FRAME_VISIO_URL")
73 (stripRight '/' $ val "FRAME_SEARX_URL")
74 (stripRight '/' $ val "FRAME_ISTEX_URL")
75 (read $ cs $ val "MAX_DOCS_SCRAPERS")
78 defaultConfig :: GargConfig
79 defaultConfig = GargConfig "https://localhost"
80 "https://localhost:8008/api/v1.0"
85 "https://frame_write.url"
86 "https://frame_calc.url"
87 "https://frame_searx.url"
88 "https://frame_istex.url"