Skip to content

Commit

Permalink
Bug fix - Issue #4
Browse files Browse the repository at this point in the history
QualysApplianceInput.py
 - Added error checking of the source and target appliance lists with debug output on failure
  • Loading branch information
ianglennon committed Oct 13, 2021
1 parent 9eada61 commit 22d387c
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions QualysApplianceInput.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
import QualysAPI

# Appliance map should be in the format:
# { source_appliance_id: target_appliance_id }
#
# When reading from a file, the file should be in the format:
# source_appliance_id, target_appliance_id


def readApplianceMap(inputfile: str):
appliancemap = {}
with open(inputfile, 'r') as csvfile:
Expand All @@ -16,6 +20,7 @@ def readApplianceMap(inputfile: str):

return appliancemap


def generateApplianceMap(source_api: QualysAPI.QualysAPI, target_api: QualysAPI.QualysAPI):
appliancemap = {}
srcurl = '%s/api/2.0/fo/appliance/?action=list' % source_api.server
Expand All @@ -26,6 +31,20 @@ def generateApplianceMap(source_api: QualysAPI.QualysAPI, target_api: QualysAPI.
sourcelist = sourceresp.find('.//APPLIANCE_LIST')
targetlist = targetresp.find('.//APPLIANCE_LIST')

if sourcelist is None:
print('QualysApplianceInput.generateApplianceMap ERROR: Unable to obtain appliance list from source '
'subscription')
if source_api.debug:
print(ET.tostring(sourceresp, method='xml', encoding='utf-8').decode())
return None

if targetlist is None:
print('QualysApplianceInput.generateApplianceMap Error: Unable to obtain appliance list from target '
'subscription')
if target_api.debug:
print(ET.tostring(targetresp, method='xml', encoding='utf-8').decode())
return None

for sourceappliance in sourcelist.findall('APPLIANCE'):
srcappliancename = sourceappliance.find('NAME').text
srcapplianceid = sourceappliance.find('ID').text
Expand Down

0 comments on commit 22d387c

Please sign in to comment.