Changeset View
Changeset View
Standalone View
Standalone View
swh/web/api/views/metadata.py
Show First 20 Lines • Show All 183 Lines • ▼ Show 20 Lines | def api_raw_extrinsic_metadata_get(request, id): | ||||
if filename and re.match("[a-zA-Z0-9:._-]+", filename): | if filename and re.match("[a-zA-Z0-9:._-]+", filename): | ||||
response["Content-disposition"] = f'attachment; filename="{filename}"' | response["Content-disposition"] = f'attachment; filename="{filename}"' | ||||
else: | else: | ||||
# It should always be not-None and match the regexp if the URL was created by | # It should always be not-None and match the regexp if the URL was created by | ||||
# /raw-extrinsic-metadata/swhid/, but we're better safe than sorry. | # /raw-extrinsic-metadata/swhid/, but we're better safe than sorry. | ||||
response["Content-disposition"] = "attachment" | response["Content-disposition"] = "attachment" | ||||
return response | return response | ||||
@api_route( | |||||
f"/raw-extrinsic-metadata/swhid/(?P<target>{SWHID_RE})/authorities/", | |||||
"api-1-raw-extrinsic-metadata-swhid-authorities", | |||||
) | |||||
@api_doc("/raw-extrinsic-metadata/swhid/authorities/") | |||||
@format_docstring() | |||||
def api_raw_extrinsic_metadata_swhid_authorities(request, target): | |||||
""" | |||||
.. http:get:: /api/1/raw-extrinsic-metadata/swhid/(target)/authorities/ | |||||
Returns a list of metadata authorities that provided metadata on | |||||
olasd: s/objects/object/ or s/objects/target/ | |||||
the given target. | |||||
They can then be used to get the raw `extrinsic metadata`_ collected on | |||||
that object from each of the authorities. | |||||
.. _extrinsic metadata: https://docs.softwareheritage.org/devel/glossary.html#term-extrinsic-metadata | |||||
Done Inline Actionss/metadata/metadata-providing authorities/? olasd: s/metadata/metadata-providing authorities/? | |||||
:param string target: The SWHID of the object 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:: | |||||
Done Inline ActionsNeeds a trailing slash? olasd: Needs a trailing slash? | |||||
:swh_web_api:`raw-extrinsic-metadata/swhid/swh:1:dir:a2faa28028657859c16ff506924212b33f0e1307/authorities/` | |||||
""" # noqa | |||||
target_str = target | |||||
try: | |||||
target = identifiers.CoreSWHID.from_string(target_str).to_extended() | |||||
except identifiers.ValidationError as e: | |||||
raise BadInputExc(f"Invalid target SWHID: {e.args[0]}") from None | |||||
authorities = archive.storage.raw_extrinsic_metadata_get_authorities(target=target) | |||||
results = [ | |||||
{ | |||||
**authority.to_dict(), | |||||
"metadata_list_url": reverse( | |||||
"api-1-raw-extrinsic-metadata-swhid", | |||||
url_args={"target": target_str}, | |||||
query_params={"authority": f"{authority.type.value} {authority.url}"}, | |||||
request=request, | |||||
), | |||||
} | |||||
Done Inline Actions*rolls eyes* Thanks black. olasd: *rolls eyes* Thanks black. | |||||
for authority in authorities | |||||
] | |||||
return { | |||||
"results": results, | |||||
"headers": {}, | |||||
} |
s/objects/object/ or s/objects/target/