]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/API/Admin/EnvTypes.hs
[mail] add HasMail class, use gargantext.ini for config
[gargantext.git] / src / Gargantext / API / Admin / EnvTypes.hs
1 -- |
2
3 {-# LANGUAGE TemplateHaskell #-}
4
5 module Gargantext.API.Admin.EnvTypes where
6
7 import Control.Lens
8 import Data.Pool (Pool)
9 import Database.PostgreSQL.Simple (Connection)
10 import GHC.Generics (Generic)
11 import Network.HTTP.Client (Manager)
12 import Servant.Client (BaseUrl)
13 import Servant.Job.Async (HasJobEnv(..), Job)
14 import System.Log.FastLogger
15 import qualified Servant.Job.Core
16
17 import Gargantext.API.Ngrams.Types (HasRepoVar(..), HasRepoSaver(..), HasRepo(..), RepoEnv(..))
18 import Gargantext.API.Admin.Types
19 import Gargantext.API.Admin.Orchestrator.Types
20 import Gargantext.Core.NodeStory
21 import Gargantext.Core.Mail.Types (HasMail, mailSettings)
22 import Gargantext.Database.Prelude (HasConnectionPool(..), HasConfig(..))
23 import Gargantext.Prelude
24 import Gargantext.Prelude.Config (GargConfig(..))
25 import Gargantext.Prelude.Mail.Types (MailConfig)
26
27 data Env = Env
28 { _env_settings :: !Settings
29 , _env_logger :: !LoggerSet
30 , _env_pool :: !(Pool Connection)
31 , _env_repo :: !RepoEnv
32 , _env_nodeStory :: !NodeStoryEnv
33 , _env_manager :: !Manager
34 , _env_self_url :: !BaseUrl
35 , _env_scrapers :: !ScrapersEnv
36 , _env_config :: !GargConfig
37 , _env_mail :: !MailConfig
38 }
39 deriving (Generic)
40
41 makeLenses ''Env
42
43 instance HasConfig Env where
44 hasConfig = env_config
45
46 instance HasConnectionPool Env where
47 connPool = env_pool
48
49 instance HasNodeStoryEnv Env where
50 hasNodeStory = env_nodeStory
51
52 instance HasNodeStoryVar Env where
53 hasNodeStoryVar = hasNodeStory . nse_getter
54
55 instance HasNodeStorySaver Env where
56 hasNodeStorySaver = hasNodeStory . nse_saver
57
58 instance HasSettings Env where
59 settings = env_settings
60
61 instance HasMail Env where
62 mailSettings = env_mail
63
64 -- Specific to Repo
65 instance HasRepoVar Env where
66 repoVar = repoEnv . repoVar
67 instance HasRepoSaver Env where
68 repoSaver = repoEnv . repoSaver
69 instance HasRepo Env where
70 repoEnv = env_repo
71
72
73
74
75 instance Servant.Job.Core.HasEnv Env (Job JobLog JobLog) where
76 _env = env_scrapers . Servant.Job.Core._env
77
78 instance HasJobEnv Env JobLog JobLog where
79 job_env = env_scrapers
80
81 data MockEnv = MockEnv
82 { _menv_firewall :: !FireWall
83 }
84 deriving (Generic)
85
86 makeLenses ''MockEnv
87
88
89
90 data DevEnv = DevEnv
91 { _dev_env_settings :: !Settings
92 , _dev_env_repo :: !RepoEnv
93 , _dev_env_config :: !GargConfig
94 , _dev_env_pool :: !(Pool Connection)
95 , _dev_env_nodeStory :: !NodeStoryEnv
96 , _dev_env_mail :: !MailConfig
97 }
98
99 makeLenses ''DevEnv
100
101 instance HasConfig DevEnv where
102 hasConfig = dev_env_config
103
104 instance HasConnectionPool DevEnv where
105 connPool = dev_env_pool
106
107 instance HasSettings DevEnv where
108 settings = dev_env_settings
109
110
111 instance HasNodeStoryEnv DevEnv where
112 hasNodeStory = dev_env_nodeStory
113
114 instance HasNodeStoryVar DevEnv where
115 hasNodeStoryVar = hasNodeStory . nse_getter
116
117 instance HasNodeStorySaver DevEnv where
118 hasNodeStorySaver = hasNodeStory . nse_saver
119
120
121 instance HasRepoVar DevEnv where
122 repoVar = repoEnv . repoVar
123 instance HasRepoSaver DevEnv where
124 repoSaver = repoEnv . repoSaver
125 instance HasRepo DevEnv where
126 repoEnv = dev_env_repo
127
128 instance HasMail DevEnv where
129 mailSettings = dev_env_mail