Skip to content

Commit 8ef683c

Browse files
committed
feat: reset_subaccount_password
1 parent 4ddca12 commit 8ef683c

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

hcloud/storage_boxes/client.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,3 +1070,27 @@ def change_subaccount_home_directory(
10701070
json=data,
10711071
)
10721072
return BoundAction(self._parent.actions, response["action"])
1073+
1074+
def reset_subaccount_password(
1075+
self,
1076+
subaccount: StorageBoxSubaccount | BoundStorageBoxSubaccount,
1077+
password: str,
1078+
) -> BoundAction:
1079+
"""
1080+
Reset the password of a Storage Box Subaccount.
1081+
1082+
See https://docs.hetzner.cloud/reference/hetzner#storage-box-subaccount-actions-reset-password
1083+
1084+
:param subaccount: Storage Box Subaccount to update.
1085+
:param password: Password for the Subaccount.
1086+
"""
1087+
data: dict[str, Any] = {
1088+
"password": password,
1089+
}
1090+
1091+
response = self._client.request(
1092+
method="POST",
1093+
url=f"{self._base_url}/{subaccount.storage_box.id}/subaccounts/{subaccount.id}/actions/reset_subaccount_password",
1094+
json=data,
1095+
)
1096+
return BoundAction(self._parent.actions, response["action"])

tests/unit/storage_boxes/test_client.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,3 +1068,26 @@ def test_change_subaccount_home_directory(
10681068
)
10691069

10701070
assert_bound_action1(action, resource_client._parent.actions)
1071+
1072+
def test_reset_subaccount_password(
1073+
self,
1074+
request_mock: mock.MagicMock,
1075+
resource_client: StorageBoxesClient,
1076+
action_response,
1077+
):
1078+
request_mock.return_value = action_response
1079+
1080+
action = resource_client.reset_subaccount_password(
1081+
StorageBoxSubaccount(id=45, storage_box=StorageBox(42)),
1082+
password="password",
1083+
)
1084+
1085+
request_mock.assert_called_with(
1086+
method="POST",
1087+
url="/storage_boxes/42/subaccounts/45/actions/reset_subaccount_password",
1088+
json={
1089+
"password": "password",
1090+
},
1091+
)
1092+
1093+
assert_bound_action1(action, resource_client._parent.actions)

0 commit comments

Comments
 (0)