@@ -38,11 +38,12 @@ def dojo_connection(host, api_key, user, proxy):
3838 # 3. Call this script to load scan data, specifying scanner type
3939 # 4. Script returns along with a pass or fail results: Example: 2 new critical vulns, 1 low out of 10 vulnerabilities
4040
41- def return_engagement (dd , product_id , user ):
41+ def return_engagement (dd , product_id , user , build_id = None ):
4242 #Specify the product id
4343 product_id = product_id
4444 engagement_id = None
4545
46+ """
4647 # Check for a CI/CD engagement_id
4748 engagements = dd.list_engagements(product_in=product_id, status="In Progress")
4849
@@ -52,16 +53,21 @@ def return_engagement(dd, product_id, user):
5253 engagement_id = engagement['id']
5354
5455 if engagement_id == None:
55- start_date = datetime .now ()
56- end_date = start_date + timedelta (days = 180 )
57- users = dd .list_users (user )
58- user_id = None
56+ """
57+ start_date = datetime .now ()
58+ end_date = start_date + timedelta (days = 1 )
59+ users = dd .list_users (user )
60+ user_id = None
5961
60- if users .success :
61- user_id = users .data ["objects" ][0 ]["id" ]
62+ if users .success :
63+ user_id = users .data ["objects" ][0 ]["id" ]
6264
63- engagement_id = dd .create_engagement ("Recurring CI/CD Integration" , product_id , str (user_id ),
64- "In Progress" , start_date .strftime ("%Y-%m-%d" ), end_date .strftime ("%Y-%m-%d" ))
65+ engagementText = "CI/CD Integration"
66+ if build_id is not None :
67+ engagementText = engagementText + " - Build #" + build_id
68+
69+ engagement_id = dd .create_engagement (engagementText , product_id , str (user_id ),
70+ "In Progress" , start_date .strftime ("%Y-%m-%d" ), end_date .strftime ("%Y-%m-%d" ))
6571 return engagement_id
6672
6773def process_findings (dd , engagement_id , dir , build = None ):
@@ -238,6 +244,7 @@ class Main:
238244 parser .add_argument ('--host' , help = "DefectDojo Hostname" , required = True )
239245 parser .add_argument ('--proxy' , help = "Proxy ex:localhost:8080" , required = False , default = None )
240246 parser .add_argument ('--api_key' , help = "API Key" , required = True )
247+ parser .add_argument ('--build_id' , help = "Reference to external build id" , required = False )
241248 parser .add_argument ('--user' , help = "User" , required = True )
242249 parser .add_argument ('--product' , help = "DefectDojo Product ID" , required = True )
243250 parser .add_argument ('--file' , help = "Scanner file" , required = False )
@@ -264,10 +271,11 @@ class Main:
264271 max_medium = args ["medium" ]
265272 build = args ["build" ]
266273 proxy = args ["proxy" ]
274+ build_id = args ["build_id" ]
267275
268276 if dir is not None or file is not None :
269277 dd = dojo_connection (host , api_key , user , proxy = proxy )
270- engagement_id = return_engagement (dd , product_id , user )
278+ engagement_id = return_engagement (dd , product_id , user , build_id = build_id )
271279 test_ids = None
272280 if file is not None :
273281 if scanner is not None :
@@ -277,6 +285,8 @@ class Main:
277285 else :
278286 test_ids = process_findings (dd , engagement_id , dir , build )
279287
288+ #Close the engagement_id
289+ dd .close_engagement (engagement_id )
280290 summary (dd , engagement_id , test_ids , max_critical , max_high , max_medium )
281291 else :
282292 print "No file or directory to scan specified."
0 commit comments