Skip to content

Commit

Permalink
refactor: apply mypy, flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
Matze08 committed Jan 20, 2025
1 parent bc9d6d2 commit a8caed9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
22 changes: 13 additions & 9 deletions cdxev/build_public_bom.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
# SPDX-License-Identifier: GPL-3.0-or-later

import json
import logging
import re
import typing as t
from pathlib import Path
from typing import Any, Sequence
import logging
from cdxev.log import LogMessage

from jsonschema import Draft7Validator, FormatChecker

from cdxev.auxiliary.sbomFunctions import extract_components
from cdxev.log import LogMessage

logger = logging.getLogger(__name__)

def check_affected_metadata(metadata: dict[str, Any], path_to_schema: str) -> bool:

def check_affected_metadata(metadata: dict[str, Any], path_to_schema: Path) -> bool:
"""
Checks if the metadata.component is affected by the schema.
Checks if the metadata.component is affected by the schema.
If so, the function prints a warning.
Parameters
----------
Expand All @@ -32,11 +35,11 @@ def check_affected_metadata(metadata: dict[str, Any], path_to_schema: str) -> bo
validator_for_being_internal = create_internal_validator(path_to_schema)
if validator_for_being_internal.is_valid(metadata.get("component", [])):
logger.warning(
LogMessage(
"Warning: `metadata.component` is not affected by the JSON schema!",
"Please check manually."
)
LogMessage(
"Warning: `metadata.component` is not affected by the JSON schema!",
"Please check manually.",
)
)
return True
return False

Expand Down Expand Up @@ -182,7 +185,8 @@ def build_public_bom(sbom: dict, path_to_schema: t.Union[Path, None]) -> dict:
metadata = sbom.get("metadata", [])
components = sbom.get("components", [])
dependencies = sbom.get("dependencies", [])
check_affected_metadata(metadata, path_to_schema)
if path_to_schema:
check_affected_metadata(metadata, path_to_schema)
(
list_of_removed_components,
cleared_components,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_build_public_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,4 @@ def test_build_public_affected_metadata_warning(self) -> None:
sbom = get_test_sbom()
metadata = sbom.get("metadata", [])
metadata["component"]["group"] = "com.acme.internal"
self.assertTrue(b_p_b.check_affected_metadata(metadata, path_to_documentation_schema_1))
self.assertTrue(b_p_b.check_affected_metadata(metadata, path_to_documentation_schema_1))

0 comments on commit a8caed9

Please sign in to comment.