diff --git a/onekey_client/cli/firmware_upload.py b/onekey_client/cli/firmware_upload.py index ec94a11..a1f2772 100644 --- a/onekey_client/cli/firmware_upload.py +++ b/onekey_client/cli/firmware_upload.py @@ -7,6 +7,19 @@ from onekey_client.errors import QueryError +def _parse_properties( + _ctx: click.Context, _param: click.Parameter, values: tuple[str, ...] +) -> dict[str, str]: + properties = {} + for value in values: + name, separator, property_value = value.partition("=") + if not separator or not name.strip(): + error = "Expected NAME=VALUE with a non-empty property name" + raise click.BadParameter(error) + properties[name] = property_value + return properties + + @click.command() @click.option( "--product", "product_name", required=True, help="Product name to add the firmware" @@ -44,6 +57,14 @@ @click.option("--monitoring", is_flag=True, default=False, help="Enable monitoring") @click.option("--label", multiple=True, help="Add a label (repeatable)") @click.option("--notes", help="Free-text notes for the firmware") +@click.option( + "--property", + "properties", + multiple=True, + metavar="NAME=VALUE", + callback=_parse_properties, + help="Add a firmware property (repeatable; last value wins for duplicate names)", +) @click.argument( "filename", type=click.Path(exists=True, path_type=Path), required=False ) @@ -60,6 +81,7 @@ def upload_firmware( name: str | None, label: tuple[str], notes: str | None, + properties: dict[str, str], sbom: Path | None, filename: Path | None, ): @@ -90,6 +112,7 @@ def upload_firmware( analysis_configuration_id=analysis_configuration_id, labels=list(label), notes=notes, + properties=properties or None, ) try: diff --git a/onekey_client/client.py b/onekey_client/client.py index 7b34ec4..d231668 100644 --- a/onekey_client/client.py +++ b/onekey_client/client.py @@ -232,6 +232,11 @@ def upload_firmware( "productCategory": metadata.product_category, "productGroupID": str(metadata.product_group_id), } + if metadata.properties is not None: + variables["firmware"]["properties"] = [ + {"name": name, "value": value} + for name, value in metadata.properties.items() + ] upload_mutation = load_query("create_firmware_upload.graphql") res = self.query(upload_mutation, variables=variables) diff --git a/onekey_client/models.py b/onekey_client/models.py index ff1352a..e94916c 100644 --- a/onekey_client/models.py +++ b/onekey_client/models.py @@ -20,3 +20,4 @@ class FirmwareMetadata(BaseModel): product_group_id: UUID analysis_configuration_id: UUID labels: list[str] | None = None + properties: dict[str, str] | None = None