-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathsbom_command.py
More file actions
73 lines (65 loc) · 2.22 KB
/
sbom_command.py
File metadata and controls
73 lines (65 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from pathlib import Path
from typing import Annotated, Optional
import typer
from cycode.cli.cli_types import BusinessImpactOption
from cycode.cli.exceptions.handle_report_sbom_errors import handle_report_exception
from cycode.cli.utils.get_api_client import get_import_sbom_cycode_client
from cycode.cyclient.import_sbom_client import ImportSbomParameters
def sbom_command(
ctx: typer.Context,
path: Annotated[
Path,
typer.Argument(
exists=True, resolve_path=True, dir_okay=False, readable=True, help='Path to SBOM file.', show_default=False
),
],
sbom_name: Annotated[
str, typer.Option('--name', '-n', help='SBOM Name.', case_sensitive=False, show_default=False)
],
vendor: Annotated[
str, typer.Option('--vendor', '-v', help='Vendor Name.', case_sensitive=False, show_default=False)
],
labels: Annotated[
Optional[list[str]],
typer.Option(
'--label', '-l', help='Label, can be specified multiple times.', case_sensitive=False, show_default=False
),
] = None,
owners: Annotated[
Optional[list[str]],
typer.Option(
'--owner',
'-o',
help='Email address of a user in Cycode platform, can be specified multiple times.',
case_sensitive=True,
show_default=False,
),
] = None,
business_impact: Annotated[
BusinessImpactOption,
typer.Option(
'--business-impact',
'-b',
help='Business Impact.',
case_sensitive=True,
show_default=True,
),
] = BusinessImpactOption.MEDIUM,
) -> None:
"""Import SBOM."""
client = get_import_sbom_cycode_client(ctx)
import_parameters = ImportSbomParameters(
Name=sbom_name,
Vendor=vendor,
BusinessImpact=business_impact,
Labels=labels,
Owners=owners,
)
try:
if not path.exists():
from errno import ENOENT
from os import strerror
raise FileNotFoundError(ENOENT, strerror(ENOENT), path.absolute())
client.request_sbom_import_execution(import_parameters, path)
except Exception as e:
handle_report_exception(ctx, e)