Skip to content

Commit 0b35f0c

Browse files
committed
added tests and ran ruff
1 parent c4aa2fe commit 0b35f0c

File tree

8 files changed

+438
-34
lines changed

8 files changed

+438
-34
lines changed

cycode/cli/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from typer.completion import install_callback, show_callback
1010

1111
from cycode import __version__
12-
from cycode.cli.apps import ai_remediation, auth, configure, ignore, report, scan, status,report_import
12+
from cycode.cli.apps import ai_remediation, auth, configure, ignore, report, scan, status, report_import
1313

1414
if sys.version_info >= (3, 10):
1515
from cycode.cli.apps import mcp

cycode/cli/apps/report_import/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@
55

66
app = typer.Typer(name='import', no_args_is_help=True)
77
app.callback(short_help='Import report. You`ll need to specify which report type to import.')(report_import_command)
8-
app.command(name='sbom',short_help='Import SBOM report from a local path.')(sbom_command)
9-
8+
app.command(name='sbom', short_help='Import SBOM report from a local path.')(sbom_command)

cycode/cli/apps/report_import/sbom/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33
from cycode.cli.apps.report_import.sbom.sbom_command import sbom_command
44

55
app = typer.Typer(name='sbom')
6-
app.command(name='path',short_help='Import SBOM report from a local path.')(sbom_command)
7-
6+
app.command(name='path', short_help='Import SBOM report from a local path.')(sbom_command)

cycode/cli/apps/report_import/sbom/sbom_command.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,20 @@ def sbom_command(
3232
str, typer.Option('--vendor', '-v', help='Vendor Name.', case_sensitive=False, show_default=False)
3333
],
3434
labels: Annotated[
35-
Optional[List[str]], typer.Option('--label', '-l', help='Label, can be specified multiple times.', case_sensitive=False, show_default=False)
35+
Optional[List[str]],
36+
typer.Option(
37+
'--label', '-l', help='Label, can be specified multiple times.', case_sensitive=False, show_default=False
38+
),
3639
] = [],
3740
owners: Annotated[
38-
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)
41+
Optional[List[str]],
42+
typer.Option(
43+
'--owner',
44+
'-o',
45+
help='Email address of a user in Cycode platform, can be specified multiple times.',
46+
case_sensitive=True,
47+
show_default=False,
48+
),
3949
] = [],
4050
business_impact: Annotated[
4151
BusinessImpactOption,
@@ -65,6 +75,7 @@ def sbom_command(
6575
if not input_file.exists():
6676
from errno import ENOENT
6777
from os import strerror
78+
6879
raise FileNotFoundError(ENOENT, strerror(ENOENT), input_file.absolute())
6980

7081
client.request_sbom_import_execution(import_parameters, input_file)

cycode/cyclient/import_sbom_client.py

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ def to_request_form(self) -> dict:
2525
form_data = {}
2626
for field in dataclasses.fields(self):
2727
key = field.name
28-
val = getattr(self,key)
28+
val = getattr(self, key)
2929
if val is None or len(val) == 0:
3030
continue
31-
if isinstance(val,list):
32-
form_data[f"{key}[]"] = val
31+
if isinstance(val, list):
32+
form_data[f'{key}[]'] = val
3333
else:
3434
form_data[key] = val
3535
return form_data
@@ -52,38 +52,29 @@ def request_sbom_import_execution(self, params: ImportSbomParameters, file_path:
5252
request_args = {
5353
'url_path': self.IMPORT_SBOM_REQUEST_PATH,
5454
'data': form_data,
55-
'files': {
56-
'File': open(file_path.absolute(),'rb')
57-
},
55+
'files': {'File': open(file_path.absolute(), 'rb')},
5856
}
5957

6058
response = self.client.post(**request_args)
6159

6260
if response.status_code != 201:
63-
raise RequestHttpError(response.status_code, response.text,response)
64-
65-
def get_owners_user_ids(self,owners: List[str]) -> List[str]:
66-
return [ self._get_user_id_by_email(owner) for owner in owners]
67-
68-
def _get_user_id_by_email(self,email: str) -> str:
69-
70-
request_args = {
71-
'url_path': self.GET_USER_ID_REQUEST_PATH,
72-
'params': {
73-
'email': email
74-
}
75-
}
61+
raise RequestHttpError(response.status_code, response.text, response)
62+
63+
def get_owners_user_ids(self, owners: List[str]) -> List[str]:
64+
return [self._get_user_id_by_email(owner) for owner in owners]
65+
66+
def _get_user_id_by_email(self, email: str) -> str:
67+
request_args = {'url_path': self.GET_USER_ID_REQUEST_PATH, 'params': {'email': email}}
7668

7769
response = self.client.get(**request_args)
7870
member_details = self.parse_requested_member_details_response(response)
7971

8072
if not member_details.items:
81-
raise Exception(f"Failed to find user with email '{email}'. Verify this email is registered to Cycode platform")
73+
raise Exception(
74+
f"Failed to find user with email '{email}'. Verify this email is registered to Cycode platform"
75+
)
8276
return member_details.items.pop(0).external_id
83-
77+
8478
@staticmethod
8579
def parse_requested_member_details_response(response: Response) -> models.MemberDetails:
8680
return models.RequestedMemberDetailsResultSchema().load(response.json())
87-
88-
89-

cycode/cyclient/models.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ class DetectionSchema(Schema):
4747
class Meta:
4848
unknown = EXCLUDE
4949

50-
id = fields.String(missing=None)
50+
id = fields.String(load_default=None)
5151
message = fields.String()
5252
type = fields.String()
53-
severity = fields.String(missing=None)
53+
severity = fields.String(load_default=None)
5454
detection_type_id = fields.String()
5555
detection_details = fields.Dict()
5656
detection_rule_id = fields.String()
@@ -401,10 +401,12 @@ class Meta:
401401
def build_dto(self, data: dict[str, Any], **_) -> SbomReport:
402402
return SbomReport(**data)
403403

404+
404405
@dataclass
405406
class Member:
406407
external_id: str
407408

409+
408410
class MemberSchema(Schema):
409411
class Meta:
410412
unknown = EXCLUDE
@@ -415,12 +417,14 @@ class Meta:
415417
def build_dto(self, data: dict[str, Any], **_) -> Member:
416418
return Member(**data)
417419

420+
418421
@dataclass
419422
class MemberDetails:
420423
items: list[Member]
421424
page_size: int
422425
next_page_token: Optional[str]
423426

427+
424428
class RequestedMemberDetailsResultSchema(Schema):
425429
class Meta:
426430
unknown = EXCLUDE
@@ -430,9 +434,10 @@ class Meta:
430434
next_page_token = fields.String(allow_none=True)
431435

432436
@post_load
433-
def build_dto(self, data: dict[str,Any], **_) -> MemberDetails:
437+
def build_dto(self, data: dict[str, Any], **_) -> MemberDetails:
434438
return MemberDetails(**data)
435439

440+
436441
@dataclass
437442
class ClassificationData:
438443
severity: str

0 commit comments

Comments
 (0)