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
|
|
|
|
2021-01-19 22:14:42 +03:00
|
|
|
import Hasura.Prelude
|
|
|
|
|
2019-06-11 16:29:03 +03:00
|
|
|
import Data.Aeson.TH
|
|
|
|
|
2021-01-19 22:14:42 +03:00
|
|
|
import qualified Hasura.GraphQL.Execute.LiveQuery.Options as LQ
|
|
|
|
|
2021-02-12 20:01:41 +03:00
|
|
|
import Hasura.RQL.Types (FunctionPermissionsCtx)
|
2019-06-11 16:29:03 +03:00
|
|
|
import Hasura.Server.Auth
|
|
|
|
import Hasura.Server.Auth.JWT
|
2020-04-06 07:53:58 +03:00
|
|
|
import Hasura.Server.Version (HasVersion, Version, currentVersion)
|
|
|
|
|
2019-06-11 16:29:03 +03:00
|
|
|
|
|
|
|
data JWTInfo
|
|
|
|
= JWTInfo
|
2020-08-31 19:40:01 +03:00
|
|
|
{ jwtiClaimsNamespace :: !JWTNamespace
|
2020-04-24 10:55:51 +03:00
|
|
|
, jwtiClaimsFormat :: !JWTClaimsFormat
|
2020-08-31 19:40:01 +03:00
|
|
|
, jwtiClaimsMap :: !(Maybe JWTCustomClaimsMap)
|
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-02-12 20:01:41 +03:00
|
|
|
{ scfgVersion :: !Version
|
|
|
|
, scfgIsFunctionPermissionsInferred :: !FunctionPermissionsCtx
|
|
|
|
, scfgIsAdminSecretSet :: !Bool
|
|
|
|
, scfgIsAuthHookSet :: !Bool
|
|
|
|
, scfgIsJwtSet :: !Bool
|
|
|
|
, scfgJwt :: !(Maybe JWTInfo)
|
|
|
|
, scfgIsAllowListEnabled :: !Bool
|
|
|
|
, scfgLiveQueries :: !LQ.LiveQueriesOptions
|
|
|
|
, scfgConsoleAssetsDir :: !(Maybe Text)
|
2020-04-06 07:53:58 +03:00
|
|
|
} deriving (Show, Eq)
|
2019-06-11 16:29:03 +03:00
|
|
|
|
2021-01-19 22:14:42 +03:00
|
|
|
$(deriveToJSON hasuraJSON ''ServerConfig)
|
2019-06-11 16:29:03 +03:00
|
|
|
|
2021-02-12 20:01:41 +03:00
|
|
|
runGetConfig :: HasVersion => FunctionPermissionsCtx -> AuthMode -> Bool -> LQ.LiveQueriesOptions -> Maybe Text -> ServerConfig
|
|
|
|
runGetConfig functionPermsCtx am isAllowListEnabled liveQueryOpts consoleAssetsDir = ServerConfig
|
2020-04-06 07:53:58 +03:00
|
|
|
currentVersion
|
2021-02-12 20:01:41 +03:00
|
|
|
functionPermsCtx
|
2020-04-06 07:53:58 +03:00
|
|
|
(isAdminSecretSet am)
|
|
|
|
(isAuthHookSet am)
|
|
|
|
(isJWTSet am)
|
|
|
|
(getJWTInfo am)
|
|
|
|
isAllowListEnabled
|
|
|
|
liveQueryOpts
|
2020-06-03 07:06:23 +03:00
|
|
|
consoleAssetsDir
|
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
|
|
|
|
|
|
|
|
getJWTInfo :: AuthMode -> Maybe JWTInfo
|
|
|
|
getJWTInfo (AMAdminSecretAndJWT _ jwtCtx _) =
|
2020-08-31 19:40:01 +03:00
|
|
|
Just $ case jcxClaims jwtCtx of
|
|
|
|
JCNamespace namespace claimsFormat ->
|
|
|
|
JWTInfo namespace claimsFormat Nothing
|
|
|
|
JCMap claimsMap ->
|
|
|
|
JWTInfo (ClaimNs defaultClaimsNamespace) defaultClaimsFormat $ Just claimsMap
|
2019-06-11 16:29:03 +03:00
|
|
|
getJWTInfo _ = Nothing
|