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 11bcc31
Showing 1 changed file with 17 additions and 25 deletions.
42 changes: 17 additions & 25 deletions python/nav/ipdevpoll/plugins/paloaltoarp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -98,6 +80,18 @@ def _get_paloalto_configurations(cls, netbox: Netbox):
queryset = _paloalto_profile_queryset(netbox)
return list(queryset)

@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
@defer.inlineCallbacks
def _do_request(cls, address: IP, key: str):
Expand Down Expand Up @@ -136,13 +130,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 11bcc31

Please sign in to comment.