Skip to content

Commit

Permalink
Tested Version
Browse files Browse the repository at this point in the history
  • Loading branch information
Duarte Monteiro committed Sep 4, 2015
1 parent 729c8c7 commit 02589ef
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 28 deletions.
9 changes: 5 additions & 4 deletions APICheckmarx.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
# Launch error to the user
#
def launchError(message):
return jsonify({"error":"%s" % e.message}), 500
return jsonify({"error":"%s" % message}), 500

#
# getProjectScannedDisplayData
#
@app.route('/APICX/getProjectScannedDisplayData/', methods=["GET"])
@app.route('/APICX/getProjectScannedDisplayData/', defaults={"extra_path": ""}, methods=["GET"])
@app.route('/APICX/getProjectScannedDisplayData/<int:projectID>', methods=["GET"])
def ProjectScannedDisplayData(projectID=None):
try:
Expand Down Expand Up @@ -96,7 +97,7 @@ def AssociatedGroups():
# Trigger Flask App
#
if __name__ == '__main__':
print ("Loading...")
print ("[SYS]\tLoading...")
pyC = PyCheckmarx.PyCheckmarx()
print ("Loaded!")
app.run(debug=True, host="localhost", port=8080)
print ("[SYS]\tLoaded!")
app.run(debug=True, host="0.0.0.0", port=5000)
98 changes: 74 additions & 24 deletions PyCheckmarx.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

# Python Dependencies
from suds.client import Client
from suds.sudsobject import asdict

import json

class PyCheckmarx(object):
Expand All @@ -24,8 +26,6 @@ class PyCheckmarx(object):
def __init__(self):
# Get Configuration
self.getConfig()
print self.USERNAME
print self.PASSWORD
# Open Connection With Checkmarx
self.Initclient = self.openConnection()
# Get the Service URL
Expand Down Expand Up @@ -121,44 +121,53 @@ def getSessionId(self,client, serviceUrl):
#
# Get data from the Projects
#
def getProjectScannedDisplayData(self):
tmp = self.client.service.GetProjectScannedDisplayData(self.sessionId).ProjectScannedList[0]
def getProjectScannedDisplayData(self, filterOn=False):
tmp = self.client.service.GetProjectScannedDisplayData(self.sessionId)

if not tmp.IsSuccesfull:
raise Exception("Unable to get data from the server.")

if self.DEBUG:
print dir(tmp)

return tmp
if not filterOn:
return self.convertToJson(tmp)
else:
return tmp.ProjectScannedList[0]

#
# Get Project Display Data
#
def getProjectsDisplayData(self):
tmp = self.client.service.GetProjectsDisplayData(self.SessionId).projectList[0]
def getProjectsDisplayData(self, filterOn=False):
tmp = self.client.service.GetProjectsDisplayData(self.sessionId)

if not tmp.IsSuccesfull:
raise Exception("Unable to get data from the server.")

if self.DEBUG:
print dir(tmp)

return tmp
if not filterOn:
return self.convertToJson(tmp)
else:
return tmp.projectList[0]

#
# Get Scan Info For All Projects
#
def getScanInfoForAllProjects(self):
tmp = self.client.service.GetScansDisplayDataForAllProjects(self.sessionId).ProjectScannedList[0]

def getScanInfoForAllProjects(self, filterOn=False):
tmp = self.client.service.GetScansDisplayDataForAllProjects(self.sessionId)
if not tmp.IsSuccesfull:
raise Exception("Unable to get data from the server.")

if self.DEBUG:
print dir(tmp)

return tmp

if not filterOn:
return self.convertToJson(tmp)
else:
return tmp

#
# Get Preset List
Expand All @@ -172,7 +181,7 @@ def getPresetList(self):
if self.DEBUG:
print dir(tmp)

return tmp
return self.convertToJson(tmp)

#
# Get Configuration List
Expand All @@ -186,7 +195,7 @@ def getConfigurationList(self):
if self.DEBUG:
print dir(tmp)

return tmp
return self.convertToJson(tmp)

#
# Get Associated Groups List
Expand All @@ -200,37 +209,78 @@ def getAssociatedGroups(self):
if self.DEBUG:
print dir(tmp)

return tmp
return self.convertToJson(tmp)

#
# Filter For [getProjectScannedDisplayData]
#
def filterProjectScannedDisplayData(self, projectID):
tmpProjects = getProjectScannedDisplayData()
tmpProjects = self.getProjectScannedDisplayData(True)
for project in tmpProjects:
if project.projectID == projectID:
return project
if project.ProjectID == projectID:
return self.convertToJson(project)

raise Exception("Could not find ProjectID: %s " % projectID)

#
# Filter for [getProjectsDisplayData]
#
def filterProjectsDisplayData(self,projectID):
tmpProjects = getProjectsDisplayData()
tmpProjects = self.getProjectsDisplayData(True)
for project in tmpProjects:
if project.projectID == projectID:
return project
return self.convertToJson(project)

raise Exception("Could not find ProjectID: %s " % projectID)

#
# Filter for [getScanInfoForAllProjects]
#
def filterScanInfoForAllProjects(self,projectID):
tmpProjects = getScanInfoForAllProjects()
tmpProjects = self.getScanInfoForAllProjects(True).ScanList[0]
for project in tmpProjects:
if project.projectID == projectID:
return project
if project.ProjectId == projectID:
return self.convertToJson(project)

raise Exception("Could not find ProjectID: %s " % projectID)

#
# Convert Suds object into serializable format.
#
def recursive_asdict(self,d):
out = {}
for k, v in asdict(d).iteritems():
if hasattr(v, '__keylist__'):
out[k] = self.recursive_asdict(v)
elif isinstance(v, list):
out[k] = []
for item in v:
if hasattr(item, '__keylist__'):
out[k].append(self.recursive_asdict(item))
else:
out[k].append(item)
else:
out[k] = v
return out


#
# Return Subs Object into Serializable format Handler
#
def convertToJson(self, data):
try:
tmp = self.recursive_asdict(data)
return json.dumps(tmp)
except Exception as e:
raise Exception("Unable to convert to JSON: %s" % e.message)


##########################################
#
# Testing AREA
#
##########################################

#tmp = PyCheckmarx()
#print tmp.filterProjectScannedDisplayData(20004)

0 comments on commit 02589ef

Please sign in to comment.