3 {-# LANGUAGE TemplateHaskell #-}
5 module Gargantext.API.Admin.Types where
8 import Control.Monad.Logger
9 import Data.ByteString (ByteString)
10 import Data.Pool (Pool)
11 import Database.PostgreSQL.Simple (Connection)
13 import GHC.Generics (Generic)
14 import Network.HTTP.Client (Manager)
15 import Servant.Auth.Server (JWTSettings, CookieSettings(..))
16 import Servant.Client (BaseUrl)
17 import Servant.Job.Async (HasJobEnv(..), Job)
18 import System.Log.FastLogger
19 import qualified Servant.Job.Core
21 import Gargantext.API.Admin.Orchestrator.Types
22 import Gargantext.API.Ngrams.Types (HasRepoVar(..), HasRepoSaver(..), HasRepo(..), RepoEnv(..))
23 import Gargantext.Database.Prelude (HasConnectionPool(..), HasConfig(..))
24 import Gargantext.Prelude
25 import Gargantext.Prelude.Config (GargConfig(..))
29 data SendEmailType = SendEmailViaAws
32 deriving (Show, Read, Enum, Bounded, Generic)
35 data Settings = Settings
36 { _allowedOrigin :: ByteString -- allowed origin for CORS
37 , _allowedHost :: ByteString -- allowed host for CORS
38 , _appPort :: PortNumber
39 , _logLevelLimit :: LogLevel -- log level from the monad-logger package
40 -- , _dbServer :: Text
41 -- ^ this is not used yet
42 , _jwtSettings :: JWTSettings
43 , _cookieSettings :: CookieSettings
44 , _sendLoginEmails :: SendEmailType
45 , _scrapydUrl :: BaseUrl
46 , _config :: GargConfig
51 class HasSettings env where
52 settings :: Getter env Settings
55 data FireWall = FireWall { unFireWall :: Bool }
58 { _env_settings :: !Settings
59 , _env_logger :: !LoggerSet
60 , _env_pool :: !(Pool Connection)
61 , _env_repo :: !RepoEnv
62 , _env_manager :: !Manager
63 , _env_self_url :: !BaseUrl
64 , _env_scrapers :: !ScrapersEnv
65 , _env_gargConfig :: !GargConfig
71 instance HasConfig Env where
72 hasConfig = env_gargConfig
74 instance HasConnectionPool Env where
77 instance HasRepoVar Env where
78 repoVar = repoEnv . repoVar
80 instance HasRepoSaver Env where
81 repoSaver = repoEnv . repoSaver
83 instance HasRepo Env where
86 instance HasSettings Env where
87 settings = env_settings
89 instance Servant.Job.Core.HasEnv Env (Job JobLog JobLog) where
90 _env = env_scrapers . Servant.Job.Core._env
92 instance HasJobEnv Env JobLog JobLog where
93 job_env = env_scrapers
95 data MockEnv = MockEnv
96 { _menv_firewall :: !FireWall
104 { _dev_env_pool :: !(Pool Connection)
105 , _dev_env_repo :: !RepoEnv
106 , _dev_env_settings :: !Settings
107 , _dev_env_config :: !GargConfig
112 instance HasConfig DevEnv where
113 hasConfig = dev_env_config
115 instance HasConnectionPool DevEnv where
116 connPool = dev_env_pool
118 instance HasRepoVar DevEnv where
119 repoVar = repoEnv . repoVar
121 instance HasRepoSaver DevEnv where
122 repoSaver = repoEnv . repoSaver
124 instance HasRepo DevEnv where
125 repoEnv = dev_env_repo
127 instance HasSettings DevEnv where
128 settings = dev_env_settings