Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/api/common.py
Show First 20 Lines • Show All 137 Lines • ▼ Show 20 Lines | class APIBase(APIConfig, AuthenticatedAPIView, metaclass=ABCMeta): | ||||
""" | """ | ||||
def _read_headers(self, request: Request) -> ParsedRequestHeaders: | def _read_headers(self, request: Request) -> ParsedRequestHeaders: | ||||
"""Read and unify the necessary headers from the request (those are | """Read and unify the necessary headers from the request (those are | ||||
not stored in the same location or not properly formatted). | not stored in the same location or not properly formatted). | ||||
Args: | Args: | ||||
request (Request): Input request | request: Input request | ||||
Returns: | Returns: | ||||
Dictionary with the following keys (some associated values may be | Dictionary with the following keys (some associated values may be | ||||
None): | None): | ||||
- content-type | - content-type | ||||
- content-length | - content-length | ||||
- in-progress | - in-progress | ||||
- content-disposition | - content-disposition | ||||
▲ Show 20 Lines • Show All 189 Lines • ▼ Show 20 Lines | def _delete_deposit(self, collection_name: str, deposit_id: int) -> Dict: | ||||
) | ) | ||||
DepositRequest.objects.filter(deposit=deposit).delete() | DepositRequest.objects.filter(deposit=deposit).delete() | ||||
deposit.delete() | deposit.delete() | ||||
return {} | return {} | ||||
def _check_preconditions_on( | def _check_preconditions_on( | ||||
self, filehandler, md5sum: Optional[bytes], content_length: Optional[int] = None | self, | ||||
filehandler: InMemoryUploadedFile, | |||||
md5sum: Optional[bytes], | |||||
content_length: Optional[int] = None, | |||||
) -> None: | ) -> None: | ||||
"""Check preconditions on provided file are respected. That is the | """Check preconditions on provided file are respected. That is the | ||||
length and/or the md5sum hash match the file's content. | length and/or the md5sum hash match the file's content. | ||||
Args: | Args: | ||||
filehandler (InMemoryUploadedFile): The file to check | filehandler: The file to check | ||||
md5sum: md5 hash expected from the file's content | md5sum: md5 hash expected from the file's content | ||||
content_length: the expected length if provided. | content_length: the expected length if provided. | ||||
Returns: | Returns: | ||||
Either none if no error or a dictionary with a key error | Either none if no error or a dictionary with a key error | ||||
detailing the problem. | detailing the problem. | ||||
""" | """ | ||||
Show All 30 Lines | def _binary_upload( | ||||
replace_archives: bool = False, | replace_archives: bool = False, | ||||
check_slug_is_present: bool = False, | check_slug_is_present: bool = False, | ||||
) -> Receipt: | ) -> Receipt: | ||||
"""Binary upload routine. | """Binary upload routine. | ||||
Other than such a request, a 415 response is returned. | Other than such a request, a 415 response is returned. | ||||
Args: | Args: | ||||
request (Request): the request holding information to parse | request: the request holding information to parse | ||||
and inject in db | and inject in db | ||||
headers (ParsedRequestHeaders): parsed request headers | headers: parsed request headers | ||||
collection_name (str): the associated client | collection_name: the associated client | ||||
deposit_id (id): deposit identifier if provided | deposit_id: deposit identifier if provided | ||||
replace_metadata (bool): 'Update or add' request to existing | replace_metadata: 'Update or add' request to existing | ||||
deposit. If False (default), this adds new metadata request to | deposit. If False (default), this adds new metadata request to | ||||
existing ones. Otherwise, this will replace existing metadata. | existing ones. Otherwise, this will replace existing metadata. | ||||
replace_archives (bool): 'Update or add' request to existing | replace_archives: 'Update or add' request to existing | ||||
deposit. If False (default), this adds new archive request to | deposit. If False (default), this adds new archive request to | ||||
existing ones. Otherwise, this will replace existing archives. | existing ones. Otherwise, this will replace existing archives. | ||||
ones. | ones. | ||||
check_slug_is_present: Check for the slug header if True and raise | check_slug_is_present: Check for the slug header if True and raise | ||||
if not present | if not present | ||||
Raises: | Raises: | ||||
- 400 (bad request) if the request is not providing an external | - 400 (bad request) if the request is not providing an external | ||||
▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | class APIBase(APIConfig, AuthenticatedAPIView, metaclass=ABCMeta): | ||||
) -> Receipt: | ) -> Receipt: | ||||
"""Multipart upload supported with exactly: | """Multipart upload supported with exactly: | ||||
- 1 archive (zip) | - 1 archive (zip) | ||||
- 1 atom entry | - 1 atom entry | ||||
Other than such a request, a 415 response is returned. | Other than such a request, a 415 response is returned. | ||||
Args: | Args: | ||||
request (Request): the request holding information to parse | request: the request holding information to parse | ||||
and inject in db | and inject in db | ||||
headers: parsed request headers | headers: parsed request headers | ||||
collection_name: the associated client | collection_name: the associated client | ||||
deposit_id: deposit identifier if provided | deposit_id: deposit identifier if provided | ||||
replace_metadata: 'Update or add' request to existing | replace_metadata: 'Update or add' request to existing | ||||
deposit. If False (default), this adds new metadata request to | deposit. If False (default), this adds new metadata request to | ||||
existing ones. Otherwise, this will replace existing metadata. | existing ones. Otherwise, this will replace existing metadata. | ||||
replace_archives: 'Update or add' request to existing | replace_archives: 'Update or add' request to existing | ||||
▲ Show 20 Lines • Show All 621 Lines • Show Last 20 Lines |