Skip to content

File tree

2 files changed

+154
-0
lines changed

2 files changed

+154
-0
lines changed

hcloud/storage_boxes/client.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,3 +1046,82 @@ def delete_subaccount(
10461046
return DeleteStorageBoxSubaccountResponse(
10471047
action=BoundAction(self._parent.actions, response["action"]),
10481048
)
1049+
1050+
def change_subaccount_home_directory(
1051+
self,
1052+
subaccount: StorageBoxSubaccount | BoundStorageBoxSubaccount,
1053+
home_directory: str,
1054+
) -> BoundAction:
1055+
"""
1056+
Change the home directory of a Storage Box Subaccount.
1057+
1058+
See https://docs.hetzner.cloud/reference/hetzner#storage-box-subaccount-actions-change-home-directory
1059+
1060+
:param subaccount: Storage Box Subaccount to update.
1061+
:param home_directory: Home directory for the Subaccount.
1062+
"""
1063+
if subaccount.storage_box is None:
1064+
raise ValueError("subaccount storage_box property is none")
1065+
1066+
data: dict[str, Any] = {
1067+
"home_directory": home_directory,
1068+
}
1069+
1070+
response = self._client.request(
1071+
method="POST",
1072+
url=f"{self._base_url}/{subaccount.storage_box.id}/subaccounts/{subaccount.id}/actions/change_home_directory",
1073+
json=data,
1074+
)
1075+
return BoundAction(self._parent.actions, response["action"])
1076+
1077+
def reset_subaccount_password(
1078+
self,
1079+
subaccount: StorageBoxSubaccount | BoundStorageBoxSubaccount,
1080+
password: str,
1081+
) -> BoundAction:
1082+
"""
1083+
Reset the password of a Storage Box Subaccount.
1084+
1085+
See https://docs.hetzner.cloud/reference/hetzner#storage-box-subaccount-actions-reset-password
1086+
1087+
:param subaccount: Storage Box Subaccount to update.
1088+
:param password: Password for the Subaccount.
1089+
"""
1090+
if subaccount.storage_box is None:
1091+
raise ValueError("subaccount storage_box property is none")
1092+
1093+
data: dict[str, Any] = {
1094+
"password": password,
1095+
}
1096+
1097+
response = self._client.request(
1098+
method="POST",
1099+
url=f"{self._base_url}/{subaccount.storage_box.id}/subaccounts/{subaccount.id}/actions/reset_subaccount_password",
1100+
json=data,
1101+
)
1102+
return BoundAction(self._parent.actions, response["action"])
1103+
1104+
def update_subaccount_access_settings(
1105+
self,
1106+
subaccount: StorageBoxSubaccount | BoundStorageBoxSubaccount,
1107+
access_settings: StorageBoxSubaccountAccessSettings,
1108+
) -> BoundAction:
1109+
"""
1110+
Update the access settings of a Storage Box Subaccount.
1111+
1112+
See https://docs.hetzner.cloud/reference/hetzner#storage-box-subaccount-actions-update-access-settings
1113+
1114+
:param subaccount: Storage Box Subaccount to update.
1115+
:param access_settings: Access settings for the Subaccount.
1116+
"""
1117+
if subaccount.storage_box is None:
1118+
raise ValueError("subaccount storage_box property is none")
1119+
1120+
data: dict[str, Any] = access_settings.to_payload()
1121+
1122+
response = self._client.request(
1123+
method="POST",
1124+
url=f"{self._base_url}/{subaccount.storage_box.id}/subaccounts/{subaccount.id}/actions/update_access_settings",
1125+
json=data,
1126+
)
1127+
return BoundAction(self._parent.actions, response["action"])

tests/unit/storage_boxes/test_client.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,3 +1045,78 @@ def test_delete_subaccount(
10451045
)
10461046

10471047
assert_bound_action1(result.action, resource_client._parent.actions)
1048+
1049+
def test_change_subaccount_home_directory(
1050+
self,
1051+
request_mock: mock.MagicMock,
1052+
resource_client: StorageBoxesClient,
1053+
action_response,
1054+
):
1055+
request_mock.return_value = action_response
1056+
1057+
action = resource_client.change_subaccount_home_directory(
1058+
StorageBoxSubaccount(id=45, storage_box=StorageBox(42)),
1059+
home_directory="path",
1060+
)
1061+
1062+
request_mock.assert_called_with(
1063+
method="POST",
1064+
url="/storage_boxes/42/subaccounts/45/actions/change_home_directory",
1065+
json={
1066+
"home_directory": "path",
1067+
},
1068+
)
1069+
1070+
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)
1094+
1095+
def test_update_subaccount_access_settings(
1096+
self,
1097+
request_mock: mock.MagicMock,
1098+
resource_client: StorageBoxesClient,
1099+
action_response,
1100+
):
1101+
request_mock.return_value = action_response
1102+
1103+
action = resource_client.update_subaccount_access_settings(
1104+
StorageBoxSubaccount(id=45, storage_box=StorageBox(42)),
1105+
access_settings=StorageBoxSubaccountAccessSettings(
1106+
reachable_externally=True,
1107+
ssh_enabled=True,
1108+
samba_enabled=False,
1109+
),
1110+
)
1111+
1112+
request_mock.assert_called_with(
1113+
method="POST",
1114+
url="/storage_boxes/42/subaccounts/45/actions/update_access_settings",
1115+
json={
1116+
"reachable_externally": True,
1117+
"ssh_enabled": True,
1118+
"samba_enabled": False,
1119+
},
1120+
)
1121+
1122+
assert_bound_action1(action, resource_client._parent.actions)

0 commit comments

Comments
 (0)