Skip to content

Commit 2aea41f

Browse files
committed
feat: extend firmware upload to handle SBOM and SBOM only cases
SBOM file can be also uploaded next to the firmware image. To upload only the SBOM the current workaround is to upload an empty file.
1 parent e7c664e commit 2aea41f

2 files changed

Lines changed: 21 additions & 7 deletions

File tree

onekey_client/cli/firmware_upload.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@
3232
)
3333
@click.option("--version", help="Firmware version")
3434
@click.option("--name", help="Firmware name")
35-
@click.argument("filename", type=click.Path(exists=True, path_type=Path))
35+
@click.option(
36+
"--sbom", help="Firmware SBOM", type=click.Path(exists=True, path_type=Path)
37+
)
38+
@click.argument(
39+
"filename", type=click.Path(exists=True, path_type=Path), required=False
40+
)
3641
@click.pass_obj
3742
def upload_firmware(
3843
client: Client,
@@ -42,7 +47,8 @@ def upload_firmware(
4247
analysis_configuration_name: str,
4348
version: str | None,
4449
name: str | None,
45-
filename: Path,
50+
sbom: Path | None,
51+
filename: Path | None,
4652
):
4753
"""Upload a firmware to the ONEKEY platform."""
4854
product_group_id = _get_product_group_id_by_name(client, product_group_name)
@@ -67,7 +73,9 @@ def upload_firmware(
6773
)
6874

6975
try:
70-
res = client.upload_firmware(metadata, filename, enable_monitoring=False)
76+
res = client.upload_firmware(
77+
metadata, filename, sbom_path=sbom, enable_monitoring=False
78+
)
7179
click.echo(res["id"])
7280
except QueryError as e:
7381
click.echo("Error during firmware upload:")

onekey_client/client.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,14 @@ def query(self, query: str, variables: dict | None = None, timeout=60):
188188
def upload_firmware(
189189
self,
190190
metadata: m.FirmwareMetadata,
191-
path: Path,
191+
path: Path | None,
192192
*,
193+
sbom_path: Path | None = None,
193194
enable_monitoring: bool,
194195
timeout=60,
195196
):
197+
assert path is not None or sbom_path is not None
198+
196199
variables = {
197200
"firmware": {
198201
"name": metadata.name,
@@ -215,9 +218,12 @@ def upload_firmware(
215218
raise errors.QueryError(res["createFirmwareUpload"]["errors"])
216219

217220
upload_url = res["createFirmwareUpload"]["uploadUrl"]
218-
return self._post_with_token(
219-
upload_url, files={"firmware": path.open("rb")}, timeout=timeout
220-
)
221+
222+
files = {}
223+
files["firmware"] = path.open("rb") if path is not None else b""
224+
if sbom_path is not None:
225+
files["sbom"] = sbom_path.open("rb")
226+
return self._post_with_token(upload_url, files=files, timeout=timeout)
221227

222228
@_tenant_required
223229
def get_product_groups(self):

0 commit comments

Comments
 (0)