Skip to content

Commit 6aef4f7

Browse files
authored
Fix Palo set format config parsing if curly brace exists (#651)
* allow curly braces in palo set format * switch to splitlines
1 parent 25e086c commit 6aef4f7

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

netutils/config/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1550,7 +1550,7 @@ def build_config_relationship(self) -> t.List[ConfigLine]: # pylint: disable=to
15501550

15511551
# if config is in palo brace format, convert to set
15521552
if self.config_lines_only is not None:
1553-
for line in self.config_lines_only:
1553+
for line in self.config_lines_only.splitlines():
15541554
if line.endswith("{"):
15551555
_needs_conversion = True
15561556
if _needs_conversion:
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from netutils.config.parser import ConfigLine
2+
3+
data = [
4+
ConfigLine(
5+
config_line="set mgt-config users admin phash *",
6+
parents=(),
7+
),
8+
ConfigLine(
9+
config_line="set mgt-config users admin permissions role-based superuser yes",
10+
parents=(),
11+
),
12+
ConfigLine(
13+
config_line="set mgt-config users admin public-key thisisasuperduperlongbase64encodedstring",
14+
parents=(),
15+
),
16+
ConfigLine(
17+
config_line="set mgt-config users panadmin permissions role-based superuser yes",
18+
parents=(),
19+
),
20+
ConfigLine(
21+
config_line="set mgt-config users panadmin phash passwordhash",
22+
parents=(),
23+
),
24+
ConfigLine(
25+
config_line="set deviceconfig system hostname firewall1",
26+
parents=(),
27+
),
28+
ConfigLine(
29+
config_line='set deviceconfig system login-banner "',
30+
parents=(),
31+
),
32+
ConfigLine(
33+
config_line="************************************************************************\n* firewall1.example.com * [PROD VM500 firewalls]\n************************************************************************\n* WARNING *\n* Unauthorized access to this device or devices attached to *\n* or accessible from this network is strictly prohibited. *\n* Possession of passwords or devices enabling access to this *\n* device or devices does not constitute authorization. Unauthorized *\n* access will be prosecuted to the fullest extent of the law. *\n* *\n************************************************************************^C",
34+
parents=('set deviceconfig system login-banner "',),
35+
),
36+
ConfigLine(
37+
config_line="set deviceconfig system panorama local-panorama panorama-server 10.0.0.1",
38+
parents=(),
39+
),
40+
ConfigLine(
41+
config_line="set deviceconfig system panorama local-panorama panorama-server-2 10.0.0.2",
42+
parents=(),
43+
),
44+
ConfigLine(
45+
config_line='set network interface ethernet ethernet1/15 comment "test curly braces {REMOTE DEVICE}, {REMOTE PORT}"',
46+
parents=(),
47+
),
48+
]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
set mgt-config users admin phash *
2+
set mgt-config users admin permissions role-based superuser yes
3+
set mgt-config users admin public-key thisisasuperduperlongbase64encodedstring
4+
set mgt-config users panadmin permissions role-based superuser yes
5+
set mgt-config users panadmin phash passwordhash
6+
set deviceconfig system hostname firewall1
7+
set deviceconfig system login-banner "
8+
************************************************************************
9+
* firewall1.example.com * [PROD VM500 firewalls]
10+
************************************************************************
11+
* WARNING *
12+
* Unauthorized access to this device or devices attached to *
13+
* or accessible from this network is strictly prohibited. *
14+
* Possession of passwords or devices enabling access to this *
15+
* device or devices does not constitute authorization. Unauthorized *
16+
* access will be prosecuted to the fullest extent of the law. *
17+
* *
18+
************************************************************************"
19+
20+
set deviceconfig system panorama local-panorama panorama-server 10.0.0.1
21+
set deviceconfig system panorama local-panorama panorama-server-2 10.0.0.2
22+
set network interface ethernet ethernet1/15 comment "test curly braces {REMOTE DEVICE}, {REMOTE PORT}"

0 commit comments

Comments
 (0)