Revert "add: configs as json GUC for db-root-spec"
This reverts commit f34ca15e84.
This commit is contained in:
@@ -57,7 +57,6 @@ import Protolude
|
||||
-}
|
||||
data ApiRequest = ApiRequest {
|
||||
iAction :: Action -- ^ Action on the resource
|
||||
, iIsRootRoutine :: Bool -- ^ If the request wants the root routine
|
||||
, iRange :: HM.HashMap Text NonnegRange -- ^ Requested range of rows within response
|
||||
, iTopLevelRange :: NonnegRange -- ^ Requested range of rows from the top level
|
||||
, iPayload :: Maybe Payload -- ^ Data sent by client and used for mutation actions
|
||||
@@ -77,7 +76,7 @@ data ApiRequest = ApiRequest {
|
||||
-- | Examines HTTP request and translates it into user intent.
|
||||
userApiRequest :: AppConfig -> Preferences.Preferences -> Request -> RequestBody -> Either ApiRequestError ApiRequest
|
||||
userApiRequest conf prefs req reqBody = do
|
||||
(resource, isRootRoutine) <- getResource conf $ pathInfo req
|
||||
resource <- getResource conf $ pathInfo req
|
||||
(schema, negotiatedByProfile) <- getSchema conf hdrs method
|
||||
act <- getAction resource schema method
|
||||
qPrms <- first QueryParamError $ QueryParams.parse (actIsInvokeSafe act) $ rawQueryString req
|
||||
@@ -95,7 +94,6 @@ userApiRequest conf prefs req reqBody = do
|
||||
, iCookies = iCkies
|
||||
, iPath = rawPathInfo req
|
||||
, iMethod = method
|
||||
, iIsRootRoutine = isRootRoutine
|
||||
, iSchema = schema
|
||||
, iNegotiatedByProfile = negotiatedByProfile
|
||||
, iAcceptMediaType = maybe [MTAny] (map MediaType.decodeMediaType . parseHttpAccept) $ lookupHeader "accept"
|
||||
@@ -118,16 +116,16 @@ userPreferences conf req timezones = Preferences.fromHeaders (configDbTxAllowOve
|
||||
userBearerAuth :: Request -> Maybe ByteString
|
||||
userBearerAuth req = extractBearerAuth =<< lookup hAuthorization (requestHeaders req)
|
||||
|
||||
getResource :: AppConfig -> [Text] -> Either ApiRequestError (Resource, Bool)
|
||||
getResource :: AppConfig -> [Text] -> Either ApiRequestError Resource
|
||||
getResource AppConfig{configOpenApiMode, configDbRootSpec} = \case
|
||||
[] ->
|
||||
case (configOpenApiMode,configDbRootSpec) of
|
||||
(OADisabled,_) -> Left OpenAPIDisabled
|
||||
(_, Just qi) -> Right (ResourceRoutine (qiName qi), True)
|
||||
(_, Nothing) -> Right (ResourceSchema, False)
|
||||
(_, Just qi) -> Right $ ResourceRoutine (qiName qi)
|
||||
(_, Nothing) -> Right ResourceSchema
|
||||
|
||||
[table] -> Right (ResourceRelation table, False)
|
||||
["rpc", pName] -> Right (ResourceRoutine pName , False)
|
||||
[table] -> Right $ ResourceRelation table
|
||||
["rpc", pName] -> Right $ ResourceRoutine pName
|
||||
_ -> Left InvalidResourcePath
|
||||
|
||||
getAction :: Resource -> Schema -> ByteString -> Either ApiRequestError Action
|
||||
|
||||
@@ -29,7 +29,6 @@ import PostgREST.Query.SqlFragment (escapeIdentList, fromQi,
|
||||
setConfigWithDynamicName)
|
||||
import PostgREST.SchemaCache.Identifiers (QualifiedIdentifier (..))
|
||||
import PostgREST.SchemaCache.Routine (Routine (..))
|
||||
import PostgREST.Version (prettyVersion)
|
||||
|
||||
import Protolude hiding (Handler)
|
||||
|
||||
@@ -39,7 +38,7 @@ txVarQuery dbActPlan AppConfig{..} AuthResult{..} ApiRequest{..} =
|
||||
-- To ensure `GRANT SET ON PARAMETER <superuser_setting> TO authenticator` works, the role settings must be set before the impersonated role.
|
||||
-- Otherwise the GRANT SET would have to be applied to the impersonated role. See https://github.com/PostgREST/postgrest/issues/3045
|
||||
"select " <> intercalateSnippet ", " (
|
||||
searchPathSql : roleSettingsSql ++ roleSql ++ claimsSql ++ [methodSql, pathSql] ++ headersSql ++ cookiesSql ++ timezoneSql ++ funcSettingsSql ++ appSettingsSql ++ rootSpecSettingsSql
|
||||
searchPathSql : roleSettingsSql ++ roleSql ++ claimsSql ++ [methodSql, pathSql] ++ headersSql ++ cookiesSql ++ timezoneSql ++ funcSettingsSql ++ appSettingsSql
|
||||
)
|
||||
where
|
||||
methodSql = setConfigWithConstantName ("request.method", iMethod)
|
||||
@@ -53,20 +52,6 @@ txVarQuery dbActPlan AppConfig{..} AuthResult{..} ApiRequest{..} =
|
||||
roleSql = [setConfigWithConstantName ("role", authRole)]
|
||||
roleSettingsSql = setConfigWithDynamicName <$> HM.toList (fromMaybe mempty $ HM.lookup authRole configRoleSettings)
|
||||
appSettingsSql = setConfigWithDynamicName . join bimap toUtf8 <$> configAppSettings
|
||||
rootSpecSettingsSql
|
||||
| iIsRootRoutine =
|
||||
[ setConfigWithConstantName
|
||||
( "request.root.configs"
|
||||
, LBS.toStrict $ JSON.encode $ JSON.object
|
||||
[ "server_host" JSON..= configServerHost
|
||||
, "server_port" JSON..= (show configServerPort :: Text)
|
||||
, "openapi_server_proxy_uri" JSON..= configOpenApiServerProxyUri
|
||||
, "db_schemas" JSON..= toList configDbSchemas
|
||||
, "version" JSON..= decodeUtf8 prettyVersion
|
||||
]
|
||||
)
|
||||
]
|
||||
| otherwise = mempty
|
||||
timezoneSql = maybe mempty (\(PreferTimezone tz) -> [setConfigWithConstantName ("timezone", tz)]) $ preferTimezone iPreferences
|
||||
funcSettingsSql = setConfigWithDynamicName . join bimap toUtf8 <$> funcSettings
|
||||
searchPathSql =
|
||||
|
||||
Reference in New Issue
Block a user