defectdojo_api icon indicating copy to clipboard operation
defectdojo_api copied to clipboard

When using upload_scan in response result 'id' is not present in self.data

Open dmlae opened this issue 4 years ago • 8 comments

When creating a new Engagement and uploading Scan results 'id' is not present in self.data.

Changed to check if 'id' exists, else it will return Engagement ID.

Error:

Traceback (most recent call last): File "d.py", line 280, in create_findings(dd, engagement_id, args.scanner, args.scan_file_name) File "d.py", line 248, in create_findings test_id = upload_scan.id() File "python/dojotools/v-dd/lib/python3.9/site-packages/defectdojo_api/defectdojo_apiv2.py", line 1339, in id return int(self.data["id"]) KeyError: 'id'

dmlae avatar Jul 05 '21 13:07 dmlae

Which call are you executing against the api? I don't think this change should be necessary. The POST on the engagements endpoint returns an id field. If you're using import_scan we should change the serverside code to return an id maybe.

valentijnscholten avatar Jul 05 '21 13:07 valentijnscholten

I'm calling upload_scan, should I use import_scan?

dmlae avatar Jul 05 '21 13:07 dmlae

Based on the dojo_ci.py code present in the repo:

def create_findings(dd, engagement_id, scanner, file, build=None):
    # Upload the scanner export
    if int(engagement_id) > 0:
        print("Uploading scanner data.")
        date = datetime.now()

        # upload_scan(self, engagement_id, scan_type, file, active, verified, close_old_findings, skip_duplicates, scan_date,
        upload_scan = dd.upload_scan(engagement_id, SCANNERS[scanner], file, True, False, True, True, date.strftime("%Y-%m-%d"), 
        tags="CI/CD", build=None, minimum_severity="Low")

        if upload_scan.success:
            test_id = upload_scan.id()
        else:
            print(upload_scan.message)
            quit()

dmlae avatar Jul 05 '21 13:07 dmlae

upload_scan in the api wrapper calls import_scan on the server. I think import_scan on the server should return an id, same a reimport probably. Can you create a github issue in the main repo?

valentijnscholten avatar Jul 05 '21 13:07 valentijnscholten

Yeah no problem, I'm just finishing some stuff and will create it.

Thank you

dmlae avatar Jul 05 '21 13:07 dmlae

I have the same issue @valentijnscholten , is this going to be merged?

righel avatar Nov 29 '21 10:11 righel

The id() method is used for responses that contain a model. The import and reimport don't contain a model. There is a field test in the response that contains the id of the test that was created. The d.py above that is calling the id function is not part of this repo.

valentijnscholten avatar Nov 29 '21 10:11 valentijnscholten