Debian Codegraph @

ansible_collections/hetzner/hcloud/plugins/module_utils/_storage_box_subaccount.py

raw
1 # Note that this module util is **PRIVATE** to the collection. It can have breaking changes at any time.
2 # Do not use this from other collections or standalone plugins/modules!
3
4 from __future__ import annotations
5
6 from ._vendor.hcloud.storage_boxes import (
7 BoundStorageBox,
8 BoundStorageBoxSubaccount,
9 )
10
11 NAME_LABEL_KEY = "ansible-name"
12
13
14 def get_by_label_name(storage_box: BoundStorageBox, name: str):
15 """
16 Kept for backward compatible upgrade from label based name.
17 """
18 result = storage_box.get_subaccount_list(
19 label_selector=f"{NAME_LABEL_KEY}={name}",
20 )
21 if len(result.subaccounts) == 1:
22 return result.subaccounts[0]
23 return None
24
25
26 def prepare_result(o: BoundStorageBoxSubaccount):
27 return {
28 "storage_box": o.storage_box.id,
29 "id": o.id,
30 "name": o.name,
31 "description": o.description,
32 "username": o.username,
33 "home_directory": o.home_directory,
34 "server": o.server,
35 "access_settings": {
36 "reachable_externally": o.access_settings.reachable_externally,
37 "samba_enabled": o.access_settings.samba_enabled,
38 "ssh_enabled": o.access_settings.ssh_enabled,
39 "webdav_enabled": o.access_settings.webdav_enabled,
40 "readonly": o.access_settings.readonly,
41 },
42 "labels": o.labels,
43 "created": o.created.isoformat(),
44 }