1
0
Fork 0
mirror of https://github.com/ansible-collections/hetzner.hcloud.git synced 2026-02-04 08:01:49 +00:00

refactor: reuse format_txt_record helper

This commit is contained in:
jo 2025-11-07 20:21:05 +01:00
parent b20cf937ea
commit 57930767ab
No known key found for this signature in database
GPG key ID: B2FEC9B22722B984
2 changed files with 5 additions and 10 deletions

View file

View file

@ -5,6 +5,8 @@ from typing import Literal
from ansible.errors import AnsibleFilterError
from ansible.module_utils.common.text.converters import to_native
from ..module_utils.vendor.hcloud.exp.zone import format_txt_record
# pylint: disable=unused-argument
def load_balancer_status(load_balancer: dict, *args, **kwargs) -> Literal["unknown", "unhealthy", "healthy"]:
@ -50,18 +52,11 @@ def load_balancer_status(load_balancer: dict, *args, **kwargs) -> Literal["unkno
# pylint: disable=unused-argument
def txt_record(record: str, *args, **kwargs) -> str:
"""
Return the status of a Load Balancer based on its targets.
Format a TXT record by splitting it in quoted strings of 255 characters.
Existing quotes will be escaped.
"""
try:
record = record.replace('"', '\\"')
parts = []
for start in range(0, len(record), 255):
end = min(start + 255, len(record))
parts.append('"' + record[start:end] + '"')
record = " ".join(parts)
return record
return format_txt_record(record)
except Exception as exc:
raise AnsibleFilterError(f"txt_record - {to_native(exc)}", orig_exc=exc) from exc