Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions onekey_client/cli/firmware_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
)
Expand All @@ -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,
):
Expand Down Expand Up @@ -90,6 +112,7 @@ def upload_firmware(
analysis_configuration_id=analysis_configuration_id,
labels=list(label),
notes=notes,
properties=properties or None,
)

try:
Expand Down
5 changes: 5 additions & 0 deletions onekey_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions onekey_client/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading