Skip to content

Commit

Permalink
Check only root level banner messages for ASA configs (#602)
Browse files Browse the repository at this point in the history
* Check only root level banner messages for ASA configs

---------

Co-authored-by: Carlos Huaccho <[email protected]>
  • Loading branch information
huacchob and carlitos75 authored Dec 20, 2024
1 parent b35bad3 commit 9c7e197
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
17 changes: 17 additions & 0 deletions netutils/config/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,7 @@ def banner_end(self) -> str:
class ASAConfigParser(CiscoConfigParser):
"""Cisco ASA implementation of ConfigParser Class."""

banner_start: t.List[str] = ["banner"]
comment_chars: t.List[str] = ["!", ":"]

def __init__(self, config: str):
Expand All @@ -925,6 +926,22 @@ def __init__(self, config: str):
self.same_line_children: t.Set[ConfigLine] = set()
super(ASAConfigParser, self).__init__(config)

def is_banner_start(self, line: str) -> bool:
"""Determine if the line starts a banner config.
Args:
line: The current config line in iteration.
Returns:
True if line starts banner, else False.
"""
for banner_start in self.banner_start:
if not line:
return False
if line.startswith(banner_start):
return True
return False

def _update_config_lines(self, config_line: str) -> None:
"""Add a ``ConfigLine`` object to ``self.config_lines``.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from netutils.config.parser import ConfigLine

data = [
ConfigLine(config_line="group-policy Grs-POLICY attributes", parents=()),
ConfigLine(
config_line=" banner value This is an",
parents=("group-policy Grs-POLICY attributes",),
),
ConfigLine(
config_line=" banner value example nested banner",
parents=("group-policy Grs-POLICY attributes",),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
group-policy Grs-POLICY attributes
banner value This is an
banner value example nested banner
1 change: 1 addition & 0 deletions tests/unit/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os

import pytest

from netutils.config import compliance

MOCK_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "mock", "config", "parser")
Expand Down

0 comments on commit 9c7e197

Please sign in to comment.