Skip to content

fix: encode PURL qualifiers as a normalized string #466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/macaron/database/table_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

from macaron.database.database_manager import ORMBase
from macaron.database.rfc3339_datetime import RFC3339DateTime
from macaron.errors import CUEExpectationError, CUERuntimeError
from macaron.errors import CUEExpectationError, CUERuntimeError, InvalidPURLError
from macaron.slsa_analyzer.provenance.expectations.cue import cue_validator
from macaron.slsa_analyzer.provenance.expectations.expectation import Expectation
from macaron.slsa_analyzer.slsa_req import ReqName
Expand Down Expand Up @@ -172,9 +172,21 @@ def __init__(self, purl: str, analysis: Analysis, repository: "Repository | None
The corresponding analysis.
repository: Repository | None
The corresponding repository.

Raises
------
InvalidPURLError
If the PURL provided from the user is invalid.
"""
purl_parts = PackageURL.from_string(purl)
purl_kwargs = purl_parts.to_dict()
try:
purl_parts = PackageURL.from_string(purl)
except ValueError as error:
raise InvalidPURLError(f"The package url {purl} is not valid.") from error

# We set ``encode=True`` to encode qualifiers as a normalized string because SQLite doesn't support ``dict`` type.
# TODO: Explore the ``dbm`` or ``shelve`` packages to support dict type, which are part of the Python standard library.
purl_kwargs = purl_parts.to_dict(encode=True)

super().__init__(purl=purl, analysis=analysis, repository=repository, **purl_kwargs)

@property
Expand Down