]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Prelude/Config.hs
[FIX] SocialList working for others than Ngrams with Hierarchical groups
[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_url :: !Text
27 , _gc_url_backend_api :: !Text
28
29 , _gc_masteruser :: !Text
30 , _gc_secretkey :: !Text
31
32 , _gc_datafilepath :: !FilePath
33 , _gc_repofilepath :: !FilePath
34
35 , _gc_frame_write_url :: !Text
36 , _gc_frame_calc_url :: !Text
37
38 , _gc_frame_searx_url :: !Text
39 , _gc_frame_istex_url :: !Text
40
41 , _gc_max_docs_scrapers :: !Integer
42 }
43 deriving (Generic, Show)
44
45 makeLenses ''GargConfig
46
47 readConfig :: FilePath -> IO GargConfig
48 readConfig fp = do
49 ini <- readIniFile fp
50 let ini'' = case ini of
51 Left e -> panic (pack $ "gargantext.ini not found" <> show e)
52 Right ini' -> ini'
53
54 let val x = case (lookupValue (pack "gargantext") (pack x) ini'') of
55 Left _ -> panic (pack $ "ERROR: add " <> x <> " to your gargantext.ini")
56 Right p' -> p'
57
58 pure $ GargConfig (val "URL")
59 (val "URL_BACKEND_API")
60 (val "MASTER_USER")
61 (val "SECRET_KEY")
62 (cs $ val "DATA_FILEPATH")
63 (cs $ val "REPO_FILEPATH")
64 (val "FRAME_WRITE_URL")
65 (val "FRAME_CALC_URL")
66 (val "FRAME_SEARX_URL")
67 (val "FRAME_ISTEX_URL")
68 (read $ cs $ val "MAX_DOCS_SCRAPERS")
69
70 {- UNUSED
71 defaultConfig :: GargConfig
72 defaultConfig = GargConfig "https://localhost"
73 "https://localhost:8008/api/v1.0"
74 "gargantua"
75 "secret"
76 "data"
77 "repos/"
78 "https://frame_write.url"
79 "https://frame_calc.url"
80 "https://frame_searx.url"
81 "https://frame_istex.url"
82 1000
83 -}