From 46d7125aa6f71af791b3c2704eeda425f3c9869b Mon Sep 17 00:00:00 2001 From: Christian Manivong Date: Thu, 12 Nov 2026 23:38:28 +0100 Subject: [PATCH] refactor(log-forwarding): a legacy rule's template is read on its own The quality ratchet holds _Reader.legacy at complexity 10. --- napalm_device_types/log_forwarding.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/napalm_device_types/log_forwarding.py b/napalm_device_types/log_forwarding.py index 486b07a..a6d60c5 100644 --- a/napalm_device_types/log_forwarding.py +++ b/napalm_device_types/log_forwarding.py @@ -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 --