module Webserver.Data.Context where ---------------------------------------------------------------------------------------------------- import qualified Hasql.Pool as Pool import qualified Jose.Jwk as JWK import qualified System.Environment as Env import qualified Webserver.Data.Mode as Mode import qualified Webserver.Data.Sql.Cache.Session as Session import Webserver.Data.Telemetry (TelemetryState) ---------------------------------------------------------------------------------------------------- {- A Context type. Created on app initialization and follows you around the app. Use this when you can't guarantee you'll have access to IO, since you need that for `getEnv` -} data Context = Context { mode :: !Mode.Mode , jwtKey :: !JWK.Jwk , dbPool :: !Pool.Pool , telemetry :: !TelemetryState } instance Show Context where show ctx = "Context { mode = " <> show ctx.mode <> ", dbPool = " <> ", telemetry = }" ---------------------------------------------------------------------------------------------------- loadContext :: Pool.Pool -> TelemetryState -> IO Context loadContext pool telemetrySt = do mode_ <- Env.getEnv "MODE" key <- Session.jwk return <| Context (Mode.modeFromString mode_) key pool telemetrySt