I 'm following this github URL to generate a vulnerability status report, including the result of the scan using Black Duck : https://github.com/blackducksoftware/hub-rest-api-python/tree/master In the examples, there is a Python script to make the generation happen, which is generate_vuln_status_report.py I run this script on my local machine, and it works fine. As a result, I have a zip folder that contains a csv file including the result of the Black Duck, but for all the projects that I have in the Dashboard , I need to adjust this script to make the generation done by project name and project version to be able to filter the csv file generated with the required project. I adjusted the script by this way :
` from blackduck.HubRestApi import HubInstance
import argparse
import json
import time
parser = argparse.ArgumentParser(description="Generate vulnerability status report for a
specific project version.")
parser.add_argument("--project_name", required=True, help="Name of the project")
parser.add_argument("--format", default="CSV", choices=["CSV", "JSON"], help="Report format")
parser.add_argument("--tries", type=int, default=3, help="Number of retries")
args = parser.parse_args()
hub = HubInstance()
class FailedReportDownload(Exception):
pass
def download_report(location, report_format, project_name, retries=args.tries):
report_id = location.split("/")[-1]
if retries:
print("Retrieving generated report from {}".format(location))
# response = hub.download_vuln_status_report(location)
response = hub.execute_get(location)
if response.status_code == 200:
if report_format == "CSV":
download_filename = project_name + ".zip" # Use project_name instead of filename
if report_format == "CSV":
download_filename = filename + ".zip"
response = hub.execute_get(download_url, {'Content-Type': 'application/zip'})
else:
download_filename = filename + ".json"
response = hub.execute_get(content_url)
if response.status_code == 200:
if report_format == "CSV":
with open(download_filename, "wb") as f:
f.write(response.content)
print("Successfully downloaded zip file to {} for report {}".format(
download_filename, report_id))
else:
with open(download_filename, "w") as f:
json.dump(response.json(), f, indent=3)
print("Successfully downloaded json report data to {} for report {}".format(
download_filename, report_id))
else:
print("Failed to retrieve report {}".format(report_id))
print("Probably not ready yet, waiting 5 seconds then retrying...")
time.sleep(args.tries) # Use args.tries instead of args.sleep_time
retries -= 1
download_report(location, report_format, filename, retries)
else:
print("Failed to find report information at location {}, status code: {}".format(location, response.status_code))
else:
raise FailedReportDownload("Failed to retrieve report {} after {} retries".format(report_id, args.tries))
project_name = args.project_name
version_name = args.version_name # Update this to the version you need
report_format = args.format
response = hub.create_vuln_status_report(project_name, version_name, format=report_format)
if response.status_code == 201:
print("Successfully created vulnerability status report")
location = response.headers['Location']
download_report(location, args.format, args.project_name) # Pass project_name instead of
file_name
else:
print("Failed to create vulnerability status report, status code returned:
{}".format(response.status_code))`
Also I updated the used function like this :
def create_vuln_status_report(self, project_name, version_name, format="CSV"):
assert format in HubInstance.valid_vuln_status_report_formats, "Format must be one of {}".format(HubInstance.valid_vuln_status_report_formats)
project = self.get_project_by_name(project_name)
if project:
version = self.get_version_by_name(project, version_name)
if version:
post_data = {
"reportFormat": format,
"locale": "en_US",
"project": project['_meta']['href'],
"version": version['_meta']['href']
}
url = self.get_apibase() + "/vulnerability-status-reports"
custom_headers = {
'Content-Type': 'application/vnd.blackducksoftware.report-4+json',
'Accept': 'application/vnd.blackducksoftware.report-4+json'
}
return self.execute_post(url, custom_headers=custom_headers, data=post_data)
else:
print("Version '{}' not found in project '{}'.".format(version_name, project_name))
return None
else:
print("Project '{}' not found.".format(project_name))
return None
I found this error :
3Traceback (most recent call last): File "C:\Users\Yasmine.Omrane\Desktop\source-scans\report.py", line 70, in <module> response = hub.create_vuln_status_report(project_name, version_name, format=report_format) TypeError: create_vuln_status_report() got multiple values for argument 'format'3
Any idea about the error , or I should update it by another way . I need to generate the report for the specefic project with the specefic version. Any advice please