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
|
|
|
|
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)
|
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,
|
|
|
|
scfgLiveQueries :: !LQ.LiveQueriesOptions,
|
|
|
|
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 ->
|
|
|
|
LQ.LiveQueriesOptions ->
|
|
|
|
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
|
|
|
|
consoleAssetsDir
|
|
|
|
experimentalFeatures =
|
|
|
|
ServerConfig
|
|
|
|
currentVersion
|
|
|
|
functionPermsCtx
|
|
|
|
remoteSchemaPermsCtx
|
|
|
|
(isAdminSecretSet am)
|
|
|
|
(isAuthHookSet am)
|
|
|
|
(isJWTSet am)
|
|
|
|
(getJWTInfo am)
|
|
|
|
isAllowListEnabled
|
|
|
|
liveQueryOpts
|
|
|
|
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
|