-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from sw360/83-strange-behavior-when-trying-to-…
…convert-xml-cyclonedx feat: SBOM XML conversion and SBOM validation
- Loading branch information
Showing
17 changed files
with
11,412 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# ------------------------------------------------------------------------------- | ||
# Copyright (c) 2024 Siemens | ||
# All Rights Reserved. | ||
# Author: [email protected] | ||
# | ||
# SPDX-License-Identifier: MIT | ||
# ------------------------------------------------------------------------------- | ||
|
||
import os | ||
import sys | ||
from typing import Any | ||
|
||
import capycli.common.json_support | ||
import capycli.common.script_base | ||
from capycli import get_logger | ||
from capycli.common.capycli_bom_support import CaPyCliBom | ||
from capycli.common.print import print_text | ||
from capycli.main.exceptions import CaPyCliException | ||
from capycli.main.result_codes import ResultCode | ||
|
||
LOG = get_logger(__name__) | ||
|
||
|
||
class BomValidate(capycli.common.script_base.ScriptBase): | ||
def validate(self, inputfile: str, spec_version: str) -> None: | ||
"""Main validation method.""" | ||
try: | ||
if not spec_version: | ||
print_text("No CycloneDX spec version specified, defaulting to 1.6") | ||
spec_version = "1.6" | ||
CaPyCliBom.validate_sbom(inputfile, spec_version) | ||
except CaPyCliException as error: | ||
LOG.error(f"Error processing input file: {str(error)}") | ||
sys.exit(ResultCode.RESULT_GENERAL_ERROR) | ||
|
||
def check_arguments(self, args: Any) -> None: | ||
"""Check input arguments.""" | ||
if not args.inputfile: | ||
LOG.error("No input file specified!") | ||
sys.exit(ResultCode.RESULT_COMMAND_ERROR) | ||
|
||
if not os.path.isfile(args.inputfile): | ||
LOG.error("Input file not found!") | ||
sys.exit(ResultCode.RESULT_FILE_NOT_FOUND) | ||
|
||
def display_help(self) -> None: | ||
"""Display (local) help.""" | ||
print("usage: CaPyCli bom validate [-h] -i INPUTFILE [-version SpecVersion]") | ||
print("") | ||
print("optional arguments:") | ||
print(" -h, --help Show this help message and exit") | ||
print(" -i INPUTFILE Input BOM filename (JSON)") | ||
print(" -version SpecVersion CycloneDX spec version to validate against: allowed are 1.4, 1.5, and 1.6") | ||
|
||
def run(self, args: Any) -> None: | ||
"""Main method()""" | ||
print("\n" + capycli.APP_NAME + ", " + capycli.get_app_version() + " - Validate a CaPyCLI/CycloneDX SBOM\n") | ||
|
||
if args.help: | ||
self.display_help() | ||
return | ||
|
||
self.check_arguments(args) | ||
if args.debug: | ||
global LOG | ||
LOG = get_logger(__name__) | ||
|
||
self.validate(args.inputfile, args.version) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# ------------------------------------------------------------------------------- | ||
# Copyright (c) 2019-23 Siemens | ||
# Copyright (c) 2019-24 Siemens | ||
# All Rights Reserved. | ||
# Author: [email protected] | ||
# | ||
|
@@ -10,6 +10,7 @@ | |
from typing import Any | ||
|
||
import capycli.bom.bom_convert | ||
import capycli.bom.bom_validate | ||
import capycli.bom.check_bom | ||
import capycli.bom.check_bom_item_status | ||
import capycli.bom.check_granularity | ||
|
@@ -46,9 +47,10 @@ def run_bom_command(args: Any) -> None: | |
print(" CreateComponents create new components and releases on SW360 (use with care!)") | ||
print(" DownloadSources download source files from the URL specified in the SBOM") | ||
print(" Granularity check a bill of material for potential component granularity issues") | ||
print(" Diff compare two bills of material.") | ||
print(" Merge merge two bills of material.") | ||
print(" Findsources determine the source code for SBOM items.") | ||
print(" Diff compare two bills of material") | ||
print(" Merge merge two bills of material") | ||
print(" Findsources determine the source code for SBOM items") | ||
print(" Validate validate an SBOM") | ||
return | ||
|
||
subcommand = args.command[1].lower() | ||
|
@@ -131,5 +133,11 @@ def run_bom_command(args: Any) -> None: | |
app13.run(args) | ||
return | ||
|
||
if subcommand == "validate": | ||
"""Validate an SBOM.""" | ||
app14 = capycli.bom.bom_validate.BomValidate() | ||
app14.run(args) | ||
return | ||
|
||
print_red("Unknown sub-command: ") | ||
sys.exit(ResultCode.RESULT_COMMAND_ERROR) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.