Debian Codegraph @

ansible_collections/community/proxmox/plugins/module_utils/proxmox_acme_plugin.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 plugin."""
7
8 from ansible.module_utils.common.text.converters import to_native
9
10 from ansible_collections.community.proxmox.plugins.module_utils.proxmox import (
11 proxmox_to_ansible_bool,
12 )
13
14
15 def acme_plugin_normalize_data_dict(data):
16 """Normalize plugin data dict to native strings."""
17 if not data:
18 return {}
19 return {to_native(k): to_native(v) for k, v in data.items()}
20
21
22 def acme_plugin_data_from_api(raw):
23 """Parse Proxmox plugin data string into a dict."""
24 data = {}
25 for raw_line in raw.splitlines():
26 line = raw_line.strip()
27 if not line or "=" not in line:
28 continue
29 key, val = line.split("=", 1)
30 data[key.strip()] = val.strip()
31 return data
32
33
34 def acme_plugin_to_ansible_result(raw):
35 """Build Ansible module result fields from GET /cluster/acme/plugins/{name} JSON."""
36 data_raw = raw.get("data", "")
37 data = acme_plugin_normalize_data_dict(acme_plugin_data_from_api(data_raw))
38
39 return {
40 "type": raw.get("type"),
41 "name": raw.get("plugin"),
42 "plugin": raw.get("api", ""),
43 "disable": proxmox_to_ansible_bool(raw.get("disable", False)),
44 "validation_delay": int(raw.get("validation-delay", 30)),
45 "data": data,
46 "digest": raw.get("digest", ""),
47 }