onekey_client


Nameonekey_client JSON
Version 2.3.0 PyPI version JSON
download
home_pagehttps://www.onekey.com/
SummaryONEKEY API client
upload_time2024-04-23 09:48:37
maintainerNone
docs_urlNone
authorONEKEY
requires_python<4.0.0,>=3.8.0
licenseMIT
keywords iot security firmware analysis
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ONEKEY API Client

This is the official Python client for the
[ONEKEY](https://www.onekey.com/) 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:

```commandline
pip install onekey-client
```

# CLI Usage

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

```commandline
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:

```commandline
onekey --email "<email>" --tenant "<tenant-name>" --password "<password>" get-tenant-token
```

```commandline
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:

```python
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:

```python
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

```python
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:

```python
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](https://github.com/onekey-sec/python-client/issues/new)
or contact us at support@onekey.com.

            

Raw data

            {
    "_id": null,
    "home_page": "https://www.onekey.com/",
    "name": "onekey_client",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0.0,>=3.8.0",
    "maintainer_email": null,
    "keywords": "iot, security, firmware, analysis",
    "author": "ONEKEY",
    "author_email": "support@onekey.com",
    "download_url": "https://files.pythonhosted.org/packages/f1/30/b70a97dbca43861997a9813feed10ca491123b410709e0a8c096e44e3d82/onekey_client-2.3.0.tar.gz",
    "platform": null,
    "description": "# ONEKEY API Client\n\nThis is the official Python client for the\n[ONEKEY](https://www.onekey.com/) public API. This package provides both a cli and a python library.\n\n# Installation\n\nThe client is available at https://github.com/onekey-sec/python-client or can be installed as a python package:\n\n```commandline\npip install onekey-client\n```\n\n# CLI Usage\n\nThe client can be used with the onekey command and offers multiple subcommands:\n\n```commandline\nUsage: onekey [OPTIONS] COMMAND [ARGS]...\n\nOptions:\n  --api-url TEXT        ONEKEY platform API endpoint  [default:\n                        https://app.eu.onekey.com/api]\n  --disable-tls-verify  Disable verifying server certificate, use only for\n                        testing\n  --email TEXT          Email to authenticate on the ONEKEY platform\n  --password TEXT       Password to authenticate on the ONEKEY platform\n  --tenant TEXT         Tenant name on ONEKEY platform\n  --token TEXT          API token to authenticate on the ONEKEY platform\n  --help                Show this message and exit.\n\nCommands:\n  ci-result         Fetch analysis results for CI\n  get-tenant-token  Get tenant specific Bearer token\n  list-tenants      List available tenants\n  upload-firmware   Uploads a firmware to the ONEKEY platform\n```\n\nTo use the ONEKEY platform a valid email & password need to be supplied along with specifying the tenant name to be\nused. (SSO authentication is currently not supported.) Preferred alternative is to use a dedicated API token based\nauthentication, API tokens can be generated on the ONEKEY platform.\n\nThe required parameters can be supplied through command line arguments or using environment variables prefixed with\n`ONEKEY_`, such as the following two are identical:\n\n```commandline\nonekey --email \"<email>\" --tenant \"<tenant-name>\" --password \"<password>\" get-tenant-token\n```\n\n```commandline\nONEKEY_EMAIL=\"<email>\" ONEKEY_TENANT_NAME=\"<tenant-name>\" ONEKEY_PASSWORD=\"<password>\" onekey get-tenant-token\n```\n\nEnvironment variables and command line arguments can be also mixed. Using environment variables is useful when the\nclient is used from CI/CD jobs/tasks.\n\n# API Usage\n\nFirst, you have to log in and select a tenant:\n\n```python\nfrom onekey_client import Client\n\nYOUR_API_URL = \"https://app.eu.onekey.com/api\"\n\nclient = Client(api_url=YOUR_API_URL)\n\nclient.login(EMAIL, PASSWORD)\ntenant = client.get_tenant(\"Environment name\")\nclient.use_tenant(tenant)\n```\n\nOr use an API Token:\n\n```python\nfrom onekey_client import Client\n\nYOUR_API_URL = \"https://app.eu.onekey.com/api\"\n\nclient = Client(api_url=YOUR_API_URL)\n\nclient.use_token(API_TOKEN)\n```\n\n\nAfter you logged in and selected the tenant, you can query the GraphQL API\n\n```python\nGET_ALL_FIRMWARES = \"\"\"\nquery {\n  allFirmwares {\n    id\n    name\n  }\n}\n\"\"\"\nres = client.query(GET_ALL_FIRMWARES)\nprint(res)\n\nGET_PRODUCT_GROUPS = \"\"\"\nquery {\n  allProductGroups {\n    id\n    name\n  }\n}\n\"\"\"\nres = client.query(GET_PRODUCT_GROUPS)\ndefault_product_group = next(pg for pg in res[\"allProductGroups\"] if pg[\"name\"] == \"Default\")\n\nGET_ANALYSIS_CONFIGURATIONS = \"\"\"\nquery {\n  allAnalysisConfigurations {\n    id\n    name\n  }\n}\n\"\"\"\nres = client.query(GET_ANALYSIS_CONFIGURATIONS)\ndefault_analysis_configuration = next(conf for conf in res[\"allAnalysisConfigurations\"] if conf[\"name\"] == \"Default\")\n```\n\nYou can upload firmwares:\n\n```python\nmetadata = FirmwareMetadata(\n    name=\"myFirmware\",\n    vendor_name=\"myVendor\",\n    product_name=\"myProduct\",\n    product_group_id=default_product_group[\"id\"],\n    analysis_configuration_id=default_analysis_configuration[\"id\"],\n)\n\nfirmware_path = Path(\"/path/to/firmware.bin\")\nres = client.upload_firmware(metadata, firmware_path, enable_monitoring=True)\nprint(res)\n```\n\n# Support\n\nYou can create a [new issue in this repo](https://github.com/onekey-sec/python-client/issues/new)\nor contact us at support@onekey.com.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "ONEKEY API client",
    "version": "2.3.0",
    "project_urls": {
        "Bug Tracker": "https://github.com/onekey-sec/python-client/issues",
        "GitHub": "https://github.com/onekey-sec/python-client",
        "Homepage": "https://www.onekey.com/"
    },
    "split_keywords": [
        "iot",
        " security",
        " firmware",
        " analysis"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "27c29cef1c5e2a242acb838942df01e137b43e7f6740efe29a99649b8fb771da",
                "md5": "c9fe4a1f66a5de6da29683fa9332e8d9",
                "sha256": "08bfc333ae57a27f914d51939b7e3bde8e5179cef31ecec151499706efda5457"
            },
            "downloads": -1,
            "filename": "onekey_client-2.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c9fe4a1f66a5de6da29683fa9332e8d9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0.0,>=3.8.0",
            "size": 29049,
            "upload_time": "2024-04-23T09:48:35",
            "upload_time_iso_8601": "2024-04-23T09:48:35.870052Z",
            "url": "https://files.pythonhosted.org/packages/27/c2/9cef1c5e2a242acb838942df01e137b43e7f6740efe29a99649b8fb771da/onekey_client-2.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f130b70a97dbca43861997a9813feed10ca491123b410709e0a8c096e44e3d82",
                "md5": "492ad6b389b228b0c9b94b6b59206f91",
                "sha256": "7b656b1fdffcb7c99111e74c17aa3756679481c69ae83856ac924b0f95ca0e05"
            },
            "downloads": -1,
            "filename": "onekey_client-2.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "492ad6b389b228b0c9b94b6b59206f91",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0.0,>=3.8.0",
            "size": 25297,
            "upload_time": "2024-04-23T09:48:37",
            "upload_time_iso_8601": "2024-04-23T09:48:37.069990Z",
            "url": "https://files.pythonhosted.org/packages/f1/30/b70a97dbca43861997a9813feed10ca491123b410709e0a8c096e44e3d82/onekey_client-2.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-23 09:48:37",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "onekey-sec",
    "github_project": "python-client",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "onekey_client"
}
        
Elapsed time: 0.27955s