swh.deposit.api.common module

class swh.deposit.api.common.ParsedRequestHeaders(content_type: str, content_length: Optional[int], in_progress: bool, content_disposition: Optional[str], content_md5sum: Optional[bytes], packaging: Optional[str], slug: Optional[str], on_behalf_of: Optional[str], metadata_relevant: Optional[str], swhid: Optional[str])[source]

Bases: object

Method generated by attrs for class ParsedRequestHeaders.

class swh.deposit.api.common.Receipt(deposit_id: int, deposit_date: datetime.datetime, status: str, archive: Optional[str])[source]

Bases: object

Data computed while handling the request body that will be served in the Deposit Receipt.

Method generated by attrs for class Receipt.

swh.deposit.api.common.get_deposit_by_id(deposit_id: int, collection_name: Optional[str] = None) swh.deposit.models.Deposit[source]

Gets an existing Deposit object if it exists, or raises DepositError. If collection is not None, also checks the deposit belongs to the collection.

swh.deposit.api.common.get_collection_by_name(collection_name: str)[source]

Gets an existing Deposit object if it exists, or raises DepositError.

swh.deposit.api.common.guess_deposit_origin_url(deposit: swh.deposit.models.Deposit)[source]

Guesses an origin url for the given deposit.

swh.deposit.api.common.check_client_origin(client: swh.deposit.models.DepositClient, origin_url: str)[source]
class swh.deposit.api.common.APIBase[source]

Bases: swh.deposit.config.APIConfig, rest_framework.views.APIView

Base deposit request class sharing multiple common behaviors.

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

additional_checks(request: rest_framework.request.Request, headers: swh.deposit.api.common.ParsedRequestHeaders, collection_name: str, deposit: Optional[swh.deposit.models.Deposit]) Dict[str, Any][source]

Permit the child class to enrich additional checks.

Returns

dict with ‘error’ detailing the problem.

get_client(request) swh.deposit.models.DepositClient[source]
checks(request: rest_framework.request.Request, collection_name: str, deposit: Optional[swh.deposit.models.Deposit] = None) swh.deposit.api.common.ParsedRequestHeaders[source]
restrict_access(request: rest_framework.request.Request, headers: swh.deposit.api.common.ParsedRequestHeaders, deposit: swh.deposit.models.Deposit) None[source]

Allow modifications on deposit with status ‘partial’ only, reject the rest.

get(request: rest_framework.request.Request, *args, **kwargs) Union[django.http.response.HttpResponse, django.http.response.FileResponse][source]
post(request: rest_framework.request.Request, *args, **kwargs) django.http.response.HttpResponse[source]
put(request: rest_framework.request.Request, *args, **kwargs) django.http.response.HttpResponse[source]
delete(request: rest_framework.request.Request, *args, **kwargs) django.http.response.HttpResponse[source]
class swh.deposit.api.common.APIGet[source]

Bases: swh.deposit.api.common.APIBase

Mixin for class to support GET method.

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

get(request: rest_framework.request.Request, collection_name: str, deposit_id: int) Union[django.http.response.HttpResponse, django.http.response.FileResponse][source]

Endpoint to create/add resources to deposit.

Returns

200 response when no error during routine occurred 400 if the deposit does not belong to the collection 404 if the deposit or the collection does not exist

abstract process_get(request: rest_framework.request.Request, collection_name: str, deposit: swh.deposit.models.Deposit) Tuple[int, Any, str][source]

Routine to deal with the deposit’s get processing.

Returns

Tuple status, stream of content, content-type

class swh.deposit.api.common.APIPost[source]

Bases: swh.deposit.api.common.APIBase

Mixin for class to support POST method.

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

post(request: rest_framework.request.Request, collection_name: str, deposit_id: Optional[int] = None) django.http.response.HttpResponse[source]

Endpoint to create/add resources to deposit.

Returns

204 response when no error during routine occurred. 400 if the deposit does not belong to the collection 404 if the deposit or the collection does not exist

abstract process_post(request, headers: swh.deposit.api.common.ParsedRequestHeaders, collection_name: str, deposit: Optional[swh.deposit.models.Deposit] = None) Tuple[int, str, swh.deposit.api.common.Receipt][source]

Routine to deal with the deposit’s processing.

Returns

Tuple of: - response status code (200, 201, etc…) - key iri (EM_IRI, EDIT_IRI, etc…) - Receipt

class swh.deposit.api.common.APIPut[source]

Bases: swh.deposit.api.common.APIBase

Mixin for class to support PUT method.

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

put(request: rest_framework.request.Request, collection_name: str, deposit_id: int) django.http.response.HttpResponse[source]

Endpoint to update deposit resources.

Returns

204 response when no error during routine occurred. 400 if the deposit does not belong to the collection 404 if the deposit or the collection does not exist

abstract process_put(request: rest_framework.request.Request, headers: swh.deposit.api.common.ParsedRequestHeaders, collection_name: str, deposit: swh.deposit.models.Deposit) None[source]

Routine to deal with updating a deposit in some way.

Returns

dictionary of the processing result

class swh.deposit.api.common.APIDelete[source]

Bases: swh.deposit.api.common.APIBase

Mixin for class to support DELETE method.

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

delete(request: rest_framework.request.Request, collection_name: str, deposit_id: Optional[int] = None) django.http.response.HttpResponse[source]

Endpoint to delete some deposit’s resources (archives, deposit).

Returns

204 response when no error during routine occurred. 400 if the deposit does not belong to the collection 404 if the deposit or the collection does not exist

abstract process_delete(request: rest_framework.request.Request, collection_name: str, deposit: swh.deposit.models.Deposit) None[source]

Routine to delete a resource.

This is mostly not allowed except for the EM_IRI (cf. .api.deposit_update.APIUpdateArchive)