From 664d604fe8c7a62b379de5eb57c16121c75ffd9e Mon Sep 17 00:00:00 2001 From: John Harrison Date: Sat, 14 Apr 2018 01:44:02 +0100 Subject: [PATCH 1/5] added sample, tenant/ tenant template support, unit tests --- deepsecurity/dsm.py | 33 +++++----- deepsecurity/policies.py | 2 +- deepsecurity/tenants.py | 93 ++++++++++++++++++++++++++++ deepsecurity/tenanttemplates.py | 46 ++++++++++++++ sample.py | 104 ++++++++++++++++++++++++++++++++ unittests.py | 38 ++++++++++++ 6 files changed, 301 insertions(+), 15 deletions(-) create mode 100644 deepsecurity/tenants.py create mode 100644 deepsecurity/tenanttemplates.py create mode 100644 sample.py create mode 100644 unittests.py diff --git a/deepsecurity/dsm.py b/deepsecurity/dsm.py index ee026bf..19a88b3 100644 --- a/deepsecurity/dsm.py +++ b/deepsecurity/dsm.py @@ -10,13 +10,15 @@ import computers import environments import policies +import tenants +import tenanttemplates import translation class Manager(core.CoreApi): def __init__(self, hostname='app.deepsecurity.trendmicro.com', port='4119', - tenant=None, + tenantname=None, username=None, password=None, prefix="", @@ -25,7 +27,7 @@ def __init__(self, core.CoreApi.__init__(self) self._hostname = None self._port = port - self._tenant = None + self._tenantname = None self._username = None self._password = None self._prefix = prefix @@ -35,8 +37,8 @@ def __init__(self, self._get_local_config_file() # allow for explicit override - if tenant: - self._tenant = unicode(tenant, "utf-8") if not type(tenant) == type(unicode("")) else tenant + if tenantname: + self._tenantname = unicode(tenantname, "utf-8") if not type(tenantname) == type(unicode("")) else tenantname if username: self._username = unicode(username, "utf-8") if not type(username) == type(unicode("")) else username if password: @@ -48,6 +50,9 @@ def __init__(self, self.rules = policies.Rules(manager=self) self.ip_lists = policies.IPLists(manager=self) self.cloud_accounts = environments.CloudAccounts(manager=self) + self.tenants = tenants.Tenants(manager=self) + self.tenant = tenants.Tenant(manager=self) + self.tenanttemplate = tenanttemplates.TenantTemplate(manager=self) def __del__(self): """ @@ -89,11 +94,11 @@ def port(self, value): self._set_endpoints() @property - def tenant(self): return self._tenant + def tenantname(self): return self._tenantname - @tenant.setter - def tenant(self, value): - self._tenant = value + @tenantname.setter + def tenantname(self, value): + self._tenantname = value self._reset_session() @property @@ -160,7 +165,7 @@ def _get_local_config_file(self): credentials = { 'username': None, 'password': None, - 'tenant': None, + 'tenantname': None, } try: credential_line_pattern = re.compile(r'(?P\w+) = (?P[^\n]+)') @@ -193,9 +198,9 @@ def sign_in(self): 'username': self.username, 'password': self.password, } - if self.tenant: + if self.tenantname: soap_call['call'] = 'authenticateTenant' - soap_call['data']['tenantName'] = self.tenant + soap_call['data']['tenantName'] = self.tenantname else: soap_call['call'] = 'authenticate' @@ -211,9 +216,9 @@ def sign_in(self): 'password': self.password, } } - if self.tenant: + if self.tenantname: rest_call['call'] = 'authentication/login' - rest_call['data']['dsCredentials']['tenantName'] = self.tenant + rest_call['data']['dsCredentials']['tenantName'] = self.tenantname else: rest_call['call'] = 'authentication/login/primary' @@ -434,4 +439,4 @@ def get_rule_recommendations_for_computer(self, computer_id): results[rule_key].append(internal_rule_id) results['total_recommedations'] += 1 - return results \ No newline at end of file + return results diff --git a/deepsecurity/policies.py b/deepsecurity/policies.py index f6d0633..cef7992 100644 --- a/deepsecurity/policies.py +++ b/deepsecurity/policies.py @@ -317,4 +317,4 @@ def _split_items(self): if getattr(self, 'items') and "\n" in self.items: self.addresses = self.items.split('\n') else: - self.addresses.append(self.items.strip()) \ No newline at end of file + self.addresses.append(self.items.strip()) diff --git a/deepsecurity/tenants.py b/deepsecurity/tenants.py new file mode 100644 index 0000000..7f2f924 --- /dev/null +++ b/deepsecurity/tenants.py @@ -0,0 +1,93 @@ +import core +import translation +import json +import urllib + +class Tenants(core.CoreDict): + def __init__(self, manager=None): + core.CoreDict.__init__(self) + self.manager = manager + self.log = self.manager.log if self.manager else None + + def get(self): + """ + Get all of the Tenants from Deep Security + """ + + rest_call = self.manager._get_request_format(api=self.manager.API_TYPE_REST) + + rest_call['call'] = 'tenants' + rest_call['query'] = {} + rest_call['query']['sID'] = self.manager._sessions[self.manager.API_TYPE_REST] + + response = self.manager._request(rest_call, auth_required=False) + + return response + +class Tenant(core.CoreObject): + def __init__(self, manager=None, api_response=None, log_func=None): + core.CoreObject.__init__(self) + self.manager = manager + self.log = self.manager.log if self.manager else None + if api_response: self._set_properties(api_response, log_func) + + def add(self, admin_acct=None, admin_pw=None, admin_eml=None, name=None): + """ + Add a Tenant + """ + + rest_call = self.manager._get_request_format(api=self.manager.API_TYPE_REST) + + rest_call['call'] = 'tenants' + rest_call['data'] = { + 'createTenantRequest': { + 'createOptions': { + 'adminAccount': admin_acct, + 'adminPassword': admin_pw, + 'adminEmail': admin_eml, + 'activationCodes': [ 'AM' ] + }, + 'tenantElement': { + 'tenantID': 11, + 'name': name, + 'language': 'en', + 'country': 'us', + 'timeZone': 'us/pacific', + 'modulesVisible': [ 'AM' ] + }, + 'sessionId': self.manager._sessions[self.manager.API_TYPE_REST] + } + } + + response = self.manager._request(rest_call, auth_required=False) + + return response + + def get(self, tenant_id=None, tenant_name=None, tenant_state=None, max_items=None, tenant_idop=None): + """ + Describe one/ more Tenants + """ + + rest_call = self.manager._get_request_format(api=self.manager.API_TYPE_REST) + + rest_call['query'] = {} + rest_call['query']['sID'] = self.manager._sessions[self.manager.API_TYPE_REST] + + if tenant_state: + rest_call['call'] = 'tenants/state/'+tenant_state + if max_items: + rest_call['query']['maxItems'] = max_items + if tenant_id: + rest_call['query']['tenantID'] = str(tenant_id) + if tenant_idop: + rest_call['query']['tenantIDOp'] = tenant_idop + elif tenant_id: + rest_call['call'] = 'tenants/id/'+str(tenant_id) + elif tenant_name: + rest_call['call'] = 'tenants/name/'+urllib.quote(tenant_name) + else: + rest_call['call'] = 'tenants' + + response = self.manager._request(rest_call, auth_required=False) + + return response diff --git a/deepsecurity/tenanttemplates.py b/deepsecurity/tenanttemplates.py new file mode 100644 index 0000000..96b8599 --- /dev/null +++ b/deepsecurity/tenanttemplates.py @@ -0,0 +1,46 @@ +import core +import translation +import json +import urllib + +class TenantTemplate(core.CoreObject): + def __init__(self, manager=None, api_response=None, log_func=None): + core.CoreObject.__init__(self) + self.manager = manager + self.log = self.manager.log if self.manager else None + if api_response: self._set_properties(api_response, log_func) + + def add(self, tenant_id=None): + """ + Add a Tenant Template + """ + + rest_call = self.manager._get_request_format(api=self.manager.API_TYPE_REST) + + rest_call['call'] = 'tenanttemplate' + rest_call['data'] = { + 'createTenantTemplateRequest': { + 'tenantId': tenant_id, + 'sessionId': self.manager._sessions[self.manager.API_TYPE_REST] + } + } + + response = self.manager._request(rest_call, auth_required=False) + + return response + + def get(self): + """ + Describe a Tenant Template + """ + + rest_call = self.manager._get_request_format(api=self.manager.API_TYPE_REST) + + rest_call['query'] = {} + rest_call['query']['sID'] = self.manager._sessions[self.manager.API_TYPE_REST] + + rest_call['call'] = 'tenanttemplate' + + response = self.manager._request(rest_call, auth_required=False) + + return response diff --git a/sample.py b/sample.py new file mode 100644 index 0000000..0834ac1 --- /dev/null +++ b/sample.py @@ -0,0 +1,104 @@ +import deepsecurity, json + +# 1. Create a manager object and authenticate. Usage via the API mirrors the +# web administration console for permissions. This defaults to Deep Security +# as a Service +mgr = deepsecurity.dsm.Manager(hostname="dsm.cleardata.com", port="443", username="john.harrison@cleardata.com", password="QFD!C*#bHEr5", tenantname="primary", ignore_ssl_validation=True) +#mgr = deepsecurity.dsm.Manager(username=user, password=pwd, tenantname=tenant_name) +# Create same object against your own Deep Security Manager with a self-signed SSL certificate +#mgr = deepsecurity.dsm.Manager(hostname=hostname, username=user, password=pwd, ignore_ssl_validation=True) + +# 2. With the object created, you have to authenticate +mgr.sign_in() + +# 3. The Manager() object won't have any data populated yet but does have a number of properties +# all work in a similar manner +print '' +print 'add a tenant' +print '--- - ------' +print '' +mgr.tenant.add(admin_acct='testadmin', admin_pw='Ou812345!', admin_eml='test@mytest.com', name='tenanttest2222') +#print json.dumps(mgr.tenants.get(),indent=2,sort_keys=True) +print '' +print json.dumps(mgr.tenant.get(tenant_id=11),indent=2,sort_keys=True) +print '' +#print mgr.tenant.get(tenant_name='00004269 - Chicagoland Smile Group - PHX3') +#print mgr.tenant.get(tenant_state='active', tenant_id=6, tenant_idop='eq') +print '' +print 'add a tenant template' +print '--- - ------ --------' +mgr.tenanttemplate.add(tenant_id=11) +print '' +print json.dumps(mgr.tenanttemplate.get(),indent=2,sort_keys=True) +''' +mgr.policies.get() +mgr.rules.get() +mgr.ip_lists.get() +mgr.cloud_accounts.get() +mgr.computer_groups.get() +mgr.computers.get() + +# 4. Each of these properties inherits from core.CoreDict which exposes the .get() and other +# useful methods. .get() can be filtered for various properties in order to reduce the +# amount of data you're getting from the Manager(). By default .get() will get all +# of the data it can. +# +# core.CoreDict also exposes a .find() method which is extremely useful for searching +# for specific objects that meet various criteria. .find() takes a set of keyword arguments +# that translate to properties on the objects in the core.CoreDict +# +# For example, this simple loop shows all computers that are currently 'Unmanaged' by +# by Deep Security +for computer_id in mgr.computers.find(overall_status='Unmanaged.*'): + computer = mgr.computers[computer_id] + print "{}\t{}\t{}".format(computer.name, computer.display_name, computer.overall_status) + +# For example, here's all the computers that are running Windows and have the security +# policy "Store UI" or "Shipping" +for computer_id in mgr.computers.find(platform='Windows.*', policy_name=['Store UI', 'Shipping']): + computer = mgr.computers[computer_id] + print "{}\t{}\t{}".format(computer.name, computer.display_name, computer.overall_status) + +# The .find() method takes uses a regex for string comparison and direct comparison for +# other objects. It's extremely flexible and works for all core.CoreDict objects + +# 5. You can also take actions on each of these objects. Where it makes sense, the relevant API +# methods have been added to the object itself. +# +# For example, if you want to scan a set of computers for malware +#mgr.computer[1].scan_for_malware() + +# Apply the same logic for a ComputerGroup +#mgr.computer_group[1].scan_for_malware() + +# Of course, you can use the .find() method on all Computers or ComputerGroups to filter the +# request with a finer granularity +for computer_id in mgr.computers.find(platform='Windows.*', policy_name=['Store UI', 'Shipping']): + computer = mgr.computers[computer_id] + computer.scan_for_malware() + +# This applies to any type of scan or action: +# .scan_for_integrity() +# .scan_for_recommendations() +# .assign_policy() +# ... + +# 6. Adding an AWS account is a good example of a unique property for the +# environments.CloudAccounts object +#mgr.cloud_accounts.add_aws_account(friendly_name, aws_access_key=AWS_ACCESS_KEY, aws_secret_key=AWS_SECRET_KEY) + +# This would add the AWS account and all regions to Deep Security in order to sync +# the inventory of EC2 instances automatically +# +# The IAM identity for the access/secret key needs: +# - ec2::describeInstances +# - ec2::describeImages +# - ec2::describeTags + +# 7. Old school but key. API access is the same as a user logging in. If you are going to +# start a large number of session, you'll need to finish each of them to avoid +# exception being thrown. +# +# This function is also called automatically with the object's destructor +''' +mgr.sign_out() diff --git a/unittests.py b/unittests.py new file mode 100644 index 0000000..51ae0d1 --- /dev/null +++ b/unittests.py @@ -0,0 +1,38 @@ +import unittest +import deepsecurity, json + +class TestStringMethods(unittest.TestCase): + + def setUp(self): + global mgr + mgr = deepsecurity.dsm.Manager(hostname="dsm.cleardata.com", port="443", username="john.harrison@cleardata.com", password="QFD!C*#bHEr5", tenantname="primary", ignore_ssl_validation=True) + mgr.sign_in() + + ''' + def test_add_tenant(self): + global mgr + response = mgr.tenant.add(admin_acct='testadmin', admin_pw='Ou812345!', admin_eml='test@mytest.com', name='tenanttest22') + self.assertEqual(response['status'], 200) + ''' + + def test_get_tenant(self): + global mgr, response + response = mgr.tenant.get(tenant_id=11) + self.assertEqual(response['status'], 200) + + def test_add_tenant_template(self): + global mgr, response + response = mgr.tenanttemplate.add(tenant_id=11) + self.assertEqual(response['status'], 200) + + def test_get_tenant_template(self): + global mgr, response + response = mgr.tenanttemplate.get() + self.assertEqual(response['status'], 200) + + def tearDown(self): + global mgr + mgr.sign_out() + +if __name__ == '__main__': + unittest.main() From 9ff28ef9c559e70ff5a1ce2baca0cbc25ad4f18a Mon Sep 17 00:00:00 2001 From: uover82 Date: Wed, 18 Apr 2018 12:03:45 -0700 Subject: [PATCH 2/5] added draft tenant.update --- deepsecurity/core.py | 2 +- deepsecurity/tenants.py | 26 +++++++++++++++++++++++++- sample.py | 9 +++++++-- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/deepsecurity/core.py b/deepsecurity/core.py index f7baebf..4dbe195 100644 --- a/deepsecurity/core.py +++ b/deepsecurity/core.py @@ -577,4 +577,4 @@ def find(self, **kwargs): if item_matches: results.append(item_id) - return results \ No newline at end of file + return results diff --git a/deepsecurity/tenants.py b/deepsecurity/tenants.py index 7f2f924..0fd92f5 100644 --- a/deepsecurity/tenants.py +++ b/deepsecurity/tenants.py @@ -48,7 +48,7 @@ def add(self, admin_acct=None, admin_pw=None, admin_eml=None, name=None): 'activationCodes': [ 'AM' ] }, 'tenantElement': { - 'tenantID': 11, + #'tenantID': 11, 'name': name, 'language': 'en', 'country': 'us', @@ -91,3 +91,27 @@ def get(self, tenant_id=None, tenant_name=None, tenant_state=None, max_items=Non response = self.manager._request(rest_call, auth_required=False) return response + + def update(self, tenant_name=None, modules_visible=None): + """ + Update a Tenant by name + """ + + rest_call = self.manager._get_request_format(api=self.manager.API_TYPE_REST) + + rest_call['query'] = {} + rest_call['query']['sID'] = self.manager._sessions[self.manager.API_TYPE_REST] + rest_call['call'] = 'tenants/name/'+urllib.quote(tenant_name) + + rest_call['data'] = { + 'updateTenantRequest': { + 'tenantElement': { + 'modulesVisible': modules_visible + }, + 'sessionId': self.manager._sessions[self.manager.API_TYPE_REST] + } + } + + response = self.manager._request(rest_call, auth_required=False) + + return response diff --git a/sample.py b/sample.py index 0834ac1..0dd91e5 100644 --- a/sample.py +++ b/sample.py @@ -3,7 +3,7 @@ # 1. Create a manager object and authenticate. Usage via the API mirrors the # web administration console for permissions. This defaults to Deep Security # as a Service -mgr = deepsecurity.dsm.Manager(hostname="dsm.cleardata.com", port="443", username="john.harrison@cleardata.com", password="QFD!C*#bHEr5", tenantname="primary", ignore_ssl_validation=True) +mgr = deepsecurity.dsm.Manager(hostname="dsm.cleardata.com", port="443", username="", password="", tenantname="primary", ignore_ssl_validation=True) #mgr = deepsecurity.dsm.Manager(username=user, password=pwd, tenantname=tenant_name) # Create same object against your own Deep Security Manager with a self-signed SSL certificate #mgr = deepsecurity.dsm.Manager(hostname=hostname, username=user, password=pwd, ignore_ssl_validation=True) @@ -13,12 +13,15 @@ # 3. The Manager() object won't have any data populated yet but does have a number of properties # all work in a similar manner +''' print '' print 'add a tenant' print '--- - ------' print '' -mgr.tenant.add(admin_acct='testadmin', admin_pw='Ou812345!', admin_eml='test@mytest.com', name='tenanttest2222') +''' +mgr.tenant.add(admin_acct='testadmin', admin_pw='Ou812345!', admin_eml='test@mytest.com', name='tenanttest333') #print json.dumps(mgr.tenants.get(),indent=2,sort_keys=True) +''' print '' print json.dumps(mgr.tenant.get(tenant_id=11),indent=2,sort_keys=True) print '' @@ -31,6 +34,8 @@ print '' print json.dumps(mgr.tenanttemplate.get(),indent=2,sort_keys=True) ''' +mgr.tenant.update('tenanttest333',['AM','FW']) +''' mgr.policies.get() mgr.rules.get() mgr.ip_lists.get() From f81fe543e37e6bc88d98934ca83663f7323d9ffc Mon Sep 17 00:00:00 2001 From: John Harrison Date: Wed, 18 Apr 2018 21:47:03 +0100 Subject: [PATCH 3/5] add tenant.update, fix tenant.add/timezone --- deepsecurity/core.py | 9 +++++++-- deepsecurity/tenants.py | 6 +++--- sample.py | 6 ++---- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/deepsecurity/core.py b/deepsecurity/core.py index 4dbe195..7dd5b77 100644 --- a/deepsecurity/core.py +++ b/deepsecurity/core.py @@ -221,8 +221,13 @@ def _request(self, request, auth_required=True): elif request.has_key('data') and request['data']: # POST url_request = urllib2.Request(url, data=json.dumps(request['data']), headers=headers) - request_type = 'POST' - self.log("Making a REST POST request with headers {}".format(headers), level='debug') + if request['call'].startswith('tenants/name'): + setattr(url_request, 'get_method', lambda: 'PUT') # make this request use the PUT HTTP verb + request_type = 'PUT' + self.log("Making a REST PUT request with headers {}".format(headers), level='debug') + else: + request_type = 'POST' + self.log("Making a REST POST request with headers {}".format(headers), level='debug') self.log(" and data {}".format(request['data']), level='debug') else: # GET diff --git a/deepsecurity/tenants.py b/deepsecurity/tenants.py index 0fd92f5..2151ef3 100644 --- a/deepsecurity/tenants.py +++ b/deepsecurity/tenants.py @@ -51,9 +51,9 @@ def add(self, admin_acct=None, admin_pw=None, admin_eml=None, name=None): #'tenantID': 11, 'name': name, 'language': 'en', - 'country': 'us', - 'timeZone': 'us/pacific', - 'modulesVisible': [ 'AM' ] + 'country': 'US', + 'timeZone': 'US/Pacific', + 'modulesVisible': ['AM'] }, 'sessionId': self.manager._sessions[self.manager.API_TYPE_REST] } diff --git a/sample.py b/sample.py index 0dd91e5..389d691 100644 --- a/sample.py +++ b/sample.py @@ -19,7 +19,7 @@ print '--- - ------' print '' ''' -mgr.tenant.add(admin_acct='testadmin', admin_pw='Ou812345!', admin_eml='test@mytest.com', name='tenanttest333') +mgr.tenant.add(admin_acct='testadmin', admin_pw='Ou812345!', admin_eml='test@mytest.com', name='tenanttest44') #print json.dumps(mgr.tenants.get(),indent=2,sort_keys=True) ''' print '' @@ -33,9 +33,7 @@ mgr.tenanttemplate.add(tenant_id=11) print '' print json.dumps(mgr.tenanttemplate.get(),indent=2,sort_keys=True) -''' -mgr.tenant.update('tenanttest333',['AM','FW']) -''' +mgr.tenant.update('tenanttest33333',['AM','FW']) mgr.policies.get() mgr.rules.get() mgr.ip_lists.get() From 577eb6b3bb01cd2ae0b1c10af579da712b02e6b7 Mon Sep 17 00:00:00 2001 From: uover82 Date: Thu, 19 Apr 2018 07:55:39 -0700 Subject: [PATCH 4/5] add tenant.update unit test, clean up sample --- deepsecurity/tenants.py | 2 +- sample.py | 28 ++++++++-------------------- unittests.py | 7 ++++++- 3 files changed, 15 insertions(+), 22 deletions(-) diff --git a/deepsecurity/tenants.py b/deepsecurity/tenants.py index 2151ef3..21788d5 100644 --- a/deepsecurity/tenants.py +++ b/deepsecurity/tenants.py @@ -48,7 +48,7 @@ def add(self, admin_acct=None, admin_pw=None, admin_eml=None, name=None): 'activationCodes': [ 'AM' ] }, 'tenantElement': { - #'tenantID': 11, + 'tenantID': 11, 'name': name, 'language': 'en', 'country': 'US', diff --git a/sample.py b/sample.py index 389d691..96376bb 100644 --- a/sample.py +++ b/sample.py @@ -3,7 +3,7 @@ # 1. Create a manager object and authenticate. Usage via the API mirrors the # web administration console for permissions. This defaults to Deep Security # as a Service -mgr = deepsecurity.dsm.Manager(hostname="dsm.cleardata.com", port="443", username="", password="", tenantname="primary", ignore_ssl_validation=True) +mgr = deepsecurity.dsm.Manager(hostname="dsm.cleardata.com", port="443", username="john.harrison@cleardata.com", password="JHpassword1!", tenantname="primary", ignore_ssl_validation=True) #mgr = deepsecurity.dsm.Manager(username=user, password=pwd, tenantname=tenant_name) # Create same object against your own Deep Security Manager with a self-signed SSL certificate #mgr = deepsecurity.dsm.Manager(hostname=hostname, username=user, password=pwd, ignore_ssl_validation=True) @@ -13,27 +13,15 @@ # 3. The Manager() object won't have any data populated yet but does have a number of properties # all work in a similar manner -''' -print '' -print 'add a tenant' -print '--- - ------' -print '' -''' -mgr.tenant.add(admin_acct='testadmin', admin_pw='Ou812345!', admin_eml='test@mytest.com', name='tenanttest44') +#mgr.tenant.add(admin_acct='testadmin', admin_pw='Ou812345!', admin_eml='test@mytest.com', name='mytenanttest') #print json.dumps(mgr.tenants.get(),indent=2,sort_keys=True) -''' -print '' -print json.dumps(mgr.tenant.get(tenant_id=11),indent=2,sort_keys=True) -print '' -#print mgr.tenant.get(tenant_name='00004269 - Chicagoland Smile Group - PHX3') +#print json.dumps(mgr.tenant.get(tenant_id=11),indent=2,sort_keys=True) +print json.dumps(mgr.tenant.get(tenant_name='mytenanttest'),indent=2,sort_keys=True) #print mgr.tenant.get(tenant_state='active', tenant_id=6, tenant_idop='eq') -print '' -print 'add a tenant template' -print '--- - ------ --------' -mgr.tenanttemplate.add(tenant_id=11) -print '' -print json.dumps(mgr.tenanttemplate.get(),indent=2,sort_keys=True) -mgr.tenant.update('tenanttest33333',['AM','FW']) +#mgr.tenanttemplate.add(tenant_id=11) +#print json.dumps(mgr.tenanttemplate.get(),indent=2,sort_keys=True) +#mgr.tenant.update(tenant_name='mytenanttest',modules_visible=['AM','FW']) +''' mgr.policies.get() mgr.rules.get() mgr.ip_lists.get() diff --git a/unittests.py b/unittests.py index 51ae0d1..f10faeb 100644 --- a/unittests.py +++ b/unittests.py @@ -5,7 +5,7 @@ class TestStringMethods(unittest.TestCase): def setUp(self): global mgr - mgr = deepsecurity.dsm.Manager(hostname="dsm.cleardata.com", port="443", username="john.harrison@cleardata.com", password="QFD!C*#bHEr5", tenantname="primary", ignore_ssl_validation=True) + mgr = deepsecurity.dsm.Manager(hostname="dsm.cleardata.com", port="443", username="john.harrison@cleardata.com", password="JHpassword1!", tenantname="primary", ignore_ssl_validation=True) mgr.sign_in() ''' @@ -15,6 +15,11 @@ def test_add_tenant(self): self.assertEqual(response['status'], 200) ''' + def test_update_tenant(self): + global mgr, response + response = mgr.tenant.update(tenant_name='mytenanttest',modules_visible=['AM','FW']) + self.assertEqual(response['status'], 200) + def test_get_tenant(self): global mgr, response response = mgr.tenant.get(tenant_id=11) From 5c7ec9433d6bf4a7e9663a4bf8a4beeff5fbd0b3 Mon Sep 17 00:00:00 2001 From: uover82 Date: Fri, 20 Apr 2018 11:43:14 -0700 Subject: [PATCH 5/5] update tenant.add module_visible support --- deepsecurity/tenants.py | 4 ++-- sample.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/deepsecurity/tenants.py b/deepsecurity/tenants.py index 21788d5..b06861b 100644 --- a/deepsecurity/tenants.py +++ b/deepsecurity/tenants.py @@ -31,7 +31,7 @@ def __init__(self, manager=None, api_response=None, log_func=None): self.log = self.manager.log if self.manager else None if api_response: self._set_properties(api_response, log_func) - def add(self, admin_acct=None, admin_pw=None, admin_eml=None, name=None): + def add(self, admin_acct=None, admin_pw=None, admin_eml=None, name=None, modules_visible=['AM']): """ Add a Tenant """ @@ -53,7 +53,7 @@ def add(self, admin_acct=None, admin_pw=None, admin_eml=None, name=None): 'language': 'en', 'country': 'US', 'timeZone': 'US/Pacific', - 'modulesVisible': ['AM'] + 'modulesVisible': modules_visible }, 'sessionId': self.manager._sessions[self.manager.API_TYPE_REST] } diff --git a/sample.py b/sample.py index 96376bb..077971b 100644 --- a/sample.py +++ b/sample.py @@ -3,7 +3,7 @@ # 1. Create a manager object and authenticate. Usage via the API mirrors the # web administration console for permissions. This defaults to Deep Security # as a Service -mgr = deepsecurity.dsm.Manager(hostname="dsm.cleardata.com", port="443", username="john.harrison@cleardata.com", password="JHpassword1!", tenantname="primary", ignore_ssl_validation=True) +mgr = deepsecurity.dsm.Manager(hostname="dsm.cleardata.com", port="443", username="", password="", tenantname="primary", ignore_ssl_validation=True) #mgr = deepsecurity.dsm.Manager(username=user, password=pwd, tenantname=tenant_name) # Create same object against your own Deep Security Manager with a self-signed SSL certificate #mgr = deepsecurity.dsm.Manager(hostname=hostname, username=user, password=pwd, ignore_ssl_validation=True) @@ -13,7 +13,7 @@ # 3. The Manager() object won't have any data populated yet but does have a number of properties # all work in a similar manner -#mgr.tenant.add(admin_acct='testadmin', admin_pw='Ou812345!', admin_eml='test@mytest.com', name='mytenanttest') +mgr.tenant.add(admin_acct='testadmin', admin_pw='Ou812345!', admin_eml='test@mytest.com', name='mytenanttest') #print json.dumps(mgr.tenants.get(),indent=2,sort_keys=True) #print json.dumps(mgr.tenant.get(tenant_id=11),indent=2,sort_keys=True) print json.dumps(mgr.tenant.get(tenant_name='mytenanttest'),indent=2,sort_keys=True)