Changeset View
Changeset View
Standalone View
Standalone View
swh/web/common/utils.py
# Copyright (C) 2017-2019 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 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 docutils.parsers.rst | import docutils.parsers.rst | ||||
import docutils.utils | import docutils.utils | ||||
import re | import re | ||||
from datetime import datetime, timezone | from datetime import datetime, timezone | ||||
from dateutil import parser as date_parser | from dateutil import parser as date_parser | ||||
from dateutil import tz | from dateutil import tz | ||||
from typing import Optional, Dict, Any | from typing import Optional, Dict, Any | ||||
from django.urls import reverse as django_reverse | from django.urls import reverse as django_reverse | ||||
from django.http import QueryDict, HttpRequest | from django.http import QueryDict, HttpRequest | ||||
from prometheus_client.registry import CollectorRegistry | from prometheus_client.registry import CollectorRegistry | ||||
from rest_framework.authentication import SessionAuthentication | from rest_framework.authentication import SessionAuthentication | ||||
from swh.model.exceptions import ValidationError | from swh.model.exceptions import ValidationError | ||||
from swh.model.identifiers import ( | from swh.model.identifiers import ( | ||||
persistent_identifier, parse_persistent_identifier, | persistent_identifier, parse_persistent_identifier, | ||||
CONTENT, DIRECTORY, RELEASE, REVISION, SNAPSHOT | CONTENT, DIRECTORY, ORIGIN, RELEASE, REVISION, SNAPSHOT | ||||
) | ) | ||||
from swh.web.common.exc import BadInputExc | from swh.web.common.exc import BadInputExc | ||||
from swh.web.config import get_config | from swh.web.config import get_config | ||||
SWH_WEB_METRICS_REGISTRY = CollectorRegistry(auto_describe=True) | SWH_WEB_METRICS_REGISTRY = CollectorRegistry(auto_describe=True) | ||||
▲ Show 20 Lines • Show All 246 Lines • ▼ Show 20 Lines | try: | ||||
elif object_type == REVISION: | elif object_type == REVISION: | ||||
browse_url = reverse('browse-revision', | browse_url = reverse('browse-revision', | ||||
url_args={'sha1_git': object_id}, | url_args={'sha1_git': object_id}, | ||||
query_params=query_dict) | query_params=query_dict) | ||||
elif object_type == SNAPSHOT: | elif object_type == SNAPSHOT: | ||||
browse_url = reverse('browse-snapshot', | browse_url = reverse('browse-snapshot', | ||||
url_args={'snapshot_id': object_id}, | url_args={'snapshot_id': object_id}, | ||||
query_params=query_dict) | query_params=query_dict) | ||||
elif object_type == ORIGIN: | |||||
raise BadInputExc(('Origin PIDs (Persistent Identifiers) are not ' | |||||
'publicly resolvable because they are for ' | |||||
vlorentz: I think `because they are not intrinsic` is more confusing than not.
What about `Origin PIDs… | |||||
Done Inline ActionsIndeed, this is simpler to understand. anlambert: Indeed, this is simpler to understand. | |||||
'internal usage only')) | |||||
except ValidationError as ve: | except ValidationError as ve: | ||||
raise BadInputExc('Error when parsing identifier. %s' % | raise BadInputExc('Error when parsing identifier. %s' % | ||||
' '.join(ve.messages)) | ' '.join(ve.messages)) | ||||
else: | else: | ||||
return {'swh_id_parsed': swh_id_parsed, | return {'swh_id_parsed': swh_id_parsed, | ||||
'browse_url': browse_url} | 'browse_url': browse_url} | ||||
▲ Show 20 Lines • Show All 88 Lines • Show Last 20 Lines |
I think because they are not intrinsic is more confusing than not.
What about Origin PIDs (Persistent Identifiers) are for internal usage only?