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
3742def upload_firmware (
3843 client : Client ,
@@ -42,17 +47,23 @@ 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):
47- """Upload a firmware to the ONEKEY platform."""
53+ """Upload a firmware / SBOM to the ONEKEY platform."""
54+ if filename is None and sbom is None :
55+ error = "Either `--sbom` or `FILENAME` or both must be provided"
56+ raise click .BadParameter (error )
57+
4858 product_group_id = _get_product_group_id_by_name (client , product_group_name )
4959 analysis_configuration_id = _get_analysis_configuration_id_by_name (
5060 client , analysis_configuration_name
5161 )
5262
5363 if name is None :
64+ postfix = filename .name if filename is not None else sbom .stem
5465 name = (
55- f"{ vendor_name } -{ product_name } -{ filename . name } "
66+ f"{ vendor_name } -{ product_name } -{ postfix } "
5667 if version is None
5768 else f"{ vendor_name } -{ product_name } -{ version } "
5869 )
@@ -67,7 +78,9 @@ def upload_firmware(
6778 )
6879
6980 try :
70- res = client .upload_firmware (metadata , filename , enable_monitoring = False )
81+ res = client .upload_firmware (
82+ metadata , filename , sbom_path = sbom , enable_monitoring = False
83+ )
7184 click .echo (res ["id" ])
7285 except QueryError as e :
7386 click .echo ("Error during firmware upload:" )
0 commit comments