]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Prelude/Config.hs
[FEAT] Adding Visio micro-service (Jitsi)
[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 Data.Text as T
21 import GHC.Generics (Generic)
22 import Control.Lens (makeLenses)
23
24 import Gargantext.Prelude
25
26
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
30
31 data GargConfig = GargConfig { _gc_url :: !T.Text
32 , _gc_url_backend_api :: !T.Text
33
34 , _gc_masteruser :: !T.Text
35 , _gc_secretkey :: !T.Text
36
37 , _gc_datafilepath :: !FilePath
38 , _gc_repofilepath :: !FilePath
39
40 , _gc_frame_write_url :: !T.Text
41 , _gc_frame_calc_url :: !T.Text
42 , _gc_frame_visio_url :: !T.Text
43
44 , _gc_frame_searx_url :: !T.Text
45 , _gc_frame_istex_url :: !T.Text
46
47 , _gc_max_docs_scrapers :: !Integer
48 }
49 deriving (Generic, Show)
50
51 makeLenses ''GargConfig
52
53 readConfig :: FilePath -> IO GargConfig
54 readConfig fp = do
55 ini <- readIniFile fp
56 let ini'' = case ini of
57 Left e -> panic (T.pack $ "gargantext.ini not found" <> show e)
58 Right ini' -> ini'
59
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")
62 Right p' -> p'
63
64 pure $ GargConfig (stripRight '/' $ val "URL")
65 (stripRight '/' $ val "URL_BACKEND_API")
66 (val "MASTER_USER")
67 (val "SECRET_KEY")
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")
76
77 {- UNUSED
78 defaultConfig :: GargConfig
79 defaultConfig = GargConfig "https://localhost"
80 "https://localhost:8008/api/v1.0"
81 "gargantua"
82 "secret"
83 "data"
84 "repos/"
85 "https://frame_write.url"
86 "https://frame_calc.url"
87 "https://frame_searx.url"
88 "https://frame_istex.url"
89 1000
90 -}