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

Added a feature to allow get and set of license from Tenable SC #845

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions tenable/sc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
feeds
files
groups
license
organizations
plugins
policies
Expand Down Expand Up @@ -61,6 +62,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
Expand Down Expand Up @@ -481,6 +483,14 @@ def groups(self):
'''
return GroupAPI(self)

@property
def license(self):
'''
The interface object for the
:doc:`Tenable Security Center License APIs <license>`.
'''
return LicenseAPI(self)

@property
def organizations(self):
'''
Expand Down
63 changes: 63 additions & 0 deletions tenable/sc/license.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
'''
License API
===========

The following methods allow for interaction into the Tenable Security Center
:sc-api:`Configuration <Configuration.htm>` 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 set(self, file):
mark-carey-sap marked this conversation as resolved.
Show resolved Hide resolved
'''
Sets the license file.

:sc-api:`license: set <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 get(self):
mark-carey-sap marked this conversation as resolved.
Show resolved Hide resolved
'''
Retrieves the current license information.

:sc-api:`license: get <license: get>`

Returns:
:obj:`dict`:
The license information.
'''
return self._api.get('configSection/0').json()['response']['LicenseConfig']
Loading