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
@@ -14,6 +14,7 @@
from django.core.files.uploadedfile import UploadedFile
from django.http import FileResponse, HttpResponse
from django.shortcuts import render
+from django.template.loader import render_to_string
from django.urls import reverse
from django.utils import timezone
from rest_framework import status
@@ -36,7 +37,6 @@
from swh.model.model import (
MetadataAuthority,
MetadataAuthorityType,
- MetadataFetcher,
Origin,
RawExtrinsicMetadata,
)
@@ -660,11 +660,7 @@
metadata={"name": deposit.client.last_name},
)
- metadata_fetcher = MetadataFetcher(
- name=self.tool["name"],
- version=self.tool["version"],
- metadata=self.tool["configuration"],
- )
+ metadata_fetcher = self.swh_deposit_fetcher()
# replace metadata within the deposit backend
deposit_request_data = {
@@ -688,6 +684,7 @@
self._check_swhid_in_archive(target_swhid)
+ # metadata deposited by the client
metadata_object = RawExtrinsicMetadata(
target=target_swhid, # core swhid or origin
discovery_date=deposit_request.date,
@@ -698,10 +695,30 @@
**metadata_context,
)
+ # metadata on the metadata object
+ swh_deposit_authority = self.swh_deposit_authority()
+ swh_deposit_fetcher = self.swh_deposit_fetcher()
+ metametadata_object = RawExtrinsicMetadata(
+ target=metadata_object.swhid(),
+ discovery_date=deposit_request.date,
+ authority=swh_deposit_authority,
+ fetcher=swh_deposit_fetcher,
+ format="xml-deposit-info",
+ metadata=render_to_string(
+ "deposit/deposit_info.xml", context={"deposit": deposit}
+ ).encode(),
+ )
+
# write to metadata storage
- self.storage_metadata.metadata_authority_add([metadata_authority])
- self.storage_metadata.metadata_fetcher_add([metadata_fetcher])
- self.storage_metadata.raw_extrinsic_metadata_add([metadata_object])
+ self.storage_metadata.metadata_authority_add(
+ [metadata_authority, swh_deposit_authority]
+ )
+ self.storage_metadata.metadata_fetcher_add(
+ [metadata_fetcher, swh_deposit_fetcher]
+ )
+ self.storage_metadata.raw_extrinsic_metadata_add(
+ [metadata_object, metametadata_object]
+ )
return (target_swhid, deposit, deposit_request)
diff --git a/swh/deposit/config.py b/swh/deposit/config.py
--- a/swh/deposit/config.py
+++ b/swh/deposit/config.py
@@ -8,6 +8,7 @@
from swh.core import config
from swh.deposit import __version__
+from swh.model.model import MetadataAuthority, MetadataAuthorityType, MetadataFetcher
from swh.scheduler import get_scheduler
from swh.scheduler.interface import SchedulerInterface
from swh.storage import get_storage
@@ -108,3 +109,17 @@
self.storage_metadata: StorageInterface = get_storage(
**self.config["storage_metadata"]
)
+
+ def swh_deposit_authority(self):
+ return MetadataAuthority(
+ type=MetadataAuthorityType.REGISTRY,
+ url=self.config["swh_authority_url"],
+ metadata={},
+ )
+
+ def swh_deposit_fetcher(self):
+ return MetadataFetcher(
+ name=self.tool["name"],
+ version=self.tool["version"],
+ metadata=self.tool["configuration"],
+ )
diff --git a/swh/deposit/templates/deposit/deposit_info.xml b/swh/deposit/templates/deposit/deposit_info.xml
new file mode 100644
--- /dev/null
+++ b/swh/deposit/templates/deposit/deposit_info.xml
@@ -0,0 +1,5 @@
+
+ {{ deposit.id }}
+ {{ deposit.client.provider_url }}
+ {{ deposit.collection.name }}
+
diff --git a/swh/deposit/tests/api/test_collection_post_atom.py b/swh/deposit/tests/api/test_collection_post_atom.py
--- a/swh/deposit/tests/api/test_collection_post_atom.py
+++ b/swh/deposit/tests/api/test_collection_post_atom.py
@@ -6,6 +6,7 @@
"""Tests the handling of the Atom content when doing a POST Col-IRI."""
from io import BytesIO
+import textwrap
import uuid
import warnings
@@ -66,6 +67,43 @@
method([attr.evolve(obj, id=swhid.object_id)])
+def _assert_deposit_info_on_metadata(
+ swh_storage, metadata_swhid, deposit, metadata_fetcher
+):
+ swh_authority = MetadataAuthority(
+ MetadataAuthorityType.REGISTRY,
+ "http://deposit.softwareheritage.example/",
+ metadata=None,
+ )
+ page_results = swh_storage.raw_extrinsic_metadata_get(metadata_swhid, swh_authority)
+
+ assert len(page_results.results) == 1
+ assert page_results.next_page_token is None
+
+ expected_xml_data = textwrap.dedent(
+ f"""\
+
+ {deposit.id}
+ https://hal-test.archives-ouvertes.fr/
+ test
+
+ """
+ )
+ assert page_results == PagedResult(
+ results=[
+ RawExtrinsicMetadata(
+ target=metadata_swhid,
+ discovery_date=deposit.complete_date,
+ authority=swh_authority,
+ fetcher=attr.evolve(metadata_fetcher, metadata=None),
+ format="xml-deposit-info",
+ metadata=expected_xml_data.encode(),
+ )
+ ],
+ next_page_token=None,
+ )
+
+
def test_post_deposit_atom_201_even_with_decimal(
authenticated_client, deposit_collection, atom_dataset
):
@@ -554,6 +592,8 @@
)
assert actual_fetcher == metadata_fetcher
+ # Get the deposited metadata object and check it:
+
page_results = swh_storage.raw_extrinsic_metadata_get(
swhid_target, metadata_authority
)
@@ -562,19 +602,20 @@
assert page_results.next_page_token is None
metadata_context = compute_metadata_context(swhid_reference)
- assert page_results == PagedResult(
- results=[
- RawExtrinsicMetadata(
- target=swhid_target,
- discovery_date=deposit.complete_date,
- authority=attr.evolve(metadata_authority, metadata=None),
- fetcher=attr.evolve(metadata_fetcher, metadata=None),
- format="sword-v2-atom-codemeta",
- metadata=xml_data.encode(),
- **metadata_context,
- )
- ],
- next_page_token=None,
+ metadata = RawExtrinsicMetadata(
+ target=swhid_target,
+ discovery_date=deposit.complete_date,
+ authority=attr.evolve(metadata_authority, metadata=None),
+ fetcher=attr.evolve(metadata_fetcher, metadata=None),
+ format="sword-v2-atom-codemeta",
+ metadata=xml_data.encode(),
+ **metadata_context,
+ )
+ assert page_results == PagedResult(results=[metadata], next_page_token=None,)
+
+ # Get metadata about the deposited metadata object and check it:
+ _assert_deposit_info_on_metadata(
+ swh_storage, metadata.swhid(), deposit, metadata_fetcher
)
@@ -633,6 +674,8 @@
)
assert actual_fetcher == metadata_fetcher
+ # Get the deposited metadata object and check it:
+
page_results = swh_storage.raw_extrinsic_metadata_get(
origin_swhid, metadata_authority
)
@@ -640,18 +683,19 @@
assert len(page_results.results) == 1
assert page_results.next_page_token is None
- assert page_results == PagedResult(
- results=[
- RawExtrinsicMetadata(
- target=origin_swhid,
- discovery_date=deposit.complete_date,
- authority=attr.evolve(metadata_authority, metadata=None),
- fetcher=attr.evolve(metadata_fetcher, metadata=None),
- format="sword-v2-atom-codemeta",
- metadata=xml_data.encode(),
- )
- ],
- next_page_token=None,
+ metadata = RawExtrinsicMetadata(
+ target=origin_swhid,
+ discovery_date=deposit.complete_date,
+ authority=attr.evolve(metadata_authority, metadata=None),
+ fetcher=attr.evolve(metadata_fetcher, metadata=None),
+ format="sword-v2-atom-codemeta",
+ metadata=xml_data.encode(),
+ )
+ assert page_results == PagedResult(results=[metadata], next_page_token=None,)
+
+ # Get metadata about the deposited metadata object and check it:
+ _assert_deposit_info_on_metadata(
+ swh_storage, metadata.swhid(), deposit, metadata_fetcher
)
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
@@ -90,6 +90,7 @@
"scheduler": {"cls": "local", **swh_scheduler_config,},
"storage": swh_storage_backend_config,
"storage_metadata": swh_storage_backend_config,
+ "swh_authority_url": "http://deposit.softwareheritage.example/",
}