Changeset View
Changeset View
Standalone View
Standalone View
swh/web/api/views/identifiers.py
# Copyright (C) 2018-2019 The Software Heritage developers | # Copyright (C) 2018-2019 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 | ||||
from swh.model.identifiers import ( | |||||
CONTENT, DIRECTORY, RELEASE, REVISION, SNAPSHOT | |||||
) | |||||
from swh.web.common import service | from swh.web.common import service | ||||
from swh.web.common.utils import resolve_swh_persistent_id | from swh.web.common.utils import resolve_swh_persistent_id | ||||
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 | ||||
@api_route(r'/resolve/(?P<swh_id>.*)/', | @api_route(r'/resolve/(?P<swh_id>.*)/', | ||||
'api-1-resolve-swh-pid') | 'api-1-resolve-swh-pid') | ||||
Show All 36 Lines | def api_resolve_swh_pid(request, swh_id): | ||||
# try to resolve the provided pid | # try to resolve the provided pid | ||||
swh_id_resolved = resolve_swh_persistent_id(swh_id) | swh_id_resolved = resolve_swh_persistent_id(swh_id) | ||||
# id is well-formed, now check that the pointed | # id is well-formed, now check that the pointed | ||||
# object is present in the archive, NotFoundExc | # object is present in the archive, NotFoundExc | ||||
# will be raised otherwise | # will be raised otherwise | ||||
swh_id_parsed = swh_id_resolved['swh_id_parsed'] | swh_id_parsed = swh_id_resolved['swh_id_parsed'] | ||||
object_type = swh_id_parsed.object_type | object_type = swh_id_parsed.object_type | ||||
object_id = swh_id_parsed.object_id | object_id = swh_id_parsed.object_id | ||||
if object_type == CONTENT: | service.lookup_object(object_type, object_id) | ||||
moranegg: nicely done ! | |||||
Not Done Inline ActionsWhere is stored the result of the lookup_object function call? ardumont: Where is stored the result of the lookup_object function call?
| |||||
Done Inline ActionsHere the idea is to check the object existence in the archive. An exception will be raised if it is not found and an HTTP error response will be generated. anlambert: Here the idea is to check the object existence in the archive.
An exception will be raised if… | |||||
service.lookup_content('sha1_git:%s' % object_id) | |||||
elif object_type == DIRECTORY: | |||||
service.lookup_directory(object_id) | |||||
elif object_type == RELEASE: | |||||
service.lookup_release(object_id) | |||||
elif object_type == REVISION: | |||||
service.lookup_revision(object_id) | |||||
elif object_type == SNAPSHOT: | |||||
service.lookup_snapshot(object_id) | |||||
# id is well-formed and the pointed object exists | # id is well-formed and the pointed object exists | ||||
swh_id_data = swh_id_parsed._asdict() | swh_id_data = swh_id_parsed._asdict() | ||||
swh_id_data['browse_url'] = swh_id_resolved['browse_url'] | swh_id_data['browse_url'] = swh_id_resolved['browse_url'] | ||||
return swh_id_data | return swh_id_data |
nicely done !