Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/api/common.py
# 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 | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import hashlib | import hashlib | ||||
from typing import Sequence, Type | from typing import Sequence, Type | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | |||||
from ..models import Deposit, DepositRequest, DepositCollection, DepositClient | from ..models import Deposit, DepositRequest, DepositCollection, DepositClient | ||||
from ..parsers import parse_xml | from ..parsers import parse_xml | ||||
ACCEPT_PACKAGINGS = ["http://purl.org/net/sword/package/SimpleZip"] | ACCEPT_PACKAGINGS = ["http://purl.org/net/sword/package/SimpleZip"] | ||||
ACCEPT_ARCHIVE_CONTENT_TYPES = ["application/zip", "application/x-tar"] | 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 | """Mixin intended as a based API view to enforce the basic | ||||
authentication check | authentication check | ||||
""" | """ | ||||
authentication_classes: Sequence[Type[BaseAuthentication]] = (BasicAuthentication,) | authentication_classes: Sequence[Type[BaseAuthentication]] = (BasicAuthentication,) | ||||
permission_classes: Sequence[Type[BasePermission]] = (IsAuthenticated,) | permission_classes: Sequence[Type[BasePermission]] = (IsAuthenticated,) | ||||
class SWHBaseDeposit(SWHDefaultConfig, SWHAPIView, metaclass=ABCMeta): | class SWHBaseDeposit(SWHDefaultConfig, AuthenticatedAPIView, metaclass=ABCMeta): | ||||
"""Base deposit request class sharing multiple common behaviors. | """Base deposit request class sharing multiple common behaviors. | ||||
""" | """ | ||||
def _read_headers(self, request): | def _read_headers(self, request): | ||||
"""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). | ||||
▲ Show 20 Lines • Show All 883 Lines • Show Last 20 Lines |