Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/api/deposit_update.py
# Copyright (C) 2017-2020 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 | ||||
from typing import Any, Dict, Optional, Tuple | from typing import Any, Dict, Optional, Tuple | ||||
from rest_framework import status | from rest_framework import status | ||||
from rest_framework.request import Request | from rest_framework.request import Request | ||||
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.models import Deposit | from swh.deposit.models import Deposit | ||||
from swh.model.hashutil import hash_to_bytes | |||||
from swh.model.identifiers import parse_swhid | from swh.model.identifiers import parse_swhid | ||||
from swh.model.model import ( | from swh.model.model import ( | ||||
MetadataAuthority, | MetadataAuthority, | ||||
MetadataAuthorityType, | MetadataAuthorityType, | ||||
MetadataFetcher, | MetadataFetcher, | ||||
MetadataTargetType, | MetadataTargetType, | ||||
RawExtrinsicMetadata, | RawExtrinsicMetadata, | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 225 Lines • ▼ Show 20 Lines | ) -> Dict[str, Any]: | ||||
metadata_fetcher = MetadataFetcher( | metadata_fetcher = MetadataFetcher( | ||||
name=self.tool["name"], | name=self.tool["name"], | ||||
version=self.tool["version"], | version=self.tool["version"], | ||||
metadata=self.tool["configuration"], | metadata=self.tool["configuration"], | ||||
) | ) | ||||
deposit_swhid = parse_swhid(swhid) | deposit_swhid = parse_swhid(swhid) | ||||
directory_id = hash_to_bytes(deposit_swhid.object_id) | |||||
# check the swhid exists in the archive | |||||
directories_missing = list( | |||||
self.storage_metadata.directory_missing([directory_id]) | |||||
) | |||||
if len(directories_missing) > 0: | |||||
return make_error_dict( | |||||
BAD_REQUEST, | |||||
f"Unknown directory SWHID {swhid} reference", | |||||
"The SWHID provided is not a known directory SWHID in SWH archive. " | |||||
"Please provide an existing SWHID.", | |||||
) | |||||
# replace metadata within the deposit backend | # replace metadata within the deposit backend | ||||
deposit_request_data = { | deposit_request_data = { | ||||
METADATA_KEY: metadata, | METADATA_KEY: metadata, | ||||
RAW_METADATA_KEY: raw_metadata, | RAW_METADATA_KEY: raw_metadata, | ||||
} | } | ||||
# actually add the metadata to the completed deposit | # actually add the metadata to the completed deposit | ||||
deposit_request = self._deposit_request_put(deposit, deposit_request_data) | deposit_request = self._deposit_request_put(deposit, deposit_request_data) | ||||
▲ Show 20 Lines • Show All 80 Lines • Show Last 20 Lines |