2019-06-11 16:29:03 +03:00
|
|
|
module Hasura.Server.Config
|
|
|
|
( runGetConfig
|
|
|
|
)
|
|
|
|
where
|
|
|
|
|
|
|
|
import Data.Aeson.Casing
|
|
|
|
import Data.Aeson.TH
|
|
|
|
|
|
|
|
import Hasura.Prelude
|
|
|
|
import Hasura.Server.Auth
|
|
|
|
import Hasura.Server.Auth.JWT
|
2020-04-06 07:53:58 +03:00
|
|
|
import Hasura.Server.Version (HasVersion, Version, currentVersion)
|
|
|
|
|
|
|
|
import qualified Hasura.GraphQL.Execute.LiveQuery.Options as LQ
|
2019-06-11 16:29:03 +03:00
|
|
|
|
|
|
|
data JWTInfo
|
|
|
|
= JWTInfo
|
2020-04-16 09:45:21 +03:00
|
|
|
{ jwtiClaimsNamespace :: !JWTConfigClaims
|
|
|
|
, jwtiClaimsFormat :: !JWTClaimsFormat
|
2019-06-11 16:29:03 +03:00
|
|
|
} deriving (Show, Eq)
|
|
|
|
|
|
|
|
$(deriveToJSON (aesonDrop 4 snakeCase) ''JWTInfo)
|
|
|
|
|
|
|
|
data ServerConfig
|
|
|
|
= ServerConfig
|
2020-04-06 07:53:58 +03:00
|
|
|
{ scfgVersion :: !Version
|
|
|
|
, scfgIsAdminSecretSet :: !Bool
|
|
|
|
, scfgIsAuthHookSet :: !Bool
|
|
|
|
, scfgIsJwtSet :: !Bool
|
|
|
|
, scfgJwt :: !(Maybe JWTInfo)
|
|
|
|
, scfgIsAllowListEnabled :: !Bool
|
|
|
|
, scfgLiveQueries :: !LQ.LiveQueriesOptions
|
|
|
|
} deriving (Show, Eq)
|
2019-06-11 16:29:03 +03:00
|
|
|
|
|
|
|
$(deriveToJSON (aesonDrop 4 snakeCase) ''ServerConfig)
|
|
|
|
|
2020-04-06 07:53:58 +03:00
|
|
|
runGetConfig :: HasVersion => AuthMode -> Bool -> LQ.LiveQueriesOptions -> ServerConfig
|
|
|
|
runGetConfig am isAllowListEnabled liveQueryOpts = ServerConfig
|
|
|
|
currentVersion
|
|
|
|
(isAdminSecretSet am)
|
|
|
|
(isAuthHookSet am)
|
|
|
|
(isJWTSet am)
|
|
|
|
(getJWTInfo am)
|
|
|
|
isAllowListEnabled
|
|
|
|
liveQueryOpts
|
|
|
|
|
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-04-16 09:45:21 +03:00
|
|
|
Just $ JWTInfo claimsNs format
|
2019-06-11 16:29:03 +03:00
|
|
|
where
|
2020-04-16 09:45:21 +03:00
|
|
|
claimsNs = jcxClaimNs jwtCtx
|
2019-06-11 16:29:03 +03:00
|
|
|
format = jcxClaimsFormat jwtCtx
|
|
|
|
getJWTInfo _ = Nothing
|