-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added feature - TenableAD license APIs
Added feature - TenableAD license APIs rebased to master and done requested changes
- Loading branch information
1 parent
931104d
commit 862f365
Showing
9 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.. automodule:: tenable.ad.license.api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
event | ||
infrastructure | ||
ldap_configuration | ||
license | ||
lockout_policy | ||
preference | ||
profiles | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
''' | ||
License | ||
============= | ||
Methods described in this section relate to the license API. | ||
These methods can be accessed at ``TenableAD.license``. | ||
.. rst-class:: hide-signature | ||
.. autoclass:: LicenseAPI | ||
:members: | ||
''' | ||
from typing import Dict | ||
from tenable.ad.license.schema import LicenseSchema | ||
from tenable.base.endpoint import APIEndpoint | ||
|
||
|
||
class LicenseAPI(APIEndpoint): | ||
_path = 'license' | ||
_schema = LicenseSchema() | ||
|
||
def details(self) -> Dict: | ||
''' | ||
Get license singleton | ||
Returns: | ||
dict: | ||
The license object | ||
Examples: | ||
>>> tad.license.details() | ||
''' | ||
return self._schema.load(self._get()) | ||
|
||
def create(self, license: str) -> Dict: | ||
''' | ||
Create new license singleton | ||
Args: | ||
license (str): | ||
The license string object. | ||
Return: | ||
The license object | ||
Example: | ||
>>> tad.license.create( | ||
... license='license' | ||
... ) | ||
''' | ||
payload = self._schema.dump(self._schema.load({ | ||
'license': license | ||
})) | ||
return self._schema.load(self._post(json=payload)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from marshmallow import fields | ||
from tenable.ad.base.schema import CamelCaseSchema, last_word_uppercase | ||
|
||
|
||
class LicenseSchema(CamelCaseSchema): | ||
class Meta: | ||
case_convertors = { | ||
'expiration_date_utc': last_word_uppercase | ||
} | ||
|
||
customer_name = fields.Str() | ||
max_active_user_count = fields.Int() | ||
current_active_user_count = fields.Int() | ||
expiration_date_utc = fields.DateTime() | ||
in_app_eula = fields.Bool() | ||
features = fields.List(fields.Str()) | ||
license = fields.Str() | ||
license_type = fields.Str(data_key='type') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import datetime | ||
import responses | ||
|
||
from tests.ad.conftest import RE_BASE | ||
|
||
|
||
@responses.activate | ||
def test_license_details(api): | ||
responses.add(responses.GET, | ||
f'{RE_BASE}/license', | ||
json={ | ||
'customerName': 'pytenable', | ||
'maxActiveUserCount': 100, | ||
'currentActiveUserCount': 0, | ||
'expirationDateUTC': '2021-11-17T13:44:24.259Z', | ||
'inAppEula': False, | ||
'features': ['something'], | ||
'type': 'license type' | ||
} | ||
) | ||
resp = api.license.details() | ||
assert isinstance(resp, dict) | ||
assert resp['customer_name'] == 'pytenable' | ||
assert resp['max_active_user_count'] == 100 | ||
assert resp['current_active_user_count'] == 0 | ||
assert resp['expiration_date_utc'] == datetime.datetime( | ||
2021, 11, 17, 13, 44, 24, 259000, tzinfo=datetime.timezone.utc) | ||
assert resp['in_app_eula'] == False | ||
assert resp['features'][0] == 'something' | ||
assert resp['license_type'] == 'license type' | ||
|
||
|
||
@responses.activate | ||
def test_license_create(api): | ||
responses.add(responses.POST, | ||
f'{RE_BASE}/license', | ||
json={ | ||
'customerName': 'pytenable', | ||
'maxActiveUserCount': 100, | ||
'currentActiveUserCount': 0, | ||
'expirationDateUTC': '2021-11-17T13:44:24.259Z', | ||
'inAppEula': False, | ||
'features': ['something'], | ||
'type': 'license type' | ||
} | ||
) | ||
resp = api.license.create(license='license') | ||
assert isinstance(resp, dict) | ||
assert resp['customer_name'] == 'pytenable' | ||
assert resp['max_active_user_count'] == 100 | ||
assert resp['current_active_user_count'] == 0 | ||
assert resp['expiration_date_utc'] == datetime.datetime( | ||
2021, 11, 17, 13, 44, 24, 259000, tzinfo=datetime.timezone.utc) | ||
assert resp['in_app_eula'] == False | ||
assert resp['features'][0] == 'something' | ||
assert resp['license_type'] == 'license type' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
''' | ||
Testing the license schemas | ||
''' | ||
import datetime | ||
import pytest | ||
from tenable.ad.license.schema import LicenseSchema | ||
|
||
|
||
@pytest.fixture() | ||
def license_schema_request_payload(): | ||
return { | ||
'license': 'license' | ||
} | ||
|
||
|
||
def test_license_schema_request_payload(license_schema_request_payload): | ||
''' | ||
test license create payload input to schema | ||
''' | ||
schema = LicenseSchema() | ||
req = schema.dump(schema.load(license_schema_request_payload)) | ||
assert req['license'] == 'license' | ||
|
||
|
||
@pytest.fixture() | ||
def license_schema_response(): | ||
return { | ||
'customerName': 'pytenable', | ||
'maxActiveUserCount': 100, | ||
'currentActiveUserCount': 0, | ||
'expirationDateUTC': '2021-11-17T13:44:24.259Z', | ||
'inAppEula': False, | ||
'features': ['something'], | ||
'type': 'license type' | ||
} | ||
|
||
|
||
def test_license_schema_response(license_schema_response): | ||
''' | ||
test license get response to schema | ||
''' | ||
schema = LicenseSchema() | ||
req = schema.load(license_schema_response) | ||
assert req['customer_name'] == 'pytenable' | ||
assert req['max_active_user_count'] == 100 | ||
assert req['current_active_user_count'] == 0 | ||
assert req['expiration_date_utc'] == datetime.datetime( | ||
2021, 11, 17, 13, 44, 24, 259000, tzinfo=datetime.timezone.utc) | ||
assert req['in_app_eula'] is False | ||
assert req['features'][0] == 'something' | ||
assert req['license_type'] == 'license type' |