def test_get_all_project_details(): projects_api = ProjectsAPI() all_projects = projects_api.get_all_project_details() assert all_projects is not None if len(all_projects) > 0: first_project = all_projects[0] project_detail = projects_api.get_all_project_details( first_project.name, first_project.team_id) assert project_detail is not None
def test_sample(): team_api = TeamAPI() projects_api = ProjectsAPI() scan_api = ScansAPI() team_id = team_api.get_team_id_by_team_full_name() projects = projects_api.get_all_project_details(project_name="jvl_git", team_id=team_id) for project in projects: scans = scan_api.get_all_scans_for_project( project_id=project.project_id, scan_status='Finished') for scan in scans: print(str(scan.id))
body_msg += "Project: " + doc['CxXMLResults']["@ProjectName"] + "\n" body_msg += "Team: " + doc['CxXMLResults']["@Team"] + "\n" body_msg += "Link: " + result["@DeepLink"] + "\n" return (csv_msg, body_msg) # ----------------------------------------------------------------------------- if __name__ == '__main__': projects_api = ProjectsAPI() scan_api = ScansAPI() csvBody = "status,project name,team,deep link\n" msgBody = "" # get a list of all the projects projects = projects_api.get_all_project_details() # go through all the projects for project in projects: # get last scanned that finished last_scans = scan_api.get_all_scans_for_project(project.project_id, "Finished", 1) scan_id = last_scans[0].id scan_report = scan_api.register_scan_report(scan_id, "XML") if scan_report and scan_report.report_id: while not scan_api.is_report_generation_finished(scan_report.report_id): time.sleep(1) report_content = scan_api.get_report_by_id(scan_report.report_id)
def get_project_results(user_startdate, user_enddate): """ - Get a list of all the projects - Get a list of all the Finished scans for each project - Get the results of the scan in an XML format - Parse through the results to create an element - Check to see if there are any elements that don't exist, if they don't, create a fixed element - Add the element to the report list that is conveted to a json string on return """ scan_api = ScansAPI() projects_api = ProjectsAPI() projects = projects_api.get_all_project_details() filename = str(time.strftime("%Y%m%d-%H%M%S")) + "_list_of_vulns.json" file = open(filename,"w") report = [] for project in projects: print ("Scanning project: " + project.name + "... ") current_scan_results = [] last_scan_results = [] try: scans = scan_api.get_all_scans_for_project(project.project_id, "Finished") scans.reverse() except: print ("Exception found when getting list of scans for project: " + project.name) for scan in scans: if (debug): start_time = datetime.datetime.now() print ("Starting report for scan: " + str(scan.id)) # convert scan date from ISO 8601 if "." in scan.date_and_time.finished_on: scan_date = datetime.datetime.strptime(scan.date_and_time.finished_on, "%Y-%m-%dT%H:%M:%S.%f") else: scan_date = datetime.datetime.strptime(scan.date_and_time.finished_on, "%Y-%m-%dT%H:%M:%S") # if no start date entered or if the scan start date is greater than the user start date entered # or # if no end date entered or if the scan start date is less than the user end date entered if (not user_startdate or scan_date > user_startdate) and (not user_enddate or scan_date < user_enddate): try: scan_report = scan_api.register_scan_report(scan.id, "XML") if scan_report and scan_report.report_id: while not scan_api.is_report_generation_finished(scan_report.report_id): time.sleep(.300) report_content = scan_api.get_report_by_id(scan_report.report_id) if report_content: document = xmltodict.parse(report_content, force_list={'Query'}) if document: current_scan_results, scan_start_date = parse_xml (document, report) if last_scan_results: create_fixed_elements(last_scan_results, current_scan_results, scan_start_date, report) else: print ("[ERROR] document parsing failed for " + str(scan.id)) else: print ("[ERROR] report content failed for " + str(scan.id)) else: print ("[ERROR] scan report not found for " + str(scan.id)) last_scan_results = current_scan_results except: print ("Exception when getting report of scan (possibly scan didn't run because no code changes): " + str(scan.id) + " / project: " + project.name) if (debug): print ("Ending report for scan: " + str(scan.id) + " took " + str(datetime.datetime.now() - start_time)) print ("... Finished " + project.name) file.write (json.dumps(report, sort_keys=True, indent=4)) file.close() return ()