Skip to content

Commit 28bcf34

Browse files
committed
feat: reset password
1 parent 678c119 commit 28bcf34

2 files changed

Lines changed: 49 additions & 1 deletion

File tree

hcloud/storage_boxes/client.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,11 +435,38 @@ def change_type(
435435
:param storage_box: Storage Box to update.
436436
:param storage_box_type: Type of Storage Box to change to.
437437
"""
438-
data: dict[str, Any] = {"storage_box_type": storage_box_type.id_or_name}
438+
data: dict[str, Any] = {
439+
"storage_box_type": storage_box_type.id_or_name,
440+
}
439441

440442
response = self._client.request(
441443
method="POST",
442444
url=f"{self._base_url}/{storage_box.id}/actions/change_type",
443445
json=data,
444446
)
445447
return BoundAction(self._parent.actions, response["action"])
448+
449+
def reset_password(
450+
self,
451+
storage_box: StorageBox | BoundStorageBox,
452+
*,
453+
password: str,
454+
) -> BoundAction:
455+
"""
456+
Reset the password of a Storage Box.
457+
458+
See https://docs.hetzner.cloud/reference/cloud#TODO
459+
460+
:param storage_box: Storage Box to update.
461+
:param password: Password for the Storage Box.
462+
"""
463+
data: dict[str, Any] = {
464+
"password": password,
465+
}
466+
467+
response = self._client.request(
468+
method="POST",
469+
url=f"{self._base_url}/{storage_box.id}/actions/reset_password",
470+
json=data,
471+
)
472+
return BoundAction(self._parent.actions, response["action"])

tests/unit/storage_boxes/test_client.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,24 @@ def test_change_type(
348348
)
349349

350350
assert_bound_action1(action, resource_client._parent.actions)
351+
352+
def test_reset_password(
353+
self,
354+
request_mock: mock.MagicMock,
355+
resource_client: StorageBoxesClient,
356+
action_response,
357+
):
358+
request_mock.return_value = action_response
359+
360+
action = resource_client.reset_password(
361+
StorageBox(id=42),
362+
password="password",
363+
)
364+
365+
request_mock.assert_called_with(
366+
method="POST",
367+
url="/storage_boxes/42/actions/reset_password",
368+
json={"password": "password"},
369+
)
370+
371+
assert_bound_action1(action, resource_client._parent.actions)

0 commit comments

Comments
 (0)