Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/api/common.py
Show All 12 Lines | |||||
import attr | import attr | ||||
from django.core.files.uploadedfile import UploadedFile | from django.core.files.uploadedfile import UploadedFile | ||||
from django.http import FileResponse, HttpResponse | from django.http import FileResponse, HttpResponse | ||||
from django.shortcuts import render | from django.shortcuts import render | ||||
from django.template.loader import render_to_string | from django.template.loader import render_to_string | ||||
from django.urls import reverse | from django.urls import reverse | ||||
from django.utils import timezone | from django.utils import timezone | ||||
from rest_framework import status | from rest_framework import status | ||||
from rest_framework.authentication import BaseAuthentication, BasicAuthentication | from rest_framework.authentication import BaseAuthentication | ||||
from rest_framework.permissions import BasePermission, IsAuthenticated | from rest_framework.permissions import BasePermission, IsAuthenticated | ||||
from rest_framework.request import Request | from rest_framework.request import Request | ||||
from rest_framework.views import APIView | from rest_framework.views import APIView | ||||
from swh.deposit.api.checks import check_metadata | from swh.deposit.api.checks import check_metadata | ||||
from swh.deposit.api.converters import convert_status_detail | from swh.deposit.api.converters import convert_status_detail | ||||
from swh.deposit.auth import HasDepositPermission, KeycloakBasicAuthentication | |||||
from swh.deposit.models import Deposit | from swh.deposit.models import Deposit | ||||
from swh.deposit.utils import compute_metadata_context | from swh.deposit.utils import compute_metadata_context | ||||
from swh.model import hashutil | from swh.model import hashutil | ||||
from swh.model.identifiers import ( | from swh.model.identifiers import ( | ||||
ExtendedObjectType, | ExtendedObjectType, | ||||
ExtendedSWHID, | ExtendedSWHID, | ||||
QualifiedSWHID, | QualifiedSWHID, | ||||
ValidationError, | ValidationError, | ||||
▲ Show 20 Lines • Show All 128 Lines • ▼ Show 20 Lines | |||||
class AuthenticatedAPIView(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]] = ( | ||||
permission_classes: Sequence[Type[BasePermission]] = (IsAuthenticated,) | KeycloakBasicAuthentication, | ||||
) | |||||
permission_classes: Sequence[Type[BasePermission]] = ( | |||||
IsAuthenticated, | |||||
HasDepositPermission, | |||||
) | |||||
class APIBase(APIConfig, AuthenticatedAPIView, metaclass=ABCMeta): | class APIBase(APIConfig, AuthenticatedAPIView, metaclass=ABCMeta): | ||||
"""Base deposit request class sharing multiple common behaviors. | """Base deposit request class sharing multiple common behaviors. | ||||
""" | """ | ||||
_client: Optional[DepositClient] = None | _client: Optional[DepositClient] = None | ||||
▲ Show 20 Lines • Show All 1,082 Lines • Show Last 20 Lines |