Skip to content
Snippets Groups Projects
Commit 49986f16 authored by Aymeric Varasse's avatar Aymeric Varasse
Browse files

Add checks to verify if provided SWHID is valid

parent 8ba7aab1
No related branches found
No related tags found
No related merge requests found
......@@ -16,9 +16,10 @@ from swh.graph.grpc.swhgraph_pb2 import (
)
from swh.graph.grpc.swhgraph_pb2_grpc import TraversalServiceStub
from swh.model.cli import swhid_of_file
from swh.model.exceptions import ValidationError
# documentation: https://docs.softwareheritage.org/devel/apidoc/swh.model.swhids.html
from swh.model.swhids import ExtendedObjectType, ExtendedSWHID
from swh.model.swhids import CoreSWHID, ExtendedObjectType, ExtendedSWHID
from swh.web.client.client import WebAPIClient
# global variable holding headers parameters
......@@ -121,6 +122,14 @@ def main(
global swhcli
global verbose
verbose = trace
# Check if content SWHID is valid
try:
CoreSWHID.from_string(content_swhid)
except ValidationError:
print(f"Error: '{content_swhid}' is not a valid SWHID")
return
if swh_bearer_token:
swhcli = WebAPIClient(
api_url="https://archive.softwareheritage.org/api/1/",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment