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

Create reports_definition.py for launching reports from pyTenable #656

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
10 changes: 10 additions & 0 deletions tenable/sc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
policies
queries
recast_risks
reports_definition
repositories
roles
scan_instances
Expand Down Expand Up @@ -66,6 +67,7 @@
from .policies import ScanPolicyAPI
from .queries import QueryAPI
from .recast_risks import RecastRiskAPI
from .reports_definition import ReportDefinitionsAPI
from .repositories import RepositoryAPI
from .roles import RoleAPI
from .scanners import ScannerAPI
Expand Down Expand Up @@ -521,6 +523,14 @@ def recast_risks(self):
'''
return RecastRiskAPI(self)

@property
def report_definitions(self):
'''
The interface object for the
:doc:`Tenable.sc ReportDefinition APIs <reports_definition>`.
'''
return ReportDefinitionsAPI(self)

@property
def repositories(self):
'''
Expand Down
34 changes: 34 additions & 0 deletions tenable/sc/reports_definition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'''
Reports Definition
============

The following methods allow for interaction into the Tenable.sc
:sc-api:`ReportDefinition <ReportsDefinition.html>` API.

Methods available on ``sc.reports_definition``:

.. rst-class:: hide-signature
.. autoclass:: ReportsDefinitionAPI
:members:
'''
from .base import SCEndpoint

class ReportDefinitionsAPI(SCEndpoint):
def launch(self, id):
'''
Launches a Report definition.
:sc-api:`report-definitions: launch <ReportsDefinition.html#ReportsDefinitionRESTReference-/reportDefinition/{id}/launch>`
Args:
id (int): The report definition identifier to launch.
Returns:
:obj:`dict`:
A report ID resource for the newly launched report definition.
Examples:
>>> running = sc.report_definitions.launch(1)
>>> print('The Scan Result ID is {}'.format(
... running['scanResult']['id']))
'''
payload = dict()

return self._api.post('reportDefinition/{}/launch'.format(
self._check('id', id, int)), json=payload).json()['response']
Loading