Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# jsonschema.validate using given schema
validate(json_data, schema, **__validate_kwargs)
try:
provided_scopes = json.loads(
event["requestContext"]["authorizer"]["scopes"]
)
except KeyError:
provided_scopes = []
except json.decoder.JSONDecodeError:
# Ignore passed scopes if it isn't properly json encoded
provided_scopes = []
for scope in scopes or []:
if scope not in provided_scopes:
raise ScopeMissing("Scope: '{}' is missing".format(scope))
return func(event, *args, **kwargs)
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"
logging.warning(
logging_message.format(status_code=403, message=error_description)
)
error_tuple = (error_description, 403)
except Exception as error:
if error_handler:
error_handler(error, method_name)
else:
raise
body, status_code = error_tuple
return Response(body, status_code).to_json(
application_load_balancer=application_load_balancer
)