start adapting py sdk to v1.0

This commit is contained in:
Kenneth Bingham 2025-02-27 15:07:37 -05:00
parent f48a49436e
commit 7545eeadb3
No known key found for this signature in database
GPG Key ID: 31709281860130B6
9 changed files with 309 additions and 17 deletions

View File

@ -4,7 +4,7 @@ This example shows the use of the zrok SDK spinning up a simple pastebin command
## Self-hosting Setup :wrench: ## Self-hosting Setup :wrench:
You don't need this section if you're using hosted zrok from NetFoundry (https://api.zrok.io/). You don't need this section if you're using hosted zrok from NetFoundry (https://api-v1.zrok.io/).
Refer to the [setup guide](../../../docs/guides/self-hosting/self_hosting_guide.md) for details on setting up your zrok Refer to the [setup guide](../../../docs/guides/self-hosting/self_hosting_guide.md) for details on setting up your zrok
environment if you're self-hosting zrok. environment if you're self-hosting zrok.

View File

@ -0,0 +1,3 @@
flask
requests
waitress

View File

@ -29,4 +29,4 @@ test-requirements.txt
test/ test/
docs/ docs/
README.md README.md
setup.py setup.py

View File

@ -0,0 +1,275 @@
# zrok_sdk
zrok client access
This Python package is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project:
- API version: 1.0.0
- Package version: 1.0.0
- Build package: io.swagger.codegen.v3.generators.python.PythonClientCodegen
## Requirements.
Python 2.7 and 3.4+
## Installation & Usage
### pip install
If the python package is hosted on Github, you can install directly from Github
```sh
pip install git+https://github.com/GIT_USER_ID/GIT_REPO_ID.git
```
(you may need to run `pip` with root permission: `sudo pip install git+https://github.com/GIT_USER_ID/GIT_REPO_ID.git`)
Then import the package:
```python
import zrok_api
```
### Setuptools
Install via [Setuptools](http://pypi.python.org/pypi/setuptools).
```sh
python setup.py install --user
```
(or `sudo python setup.py install` to install the package for all users)
Then import the package:
```python
import zrok_api
```
## Getting Started
Please follow the [installation procedure](#installation--usage) and then run the following:
```python
from __future__ import print_function
import time
import zrok_api
from zrok_api.rest import ApiException
from pprint import pprint
# Configure API key authorization: key
configuration = zrok_api.Configuration()
configuration.api_key['x-token'] = 'YOUR_API_KEY'
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['x-token'] = 'Bearer'
# create an instance of the API class
api_instance = zrok_api.AccountApi(zrok_api.ApiClient(configuration))
body = zrok_api.ChangePasswordBody() # ChangePasswordBody | (optional)
try:
api_instance.change_password(body=body)
except ApiException as e:
print("Exception when calling AccountApi->change_password: %s\n" % e)
# create an instance of the API class
api_instance = zrok_api.AccountApi(zrok_api.ApiClient(configuration))
body = zrok_api.InviteBody() # InviteBody | (optional)
try:
api_instance.invite(body=body)
except ApiException as e:
print("Exception when calling AccountApi->invite: %s\n" % e)
# create an instance of the API class
api_instance = zrok_api.AccountApi(zrok_api.ApiClient(configuration))
body = zrok_api.LoginBody() # LoginBody | (optional)
try:
api_response = api_instance.login(body=body)
pprint(api_response)
except ApiException as e:
print("Exception when calling AccountApi->login: %s\n" % e)
# Configure API key authorization: key
configuration = zrok_api.Configuration()
configuration.api_key['x-token'] = 'YOUR_API_KEY'
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['x-token'] = 'Bearer'
# create an instance of the API class
api_instance = zrok_api.AccountApi(zrok_api.ApiClient(configuration))
body = zrok_api.RegenerateAccountTokenBody() # RegenerateAccountTokenBody | (optional)
try:
api_response = api_instance.regenerate_account_token(body=body)
pprint(api_response)
except ApiException as e:
print("Exception when calling AccountApi->regenerate_account_token: %s\n" % e)
# create an instance of the API class
api_instance = zrok_api.AccountApi(zrok_api.ApiClient(configuration))
body = zrok_api.RegisterBody() # RegisterBody | (optional)
try:
api_response = api_instance.register(body=body)
pprint(api_response)
except ApiException as e:
print("Exception when calling AccountApi->register: %s\n" % e)
# create an instance of the API class
api_instance = zrok_api.AccountApi(zrok_api.ApiClient(configuration))
body = zrok_api.ResetPasswordBody() # ResetPasswordBody | (optional)
try:
api_instance.reset_password(body=body)
except ApiException as e:
print("Exception when calling AccountApi->reset_password: %s\n" % e)
# create an instance of the API class
api_instance = zrok_api.AccountApi(zrok_api.ApiClient(configuration))
body = zrok_api.ResetPasswordRequestBody() # ResetPasswordRequestBody | (optional)
try:
api_instance.reset_password_request(body=body)
except ApiException as e:
print("Exception when calling AccountApi->reset_password_request: %s\n" % e)
# create an instance of the API class
api_instance = zrok_api.AccountApi(zrok_api.ApiClient(configuration))
body = zrok_api.VerifyBody() # VerifyBody | (optional)
try:
api_response = api_instance.verify(body=body)
pprint(api_response)
except ApiException as e:
print("Exception when calling AccountApi->verify: %s\n" % e)
```
## Documentation for API Endpoints
All URIs are relative to */api/v1*
Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*AccountApi* | [**change_password**](docs/AccountApi.md#change_password) | **POST** /changePassword |
*AccountApi* | [**invite**](docs/AccountApi.md#invite) | **POST** /invite |
*AccountApi* | [**login**](docs/AccountApi.md#login) | **POST** /login |
*AccountApi* | [**regenerate_account_token**](docs/AccountApi.md#regenerate_account_token) | **POST** /regenerateAccountToken |
*AccountApi* | [**register**](docs/AccountApi.md#register) | **POST** /register |
*AccountApi* | [**reset_password**](docs/AccountApi.md#reset_password) | **POST** /resetPassword |
*AccountApi* | [**reset_password_request**](docs/AccountApi.md#reset_password_request) | **POST** /resetPasswordRequest |
*AccountApi* | [**verify**](docs/AccountApi.md#verify) | **POST** /verify |
*AdminApi* | [**add_organization_member**](docs/AdminApi.md#add_organization_member) | **POST** /organization/add |
*AdminApi* | [**create_account**](docs/AdminApi.md#create_account) | **POST** /account |
*AdminApi* | [**create_frontend**](docs/AdminApi.md#create_frontend) | **POST** /frontend |
*AdminApi* | [**create_identity**](docs/AdminApi.md#create_identity) | **POST** /identity |
*AdminApi* | [**create_organization**](docs/AdminApi.md#create_organization) | **POST** /organization |
*AdminApi* | [**delete_frontend**](docs/AdminApi.md#delete_frontend) | **DELETE** /frontend |
*AdminApi* | [**delete_organization**](docs/AdminApi.md#delete_organization) | **DELETE** /organization |
*AdminApi* | [**grants**](docs/AdminApi.md#grants) | **POST** /grants |
*AdminApi* | [**invite_token_generate**](docs/AdminApi.md#invite_token_generate) | **POST** /invite/token/generate |
*AdminApi* | [**list_frontends**](docs/AdminApi.md#list_frontends) | **GET** /frontends |
*AdminApi* | [**list_organization_members**](docs/AdminApi.md#list_organization_members) | **POST** /organization/list |
*AdminApi* | [**list_organizations**](docs/AdminApi.md#list_organizations) | **GET** /organizations |
*AdminApi* | [**remove_organization_member**](docs/AdminApi.md#remove_organization_member) | **POST** /organization/remove |
*AdminApi* | [**update_frontend**](docs/AdminApi.md#update_frontend) | **PATCH** /frontend |
*EnvironmentApi* | [**disable**](docs/EnvironmentApi.md#disable) | **POST** /disable |
*EnvironmentApi* | [**enable**](docs/EnvironmentApi.md#enable) | **POST** /enable |
*MetadataApi* | [**client_version_check**](docs/MetadataApi.md#client_version_check) | **POST** /clientVersionCheck |
*MetadataApi* | [**configuration**](docs/MetadataApi.md#configuration) | **GET** /configuration |
*MetadataApi* | [**get_account_detail**](docs/MetadataApi.md#get_account_detail) | **GET** /detail/account |
*MetadataApi* | [**get_account_metrics**](docs/MetadataApi.md#get_account_metrics) | **GET** /metrics/account |
*MetadataApi* | [**get_environment_detail**](docs/MetadataApi.md#get_environment_detail) | **GET** /detail/environment/{envZId} |
*MetadataApi* | [**get_environment_metrics**](docs/MetadataApi.md#get_environment_metrics) | **GET** /metrics/environment/{envId} |
*MetadataApi* | [**get_frontend_detail**](docs/MetadataApi.md#get_frontend_detail) | **GET** /detail/frontend/{frontendId} |
*MetadataApi* | [**get_share_detail**](docs/MetadataApi.md#get_share_detail) | **GET** /detail/share/{shareToken} |
*MetadataApi* | [**get_share_metrics**](docs/MetadataApi.md#get_share_metrics) | **GET** /metrics/share/{shareToken} |
*MetadataApi* | [**get_sparklines**](docs/MetadataApi.md#get_sparklines) | **POST** /sparklines |
*MetadataApi* | [**list_memberships**](docs/MetadataApi.md#list_memberships) | **GET** /memberships |
*MetadataApi* | [**list_org_members**](docs/MetadataApi.md#list_org_members) | **GET** /members/{organizationToken} |
*MetadataApi* | [**org_account_overview**](docs/MetadataApi.md#org_account_overview) | **GET** /overview/{organizationToken}/{accountEmail} |
*MetadataApi* | [**overview**](docs/MetadataApi.md#overview) | **GET** /overview |
*MetadataApi* | [**version**](docs/MetadataApi.md#version) | **GET** /version |
*MetadataApi* | [**version_inventory**](docs/MetadataApi.md#version_inventory) | **GET** /versions |
*ShareApi* | [**access**](docs/ShareApi.md#access) | **POST** /access |
*ShareApi* | [**share**](docs/ShareApi.md#share) | **POST** /share |
*ShareApi* | [**unaccess**](docs/ShareApi.md#unaccess) | **DELETE** /unaccess |
*ShareApi* | [**unshare**](docs/ShareApi.md#unshare) | **DELETE** /unshare |
*ShareApi* | [**update_access**](docs/ShareApi.md#update_access) | **PATCH** /access |
*ShareApi* | [**update_share**](docs/ShareApi.md#update_share) | **PATCH** /share |
## Documentation For Models
- [AccessBody](docs/AccessBody.md)
- [AccessBody1](docs/AccessBody1.md)
- [AccountBody](docs/AccountBody.md)
- [AuthUser](docs/AuthUser.md)
- [ChangePasswordBody](docs/ChangePasswordBody.md)
- [ClientVersionCheckBody](docs/ClientVersionCheckBody.md)
- [Configuration](docs/Configuration.md)
- [DisableBody](docs/DisableBody.md)
- [EnableBody](docs/EnableBody.md)
- [Environment](docs/Environment.md)
- [EnvironmentAndResources](docs/EnvironmentAndResources.md)
- [Environments](docs/Environments.md)
- [ErrorMessage](docs/ErrorMessage.md)
- [Frontend](docs/Frontend.md)
- [FrontendBody](docs/FrontendBody.md)
- [FrontendBody1](docs/FrontendBody1.md)
- [FrontendBody2](docs/FrontendBody2.md)
- [Frontends](docs/Frontends.md)
- [GrantsBody](docs/GrantsBody.md)
- [IdentityBody](docs/IdentityBody.md)
- [InlineResponse200](docs/InlineResponse200.md)
- [InlineResponse2001](docs/InlineResponse2001.md)
- [InlineResponse2002](docs/InlineResponse2002.md)
- [InlineResponse2003](docs/InlineResponse2003.md)
- [InlineResponse2003Members](docs/InlineResponse2003Members.md)
- [InlineResponse2004](docs/InlineResponse2004.md)
- [InlineResponse2004Organizations](docs/InlineResponse2004Organizations.md)
- [InlineResponse2005](docs/InlineResponse2005.md)
- [InlineResponse2005Memberships](docs/InlineResponse2005Memberships.md)
- [InlineResponse2006](docs/InlineResponse2006.md)
- [InlineResponse2007](docs/InlineResponse2007.md)
- [InlineResponse201](docs/InlineResponse201.md)
- [InlineResponse2011](docs/InlineResponse2011.md)
- [InlineResponse2012](docs/InlineResponse2012.md)
- [InlineResponse2013](docs/InlineResponse2013.md)
- [InviteBody](docs/InviteBody.md)
- [LoginBody](docs/LoginBody.md)
- [Metrics](docs/Metrics.md)
- [MetricsSample](docs/MetricsSample.md)
- [OrganizationAddBody](docs/OrganizationAddBody.md)
- [OrganizationBody](docs/OrganizationBody.md)
- [OrganizationBody1](docs/OrganizationBody1.md)
- [OrganizationListBody](docs/OrganizationListBody.md)
- [OrganizationRemoveBody](docs/OrganizationRemoveBody.md)
- [Overview](docs/Overview.md)
- [Principal](docs/Principal.md)
- [RegenerateAccountTokenBody](docs/RegenerateAccountTokenBody.md)
- [RegisterBody](docs/RegisterBody.md)
- [ResetPasswordBody](docs/ResetPasswordBody.md)
- [ResetPasswordRequestBody](docs/ResetPasswordRequestBody.md)
- [Share](docs/Share.md)
- [ShareBody](docs/ShareBody.md)
- [ShareRequest](docs/ShareRequest.md)
- [ShareResponse](docs/ShareResponse.md)
- [Shares](docs/Shares.md)
- [SparkData](docs/SparkData.md)
- [SparkDataSample](docs/SparkDataSample.md)
- [SparklinesBody](docs/SparklinesBody.md)
- [TokenGenerateBody](docs/TokenGenerateBody.md)
- [UnaccessBody](docs/UnaccessBody.md)
- [UnshareBody](docs/UnshareBody.md)
- [VerifyBody](docs/VerifyBody.md)
- [Version](docs/Version.md)
## Documentation For Authorization
## key
- **Type**: API key
- **API key parameter name**: x-token
- **Location**: HTTP header
## Author

View File

@ -12,7 +12,7 @@ VERSION = "1.0.0"
# prerequisite: setuptools # prerequisite: setuptools
# http://pypi.python.org/pypi/setuptools # http://pypi.python.org/pypi/setuptools
REQUIRES = ["urllib3 >= 1.15", "six >= 1.10", "certifi", "python-dateutil", "openziti >= 0.8.1"] REQUIRES = ["urllib3 >= 1.15", "six >= 1.10", "certifi", "python-dateutil", "openziti >= 1.0.0"]
setup( setup(
name=NAME, name=NAME,

View File

@ -1,5 +1,6 @@
from zrok.environment.root import Root from zrok.environment.root import Root
from zrok_api.models import AccessRequest, UnaccessRequest from zrok_api.models.access_request import AccessRequest
from zrok_api.models.unaccess_request import UnaccessRequest
from zrok_api.api import ShareApi from zrok_api.api import ShareApi
from zrok import model from zrok import model

View File

@ -7,8 +7,7 @@ import zrok_api as zrok
from zrok_api.configuration import Configuration from zrok_api.configuration import Configuration
import re import re
V = "v0.4" V = "v1.0"
@dataclass @dataclass
class Metadata: class Metadata:
@ -52,12 +51,7 @@ class Root:
cfg.api_key_prefix['Authorization'] = 'Bearer' cfg.api_key_prefix['Authorization'] = 'Bearer'
zrock_client = zrok.ApiClient(configuration=cfg) zrock_client = zrok.ApiClient(configuration=cfg)
v = zrok.MetadataApi(zrock_client).version() self.client_version_check(zrock_client) # Perform version check
# allow reported version string to be optionally prefixed with
# "refs/heads/" or "refs/tags/"
rxp = re.compile("^(refs/(heads|tags)/)?" + V)
if not rxp.match(v):
raise Exception("expected a '" + V + "' version, received: '" + v + "'")
return zrock_client return zrock_client
def ApiEndpoint(self) -> ApiEndpoint: def ApiEndpoint(self) -> ApiEndpoint:
@ -91,6 +85,22 @@ class Root:
def ZitiIdentityNamed(self, name: str) -> str: def ZitiIdentityNamed(self, name: str) -> str:
return identityFile(name) return identityFile(name)
def client_version_check(self, zrock_client):
"""Check if the client version is compatible with the API."""
metadata_api = zrok.MetadataApi(zrock_client)
try:
print(f"Sending client version: {V}") # Log the version being sent
data, status_code, headers = metadata_api.client_version_check_with_http_info(body={"clientVersion": V})
# Check if the response status code is 200 OK
if status_code != 200:
raise Exception(f"Client version check failed: Unexpected status code {status_code}")
# Success case - status code is 200 and empty response body is expected
return
except Exception as e:
raise Exception(f"Client version check failed: {str(e)}")
def Default() -> Root: def Default() -> Root:
r = Root() r = Root()

View File

@ -1,7 +1,9 @@
from zrok.environment.root import Root
from zrok_api.models import ShareRequest, UnshareRequest, AuthUser
from zrok_api.api import ShareApi
from zrok import model from zrok import model
from zrok_api.api import ShareApi
from zrok.environment.root import Root
from zrok_api.models.auth_user import AuthUser
from zrok_api.models.share_request import ShareRequest
from zrok_api.models.unshare_request import UnshareRequest
class Share(): class Share():
@ -58,7 +60,7 @@ def CreateShare(root: Root, request: model.ShareRequest) -> model.Share:
except Exception as e: except Exception as e:
raise Exception("unable to create share", e) raise Exception("unable to create share", e)
return model.Share(Token=res.shr_token, return model.Share(Token=res.share_token,
FrontendEndpoints=res.frontend_proxy_endpoints) FrontendEndpoints=res.frontend_proxy_endpoints)

View File

@ -111,7 +111,8 @@ class MetadataApi(object):
auth_settings = [] # noqa: E501 auth_settings = [] # noqa: E501
return self.api_client.call_api( return self.api_client.call_api(
'/clientVersionCheck', 'POST', # '/clientVersionCheck', 'POST',
'/version', 'POST',
path_params, path_params,
query_params, query_params,
header_params, header_params,