Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/api/common.py
Show First 20 Lines • Show All 244 Lines • ▼ Show 20 Lines | ) -> Deposit: | ||||
if self.config["checks"]: | if self.config["checks"]: | ||||
deposit.save() # needed to have a deposit id | deposit.save() # needed to have a deposit id | ||||
scheduler = self.scheduler | scheduler = self.scheduler | ||||
if deposit.status == DEPOSIT_STATUS_DEPOSITED and not deposit.check_task_id: | if deposit.status == DEPOSIT_STATUS_DEPOSITED and not deposit.check_task_id: | ||||
task = create_oneshot_task_dict( | task = create_oneshot_task_dict( | ||||
"check-deposit", | "check-deposit", | ||||
collection=deposit.collection.name, | collection=deposit.collection.name, | ||||
deposit_id=deposit.id, | deposit_id=deposit.id, | ||||
retries_left=3, | retries_left=3, | ||||
ardumont: why remove it?
It's to retry in case of failing because of technical issues (communication for… | |||||
Done Inline ActionsI don't remember changing that line vlorentz: I don't remember changing that line | |||||
) | ) | ||||
check_task_id = scheduler.create_tasks([task])[0]["id"] | check_task_id = scheduler.create_tasks([task])[0]["id"] | ||||
deposit.check_task_id = check_task_id | deposit.check_task_id = check_task_id | ||||
deposit.save() | deposit.save() | ||||
return deposit | return deposit | ||||
▲ Show 20 Lines • Show All 506 Lines • ▼ Show 20 Lines | ) -> Receipt: | ||||
if not metadata: | if not metadata: | ||||
raise DepositError( | raise DepositError( | ||||
BAD_REQUEST, | BAD_REQUEST, | ||||
"Empty body request is not supported", | "Empty body request is not supported", | ||||
"Atom entry deposit is supposed to send for metadata. " | "Atom entry deposit is supposed to send for metadata. " | ||||
"If the body is empty, there is no metadata.", | "If the body is empty, there is no metadata.", | ||||
) | ) | ||||
if ( | |||||
"atom:external_identifier" in metadata | |||||
and metadata["atom:external_identifier"] != headers.slug | |||||
): | |||||
# TODO: When clients stopped using it, raise this error | |||||
# even when they are equal. | |||||
raise DepositError( | |||||
BAD_REQUEST, | |||||
"The 'external_identifier' tag is deprecated, " | |||||
"the Slug header should be used instead.", | |||||
) | |||||
# Determine if we are in the metadata-only deposit case | # Determine if we are in the metadata-only deposit case | ||||
try: | try: | ||||
swhid = parse_swh_reference(metadata) | swhid = parse_swh_reference(metadata) | ||||
except ValidationError as e: | except ValidationError as e: | ||||
raise DepositError( | raise DepositError( | ||||
PARSING_ERROR, "Invalid SWHID reference", str(e), | PARSING_ERROR, "Invalid SWHID reference", str(e), | ||||
) | ) | ||||
if swhid is not None: | if swhid is None and check_slug_is_present and not headers.slug: | ||||
external_id = metadata.get("external_identifier", headers.slug) | |||||
else: | |||||
slug = headers.slug | |||||
if check_slug_is_present and not slug: | |||||
raise_missing_slug_error() | raise_missing_slug_error() | ||||
external_id = metadata.get("external_identifier", slug) | |||||
deposit = self._deposit_put( | deposit = self._deposit_put( | ||||
request, | request, | ||||
deposit_id=deposit_id, | deposit_id=deposit_id, | ||||
in_progress=headers.in_progress, | in_progress=headers.in_progress, | ||||
external_id=external_id, | external_id=headers.slug, | ||||
) | ) | ||||
if swhid is not None: | if swhid is not None: | ||||
swhid, swhid_ref, depo, depo_request = self._store_metadata_deposit( | swhid, swhid_ref, depo, depo_request = self._store_metadata_deposit( | ||||
deposit, swhid, metadata, raw_metadata | deposit, swhid, metadata, raw_metadata | ||||
) | ) | ||||
deposit.status = DEPOSIT_STATUS_LOAD_SUCCESS | deposit.status = DEPOSIT_STATUS_LOAD_SUCCESS | ||||
▲ Show 20 Lines • Show All 192 Lines • ▼ Show 20 Lines | ) -> Tuple[int, Any, str]: | ||||
Returns: | Returns: | ||||
Tuple status, stream of content, content-type | Tuple status, stream of content, content-type | ||||
""" | """ | ||||
pass | pass | ||||
class APIPost(APIBase, metaclass=ABCMeta): | class APIPost(APIBase, metaclass=ABCMeta): | ||||
"""Mixin for class to support POST method. | """Mixin for class to support POST method. | ||||
Not Done Inline ActionsNope, it's post alright ardumont: Nope, it's post alright | |||||
Done Inline Actions... why did i do that vlorentz: ... why did i do that | |||||
""" | """ | ||||
def post( | def post( | ||||
self, request: Request, collection_name: str, deposit_id: Optional[int] = None | self, request: Request, collection_name: str, deposit_id: Optional[int] = None | ||||
) -> HttpResponse: | ) -> HttpResponse: | ||||
"""Endpoint to create/add resources to deposit. | """Endpoint to create/add resources to deposit. | ||||
▲ Show 20 Lines • Show All 140 Lines • Show Last 20 Lines |
why remove it?
It's to retry in case of failing because of technical issues (communication for example), not trying 3 times to validate invalid deposits heh.