drukbox-python-sdk 0.1.0__py3-none-any.whl → 0.2.0__py3-none-any.whl
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.
- {drukbox_python_sdk-0.1.0.dist-info → drukbox_python_sdk-0.2.0.dist-info}/METADATA +31 -3
- drukbox_python_sdk-0.2.0.dist-info/RECORD +7 -0
- drukbox_sdk/__init__.py +4 -0
- drukbox_sdk/api.py +51 -1
- drukbox_sdk/exceptions.py +6 -5
- drukbox_python_sdk-0.1.0.dist-info/RECORD +0 -7
- {drukbox_python_sdk-0.1.0.dist-info → drukbox_python_sdk-0.2.0.dist-info}/WHEEL +0 -0
- {drukbox_python_sdk-0.1.0.dist-info → drukbox_python_sdk-0.2.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: drukbox-python-sdk
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Async Python client for Drukbox.
|
|
5
5
|
Project-URL: Homepage, https://github.com/clawhaven/drukbox-python-sdk
|
|
6
6
|
Project-URL: Repository, https://github.com/clawhaven/drukbox-python-sdk
|
|
@@ -71,6 +71,8 @@ Public exports live in `drukbox_sdk`:
|
|
|
71
71
|
- `SandboxAPI`
|
|
72
72
|
- `SandboxHost`
|
|
73
73
|
- `SandboxTemplate`
|
|
74
|
+
- `Secret`
|
|
75
|
+
- `Issuer`
|
|
74
76
|
- `DoctorReport` and `DoctorCheck`
|
|
75
77
|
- `HTTPProxy` and `HTTPProxyAttachment`
|
|
76
78
|
- `SandboxAPIError` and typed subclasses for auth, not found, conflict,
|
|
@@ -88,13 +90,39 @@ Supported host operations:
|
|
|
88
90
|
- `aclose`
|
|
89
91
|
|
|
90
92
|
`create_host` supports the service's optional `image`, `env`, `expires_at`,
|
|
91
|
-
`permanent`, `provider`, `instance_type`, `disk_gb`, `template`,
|
|
92
|
-
`Idempotency-Key` inputs. `instance_type` (provider-native size, e.g.
|
|
93
|
+
`permanent`, `provider`, `instance_type`, `disk_gb`, `template`, `secrets`,
|
|
94
|
+
and `Idempotency-Key` inputs. `instance_type` (provider-native size, e.g.
|
|
93
95
|
`t3.xlarge` / `cx33`) and `disk_gb` pin the VM shape; omit either for the
|
|
94
96
|
provider default. Omit `expires_at` for the default lease, pass a datetime for
|
|
95
97
|
an explicit expiry, or pass `permanent=True` for a never-reaped host.
|
|
96
98
|
`template` accepts a template ID. An explicit `image` wins over it.
|
|
97
99
|
|
|
100
|
+
`secrets` gives the box credentials it never sees. Each entry is a `Secret`,
|
|
101
|
+
a value the caller holds, or an `Issuer`, a URL Drukbox fetches the value
|
|
102
|
+
from. The box gets a placeholder per entry in the service's variable, and the
|
|
103
|
+
Drukbox swaps it on the way out. A custom service names its `host` and
|
|
104
|
+
`auth_variable`:
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
from drukbox_sdk import Issuer, Secret
|
|
108
|
+
|
|
109
|
+
host = await sandbox.create_host(
|
|
110
|
+
secrets={
|
|
111
|
+
"anthropic": Issuer(
|
|
112
|
+
"https://mint.example/box-1/anthropic",
|
|
113
|
+
headers={"Authorization": "Bearer ..."},
|
|
114
|
+
refresh="1h",
|
|
115
|
+
),
|
|
116
|
+
"openai": Secret("sk-..."),
|
|
117
|
+
"acme": Secret("ak_...", host="api.acme.test", auth_variable="ACME_TOKEN"),
|
|
118
|
+
},
|
|
119
|
+
)
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
The response carries no secret. A service name Drukbox does not know raises
|
|
123
|
+
`SandboxValidationError`. A deployment without the secrets proxy raises
|
|
124
|
+
`SandboxConflictError`.
|
|
125
|
+
|
|
98
126
|
`renew_host` extends a host's lease via `POST /hosts/{id}/renew`. Omit
|
|
99
127
|
`expires_at` to extend by the service's default TTL; renewal never makes a host
|
|
100
128
|
permanent.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
drukbox_sdk/__init__.py,sha256=7LHAef5BXUaEN_pk9pXeowyV8CuQxWnbghANSZZTcPM,970
|
|
2
|
+
drukbox_sdk/api.py,sha256=tcVaHQom-O2Xq8BbThFTjiRt7zHkWw3a6WYwC4rW3c0,22300
|
|
3
|
+
drukbox_sdk/exceptions.py,sha256=Vzs4zVOywWsWfiZm6vgQ65ScI3Nn7zLGVj-8eT1YAR0,2224
|
|
4
|
+
drukbox_python_sdk-0.2.0.dist-info/METADATA,sha256=3XKJgIsi_BHqaCuNhNaOSa6MSje_67u40BlCATpm3s4,5870
|
|
5
|
+
drukbox_python_sdk-0.2.0.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
|
|
6
|
+
drukbox_python_sdk-0.2.0.dist-info/licenses/LICENSE,sha256=zM66rWL3BWGJBa_mZPnM0WUomSSZ1xtWVtGQovQ71M8,1078
|
|
7
|
+
drukbox_python_sdk-0.2.0.dist-info/RECORD,,
|
drukbox_sdk/__init__.py
CHANGED
|
@@ -9,9 +9,11 @@ from .api import (
|
|
|
9
9
|
DoctorReport,
|
|
10
10
|
HTTPProxy,
|
|
11
11
|
HTTPProxyAttachment,
|
|
12
|
+
Issuer,
|
|
12
13
|
SandboxAPI,
|
|
13
14
|
SandboxHost,
|
|
14
15
|
SandboxTemplate,
|
|
16
|
+
Secret,
|
|
15
17
|
)
|
|
16
18
|
from .exceptions import (
|
|
17
19
|
SandboxAPIError,
|
|
@@ -29,6 +31,7 @@ __all__ = [
|
|
|
29
31
|
"DoctorReport",
|
|
30
32
|
"HTTPProxy",
|
|
31
33
|
"HTTPProxyAttachment",
|
|
34
|
+
"Issuer",
|
|
32
35
|
"SandboxAPI",
|
|
33
36
|
"SandboxAPIError",
|
|
34
37
|
"SandboxAuthError",
|
|
@@ -40,4 +43,5 @@ __all__ = [
|
|
|
40
43
|
"SandboxTemplate",
|
|
41
44
|
"SandboxUnavailableError",
|
|
42
45
|
"SandboxValidationError",
|
|
46
|
+
"Secret",
|
|
43
47
|
]
|
drukbox_sdk/api.py
CHANGED
|
@@ -39,7 +39,7 @@ For env-backed config use :meth:`SandboxAPI.from_env`.
|
|
|
39
39
|
import asyncio
|
|
40
40
|
import os
|
|
41
41
|
import uuid
|
|
42
|
-
from dataclasses import dataclass
|
|
42
|
+
from dataclasses import dataclass, field
|
|
43
43
|
from datetime import datetime
|
|
44
44
|
from typing import Any, Self
|
|
45
45
|
|
|
@@ -108,6 +108,50 @@ class SandboxHost:
|
|
|
108
108
|
expires_at: str | None
|
|
109
109
|
|
|
110
110
|
|
|
111
|
+
@dataclass(frozen=True, kw_only=True)
|
|
112
|
+
class _Service:
|
|
113
|
+
"""The custom service fields of a secret. None is unset. An empty
|
|
114
|
+
``auth_prefix`` is set, and Drukbox reads it as no prefix."""
|
|
115
|
+
|
|
116
|
+
host: str | None = None
|
|
117
|
+
auth_variable: str | None = None
|
|
118
|
+
auth_header: str | None = None
|
|
119
|
+
auth_prefix: str | None = None
|
|
120
|
+
|
|
121
|
+
def get_service(self) -> dict[str, Any]:
|
|
122
|
+
fields = {
|
|
123
|
+
"host": self.host,
|
|
124
|
+
"auth_variable": self.auth_variable,
|
|
125
|
+
"auth_header": self.auth_header,
|
|
126
|
+
"auth_prefix": self.auth_prefix,
|
|
127
|
+
}
|
|
128
|
+
return {name: value for name, value in fields.items() if value is not None}
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
@dataclass(frozen=True)
|
|
132
|
+
class Secret(_Service):
|
|
133
|
+
"""A credential the caller holds."""
|
|
134
|
+
|
|
135
|
+
value: str = field(repr=False)
|
|
136
|
+
|
|
137
|
+
def entry(self) -> dict[str, Any]:
|
|
138
|
+
return {**self.get_service(), "value": self.value}
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
@dataclass(frozen=True)
|
|
142
|
+
class Issuer(_Service):
|
|
143
|
+
"""A credential Drukbox fetches from ``url`` with ``headers``, and again
|
|
144
|
+
every ``refresh`` when the answer carries no ``expires_at``."""
|
|
145
|
+
|
|
146
|
+
url: str
|
|
147
|
+
headers: dict[str, str] = field(repr=False)
|
|
148
|
+
refresh: str
|
|
149
|
+
|
|
150
|
+
def entry(self) -> dict[str, Any]:
|
|
151
|
+
issuer = {"url": self.url, "headers": dict(self.headers), "refresh": self.refresh}
|
|
152
|
+
return {**self.get_service(), "issuer": issuer}
|
|
153
|
+
|
|
154
|
+
|
|
111
155
|
@dataclass(frozen=True)
|
|
112
156
|
class SandboxTemplate:
|
|
113
157
|
"""Snapshot of a reusable sandbox template as returned by the service.
|
|
@@ -240,6 +284,7 @@ class SandboxAPI:
|
|
|
240
284
|
instance_type: str | None = None,
|
|
241
285
|
permanent: bool = False,
|
|
242
286
|
provider: str | None = None,
|
|
287
|
+
secrets: dict[str, Secret | Issuer] | None = None,
|
|
243
288
|
template: uuid.UUID | str | None = None,
|
|
244
289
|
) -> SandboxHost:
|
|
245
290
|
"""Provision a new host.
|
|
@@ -274,6 +319,9 @@ class SandboxAPI:
|
|
|
274
319
|
Lease: omit ``expires_at`` for the service's default lease, pass a
|
|
275
320
|
``datetime`` for an explicit expiry, or pass ``permanent=True`` for
|
|
276
321
|
a host the janitor never reaps.
|
|
322
|
+
|
|
323
|
+
``secrets`` maps a service name to a :class:`Secret` or an
|
|
324
|
+
:class:`Issuer`. The response carries no secret.
|
|
277
325
|
"""
|
|
278
326
|
|
|
279
327
|
if expires_at and permanent:
|
|
@@ -295,6 +343,8 @@ class SandboxAPI:
|
|
|
295
343
|
payload["instance_type"] = instance_type
|
|
296
344
|
if provider is not None:
|
|
297
345
|
payload["provider"] = provider
|
|
346
|
+
if secrets:
|
|
347
|
+
payload["secrets"] = {name: entry.entry() for name, entry in secrets.items()}
|
|
298
348
|
if template is not None:
|
|
299
349
|
payload["template"] = str(template)
|
|
300
350
|
|
drukbox_sdk/exceptions.py
CHANGED
|
@@ -37,8 +37,8 @@ class SandboxNotFoundError(SandboxAPIError):
|
|
|
37
37
|
class SandboxConflictError(SandboxAPIError):
|
|
38
38
|
"""409 — the operation conflicts with the current state.
|
|
39
39
|
|
|
40
|
-
e.g.
|
|
41
|
-
the
|
|
40
|
+
e.g. a template that is still building, or secrets on a deployment
|
|
41
|
+
without the secrets proxy configured.
|
|
42
42
|
"""
|
|
43
43
|
|
|
44
44
|
|
|
@@ -53,9 +53,10 @@ class SandboxProvisioningError(SandboxAPIError):
|
|
|
53
53
|
class SandboxValidationError(SandboxAPIError):
|
|
54
54
|
"""422 — the service rejected the request payload as invalid.
|
|
55
55
|
|
|
56
|
-
e.g. an env key that isn't a valid environment-variable name,
|
|
57
|
-
proxy target URL carrying a path or credentials
|
|
58
|
-
|
|
56
|
+
e.g. an env key that isn't a valid environment-variable name, a
|
|
57
|
+
proxy target URL carrying a path or credentials, or a secret for a
|
|
58
|
+
service name Drukbox does not know. The request is malformed, so
|
|
59
|
+
retrying it unchanged won't help — fix the input.
|
|
59
60
|
"""
|
|
60
61
|
|
|
61
62
|
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
drukbox_sdk/__init__.py,sha256=8gZrxZhT8ivzDFZmTcnN5PbwL_kwRwHluJOQHfJJeaI,918
|
|
2
|
-
drukbox_sdk/api.py,sha256=kO8qOaxLZ3How5b-yJNW51A7JjnVt7jP4BDf4kgnv3A,20655
|
|
3
|
-
drukbox_sdk/exceptions.py,sha256=YecxsuwpHhwzgw-_h9KbXf1WqY6R0JIJrwPY3Eg4e6I,2146
|
|
4
|
-
drukbox_python_sdk-0.1.0.dist-info/METADATA,sha256=mOJsJfO_rokCOmynC-C9DbdGqpqkYD0elzzRoCX6vzc,4943
|
|
5
|
-
drukbox_python_sdk-0.1.0.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
|
|
6
|
-
drukbox_python_sdk-0.1.0.dist-info/licenses/LICENSE,sha256=zM66rWL3BWGJBa_mZPnM0WUomSSZ1xtWVtGQovQ71M8,1078
|
|
7
|
-
drukbox_python_sdk-0.1.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|