Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading