diff --git a/swh/deposit/api/common.py b/swh/deposit/api/common.py --- a/swh/deposit/api/common.py +++ b/swh/deposit/api/common.py @@ -1,4 +1,4 @@ -# Copyright (C) 2017-2019 The Software Heritage developers +# Copyright (C) 2017-2020 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information @@ -21,7 +21,7 @@ from swh.scheduler.utils import create_oneshot_task_dict from ..config import ( - SWHDefaultConfig, + APIConfig, EDIT_SE_IRI, EM_IRI, CONT_FILE_IRI, @@ -58,7 +58,7 @@ ACCEPT_ARCHIVE_CONTENT_TYPES = ["application/zip", "application/x-tar"] -class SWHAPIView(APIView): +class AuthenticatedAPIView(APIView): """Mixin intended as a based API view to enforce the basic authentication check @@ -68,7 +68,7 @@ permission_classes: Sequence[Type[BasePermission]] = (IsAuthenticated,) -class SWHBaseDeposit(SWHDefaultConfig, SWHAPIView, metaclass=ABCMeta): +class APIBase(APIConfig, AuthenticatedAPIView, metaclass=ABCMeta): """Base deposit request class sharing multiple common behaviors. """ @@ -797,7 +797,7 @@ return self._basic_not_allowed_method(request, "DELETE") -class SWHGetDepositAPI(SWHBaseDeposit, metaclass=ABCMeta): +class GetAPI(APIBase, metaclass=ABCMeta): """Mixin for class to support GET method. """ @@ -834,7 +834,7 @@ pass -class SWHPostDepositAPI(SWHBaseDeposit, metaclass=ABCMeta): +class APIPost(APIBase, metaclass=ABCMeta): """Mixin for class to support DELETE method. """ @@ -888,7 +888,7 @@ pass -class SWHPutDepositAPI(SWHBaseDeposit, metaclass=ABCMeta): +class APIPut(APIBase, metaclass=ABCMeta): """Mixin for class to support PUT method. """ @@ -926,7 +926,7 @@ pass -class SWHDeleteDepositAPI(SWHBaseDeposit, metaclass=ABCMeta): +class APIDelete(APIBase, metaclass=ABCMeta): """Mixin for class to support DELETE method. """ @@ -956,7 +956,7 @@ """Routine to delete a resource. This is mostly not allowed except for the - EM_IRI (cf. .api.deposit_update.SWHUpdateArchiveDeposit) + EM_IRI (cf. .api.deposit_update.APIUpdateArchive) """ pass diff --git a/swh/deposit/api/deposit.py b/swh/deposit/api/deposit.py --- a/swh/deposit/api/deposit.py +++ b/swh/deposit/api/deposit.py @@ -1,11 +1,11 @@ -# Copyright (C) 2017-2018 The Software Heritage developers +# Copyright (C) 2017-2020 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information from rest_framework import status -from .common import SWHPostDepositAPI, ACCEPT_ARCHIVE_CONTENT_TYPES +from .common import APIPost, ACCEPT_ARCHIVE_CONTENT_TYPES from ..config import EDIT_SE_IRI from ..errors import make_error_dict, BAD_REQUEST from ..parsers import SWHFileUploadZipParser, SWHFileUploadTarParser @@ -13,7 +13,7 @@ from ..parsers import SWHMultiPartParser -class SWHDeposit(SWHPostDepositAPI): +class APIPostDeposit(APIPost): """Deposit request class defining api endpoints for sword deposit. What's known as 'Col IRI' in the sword specification. diff --git a/swh/deposit/api/deposit_content.py b/swh/deposit/api/deposit_content.py --- a/swh/deposit/api/deposit_content.py +++ b/swh/deposit/api/deposit_content.py @@ -1,4 +1,4 @@ -# Copyright (C) 2017 The Software Heritage developers +# Copyright (C) 2017-2020 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information @@ -6,13 +6,13 @@ from django.shortcuts import render from rest_framework import status -from .common import SWHBaseDeposit +from .common import APIBase from ..errors import NOT_FOUND, make_error_response from ..errors import make_error_response_from_dict from ..models import DEPOSIT_STATUS_DETAIL, Deposit, DepositRequest -class SWHDepositContent(SWHBaseDeposit): +class APIContent(APIBase): def get(self, req, collection_name, deposit_id, format=None): checks = self.checks(req, collection_name, deposit_id) if "error" in checks: diff --git a/swh/deposit/api/deposit_status.py b/swh/deposit/api/deposit_status.py --- a/swh/deposit/api/deposit_status.py +++ b/swh/deposit/api/deposit_status.py @@ -6,14 +6,14 @@ from django.shortcuts import render from rest_framework import status -from .common import SWHBaseDeposit +from .common import APIBase from .converters import convert_status_detail from ..errors import NOT_FOUND, make_error_response from ..errors import make_error_response_from_dict from ..models import DEPOSIT_STATUS_DETAIL, Deposit -class SWHDepositStatus(SWHBaseDeposit): +class APIStatus(APIBase): """Deposit status. What's known as 'State IRI' in the sword specification. diff --git a/swh/deposit/api/deposit_update.py b/swh/deposit/api/deposit_update.py --- a/swh/deposit/api/deposit_update.py +++ b/swh/deposit/api/deposit_update.py @@ -1,11 +1,11 @@ -# Copyright (C) 2017-2018 The Software Heritage developers +# Copyright (C) 2017-2020 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information from rest_framework import status -from .common import SWHPostDepositAPI, SWHPutDepositAPI, SWHDeleteDepositAPI +from .common import APIPost, APIPut, APIDelete from .common import ACCEPT_ARCHIVE_CONTENT_TYPES from ..config import CONT_FILE_IRI, EDIT_SE_IRI, EM_IRI from ..errors import make_error_dict, BAD_REQUEST @@ -14,7 +14,7 @@ from ..parsers import SWHMultiPartParser -class SWHUpdateArchiveDeposit(SWHPostDepositAPI, SWHPutDepositAPI, SWHDeleteDepositAPI): +class APIUpdateArchive(APIPost, APIPut, APIDelete): """Deposit request class defining api endpoints for sword deposit. What's known as 'EM IRI' in the sword specification. @@ -83,9 +83,7 @@ return self._delete_archives(collection_name, deposit_id) -class SWHUpdateMetadataDeposit( - SWHPostDepositAPI, SWHPutDepositAPI, SWHDeleteDepositAPI -): +class APIUpdateMetadata(APIPost, APIPut, APIDelete): """Deposit request class defining api endpoints for sword deposit. What's known as 'Edit IRI' (and SE IRI) in the sword specification. diff --git a/swh/deposit/api/private/__init__.py b/swh/deposit/api/private/__init__.py --- a/swh/deposit/api/private/__init__.py +++ b/swh/deposit/api/private/__init__.py @@ -1,16 +1,16 @@ -# Copyright (C) 2017-2019 The Software Heritage developers +# Copyright (C) 2017-2020 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information from swh.deposit import utils -from ...config import METADATA_TYPE, SWHDefaultConfig +from ...config import METADATA_TYPE, APIConfig from ...models import DepositRequest, Deposit from rest_framework.permissions import AllowAny -from swh.deposit.api.common import SWHAPIView +from swh.deposit.api.common import AuthenticatedAPIView from swh.deposit.errors import make_error_dict, NOT_FOUND @@ -58,7 +58,7 @@ return utils.merge(*metadata) -class SWHPrivateAPIView(SWHDefaultConfig, SWHAPIView): +class SWHPrivateAPIView(APIConfig, AuthenticatedAPIView): """Mixin intended as private api (so no authentication) based API view (for the private ones). diff --git a/swh/deposit/api/private/deposit_check.py b/swh/deposit/api/private/deposit_check.py --- a/swh/deposit/api/private/deposit_check.py +++ b/swh/deposit/api/private/deposit_check.py @@ -1,4 +1,4 @@ -# Copyright (C) 2017-2019 The Software Heritage developers +# Copyright (C) 2017-2020 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information @@ -16,7 +16,7 @@ from swh.scheduler.utils import create_oneshot_task_dict from . import DepositReadMixin, SWHPrivateAPIView -from ..common import SWHGetDepositAPI +from ..common import GetAPI from ...config import DEPOSIT_STATUS_VERIFIED, DEPOSIT_STATUS_REJECTED from ...config import ARCHIVE_TYPE from ...models import Deposit @@ -55,7 +55,7 @@ ) -class SWHChecksDeposit(SWHPrivateAPIView, SWHGetDepositAPI, DepositReadMixin): +class SWHChecksDeposit(SWHPrivateAPIView, GetAPI, DepositReadMixin): """Dedicated class to read a deposit's raw archives content. Only GET is supported. diff --git a/swh/deposit/api/private/deposit_read.py b/swh/deposit/api/private/deposit_read.py --- a/swh/deposit/api/private/deposit_read.py +++ b/swh/deposit/api/private/deposit_read.py @@ -18,7 +18,7 @@ from . import DepositReadMixin, SWHPrivateAPIView from ...config import SWH_PERSON, ARCHIVE_TYPE -from ..common import SWHGetDepositAPI +from ..common import GetAPI from ...models import Deposit @@ -60,7 +60,7 @@ shutil.rmtree(dir_path) -class SWHDepositReadArchives(SWHPrivateAPIView, SWHGetDepositAPI, DepositReadMixin): +class SWHDepositReadArchives(SWHPrivateAPIView, GetAPI, DepositReadMixin): """Dedicated class to read a deposit's raw archives content. Only GET is supported. @@ -102,7 +102,7 @@ ) -class SWHDepositReadMetadata(SWHPrivateAPIView, SWHGetDepositAPI, DepositReadMixin): +class SWHDepositReadMetadata(SWHPrivateAPIView, GetAPI, DepositReadMixin): """Class in charge of aggregating metadata on a deposit. """ diff --git a/swh/deposit/api/private/deposit_update_status.py b/swh/deposit/api/private/deposit_update_status.py --- a/swh/deposit/api/private/deposit_update_status.py +++ b/swh/deposit/api/private/deposit_update_status.py @@ -8,7 +8,7 @@ from swh.model.identifiers import DIRECTORY, swhid, REVISION, SNAPSHOT from . import SWHPrivateAPIView -from ..common import SWHPutDepositAPI +from ..common import APIPut from ...errors import make_error_dict, BAD_REQUEST from ...models import Deposit, DEPOSIT_STATUS_DETAIL from ...models import DEPOSIT_STATUS_LOAD_SUCCESS @@ -17,7 +17,7 @@ MANDATORY_KEYS = ["origin_url", "revision_id", "directory_id", "snapshot_id"] -class SWHUpdateStatusDeposit(SWHPrivateAPIView, SWHPutDepositAPI): +class SWHUpdateStatusDeposit(SWHPrivateAPIView, APIPut): """Deposit request class to update the deposit's status. HTTP verbs supported: PUT diff --git a/swh/deposit/api/service_document.py b/swh/deposit/api/service_document.py --- a/swh/deposit/api/service_document.py +++ b/swh/deposit/api/service_document.py @@ -1,4 +1,4 @@ -# Copyright (C) 2017-2019 The Software Heritage developers +# Copyright (C) 2017-2020 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information @@ -6,13 +6,13 @@ from django.shortcuts import render from django.urls import reverse -from .common import SWHBaseDeposit, ACCEPT_PACKAGINGS +from .common import APIBase, ACCEPT_PACKAGINGS from .common import ACCEPT_ARCHIVE_CONTENT_TYPES from ..config import COL_IRI from ..models import DepositClient, DepositCollection -class SWHServiceDocument(SWHBaseDeposit): +class APIServiceDocument(APIBase): def get(self, req, *args, **kwargs): client = DepositClient.objects.get(username=req.user) diff --git a/swh/deposit/api/urls.py b/swh/deposit/api/urls.py --- a/swh/deposit/api/urls.py +++ b/swh/deposit/api/urls.py @@ -1,4 +1,4 @@ -# Copyright (C) 2017-2019 The Software Heritage developers +# Copyright (C) 2017-2020 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information @@ -12,12 +12,12 @@ from ..config import EDIT_SE_IRI, EM_IRI, CONT_FILE_IRI from ..config import SD_IRI, COL_IRI, STATE_IRI -from .deposit import SWHDeposit -from .deposit_status import SWHDepositStatus -from .deposit_update import SWHUpdateMetadataDeposit -from .deposit_update import SWHUpdateArchiveDeposit -from .deposit_content import SWHDepositContent -from .service_document import SWHServiceDocument +from .deposit import APIPostDeposit +from .deposit_status import APIStatus +from .deposit_update import APIUpdateMetadata +from .deposit_update import APIUpdateArchive +from .deposit_content import APIContent +from .service_document import APIServiceDocument def api_view(req): @@ -30,16 +30,16 @@ url(r"^$", api_view, name="api"), # SD IRI - Service Document IRI # -> GET - url(r"^servicedocument/", SWHServiceDocument.as_view(), name=SD_IRI), + url(r"^servicedocument/", APIServiceDocument.as_view(), name=SD_IRI), # Col IRI - Collection IRI # -> POST - url(r"^(?P[^/]+)/$", SWHDeposit.as_view(), name=COL_IRI), + url(r"^(?P[^/]+)/$", APIPostDeposit.as_view(), name=COL_IRI), # EM IRI - Atom Edit Media IRI (update archive IRI) # -> PUT (update-in-place existing archive) # -> POST (add new archive) url( r"^(?P[^/]+)/(?P[^/]+)/media/$", - SWHUpdateArchiveDeposit.as_view(), + APIUpdateArchive.as_view(), name=EM_IRI, ), # Edit IRI - Atom Entry Edit IRI (update metadata IRI) @@ -48,21 +48,21 @@ # -> POST (add new metadata) url( r"^(?P[^/]+)/(?P[^/]+)/metadata/$", - SWHUpdateMetadataDeposit.as_view(), + APIUpdateMetadata.as_view(), name=EDIT_SE_IRI, ), # State IRI # -> GET url( r"^(?P[^/]+)/(?P[^/]+)/status/$", - SWHDepositStatus.as_view(), + APIStatus.as_view(), name=STATE_IRI, ), # Cont/File IRI # -> GET url( r"^(?P[^/]+)/(?P[^/]+)/content/$", - SWHDepositContent.as_view(), + APIContent.as_view(), name=CONT_FILE_IRI, ), # specification is not clear about # FILE-IRI, we assume it's the same as diff --git a/swh/deposit/cli/admin.py b/swh/deposit/cli/admin.py --- a/swh/deposit/cli/admin.py +++ b/swh/deposit/cli/admin.py @@ -231,7 +231,7 @@ DEPOSIT_STATUS_LOAD_SUCCESS, DEPOSIT_STATUS_LOAD_FAILURE, DEPOSIT_STATUS_VERIFIED, - SWHDefaultConfig, + APIConfig, ) try: @@ -268,7 +268,7 @@ deposit.save() # Trigger back the deposit - scheduler = SWHDefaultConfig().scheduler + scheduler = APIConfig().scheduler scheduler.set_status_tasks( [task_id], status="next_run_not_scheduled", next_run=datetime.now() ) diff --git a/swh/deposit/config.py b/swh/deposit/config.py --- a/swh/deposit/config.py +++ b/swh/deposit/config.py @@ -81,7 +81,7 @@ django.setup() -class SWHDefaultConfig(SWHConfig): +class APIConfig(SWHConfig): """Mixin intended to enrich views with SWH configuration. """ diff --git a/swh/deposit/parsers.py b/swh/deposit/parsers.py --- a/swh/deposit/parsers.py +++ b/swh/deposit/parsers.py @@ -1,4 +1,4 @@ -# Copyright (C) 2017-2019 The Software Heritage developers +# Copyright (C) 2017-2020 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information @@ -65,7 +65,7 @@ # We do not actually want to parse the stream yet # because we want to keep the raw data as well # this is done later in the atom entry call - # (cf. swh.deposit.api.common.SWHBaseDeposit._atom_entry) + # (cf. swh.deposit.api.common.APIBase._atom_entry) return stream diff --git a/swh/deposit/tests/conftest.py b/swh/deposit/tests/conftest.py --- a/swh/deposit/tests/conftest.py +++ b/swh/deposit/tests/conftest.py @@ -23,7 +23,7 @@ from swh.model.identifiers import DIRECTORY, swhid, REVISION, SNAPSHOT from swh.deposit.config import setup_django_for from swh.deposit.parsers import parse_xml -from swh.deposit.config import SWHDefaultConfig +from swh.deposit.config import APIConfig from swh.deposit.config import ( COL_IRI, EDIT_SE_IRI, @@ -76,7 +76,7 @@ @pytest.fixture(autouse=True) def deposit_autoconfig(monkeypatch, deposit_config, swh_scheduler_config): - """Enforce config for deposit classes inherited from SWHDefaultConfig.""" + """Enforce config for deposit classes inherited from APIConfig.""" def mock_parse_config(*args, **kw): config = deposit_config.copy() @@ -86,7 +86,7 @@ } return config - monkeypatch.setattr(SWHDefaultConfig, "parse_config_file", mock_parse_config) + monkeypatch.setattr(APIConfig, "parse_config_file", mock_parse_config) scheduler = get_scheduler("local", swh_scheduler_config) task_type = {