-
-
Notifications
You must be signed in to change notification settings - Fork 117
[17.0][FWD] endpoint: forward-port querystring params usage
#114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 17.0
Are you sure you want to change the base?
Changes from all commits
f5574cf
6e510ae
0b1e21a
1b39d23
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -105,8 +105,10 @@ def _default_code_snippet_docs(self): | |
| 'sha3_512', 'shake_128', 'shake_256', 'blake2b', | ||
| 'blake2s', 'md5', 'new' | ||
| * hmac: Python 'hmac' library. Use 'new' to create HMAC objects. | ||
| * querystring_params | ||
|
|
||
| Must generate either an instance of ``Response`` into ``response`` var or: | ||
| Must assign a ``result`` variable, with either an instance of ``Response``, | ||
| or a dict containiny any of the keys: | ||
|
|
||
| * payload | ||
| * headers | ||
|
|
@@ -187,10 +189,11 @@ def _code_snippet_log_func(self, message, level="info"): | |
| ), | ||
| ) | ||
|
|
||
| def _handle_exec__code(self, request): | ||
| def _handle_exec__code(self, request, querystring_params=None): | ||
| if not self._code_snippet_valued(): | ||
| return {} | ||
| eval_ctx = self._get_code_snippet_eval_context(request) | ||
| eval_ctx["querystring_params"] = querystring_params or {} | ||
| snippet = self.code_snippet | ||
| safe_eval.safe_eval(snippet, eval_ctx, mode="exec", nocopy=True) | ||
| result = eval_ctx.get("result") | ||
|
|
@@ -238,14 +241,18 @@ def _get_handler(self): | |
| _("Missing handler for exec mode %s") % self.exec_mode | ||
| ) from e | ||
|
|
||
| def _handle_request(self, request): | ||
| def _handle_request(self, request, querystring_params=None): | ||
| # Switch user for the whole process | ||
| self_with_user = self | ||
| if self.exec_as_user_id: | ||
| self_with_user = self.with_user(user=self.exec_as_user_id) | ||
| handler = self_with_user._get_handler() | ||
| try: | ||
| res = handler(request) | ||
| # In case the handler does not support params | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would simply let it fail. Or if you really want you can catch a
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to be answered |
||
| if querystring_params: | ||
| res = handler(request, querystring_params=querystring_params) | ||
| else: | ||
| res = handler(request) | ||
| except self._bad_request_exceptions() as orig_exec: | ||
| self._logger.error("_validate_request: BadRequest") | ||
| raise werkzeug.exceptions.BadRequest() from orig_exec | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,3 +77,7 @@ def test_call6(self): | |
| def test_call7(self): | ||
| response = self.url_open("/demo/bad_method", data="ok") | ||
| self.assertEqual(response.status_code, 405) | ||
|
|
||
| def test_call8(self): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure to understand how this test is supposed to work. You should pass params in the query string no?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test only used the URL path converters (string:param1/int:param2), so it never actually checked a real query string. |
||
| response = self.url_open("/demo/test/8?extra=1") | ||
| self.assertEqual(response.json(), {"param1": "test", "param2": 8, "extra": "1"}) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we really need this? We have the request and as such we have
request.paramsthat contains the qs params.