From 7545eeadb3f4fab253e63109b49a397dee92135a Mon Sep 17 00:00:00 2001 From: Kenneth Bingham Date: Thu, 27 Feb 2025 15:07:37 -0500 Subject: [PATCH] start adapting py sdk to v1.0 --- sdk/python/examples/pastebin/README.md | 2 +- sdk/python/examples/proxy/requirements.txt | 3 + sdk/python/sdk/zrok/.swagger-codegen-ignore | 2 +- sdk/python/sdk/zrok/README.md | 275 ++++++++++++++++++ sdk/python/sdk/zrok/setup.py | 2 +- sdk/python/sdk/zrok/zrok/access.py | 3 +- sdk/python/sdk/zrok/zrok/environment/root.py | 26 +- sdk/python/sdk/zrok/zrok/share.py | 10 +- .../sdk/zrok/zrok_api/api/metadata_api.py | 3 +- 9 files changed, 309 insertions(+), 17 deletions(-) create mode 100644 sdk/python/examples/proxy/requirements.txt create mode 100644 sdk/python/sdk/zrok/README.md diff --git a/sdk/python/examples/pastebin/README.md b/sdk/python/examples/pastebin/README.md index be016135..18cbef8d 100644 --- a/sdk/python/examples/pastebin/README.md +++ b/sdk/python/examples/pastebin/README.md @@ -4,7 +4,7 @@ This example shows the use of the zrok SDK spinning up a simple pastebin command ## 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 environment if you're self-hosting zrok. diff --git a/sdk/python/examples/proxy/requirements.txt b/sdk/python/examples/proxy/requirements.txt new file mode 100644 index 00000000..3db45633 --- /dev/null +++ b/sdk/python/examples/proxy/requirements.txt @@ -0,0 +1,3 @@ +flask +requests +waitress diff --git a/sdk/python/sdk/zrok/.swagger-codegen-ignore b/sdk/python/sdk/zrok/.swagger-codegen-ignore index cbe3e7fe..f86cf33f 100644 --- a/sdk/python/sdk/zrok/.swagger-codegen-ignore +++ b/sdk/python/sdk/zrok/.swagger-codegen-ignore @@ -29,4 +29,4 @@ test-requirements.txt test/ docs/ README.md -setup.py \ No newline at end of file +setup.py diff --git a/sdk/python/sdk/zrok/README.md b/sdk/python/sdk/zrok/README.md new file mode 100644 index 00000000..1ec5f374 --- /dev/null +++ b/sdk/python/sdk/zrok/README.md @@ -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 + + diff --git a/sdk/python/sdk/zrok/setup.py b/sdk/python/sdk/zrok/setup.py index 801f64a3..a58ce211 100644 --- a/sdk/python/sdk/zrok/setup.py +++ b/sdk/python/sdk/zrok/setup.py @@ -12,7 +12,7 @@ VERSION = "1.0.0" # prerequisite: 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( name=NAME, diff --git a/sdk/python/sdk/zrok/zrok/access.py b/sdk/python/sdk/zrok/zrok/access.py index dc3a1dfd..8c91e869 100644 --- a/sdk/python/sdk/zrok/zrok/access.py +++ b/sdk/python/sdk/zrok/zrok/access.py @@ -1,5 +1,6 @@ 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 import model diff --git a/sdk/python/sdk/zrok/zrok/environment/root.py b/sdk/python/sdk/zrok/zrok/environment/root.py index ad7ae6ef..5ce3026d 100644 --- a/sdk/python/sdk/zrok/zrok/environment/root.py +++ b/sdk/python/sdk/zrok/zrok/environment/root.py @@ -7,8 +7,7 @@ import zrok_api as zrok from zrok_api.configuration import Configuration import re -V = "v0.4" - +V = "v1.0" @dataclass class Metadata: @@ -52,12 +51,7 @@ class Root: cfg.api_key_prefix['Authorization'] = 'Bearer' zrock_client = zrok.ApiClient(configuration=cfg) - v = zrok.MetadataApi(zrock_client).version() - # 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 + "'") + self.client_version_check(zrock_client) # Perform version check return zrock_client def ApiEndpoint(self) -> ApiEndpoint: @@ -91,6 +85,22 @@ class Root: def ZitiIdentityNamed(self, name: str) -> str: 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: r = Root() diff --git a/sdk/python/sdk/zrok/zrok/share.py b/sdk/python/sdk/zrok/zrok/share.py index 918f5c6a..4b861bf4 100644 --- a/sdk/python/sdk/zrok/zrok/share.py +++ b/sdk/python/sdk/zrok/zrok/share.py @@ -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_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(): @@ -58,7 +60,7 @@ def CreateShare(root: Root, request: model.ShareRequest) -> model.Share: except Exception as 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) diff --git a/sdk/python/sdk/zrok/zrok_api/api/metadata_api.py b/sdk/python/sdk/zrok/zrok_api/api/metadata_api.py index a07654db..4b93eb04 100644 --- a/sdk/python/sdk/zrok/zrok_api/api/metadata_api.py +++ b/sdk/python/sdk/zrok/zrok_api/api/metadata_api.py @@ -111,7 +111,8 @@ class MetadataApi(object): auth_settings = [] # noqa: E501 return self.api_client.call_api( - '/clientVersionCheck', 'POST', + # '/clientVersionCheck', 'POST', + '/version', 'POST', path_params, query_params, header_params,