Skip to content

Commit 17f3453

Browse files
committed
chore: address PR comments
Signed-off-by: behnazh-w <behnaz.hassanshahi@oracle.com>
1 parent f36950c commit 17f3453

File tree

6 files changed

+15
-25
lines changed

6 files changed

+15
-25
lines changed

src/macaron/repo_finder/provenance_extractor.py

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,6 @@ class SLSAGithubGenericBuildDefinitionV01(ProvenanceBuildDefinition):
412412
def get_build_invocation(self, statement: InTotoV01Statement | InTotoV1Statement) -> tuple[str | None, str | None]:
413413
"""Retrieve the build invocation information from the given statement.
414414
415-
This method is intended to be implemented by subclasses to extract
416-
specific invocation details from a provenance statement.
417-
418415
Parameters
419416
----------
420417
statement : InTotoV1Statement | InTotoV01Statement
@@ -456,9 +453,6 @@ class SLSAGithubActionsBuildDefinitionV1(ProvenanceBuildDefinition):
456453
def get_build_invocation(self, statement: InTotoV01Statement | InTotoV1Statement) -> tuple[str | None, str | None]:
457454
"""Retrieve the build invocation information from the given statement.
458455
459-
This method is intended to be implemented by subclasses to extract
460-
specific invocation details from a provenance statement.
461-
462456
Parameters
463457
----------
464458
statement : InTotoV1Statement | InTotoV01Statement
@@ -496,9 +490,6 @@ class SLSANPMCLIBuildDefinitionV2(ProvenanceBuildDefinition):
496490
def get_build_invocation(self, statement: InTotoV01Statement | InTotoV1Statement) -> tuple[str | None, str | None]:
497491
"""Retrieve the build invocation information from the given statement.
498492
499-
This method is intended to be implemented by subclasses to extract
500-
specific invocation details from a provenance statement.
501-
502493
Parameters
503494
----------
504495
statement : InTotoV1Statement | InTotoV01Statement
@@ -540,9 +531,6 @@ class SLSAGCBBuildDefinitionV1(ProvenanceBuildDefinition):
540531
def get_build_invocation(self, statement: InTotoV01Statement | InTotoV1Statement) -> tuple[str | None, str | None]:
541532
"""Retrieve the build invocation information from the given statement.
542533
543-
This method is intended to be implemented by subclasses to extract
544-
specific invocation details from a provenance statement.
545-
546534
Parameters
547535
----------
548536
statement : InTotoV1Statement | InTotoV01Statement
@@ -576,9 +564,6 @@ class SLSAOCIBuildDefinitionV1(ProvenanceBuildDefinition):
576564
def get_build_invocation(self, statement: InTotoV01Statement | InTotoV1Statement) -> tuple[str | None, str | None]:
577565
"""Retrieve the build invocation information from the given statement.
578566
579-
This method is intended to be implemented by subclasses to extract
580-
specific invocation details from a provenance statement.
581-
582567
Parameters
583568
----------
584569
statement : InTotoV1Statement | InTotoV01Statement
@@ -613,9 +598,6 @@ class WitnessGitLabBuildDefinitionV01(ProvenanceBuildDefinition):
613598
def get_build_invocation(self, statement: InTotoV01Statement | InTotoV1Statement) -> tuple[str | None, str | None]:
614599
"""Retrieve the build invocation information from the given statement.
615600
616-
This method is intended to be implemented by subclasses to extract
617-
specific invocation details from a provenance statement.
618-
619601
Parameters
620602
----------
621603
statement : InTotoV1Statement | InTotoV01Statement
@@ -666,6 +648,7 @@ def get_build_type(statement: InTotoV1Statement | InTotoV01Statement) -> str | N
666648
if statement["predicate"] is None:
667649
return None
668650

651+
# Different build provenances might store the buildType field in different sections.
669652
if build_type := json_extract(statement["predicate"], ["buildType"], str):
670653
return build_type
671654

