mirror of
https://github.com/ansible-collections/hetzner.hcloud.git
synced 2026-02-04 08:01:49 +00:00
implement reset password
This commit is contained in:
parent
cb5fee77d0
commit
018c0071a4
2 changed files with 36 additions and 1 deletions
|
|
@ -185,6 +185,7 @@ hcloud_storage_box_subaccount:
|
|||
"""
|
||||
|
||||
from ..module_utils import storage_box, storage_box_subaccount
|
||||
from ..module_utils.client import client_resource_not_found
|
||||
from ..module_utils.hcloud import AnsibleHCloud, AnsibleModule
|
||||
from ..module_utils.storage_box_subaccount import NAME_LABEL_KEY
|
||||
from ..module_utils.vendor.hcloud import HCloudException
|
||||
|
|
@ -338,6 +339,27 @@ class AnsibleStorageBoxSnapshot(AnsibleHCloud):
|
|||
except HCloudException as exception:
|
||||
self.fail_json_hcloud(exception)
|
||||
|
||||
def reset_password(self):
|
||||
self.fail_on_invalid_params(
|
||||
required=["password"],
|
||||
)
|
||||
try:
|
||||
self._fetch()
|
||||
if self.storage_box_subaccount is None:
|
||||
raise client_resource_not_found(
|
||||
"storage box",
|
||||
self.module.params.get("id") or self.module.params.get("name"),
|
||||
)
|
||||
if not self.module.check_mode:
|
||||
action = self.storage_box_subaccount.reset_password(self.module.params.get("password"))
|
||||
self.actions.append(action)
|
||||
self._wait_actions()
|
||||
|
||||
self._mark_as_changed()
|
||||
|
||||
except HCloudException as exception:
|
||||
self.fail_json_hcloud(exception)
|
||||
|
||||
@classmethod
|
||||
def define_module(cls):
|
||||
return AnsibleModule(
|
||||
|
|
@ -375,7 +397,8 @@ def main():
|
|||
o = AnsibleStorageBoxSnapshot(module)
|
||||
|
||||
match module.params.get("state"):
|
||||
# TODO: reset password
|
||||
case "reset_password":
|
||||
o.reset_password()
|
||||
case "absent":
|
||||
o.absent()
|
||||
case _:
|
||||
|
|
|
|||
|
|
@ -154,6 +154,18 @@
|
|||
- result.hcloud_storage_box_subaccount.access_settings.readonly == true
|
||||
- result.hcloud_storage_box_subaccount.created is not none
|
||||
|
||||
- name: Test reset password
|
||||
hetzner.hcloud.storage_box_subaccount:
|
||||
storage_box: "{{ test_storage_box.hcloud_storage_box.id }}"
|
||||
name: team2
|
||||
password: "{{ hcloud_storage_box_password }}"
|
||||
state: reset_password
|
||||
register: result
|
||||
- name: Verify reset password
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- result is changed
|
||||
|
||||
- name: Test delete
|
||||
hetzner.hcloud.storage_box_subaccount:
|
||||
storage_box: "{{ test_storage_box.hcloud_storage_box.id }}"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue