forked from tangyanhan/CxRestPy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkmarx_api.py
49 lines (41 loc) · 2.06 KB
/
checkmarx_api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from core import cli_arguments
from core.api import RestAPI
from core.projects import choose_project, create_project, generate_new_temp_project
from core.projects.delete_projects import delete_all_projects, delete_project
from core.reports import generate_new_report_file
from core.scans import create_scan, wait_for_finishing_scan
from core.utils.output_format import get_format
checkmarx = RestAPI.CxRestAPI()
def main():
print("* Welcome to Checkmarx Rest api! *")
if cli_arguments.delete_previous:
delete_all_projects(checkmarx=checkmarx)
if cli_arguments.auto: # check if existed or create new project
project = generate_new_temp_project(checkmarx=checkmarx)
elif input("- Do you want to create new project?(Y/N)").upper() == "Y":
project = create_project(checkmarx=checkmarx,
project_name=cli_arguments.project or input("- Set your project name:"))
else:
project = choose_project(checkmarx)
project_id = project.get("id")
project_name = project.get("name")
target_path = cli_arguments.scan_folder or input("- Set target path:")
print(f"* Target path: {target_path}")
if target_path[:-3] == 'zip':
checkmarx.upload_source_code_zip_file(target_id=project_id, zip_path=target_path)
else:
checkmarx.upload_source_code_folder(target_id=project_id, target_path=target_path)
print("* Files uploaded successfully\n* Creating new scan...")
scan = create_scan(checkmarx=checkmarx, project_id=project_id)
scan_id = scan.get("id")
wait_for_finishing_scan(checkmarx=checkmarx, scan_id=scan_id)
print('* Scan finished successfully')
report_type = cli_arguments.format or get_format()
print("* Creating report...")
report_name = f'{project_name}.{report_type}'
generate_new_report_file(checkmarx=checkmarx, report_type=report_type, scan_id=scan_id, file_name=report_name)
if cli_arguments.delete:
delete_project(checkmarx=checkmarx, project=project)
print("* Successful! Thanks for usage. *")
if __name__ == '__main__':
main()