Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def validate_update_request(self, req: falcon.Request):
methods = self.Meta.methods
if UPDATE not in methods and BULK_UPDATE not in methods:
raise MethodNotAllowed()
payload = json.load(req.bounded_stream)
data = payload.get(self.Meta.name)
try:
deserialized = self.load(data, partial=True, many=True)
except ValidationError as exc:
raise BadRequest(exc.messages)
req.stream = {self.Meta.name: deserialized}
):
"""
Falcon method. DELETE-request entry point.
Here is a database transaction opening.
This is where authentication takes place
(if auth class is pointed in `resource <#awokado.meta.ResourceMeta>`_)
Then delete method is run.
"""
with Transaction(DATABASE_URL, engine=persistent_engine) as t:
session = t.session
user_id, token = self.auth(session, req, resp)
if DELETE not in self.Meta.methods:
raise MethodNotAllowed()
ids_to_delete = req.get_param_as_list("ids")
data = [ids_to_delete, resource_id]
if not any(data) or all(data):
raise BadRequest(
details=(
"It should be a bulk delete (?ids=1,2,3) or delete"
" of a single resource (v1/resource/1)"
)
)
if not ids_to_delete:
ids_to_delete = [resource_id]
if self.Meta.auth:
def validate_create_request(self, req: falcon.Request, is_bulk=False):
methods = self.Meta.methods
payload = json.load(req.bounded_stream)
if isinstance(payload.get(self.Meta.name), list):
request_method = BULK_CREATE
is_bulk = True
else:
request_method = CREATE
if request_method not in methods:
raise MethodNotAllowed()
data = payload.get(self.Meta.name)
if not data:
raise BadRequest(
f"Invalid schema, resource name is missing at the top level. "
f"Your POST request has to look like: "
f'{{"{self.Meta.name}": [{{"field_name": "field_value"}}] '
f'or {{"field_name": "field_value"}} }}'
)
try:
deserialized = self.load(data, many=is_bulk)
except ValidationError as exc:
raise BadRequest(exc.messages)