Skip to main content

ONEKEY API client

Project description

ONEKEY API Client

This is the official Python client for the ONEKEY public API. This package provides both a cli and a python library.

Installation

The client is available at https://github.com/onekey-sec/python-client or can be installed as a python package:

pip install onekey-client

CLI Usage

The client can be used with the onekey command and offers multiple subcommands:

Usage: onekey [OPTIONS] COMMAND [ARGS]...

Options:
  --api-url TEXT        ONEKEY platform API endpoint  [default:
                        https://app.eu.onekey.com/api]
  --disable-tls-verify  Disable verifying server certificate, use only for
                        testing
  --email TEXT          Email to authenticate on the ONEKEY platform
  --password TEXT       Password to authenticate on the ONEKEY platform
  --tenant TEXT         Tenant name on ONEKEY platform
  --token TEXT          API token to authenticate on the ONEKEY platform
  --help                Show this message and exit.

Commands:
  ci-result         Fetch analysis results for CI
  get-tenant-token  Get tenant specific Bearer token
  list-tenants      List available tenants
  upload-firmware   Uploads a firmware to the ONEKEY platform

To use the ONEKEY platform a valid email & password need to be supplied along with specifying the tenant name to be used. (SSO authentication is currently not supported.) Preferred alternative is to use a dedicated API token based authentication, API tokens can be generated on the ONEKEY platform.

The required parameters can be supplied through command line arguments or using environment variables prefixed with ONEKEY_, such as the following two are identical:

onekey --email "<email>" --tenant "<tenant-name>" --password "<password>" get-tenant-token
ONEKEY_EMAIL="<email>" ONEKEY_TENANT_NAME="<tenant-name>" ONEKEY_PASSWORD="<password>" onekey get-tenant-token

Environment variables and command line arguments can be also mixed. Using environment variables is useful when the client is used from CI/CD jobs/tasks.

API Usage

First, you have to log in and select a tenant:

from onekey_client import Client

YOUR_API_URL = "https://app.eu.onekey.com/api"

client = Client(api_url=YOUR_API_URL)

client.login(EMAIL, PASSWORD)
tenant = client.get_tenant("Environment name")
client.use_tenant(tenant)

Or use an API Token:

from onekey_client import Client

YOUR_API_URL = "https://app.eu.onekey.com/api"

client = Client(api_url=YOUR_API_URL)

client.use_token(API_TOKEN)

After you logged in and selected the tenant, you can query the GraphQL API

GET_ALL_FIRMWARES = """
query {
  allFirmwares {
    id
    name
  }
}
"""
res = client.query(GET_ALL_FIRMWARES)
print(res)

GET_PRODUCT_GROUPS = """
query {
  allProductGroups {
    id
    name
  }
}
"""
res = client.query(GET_PRODUCT_GROUPS)
default_product_group = next(pg for pg in res["allProductGroups"] if pg["name"] == "Default")

GET_ANALYSIS_CONFIGURATIONS = """
query {
  allAnalysisConfigurations {
    id
    name
  }
}
"""
res = client.query(GET_ANALYSIS_CONFIGURATIONS)
default_analysis_configuration = next(conf for conf in res["allAnalysisConfigurations"] if conf["name"] == "Default")

You can upload firmwares:

metadata = FirmwareMetadata(
    name="myFirmware",
    vendor_name="myVendor",
    product_name="myProduct",
    product_group_id=default_product_group["id"],
    analysis_configuration_id=default_analysis_configuration["id"],
)

firmware_path = Path("/path/to/firmware.bin")
res = client.upload_firmware(metadata, firmware_path, enable_monitoring=True)
print(res)

Support

You can create a new issue in this repo or contact us at support@onekey.com.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

onekey_client-2.4.0.tar.gz (59.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

onekey_client-2.4.0-py3-none-any.whl (28.9 kB view details)

Uploaded Python 3

File details

Details for the file onekey_client-2.4.0.tar.gz.

File metadata

  • Download URL: onekey_client-2.4.0.tar.gz
  • Upload date:
  • Size: 59.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for onekey_client-2.4.0.tar.gz
Algorithm Hash digest
SHA256 340c2ffe9f1a36445ffc3af28e80608c8a7c1d8e71eabb0cc516bd872aadbc19
MD5 4277c548f709908d91cf8e9c65a674ee
BLAKE2b-256 cffe7ad5fdd4bcbc6fc30bf7f05851511dee2b4504f1524e3a49696b799bfdec

See more details on using hashes here.

File details

Details for the file onekey_client-2.4.0-py3-none-any.whl.

File metadata

  • Download URL: onekey_client-2.4.0-py3-none-any.whl
  • Upload date:
  • Size: 28.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for onekey_client-2.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6c22b925dc314c4c6727c753e19b3184fbf1788935e99ef6c6fad79bb17c3b83
MD5 6c4fcf12ebef530d3c87e6706cad37c6
BLAKE2b-256 ff1128c6ad9a2906872aef27f3ed1fcc25e1c72fd9a6ef87bdeefaca4e1e03eb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page