onekey-sec/python-client

GitHub: onekey-sec/python-client

ONEKEY Python 客户端,简化与 ONEKEY 平台交互的 Python API。

Stars: 6 | Forks: 3

# ONEKEY API 客户端 这是 [ONEKEY](https://www.onekey.com/) 公共 API 的官方 Python 客户端。此包提供命令行界面和 Python 库。 # 安装 客户端可在 https://github.com/onekey-sec/python-client 获取,或作为 Python 包安装: ``` pip install onekey-client ``` # 命令行界面使用 客户端可以使用 onekey 命令,并提供多个子命令: ``` 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 ``` 要使用 ONEKEY 平台,需要提供有效的电子邮件和密码,并指定要使用的租户名称。(目前不支持 SSO 认证。)首选的替代方案是使用基于 API 令牌的认证,API 令牌可以在 ONEKEY 平台上生成。 所需的参数可以通过命令行参数或使用以 `ONEKEY_` 为前缀的环境变量提供,如下两个是相同的: ``` onekey --email "" --tenant "" --password "" get-tenant-token ``` ``` ONEKEY_EMAIL="" ONEKEY_TENANT_NAME="" ONEKEY_PASSWORD="" onekey get-tenant-token ``` 环境变量和命令行参数也可以混合使用。使用环境变量在 CI/CD 作业/任务中使用客户端时很有用。 # API 使用 首先,您必须登录并选择一个租户: ``` 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) ``` 或使用 API 令牌: ``` 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) ``` 登录并选择租户后,您可以查询 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") ``` 您可以上传固件: ``` 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) ``` # 支持 您可以在本存储库中创建 [新问题](https://github.com/onekey-sec/python-client/issues/new) 或通过 support@onekey.com 联系我们。
标签:LNA, 逆向工具