Skip to content

Commit 0fdb80e

Browse files
committed
Merge branch 'release/0.6.6'
2 parents c96173c + b1e105f commit 0fdb80e

File tree

4 files changed

+95
-2
lines changed

4 files changed

+95
-2
lines changed

HISTORY.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
History
44
=======
55

6+
0.6.6
7+
-----
8+
9+
Released: 2018-10-16
10+
11+
Status: Alpha
12+
13+
- Added `test_security_policy_match()` to PanDevice objects
14+
615
0.6.5
716
-----
817

pandevice/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
__author__ = 'Palo Alto Networks'
2525
__email__ = '[email protected]'
26-
__version__ = '0.6.5'
26+
__version__ = '0.6.6'
2727

2828

2929
import logging

pandevice/base.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4521,3 +4521,87 @@ def request_password_hash(self, value):
45214521
raise ValueError('No password hash in response')
45224522

45234523
return elm.text
4524+
4525+
def test_security_policy_match(self, source, destination, protocol,
4526+
application=None, category=None, port=None, user=None,
4527+
from_zone=None, to_zone=None, show_all=False):
4528+
"""Test security policy match using the given criteria.
4529+
4530+
This function will always return a list for its results. If `show_all`
4531+
is set to False, then the list will only have one entry in it. The
4532+
keys in each dict are as follows:
4533+
* name (str): rule's name
4534+
* index (int): the index of the security rule
4535+
* action (str): the security rule's action
4536+
4537+
Args:
4538+
source (str): Source IP address.
4539+
destination (str): Destination IP address.
4540+
protocol (int): IP protocol value (1-255).
4541+
application (str): Application name.
4542+
category (str): Category name.
4543+
port (int): Destination port.
4544+
user (str): Source user.
4545+
from_zone (str): Source zone name.
4546+
to_zone (str): Destination zone name.
4547+
show_all (bool): Show all potential match rules until first allow.
4548+
4549+
Returns:
4550+
List of dicts
4551+
"""
4552+
extras = (
4553+
('application', application),
4554+
('category', category),
4555+
('destination-port', port),
4556+
('source-user', user),
4557+
('from', from_zone),
4558+
('to', to_zone),
4559+
('show-all', show_all),
4560+
)
4561+
4562+
# Build up the XML document.
4563+
root = ET.Element('test')
4564+
elm = ET.SubElement(root, 'security-policy-match')
4565+
4566+
# Add in required params.
4567+
ET.SubElement(elm, 'source').text = source
4568+
ET.SubElement(elm, 'destination').text = destination
4569+
ET.SubElement(elm, 'protocol').text = str(int(protocol))
4570+
4571+
# Add in the optional params.
4572+
for desc, val in extras:
4573+
if val is None:
4574+
continue
4575+
4576+
if desc == 'destination-port':
4577+
ET.SubElement(elm, desc).text = str(int(val))
4578+
elif desc == 'show-all':
4579+
ET.SubElement(elm, desc).text = 'yes' if val else 'no'
4580+
else:
4581+
ET.SubElement(elm, desc).text = val
4582+
4583+
# Run the test operation.
4584+
res = self.op(ET.tostring(root, encoding='utf-8'), cmd_xml=False)
4585+
4586+
# Build up the answer.
4587+
#
4588+
# Side note here: the XML document returned here does not follow the
4589+
# rules of the API, so we can't use the SecurityRule module to parse
4590+
# the results. For this reason, we won't parse everything, just
4591+
# name, index, and action.
4592+
ans = []
4593+
for elm in res.findall('./result/rules/entry'):
4594+
val = {
4595+
'name': elm.attrib['name'],
4596+
}
4597+
4598+
e = elm.find('./index')
4599+
val['index'] = 0 if e is None else int(e.text)
4600+
4601+
e = elm.find('./action')
4602+
val['action'] = '' if e is None else e.text
4603+
4604+
ans.append(val)
4605+
4606+
# Done.
4607+
return ans

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
setup(
2525
name='pandevice',
26-
version='0.6.5',
26+
version='0.6.6',
2727
description='Framework for interacting with Palo Alto Networks devices via API',
2828
long_description='The Palo Alto Networks Device Framework is a way to interact with Palo Alto Networks devices (including Next-generation Firewalls and Panorama) using the device API that is object oriented and conceptually similar to interaction with the device via the GUI or CLI.',
2929
author='Palo Alto Networks',

0 commit comments

Comments
 (0)