Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion endpoint/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def _handle_endpoint(self, env, model, endpoint_route, **params):
if not endpoint:
raise NotFound()
endpoint._validate_request(request)
result = endpoint._handle_request(request)
result = endpoint._handle_request(request, querystring_params=params)
return self._handle_result(result)

def _handle_result(self, result):
Expand Down
15 changes: 11 additions & 4 deletions endpoint/models/endpoint_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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 TypeError and log it. But I would just let it break. Beside, I doubt anyone did ever implement a different handler :)

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
Expand Down
Loading