2022-03-16 03:39:21 +03:00
|
|
|
{-# LANGUAGE TemplateHaskell #-}
|
|
|
|
|
2020-04-24 10:55:51 +03:00
|
|
|
-- | API related to server configuration
|
2020-06-19 09:42:32 +03:00
|
|
|
module Hasura.Server.API.Config
|
2021-09-24 01:56:37 +03:00
|
|
|
-- required by pro
|
|
|
|
( ServerConfig (..),
|
|
|
|
runGetConfig,
|
|
|
|
)
|
|
|
|
where
|
2019-06-11 16:29:03 +03:00
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
import Data.Aeson.TH
|
|
|
|
import Data.HashSet qualified as Set
|
2022-03-21 13:39:49 +03:00
|
|
|
import Hasura.GraphQL.Execute.Subscription.Options qualified as ES
|
2021-09-24 01:56:37 +03:00
|
|
|
import Hasura.Prelude
|
2022-04-27 16:57:28 +03:00
|
|
|
import Hasura.RQL.Types.Function
|
|
|
|
import Hasura.RQL.Types.RemoteSchema
|
2021-09-24 01:56:37 +03:00
|
|
|
import Hasura.Server.Auth
|
|
|
|
import Hasura.Server.Auth.JWT
|
|
|
|
import Hasura.Server.Types (ExperimentalFeature)
|
2021-10-13 19:38:56 +03:00
|
|
|
import Hasura.Server.Version (Version, currentVersion)
|
2021-01-19 22:14:42 +03:00
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
data JWTInfo = JWTInfo
|
|
|
|
{ jwtiClaimsNamespace :: !JWTNamespace,
|
|
|
|
jwtiClaimsFormat :: !JWTClaimsFormat,
|
|
|
|
jwtiClaimsMap :: !(Maybe JWTCustomClaimsMap)
|
|
|
|
}
|
|
|
|
deriving (Show, Eq)
|
2019-06-11 16:29:03 +03:00
|
|
|
|
2021-01-19 22:14:42 +03:00
|
|
|
$(deriveToJSON hasuraJSON ''JWTInfo)
|
2019-06-11 16:29:03 +03:00
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
data ServerConfig = ServerConfig
|
|
|
|
{ scfgVersion :: !Version,
|
|
|
|
scfgIsFunctionPermissionsInferred :: !FunctionPermissionsCtx,
|
|
|
|
scfgIsRemoteSchemaPermissionsEnabled :: !RemoteSchemaPermsCtx,
|
|
|
|
scfgIsAdminSecretSet :: !Bool,
|
|
|
|
scfgIsAuthHookSet :: !Bool,
|
|
|
|
scfgIsJwtSet :: !Bool,
|
2022-02-14 02:33:49 +03:00
|
|
|
scfgJwt :: ![JWTInfo],
|
2021-09-24 01:56:37 +03:00
|
|
|
scfgIsAllowListEnabled :: !Bool,
|
2022-03-21 13:39:49 +03:00
|
|
|
scfgLiveQueries :: !ES.LiveQueriesOptions,
|
2022-04-22 22:53:12 +03:00
|
|
|
scfgStreamingQueries :: !ES.SubscriptionsOptions,
|
2021-09-24 01:56:37 +03:00
|
|
|
scfgConsoleAssetsDir :: !(Maybe Text),
|
|
|
|
scfgExperimentalFeatures :: !(Set.HashSet ExperimentalFeature)
|
|
|
|
}
|
|
|
|
deriving (Show, Eq)
|
|
|
|
|
2021-01-19 22:14:42 +03:00
|
|
|
$(deriveToJSON hasuraJSON ''ServerConfig)
|
2019-06-11 16:29:03 +03:00
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
runGetConfig ::
|
|
|
|
FunctionPermissionsCtx ->
|
|
|
|
RemoteSchemaPermsCtx ->
|
|
|
|
AuthMode ->
|
|
|
|
Bool ->
|
2022-03-21 13:39:49 +03:00
|
|
|
ES.LiveQueriesOptions ->
|
2022-04-22 22:53:12 +03:00
|
|
|
ES.SubscriptionsOptions ->
|
2021-09-24 01:56:37 +03:00
|
|
|
Maybe Text ->
|
|
|
|
Set.HashSet ExperimentalFeature ->
|
|
|
|
ServerConfig
|
2021-03-09 21:45:43 +03:00
|
|
|
runGetConfig
|
2021-09-24 01:56:37 +03:00
|
|
|
functionPermsCtx
|
|
|
|
remoteSchemaPermsCtx
|
|
|
|
am
|
|
|
|
isAllowListEnabled
|
|
|
|
liveQueryOpts
|
2022-04-22 22:53:12 +03:00
|
|
|
streamQueryOpts
|
2021-09-24 01:56:37 +03:00
|
|
|
consoleAssetsDir
|
|
|
|
experimentalFeatures =
|
|
|
|
ServerConfig
|
|
|
|
currentVersion
|
|
|
|
functionPermsCtx
|
|
|
|
remoteSchemaPermsCtx
|
|
|
|
(isAdminSecretSet am)
|
|
|
|
(isAuthHookSet am)
|
|
|
|
(isJWTSet am)
|
|
|
|
(getJWTInfo am)
|
|
|
|
isAllowListEnabled
|
|
|
|
liveQueryOpts
|
2022-04-22 22:53:12 +03:00
|
|
|
streamQueryOpts
|
2021-09-24 01:56:37 +03:00
|
|
|
consoleAssetsDir
|
|
|
|
experimentalFeatures
|
2020-04-06 07:53:58 +03:00
|
|
|
|
2019-06-11 16:29:03 +03:00
|
|
|
isAdminSecretSet :: AuthMode -> Bool
|
|
|
|
isAdminSecretSet = \case
|
|
|
|
AMNoAuth -> False
|
2021-09-24 01:56:37 +03:00
|
|
|
_ -> True
|
2019-06-11 16:29:03 +03:00
|
|
|
|
|
|
|
isAuthHookSet :: AuthMode -> Bool
|
|
|
|
isAuthHookSet = \case
|
|
|
|
AMAdminSecretAndHook _ _ -> True
|
2021-09-24 01:56:37 +03:00
|
|
|
_ -> False
|
2019-06-11 16:29:03 +03:00
|
|
|
|
|
|
|
isJWTSet :: AuthMode -> Bool
|
|
|
|
isJWTSet = \case
|
2021-09-24 01:56:37 +03:00
|
|
|
AMAdminSecretAndJWT {} -> True
|
|
|
|
_ -> False
|
2019-06-11 16:29:03 +03:00
|
|
|
|
2022-02-14 02:33:49 +03:00
|
|
|
getJWTInfo :: AuthMode -> [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
|