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,
|
(ActionInvoke, TargetProc qi,
|
||||||
Just (PayloadJSON (UniformObjects payload))) -> do
|
Just (PayloadJSON (UniformObjects payload))) -> do
|
||||||
exists <- H.query qi doesProcExist
|
let p = V.head payload
|
||||||
if exists
|
jwtSecret = configJwtSecret conf
|
||||||
then do
|
respondToRange $ do
|
||||||
let p = V.head payload
|
row <- H.query () (callProc qi p topLevelRange shouldCount)
|
||||||
jwtSecret = configJwtSecret conf
|
returnJWT <- H.query qi doesProcReturnJWT
|
||||||
respondToRange $ do
|
let (tableTotal, queryTotal, body) = fromMaybe (Just 0, 0, emptyArray) row
|
||||||
row <- H.query () (callProc qi p topLevelRange shouldCount)
|
(status, contentRange) = rangeHeader queryTotal tableTotal
|
||||||
returnJWT <- H.query qi doesProcReturnJWT
|
in
|
||||||
let (tableTotal, queryTotal, body) = fromMaybe (Just 0, 0, emptyArray) row
|
return $ responseLBS status [jsonH, contentRange]
|
||||||
(status, contentRange) = rangeHeader queryTotal tableTotal
|
(if returnJWT
|
||||||
in
|
then "{\"token\":\"" <> cs (tokenJWT jwtSecret body) <> "\"}"
|
||||||
return $ responseLBS status [jsonH, contentRange]
|
else cs $ encode body)
|
||||||
(if returnJWT
|
|
||||||
then "{\"token\":\"" <> cs (tokenJWT jwtSecret body) <> "\"}"
|
|
||||||
else cs $ encode body)
|
|
||||||
else return notFound
|
|
||||||
|
|
||||||
(ActionRead, TargetRoot, Nothing) -> do
|
(ActionRead, TargetRoot, Nothing) -> do
|
||||||
let encodeApi ti = encodeOpenAPI ti host port
|
let encodeApi ti = encodeOpenAPI ti host port
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
module PostgREST.DbStructure (
|
module PostgREST.DbStructure (
|
||||||
getDbStructure
|
getDbStructure
|
||||||
, accessibleTables
|
, accessibleTables
|
||||||
, doesProcExist
|
|
||||||
, doesProcReturnJWT
|
, doesProcReturnJWT
|
||||||
) where
|
) where
|
||||||
|
|
||||||
@@ -104,19 +103,6 @@ decodeSynonyms cols =
|
|||||||
<*> HD.value HD.text <*> HD.value HD.text
|
<*> HD.value HD.text <*> HD.value HD.text
|
||||||
<*> 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.Query QualifiedIdentifier Bool
|
||||||
doesProcReturnJWT =
|
doesProcReturnJWT =
|
||||||
H.statement sql encodeQi (HD.singleRow (HD.value HD.bool)) True
|
H.statement sql encodeQi (HD.singleRow (HD.value HD.bool)) True
|
||||||
|
|||||||
@@ -477,6 +477,11 @@ spec = do
|
|||||||
request methodPost "/rpc/sayhello"
|
request methodPost "/rpc/sayhello"
|
||||||
(acceptHdrs "application/json") "sdfsdf"
|
(acceptHdrs "application/json") "sdfsdf"
|
||||||
`shouldRespondWith` 400
|
`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
|
context "unsupported verbs" $ do
|
||||||
it "DELETE fails" $
|
it "DELETE fails" $
|
||||||
|
|||||||
Reference in New Issue
Block a user