Skip to content
This repository has been archived by the owner on Aug 7, 2020. It is now read-only.

Commit

Permalink
During scan import user should have option whether or not results wil…
Browse files Browse the repository at this point in the history
…l appear in aggregate
  • Loading branch information
tenableAndrew authored and alanfung committed Aug 30, 2017
1 parent 93ae901 commit afa5241
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Expand Up @@ -5,6 +5,7 @@ CHANGELOG
Unreleased
==========

* Added: Support for include_aggregate parameter for ScansApi.import_scan.

0.2.0
=====
Expand Down
11 changes: 9 additions & 2 deletions tenable_io/api/scans.py
Expand Up @@ -125,14 +125,21 @@ def history(self, scan_id, history_id):
path_params={'scan_id': scan_id, 'history_id': history_id})
return ScanHistory.from_json(response.text)

def import_scan(self, scan_import):
def import_scan(self, scan_import, include_aggregate=True):
"""Import an existing scan which has been uploaded using :func:`TenableIO.FileApi.upload`
:param scan_import: An instance of :class:`ScanImportRequest`.
:param include_aggregate: Boolean indicating whether scan data should appear in Workbenches.
:raise TenableIOApiException: When API error is encountered.
:return: The ID of the imported scan.
"""
response = self._client.post('scans/import', scan_import)
aggregate_option = 0
if include_aggregate:
aggregate_option = 1

response = self._client.post('scans/import?include_aggregate=%(include_aggregate)s',
scan_import,
path_params={'include_aggregate': aggregate_option})
return loads(response.text).get('scan', {}).get('id')

def launch(self, scan_id, scan_launch_request):
Expand Down
5 changes: 3 additions & 2 deletions tenable_io/helpers/scan.py
Expand Up @@ -131,15 +131,16 @@ def template(self, name=None, title=None):

return template

def import_scan(self, path):
def import_scan(self, path, include_aggregate=True):
"""Uploads and then imports scan report.
:param path: Path of the scan report.
:param include_aggregate: Flag indicating whether import scan results should be shown on Workbenches.
:return: ScanRef referenced by id if exists.
"""
uploaded_file_name = self._client.file_helper.upload(path)

imported_scan_id = self._client.scans_api.import_scan(ScanImportRequest(uploaded_file_name))
imported_scan_id = self._client.scans_api.import_scan(ScanImportRequest(uploaded_file_name), include_aggregate)

return self.id(imported_scan_id)

Expand Down

0 comments on commit afa5241

Please sign in to comment.