swh.deposit.api package

Submodules

swh.deposit.api.common module

class swh.deposit.api.common.SWHAPIView(**kwargs)[source]

Bases: rest_framework.views.APIView

Mixin intended as a based API view to enforce the basic authentication check

authentication_classes = (<class 'rest_framework.authentication.BasicAuthentication'>,)
permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>,)
class swh.deposit.api.common.SWHPrivateAPIView(**kwargs)[source]

Bases: swh.deposit.api.common.SWHAPIView

Mixin intended as private api (so no authentication) based API view (for the private ones).

authentication_classes = ()
permission_classes = (<class 'rest_framework.permissions.AllowAny'>,)
class swh.deposit.api.common.SWHBaseDeposit[source]

Bases: swh.deposit.config.SWHDefaultConfig, swh.deposit.api.common.SWHAPIView

Base deposit request class sharing multiple common behaviors.

additional_checks(req, headers, collection_name, deposit_id=None)[source]

Permit the child class to enrich additional checks.

Returns:dict with ‘error’ detailing the problem.
checks(req, collection_name, deposit_id=None)[source]
restrict_access(req, deposit=None)[source]
get(req, *args, **kwargs)[source]
post(req, *args, **kwargs)[source]
put(req, *args, **kwargs)[source]
delete(req, *args, **kwargs)[source]
class swh.deposit.api.common.SWHGetDepositAPI[source]

Bases: swh.deposit.api.common.SWHBaseDeposit

Mixin for class to support GET method.