@@ -695,6 +678,9 @@ def find_build_def(statement: InTotoV01Statement | InTotoV1Statement) -> Provena
695678
Raised when the build definition cannot be found in the provenance statement.
696679
"""
697680
build_type = ProvenancePredicate.get_build_type(statement)
681+
if build_type is None:
682+
raise ProvenanceError("Unable to find buildType in the provenance statement.")
683+
698684
build_defs: list[ProvenanceBuildDefinition] = [
699685
SLSAGithubGenericBuildDefinitionV01(),
700686
SLSAGithubActionsBuildDefinitionV1(),

src/macaron/repo_finder/repo_finder_deps_dev.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def _create_urls(self, purl: PackageURL) -> list[str]:
125125
The list of created URLs.
126126
"""
127127
# See https://docs.deps.dev/api/v3alpha/
128-
base_url = f"https://api.deps.dev/v3alpha/purl/{encode(str(purl)).replace('/', '%2F')}"
128+
base_url = f"https://api.deps.dev/v3alpha/purl/{encode(str(purl), safe='')}"
129129

130130
if not base_url:
131131
return []

src/macaron/slsa_analyzer/checks/build_as_code_check.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def run_check(self, ctx: AnalyzeContext) -> CheckResultData:
169169
job = callee.caller
170170

171171
# We always expect the caller of the node that calls a third-party
172-
# or Reusable GitHub Action to be be a GitHubJobNode.
172+
# or Reusable GitHub Action to be a GitHubJobNode.
173173
if not isinstance(job, GitHubJobNode):
174174
continue
175175

src/macaron/slsa_analyzer/ci_service/github_actions/github_actions_ci.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ def workflow_run_deleted(self, timestamp: datetime) -> bool:
451451
# TODO: change this check if this issue is resolved:
452452
# https://github.com/orgs/community/discussions/138249
453453
if datetime.now(timezone.utc) - timedelta(days=400) > timestamp:
454-
logger.debug("Artifact published at %s is older than 410 days.", timestamp)
454+
logger.debug("Artifact published at %s is older than 400 days.", timestamp)
455455
return True
456456

457457
return False

src/macaron/slsa_analyzer/package_registry/maven_central_registry.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ def find_publish_timestamp(self, purl: str, registry_url: str | None = None) ->
214214
purl_object = PackageURL.from_string(purl)
215215
except ValueError as error:
216216
logger.debug("Could not parse PURL: %s", error)
217+
218+
if not purl_object.version:
219+
raise InvalidHTTPResponseError("The PackageURL of the software component misses version.")
220+
217221
query_params = [f"q=g:{purl_object.namespace}", f"a:{purl_object.name}", f"v:{purl_object.version}"]
218222

219223
try:
@@ -230,7 +234,7 @@ def find_publish_timestamp(self, purl: str, registry_url: str | None = None) ->
230234
raise InvalidHTTPResponseError("Failed to construct the search URL for Maven Central.") from error
231235

232236
response = send_get_http_raw(url, headers=None, timeout=self.request_timeout)
233-
if response and response.status_code == 200:
237+
if response:
234238
try:
235239
res_obj = response.json()
236240
except requests.exceptions.JSONDecodeError as error:

src/macaron/slsa_analyzer/package_registry/package_registry.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def find_publish_timestamp(self, purl: str, registry_url: str | None = None) ->
8888
# is available for subsequent processing.
8989

9090
base_url_parsed = urllib.parse.urlparse(registry_url or "https://api.deps.dev")
91-
path_params = "/".join(["v3alpha", "purl", encode(purl).replace("/", "%2F")])
91+
path_params = "/".join(["v3alpha", "purl", encode(purl, safe="")])
9292
try:
9393
url = urllib.parse.urlunsplit(
9494
urllib.parse.SplitResult(
@@ -118,8 +118,8 @@ def find_publish_timestamp(self, purl: str, registry_url: str | None = None) ->
118118
logger.debug("Found timestamp: %s.", timestamp)
119119

120120
try:
121-
return datetime.fromisoformat(timestamp.replace("Z", "+00:00"))
122-
except (OverflowError, OSError) as error:
121+
return datetime.fromisoformat(timestamp)
122+
except ValueError as error:
123123
raise InvalidHTTPResponseError(f"The timestamp returned by {url} is invalid") from error
124124

125125
raise InvalidHTTPResponseError(f"Invalid response from deps.dev for {url}.")

0 commit comments

Comments
 (0)