mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-17 04:24:35 +03:00
f243760398
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/2765 Co-authored-by: Philip Lykke Carlsen <358550+plcplc@users.noreply.github.com> Co-authored-by: Chris Done <11019+chrisdone@users.noreply.github.com> Co-authored-by: Aishwarya Rao <59638722+aishwaryarao712@users.noreply.github.com> Co-authored-by: Tirumarai Selvan <8663570+tirumaraiselvan@users.noreply.github.com> Co-authored-by: Karthikeyan Chinnakonda <15602904+codingkarthik@users.noreply.github.com> Co-authored-by: Ikechukwu Eze <22247592+iykekings@users.noreply.github.com> Co-authored-by: Brandon Simmons <210815+jberryman@users.noreply.github.com> Co-authored-by: awjchen <13142944+awjchen@users.noreply.github.com> Co-authored-by: Martin Mark <74692114+martin-hasura@users.noreply.github.com> Co-authored-by: Abby Sassel <3883855+sassela@users.noreply.github.com> Co-authored-by: Sooraj <8408875+soorajshankar@users.noreply.github.com> Co-authored-by: Sameer Kolhar <6604943+kolharsam@users.noreply.github.com> Co-authored-by: Vijay Prasanna <11921040+vijayprasanna13@users.noreply.github.com> Co-authored-by: hasura-bot <30118761+hasura-bot@users.noreply.github.com> Co-authored-by: Rakesh Emmadi <12475069+rakeshkky@users.noreply.github.com> Co-authored-by: Sibi Prabakaran <737477+psibi@users.noreply.github.com> Co-authored-by: Robert <132113+robx@users.noreply.github.com> Co-authored-by: Vishnu Bharathi <4211715+scriptnull@users.noreply.github.com> Co-authored-by: Praveen Durairaju <14110316+praveenweb@users.noreply.github.com> Co-authored-by: Abhijeet Khangarot <26903230+abhi40308@users.noreply.github.com> GitOrigin-RevId: b3b07c3b42da9f3daa450d6d9e5fbf0bf506c651
103 lines
2.7 KiB
Haskell
103 lines
2.7 KiB
Haskell
-- | API related to server configuration
|
|
module Hasura.Server.API.Config
|
|
-- required by pro
|
|
( ServerConfig (..),
|
|
runGetConfig,
|
|
)
|
|
where
|
|
|
|
import Data.Aeson.TH
|
|
import Data.HashMap.Strict qualified as Map
|
|
import Data.HashSet qualified as Set
|
|
import Hasura.GraphQL.Execute.LiveQuery.Options qualified as LQ
|
|
import Hasura.Prelude
|
|
import Hasura.RQL.Types
|
|
( FunctionPermissionsCtx,
|
|
RemoteSchemaPermsCtx,
|
|
)
|
|
import Hasura.Server.Auth
|
|
import Hasura.Server.Auth.JWT
|
|
import Hasura.Server.Types (ExperimentalFeature)
|
|
import Hasura.Server.Version (Version, currentVersion)
|
|
|
|
data JWTInfo = JWTInfo
|
|
{ jwtiClaimsNamespace :: !JWTNamespace,
|
|
jwtiClaimsFormat :: !JWTClaimsFormat,
|
|
jwtiClaimsMap :: !(Maybe JWTCustomClaimsMap)
|
|
}
|
|
deriving (Show, Eq)
|
|
|
|
$(deriveToJSON hasuraJSON ''JWTInfo)
|
|
|
|
data ServerConfig = ServerConfig
|
|
{ scfgVersion :: !Version,
|
|
scfgIsFunctionPermissionsInferred :: !FunctionPermissionsCtx,
|
|
scfgIsRemoteSchemaPermissionsEnabled :: !RemoteSchemaPermsCtx,
|
|
scfgIsAdminSecretSet :: !Bool,
|
|
scfgIsAuthHookSet :: !Bool,
|
|
scfgIsJwtSet :: !Bool,
|
|
scfgJwt :: !(Map.HashMap (Maybe StringOrURI) JWTInfo),
|
|
scfgIsAllowListEnabled :: !Bool,
|
|
scfgLiveQueries :: !LQ.LiveQueriesOptions,
|
|
scfgConsoleAssetsDir :: !(Maybe Text),
|
|
scfgExperimentalFeatures :: !(Set.HashSet ExperimentalFeature)
|
|
}
|
|
deriving (Show, Eq)
|
|
|
|
$(deriveToJSON hasuraJSON ''ServerConfig)
|
|
|
|
runGetConfig ::
|
|
FunctionPermissionsCtx ->
|
|
RemoteSchemaPermsCtx ->
|
|
AuthMode ->
|
|
Bool ->
|
|
LQ.LiveQueriesOptions ->
|
|
Maybe Text ->
|
|
Set.HashSet ExperimentalFeature ->
|
|
ServerConfig
|
|
runGetConfig
|
|
functionPermsCtx
|
|
remoteSchemaPermsCtx
|
|
am
|
|
isAllowListEnabled
|
|
liveQueryOpts
|
|
consoleAssetsDir
|
|
experimentalFeatures =
|
|
ServerConfig
|
|
currentVersion
|
|
functionPermsCtx
|
|
remoteSchemaPermsCtx
|
|
(isAdminSecretSet am)
|
|
(isAuthHookSet am)
|
|
(isJWTSet am)
|
|
(getJWTInfo am)
|
|
isAllowListEnabled
|
|
liveQueryOpts
|
|
consoleAssetsDir
|
|
experimentalFeatures
|
|
|
|
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 -> Map.HashMap (Maybe StringOrURI) JWTInfo
|
|
getJWTInfo (AMAdminSecretAndJWT _ jwtCtxs _) =
|
|
let f jwtCtx = case jcxClaims jwtCtx of
|
|
JCNamespace namespace claimsFormat ->
|
|
JWTInfo namespace claimsFormat Nothing
|
|
JCMap claimsMap ->
|
|
JWTInfo (ClaimNs defaultClaimsNamespace) defaultClaimsFormat $ Just claimsMap
|
|
in fmap f jwtCtxs
|
|
getJWTInfo _ = mempty
|