diff --git a/docs/user/include_jinja_list.md b/docs/user/include_jinja_list.md index a17f8d9e..3b6addc7 100644 --- a/docs/user/include_jinja_list.md +++ b/docs/user/include_jinja_list.md @@ -17,8 +17,8 @@ | feature_compliance | netutils.config.compliance.feature_compliance | | find_unordered_cfg_lines | netutils.config.compliance.find_unordered_cfg_lines | | section_config | netutils.config.compliance.section_config | -| palo_alto_clean_newlines | netutils.config.conversion.palo_alto_clean_newlines | | paloalto_panos_brace_to_set | netutils.config.conversion.paloalto_panos_brace_to_set | +| paloalto_panos_clean_newlines | netutils.config.conversion.paloalto_panos_clean_newlines | | fqdn_to_ip | netutils.dns.fqdn_to_ip | | is_fqdn_resolvable | netutils.dns.is_fqdn_resolvable | | hash_data | netutils.hash.hash_data | diff --git a/netutils/config/conversion.py b/netutils/config/conversion.py index 114e8e74..dd3caff2 100644 --- a/netutils/config/conversion.py +++ b/netutils/config/conversion.py @@ -10,7 +10,7 @@ } -def palo_alto_clean_newlines(cfg: str) -> str: +def paloalto_panos_clean_newlines(cfg: str) -> str: r"""Takes in the configuration and replaces any inappropriate newline characters with a space. Args: @@ -20,7 +20,7 @@ def palo_alto_clean_newlines(cfg: str) -> str: str: Cleaned configuration as a string Examples: - >>> from netutils.config.conversion import palo_alto_clean_newlines + >>> from netutils.config.conversion import paloalto_panos_clean_newlines >>> config = ''' ... config { ... syslog { @@ -64,7 +64,7 @@ def palo_alto_clean_newlines(cfg: str) -> str: ... } ... } ... }''' - >>> palo_alto_clean_newlines(cfg=config) == \ + >>> paloalto_panos_clean_newlines(cfg=config) == \ ... ''' ... config { ... syslog { @@ -108,14 +108,14 @@ def palo_alto_clean_newlines(cfg: str) -> str: ... }''' True """ - palo_alto_no_newline_cleanup_match = ["private-key", "public-key", "login-banner"] - palo_alto_newline_regex = re.compile( + paloalto_panos_no_newline_cleanup_match = ["private-key", "public-key", "login-banner"] + paloalto_panos_newline_regex = re.compile( r"\w+?-?\w+\s\"(?:[^\"\\]|\\.)*\n(?:[^\"\\]|\\.)*\";$", re.MULTILINE | re.DOTALL ) - newlines_cleaned_cfg = palo_alto_newline_regex.sub( + newlines_cleaned_cfg = paloalto_panos_newline_regex.sub( lambda match: match.group().replace("\n", " ") - if not any(substring in match.group() for substring in palo_alto_no_newline_cleanup_match) + if not any(substring in match.group() for substring in paloalto_panos_no_newline_cleanup_match) else match.group(), cfg, ) @@ -175,9 +175,9 @@ def paloalto_panos_brace_to_set(cfg: str, cfg_type: str = "file") -> str: raise ValueError("The variable `cfg_type` must be either `file` or `string`.") if cfg_type == "file": cfg_raw = _open_file_config(cfg) - cfg_list = palo_alto_clean_newlines(cfg=cfg_raw).splitlines() + cfg_list = paloalto_panos_clean_newlines(cfg=cfg_raw).splitlines() else: - cfg_raw = palo_alto_clean_newlines(cfg=cfg) + cfg_raw = paloalto_panos_clean_newlines(cfg=cfg) cfg_list = cfg_raw.splitlines() for i, line in enumerate(cfg_list): diff --git a/netutils/utils.py b/netutils/utils.py index dd69ed28..602324e2 100644 --- a/netutils/utils.py +++ b/netutils/utils.py @@ -86,7 +86,7 @@ "uptime_seconds_to_string": "time.uptime_seconds_to_string", "uptime_string_to_seconds": "time.uptime_string_to_seconds", "get_napalm_getters": "lib_helpers.get_napalm_getters", - "palo_alto_clean_newlines": "config.conversion.palo_alto_clean_newlines", + "paloalto_panos_clean_newlines": "config.conversion.paloalto_panos_clean_newlines", "paloalto_panos_brace_to_set": "config.conversion.paloalto_panos_brace_to_set", "compare_version_loose": "os_version.compare_version_loose", "compare_version_strict": "os_version.compare_version_strict", diff --git a/tests/unit/test_sanitize.py b/tests/unit/test_sanitize.py index 39afbd95..9d21ede4 100644 --- a/tests/unit/test_sanitize.py +++ b/tests/unit/test_sanitize.py @@ -4,7 +4,7 @@ import pytest from netutils.config import compliance -from netutils.config.conversion import palo_alto_clean_newlines +from netutils.config.conversion import paloalto_panos_clean_newlines MOCK_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "mock", "config", "sanitize") @@ -23,6 +23,6 @@ def test_panos_newline_character(_file, get_text_data): truncate_file = os.path.join(MOCK_DIR, _file[0][: -len(TXT_FILE)]) sent_cfg = get_text_data(os.path.join(MOCK_DIR, _file[0])) - sanitized_cfg = palo_alto_clean_newlines(cfg=sent_cfg) + sanitized_cfg = paloalto_panos_clean_newlines(cfg=sent_cfg) received_data = get_text_data(truncate_file + "_sanitized.txt") assert sanitized_cfg == received_data