shako-sdk 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- shako_sdk-0.1.0/.gitignore +5 -0
- shako_sdk-0.1.0/LICENSE +21 -0
- shako_sdk-0.1.0/PKG-INFO +109 -0
- shako_sdk-0.1.0/README.md +92 -0
- shako_sdk-0.1.0/pyproject.toml +34 -0
- shako_sdk-0.1.0/src/shako_sdk/__init__.py +7 -0
- shako_sdk-0.1.0/src/shako_sdk/_base.py +22 -0
- shako_sdk-0.1.0/src/shako_sdk/_client.py +118 -0
- shako_sdk-0.1.0/src/shako_sdk/_resources.py +592 -0
- shako_sdk-0.1.0/src/shako_sdk/_version.py +1 -0
- shako_sdk-0.1.0/src/shako_sdk/py.typed +0 -0
- shako_sdk-0.1.0/src/shako_sdk/types.py +417 -0
- shako_sdk-0.1.0/tests/test_client.py +202 -0
- shako_sdk-0.1.0/tests/typecheck.py +31 -0
shako_sdk-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ShakoAI, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
shako_sdk-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: shako-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: The Shako API for Python: VMs, ports, backups, secrets and credit, with an API key.
|
|
5
|
+
Project-URL: Homepage, https://shako.dev
|
|
6
|
+
Project-URL: Documentation, https://shako.dev/api
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Keywords: api,cloud,sdk,shako,vm
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Typing :: Typed
|
|
15
|
+
Requires-Python: >=3.9
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
|
|
18
|
+
# shako-sdk
|
|
19
|
+
|
|
20
|
+
The Shako API for Python: VMs, ports, backups, secrets, devices, credit and tenants, with an API key.
|
|
21
|
+
|
|
22
|
+
Each method is one endpoint of the REST API. `shako.vms.create(...)` is https://shako.dev/api/vms/create, and that
|
|
23
|
+
page has each field, its default and the answer.
|
|
24
|
+
|
|
25
|
+
## Install
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
pip install shako-sdk
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Python 3.9 or newer. The package needs no other packages.
|
|
32
|
+
|
|
33
|
+
## API key
|
|
34
|
+
|
|
35
|
+
Make a key with the CLI, or in the workspace (https://workspace.shako.dev, Account settings › API keys). Shako shows
|
|
36
|
+
the key only once.
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
shako api-key create ci --role contributor --tenant acme --days 90
|
|
40
|
+
export SHAKO_API_KEY=shk_k_...
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Use
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
from shako_sdk import Shako
|
|
47
|
+
|
|
48
|
+
shako = Shako() # the key from SHAKO_API_KEY
|
|
49
|
+
|
|
50
|
+
for vm in shako.vms.list():
|
|
51
|
+
print(vm["name"], vm["state"])
|
|
52
|
+
|
|
53
|
+
shako.vms.create(name="web1", size="small")
|
|
54
|
+
print(shako.ports.create("web1", port=8000)["url"])
|
|
55
|
+
print(shako.billing.usage()["total_cost"])
|
|
56
|
+
shako.vms.delete("web1")
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
- `shako.<resource>.<endpoint>`: the resources and the endpoints of https://shako.dev/api, with `_` in place of `-`
|
|
60
|
+
(`shako.screen_links.create`, `shako.billing.top_up`).
|
|
61
|
+
- The args of the path are positional: `shako.vms.get("web1")`, `shako.ports.delete("web1", 8000)`.
|
|
62
|
+
- The fields of the query or the body are keyword args: `shako.vms.update("web1", sleep="never")`.
|
|
63
|
+
- An answer is a `dict`, and a list is a `list`. The types are in `shako_sdk.types` (for example `VmView`).
|
|
64
|
+
|
|
65
|
+
## Tenant
|
|
66
|
+
|
|
67
|
+
A key for one tenant needs no tenant: the client reads it from `GET /v1/whoami` once. A key for your account
|
|
68
|
+
(`shako api-key create ops --role owner --account`) needs the tenant:
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
shako = Shako(tenant="acme") # each request
|
|
72
|
+
shako.vms.list(tenant="other") # one request
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Errors
|
|
76
|
+
|
|
77
|
+
An error answer raises `ShakoError`:
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
from shako_sdk import ShakoError
|
|
81
|
+
|
|
82
|
+
try:
|
|
83
|
+
shako.billing.top_up(amount=5)
|
|
84
|
+
except ShakoError as err:
|
|
85
|
+
print(err.code, err.status, err.message)
|
|
86
|
+
# forbidden 403 API key ci needs the role owner on acme for credit-add. See shako access ls, ...
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The codes: https://shako.dev/api/errors. When no answer comes, the code is `unreachable` and the status is 0.
|
|
90
|
+
|
|
91
|
+
## An endpoint with no method
|
|
92
|
+
|
|
93
|
+
`shako.request("GET", "/v1/tenants/{tenant}/vms/{name}", {"name": "web1"})` sends any request, and returns the JSON
|
|
94
|
+
answer.
|
|
95
|
+
|
|
96
|
+
## Options
|
|
97
|
+
|
|
98
|
+
`Shako(api_key=None, *, tenant=None, base_url=None, timeout=900)`
|
|
99
|
+
|
|
100
|
+
| Option | When it is missing |
|
|
101
|
+
|---|---|
|
|
102
|
+
| `api_key` | The environment variable `SHAKO_API_KEY`. |
|
|
103
|
+
| `tenant` | The tenant of the key, when the key has only one. |
|
|
104
|
+
| `base_url` | The environment variable `SHAKO_API`, then `https://api.shako.dev`. |
|
|
105
|
+
| `timeout` | 900 seconds for one request. A create waits until the VM boots. |
|
|
106
|
+
|
|
107
|
+
## License
|
|
108
|
+
|
|
109
|
+
MIT
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# shako-sdk
|
|
2
|
+
|
|
3
|
+
The Shako API for Python: VMs, ports, backups, secrets, devices, credit and tenants, with an API key.
|
|
4
|
+
|
|
5
|
+
Each method is one endpoint of the REST API. `shako.vms.create(...)` is https://shako.dev/api/vms/create, and that
|
|
6
|
+
page has each field, its default and the answer.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
pip install shako-sdk
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Python 3.9 or newer. The package needs no other packages.
|
|
15
|
+
|
|
16
|
+
## API key
|
|
17
|
+
|
|
18
|
+
Make a key with the CLI, or in the workspace (https://workspace.shako.dev, Account settings › API keys). Shako shows
|
|
19
|
+
the key only once.
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
shako api-key create ci --role contributor --tenant acme --days 90
|
|
23
|
+
export SHAKO_API_KEY=shk_k_...
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Use
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
from shako_sdk import Shako
|
|
30
|
+
|
|
31
|
+
shako = Shako() # the key from SHAKO_API_KEY
|
|
32
|
+
|
|
33
|
+
for vm in shako.vms.list():
|
|
34
|
+
print(vm["name"], vm["state"])
|
|
35
|
+
|
|
36
|
+
shako.vms.create(name="web1", size="small")
|
|
37
|
+
print(shako.ports.create("web1", port=8000)["url"])
|
|
38
|
+
print(shako.billing.usage()["total_cost"])
|
|
39
|
+
shako.vms.delete("web1")
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
- `shako.<resource>.<endpoint>`: the resources and the endpoints of https://shako.dev/api, with `_` in place of `-`
|
|
43
|
+
(`shako.screen_links.create`, `shako.billing.top_up`).
|
|
44
|
+
- The args of the path are positional: `shako.vms.get("web1")`, `shako.ports.delete("web1", 8000)`.
|
|
45
|
+
- The fields of the query or the body are keyword args: `shako.vms.update("web1", sleep="never")`.
|
|
46
|
+
- An answer is a `dict`, and a list is a `list`. The types are in `shako_sdk.types` (for example `VmView`).
|
|
47
|
+
|
|
48
|
+
## Tenant
|
|
49
|
+
|
|
50
|
+
A key for one tenant needs no tenant: the client reads it from `GET /v1/whoami` once. A key for your account
|
|
51
|
+
(`shako api-key create ops --role owner --account`) needs the tenant:
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
shako = Shako(tenant="acme") # each request
|
|
55
|
+
shako.vms.list(tenant="other") # one request
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Errors
|
|
59
|
+
|
|
60
|
+
An error answer raises `ShakoError`:
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
from shako_sdk import ShakoError
|
|
64
|
+
|
|
65
|
+
try:
|
|
66
|
+
shako.billing.top_up(amount=5)
|
|
67
|
+
except ShakoError as err:
|
|
68
|
+
print(err.code, err.status, err.message)
|
|
69
|
+
# forbidden 403 API key ci needs the role owner on acme for credit-add. See shako access ls, ...
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
The codes: https://shako.dev/api/errors. When no answer comes, the code is `unreachable` and the status is 0.
|
|
73
|
+
|
|
74
|
+
## An endpoint with no method
|
|
75
|
+
|
|
76
|
+
`shako.request("GET", "/v1/tenants/{tenant}/vms/{name}", {"name": "web1"})` sends any request, and returns the JSON
|
|
77
|
+
answer.
|
|
78
|
+
|
|
79
|
+
## Options
|
|
80
|
+
|
|
81
|
+
`Shako(api_key=None, *, tenant=None, base_url=None, timeout=900)`
|
|
82
|
+
|
|
83
|
+
| Option | When it is missing |
|
|
84
|
+
|---|---|
|
|
85
|
+
| `api_key` | The environment variable `SHAKO_API_KEY`. |
|
|
86
|
+
| `tenant` | The tenant of the key, when the key has only one. |
|
|
87
|
+
| `base_url` | The environment variable `SHAKO_API`, then `https://api.shako.dev`. |
|
|
88
|
+
| `timeout` | 900 seconds for one request. A create waits until the VM boots. |
|
|
89
|
+
|
|
90
|
+
## License
|
|
91
|
+
|
|
92
|
+
MIT
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling==1.27.0"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "shako-sdk"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "The Shako API for Python: VMs, ports, backups, secrets and credit, with an API key."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
requires-python = ">=3.9"
|
|
13
|
+
dependencies = []
|
|
14
|
+
keywords = ["shako", "vm", "cloud", "sdk", "api"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 4 - Beta",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Typing :: Typed",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
[project.urls]
|
|
24
|
+
Homepage = "https://shako.dev"
|
|
25
|
+
Documentation = "https://shako.dev/api"
|
|
26
|
+
|
|
27
|
+
[tool.hatch.version]
|
|
28
|
+
path = "src/shako_sdk/_version.py"
|
|
29
|
+
|
|
30
|
+
[tool.hatch.build.targets.wheel]
|
|
31
|
+
packages = ["src/shako_sdk"]
|
|
32
|
+
|
|
33
|
+
[tool.hatch.build.targets.sdist]
|
|
34
|
+
include = ["src/shako_sdk", "tests", "README.md", "LICENSE"]
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"""The Shako API for Python (https://shako.dev/api): shako.vms, shako.ports, shako.secrets, ..., with an API key."""
|
|
2
|
+
|
|
3
|
+
from . import types
|
|
4
|
+
from ._client import Shako, ShakoError
|
|
5
|
+
from ._version import __version__
|
|
6
|
+
|
|
7
|
+
__all__ = ["Shako", "ShakoError", "__version__", "types"]
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""The base of each resource of the API (_resources.py)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any, Dict, Optional, Protocol
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Client(Protocol):
|
|
9
|
+
def request(self, method: str, path: str, params: Optional[Dict[str, Any]] = None,
|
|
10
|
+
fields: Optional[Dict[str, Any]] = None, tenant: Optional[str] = None) -> Any: ...
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Resource:
|
|
14
|
+
"""A resource of the API. Each method sends the request of its endpoint through the client."""
|
|
15
|
+
|
|
16
|
+
def __init__(self, client: Client) -> None:
|
|
17
|
+
self._client = client
|
|
18
|
+
|
|
19
|
+
def _call(self, method: str, path: str, params: Dict[str, Any], fields: Optional[Dict[str, Any]],
|
|
20
|
+
tenant: Optional[str], data: bool = False) -> Any:
|
|
21
|
+
answer = self._client.request(method, path, params, fields, tenant)
|
|
22
|
+
return answer["data"] if data else answer
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"""The client: each method of a resource is one HTTPS request of the REST API (https://shako.dev/api)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
import re
|
|
8
|
+
import urllib.error
|
|
9
|
+
import urllib.request
|
|
10
|
+
from typing import Any, Dict, Optional
|
|
11
|
+
from urllib.parse import quote, urlencode
|
|
12
|
+
|
|
13
|
+
from ._resources import Resources
|
|
14
|
+
from ._version import __version__
|
|
15
|
+
|
|
16
|
+
DEFAULT_URL = "https://api.shako.dev"
|
|
17
|
+
# The seconds for one request. A create waits until the VM boots, as the shako CLI does.
|
|
18
|
+
TIMEOUT = 15 * 60
|
|
19
|
+
# The HTTP status of a proxy in front of Shako when Shako does not answer.
|
|
20
|
+
NO_ANSWER = (502, 503, 504)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class ShakoError(Exception):
|
|
24
|
+
"""An error answer, or no answer.
|
|
25
|
+
|
|
26
|
+
code: the code of the error (https://shako.dev/api/errors). It is unreachable when Shako did not answer.
|
|
27
|
+
message: the text of the error, for people.
|
|
28
|
+
status: the HTTP status. It is 0 when no answer came.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
def __init__(self, code: str, message: str, status: int) -> None:
|
|
32
|
+
super().__init__(message)
|
|
33
|
+
self.code = code
|
|
34
|
+
self.message = message
|
|
35
|
+
self.status = status
|
|
36
|
+
|
|
37
|
+
def __repr__(self) -> str:
|
|
38
|
+
return f"ShakoError(code={self.code!r}, status={self.status}, message={self.message!r})"
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class Shako(Resources):
|
|
42
|
+
"""A client of the Shako API (https://shako.dev/api): shako.vms, shako.ports, shako.secrets, ...
|
|
43
|
+
|
|
44
|
+
api_key: an API key (shako api-key create). If it is missing, the environment variable SHAKO_API_KEY.
|
|
45
|
+
tenant: the tenant of each request. If it is missing, the tenant of the key, when the key has only one.
|
|
46
|
+
base_url: if it is missing, the environment variable SHAKO_API, then https://api.shako.dev.
|
|
47
|
+
timeout: the seconds for one request.
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
def __init__(self, api_key: Optional[str] = None, *, tenant: Optional[str] = None,
|
|
51
|
+
base_url: Optional[str] = None, timeout: float = TIMEOUT) -> None:
|
|
52
|
+
key = api_key or os.environ.get("SHAKO_API_KEY")
|
|
53
|
+
if not key:
|
|
54
|
+
raise ValueError("no API key: give Shako(api_key=...) or set SHAKO_API_KEY (https://shako.dev/api)")
|
|
55
|
+
self._api_key = key
|
|
56
|
+
self.tenant = tenant
|
|
57
|
+
self.base_url = (base_url or os.environ.get("SHAKO_API") or DEFAULT_URL).rstrip("/")
|
|
58
|
+
self.timeout = timeout
|
|
59
|
+
self._key_tenant: Optional[str] = None
|
|
60
|
+
self._attach(self)
|
|
61
|
+
|
|
62
|
+
def __repr__(self) -> str:
|
|
63
|
+
return f"Shako(base_url={self.base_url!r}, tenant={self.tenant!r})"
|
|
64
|
+
|
|
65
|
+
def request(self, method: str, path: str, params: Optional[Dict[str, Any]] = None,
|
|
66
|
+
fields: Optional[Dict[str, Any]] = None, tenant: Optional[str] = None) -> Any:
|
|
67
|
+
"""One request: the path with the values of params (and the tenant), and the fields in the query of a GET or
|
|
68
|
+
in the JSON body. A field that is None is not sent. Returns the JSON answer. Raises ShakoError."""
|
|
69
|
+
values = {k: str(v) for k, v in (params or {}).items()}
|
|
70
|
+
if "{tenant}" in path:
|
|
71
|
+
values["tenant"] = tenant or self.tenant or self._tenant_of_key()
|
|
72
|
+
|
|
73
|
+
def value(match: "re.Match[str]") -> str:
|
|
74
|
+
return quote(values[match.group(1)], safe="")
|
|
75
|
+
|
|
76
|
+
url = self.base_url + re.sub(r"\{(\w+)\}", value, path)
|
|
77
|
+
sent = {k: v for k, v in (fields or {}).items() if v is not None}
|
|
78
|
+
headers = {"Authorization": f"Bearer {self._api_key}", "Accept": "application/json",
|
|
79
|
+
"User-Agent": f"shako-sdk-python/{__version__}"}
|
|
80
|
+
data = None
|
|
81
|
+
if method == "GET":
|
|
82
|
+
if sent:
|
|
83
|
+
url += "?" + urlencode({k: str(v).lower() if isinstance(v, bool) else v for k, v in sent.items()})
|
|
84
|
+
elif fields is not None:
|
|
85
|
+
data = json.dumps(sent).encode()
|
|
86
|
+
headers["Content-Type"] = "application/json"
|
|
87
|
+
try:
|
|
88
|
+
with urllib.request.urlopen(urllib.request.Request(url, data=data, method=method, headers=headers),
|
|
89
|
+
timeout=self.timeout) as response:
|
|
90
|
+
status, raw = response.status, response.read()
|
|
91
|
+
except urllib.error.HTTPError as err:
|
|
92
|
+
status, raw = err.code, err.read()
|
|
93
|
+
except OSError as err: # URLError, a refused connection, a timeout
|
|
94
|
+
reason = getattr(err, "reason", None) or err
|
|
95
|
+
raise ShakoError("unreachable", f"no answer from {self.base_url}: {reason}", 0) from err
|
|
96
|
+
try:
|
|
97
|
+
answer = json.loads(raw)
|
|
98
|
+
except ValueError:
|
|
99
|
+
code = "unreachable" if status in NO_ANSWER else "internal"
|
|
100
|
+
raise ShakoError(code, f"HTTP {status} with no JSON answer from {self.base_url}", status) from None
|
|
101
|
+
if 200 <= status < 300:
|
|
102
|
+
return answer
|
|
103
|
+
error = answer.get("error") if isinstance(answer, dict) else None
|
|
104
|
+
if isinstance(error, dict):
|
|
105
|
+
raise ShakoError(str(error.get("code") or "internal"), str(error.get("message") or f"HTTP {status}"),
|
|
106
|
+
status)
|
|
107
|
+
raise ShakoError("unreachable" if status in NO_ANSWER else "internal", f"HTTP {status} from {self.base_url}",
|
|
108
|
+
status)
|
|
109
|
+
|
|
110
|
+
def _tenant_of_key(self) -> str:
|
|
111
|
+
"""The tenant of a key for one tenant, from GET /v1/whoami, once."""
|
|
112
|
+
if self._key_tenant is None:
|
|
113
|
+
tenant = self.request("GET", "/v1/whoami").get("tenant")
|
|
114
|
+
if not tenant:
|
|
115
|
+
raise ValueError("the API key has more than one tenant: give Shako(tenant=...), or tenant=... to the "
|
|
116
|
+
"method")
|
|
117
|
+
self._key_tenant = tenant
|
|
118
|
+
return self._key_tenant
|