Skip to content

Commit 640a012

Browse files
committed
chore(sdk): add support for custom auth endpoint and add example
1 parent 8d13395 commit 640a012

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,29 @@ Using this flow is less secure since the token is long-lived. You can provide th
154154
2. Setting the environment variable `STACKIT_SERVICE_ACCOUNT_TOKEN`
155155
3. Setting it in the credentials file (see above)
156156

157+
## Using custom endpoints
158+
159+
The example below shows how to use the STACKIT Python SDK in custom STACKIT environments.
160+
161+
```python
162+
from stackit.iaas.api.default_api import DefaultApi
163+
from stackit.core.configuration import Configuration
164+
165+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
166+
167+
# Create a new API client that uses custom authentication and service endpoints
168+
config = Configuration(
169+
service_account_key_path="/home/bob/.stackit/sa_key.json",
170+
custom_token_endpoint="https://service-account.api.qa.stackit.cloud/token",
171+
custom_endpoint="https://iaas.api.eu01.qa.stackit.cloud",
172+
)
173+
client = DefaultApi(config)
174+
175+
print(client.list_project_nics(
176+
project_id=project_id,
177+
))
178+
```
179+
157180
## Reporting issues
158181

159182
If you encounter any issues or have suggestions for improvements, please open an issue in the repository or create a ticket in the [STACKIT Help Center](https://support.stackit.cloud/).

core/src/stackit/core/configuration.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ def __init__(
3232
private_key_path=None,
3333
credentials_file_path=None,
3434
custom_endpoint=None,
35+
custom_token_endpoint=None,
3536
custom_http_session=None,
3637
custom_auth=None,
3738
server_index=None,
3839
) -> None:
3940
environment_variables = EnvironmentVariables()
4041
self.region = region if region else environment_variables.region
41-
self.token_endpoint = environment_variables.token_baseurl
42+
self.token_endpoint = custom_token_endpoint if custom_token_endpoint else environment_variables.token_baseurl
4243
self.service_account_token = (
4344
environment_variables.service_account_token if service_account_token is None else service_account_token
4445
)

0 commit comments

Comments
 (0)