Fix interpreting urls from environment in the TestWebhookTransform endpoint

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3127
GitOrigin-RevId: 0e5ceaa01f3f27275accd828647ae8587216c80f
This commit is contained in:
Lyndon Maydwell 2021-12-14 14:24:08 +11:00 committed by hasura-bot
parent 038a6113c3
commit 36a987811e
5 changed files with 40 additions and 2 deletions

View File

@ -3,6 +3,8 @@
## Next release
(Add highlights/major features below)
- server: fix issue interpreting urls from environment in the `TestWebhookTransform` endpoint.
### Bug fixes and improvements
(Add entries below in the order of server, console, cli, docs, others)

View File

@ -494,7 +494,7 @@ runTestWebhookTransform (TestWebhookTransform env urlE payload mt sv) = do
let env' = bimap T.pack (J.String . T.pack) <$> Env.toList env
decodeKritiResult = TE.decodeUtf8 . BL.toStrict . J.encode
kritiUrlResult <- hoistEither $ first UrlInterpError $ decodeKritiResult <$> K.runKriti url env'
kritiUrlResult <- hoistEither $ first UrlInterpError $ decodeKritiResult <$> K.runKriti ("\"" <> url <> "\"") env'
let unwrappedUrl = T.drop 1 $ T.dropEnd 1 kritiUrlResult
initReq <- hoistEither $ first RequestInitializationError $ HTTP.mkRequestEither unwrappedUrl

View File

@ -194,7 +194,7 @@ instance FromJSON WebHookUrl where
parseJSON (Object o) = do
var <- o .: "from_env"
pure $ EnvVar var
parseJSON (String str) = pure $ URL $ "\"" <> str <> "\""
parseJSON (String str) = pure $ URL str
parseJSON _ = empty
instance ToJSON WebHookUrl where

View File

@ -0,0 +1,33 @@
- description: Test Webhook Transform
url: /v1/metadata
headers:
X-Hasura-Role: admin
status: 200
response:
body: hello_world
headers:
- - content-type
- application/json
- - foo
- bar
method: POST
webhook_url: http://www.google.com?foo=bar
query:
type: test_webhook_transform
args:
env:
MY_WEBHOOK: http://www.google.net
webhook_url:
from_env: MY_WEBHOOK
body:
hello: world
request_transform:
url: "http://www.google.com"
template_engine: Kriti
body: "\"hello_{{ $body.hello }}\""
method: POST
query_params:
"foo": "bar"
request_headers:
add_headers:
foo: "bar"

View File

@ -223,6 +223,9 @@ class TestMetadata:
def test_webhook_transform_success(self, hge_ctx):
check_query_f(hge_ctx, self.dir() + '/test_webhook_transform_success.yaml')
def test_webhook_transform_with_url_env_reference_success(self, hge_ctx):
check_query_f(hge_ctx, self.dir() + '/test_webhook_transform_env_reference_success.yaml')
def test_webhook_transform_bad_parse(self, hge_ctx):
check_query_f(hge_ctx, self.dir() + '/test_webhook_transform_bad_parse.yaml')