diff --git a/internal_auth/.gitattributes b/internal_auth/.gitattributes new file mode 100755 index 000000000..4d75d5900 --- /dev/null +++ b/internal_auth/.gitattributes @@ -0,0 +1,2 @@ +# This allows generated code to be indexed correctly +*.py linguist-generated=false \ No newline at end of file diff --git a/internal_auth/.gitignore b/internal_auth/.gitignore new file mode 100755 index 000000000..8ac3f51d4 --- /dev/null +++ b/internal_auth/.gitignore @@ -0,0 +1,7 @@ +.python-version +.DS_Store +venv/ +src/*.egg-info/ +__pycache__/ +.pytest_cache/ +.python-version` diff --git a/internal_auth/README.md b/internal_auth/README.md index 584d5443e..56ffd4ee1 100755 --- a/internal_auth/README.md +++ b/internal_auth/README.md @@ -12,27 +12,147 @@ pip install git+https://github.com/epilot-dev/sdk-python.git#subdirectory=intern ```python import epilot -from epilot.models import operations, shared +from epilot.models import shared -s = epilot.Epilot() +s = epilot.Epilot( + security=shared.Security( + sigv4="", + ), +) - -res = s.get_jwks() + +res = s.epilot.get_jwks() if res.get_jwks_200_application_json_object is not None: # handle response + pass ``` -## SDK Available Operations +## Available Resources and Operations -### Epilot SDK +### [Epilot SDK](docs/sdks/epilot/README.md) -* `get_jwks` - getJwks -* `get_open_id_configuration` - getOpenIDConfiguration -* `get_token` - getToken -* `get_token_v2` - getTokenV2 +* [get_jwks](docs/sdks/epilot/README.md#get_jwks) - getJwks +* [get_open_id_configuration](docs/sdks/epilot/README.md#get_open_id_configuration) - getOpenIDConfiguration +* [get_token](docs/sdks/epilot/README.md#get_token) - getToken +* [get_token_v2](docs/sdks/epilot/README.md#get_token_v2) - getTokenV2 + + + + + + + + + +# Pagination + +Some of the endpoints in this SDK support pagination. To use pagination, you make your SDK calls as usual, but the +returned response object will have a `Next` method that can be called to pull down the next group of results. If the +return value of `Next` is `None`, then there are no more pages to be fetched. + +Here's an example of one such pagination call: + + + + + +# Error Handling + +Handling errors in your SDK should largely match your expectations. All operations return a response object or raise an error. If Error objects are specified in your OpenAPI Spec, the SDK will raise the appropriate Error type. + + + + + + + +# Server Selection + +## Select Server by Index + +You can override the default server globally by passing a server index to the `server_idx: int` optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers: + +| # | Server | Variables | +| - | ------ | --------- | +| 0 | `https://internal-auth.sls.epilot.io/v1/internal-auth` | None | + +For example: + + +```python +import epilot +from epilot.models import shared + +s = epilot.Epilot( + security=shared.Security( + sigv4="", + ), + server_idx=0 +) + + +res = s.epilot.get_jwks() + +if res.get_jwks_200_application_json_object is not None: + # handle response + pass +``` + + +## Override Server URL Per-Client + +The default server can also be overridden globally by passing a URL to the `server_url: str` optional parameter when initializing the SDK client instance. For example: + + +```python +import epilot +from epilot.models import shared + +s = epilot.Epilot( + security=shared.Security( + sigv4="", + ), + server_url="https://internal-auth.sls.epilot.io/v1/internal-auth" +) + + +res = s.epilot.get_jwks() + +if res.get_jwks_200_application_json_object is not None: + # handle response + pass +``` + + + + + +# Custom HTTP Client + +The Python SDK makes API calls using the (requests)[https://pypi.org/project/requests/] HTTP library. In order to provide a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration, you can initialize the SDK client with a custom `requests.Session` object. + + +For example, you could specify a header for every request that your sdk makes as follows: + +```python +import epilot +import requests + +http_client = requests.Session() +http_client.headers.update({'x-custom-header': 'someValue'}) +s = epilot.Epilot(client: http_client) +``` + + + + + + + + ### SDK Generated by [Speakeasy](https://docs.speakeasyapi.dev/docs/using-speakeasy/client-sdks) diff --git a/internal_auth/RELEASES.md b/internal_auth/RELEASES.md index ee415d4d9..19a3dcb71 100644 --- a/internal_auth/RELEASES.md +++ b/internal_auth/RELEASES.md @@ -34,4 +34,550 @@ Based on: ### Changes Based on: - OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml -- Speakeasy CLI 1.19.2 (2.16.5) https://github.com/speakeasy-api/speakeasy \ No newline at end of file +- Speakeasy CLI 1.19.2 (2.16.5) https://github.com/speakeasy-api/speakeasy + +## 2023-04-01 00:37:58 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.19.3 (2.16.7) https://github.com/speakeasy-api/speakeasy + +## 2023-04-06 00:35:12 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.19.6 (2.17.8) https://github.com/speakeasy-api/speakeasy + +## 2023-04-12 00:36:02 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.19.7 (2.17.9) https://github.com/speakeasy-api/speakeasy + +## 2023-04-14 00:35:21 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.20.0 (2.18.0) https://github.com/speakeasy-api/speakeasy + +## 2023-04-18 00:35:48 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.20.1 (2.18.1) https://github.com/speakeasy-api/speakeasy + +## 2023-04-19 00:37:34 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.20.2 (2.18.2) https://github.com/speakeasy-api/speakeasy + +## 2023-04-21 00:35:45 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.21.4 (2.19.1) https://github.com/speakeasy-api/speakeasy + +## 2023-04-22 00:36:07 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.22.1 (2.20.1) https://github.com/speakeasy-api/speakeasy + +## 2023-04-26 00:36:42 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.23.1 (2.21.1) https://github.com/speakeasy-api/speakeasy + +## 2023-04-27 00:39:09 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.25.1 (2.22.0) https://github.com/speakeasy-api/speakeasy + +## 2023-04-28 00:37:33 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.26.2 (2.23.2) https://github.com/speakeasy-api/speakeasy + +## 2023-04-29 00:35:10 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.26.4 (2.23.4) https://github.com/speakeasy-api/speakeasy + +## 2023-05-02 00:36:43 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.26.5 (2.23.6) https://github.com/speakeasy-api/speakeasy + +## 2023-05-03 00:36:20 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.27.0 (2.24.0) https://github.com/speakeasy-api/speakeasy + +## 2023-05-05 00:33:45 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.29.0 (2.26.0) https://github.com/speakeasy-api/speakeasy + +## 2023-05-06 00:33:30 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.29.1 (2.26.1) https://github.com/speakeasy-api/speakeasy + +## 2023-05-10 00:36:13 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.29.2 (2.26.2) https://github.com/speakeasy-api/speakeasy + +## 2023-05-11 00:36:27 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.30.0 (2.26.3) https://github.com/speakeasy-api/speakeasy + +## 2023-05-12 00:36:00 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.30.1 (2.26.4) https://github.com/speakeasy-api/speakeasy + +## 2023-05-13 00:34:52 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.31.1 (2.27.0) https://github.com/speakeasy-api/speakeasy + +## 2023-05-16 00:36:53 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.32.0 (2.28.0) https://github.com/speakeasy-api/speakeasy + +## 2023-05-17 00:39:50 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.33.2 (2.29.0) https://github.com/speakeasy-api/speakeasy + +## 2023-05-18 00:36:45 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.34.0 (2.30.0) https://github.com/speakeasy-api/speakeasy + +## 2023-05-19 00:36:57 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.35.0 (2.31.0) https://github.com/speakeasy-api/speakeasy + +## 2023-05-23 00:37:54 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.37.5 (2.32.2) https://github.com/speakeasy-api/speakeasy + +## 2023-05-27 00:38:18 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.39.0 (2.32.7) https://github.com/speakeasy-api/speakeasy + +## 2023-06-01 00:52:15 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.40.2 (2.34.2) https://github.com/speakeasy-api/speakeasy + +## 2023-06-02 00:41:55 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.40.3 (2.34.7) https://github.com/speakeasy-api/speakeasy + +## 2023-06-03 00:41:12 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.43.0 (2.35.3) https://github.com/speakeasy-api/speakeasy + +## 2023-06-07 00:44:11 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.44.2 (2.35.9) https://github.com/speakeasy-api/speakeasy + +## 2023-06-08 00:42:22 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.45.0 (2.37.0) https://github.com/speakeasy-api/speakeasy + +## 2023-06-09 00:44:50 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.45.2 (2.37.2) https://github.com/speakeasy-api/speakeasy + +## 2023-06-10 00:39:34 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.47.0 (2.39.0) https://github.com/speakeasy-api/speakeasy + +## 2023-06-11 00:51:19 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.47.1 (2.39.2) https://github.com/speakeasy-api/speakeasy + +## 2023-06-14 00:40:00 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.47.3 (2.40.1) https://github.com/speakeasy-api/speakeasy + +## 2023-06-16 00:42:17 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.48.0 (2.41.1) https://github.com/speakeasy-api/speakeasy + +## 2023-06-20 00:39:41 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.49.0 (2.41.4) https://github.com/speakeasy-api/speakeasy + +## 2023-06-21 00:42:03 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.49.1 (2.41.5) https://github.com/speakeasy-api/speakeasy + +## 2023-06-23 00:45:41 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.50.1 (2.43.2) https://github.com/speakeasy-api/speakeasy + +## 2023-06-27 00:46:04 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.51.1 (2.50.2) https://github.com/speakeasy-api/speakeasy + +## 2023-06-29 00:45:32 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.51.3 (2.52.2) https://github.com/speakeasy-api/speakeasy + +## 2023-07-01 00:51:56 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.52.0 (2.55.0) https://github.com/speakeasy-api/speakeasy + +## 2023-07-06 00:48:57 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.52.2 (2.57.2) https://github.com/speakeasy-api/speakeasy + +## 2023-07-07 00:48:31 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.53.0 (2.58.0) https://github.com/speakeasy-api/speakeasy + +## 2023-07-08 00:46:34 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.53.1 (2.58.2) https://github.com/speakeasy-api/speakeasy + +## 2023-07-11 00:41:40 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.56.0 (2.61.0) https://github.com/speakeasy-api/speakeasy + +## 2023-07-12 00:47:48 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.56.3 (2.61.4) https://github.com/speakeasy-api/speakeasy + +## 2023-07-13 00:48:02 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.57.0 (2.62.1) https://github.com/speakeasy-api/speakeasy + +## 2023-07-14 00:47:14 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.59.0 (2.65.0) https://github.com/speakeasy-api/speakeasy + +## 2023-07-18 01:05:24 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.61.0 (2.70.0) https://github.com/speakeasy-api/speakeasy + +## 2023-07-19 01:11:50 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.62.1 (2.70.2) https://github.com/speakeasy-api/speakeasy + +## 2023-07-22 00:40:52 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.64.0 (2.71.0) https://github.com/speakeasy-api/speakeasy + +## 2023-07-26 00:39:45 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.65.0 (2.73.0) https://github.com/speakeasy-api/speakeasy + +## 2023-07-27 00:37:38 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.65.1 (2.73.1) https://github.com/speakeasy-api/speakeasy + +## 2023-07-28 00:37:55 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.65.2 (2.75.1) https://github.com/speakeasy-api/speakeasy + +## 2023-08-01 00:45:03 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.66.1 (2.75.2) https://github.com/speakeasy-api/speakeasy + +## 2023-08-03 00:39:41 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.68.1 (2.77.1) https://github.com/speakeasy-api/speakeasy + +## 2023-08-04 00:39:44 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.68.3 (2.81.1) https://github.com/speakeasy-api/speakeasy + +## 2023-08-08 00:38:01 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.69.1 (2.82.0) https://github.com/speakeasy-api/speakeasy + +## 2023-08-15 00:31:26 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.72.0 (2.84.1) https://github.com/speakeasy-api/speakeasy +### Generated +- [python v1.40.0] internal_auth + +## 2023-08-19 00:29:49 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.74.3 (2.86.6) https://github.com/speakeasy-api/speakeasy +### Generated +- [python v1.40.1] internal_auth + +## 2023-08-25 00:32:03 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.74.11 (2.87.1) https://github.com/speakeasy-api/speakeasy +### Generated +- [python v1.40.2] internal_auth + +## 2023-08-26 00:30:26 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.74.16 (2.88.2) https://github.com/speakeasy-api/speakeasy +### Generated +- [python v1.41.0] internal_auth + +## 2023-08-29 00:32:28 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.74.17 (2.88.5) https://github.com/speakeasy-api/speakeasy +### Generated +- [python v1.41.1] internal_auth + +## 2023-08-31 00:32:31 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.76.0 (2.89.1) https://github.com/speakeasy-api/speakeasy +### Generated +- [python v1.42.0] internal_auth + +## 2023-09-01 00:35:00 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.77.0 (2.91.2) https://github.com/speakeasy-api/speakeasy +### Generated +- [python v1.43.0] internal_auth + +## 2023-09-02 00:30:54 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.77.2 (2.93.0) https://github.com/speakeasy-api/speakeasy +### Generated +- [python v1.43.1] internal_auth + +## 2023-09-05 00:31:55 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.78.3 (2.96.3) https://github.com/speakeasy-api/speakeasy +### Generated +- [python v1.43.2] internal_auth + +## 2023-09-12 00:31:12 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.82.5 (2.108.3) https://github.com/speakeasy-api/speakeasy +### Generated +- [python v1.43.3] internal_auth + +## 2023-09-16 00:31:44 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.86.0 (2.115.2) https://github.com/speakeasy-api/speakeasy +### Generated +- [python v1.43.4] internal_auth + +## 2023-09-20 00:32:53 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.88.0 (2.118.1) https://github.com/speakeasy-api/speakeasy +### Generated +- [python v1.43.5] internal_auth + +## 2023-09-22 00:32:59 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.89.0 (2.125.1) https://github.com/speakeasy-api/speakeasy +### Generated +- [python v1.44.0] internal_auth + +## 2023-09-26 00:34:00 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.91.0 (2.129.1) https://github.com/speakeasy-api/speakeasy +### Generated +- [python v1.45.0] internal_auth + +## 2023-09-27 00:33:34 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.91.2 (2.131.1) https://github.com/speakeasy-api/speakeasy +### Generated +- [python v1.45.1] internal_auth + +## 2023-09-29 00:33:24 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.91.3 (2.139.1) https://github.com/speakeasy-api/speakeasy +### Generated +- [python v1.46.0] internal_auth + +## 2023-10-01 00:38:11 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.92.2 (2.142.2) https://github.com/speakeasy-api/speakeasy +### Generated +- [python v1.47.0] internal_auth + +## 2023-10-02 00:33:48 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.92.3 (2.143.2) https://github.com/speakeasy-api/speakeasy +### Generated +- [python v1.47.1] internal_auth + +## 2023-10-05 00:33:30 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.94.0 (2.147.0) https://github.com/speakeasy-api/speakeasy +### Generated +- [python v1.47.2] internal_auth + +## 2023-10-07 00:32:42 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.96.1 (2.150.0) https://github.com/speakeasy-api/speakeasy +### Generated +- [python v1.48.0] internal_auth + +## 2023-10-13 00:34:23 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.99.0 (2.154.1) https://github.com/speakeasy-api/speakeasy +### Generated +- [python v1.48.1] internal_auth + +## 2023-10-18 00:33:33 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.101.0 (2.161.0) https://github.com/speakeasy-api/speakeasy +### Generated +- [python v2.0.0] internal_auth + +## 2023-10-21 00:32:11 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.104.0 (2.169.0) https://github.com/speakeasy-api/speakeasy +### Generated +- [python v2.1.0] internal_auth + +## 2023-10-28 00:31:57 +### Changes +Based on: +- OpenAPI Doc 0.0.1 https://docs.api.epilot.io/internal-auth.yaml +- Speakeasy CLI 1.109.0 (2.173.0) https://github.com/speakeasy-api/speakeasy +### Generated +- [python v2.1.1] internal_auth \ No newline at end of file diff --git a/internal_auth/USAGE.md b/internal_auth/USAGE.md index 510d6bd4b..d7d392686 100755 --- a/internal_auth/USAGE.md +++ b/internal_auth/USAGE.md @@ -1,14 +1,21 @@ + + ```python import epilot -from epilot.models import operations, shared +from epilot.models import shared + +s = epilot.Epilot( + security=shared.Security( + sigv4="", + ), +) -s = epilot.Epilot() - -res = s.get_jwks() +res = s.epilot.get_jwks() if res.get_jwks_200_application_json_object is not None: # handle response + pass ``` \ No newline at end of file diff --git a/internal_auth/docs/models/operations/getjwks200applicationjson.md b/internal_auth/docs/models/operations/getjwks200applicationjson.md new file mode 100755 index 000000000..19b52ffdf --- /dev/null +++ b/internal_auth/docs/models/operations/getjwks200applicationjson.md @@ -0,0 +1,10 @@ +# GetJwks200ApplicationJSON + +Set of jwks + + +## Fields + +| Field | Type | Required | Description | +| ----------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | +| `keys` | List[[GetJwks200ApplicationJSONKeys](../../models/operations/getjwks200applicationjsonkeys.md)] | :heavy_minus_sign: | N/A | \ No newline at end of file diff --git a/internal_auth/docs/models/operations/getjwks200applicationjsonkeys.md b/internal_auth/docs/models/operations/getjwks200applicationjsonkeys.md new file mode 100755 index 000000000..768bcc2ff --- /dev/null +++ b/internal_auth/docs/models/operations/getjwks200applicationjsonkeys.md @@ -0,0 +1,13 @@ +# GetJwks200ApplicationJSONKeys + + +## Fields + +| Field | Type | Required | Description | Example | +| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| `alg` | *Optional[str]* | :heavy_minus_sign: | N/A | RS256 | +| `e` | *Optional[str]* | :heavy_minus_sign: | N/A | AQAB | +| `kid` | *Optional[str]* | :heavy_minus_sign: | N/A | tXWU5mPMbRPczpbQwi6vbhLF4GgF3wlMDSyqo7pfeiw= | +| `kty` | *Optional[str]* | :heavy_minus_sign: | N/A | RSA | +| `n` | *Optional[str]* | :heavy_minus_sign: | N/A | h_QDoCjZ8W_trtYXaP7_S22wf5r5Wd9XBLED78oT44bJjQXn8ddcFV8Hik65_4IYXVX_hTTU4zpxe3H8vx2j7-Zz3O59mYMp5S0MzODNEdf5Y_2o19eis0brmAJniixsNlQ9LlYkdrVamrgaxHu3ZpP_99zkfFybYeuYoQNzb3PyrT8xVnz_USs_nlFMHpGUxvvz7gfKPqxcLvgLJr4cwI9yzaSY9CD4qW181QVcnL_WzpQ8xx6AuhhHZQ1l_3GG4InTk8ahE7U2ZHVu8RrX6d01pMgc3piEcet9RgFLnhbTg3YIiKGoAbN42wJn_x3lgIAC42T9mbmTsHyUdS6nUQ | +| `use` | *Optional[str]* | :heavy_minus_sign: | N/A | sig | \ No newline at end of file diff --git a/internal_auth/docs/models/operations/getjwksresponse.md b/internal_auth/docs/models/operations/getjwksresponse.md new file mode 100755 index 000000000..577380e2b --- /dev/null +++ b/internal_auth/docs/models/operations/getjwksresponse.md @@ -0,0 +1,11 @@ +# GetJwksResponse + + +## Fields + +| Field | Type | Required | Description | +| ------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | +| `content_type` | *str* | :heavy_check_mark: | HTTP response content type for this operation | +| `status_code` | *int* | :heavy_check_mark: | HTTP response status code for this operation | +| `raw_response` | [requests.Response](https://requests.readthedocs.io/en/latest/api/#requests.Response) | :heavy_minus_sign: | Raw HTTP response; suitable for custom response parsing | +| `get_jwks_200_application_json_object` | [Optional[GetJwks200ApplicationJSON]](../../models/operations/getjwks200applicationjson.md) | :heavy_minus_sign: | Set of jwks | \ No newline at end of file diff --git a/internal_auth/docs/models/operations/getopenidconfiguration200applicationjson.md b/internal_auth/docs/models/operations/getopenidconfiguration200applicationjson.md new file mode 100755 index 000000000..de19735b2 --- /dev/null +++ b/internal_auth/docs/models/operations/getopenidconfiguration200applicationjson.md @@ -0,0 +1,11 @@ +# GetOpenIDConfiguration200ApplicationJSON + +OpenID Configuration + + +## Fields + +| Field | Type | Required | Description | Example | +| ---------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- | +| `issuer` | *Optional[str]* | :heavy_minus_sign: | N/A | https://h2d2syd0a4.execute-api.eu-central-1.amazonaws.com/dev/v1/internal-auth | +| `jwks_uri` | *Optional[str]* | :heavy_minus_sign: | N/A | https://h2d2syd0a4.execute-api.eu-central-1.amazonaws.com/dev/v1/internal-auth/.well-known/jwks.json | \ No newline at end of file diff --git a/internal_auth/docs/models/operations/getopenidconfigurationresponse.md b/internal_auth/docs/models/operations/getopenidconfigurationresponse.md new file mode 100755 index 000000000..dbf28ce87 --- /dev/null +++ b/internal_auth/docs/models/operations/getopenidconfigurationresponse.md @@ -0,0 +1,11 @@ +# GetOpenIDConfigurationResponse + + +## Fields + +| Field | Type | Required | Description | +| ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- | +| `content_type` | *str* | :heavy_check_mark: | HTTP response content type for this operation | +| `status_code` | *int* | :heavy_check_mark: | HTTP response status code for this operation | +| `raw_response` | [requests.Response](https://requests.readthedocs.io/en/latest/api/#requests.Response) | :heavy_minus_sign: | Raw HTTP response; suitable for custom response parsing | +| `get_open_id_configuration_200_application_json_object` | [Optional[GetOpenIDConfiguration200ApplicationJSON]](../../models/operations/getopenidconfiguration200applicationjson.md) | :heavy_minus_sign: | OpenID Configuration | \ No newline at end of file diff --git a/internal_auth/docs/models/operations/gettoken200applicationjson.md b/internal_auth/docs/models/operations/gettoken200applicationjson.md new file mode 100755 index 000000000..f1da9022c --- /dev/null +++ b/internal_auth/docs/models/operations/gettoken200applicationjson.md @@ -0,0 +1,10 @@ +# GetToken200ApplicationJSON + +JWT Token + + +## Fields + +| Field | Type | Required | Description | Example | +| -------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `token` | *Optional[str]* | :heavy_minus_sign: | JWT Token | eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0IiwibmFtZSI6IkhlbGxvIGVwaWxvdCIsImlhdCI6MTUxNjIzOTAyMn0.FhoeinGX4X3wh6K4KFJbdIJ3JAG12Ezi-s6BhT-ngK4 | \ No newline at end of file diff --git a/internal_auth/docs/models/operations/gettokenresponse.md b/internal_auth/docs/models/operations/gettokenresponse.md new file mode 100755 index 000000000..f6aaea6bf --- /dev/null +++ b/internal_auth/docs/models/operations/gettokenresponse.md @@ -0,0 +1,11 @@ +# GetTokenResponse + + +## Fields + +| Field | Type | Required | Description | +| --------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- | +| `content_type` | *str* | :heavy_check_mark: | HTTP response content type for this operation | +| `status_code` | *int* | :heavy_check_mark: | HTTP response status code for this operation | +| `raw_response` | [requests.Response](https://requests.readthedocs.io/en/latest/api/#requests.Response) | :heavy_minus_sign: | Raw HTTP response; suitable for custom response parsing | +| `get_token_200_application_json_object` | [Optional[GetToken200ApplicationJSON]](../../models/operations/gettoken200applicationjson.md) | :heavy_minus_sign: | JWT Token | \ No newline at end of file diff --git a/internal_auth/docs/models/operations/gettokenv2200applicationjson.md b/internal_auth/docs/models/operations/gettokenv2200applicationjson.md new file mode 100755 index 000000000..fc4b8c5a2 --- /dev/null +++ b/internal_auth/docs/models/operations/gettokenv2200applicationjson.md @@ -0,0 +1,10 @@ +# GetTokenV2200ApplicationJSON + +JWT Token + + +## Fields + +| Field | Type | Required | Description | Example | +| -------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `token` | *Optional[str]* | :heavy_minus_sign: | JWT Token | eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0IiwibmFtZSI6IkhlbGxvIGVwaWxvdCIsImlhdCI6MTUxNjIzOTAyMn0.FhoeinGX4X3wh6K4KFJbdIJ3JAG12Ezi-s6BhT-ngK4 | \ No newline at end of file diff --git a/internal_auth/docs/models/operations/gettokenv2response.md b/internal_auth/docs/models/operations/gettokenv2response.md new file mode 100755 index 000000000..fd54bb843 --- /dev/null +++ b/internal_auth/docs/models/operations/gettokenv2response.md @@ -0,0 +1,11 @@ +# GetTokenV2Response + + +## Fields + +| Field | Type | Required | Description | +| ------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- | +| `content_type` | *str* | :heavy_check_mark: | HTTP response content type for this operation | +| `status_code` | *int* | :heavy_check_mark: | HTTP response status code for this operation | +| `raw_response` | [requests.Response](https://requests.readthedocs.io/en/latest/api/#requests.Response) | :heavy_minus_sign: | Raw HTTP response; suitable for custom response parsing | +| `get_token_v2_200_application_json_object` | [Optional[GetTokenV2200ApplicationJSON]](../../models/operations/gettokenv2200applicationjson.md) | :heavy_minus_sign: | JWT Token | \ No newline at end of file diff --git a/internal_auth/docs/models/shared/authrequest.md b/internal_auth/docs/models/shared/authrequest.md new file mode 100755 index 000000000..ee14a7757 --- /dev/null +++ b/internal_auth/docs/models/shared/authrequest.md @@ -0,0 +1,10 @@ +# AuthRequest + + +## Fields + +| Field | Type | Required | Description | Example | +| ----------------------- | ----------------------- | ----------------------- | ----------------------- | ----------------------- | +| `additional_properties` | Dict[str, *Any*] | :heavy_minus_sign: | N/A | | +| `assume_roles` | List[*str*] | :heavy_minus_sign: | List of assumed roles | org_id:root | +| `org_id` | *Optional[str]* | :heavy_minus_sign: | Organization Id | 12345 | \ No newline at end of file diff --git a/internal_auth/docs/models/shared/security.md b/internal_auth/docs/models/shared/security.md new file mode 100755 index 000000000..90d24ac59 --- /dev/null +++ b/internal_auth/docs/models/shared/security.md @@ -0,0 +1,8 @@ +# Security + + +## Fields + +| Field | Type | Required | Description | Example | +| ------------------ | ------------------ | ------------------ | ------------------ | ------------------ | +| `sigv4` | *str* | :heavy_check_mark: | N/A | | \ No newline at end of file diff --git a/internal_auth/docs/sdks/epilot/README.md b/internal_auth/docs/sdks/epilot/README.md new file mode 100755 index 000000000..ff52c5a1e --- /dev/null +++ b/internal_auth/docs/sdks/epilot/README.md @@ -0,0 +1,215 @@ +# Epilot SDK + + +## Overview + +Internal Auth API: Auth API to provide JWT tokens for internal API access that work with the epilot custom authorizer. + +Converts AWS credentials into a JWT token with caller's ARN `callerIdentity` and list of `policies` granting access to API Gateway as claims. + + +### Available Operations + +* [get_jwks](#get_jwks) - getJwks +* [get_open_id_configuration](#get_open_id_configuration) - getOpenIDConfiguration +* [get_token](#get_token) - getToken +* [get_token_v2](#get_token_v2) - getTokenV2 + +## get_jwks + +Get jwks public key set to verify tokens generated by this API + +### Example Usage + +```python +import epilot +from epilot.models import shared + +s = epilot.Epilot( + security=shared.Security( + sigv4="", + ), +) + + +res = s.epilot.get_jwks() + +if res.get_jwks_200_application_json_object is not None: + # handle response + pass +``` + + +### Response + +**[operations.GetJwksResponse](../../models/operations/getjwksresponse.md)** + + +## get_open_id_configuration + +OpenID Connect configuration for internal auth as identity provider + +Note: This API is not a fully compliant OAuth2.0 / OIDC identity provider, but this endpoint is useful to +automate the process of verifying JWT tokens. + + +### Example Usage + +```python +import epilot +from epilot.models import shared + +s = epilot.Epilot( + security=shared.Security( + sigv4="", + ), +) + + +res = s.epilot.get_open_id_configuration() + +if res.get_open_id_configuration_200_application_json_object is not None: + # handle response + pass +``` + + +### Response + +**[operations.GetOpenIDConfigurationResponse](../../models/operations/getopenidconfigurationresponse.md)** + + +## get_token + +Generates token for internal API access + +Example JWT payload: + +```json +{ + "callerIdentity": "arn:aws:sts::912468240823:assumed-role/ep_prod_access_admin/awsmfa_20210225T193753", + "policies": [ + { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": "*", + "Resource": "*" + } + ] + } + ], + "iss": "https://internal-auth.sls.epilot.io/v1/internal-auth", + "iat": 1614278397, + "exp": 1614281997 +} +``` + + +### Example Usage + +```python +import epilot +from epilot.models import shared + +s = epilot.Epilot( + security=shared.Security( + sigv4="", + ), +) + + +res = s.epilot.get_token() + +if res.get_token_200_application_json_object is not None: + # handle response + pass +``` + + +### Response + +**[operations.GetTokenResponse](../../models/operations/gettokenresponse.md)** + + +## get_token_v2 + +Generates token for internal API access with internal roles + +Example JWT payload: + +```json +{ + "callerIdentity": "arn:aws:sts::912468240823:assumed-role/ep_prod_access_admin/awsmfa_20210225T193753", + "policies": [ + { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": "*", + "Resource": "*" + } + ] + } + ], + "assume_roles": ["org_id:note_role", "org_id:file_role"], + "org_id": "org_id", + "iss": "https://internal-auth.sls.epilot.io/v1/internal-auth", + "iat": 1614278397, + "exp": 1614281997 +} +``` + + +### Example Usage + +```python +import epilot +from epilot.models import shared + +s = epilot.Epilot( + security=shared.Security( + sigv4="", + ), +) + +req = shared.AuthRequest( + additional_properties={ + "key": 'string', + }, + assume_roles=[ + 'o', + 'r', + 'g', + '_', + 'i', + 'd', + ':', + 'r', + 'o', + 'o', + 't', + ], + org_id='12345', +) + +res = s.epilot.get_token_v2(req) + +if res.get_token_v2_200_application_json_object is not None: + # handle response + pass +``` + +### Parameters + +| Parameter | Type | Required | Description | +| -------------------------------------------------------- | -------------------------------------------------------- | -------------------------------------------------------- | -------------------------------------------------------- | +| `request` | [shared.AuthRequest](../../models/shared/authrequest.md) | :heavy_check_mark: | The request object to use for the request. | + + +### Response + +**[operations.GetTokenV2Response](../../models/operations/gettokenv2response.md)** + diff --git a/internal_auth/files.gen b/internal_auth/files.gen index 55b1bbddc..04255cf79 100755 --- a/internal_auth/files.gen +++ b/internal_auth/files.gen @@ -1,8 +1,10 @@ +src/epilot/sdkconfiguration.py src/epilot/sdk.py pylintrc setup.py src/epilot/__init__.py src/epilot/models/__init__.py +src/epilot/models/errors/sdkerror.py src/epilot/utils/__init__.py src/epilot/utils/retries.py src/epilot/utils/utils.py @@ -11,4 +13,21 @@ src/epilot/models/operations/getopenidconfiguration.py src/epilot/models/operations/gettoken.py src/epilot/models/operations/gettokenv2.py src/epilot/models/operations/__init__.py -USAGE.md \ No newline at end of file +src/epilot/models/shared/authrequest.py +src/epilot/models/shared/security.py +src/epilot/models/shared/__init__.py +src/epilot/models/errors/__init__.py +USAGE.md +docs/models/operations/getjwks200applicationjsonkeys.md +docs/models/operations/getjwks200applicationjson.md +docs/models/operations/getjwksresponse.md +docs/models/operations/getopenidconfiguration200applicationjson.md +docs/models/operations/getopenidconfigurationresponse.md +docs/models/operations/gettoken200applicationjson.md +docs/models/operations/gettokenresponse.md +docs/models/operations/gettokenv2200applicationjson.md +docs/models/operations/gettokenv2response.md +docs/models/shared/authrequest.md +docs/models/shared/security.md +docs/sdks/epilot/README.md +.gitattributes \ No newline at end of file diff --git a/internal_auth/gen.yaml b/internal_auth/gen.yaml index 97cad151e..9e308da85 100644 --- a/internal_auth/gen.yaml +++ b/internal_auth/gen.yaml @@ -2,15 +2,25 @@ configVersion: 1.0.0 management: docChecksum: 1f3c7839d6737ba543966ccb621fa732 docVersion: 0.0.1 - speakeasyVersion: 1.19.2 - generationVersion: 2.16.5 + speakeasyVersion: 1.109.0 + generationVersion: 2.173.0 generation: - telemetryEnabled: false + repoURL: https://github.com/epilot-dev/sdk-python.git sdkClassName: epilot - sdkFlattening: true singleTagPerOp: false + telemetryEnabled: false +features: + python: + additionalProperties: 0.1.0 + core: 3.3.1 + globalSecurity: 2.82.0 + globalServerURLs: 2.82.0 python: - version: 1.2.2 + version: 2.1.1 author: epilot description: Python Client SDK for Epilot + flattenGlobalSecurity: false + installationURL: https://github.com/epilot-dev/sdk-python.git#subdirectory=internal_auth + maxMethodParams: 0 packageName: epilot-internal-auth + repoSubDirectory: internal_auth diff --git a/internal_auth/pylintrc b/internal_auth/pylintrc index 1024ae5ab..894f2eff3 100755 --- a/internal_auth/pylintrc +++ b/internal_auth/pylintrc @@ -88,7 +88,7 @@ persistent=yes # Minimum Python version to use for version dependent checks. Will default to # the version used to run pylint. -py-version=3.9 +py-version=3.8 # Discover python modules and packages in the file system subtree. recursive=no @@ -116,20 +116,15 @@ argument-naming-style=snake_case #argument-rgx= # Naming style matching correct attribute names. -attr-naming-style=snake_case +#attr-naming-style=snake_case # Regular expression matching correct attribute names. Overrides attr-naming- # style. If left empty, attribute names will be checked with the set naming # style. -#attr-rgx= +attr-rgx=[^\W\d][^\W]*|__.*__$ # Bad variable names which should always be refused, separated by a comma. -bad-names=foo, - bar, - baz, - toto, - tutu, - tata +bad-names= # Bad variable names regexes, separated by a comma. If names match any regex, # they will always be refused @@ -440,7 +435,13 @@ disable=raw-checker-failed, trailing-newlines, too-many-public-methods, too-many-locals, - too-many-lines + too-many-lines, + using-constant-test, + too-many-statements, + cyclic-import, + too-many-nested-blocks, + too-many-boolean-expressions, + no-else-raise # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option @@ -621,7 +622,7 @@ additional-builtins= allow-global-unused-variables=yes # List of names allowed to shadow builtins -allowed-redefined-builtins= +allowed-redefined-builtins=id,object # List of strings which can identify a callback function by name. A callback # name must start or end with one of those strings. diff --git a/internal_auth/setup.py b/internal_auth/setup.py index 63658cf5a..ac0dfcf2c 100755 --- a/internal_auth/setup.py +++ b/internal_auth/setup.py @@ -10,30 +10,31 @@ setuptools.setup( name="epilot-internal-auth", - version="1.2.2", + version="2.1.1", author="epilot", description="Python Client SDK for Epilot", long_description=long_description, long_description_content_type="text/markdown", packages=setuptools.find_packages(where="src"), install_requires=[ - "certifi==2022.12.07", - "charset-normalizer==2.1.1", - "dataclasses-json-speakeasy==0.5.8", - "idna==3.3", - "marshmallow==3.17.1", - "marshmallow-enum==1.5.1", - "mypy-extensions==0.4.3", - "packaging==21.3", - "pyparsing==3.0.9", - "python-dateutil==2.8.2", - "requests==2.28.1", - "six==1.16.0", - "typing-inspect==0.8.0", - "typing_extensions==4.3.0", - "urllib3==1.26.12", - "pylint==2.16.2", + "certifi>=2023.7.22", + "charset-normalizer>=3.2.0", + "dataclasses-json>=0.6.1", + "idna>=3.4", + "jsonpath-python>=1.0.6 ", + "marshmallow>=3.19.0", + "mypy-extensions>=1.0.0", + "packaging>=23.1", + "python-dateutil>=2.8.2", + "requests>=2.31.0", + "six>=1.16.0", + "typing-inspect>=0.9.0", + "typing_extensions>=4.7.1", + "urllib3>=2.0.4", ], + extras_require={ + "dev":["pylint==2.16.2"] + }, package_dir={'': 'src'}, - python_requires='>=3.9' + python_requires='>=3.8' ) diff --git a/internal_auth/src/epilot/__init__.py b/internal_auth/src/epilot/__init__.py index b9e232018..e6c0deeb6 100755 --- a/internal_auth/src/epilot/__init__.py +++ b/internal_auth/src/epilot/__init__.py @@ -1,3 +1,4 @@ """Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.""" from .sdk import * +from .sdkconfiguration import * diff --git a/internal_auth/src/epilot/models/__init__.py b/internal_auth/src/epilot/models/__init__.py index 889f8adcf..36628d6cc 100755 --- a/internal_auth/src/epilot/models/__init__.py +++ b/internal_auth/src/epilot/models/__init__.py @@ -1,2 +1,3 @@ """Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.""" +# __init__.py diff --git a/internal_auth/src/epilot/models/errors/__init__.py b/internal_auth/src/epilot/models/errors/__init__.py new file mode 100755 index 000000000..cfd848441 --- /dev/null +++ b/internal_auth/src/epilot/models/errors/__init__.py @@ -0,0 +1,4 @@ +"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.""" + +from .sdkerror import SDKError +__all__ = ["SDKError"] diff --git a/internal_auth/src/epilot/models/errors/sdkerror.py b/internal_auth/src/epilot/models/errors/sdkerror.py new file mode 100755 index 000000000..6bb02bbd6 --- /dev/null +++ b/internal_auth/src/epilot/models/errors/sdkerror.py @@ -0,0 +1,24 @@ +"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.""" + +import requests as requests_http + + +class SDKError(Exception): + """Represents an error returned by the API.""" + message: str + status_code: int + body: str + raw_response: requests_http.Response + + def __init__(self, message: str, status_code: int, body: str, raw_response: requests_http.Response): + self.message = message + self.status_code = status_code + self.body = body + self.raw_response = raw_response + + def __str__(self): + body = '' + if len(self.body) > 0: + body = f'\n{self.body}' + + return f'{self.message}: Status {self.status_code}{body}' diff --git a/internal_auth/src/epilot/models/operations/__init__.py b/internal_auth/src/epilot/models/operations/__init__.py index 7a5793027..4445ca0e9 100755 --- a/internal_auth/src/epilot/models/operations/__init__.py +++ b/internal_auth/src/epilot/models/operations/__init__.py @@ -5,4 +5,4 @@ from .gettoken import * from .gettokenv2 import * -__all__ = ["GetJwks200ApplicationJSON","GetJwks200ApplicationJSONKeys","GetJwksResponse","GetOpenIDConfiguration200ApplicationJSON","GetOpenIDConfigurationResponse","GetToken200ApplicationJSON","GetTokenResponse","GetTokenSecurity","GetTokenV2200ApplicationJSON","GetTokenV2Response","GetTokenV2Security"] +__all__ = ["GetJwks200ApplicationJSON","GetJwks200ApplicationJSONKeys","GetJwksResponse","GetOpenIDConfiguration200ApplicationJSON","GetOpenIDConfigurationResponse","GetToken200ApplicationJSON","GetTokenResponse","GetTokenV2200ApplicationJSON","GetTokenV2Response"] diff --git a/internal_auth/src/epilot/models/operations/getjwks.py b/internal_auth/src/epilot/models/operations/getjwks.py index 6c983a376..5122f6d9b 100755 --- a/internal_auth/src/epilot/models/operations/getjwks.py +++ b/internal_auth/src/epilot/models/operations/getjwks.py @@ -5,35 +5,40 @@ import requests as requests_http from dataclasses_json import Undefined, dataclass_json from epilot import utils -from typing import Optional +from typing import List, Optional @dataclass_json(undefined=Undefined.EXCLUDE) @dataclasses.dataclass class GetJwks200ApplicationJSONKeys: + alg: Optional[str] = dataclasses.field(default=None, metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('alg'), 'exclude': lambda f: f is None }}) + e: Optional[str] = dataclasses.field(default=None, metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('e'), 'exclude': lambda f: f is None }}) + kid: Optional[str] = dataclasses.field(default=None, metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('kid'), 'exclude': lambda f: f is None }}) + kty: Optional[str] = dataclasses.field(default=None, metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('kty'), 'exclude': lambda f: f is None }}) + n: Optional[str] = dataclasses.field(default=None, metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('n'), 'exclude': lambda f: f is None }}) + use: Optional[str] = dataclasses.field(default=None, metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('use'), 'exclude': lambda f: f is None }}) - alg: Optional[str] = dataclasses.field(default=None, metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('alg'), 'exclude': lambda f: f is None }}) - e: Optional[str] = dataclasses.field(default=None, metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('e'), 'exclude': lambda f: f is None }}) - kid: Optional[str] = dataclasses.field(default=None, metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('kid'), 'exclude': lambda f: f is None }}) - kty: Optional[str] = dataclasses.field(default=None, metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('kty'), 'exclude': lambda f: f is None }}) - n: Optional[str] = dataclasses.field(default=None, metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('n'), 'exclude': lambda f: f is None }}) - use: Optional[str] = dataclasses.field(default=None, metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('use'), 'exclude': lambda f: f is None }}) - + + @dataclass_json(undefined=Undefined.EXCLUDE) @dataclasses.dataclass class GetJwks200ApplicationJSON: r"""Set of jwks""" + keys: Optional[List[GetJwks200ApplicationJSONKeys]] = dataclasses.field(default=None, metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('keys'), 'exclude': lambda f: f is None }}) - keys: Optional[list[GetJwks200ApplicationJSONKeys]] = dataclasses.field(default=None, metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('keys'), 'exclude': lambda f: f is None }}) - + + @dataclasses.dataclass class GetJwksResponse: - - content_type: str = dataclasses.field() - status_code: int = dataclasses.field() + content_type: str = dataclasses.field() + r"""HTTP response content type for this operation""" + status_code: int = dataclasses.field() + r"""HTTP response status code for this operation""" get_jwks_200_application_json_object: Optional[GetJwks200ApplicationJSON] = dataclasses.field(default=None) - r"""Set of jwks""" - raw_response: Optional[requests_http.Response] = dataclasses.field(default=None) - \ No newline at end of file + r"""Set of jwks""" + raw_response: Optional[requests_http.Response] = dataclasses.field(default=None) + r"""Raw HTTP response; suitable for custom response parsing""" + + diff --git a/internal_auth/src/epilot/models/operations/getopenidconfiguration.py b/internal_auth/src/epilot/models/operations/getopenidconfiguration.py index 60abb6e56..a014d20ac 100755 --- a/internal_auth/src/epilot/models/operations/getopenidconfiguration.py +++ b/internal_auth/src/epilot/models/operations/getopenidconfiguration.py @@ -12,17 +12,21 @@ @dataclasses.dataclass class GetOpenIDConfiguration200ApplicationJSON: r"""OpenID Configuration""" + issuer: Optional[str] = dataclasses.field(default=None, metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('issuer'), 'exclude': lambda f: f is None }}) + jwks_uri: Optional[str] = dataclasses.field(default=None, metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('jwks_uri'), 'exclude': lambda f: f is None }}) - issuer: Optional[str] = dataclasses.field(default=None, metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('issuer'), 'exclude': lambda f: f is None }}) - jwks_uri: Optional[str] = dataclasses.field(default=None, metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('jwks_uri'), 'exclude': lambda f: f is None }}) - + + @dataclasses.dataclass class GetOpenIDConfigurationResponse: - - content_type: str = dataclasses.field() - status_code: int = dataclasses.field() + content_type: str = dataclasses.field() + r"""HTTP response content type for this operation""" + status_code: int = dataclasses.field() + r"""HTTP response status code for this operation""" get_open_id_configuration_200_application_json_object: Optional[GetOpenIDConfiguration200ApplicationJSON] = dataclasses.field(default=None) - r"""OpenID Configuration""" - raw_response: Optional[requests_http.Response] = dataclasses.field(default=None) - \ No newline at end of file + r"""OpenID Configuration""" + raw_response: Optional[requests_http.Response] = dataclasses.field(default=None) + r"""Raw HTTP response; suitable for custom response parsing""" + + diff --git a/internal_auth/src/epilot/models/operations/gettoken.py b/internal_auth/src/epilot/models/operations/gettoken.py index 3e53739d6..14a672146 100755 --- a/internal_auth/src/epilot/models/operations/gettoken.py +++ b/internal_auth/src/epilot/models/operations/gettoken.py @@ -8,27 +8,25 @@ from typing import Optional -@dataclasses.dataclass -class GetTokenSecurity: - - sigv4: str = dataclasses.field(metadata={'security': { 'scheme': True, 'type': 'apiKey', 'sub_type': 'header', 'field_name': 'Authorization' }}) - - @dataclass_json(undefined=Undefined.EXCLUDE) @dataclasses.dataclass class GetToken200ApplicationJSON: r"""JWT Token""" - token: Optional[str] = dataclasses.field(default=None, metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('token'), 'exclude': lambda f: f is None }}) - r"""JWT Token""" + r"""JWT Token""" + + @dataclasses.dataclass class GetTokenResponse: - - content_type: str = dataclasses.field() - status_code: int = dataclasses.field() + content_type: str = dataclasses.field() + r"""HTTP response content type for this operation""" + status_code: int = dataclasses.field() + r"""HTTP response status code for this operation""" get_token_200_application_json_object: Optional[GetToken200ApplicationJSON] = dataclasses.field(default=None) - r"""JWT Token""" - raw_response: Optional[requests_http.Response] = dataclasses.field(default=None) - \ No newline at end of file + r"""JWT Token""" + raw_response: Optional[requests_http.Response] = dataclasses.field(default=None) + r"""Raw HTTP response; suitable for custom response parsing""" + + diff --git a/internal_auth/src/epilot/models/operations/gettokenv2.py b/internal_auth/src/epilot/models/operations/gettokenv2.py index 0a6409dd6..dc45caa94 100755 --- a/internal_auth/src/epilot/models/operations/gettokenv2.py +++ b/internal_auth/src/epilot/models/operations/gettokenv2.py @@ -8,27 +8,25 @@ from typing import Optional -@dataclasses.dataclass -class GetTokenV2Security: - - sigv4: str = dataclasses.field(metadata={'security': { 'scheme': True, 'type': 'apiKey', 'sub_type': 'header', 'field_name': 'Authorization' }}) - - @dataclass_json(undefined=Undefined.EXCLUDE) @dataclasses.dataclass class GetTokenV2200ApplicationJSON: r"""JWT Token""" - token: Optional[str] = dataclasses.field(default=None, metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('token'), 'exclude': lambda f: f is None }}) - r"""JWT Token""" + r"""JWT Token""" + + @dataclasses.dataclass class GetTokenV2Response: - - content_type: str = dataclasses.field() - status_code: int = dataclasses.field() + content_type: str = dataclasses.field() + r"""HTTP response content type for this operation""" + status_code: int = dataclasses.field() + r"""HTTP response status code for this operation""" get_token_v2_200_application_json_object: Optional[GetTokenV2200ApplicationJSON] = dataclasses.field(default=None) - r"""JWT Token""" - raw_response: Optional[requests_http.Response] = dataclasses.field(default=None) - \ No newline at end of file + r"""JWT Token""" + raw_response: Optional[requests_http.Response] = dataclasses.field(default=None) + r"""Raw HTTP response; suitable for custom response parsing""" + + diff --git a/internal_auth/src/epilot/models/shared/__init__.py b/internal_auth/src/epilot/models/shared/__init__.py new file mode 100755 index 000000000..6c0f0e55f --- /dev/null +++ b/internal_auth/src/epilot/models/shared/__init__.py @@ -0,0 +1,6 @@ +"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.""" + +from .authrequest import * +from .security import * + +__all__ = ["AuthRequest","Security"] diff --git a/internal_auth/src/epilot/models/shared/authrequest.py b/internal_auth/src/epilot/models/shared/authrequest.py new file mode 100755 index 000000000..ce0a8a185 --- /dev/null +++ b/internal_auth/src/epilot/models/shared/authrequest.py @@ -0,0 +1,19 @@ +"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.""" + +from __future__ import annotations +import dataclasses +from dataclasses_json import Undefined, dataclass_json +from epilot import utils +from typing import Any, Dict, List, Optional + + +@dataclass_json(undefined=Undefined.EXCLUDE) +@dataclasses.dataclass +class AuthRequest: + additional_properties: Optional[Dict[str, Any]] = dataclasses.field(default=None, metadata={'dataclasses_json': { 'exclude': lambda f: f is None }}) + assume_roles: Optional[List[str]] = dataclasses.field(default=None, metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('assume_roles'), 'exclude': lambda f: f is None }}) + r"""List of assumed roles""" + org_id: Optional[str] = dataclasses.field(default=None, metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('org_id'), 'exclude': lambda f: f is None }}) + r"""Organization Id""" + + diff --git a/internal_auth/src/epilot/models/shared/security.py b/internal_auth/src/epilot/models/shared/security.py new file mode 100755 index 000000000..3ba908148 --- /dev/null +++ b/internal_auth/src/epilot/models/shared/security.py @@ -0,0 +1,11 @@ +"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.""" + +from __future__ import annotations +import dataclasses + + +@dataclasses.dataclass +class Security: + sigv4: str = dataclasses.field(metadata={'security': { 'scheme': True, 'type': 'apiKey', 'sub_type': 'header', 'field_name': 'Authorization' }}) + + diff --git a/internal_auth/src/epilot/sdk.py b/internal_auth/src/epilot/sdk.py index 1b4294064..86ed05e1a 100755 --- a/internal_auth/src/epilot/sdk.py +++ b/internal_auth/src/epilot/sdk.py @@ -1,73 +1,73 @@ """Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.""" import requests as requests_http -from . import utils -from epilot.models import operations -from typing import Any, Optional - -SERVERS = [ - "https://internal-auth.sls.epilot.io/v1/internal-auth", -] -"""Contains the list of servers available to the SDK""" +from .sdkconfiguration import SDKConfiguration +from epilot import utils +from epilot.models import errors, operations, shared +from typing import Dict, Optional class Epilot: - r"""Auth API to provide JWT tokens for internal API access that work with the epilot custom authorizer. - + r"""Internal Auth API: Auth API to provide JWT tokens for internal API access that work with the epilot custom authorizer. + Converts AWS credentials into a JWT token with caller's ARN `callerIdentity` and list of `policies` granting access to API Gateway as claims. - """ - _client: requests_http.Session - _security_client: requests_http.Session - _server_url: str = SERVERS[0] - _language: str = "python" - _sdk_version: str = "1.2.2" - _gen_version: str = "2.16.5" + sdk_configuration: SDKConfiguration def __init__(self, + security: shared.Security = None, + server_idx: int = None, server_url: str = None, - url_params: dict[str, str] = None, - client: requests_http.Session = None + url_params: Dict[str, str] = None, + client: requests_http.Session = None, + retry_config: utils.RetryConfig = None ) -> None: """Instantiates the SDK configuring it with the provided parameters. + :param security: The security details required for authentication + :type security: shared.Security + :param server_idx: The index of the server to use for all operations + :type server_idx: int :param server_url: The server URL to use for all operations :type server_url: str :param url_params: Parameters to optionally template the server URL with - :type url_params: dict[str, str] + :type url_params: Dict[str, str] :param client: The requests.Session HTTP client to use for all operations - :type client: requests_http.Session + :type client: requests_http.Session + :param retry_config: The utils.RetryConfig to use globally + :type retry_config: utils.RetryConfig """ - self._client = requests_http.Session() + if client is None: + client = requests_http.Session() - if server_url is not None: - if url_params is not None: - self._server_url = utils.template_url(server_url, url_params) - else: - self._server_url = server_url - - if client is not None: - self._client = client + security_client = utils.configure_security_client(client, security) - self._security_client = self._client + if server_url is not None: + if url_params is not None: + server_url = utils.template_url(server_url, url_params) + self.sdk_configuration = SDKConfiguration(client, security_client, server_url, server_idx, retry_config=retry_config) + + def get_jwks(self) -> operations.GetJwksResponse: r"""getJwks Get jwks public key set to verify tokens generated by this API """ - base_url = self._server_url - - url = base_url.removesuffix('/') + '/.well-known/jwks.json' + base_url = utils.template_url(*self.sdk_configuration.get_server_details()) + url = base_url + '/.well-known/jwks.json' + headers = {} + headers['Accept'] = 'application/json' + headers['user-agent'] = self.sdk_configuration.user_agent - client = self._client + client = self.sdk_configuration.security_client - http_res = client.request('GET', url) + http_res = client.request('GET', url, headers=headers) content_type = http_res.headers.get('Content-Type') res = operations.GetJwksResponse(status_code=http_res.status_code, content_type=content_type, raw_response=http_res) @@ -76,25 +76,29 @@ def get_jwks(self) -> operations.GetJwksResponse: if utils.match_content_type(content_type, 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[operations.GetJwks200ApplicationJSON]) res.get_jwks_200_application_json_object = out + else: + raise errors.SDKError(f'unknown content-type received: {content_type}', http_res.status_code, http_res.text, http_res) return res + def get_open_id_configuration(self) -> operations.GetOpenIDConfigurationResponse: r"""getOpenIDConfiguration OpenID Connect configuration for internal auth as identity provider - + Note: This API is not a fully compliant OAuth2.0 / OIDC identity provider, but this endpoint is useful to automate the process of verifying JWT tokens. - """ - base_url = self._server_url - - url = base_url.removesuffix('/') + '/.well-known/openid-configuration' + base_url = utils.template_url(*self.sdk_configuration.get_server_details()) + url = base_url + '/.well-known/openid-configuration' + headers = {} + headers['Accept'] = 'application/json' + headers['user-agent'] = self.sdk_configuration.user_agent - client = self._client + client = self.sdk_configuration.security_client - http_res = client.request('GET', url) + http_res = client.request('GET', url, headers=headers) content_type = http_res.headers.get('Content-Type') res = operations.GetOpenIDConfigurationResponse(status_code=http_res.status_code, content_type=content_type, raw_response=http_res) @@ -103,15 +107,18 @@ def get_open_id_configuration(self) -> operations.GetOpenIDConfigurationResponse if utils.match_content_type(content_type, 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[operations.GetOpenIDConfiguration200ApplicationJSON]) res.get_open_id_configuration_200_application_json_object = out + else: + raise errors.SDKError(f'unknown content-type received: {content_type}', http_res.status_code, http_res.text, http_res) return res - def get_token(self, security: operations.GetTokenSecurity) -> operations.GetTokenResponse: + + def get_token(self) -> operations.GetTokenResponse: r"""getToken Generates token for internal API access - + Example JWT payload: - + ```json { \"callerIdentity\": \"arn:aws:sts::912468240823:assumed-role/ep_prod_access_admin/awsmfa_20210225T193753\", @@ -132,16 +139,17 @@ def get_token(self, security: operations.GetTokenSecurity) -> operations.GetToke \"exp\": 1614281997 } ``` - """ - base_url = self._server_url - - url = base_url.removesuffix('/') + '/auth' + base_url = utils.template_url(*self.sdk_configuration.get_server_details()) + url = base_url + '/auth' + headers = {} + headers['Accept'] = 'application/json' + headers['user-agent'] = self.sdk_configuration.user_agent - client = utils.configure_security_client(self._client, security) + client = self.sdk_configuration.security_client - http_res = client.request('GET', url) + http_res = client.request('GET', url, headers=headers) content_type = http_res.headers.get('Content-Type') res = operations.GetTokenResponse(status_code=http_res.status_code, content_type=content_type, raw_response=http_res) @@ -150,15 +158,18 @@ def get_token(self, security: operations.GetTokenSecurity) -> operations.GetToke if utils.match_content_type(content_type, 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[operations.GetToken200ApplicationJSON]) res.get_token_200_application_json_object = out + else: + raise errors.SDKError(f'unknown content-type received: {content_type}', http_res.status_code, http_res.text, http_res) return res - def get_token_v2(self, request: dict[str, Any], security: operations.GetTokenV2Security) -> operations.GetTokenV2Response: + + def get_token_v2(self, request: shared.AuthRequest) -> operations.GetTokenV2Response: r"""getTokenV2 Generates token for internal API access with internal roles - + Example JWT payload: - + ```json { \"callerIdentity\": \"arn:aws:sts::912468240823:assumed-role/ep_prod_access_admin/awsmfa_20210225T193753\", @@ -181,18 +192,18 @@ def get_token_v2(self, request: dict[str, Any], security: operations.GetTokenV2S \"exp\": 1614281997 } ``` - """ - base_url = self._server_url - - url = base_url.removesuffix('/') + '/auth' + base_url = utils.template_url(*self.sdk_configuration.get_server_details()) + url = base_url + '/auth' headers = {} - req_content_type, data, form = utils.serialize_request_body(request, "request", 'json') + req_content_type, data, form = utils.serialize_request_body(request, "request", False, True, 'json') if req_content_type not in ('multipart/form-data', 'multipart/mixed'): headers['content-type'] = req_content_type + headers['Accept'] = 'application/json' + headers['user-agent'] = self.sdk_configuration.user_agent - client = utils.configure_security_client(self._client, security) + client = self.sdk_configuration.security_client http_res = client.request('POST', url, data=data, files=form, headers=headers) content_type = http_res.headers.get('Content-Type') @@ -203,6 +214,8 @@ def get_token_v2(self, request: dict[str, Any], security: operations.GetTokenV2S if utils.match_content_type(content_type, 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[operations.GetTokenV2200ApplicationJSON]) res.get_token_v2_200_application_json_object = out + else: + raise errors.SDKError(f'unknown content-type received: {content_type}', http_res.status_code, http_res.text, http_res) return res diff --git a/internal_auth/src/epilot/sdkconfiguration.py b/internal_auth/src/epilot/sdkconfiguration.py new file mode 100755 index 000000000..adc02bada --- /dev/null +++ b/internal_auth/src/epilot/sdkconfiguration.py @@ -0,0 +1,34 @@ +"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.""" + +import requests +from dataclasses import dataclass +from typing import Dict, Tuple +from .utils.retries import RetryConfig +from .utils import utils + + +SERVERS = [ + 'https://internal-auth.sls.epilot.io/v1/internal-auth', +] +"""Contains the list of servers available to the SDK""" + +@dataclass +class SDKConfiguration: + client: requests.Session + security_client: requests.Session + server_url: str = '' + server_idx: int = 0 + language: str = 'python' + openapi_doc_version: str = '0.0.1' + sdk_version: str = '2.1.1' + gen_version: str = '2.173.0' + user_agent: str = 'speakeasy-sdk/python 2.1.1 2.173.0 0.0.1 epilot-internal-auth' + retry_config: RetryConfig = None + + def get_server_details(self) -> Tuple[str, Dict[str, str]]: + if self.server_url: + return utils.remove_suffix(self.server_url, '/'), {} + if self.server_idx is None: + self.server_idx = 0 + + return SERVERS[self.server_idx], {} diff --git a/internal_auth/src/epilot/utils/retries.py b/internal_auth/src/epilot/utils/retries.py index c6251d948..25f49a1f2 100755 --- a/internal_auth/src/epilot/utils/retries.py +++ b/internal_auth/src/epilot/utils/retries.py @@ -2,6 +2,7 @@ import random import time +from typing import List import requests @@ -24,16 +25,17 @@ class RetryConfig: backoff: BackoffStrategy retry_connection_errors: bool - def __init__(self, strategy: str, retry_connection_errors: bool): + def __init__(self, strategy: str, backoff: BackoffStrategy, retry_connection_errors: bool): self.strategy = strategy + self.backoff = backoff self.retry_connection_errors = retry_connection_errors class Retries: config: RetryConfig - status_codes: list[str] + status_codes: List[str] - def __init__(self, config: RetryConfig, status_codes: list[str]): + def __init__(self, config: RetryConfig, status_codes: List[str]): self.config = config self.status_codes = status_codes diff --git a/internal_auth/src/epilot/utils/utils.py b/internal_auth/src/epilot/utils/utils.py index 9d4fba324..3ab126104 100755 --- a/internal_auth/src/epilot/utils/utils.py +++ b/internal_auth/src/epilot/utils/utils.py @@ -3,11 +3,14 @@ import base64 import json import re +import sys from dataclasses import Field, dataclass, fields, is_dataclass, make_dataclass from datetime import date, datetime +from decimal import Decimal from email.message import Message from enum import Enum -from typing import Any, Callable, Optional, Tuple, Union, get_args, get_origin +from typing import (Any, Callable, Dict, List, Optional, Tuple, Union, + get_args, get_origin) from xmlrpc.client import boolean import dateutil.parser @@ -17,14 +20,14 @@ class SecurityClient: client: requests.Session - query_params: dict[str, str] = {} + query_params: Dict[str, str] = {} def __init__(self, client: requests.Session): self.client = client def request(self, method, url, **kwargs): params = kwargs.get('params', {}) - kwargs["params"] = self.query_params | params + kwargs["params"] = {**self.query_params, **params} return self.client.request(method, url, **kwargs) @@ -67,7 +70,7 @@ def _parse_security_option(client: SecurityClient, option: dataclass): client, metadata, getattr(option, opt_field.name)) -def _parse_security_scheme(client: SecurityClient, scheme_metadata: dict, scheme: any): +def _parse_security_scheme(client: SecurityClient, scheme_metadata: Dict, scheme: any): scheme_type = scheme_metadata.get('type') sub_type = scheme_metadata.get('sub_type') @@ -91,7 +94,7 @@ def _parse_security_scheme(client: SecurityClient, scheme_metadata: dict, scheme client, scheme_metadata, scheme_metadata, scheme) -def _parse_security_scheme_value(client: SecurityClient, scheme_metadata: dict, security_metadata: dict, value: any): +def _parse_security_scheme_value(client: SecurityClient, scheme_metadata: Dict, security_metadata: Dict, value: any): scheme_type = scheme_metadata.get('type') sub_type = scheme_metadata.get('sub_type') @@ -112,7 +115,8 @@ def _parse_security_scheme_value(client: SecurityClient, scheme_metadata: dict, client.client.headers[header_name] = value elif scheme_type == 'http': if sub_type == 'bearer': - client.client.headers[header_name] = value + client.client.headers[header_name] = value.lower().startswith( + 'bearer ') and value or f'Bearer {value}' else: raise Exception('not supported') else: @@ -141,7 +145,8 @@ def _parse_basic_auth_scheme(client: SecurityClient, scheme: dataclass): client.client.headers['Authorization'] = f'Basic {base64.b64encode(data).decode()}' -def generate_url(clazz: type, server_url: str, path: str, path_params: dataclass, gbls: dict[str, dict[str, dict[str, Any]]] = None) -> str: +def generate_url(clazz: type, server_url: str, path: str, path_params: dataclass, + gbls: Dict[str, Dict[str, Dict[str, Any]]] = None) -> str: path_param_fields: Tuple[Field, ...] = fields(clazz) for field in path_param_fields: request_metadata = field.metadata.get('request') @@ -152,71 +157,80 @@ def generate_url(clazz: type, server_url: str, path: str, path_params: dataclass if param_metadata is None: continue - if param_metadata.get('style', 'simple') == 'simple': - param = getattr( - path_params, field.name) if path_params is not None else None - param = _populate_from_globals( - field.name, param, 'pathParam', gbls) - - if param is None: - continue - - if isinstance(param, list): - pp_vals: list[str] = [] - for pp_val in param: - if pp_val is None: - continue - pp_vals.append(_val_to_string(pp_val)) - path = path.replace( - '{' + param_metadata.get('field_name', field.name) + '}', ",".join(pp_vals), 1) - elif isinstance(param, dict): - pp_vals: list[str] = [] - for pp_key in param: - if param[pp_key] is None: - continue - if param_metadata.get('explode'): - pp_vals.append( - f"{pp_key}={_val_to_string(param[pp_key])}") - else: - pp_vals.append( - f"{pp_key},{_val_to_string(param[pp_key])}") - path = path.replace( - '{' + param_metadata.get('field_name', field.name) + '}', ",".join(pp_vals), 1) - elif not isinstance(param, (str, int, float, complex, bool)): - pp_vals: list[str] = [] - param_fields: Tuple[Field, ...] = fields(param) - for param_field in param_fields: - param_value_metadata = param_field.metadata.get( - 'path_param') - if not param_value_metadata: - continue + param = getattr( + path_params, field.name) if path_params is not None else None + param = _populate_from_globals( + field.name, param, 'pathParam', gbls) - parm_name = param_value_metadata.get( - 'field_name', field.name) + if param is None: + continue - param_field_val = getattr(param, param_field.name) - if param_field_val is None: - continue - if param_metadata.get('explode'): - pp_vals.append( - f"{parm_name}={_val_to_string(param_field_val)}") - else: - pp_vals.append( - f"{parm_name},{_val_to_string(param_field_val)}") - path = path.replace( - '{' + param_metadata.get('field_name', field.name) + '}', ",".join(pp_vals), 1) - else: + f_name = param_metadata.get("field_name", field.name) + serialization = param_metadata.get('serialization', '') + if serialization != '': + serialized_params = _get_serialized_params( + param_metadata, f_name, param) + for key, value in serialized_params.items(): path = path.replace( - '{' + param_metadata.get('field_name', field.name) + '}', _val_to_string(param), 1) + '{' + key + '}', value, 1) + else: + if param_metadata.get('style', 'simple') == 'simple': + if isinstance(param, List): + pp_vals: List[str] = [] + for pp_val in param: + if pp_val is None: + continue + pp_vals.append(_val_to_string(pp_val)) + path = path.replace( + '{' + param_metadata.get('field_name', field.name) + '}', ",".join(pp_vals), 1) + elif isinstance(param, Dict): + pp_vals: List[str] = [] + for pp_key in param: + if param[pp_key] is None: + continue + if param_metadata.get('explode'): + pp_vals.append( + f"{pp_key}={_val_to_string(param[pp_key])}") + else: + pp_vals.append( + f"{pp_key},{_val_to_string(param[pp_key])}") + path = path.replace( + '{' + param_metadata.get('field_name', field.name) + '}', ",".join(pp_vals), 1) + elif not isinstance(param, (str, int, float, complex, bool, Decimal)): + pp_vals: List[str] = [] + param_fields: Tuple[Field, ...] = fields(param) + for param_field in param_fields: + param_value_metadata = param_field.metadata.get( + 'path_param') + if not param_value_metadata: + continue + + parm_name = param_value_metadata.get( + 'field_name', field.name) + + param_field_val = getattr(param, param_field.name) + if param_field_val is None: + continue + if param_metadata.get('explode'): + pp_vals.append( + f"{parm_name}={_val_to_string(param_field_val)}") + else: + pp_vals.append( + f"{parm_name},{_val_to_string(param_field_val)}") + path = path.replace( + '{' + param_metadata.get('field_name', field.name) + '}', ",".join(pp_vals), 1) + else: + path = path.replace( + '{' + param_metadata.get('field_name', field.name) + '}', _val_to_string(param), 1) - return server_url.removesuffix("/") + path + return remove_suffix(server_url, '/') + path def is_optional(field): return get_origin(field) is Union and type(None) in get_args(field) -def template_url(url_with_params: str, params: dict[str, str]) -> str: +def template_url(url_with_params: str, params: Dict[str, str]) -> str: for key, value in params.items(): url_with_params = url_with_params.replace( '{' + key + '}', value) @@ -224,8 +238,9 @@ def template_url(url_with_params: str, params: dict[str, str]) -> str: return url_with_params -def get_query_params(clazz: type, query_params: dataclass, gbls: dict[str, dict[str, dict[str, Any]]] = None) -> dict[str, list[str]]: - params: dict[str, list[str]] = {} +def get_query_params(clazz: type, query_params: dataclass, gbls: Dict[str, Dict[str, Dict[str, Any]]] = None) -> Dict[ + str, List[str]]: + params: Dict[str, List[str]] = {} param_fields: Tuple[Field, ...] = fields(clazz) for field in param_fields: @@ -246,26 +261,33 @@ def get_query_params(clazz: type, query_params: dataclass, gbls: dict[str, dict[ f_name = metadata.get("field_name") serialization = metadata.get('serialization', '') if serialization != '': - params = params | _get_serialized_query_params( - metadata, f_name, value) + serialized_parms = _get_serialized_params(metadata, f_name, value) + for key, value in serialized_parms.items(): + if key in params: + params[key].extend(value) + else: + params[key] = [value] else: style = metadata.get('style', 'form') if style == 'deepObject': - params = params | _get_deep_object_query_params( - metadata, f_name, value) + params = {**params, **_get_deep_object_query_params( + metadata, f_name, value)} elif style == 'form': - params = params | _get_form_query_params( - metadata, f_name, value) + params = {**params, **_get_delimited_query_params( + metadata, f_name, value, ",")} + elif style == 'pipeDelimited': + params = {**params, **_get_delimited_query_params( + metadata, f_name, value, "|")} else: raise Exception('not yet implemented') return params -def get_headers(headers_params: dataclass) -> dict[str, str]: +def get_headers(headers_params: dataclass) -> Dict[str, str]: if headers_params is None: return {} - headers: dict[str, str] = {} + headers: Dict[str, str] = {} param_fields: Tuple[Field, ...] = fields(headers_params) for field in param_fields: @@ -282,8 +304,8 @@ def get_headers(headers_params: dataclass) -> dict[str, str]: return headers -def _get_serialized_query_params(metadata: dict, field_name: str, obj: any) -> dict[str, list[str]]: - params: dict[str, list[str]] = {} +def _get_serialized_params(metadata: Dict, field_name: str, obj: any) -> Dict[str, str]: + params: Dict[str, str] = {} serialization = metadata.get('serialization', '') if serialization == 'json': @@ -292,8 +314,8 @@ def _get_serialized_query_params(metadata: dict, field_name: str, obj: any) -> d return params -def _get_deep_object_query_params(metadata: dict, field_name: str, obj: any) -> dict[str, list[str]]: - params: dict[str, list[str]] = {} +def _get_deep_object_query_params(metadata: Dict, field_name: str, obj: any) -> Dict[str, List[str]]: + params: Dict[str, List[str]] = {} if obj is None: return params @@ -309,27 +331,30 @@ def _get_deep_object_query_params(metadata: dict, field_name: str, obj: any) -> if obj_val is None: continue - if isinstance(obj_val, list): + if isinstance(obj_val, List): for val in obj_val: if val is None: continue - if params.get(f'{metadata.get("field_name", field_name)}[{obj_param_metadata.get("field_name", obj_field.name)}]') is None: - params[f'{metadata.get("field_name", field_name)}[{obj_param_metadata.get("field_name", obj_field.name)}]'] = [ + if params.get( + f'{metadata.get("field_name", field_name)}[{obj_param_metadata.get("field_name", obj_field.name)}]') is None: + params[ + f'{metadata.get("field_name", field_name)}[{obj_param_metadata.get("field_name", obj_field.name)}]'] = [ ] params[ - f'{metadata.get("field_name", field_name)}[{obj_param_metadata.get("field_name", obj_field.name)}]'].append(_val_to_string(val)) + f'{metadata.get("field_name", field_name)}[{obj_param_metadata.get("field_name", obj_field.name)}]'].append( + _val_to_string(val)) else: params[ f'{metadata.get("field_name", field_name)}[{obj_param_metadata.get("field_name", obj_field.name)}]'] = [ _val_to_string(obj_val)] - elif isinstance(obj, dict): + elif isinstance(obj, Dict): for key, value in obj.items(): if value is None: continue - if isinstance(value, list): + if isinstance(value, List): for val in value: if val is None: continue @@ -355,28 +380,36 @@ def _get_query_param_field_name(obj_field: Field) -> str: return obj_param_metadata.get("field_name", obj_field.name) -def _get_form_query_params(metadata: dict, field_name: str, obj: any) -> dict[str, list[str]]: - return _populate_form(field_name, metadata.get("explode", True), obj, _get_query_param_field_name) +def _get_delimited_query_params(metadata: Dict, field_name: str, obj: any, delimiter: str) -> Dict[ + str, List[str]]: + return _populate_form(field_name, metadata.get("explode", True), obj, _get_query_param_field_name, delimiter) SERIALIZATION_METHOD_TO_CONTENT_TYPE = { - 'json': 'application/json', - 'form': 'application/x-www-form-urlencoded', + 'json': 'application/json', + 'form': 'application/x-www-form-urlencoded', 'multipart': 'multipart/form-data', - 'raw': 'application/octet-stream', - 'string': 'text/plain', + 'raw': 'application/octet-stream', + 'string': 'text/plain', } -def serialize_request_body(request: dataclass, request_field_name: str, serialization_method: str) -> Tuple[str, any, any]: +def serialize_request_body(request: dataclass, request_field_name: str, nullable: bool, optional: bool, serialization_method: str, encoder=None) -> Tuple[ + str, any, any]: if request is None: - return None, None, None, None + if not nullable and optional: + return None, None, None if not is_dataclass(request) or not hasattr(request, request_field_name): - return serialize_content_type(request_field_name, SERIALIZATION_METHOD_TO_CONTENT_TYPE[serialization_method], request) + return serialize_content_type(request_field_name, SERIALIZATION_METHOD_TO_CONTENT_TYPE[serialization_method], + request, encoder) request_val = getattr(request, request_field_name) + if request_val is None: + if not nullable and optional: + return None, None, None + request_fields: Tuple[Field, ...] = fields(request) request_metadata = None @@ -388,12 +421,13 @@ def serialize_request_body(request: dataclass, request_field_name: str, serializ if request_metadata is None: raise Exception('invalid request type') - return serialize_content_type(request_field_name, request_metadata.get('media_type', 'application/octet-stream'), request_val) + return serialize_content_type(request_field_name, request_metadata.get('media_type', 'application/octet-stream'), + request_val) -def serialize_content_type(field_name: str, media_type: str, request: dataclass) -> Tuple[str, any, list[list[any]]]: +def serialize_content_type(field_name: str, media_type: str, request: dataclass, encoder=None) -> Tuple[str, any, List[List[any]]]: if re.match(r'(application|text)\/.*?\+*json.*', media_type) is not None: - return media_type, marshal_json(request), None + return media_type, marshal_json(request, encoder), None if re.match(r'multipart\/.*', media_type) is not None: return serialize_multipart_form(media_type, request) if re.match(r'application\/x-www-form-urlencoded.*', media_type) is not None: @@ -407,8 +441,8 @@ def serialize_content_type(field_name: str, media_type: str, request: dataclass) f"invalid request body type {type(request)} for mediaType {media_type}") -def serialize_multipart_form(media_type: str, request: dataclass) -> Tuple[str, any, list[list[any]]]: - form: list[list[any]] = [] +def serialize_multipart_form(media_type: str, request: dataclass) -> Tuple[str, any, List[List[any]]]: + form: List[List[any]] = [] request_fields = fields(request) for field in request_fields: @@ -449,7 +483,7 @@ def serialize_multipart_form(media_type: str, request: dataclass) -> Tuple[str, else: field_name = field_metadata.get( "field_name", field.name) - if isinstance(val, list): + if isinstance(val, List): for value in val: if value is None: continue @@ -460,8 +494,8 @@ def serialize_multipart_form(media_type: str, request: dataclass) -> Tuple[str, return media_type, None, form -def serialize_dict(original: dict, explode: bool, field_name, existing: Optional[dict[str, list[str]]]) -> dict[ - str, list[str]]: +def serialize_dict(original: Dict, explode: bool, field_name, existing: Optional[Dict[str, List[str]]]) -> Dict[ + str, List[str]]: if existing is None: existing = [] @@ -481,8 +515,8 @@ def serialize_dict(original: dict, explode: bool, field_name, existing: Optional return existing -def serialize_form_data(field_name: str, data: dataclass) -> dict[str, any]: - form: dict[str, list[str]] = {} +def serialize_form_data(field_name: str, data: dataclass) -> Dict[str, any]: + form: Dict[str, List[str]] = {} if is_dataclass(data): for field in fields(data): @@ -500,12 +534,12 @@ def serialize_form_data(field_name: str, data: dataclass) -> dict[str, any]: form[field_name] = [marshal_json(val)] else: if metadata.get('style', 'form') == 'form': - form = form | _populate_form( - field_name, metadata.get('explode', True), val, _get_form_field_name) + form = {**form, **_populate_form( + field_name, metadata.get('explode', True), val, _get_form_field_name, ",")} else: raise Exception( f'Invalid form style for field {field.name}') - elif isinstance(data, dict): + elif isinstance(data, Dict): for key, value in data.items(): form[key] = [_val_to_string(value)] else: @@ -523,8 +557,9 @@ def _get_form_field_name(obj_field: Field) -> str: return obj_param_metadata.get("field_name", obj_field.name) -def _populate_form(field_name: str, explode: boolean, obj: any, get_field_name_func: Callable) -> dict[str, list[str]]: - params: dict[str, list[str]] = {} +def _populate_form(field_name: str, explode: boolean, obj: any, get_field_name_func: Callable, delimiter: str) -> \ + Dict[str, List[str]]: + params: Dict[str, List[str]] = {} if obj is None: return params @@ -546,11 +581,11 @@ def _populate_form(field_name: str, explode: boolean, obj: any, get_field_name_f params[obj_field_name] = [_val_to_string(val)] else: items.append( - f'{obj_field_name},{_val_to_string(val)}') + f'{obj_field_name}{delimiter}{_val_to_string(val)}') if len(items) > 0: - params[field_name] = [','.join(items)] - elif isinstance(obj, dict): + params[field_name] = [delimiter.join(items)] + elif isinstance(obj, Dict): items = [] for key, value in obj.items(): if value is None: @@ -559,11 +594,11 @@ def _populate_form(field_name: str, explode: boolean, obj: any, get_field_name_f if explode: params[key] = _val_to_string(value) else: - items.append(f'{key},{_val_to_string(value)}') + items.append(f'{key}{delimiter}{_val_to_string(value)}') if len(items) > 0: - params[field_name] = [','.join(items)] - elif isinstance(obj, list): + params[field_name] = [delimiter.join(items)] + elif isinstance(obj, List): items = [] for value in obj: @@ -578,7 +613,8 @@ def _populate_form(field_name: str, explode: boolean, obj: any, get_field_name_f items.append(_val_to_string(value)) if len(items) > 0: - params[field_name] = [','.join([str(item) for item in items])] + params[field_name] = [delimiter.join( + [str(item) for item in items])] else: params[field_name] = [_val_to_string(obj)] @@ -616,7 +652,7 @@ def _serialize_header(explode: bool, obj: any) -> str: if len(items) > 0: return ','.join(items) - elif isinstance(obj, dict): + elif isinstance(obj, Dict): items = [] for key, value in obj.items(): @@ -631,7 +667,7 @@ def _serialize_header(explode: bool, obj: any) -> str: if len(items) > 0: return ','.join([str(item) for item in items]) - elif isinstance(obj, list): + elif isinstance(obj, List): items = [] for value in obj: @@ -648,20 +684,28 @@ def _serialize_header(explode: bool, obj: any) -> str: return '' -def unmarshal_json(data, typ): - unmarhsal = make_dataclass('Unmarhsal', [('res', typ)], +def unmarshal_json(data, typ, decoder=None): + unmarshal = make_dataclass('Unmarshal', [('res', typ)], bases=(DataClassJsonMixin,)) json_dict = json.loads(data) - out = unmarhsal.from_dict({"res": json_dict}) - return out.res + try: + out = unmarshal.from_dict({"res": json_dict}) + except AttributeError as attr_err: + raise AttributeError( + f'unable to unmarshal {data} as {typ}') from attr_err + + return out.res if decoder is None else decoder(out.res) -def marshal_json(val): +def marshal_json(val, encoder=None): marshal = make_dataclass('Marshal', [('res', type(val))], bases=(DataClassJsonMixin,)) marshaller = marshal(res=val) json_dict = marshaller.to_dict() - return json.dumps(json_dict["res"]) + + val = json_dict["res"] if encoder is None else encoder(json_dict["res"]) + + return json.dumps(val) def match_content_type(content_type: str, pattern: str) -> boolean: @@ -705,6 +749,106 @@ def datefromisoformat(date_str: str): return dateutil.parser.parse(date_str).date() +def bigintencoder(optional: bool): + def bigintencode(val: int): + if optional and val is None: + return None + return str(val) + + return bigintencode + + +def bigintdecoder(val): + if isinstance(val, float): + raise ValueError(f"{val} is a float") + return int(val) + + +def decimalencoder(optional: bool, as_str: bool): + def decimalencode(val: Decimal): + if optional and val is None: + return None + + if as_str: + return str(val) + + return float(val) + + return decimalencode + + +def decimaldecoder(val): + return Decimal(str(val)) + + +def map_encoder(optional: bool, value_encoder: Callable): + def map_encode(val: Dict): + if optional and val is None: + return None + + encoded = {} + for key, value in val.items(): + encoded[key] = value_encoder(value) + + return encoded + + return map_encode + + +def map_decoder(value_decoder: Callable): + def map_decode(val: Dict): + decoded = {} + for key, value in val.items(): + decoded[key] = value_decoder(value) + + return decoded + + return map_decode + + +def list_encoder(optional: bool, value_encoder: Callable): + def list_encode(val: List): + if optional and val is None: + return None + + encoded = [] + for value in val: + encoded.append(value_encoder(value)) + + return encoded + + return list_encode + + +def list_decoder(value_decoder: Callable): + def list_decode(val: List): + decoded = [] + for value in val: + decoded.append(value_decoder(value)) + + return decoded + + return list_decode + +def union_encoder(all_encoders: Dict[str, Callable]): + def selective_encoder(val: any): + if type(val) in all_encoders: + return all_encoders[type(val)](val) + return val + return selective_encoder + +def union_decoder(all_decoders: List[Callable]): + def selective_decoder(val: any): + decoded = val + for decoder in all_decoders: + try: + decoded = decoder(val) + break + except (TypeError, ValueError): + continue + return decoded + return selective_decoder + def get_field_name(name): def override(_, _field_name=name): return _field_name @@ -718,12 +862,12 @@ def _val_to_string(val): if isinstance(val, datetime): return val.isoformat().replace('+00:00', 'Z') if isinstance(val, Enum): - return val.value + return str(val.value) return str(val) -def _populate_from_globals(param_name: str, value: any, param_type: str, gbls: dict[str, dict[str, dict[str, Any]]]): +def _populate_from_globals(param_name: str, value: any, param_type: str, gbls: Dict[str, Dict[str, Dict[str, Any]]]): if value is None and gbls is not None: if 'parameters' in gbls: if param_type in gbls['parameters']: @@ -733,3 +877,16 @@ def _populate_from_globals(param_name: str, value: any, param_type: str, gbls: d value = global_value return value + + +def decoder_with_discriminator(field_name): + def decode_fx(obj): + kls = getattr(sys.modules['sdk.models.shared'], obj[field_name]) + return unmarshal_json(json.dumps(obj), kls) + return decode_fx + + +def remove_suffix(input_string, suffix): + if suffix and input_string.endswith(suffix): + return input_string[:-len(suffix)] + return input_string