@@ -97,7 +97,7 @@ def remediation_is_valid(vuln, remediation_data):
9797
9898 if vulnerability_name in remediation_data .keys ():
9999 remediation = remediation_data [vulnerability_name ]
100- if (remediation_status == remediation [0 ] and remediation_comment == remediation [1 ]):
100+ if (remediation_status == remediation [0 ] and remediation_comment == remediation [1 ]. replace ( ' \\ n' , ' \n ' ) ):
101101 return None
102102 return remediation_data [vulnerability_name ]
103103 else :
@@ -133,7 +133,7 @@ def set_vulnerablity_remediation(hub, vuln, remediation_status, remediation_comm
133133 response = hub .execute_put (url , data = update )
134134 return response
135135
136- def process_vulnerabilities (hub , vulnerable_components , remediation_data = None , exclusion_data = None , dry_run = False ):
136+ def process_vulnerabilities (hub , vulnerable_components , remediation_data = None , exclusion_data = None , dry_run = False , overwrite_existing = False ):
137137
138138 if (dry_run ):
139139 print (f"Opening dry run output file: { dry_run } " )
@@ -144,8 +144,8 @@ def process_vulnerabilities(hub, vulnerable_components, remediation_data=None, e
144144 print ('"Component Name","Component Version","CVE","Reason","Remeidation Status","HTTP response code"' )
145145
146146 for vuln in vulnerable_components ['items' ]:
147- if vuln ['vulnerabilityWithRemediation' ]['remediationStatus' ] == "NEW" :
148- remediation_action = None
147+ if overwrite_existing or vuln ['vulnerabilityWithRemediation' ]['remediationStatus' ] == "NEW" :
148+ remediation_action = None
149149 exclusion_action = None
150150
151151 if (remediation_data ):
@@ -166,8 +166,7 @@ def process_vulnerabilities(hub, vulnerable_components, remediation_data=None, e
166166
167167 if (remediation_action ):
168168 if (dry_run ):
169- remediation_action .insert (0 , vuln ['vulnerabilityWithRemediation' ]['vulnerabilityName' ])
170- csv_writer .writerow (remediation_action )
169+ csv_writer .writerow ([vuln ['vulnerabilityWithRemediation' ]['vulnerabilityName' ]] + remediation_action )
171170 else :
172171 resp = set_vulnerablity_remediation (hub , vuln , remediation_action [0 ],remediation_action [1 ])
173172 count += 1
@@ -220,6 +219,7 @@ def main(argv=None): # IGNORE:C0111
220219 parser .add_argument ("--cve-remediation-list-custom-field-label" , default = 'CVE Remediation List' , help = 'Label of Custom Field on Black Duck that contains remeidation list file name' )
221220 parser .add_argument ("--origin-exclusion-list-custom-field-label" , default = 'Origin Exclusion List' , help = 'Label of Custom Field on Black Duck that containts origin exclusion list file name' )
222221 parser .add_argument ('-V' , '--version' , action = 'version' , version = program_version_message )
222+ parser .add_argument ("--overwrite-existing" , dest = 'overwrite_existing' , action = "store_true" , help = 'By default only NEW vulnerabilities are remediated. Enabling this flag will update all vulnerabilities.' )
223223
224224 # Process arguments
225225 args = parser .parse_args ()
@@ -233,6 +233,7 @@ def main(argv=None): # IGNORE:C0111
233233 #dry_run = args.dry_run
234234 #dry_run_output = args.dry_run_output
235235 dry_run = args .dry_run
236+ overwrite_existing = args .overwrite_existing
236237 print (args .dry_run )
237238
238239 message = f"{ program_version_message } \n \n Project: { projectname } \n Version: { projectversion } \n Process origin exclusion list: { process_origin_exclulsion } \n Process CVE remediation list: { process_cve_remediation } "
@@ -276,8 +277,9 @@ def main(argv=None): # IGNORE:C0111
276277
277278 # Retrieve the vulnerabiltites for the project version. Newer API versions only allow 1000 items at most.
278279 vulnerable_components = hub .get_vulnerable_bom_components (version , 1000 )
279- process_vulnerabilities (hub , vulnerable_components , remediation_data , exclusion_data , dry_run )
280-
280+
281+ process_vulnerabilities (hub , vulnerable_components , remediation_data , exclusion_data , dry_run , overwrite_existing )
282+
281283 return 0
282284 except Exception :
283285 ### handle keyboard interrupt ###
0 commit comments