Skip to content

Commit

Permalink
Reduce deviations from original code
Browse files Browse the repository at this point in the history
  • Loading branch information
jorund1 committed Nov 14, 2024
1 parent 8503acf commit fe3a967
Showing 1 changed file with 18 additions and 28 deletions.
46 changes: 18 additions & 28 deletions python/nav/ipdevpoll/plugins/paloaltoarp.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
ipdevpoll plugin for fetching arp mappings from Palo Alto firewalls
Configure a netbox to work with this plugin by assigning it a
HTTP_REST_API management profile with service set to "Palo Alto ARP"
HTTP_API management profile with service set to "Palo Alto ARP"
in seedDB.
"""

Expand All @@ -42,13 +42,7 @@ class PaloaltoArp(Arp):
@classmethod
@defer.inlineCallbacks
def can_handle(cls, netbox):
"""
Return True if this plugin can handle the given netbox.
A netbox can be handled if there is any HTTP_REST_API management profile
associated with the netbox with "service" set to "Palo Alto ARP" in the
profile's configuration dict.
"""
"""Return True if this plugin can handle the given netbox."""
has_configurations = yield cls._has_paloalto_configurations(netbox)
returnValue(has_configurations)

Expand All @@ -66,18 +60,6 @@ def handle(self):
yield self._process_data(mappings)
break

@classmethod
@defer.inlineCallbacks
def _get_paloalto_arp_mappings(cls, ip: IP, api_key: str):
"""
Make a HTTP request for ARP data from Paloalto device with the given
ip-address, using the given api-key. Returns a formatted list of ARP
mappings for use in NAV.
"""
arptable = yield cls._do_request(ip, api_key)
mappings = _parse_arp(arptable) if arptable else []
returnValue(mappings)

@classmethod
@db.synchronous_db_access
def _has_paloalto_configurations(cls, netbox: Netbox):
Expand All @@ -100,10 +82,20 @@ def _get_paloalto_configurations(cls, netbox: Netbox):

@classmethod
@defer.inlineCallbacks
def _do_request(cls, address: IP, key: str):
def _get_paloalto_arp_mappings(cls, address: IP, api_key: str):
"""
Make a HTTP request to Paloalto device
Make a HTTP request for ARP data from Paloalto device with the given
ip-address, using the given api-key. Returns a formatted list of ARP
mappings for use in NAV.
"""
arptable = yield cls._do_request(address, api_key)
mappings = _parse_arp(arptable) if arptable else []
returnValue(mappings)

@classmethod
@defer.inlineCallbacks
def _do_request(cls, address: IP, key: str):
"""Make a HTTP request to Paloalto device"""

class SslPolicy(client.BrowserLikePolicyForHTTPS):
def creatorForNetloc(self, hostname, port):
Expand Down Expand Up @@ -136,13 +128,11 @@ def creatorForNetloc(self, hostname, port):

def _parse_arp(arpbytes: bytes) -> list[tuple[str, IP, str]]:
"""
Create mappings from arp table.
.. note:: xml.etree.ElementTree is considered insecure:
https://docs.python.org/3/library/xml.html#xml-vulnerabilities
However, since we are not parsing untrusted data, this should not
be a problem.
Create mappings from arp table
xml.etree.ElementTree is considered insecure: https://docs.python.org/3/library/xml.html#xml-vulnerabilities
However, since we are not parsing untrusted data, this should not be a problem.
"""

arps = []

root = ET.fromstring(arpbytes.decode("utf-8"))
Expand Down

0 comments on commit fe3a967

Please sign in to comment.