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
|
|
|
|
-- required by pro
|
|
|
|
( ServerConfig (..),
|
|
|
|
runGetConfig,
|
|
|
|
)
|
|
|
|
where
|
2019-06-11 16:29:03 +03:00
|
|
|
|
|
|
|
import Data.Aeson.TH
|
2021-03-09 21:45:43 +03:00
|
|
|
import Data.HashSet qualified as Set
|
2022-03-21 13:39:49 +03:00
|
|
|
import Hasura.GraphQL.Execute.Subscription.Options qualified as ES
|
2022-11-21 08:03:37 +03:00
|
|
|
import Hasura.GraphQL.Schema.NamingCase
|
2021-01-19 22:14:42 +03:00
|
|
|
import Hasura.Prelude
|
2023-04-24 18:17:15 +03:00
|
|
|
import Hasura.RQL.Types.Schema.Options qualified as Options
|
2019-06-11 16:29:03 +03:00
|
|
|
import Hasura.Server.Auth
|
|
|
|
import Hasura.Server.Auth.JWT
|
2023-02-08 06:35:19 +03:00
|
|
|
import Hasura.Server.Init.Config (API (METRICS), AllowListStatus)
|
2021-03-09 21:45:43 +03:00
|
|
|
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
|
|
|
|
2019-06-11 16:29:03 +03:00
|
|
|
data JWTInfo = JWTInfo
|
|
|
|
{ jwtiClaimsNamespace :: !JWTNamespace,
|
|
|
|
jwtiClaimsFormat :: !JWTClaimsFormat,
|
2020-08-31 19:40:01 +03:00
|
|
|
jwtiClaimsMap :: !(Maybe JWTCustomClaimsMap)
|
2021-09-24 01:56:37 +03:00
|
|
|
}
|
2019-06-11 16:29:03 +03:00
|
|
|
deriving (Show, Eq)
|
|
|
|
|
2021-01-19 22:14:42 +03:00
|
|
|
$(deriveToJSON hasuraJSON ''JWTInfo)
|
2019-06-11 16:29:03 +03:00
|
|
|
|
|
|
|
data ServerConfig = ServerConfig
|
2021-03-04 19:21:27 +03:00
|
|
|
{ scfgVersion :: !Version,
|
2022-07-14 20:57:28 +03:00
|
|
|
scfgIsFunctionPermissionsInferred :: !Options.InferFunctionPermissions,
|
|
|
|
scfgIsRemoteSchemaPermissionsEnabled :: !Options.RemoteSchemaPermissions,
|
2021-03-04 19:21:27 +03:00
|
|
|
scfgIsAdminSecretSet :: !Bool,
|
|
|
|
scfgIsAuthHookSet :: !Bool,
|
|
|
|
scfgIsJwtSet :: !Bool,
|
2022-02-14 02:33:49 +03:00
|
|
|
scfgJwt :: ![JWTInfo],
|
2023-02-08 06:35:19 +03:00
|
|
|
scfgIsAllowListEnabled :: !AllowListStatus,
|
2022-03-21 13:39:49 +03:00
|
|
|
scfgLiveQueries :: !ES.LiveQueriesOptions,
|
2022-04-22 22:53:12 +03:00
|
|
|
scfgStreamingQueries :: !ES.SubscriptionsOptions,
|
2021-03-04 19:21:27 +03:00
|
|
|
scfgConsoleAssetsDir :: !(Maybe Text),
|
2022-09-27 09:48:21 +03:00
|
|
|
scfgExperimentalFeatures :: !(Set.HashSet ExperimentalFeature),
|
2022-11-21 08:03:37 +03:00
|
|
|
scfgIsPrometheusMetricsEnabled :: !Bool,
|
2023-01-30 07:59:30 +03:00
|
|
|
scfgDefaultNamingConvention :: !NamingCase
|
2020-04-06 07:53:58 +03:00
|
|
|
}
|
|
|
|
deriving (Show, Eq)
|
2021-09-24 01:56:37 +03:00
|
|
|
|
2021-01-19 22:14:42 +03:00
|
|
|
$(deriveToJSON hasuraJSON ''ServerConfig)
|
2019-06-11 16:29:03 +03:00
|
|
|
|
2021-03-09 21:45:43 +03:00
|
|
|
runGetConfig ::
|
2022-07-14 20:57:28 +03:00
|
|
|
Options.InferFunctionPermissions ->
|
|
|
|
Options.RemoteSchemaPermissions ->
|
2021-03-09 21:45:43 +03:00
|
|
|
AuthMode ->
|
2023-02-08 06:35:19 +03:00
|
|
|
AllowListStatus ->
|
2022-03-21 13:39:49 +03:00
|
|
|
ES.LiveQueriesOptions ->
|
2022-04-22 22:53:12 +03:00
|
|
|
ES.SubscriptionsOptions ->
|
2021-03-09 21:45:43 +03:00
|
|
|
Maybe Text ->
|
|
|
|
Set.HashSet ExperimentalFeature ->
|
2022-09-27 09:48:21 +03:00
|
|
|
Set.HashSet API ->
|
2023-01-30 07:59:30 +03:00
|
|
|
NamingCase ->
|
2021-03-09 21:45:43 +03:00
|
|
|
ServerConfig
|
|
|
|
runGetConfig
|
|
|
|
functionPermsCtx
|
|
|
|
remoteSchemaPermsCtx
|
|
|
|
am
|
2023-02-08 06:35:19 +03:00
|
|
|
allowListStatus
|
2021-03-09 21:45:43 +03:00
|
|
|
liveQueryOpts
|
2022-04-22 22:53:12 +03:00
|
|
|
streamQueryOpts
|
2021-03-09 21:45:43 +03:00
|
|
|
consoleAssetsDir
|
2022-09-27 09:48:21 +03:00
|
|
|
experimentalFeatures
|
2022-11-21 08:03:37 +03:00
|
|
|
enabledAPIs
|
|
|
|
defaultNamingConvention =
|
2021-03-09 21:45:43 +03:00
|
|
|
ServerConfig
|
2020-04-06 07:53:58 +03:00
|
|
|
currentVersion
|
2021-02-12 20:01:41 +03:00
|
|
|
functionPermsCtx
|
2021-03-04 19:21:27 +03:00
|
|
|
remoteSchemaPermsCtx
|
2020-04-06 07:53:58 +03:00
|
|
|
(isAdminSecretSet am)
|
|
|
|
(isAuthHookSet am)
|
|
|
|
(isJWTSet am)
|
|
|
|
(getJWTInfo am)
|
2023-02-08 06:35:19 +03:00
|
|
|
allowListStatus
|
2020-04-06 07:53:58 +03:00
|
|
|
liveQueryOpts
|
2022-04-22 22:53:12 +03:00
|
|
|
streamQueryOpts
|
2020-06-03 07:06:23 +03:00
|
|
|
consoleAssetsDir
|
2021-03-09 21:45:43 +03:00
|
|
|
experimentalFeatures
|
2022-09-27 09:48:21 +03:00
|
|
|
isPrometheusMetricsEnabled
|
2022-11-21 08:03:37 +03:00
|
|
|
defaultNamingConvention
|
2022-09-27 09:48:21 +03:00
|
|
|
where
|
|
|
|
isPrometheusMetricsEnabled = METRICS `Set.member` enabledAPIs
|
2020-04-06 07:53:58 +03:00
|
|
|
|
2019-06-11 16:29:03 +03:00
|
|
|
isAdminSecretSet :: AuthMode -> Bool
|
|
|
|
isAdminSecretSet = \case
|
|
|
|
AMNoAuth -> False
|
|
|
|
_ -> True
|
|
|
|
|
|
|
|
isAuthHookSet :: AuthMode -> Bool
|
|
|
|
isAuthHookSet = \case
|
|
|
|
AMAdminSecretAndHook _ _ -> True
|
|
|
|
_ -> False
|
|
|
|
|
|
|
|
isJWTSet :: AuthMode -> Bool
|
|
|
|
isJWTSet = \case
|
|
|
|
AMAdminSecretAndJWT {} -> True
|
|
|
|
_ -> False
|
|
|
|
|
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
|