drukbox-python-sdk 0.5.0__tar.gz → 0.6.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.
- {drukbox_python_sdk-0.5.0 → drukbox_python_sdk-0.6.0}/AGENTS.md +4 -3
- {drukbox_python_sdk-0.5.0 → drukbox_python_sdk-0.6.0}/PKG-INFO +8 -6
- {drukbox_python_sdk-0.5.0 → drukbox_python_sdk-0.6.0}/README.md +7 -5
- {drukbox_python_sdk-0.5.0 → drukbox_python_sdk-0.6.0}/pyproject.toml +1 -1
- {drukbox_python_sdk-0.5.0 → drukbox_python_sdk-0.6.0}/src/drukbox_sdk/api.py +25 -8
- {drukbox_python_sdk-0.5.0 → drukbox_python_sdk-0.6.0}/tests/test_api.py +55 -0
- {drukbox_python_sdk-0.5.0 → drukbox_python_sdk-0.6.0}/.github/workflows/on-main-merge.yml +0 -0
- {drukbox_python_sdk-0.5.0 → drukbox_python_sdk-0.6.0}/.github/workflows/on-pull-request.yml +0 -0
- {drukbox_python_sdk-0.5.0 → drukbox_python_sdk-0.6.0}/.github/workflows/release.yml +0 -0
- {drukbox_python_sdk-0.5.0 → drukbox_python_sdk-0.6.0}/.gitignore +0 -0
- {drukbox_python_sdk-0.5.0 → drukbox_python_sdk-0.6.0}/LICENSE +0 -0
- {drukbox_python_sdk-0.5.0 → drukbox_python_sdk-0.6.0}/src/drukbox_sdk/__init__.py +0 -0
- {drukbox_python_sdk-0.5.0 → drukbox_python_sdk-0.6.0}/src/drukbox_sdk/exceptions.py +0 -0
- {drukbox_python_sdk-0.5.0 → drukbox_python_sdk-0.6.0}/tests/__init__.py +0 -0
|
@@ -57,6 +57,7 @@ run.
|
|
|
57
57
|
consumers unless the user asks for them.
|
|
58
58
|
- Preserve user changes in the worktree; do not clean or rewrite unrelated
|
|
59
59
|
files.
|
|
60
|
-
- A version bump rides alone:
|
|
61
|
-
only `pyproject.toml`, with no other change in it.
|
|
62
|
-
a feature or fix commit. The release tag is
|
|
60
|
+
- A version bump rides alone: its own commit (`chore: bump to X`) that
|
|
61
|
+
touches only `pyproject.toml`, in its own PR with no other change in it.
|
|
62
|
+
Never fold the bump into a feature or fix commit or PR. The release tag is
|
|
63
|
+
cut from the bump commit.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: drukbox-python-sdk
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.6.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
|
|
@@ -94,10 +94,11 @@ Supported host operations:
|
|
|
94
94
|
- `aclose`
|
|
95
95
|
|
|
96
96
|
`create_host` supports the service's optional `image`, `env`, `expires_at`,
|
|
97
|
-
`permanent`, `provider`, `instance_type`, `disk_gb`, `
|
|
98
|
-
and `Idempotency-Key` inputs. `instance_type` (provider-native size, e.g.
|
|
97
|
+
`permanent`, `provider`, `instance_type`, `disk_gb`, `cpu`, `memory_gb`, `template`,
|
|
98
|
+
`secrets`, and `Idempotency-Key` inputs. `instance_type` (provider-native size, e.g.
|
|
99
99
|
`t3.xlarge` / `cx33`) and `disk_gb` pin the VM shape; omit either for the
|
|
100
|
-
provider default.
|
|
100
|
+
provider default. `cpu` (vCPUs) and `memory_gb` size the VM by what it needs, on a
|
|
101
|
+
provider that can. Omit `expires_at` for the default lease, pass a datetime for
|
|
101
102
|
an explicit expiry, or pass `permanent=True` for a never-reaped host.
|
|
102
103
|
`template` accepts a template ID. An explicit `image` wins over it.
|
|
103
104
|
|
|
@@ -157,8 +158,9 @@ Supported template operations:
|
|
|
157
158
|
- `delete_template`
|
|
158
159
|
|
|
159
160
|
`create_template` returns immediately with a `building` record. Poll
|
|
160
|
-
`get_template` until the status is `available` or `failed`.
|
|
161
|
-
|
|
161
|
+
`get_template` until the status is `available` or `failed`. While it builds,
|
|
162
|
+
`build_step` names the step the build is in. A failed record keeps that step
|
|
163
|
+
and carries the reason in `last_error`.
|
|
162
164
|
|
|
163
165
|
Supported HTTP-proxy operations:
|
|
164
166
|
|
|
@@ -81,10 +81,11 @@ Supported host operations:
|
|
|
81
81
|
- `aclose`
|
|
82
82
|
|
|
83
83
|
`create_host` supports the service's optional `image`, `env`, `expires_at`,
|
|
84
|
-
`permanent`, `provider`, `instance_type`, `disk_gb`, `
|
|
85
|
-
and `Idempotency-Key` inputs. `instance_type` (provider-native size, e.g.
|
|
84
|
+
`permanent`, `provider`, `instance_type`, `disk_gb`, `cpu`, `memory_gb`, `template`,
|
|
85
|
+
`secrets`, and `Idempotency-Key` inputs. `instance_type` (provider-native size, e.g.
|
|
86
86
|
`t3.xlarge` / `cx33`) and `disk_gb` pin the VM shape; omit either for the
|
|
87
|
-
provider default.
|
|
87
|
+
provider default. `cpu` (vCPUs) and `memory_gb` size the VM by what it needs, on a
|
|
88
|
+
provider that can. Omit `expires_at` for the default lease, pass a datetime for
|
|
88
89
|
an explicit expiry, or pass `permanent=True` for a never-reaped host.
|
|
89
90
|
`template` accepts a template ID. An explicit `image` wins over it.
|
|
90
91
|
|
|
@@ -144,8 +145,9 @@ Supported template operations:
|
|
|
144
145
|
- `delete_template`
|
|
145
146
|
|
|
146
147
|
`create_template` returns immediately with a `building` record. Poll
|
|
147
|
-
`get_template` until the status is `available` or `failed`.
|
|
148
|
-
|
|
148
|
+
`get_template` until the status is `available` or `failed`. While it builds,
|
|
149
|
+
`build_step` names the step the build is in. A failed record keeps that step
|
|
150
|
+
and carries the reason in `last_error`.
|
|
149
151
|
|
|
150
152
|
Supported HTTP-proxy operations:
|
|
151
153
|
|
|
@@ -163,9 +163,12 @@ class SandboxTemplate:
|
|
|
163
163
|
"""Snapshot of a reusable sandbox template as returned by the service.
|
|
164
164
|
|
|
165
165
|
``status`` moves from ``"building"`` to ``"available"`` or
|
|
166
|
-
``"failed"``. While the build runs, ``image`` is empty
|
|
167
|
-
|
|
168
|
-
|
|
166
|
+
``"failed"``. While the build runs, ``image`` is empty and
|
|
167
|
+
``build_step`` names the step the build is in. A failed build keeps
|
|
168
|
+
the step it failed in and carries its reason in ``last_error``.
|
|
169
|
+
``build_step`` is empty from a service that does not send it. The
|
|
170
|
+
record has no ``setup_script`` because the service never echoes it
|
|
171
|
+
back.
|
|
169
172
|
"""
|
|
170
173
|
|
|
171
174
|
id: str
|
|
@@ -179,6 +182,7 @@ class SandboxTemplate:
|
|
|
179
182
|
created_at: str
|
|
180
183
|
updated_at: str
|
|
181
184
|
last_used_at: str | None
|
|
185
|
+
build_step: str = ""
|
|
182
186
|
|
|
183
187
|
|
|
184
188
|
@dataclass(frozen=True)
|
|
@@ -292,12 +296,14 @@ class SandboxAPI:
|
|
|
292
296
|
async def create_host(
|
|
293
297
|
self,
|
|
294
298
|
*,
|
|
299
|
+
cpu: int | None = None,
|
|
295
300
|
disk_gb: int | None = None,
|
|
296
301
|
env: dict[str, str] | None = None,
|
|
297
302
|
expires_at: datetime | None = None,
|
|
298
303
|
idempotency_key: str | None = None,
|
|
299
304
|
image: str | None = None,
|
|
300
305
|
instance_type: str | None = None,
|
|
306
|
+
memory_gb: int | None = None,
|
|
301
307
|
permanent: bool = False,
|
|
302
308
|
provider: str | None = None,
|
|
303
309
|
secrets: dict[str, Secret | Issuer] | None = None,
|
|
@@ -332,6 +338,13 @@ class SandboxAPI:
|
|
|
332
338
|
either to use the provider's configured default. A size the active
|
|
333
339
|
provider can't serve raises :class:`SandboxResponseError` (400).
|
|
334
340
|
|
|
341
|
+
``cpu`` (vCPUs) and ``memory_gb`` size the VM by what it needs, not by a
|
|
342
|
+
provider's name for it; omit either to use the provider's default. A
|
|
343
|
+
provider that can't size a VM this way raises
|
|
344
|
+
:class:`SandboxResponseError` (400). A size the provider's account
|
|
345
|
+
does not allow fails the host: it goes to ``"error"`` with the reason
|
|
346
|
+
in ``last_error``.
|
|
347
|
+
|
|
335
348
|
Lease: omit ``expires_at`` for the service's default lease, pass a
|
|
336
349
|
``datetime`` for an explicit expiry, or pass ``permanent=True`` for
|
|
337
350
|
a host the janitor never reaps.
|
|
@@ -344,6 +357,8 @@ class SandboxAPI:
|
|
|
344
357
|
raise ValueError("a permanent host cannot carry an expires_at")
|
|
345
358
|
|
|
346
359
|
payload: dict[str, Any] = {}
|
|
360
|
+
if cpu is not None:
|
|
361
|
+
payload["cpu"] = cpu
|
|
347
362
|
if disk_gb is not None:
|
|
348
363
|
payload["disk_gb"] = disk_gb
|
|
349
364
|
if env is not None:
|
|
@@ -357,6 +372,8 @@ class SandboxAPI:
|
|
|
357
372
|
payload["image"] = image
|
|
358
373
|
if instance_type is not None:
|
|
359
374
|
payload["instance_type"] = instance_type
|
|
375
|
+
if memory_gb is not None:
|
|
376
|
+
payload["memory_gb"] = memory_gb
|
|
360
377
|
if provider is not None:
|
|
361
378
|
payload["provider"] = provider
|
|
362
379
|
if secrets:
|
|
@@ -626,11 +643,11 @@ class SandboxAPI:
|
|
|
626
643
|
raise SandboxUnavailableError(json_response.get("detail", "service unavailable"))
|
|
627
644
|
|
|
628
645
|
if response.status_code == 422:
|
|
629
|
-
#
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
raise SandboxValidationError(detail)
|
|
646
|
+
# The detail is FastAPI's list of error dicts or the service's own sentence.
|
|
647
|
+
detail = json_response.get("detail")
|
|
648
|
+
if isinstance(detail, list):
|
|
649
|
+
detail = "; ".join(error.get("msg", "") for error in detail)
|
|
650
|
+
raise SandboxValidationError(detail or "validation error")
|
|
634
651
|
|
|
635
652
|
if response.status_code >= 400:
|
|
636
653
|
raise SandboxResponseError(json_response.get("detail", "error"))
|
|
@@ -190,6 +190,8 @@ async def test_create_host_omits_image_and_env_when_unset(api: SandboxAPI):
|
|
|
190
190
|
assert "provider" not in body
|
|
191
191
|
assert "instance_type" not in body
|
|
192
192
|
assert "disk_gb" not in body
|
|
193
|
+
assert "cpu" not in body
|
|
194
|
+
assert "memory_gb" not in body
|
|
193
195
|
assert "template" not in body
|
|
194
196
|
assert "Idempotency-Key" not in route.calls.last.request.headers
|
|
195
197
|
|
|
@@ -234,6 +236,32 @@ async def test_create_host_sends_sizing_when_set(api: SandboxAPI):
|
|
|
234
236
|
assert host.disk_gb == 100
|
|
235
237
|
|
|
236
238
|
|
|
239
|
+
@respx.mock
|
|
240
|
+
async def test_create_host_sends_cpu_and_memory_when_set(api: SandboxAPI):
|
|
241
|
+
route = respx.post(f"{BASE_URL}/hosts").mock(
|
|
242
|
+
return_value=httpx.Response(201, json=_host_payload()),
|
|
243
|
+
)
|
|
244
|
+
|
|
245
|
+
await api.create_host(cpu=8, memory_gb=16)
|
|
246
|
+
|
|
247
|
+
body = route.calls.last.request.content.decode()
|
|
248
|
+
assert '"cpu":8' in body
|
|
249
|
+
assert '"memory_gb":16' in body
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
@respx.mock
|
|
253
|
+
async def test_create_host_sends_only_the_size_it_is_given(api: SandboxAPI):
|
|
254
|
+
route = respx.post(f"{BASE_URL}/hosts").mock(
|
|
255
|
+
return_value=httpx.Response(201, json=_host_payload()),
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
await api.create_host(cpu=4)
|
|
259
|
+
|
|
260
|
+
body = route.calls.last.request.content.decode()
|
|
261
|
+
assert '"cpu":4' in body
|
|
262
|
+
assert "memory_gb" not in body
|
|
263
|
+
|
|
264
|
+
|
|
237
265
|
@respx.mock
|
|
238
266
|
async def test_create_host_sends_provider_when_set(api: SandboxAPI):
|
|
239
267
|
payload = _host_payload(provider="hetzner")
|
|
@@ -633,6 +661,19 @@ async def test_get_template_returns_parsed_template(api: SandboxAPI):
|
|
|
633
661
|
assert template.status == "available"
|
|
634
662
|
assert template.image == "derived:image"
|
|
635
663
|
assert template.last_used_at == payload["last_used_at"]
|
|
664
|
+
assert template.build_step == ""
|
|
665
|
+
|
|
666
|
+
|
|
667
|
+
@respx.mock
|
|
668
|
+
async def test_get_template_carries_the_build_step(api: SandboxAPI):
|
|
669
|
+
payload = _template_payload(build_step="running setup script: Installing nodejs")
|
|
670
|
+
respx.get(f"{BASE_URL}/templates/{payload['id']}").mock(
|
|
671
|
+
return_value=httpx.Response(200, json=payload),
|
|
672
|
+
)
|
|
673
|
+
|
|
674
|
+
template = await api.get_template(payload["id"])
|
|
675
|
+
|
|
676
|
+
assert template.build_step == "running setup script: Installing nodejs"
|
|
636
677
|
|
|
637
678
|
|
|
638
679
|
@respx.mock
|
|
@@ -744,6 +785,20 @@ async def test_422_raises_sandbox_validation_error(api: SandboxAPI):
|
|
|
744
785
|
await api.create_host(env={"FOO BAR": "x"})
|
|
745
786
|
|
|
746
787
|
|
|
788
|
+
@respx.mock
|
|
789
|
+
async def test_422_string_detail_raises_sandbox_validation_error(api: SandboxAPI):
|
|
790
|
+
# Drukbox answers a refused secret with the issuer's reason as a plain string.
|
|
791
|
+
respx.post(f"{BASE_URL}/hosts").mock(
|
|
792
|
+
return_value=httpx.Response(
|
|
793
|
+
422,
|
|
794
|
+
json={"detail": "GitHub App not installed for acme", "error_code": "SECRET_REFUSED"},
|
|
795
|
+
),
|
|
796
|
+
)
|
|
797
|
+
|
|
798
|
+
with pytest.raises(SandboxValidationError, match=r"^GitHub App not installed for acme$"):
|
|
799
|
+
await api.create_host()
|
|
800
|
+
|
|
801
|
+
|
|
747
802
|
@respx.mock
|
|
748
803
|
async def test_500_raises_sandbox_response_error(api: SandboxAPI):
|
|
749
804
|
respx.get(f"{BASE_URL}/hosts").mock(
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|