Skip to content

Commit af58621

Browse files
committed
feat: change protection
1 parent d22caff commit af58621

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

hcloud/storage_boxes/client.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,3 +396,28 @@ def get_actions(
396396
status=status,
397397
sort=sort,
398398
)
399+
400+
def change_protection(
401+
self,
402+
storage_box: StorageBox | BoundStorageBox,
403+
*,
404+
delete: bool | None = None,
405+
) -> BoundAction:
406+
"""
407+
Changes the protection of a Storage Box.
408+
409+
See https://docs.hetzner.cloud/reference/cloud#TODO
410+
411+
:param storage_box: Storage Box to update.
412+
:param delete: Prevents the Storage Box from being deleted.
413+
"""
414+
data: dict[str, Any] = {}
415+
if delete is not None:
416+
data["delete"] = delete
417+
418+
response = self._client.request(
419+
method="POST",
420+
url=f"{self._base_url}/{storage_box.id}/actions/change_protection",
421+
json=data,
422+
)
423+
return BoundAction(self._parent.actions, response["action"])

tests/unit/storage_boxes/test_client.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,3 +309,21 @@ def test_get_folders(
309309
)
310310

311311
assert result.folders == ["dir1", "dir2"]
312+
313+
def test_change_protection(
314+
self,
315+
request_mock: mock.MagicMock,
316+
resource_client: StorageBoxesClient,
317+
action_response,
318+
):
319+
request_mock.return_value = action_response
320+
321+
action = resource_client.change_protection(StorageBox(id=42), delete=True)
322+
323+
request_mock.assert_called_with(
324+
method="POST",
325+
url="/storage_boxes/42/actions/change_protection",
326+
json={"delete": True},
327+
)
328+
329+
assert_bound_action1(action, resource_client._parent.actions)

0 commit comments

Comments
 (0)