mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-17 20:41:49 +03:00
a7a60c2dfe
* new typeclass to abstract the logic of QueryLog-ing * abstract the logic of logging websocket-server logs introduce a MonadWSLog typeclass * move catalog initialization to init step expose a helper function to migrate catalog create schema cache in initialiseCtx * expose various modules and functions for pro
73 lines
2.0 KiB
Haskell
73 lines
2.0 KiB
Haskell
-- | API related to server configuration
|
|
module Hasura.Server.API.Config
|
|
-- required by pro
|
|
( ServerConfig(..)
|
|
, runGetConfig
|
|
) where
|
|
|
|
import Data.Aeson.Casing
|
|
import Data.Aeson.TH
|
|
|
|
import Hasura.Prelude
|
|
import Hasura.Server.Auth
|
|
import Hasura.Server.Auth.JWT
|
|
import Hasura.Server.Version (HasVersion, Version, currentVersion)
|
|
|
|
import qualified Hasura.GraphQL.Execute.LiveQuery.Options as LQ
|
|
|
|
data JWTInfo
|
|
= JWTInfo
|
|
{ jwtiClaimsNamespace :: !JWTConfigClaims
|
|
, jwtiClaimsFormat :: !JWTClaimsFormat
|
|
} deriving (Show, Eq)
|
|
|
|
$(deriveToJSON (aesonDrop 4 snakeCase) ''JWTInfo)
|
|
|
|
data ServerConfig
|
|
= ServerConfig
|
|
{ scfgVersion :: !Version
|
|
, scfgIsAdminSecretSet :: !Bool
|
|
, scfgIsAuthHookSet :: !Bool
|
|
, scfgIsJwtSet :: !Bool
|
|
, scfgJwt :: !(Maybe JWTInfo)
|
|
, scfgIsAllowListEnabled :: !Bool
|
|
, scfgLiveQueries :: !LQ.LiveQueriesOptions
|
|
, scfgConsoleAssetsDir :: !(Maybe Text)
|
|
} deriving (Show, Eq)
|
|
|
|
$(deriveToJSON (aesonDrop 4 snakeCase) ''ServerConfig)
|
|
|
|
runGetConfig :: HasVersion => AuthMode -> Bool -> LQ.LiveQueriesOptions -> Maybe Text -> ServerConfig
|
|
runGetConfig am isAllowListEnabled liveQueryOpts consoleAssetsDir = ServerConfig
|
|
currentVersion
|
|
(isAdminSecretSet am)
|
|
(isAuthHookSet am)
|
|
(isJWTSet am)
|
|
(getJWTInfo am)
|
|
isAllowListEnabled
|
|
liveQueryOpts
|
|
consoleAssetsDir
|
|
|
|
isAdminSecretSet :: AuthMode -> Bool
|
|
isAdminSecretSet = \case
|
|
AMNoAuth -> False
|
|
_ -> True
|
|
|
|
isAuthHookSet :: AuthMode -> Bool
|
|
isAuthHookSet = \case
|
|
AMAdminSecretAndHook _ _ -> True
|
|
_ -> False
|
|
|
|
isJWTSet :: AuthMode -> Bool
|
|
isJWTSet = \case
|
|
AMAdminSecretAndJWT{} -> True
|
|
_ -> False
|
|
|
|
getJWTInfo :: AuthMode -> Maybe JWTInfo
|
|
getJWTInfo (AMAdminSecretAndJWT _ jwtCtx _) =
|
|
Just $ JWTInfo claimsNs format
|
|
where
|
|
claimsNs = jcxClaimNs jwtCtx
|
|
format = jcxClaimsFormat jwtCtx
|
|
getJWTInfo _ = Nothing
|