get(req, collection_name, deposit_id, format=None)[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
process_get(req, collection_name, deposit_id)[source]

Routine to deal with the deposit’s get processing.

Returns:Tuple status, stream of content, content-type
class swh.deposit.api.common.SWHPostDepositAPI[source]

Bases: swh.deposit.api.common.SWHBaseDeposit

Mixin for class to support DELETE method.

post(req, collection_name, deposit_id=None, format=None)[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
process_post(req, headers, collection_name, deposit_id=None)[source]

Routine to deal with the deposit’s processing.

Returns
Tuple of: - response status code (200, 201, etc…) - key iri (EM_IRI, EDIT_SE_IRI, etc…) - dictionary of the processing result
class swh.deposit.api.common.SWHPutDepositAPI[source]

Bases: swh.deposit.api.common.SWHBaseDeposit

Mixin for class to support PUT method.

put(req, collection_name, deposit_id, format=None)[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
process_put(req, headers, collection_name, deposit_id)[source]

Routine to deal with updating a deposit in some way.

Returns
dictionary of the processing result
class swh.deposit.api.common.SWHDeleteDepositAPI[source]

Bases: swh.deposit.api.common.SWHBaseDeposit

Mixin for class to support DELETE method.

delete(req, collection_name, deposit_id)[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
process_delete(req, collection_name, deposit_id)[source]

Routine to delete a resource.

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

swh.deposit.api.converters module

swh.deposit.api.converters.convert_status_detail(status_detail)[source]

Given a status_detail dict, transforms it into a human readable string.

Dict has the following form (all first level keys are optional):

{
  'url': {
      'summary': "summary-string",
      'fields': [impacted-fields-list]
  },
  'metadata': [{
      'summary': "summary-string",
      'fields': [impacted-fields-list],
  }],
  'archive': [{
      'summary': "summary-string",
      'fields': [impacted-fields-list],
  }]
}
Parameters:status_detail (dict) – The status detail dict with the syntax mentioned
Returns:the status detail as inlined string

swh.deposit.api.deposit module

class swh.deposit.api.deposit.SWHDeposit[source]

Bases: swh.deposit.api.common.SWHPostDepositAPI

Deposit request class defining api endpoints for sword deposit.

What’s known as ‘Col IRI’ in the sword specification.

HTTP verbs supported: POST

parser_classes = (<class 'swh.deposit.parsers.SWHMultiPartParser'>, <class 'swh.deposit.parsers.SWHFileUploadZipParser'>, <class 'swh.deposit.parsers.SWHFileUploadTarParser'>, <class 'swh.deposit.parsers.SWHAtomEntryParser'>)
additional_checks(req, headers, collection_name, deposit_id=None)[source]

Permit the child class to enrich additional checks.

Returns:dict with ‘error’ detailing the problem.
process_post(req, headers, collection_name, deposit_id=None)[source]

Create a first deposit as: - archive deposit (1 zip) - multipart (1 zip + 1 atom entry) - atom entry

Parameters:
  • req (Request) – the request holding the information to parse and inject in db
  • collection_name (str) – the associated client
Returns:

An http response (HttpResponse) according to the situation.

If everything is ok, a 201 response (created) with a deposit receipt.

Otherwise, depending on the upload, the following errors can be returned:

  • archive deposit:
    • 400 (bad request) if the request is not providing an external identifier
    • 403 (forbidden) if the length of the archive exceeds the max size configured
    • 412 (precondition failed) if the length or hash provided mismatch the reality of the archive.
    • 415 (unsupported media type) if a wrong media type is provided
  • multipart deposit:
    • 400 (bad request) if the request is not providing an external identifier
    • 412 (precondition failed) if the potentially md5 hash provided mismatch the reality of the archive
    • 415 (unsupported media type) if a wrong media type is provided
  • Atom entry deposit:
    • 400 (bad request) if the request is not providing an external identifier
    • 400 (bad request) if the request’s body is empty
    • 415 (unsupported media type) if a wrong media type is provided

swh.deposit.api.deposit_content module

class swh.deposit.api.deposit_content.SWHDepositContent[source]

Bases: swh.deposit.api.common.SWHBaseDeposit

get(req, collection_name, deposit_id, format=None)[source]

swh.deposit.api.deposit_status module

class swh.deposit.api.deposit_status.SWHDepositStatus[source]

Bases: swh.deposit.api.common.SWHBaseDeposit

Deposit status.

What’s known as ‘State IRI’ in the sword specification.

HTTP verbs supported: GET

get(req, collection_name, deposit_id, format=None)[source]

swh.deposit.api.deposit_update module

class swh.deposit.api.deposit_update.SWHUpdateArchiveDeposit[source]

Bases: swh.deposit.api.common.SWHPostDepositAPI, swh.deposit.api.common.SWHPutDepositAPI, swh.deposit.api.common.SWHDeleteDepositAPI

Deposit request class defining api endpoints for sword deposit.

What’s known as ‘EM IRI’ in the sword specification.

HTTP verbs supported: PUT, POST, DELETE

parser_classes = (<class 'swh.deposit.parsers.SWHFileUploadZipParser'>, <class 'swh.deposit.parsers.SWHFileUploadTarParser'>)
process_put(req, headers, collection_name, deposit_id)[source]

Replace existing content for the existing deposit.

Returns:204 No content
process_post(req, headers, collection_name, deposit_id)[source]

Add new content to the existing deposit.

Returns:201 Created Headers: Location: [Cont-File-IRI]

Body: [optional Deposit Receipt]

process_delete(req, collection_name, deposit_id)[source]

Delete content (archives) from existing deposit.

Returns:204 Created
class swh.deposit.api.deposit_update.SWHUpdateMetadataDeposit[source]

Bases: swh.deposit.api.common.SWHPostDepositAPI, swh.deposit.api.common.SWHPutDepositAPI, swh.deposit.api.common.SWHDeleteDepositAPI

Deposit request class defining api endpoints for sword deposit.

What’s known as ‘Edit IRI’ (and SE IRI) in the sword specification.

HTTP verbs supported: POST (SE IRI), PUT (Edit IRI), DELETE

parser_classes = (<class 'swh.deposit.parsers.SWHMultiPartParser'>, <class 'swh.deposit.parsers.SWHAtomEntryParser'>)
process_put(req, headers, collection_name, deposit_id)[source]

Replace existing deposit’s metadata/archive with new ones.

Returns:204 No content
process_post(req, headers, collection_name, deposit_id)[source]

Add new metadata/archive to existing deposit.

This also deals with an empty post corner case to finalize a deposit.

Returns:In optimal case for a multipart and atom-entry update, a 201 Created response. The body response will hold a deposit. And the response headers will contain an entry ‘Location’ with the EM-IRI.

For the empty post case, this returns a 200.

process_delete(req, collection_name, deposit_id)[source]

Delete the container (deposit).

source: http://swordapp.github.io/SWORDv2-Profile/SWORDProfile.html#protocoloperations_deleteconteiner # noqa

swh.deposit.api.service_document module

class swh.deposit.api.service_document.SWHServiceDocument[source]

Bases: swh.deposit.api.common.SWHBaseDeposit

get(req, *args, **kwargs)[source]

swh.deposit.api.urls module

swh URL Configuration

Module contents