Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dmlae
Copy link

@dmlae dmlae commented Jul 5, 2021

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'

… presend in self.data.

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

Traceback (most recent call last):
  File "d.py", line 280, in <module>
    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'
@valentijnscholten
Copy link
Member

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.

@dmlae
Copy link
Author

dmlae commented Jul 5, 2021

I'm calling upload_scan, should I use import_scan?

@dmlae dmlae changed the title When creating a new Engagement and uploading Scan results 'id' is not… When using upload_scan in response result 'id' is not present in self.data Jul 5, 2021
@dmlae
Copy link
Author

dmlae commented Jul 5, 2021

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()

@valentijnscholten
Copy link
Member

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?

@dmlae
Copy link
Author

dmlae commented Jul 5, 2021

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

Thank you

@righel
Copy link

righel commented Nov 29, 2021

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

@valentijnscholten
Copy link
Member

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.

Copy link

sonarqubecloud bot commented Jul 3, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants