diff --git a/tenable/sc/__init__.py b/tenable/sc/__init__.py index a811deab9..3cbbc14b5 100644 --- a/tenable/sc/__init__.py +++ b/tenable/sc/__init__.py @@ -29,6 +29,7 @@ feeds files groups + license organizations plugins policies @@ -62,6 +63,7 @@ from .files import FileAPI from .feeds import FeedAPI from .groups import GroupAPI +from .license import LicenseAPI from .organizations import OrganizationAPI from .plugins import PluginAPI from .policies import ScanPolicyAPI @@ -483,6 +485,14 @@ def groups(self): ''' return GroupAPI(self) + @property + def license(self): + ''' + The interface object for the + :doc:`Tenable Security Center License APIs `. + ''' + return LicenseAPI(self) + @property def organizations(self): ''' diff --git a/tenable/sc/license.py b/tenable/sc/license.py new file mode 100644 index 000000000..7365b89b4 --- /dev/null +++ b/tenable/sc/license.py @@ -0,0 +1,63 @@ +''' +License API +=========== + +The following methods allow for interaction into the Tenable Security Center +:sc-api:`Configuration ` API. These items are typically seen under the +**License Configuration** section of the Tenable Security Center Settings UI. + +This API is simple and utilitarian. No translation of the data returned from the raw API is done. + +Methods available on ``sc.license``: + +.. rst-class:: hide-signature +.. autoclass:: LicenseAPI + :members: +''' + +from .base import SCEndpoint +from .files import FileAPI + +class LicenseAPI(SCEndpoint): + # def _constructor(self, **kw): + # pass + + ''' + The way this works is broken for a number of reasons. The first is that we have to submit the file + AND bind the license in one HTTP(S) session. Otherwise the file gets deleted and the reference to the + file is lost. This is why we have to do the file read and upload in a single session in the set() method. + ''' + def update(self, file): + ''' + Sets the license file. + + :sc-api:`license: set ` + + Args: + file (str): The path to the license file to upload. + + We are using the internal API to do this: + ''' + # First we need to upload the file. + filedata = open(file, 'rb') + + fAPI = FileAPI(self._api) + fileName = fAPI.upload(filedata) + + filedata.close() + + # Now that we have the file uploaded, we can bind the license. + resp = self._api.post('config/license/register', json={'filename': fileName}).json() + return resp['response']['config']['LicenseConfig'] + + def details(self): + ''' + Retrieves the current license information. + + :sc-api:`license: get ` + + Returns: + :obj:`dict`: + The license information. + ''' + return self._api.get('configSection/0').json()['response']['LicenseConfig']