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
50 class HasSettings env where
51 settings :: Getter env Settings
54 data FireWall = FireWall { unFireWall :: Bool }
57 { _env_settings :: !Settings
58 , _env_logger :: !LoggerSet
59 , _env_pool :: !(Pool Connection)
60 , _env_repo :: !RepoEnv
61 , _env_manager :: !Manager
62 , _env_self_url :: !BaseUrl
63 , _env_scrapers :: !ScrapersEnv
64 , _env_config :: !GargConfig
70 instance HasConfig Env where
73 instance HasConnectionPool Env where
76 instance HasRepoVar Env where
77 repoVar = repoEnv . repoVar
79 instance HasRepoSaver Env where
80 repoSaver = repoEnv . repoSaver
82 instance HasRepo Env where
85 instance HasSettings Env where
86 settings = env_settings
88 instance Servant.Job.Core.HasEnv Env (Job JobLog JobLog) where
89 _env = env_scrapers . Servant.Job.Core._env
91 instance HasJobEnv Env JobLog JobLog where
92 job_env = env_scrapers
94 data MockEnv = MockEnv
95 { _menv_firewall :: !FireWall
103 { _dev_env_pool :: !(Pool Connection)
104 , _dev_env_repo :: !RepoEnv
105 , _dev_env_settings :: !Settings
106 , _dev_env_config :: !GargConfig
111 instance HasConfig DevEnv where
112 config = dev_env_config
114 instance HasConnectionPool DevEnv where
115 connPool = dev_env_pool
117 instance HasRepoVar DevEnv where
118 repoVar = repoEnv . repoVar
120 instance HasRepoSaver DevEnv where
121 repoSaver = repoEnv . repoSaver
123 instance HasRepo DevEnv where
124 repoEnv = dev_env_repo
126 instance HasSettings DevEnv where
127 settings = dev_env_settings