Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
) * (4 - response_len)
elif isinstance(response, dict) and all(
key in ["body", "statusCode", "headers", "multiValueHeaders"]
for key in response.keys()
):
body = response.get("body")
status_code = response.get("statusCode") or status_code
headers = response.get("headers") or headers
multiValueHeaders = (
response.get("multiValueHeaders") or multiValueHeaders
)
else: # if response is string, int, etc.
body = response
response = Response(body, status_code, headers, multiValueHeaders)
return response.to_json(
encoder=json_encoder,
application_load_balancer=application_load_balancer,
)
except ValidationError as error:
error_description = "Schema[{}] with value {}".format(
"][".join(str(error.absolute_schema_path)), error.message
)
logging.warning(
logging_message.format(status_code=400, message=error_description)
)
error_tuple = ("Validation Error", 400)
except ScopeMissing as error:
error_description = "Permission denied"
# bind the mapping to an empty server name
mapping = url_maps.bind("")
rule, kwargs = mapping.match(path, method=method_name, return_rule=True)
func = rule.endpoint
# if this is a catch-all rule, don't send any kwargs
if rule.rule == "/":
kwargs = {}
except NotFound as e:
logging.warning(logging_message.format(status_code=404, message=str(e)))
error_tuple = (str(e), 404)
if func:
try:
response = func(event, **kwargs)
if not isinstance(response, Response):
# Set defaults
status_code = headers = multiValueHeaders = None
if isinstance(response, tuple):
response_len = len(response)
if response_len > 3:
raise ValueError("Response tuple has more than 3 items")
# Unpack the tuple, missing items will be defaulted
body, status_code, headers, multiValueHeaders = response + (
None,
) * (4 - response_len)
elif isinstance(response, dict) and all(
key in ["body", "statusCode", "headers", "multiValueHeaders"]
for key in response.keys()