Changeset View
Changeset View
Standalone View
Standalone View
swh/web/api/views/metadata.py
# Copyright (C) 2021-2022 The Software Heritage developers | # Copyright (C) 2021-2022 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 Affero General Public License version 3, or any later version | # License: GNU Affero 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 base64 | import base64 | ||||
import re | import re | ||||
from typing import Dict, Optional | from typing import Dict, Optional | ||||
import iso8601 | import iso8601 | ||||
from django.http import HttpResponse | from django.http import HttpResponse | ||||
from django.shortcuts import redirect | |||||
from rest_framework.request import Request | from rest_framework.request import Request | ||||
from swh.model import hashutil, swhids | from swh.model import hashutil, swhids | ||||
from swh.model.model import MetadataAuthority, MetadataAuthorityType | from swh.model.model import MetadataAuthority, MetadataAuthorityType, Origin | ||||
from swh.web.api.apidoc import api_doc, format_docstring | from swh.web.api.apidoc import api_doc, format_docstring | ||||
from swh.web.api.apiurls import api_route | from swh.web.api.apiurls import api_route | ||||
from swh.web.common import archive, converters | from swh.web.common import archive, converters | ||||
from swh.web.common.exc import BadInputExc, NotFoundExc | from swh.web.common.exc import BadInputExc, NotFoundExc | ||||
from swh.web.common.utils import SWHID_RE, reverse | from swh.web.common.utils import SWHID_RE, reverse | ||||
@api_route( | @api_route( | ||||
▲ Show 20 Lines • Show All 205 Lines • ▼ Show 20 Lines | .. http:get:: /api/1/raw-extrinsic-metadata/swhid/(target)/authorities/ | ||||
Returns a list of metadata authorities that provided metadata on | Returns a list of metadata authorities that provided metadata on | ||||
the given target. | the given target. | ||||
They can then be used to get the raw `extrinsic metadata <https://docs.softwareheritage.org/devel/glossary.html#term-extrinsic-metadata>`__ collected on | They can then be used to get the raw `extrinsic metadata <https://docs.softwareheritage.org/devel/glossary.html#term-extrinsic-metadata>`__ collected on | ||||
that object from each of the authorities. | that object from each of the authorities. | ||||
This endpoint should only be used directly to retrieve metadata from | This endpoint should only be used directly to retrieve metadata from | ||||
core SWHIDs (with type ``cnt``, ``dir``, ``rev``, ``rel``, and ``snp``). | core SWHIDs (with type ``cnt``, ``dir``, ``rev``, ``rel``, and ``snp``). | ||||
For "extended" SWHIDs such as origins, the URL in the | For "extended" SWHIDs such as origins, | ||||
``origin_metadata_authorities_url`` field of | :http:get:`/api/1/raw-extrinsic-metadata/origin/(origin_url)/authorities/` | ||||
:http:get:`/api/1/origin/(origin_url)/get/` should be used instead of building | should be used instead of building this URL directly. | ||||
this URL directly. | |||||
:param string target: The core SWHID of the object whose metadata-providing | :param string target: The core SWHID of the object whose metadata-providing | ||||
authorities should be returned | authorities should be returned | ||||
{common_headers} | {common_headers} | ||||
:>jsonarr string type: Type of authority (deposit_client, forge, registry) | :>jsonarr string type: Type of authority (deposit_client, forge, registry) | ||||
:>jsonarr string url: Unique IRI identifying the authority | :>jsonarr string url: Unique IRI identifying the authority | ||||
Show All 29 Lines | results = [ | ||||
} | } | ||||
for authority in authorities | for authority in authorities | ||||
] | ] | ||||
return { | return { | ||||
"results": results, | "results": results, | ||||
"headers": {}, | "headers": {}, | ||||
} | } | ||||
@api_route( | |||||
"/raw-extrinsic-metadata/origin/(?P<origin_url>.*)/authorities/", | |||||
"api-1-raw-extrinsic-metadata-origin-authorities", | |||||
) | |||||
@api_doc("/raw-extrinsic-metadata/origin/authorities/") | |||||
@format_docstring() | |||||
def api_raw_extrinsic_metadata_origin_authorities(request: Request, origin_url: str): | |||||
""" | |||||
.. http:get:: /api/1/raw-extrinsic-metadata/origin/(origin_url)/authorities/ | |||||
Similar to | |||||
:http:get:`/api/1/raw-extrinsic-metadata/swhid/(target)/authorities/` | |||||
but to get metadata on origins instead of objects | |||||
:param string origin_url: The URL of the origin whose metadata-providing | |||||
authorities should be returned | |||||
{common_headers} | |||||
:>jsonarr string type: Type of authority (deposit_client, forge, registry) | |||||
:>jsonarr string url: Unique IRI identifying the authority | |||||
:>jsonarr object metadata_list_url: URL to get the list of metadata objects | |||||
on the given object from this authority | |||||
:statuscode 200: no error | |||||
**Example:** | |||||
.. parsed-literal:: | |||||
:swh_web_api:`raw-extrinsic-metadata/origin/https://github.com/rdicosmo/parmap/authorities/` | |||||
""" # noqa | |||||
url = reverse( | |||||
"api-1-raw-extrinsic-metadata-swhid-authorities", | |||||
url_args={"target": Origin(url=origin_url).swhid()}, | |||||
) | |||||
return redirect(url) |