don't check if proc exists, just call it and return 400 if it does not
This commit is contained in:
+12
-16
@@ -186,22 +186,18 @@ app dbStructure conf apiRequest =
|
||||
|
||||
(ActionInvoke, TargetProc qi,
|
||||
Just (PayloadJSON (UniformObjects payload))) -> do
|
||||
exists <- H.query qi doesProcExist
|
||||
if exists
|
||||
then do
|
||||
let p = V.head payload
|
||||
jwtSecret = configJwtSecret conf
|
||||
respondToRange $ do
|
||||
row <- H.query () (callProc qi p topLevelRange shouldCount)
|
||||
returnJWT <- H.query qi doesProcReturnJWT
|
||||
let (tableTotal, queryTotal, body) = fromMaybe (Just 0, 0, emptyArray) row
|
||||
(status, contentRange) = rangeHeader queryTotal tableTotal
|
||||
in
|
||||
return $ responseLBS status [jsonH, contentRange]
|
||||
(if returnJWT
|
||||
then "{\"token\":\"" <> cs (tokenJWT jwtSecret body) <> "\"}"
|
||||
else cs $ encode body)
|
||||
else return notFound
|
||||
let p = V.head payload
|
||||
jwtSecret = configJwtSecret conf
|
||||
respondToRange $ do
|
||||
row <- H.query () (callProc qi p topLevelRange shouldCount)
|
||||
returnJWT <- H.query qi doesProcReturnJWT
|
||||
let (tableTotal, queryTotal, body) = fromMaybe (Just 0, 0, emptyArray) row
|
||||
(status, contentRange) = rangeHeader queryTotal tableTotal
|
||||
in
|
||||
return $ responseLBS status [jsonH, contentRange]
|
||||
(if returnJWT
|
||||
then "{\"token\":\"" <> cs (tokenJWT jwtSecret body) <> "\"}"
|
||||
else cs $ encode body)
|
||||
|
||||
(ActionRead, TargetRoot, Nothing) -> do
|
||||
let encodeApi ti = encodeOpenAPI ti host port
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
module PostgREST.DbStructure (
|
||||
getDbStructure
|
||||
, accessibleTables
|
||||
, doesProcExist
|
||||
, doesProcReturnJWT
|
||||
) where
|
||||
|
||||
@@ -104,19 +103,6 @@ decodeSynonyms cols =
|
||||
<*> HD.value HD.text <*> HD.value HD.text
|
||||
<*> HD.value HD.text <*> HD.value HD.text
|
||||
|
||||
doesProcExist :: H.Query QualifiedIdentifier Bool
|
||||
doesProcExist =
|
||||
H.statement sql encodeQi (HD.singleRow (HD.value HD.bool)) True
|
||||
where
|
||||
sql = [q| SELECT EXISTS (
|
||||
SELECT 1
|
||||
FROM pg_catalog.pg_namespace n
|
||||
JOIN pg_catalog.pg_proc p
|
||||
ON pronamespace = n.oid
|
||||
WHERE nspname = $1
|
||||
AND proname = $2
|
||||
) |]
|
||||
|
||||
doesProcReturnJWT :: H.Query QualifiedIdentifier Bool
|
||||
doesProcReturnJWT =
|
||||
H.statement sql encodeQi (HD.singleRow (HD.value HD.bool)) True
|
||||
|
||||
@@ -477,6 +477,11 @@ spec = do
|
||||
request methodPost "/rpc/sayhello"
|
||||
(acceptHdrs "application/json") "sdfsdf"
|
||||
`shouldRespondWith` 400
|
||||
-- it used to be 404 and it makes sense but in another part we decided that it's good to return
|
||||
-- PostgreSQL errors (and have the proxy handle them) and this saves us an aditional query on each rpc request
|
||||
it "responds with 400 on an unexisting proc" $
|
||||
post "/rpc/fake" [json| {} |] `shouldRespondWith` 400
|
||||
|
||||
|
||||
context "unsupported verbs" $ do
|
||||
it "DELETE fails" $
|
||||
|
||||
Reference in New Issue
Block a user