refactor(log-forwarding): a legacy rule's template is read on its own
driver / standard (pull_request) Successful in 17s
driver / lint (pull_request) Successful in 14s
driver / types (pull_request) Successful in 58s
driver / test (3.12) (pull_request) Successful in 1m21s
driver / test (3.13) (pull_request) Successful in 1m8s
driver / lowest (pull_request) Successful in 40s
driver / build (pull_request) Successful in 29s
driver / security (pull_request) Successful in 1m4s
CI / driver (pull_request) Successful in 2m57s
driver / publish (pull_request) Skipped

The quality ratchet holds _Reader.legacy at complexity 10.
This commit is contained in:
christianmanivong committed 2026-11-12 23:38:28 +01:00
1 parent 8e43fe2ed9
commit 46d7125aa6
1 file changed
+9 -5
+9 -5
View File
@@ -289,19 +289,23 @@ class _Reader:
forward = _FORWARD_RE.match(action)
if forward:
protocol = {"@": "udp", "@@": "tcp"}.get(forward["at"] or "", "relp")
_, semicolon, named = action[forward.end() :].partition(";")
template = named.strip() if semicolon and named.strip() else None
if template is None and protocol != "relp":
template = self.legacy_template
self.forward(
protocol,
forward["v6"] or forward["host"],
_port(forward["port"]),
selector,
once,
template,
self.legacy_template_of(action[forward.end() :], protocol),
)
def legacy_template_of(self, rest: str, protocol: str) -> str | None:
"""The template after a legacy rule's target (``;Name``), else the default
set before it; RELP takes no forwarding default."""
_, semicolon, named = rest.partition(";")
if semicolon and named.strip():
return named.strip()
return self.legacy_template if protocol != "relp" else None
def parse_rsyslog(text: str) -> RsyslogDict:
"""rsyslog's configuration -- ``rsyslog.conf`` and ``rsyslog.d`` as one text --