Debian Codegraph @

ansible_collections/community/proxmox/plugins/module_utils/proxmox_acme_account.py

raw
1 #
2 # Copyright (c) 2026, Clément Cruau (@PendaGTP) <[email protected]>
3 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
4 # SPDX-License-Identifier: GPL-3.0-or-later
5
6 """Helpers for Proxmox ACME account."""
7
8 from ansible.module_utils.common.text.converters import to_native
9
10 MAILTO_PREFIX = "mailto:"
11
12
13 def normalize_contact_list(contacts):
14 """Normalize API contact entries (e.g. mailto:) to plain email strings."""
15 if contacts is None:
16 return []
17 out = []
18 for contact in contacts:
19 s = to_native(contact).strip()
20 if s.startswith(MAILTO_PREFIX):
21 out.append(s[len(MAILTO_PREFIX) :].strip())
22 else:
23 out.append(s)
24 return out
25
26
27 def acme_account_to_ansible_result(data):
28 """Build Ansible module result fields from GET /cluster/acme/account/{name} JSON."""
29 acc = data.get("account") or {}
30 return {
31 "directory": data.get("directory") or "",
32 "location": data.get("location") or "",
33 "tos": data.get("tos") or "",
34 "account": {
35 "contact": normalize_contact_list(acc.get("contact")),
36 "created_at": acc.get("createdAt") or "",
37 "status": acc.get("status") or "",
38 },
39 }