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