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

Commit

Permalink
Merge remote-tracking branch 'origin/master' into task/AS-19
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.rst
  • Loading branch information
tenableAndrew committed Dec 17, 2019
2 parents d37ee61 + 8ae61da commit 8bde834
Show file tree
Hide file tree
Showing 11 changed files with 1,942 additions and 7 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
CHANGELOG
=========

Unreleased
1.11.0
==========
* Added: Support for Managed Credentials API
* Added: Support for missing Editor API endpoints.

1.10.1
==========
* Fixed missing ScanRef id attribute when initializing a ScanRef via the id method.
* Fixed: missing ScanRef id attribute when initializing a ScanRef via the id method.

1.10.0
==========
Expand Down
62 changes: 62 additions & 0 deletions examples/users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import random

from tenable_io.client import TenableIOClient
from tenable_io.exceptions import TenableIOApiException
from tenable_io.api.models import User, Permissions
from tenable_io.api.users import UserCreateRequest, UserEditRequest


def example(test_domain):

test_user_name = u'example_test_user_{}'.format(random.randint(1, 100))
test_user_username = u'{}@{}'.format(test_user_name, test_domain)

'''
Instantiate an instance of the TenableIOClient.
'''
client = TenableIOClient()

'''
Create a new Standard User
'''
user_create_request = UserCreateRequest(username=test_user_username,
password='Sdk!Test1234{}'.format(random.randint(1, 100)),
permissions=Permissions.User.PERMISSION_STANDARD,
name=test_user_name,
email=test_user_username,
type=User.LOCAL)
std_user_id = client.users_api.create(user_create_request)
assert std_user_id

'''
Fetch user details
'''
std_user = client.users_api.details(std_user_id)
assert isinstance(std_user, User)
assert std_user.permissions == Permissions.User.PERMISSION_STANDARD


'''
Check that new user is included in user list
'''
user_list = client.users_api.list()
assert any([u.id for u in user_list.users if u.id == std_user_id])

'''
Edit user
'''
user_edit_request = UserEditRequest(permissions=Permissions.User.PERMISSION_SCAN_MANAGER)
edited_std_user = client.users_api.edit(std_user_id, user_edit_request)
assert isinstance(edited_std_user, User)
assert edited_std_user.permissions == Permissions.User.PERMISSION_SCAN_MANAGER

'''
Delete user
'''
assert client.users_api.delete(std_user_id)

'''
Check that deleted user is not included in user list
'''
user_list = client.users_api.list()
assert not any([u.id for u in user_list.users if u.id == std_user_id])
2 changes: 1 addition & 1 deletion tenable_io/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.10.1"
__version__ = "1.11.0"
41 changes: 40 additions & 1 deletion tenable_io/api/editor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from tenable_io.api.base import BaseApi
from tenable_io.api.models import TemplateList
from tenable_io.api.models import EditorConfigurationDetails, EditorPluginDetails, EditorTemplateDetails, TemplateList

SCAN = u'scan'
POLICY = u'policy'

class EditorApi(BaseApi):

Expand All @@ -13,3 +15,40 @@ def list(self, type):
"""
response = self._client.get('editor/%(type)s/templates', path_params={'type': type})
return TemplateList.from_json(response.text)


def details(self, type, id):
"""
Gets the configuration details for the scan or policy.
:param type: Type of entity, must be `scan` or `policy`.
:param id: numeric id of the object.
:return: An instance of :class:`tenable_io.api.models.EditorConfigurationDetails`.
"""
response = self._client.get('editor/%(type)s/%(id)s', path_params={'type': type, 'id': id})
return EditorConfigurationDetails.from_json(response.text)


def template_details(self, type, uuid):
"""
Gets the configuration details for a template.
:param type: Type of entity, must be `scan` or `policy`.
:param uuid: UUID of the template.
:return: An instance of :class:`tenable_io.api.models.EditorTemplateDetails`.
"""
response = self._client.get('editor/%(type)s/templates/%(uuid)s', path_params={'type': type, 'uuid': uuid})
return EditorTemplateDetails.from_json(response.text)


def plugin_details(self, policy_id, family_id, plugin_id):
"""
Gets the configuration details for a plugin.
:param policy_id: id of the policy.
:param family_id: id of the plugin family.
:param plugin_id: id of the plugin.
:return: An instance of :class:`tenable_io.api.models.EditorPluginDescription`.
"""
response = self._client.get('editor/policy/%(policy_id)s/families/%(family_id)s/plugins/%(plugin_id)s',
path_params={'policy_id': policy_id,
'family_id': family_id,
'plugin_id': plugin_id})
return EditorPluginDetails.from_json(response.text).plugindescription
Loading

0 comments on commit 8bde834

Please sign in to comment.