|
1 | 1 | import dataclasses |
2 | | -from typing import List, Optional |
3 | 2 | from pathlib import Path |
| 3 | +from typing import Optional |
| 4 | + |
4 | 5 | from requests import Response |
5 | | -from urllib.parse import quote |
6 | 6 |
|
7 | 7 | from cycode.cli.cli_types import BusinessImpactOption |
8 | | -from cycode.cli.exceptions.custom_exceptions import CycodeError, RequestHttpError |
9 | | -from cycode.cyclient.cycode_client_base import CycodeClientBase |
| 8 | +from cycode.cli.exceptions.custom_exceptions import RequestHttpError |
10 | 9 | from cycode.cyclient import models |
| 10 | +from cycode.cyclient.cycode_client_base import CycodeClientBase |
11 | 11 |
|
12 | 12 |
|
13 | 13 | @dataclasses.dataclass |
14 | 14 | class ImportSbomParameters: |
15 | 15 | Name: str |
16 | 16 | Vendor: str |
17 | 17 | BusinessImpact: BusinessImpactOption |
18 | | - Labels: Optional[List[str]] |
19 | | - Owners: Optional[List[str]] |
| 18 | + Labels: Optional[list[str]] |
| 19 | + Owners: Optional[list[str]] |
20 | 20 |
|
21 | | - def _owners_to_ids(self) -> List[str]: |
| 21 | + def _owners_to_ids(self) -> list[str]: |
22 | 22 | return [] |
23 | 23 |
|
24 | 24 | def to_request_form(self) -> dict: |
@@ -49,18 +49,20 @@ def request_sbom_import_execution(self, params: ImportSbomParameters, file_path: |
49 | 49 |
|
50 | 50 | form_data = params.to_request_form() |
51 | 51 |
|
52 | | - request_args = { |
53 | | - 'url_path': self.IMPORT_SBOM_REQUEST_PATH, |
54 | | - 'data': form_data, |
55 | | - 'files': {'File': open(file_path.absolute(), 'rb')}, |
56 | | - } |
| 52 | + with open(file_path.absolute(), 'rb') as f: |
| 53 | + |
| 54 | + request_args = { |
| 55 | + 'url_path': self.IMPORT_SBOM_REQUEST_PATH, |
| 56 | + 'data': form_data, |
| 57 | + 'files': {'File': f}, |
| 58 | + } |
57 | 59 |
|
58 | | - response = self.client.post(**request_args) |
| 60 | + response = self.client.post(**request_args) |
59 | 61 |
|
60 | 62 | if response.status_code != 201: |
61 | 63 | raise RequestHttpError(response.status_code, response.text, response) |
62 | 64 |
|
63 | | - def get_owners_user_ids(self, owners: List[str]) -> List[str]: |
| 65 | + def get_owners_user_ids(self, owners: list[str]) -> list[str]: |
64 | 66 | return [self._get_user_id_by_email(owner) for owner in owners] |
65 | 67 |
|
66 | 68 | def _get_user_id_by_email(self, email: str) -> str: |
|
0 commit comments