Skip to content

Commit

Permalink
Add the ability to set existing shares to use win-acls, block file ty…
Browse files Browse the repository at this point in the history
…pes and disable the first time wizard (#25)

* Add support for setting winacls on existing shares
Add support for disaling the first time setup wizard
Add support for blocking file times from shares configured with winacls
Add the respective tests to the new methods introduces
* Add documentation for blocking files from win acls shares
Add documentation for setting winacls on existing shares
* Add reports module to the core modules rst file
  • Loading branch information
saimonation committed Mar 16, 2020
1 parent 2107657 commit 36077a9
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 3 deletions.
7 changes: 7 additions & 0 deletions cterasdk/edge/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,10 @@ def set_hostname(self, hostname):
"""
logging.getLogger().info('Configuring device hostname. %s', {'hostname': hostname})
return self._gateway.put('/config/device/hostname', hostname)

def disable_wizard(self):
"""
Disable the first time wizard
"""
logging.getLogger().info('Disabling first time wizard')
return self._gateway.put('/config/gui/openFirstTimeWizard', False)
23 changes: 23 additions & 0 deletions cterasdk/edge/shares.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,29 @@ def add(self,
logging.getLogger().error("Share creation failed.")
raise CTERAException('Share creation failed', error)

def set_share_winacls(self, name):
"""
Set a network share to use Windows ACL Emulation Mode
:param str name: The share name
"""
logging.getLogger().error("Updating Windows file sharing access mode. %s", {'share': name, 'access': enum.Acl.WindowsNT})
self._gateway.put('/config/fileservices/share/' + name + '/access', enum.Acl.WindowsNT)

def block_files(self, name, extensions):
"""
Configure a share to block one or more file extensions
:param str name: The share name
:param list[str] extensions: List of file extensions to block
"""
share = self.get(name)
if share.access != enum.Acl.WindowsNT:
raise CTERAException('Cannot block file types on non Windows-ACL enabled shares', None, share=share.name, access=share.access)
logging.getLogger().error("Updating the list of blocked file extensions. %s",
{'share': name, 'extensions': extensions, 'access': enum.Acl.WindowsNT})
self._gateway.put('/config/fileservices/share/' + share.name + '/screenedFileTypes', extensions)

def set_acl(self, name, acl):
"""
Set a network share's access control entries.
Expand Down
4 changes: 2 additions & 2 deletions docs/source/api/cterasdk.core.reports.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cterasdk.core.remote module
===========================
cterasdk.core.reports module
============================

.. automodule:: cterasdk.core.reports
:members:
Expand Down
2 changes: 1 addition & 1 deletion docs/source/api/cterasdk.core.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ Submodules
cterasdk.core.login
cterasdk.core.logs
cterasdk.core.portals
cterasdk.core.reports
cterasdk.core.query
cterasdk.core.remote
cterasdk.core.servers
cterasdk.core.session
cterasdk.core.union
cterasdk.core.users
cterasdk.core.zones

21 changes: 21 additions & 0 deletions docs/source/user_guides/Gateway/Gateway.rst
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,13 @@ Device Configuration
filer.config.set_location('Jupiter')
.. automethod:: cterasdk.edge.config.Config.disable_wizard
:noindex:

.. code-block:: python
filer.config.disable_wizard()
Storage
=======

Expand Down Expand Up @@ -336,6 +343,20 @@ Shares
filer.shares.remove_acl('Accounting', [ ('DG', 'CTERA\leadership'), ('DU', 'clark.kent@ctera.com') ])
.. automethod:: cterasdk.edge.shares.Shares.set_share_winacls
:noindex:

.. code-block:: python
filer.shares.set_share_winacls('cloud')
.. automethod:: cterasdk.edge.shares.Shares.block_files
:noindex:

.. code-block:: python
filer.shares.block_files('Accounting', ['exe', 'cmd', 'bat'])
.. automethod:: cterasdk.edge.shares.Shares.delete
:noindex:

Expand Down
7 changes: 7 additions & 0 deletions tests/ut/test_edge_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,10 @@ def test_set_location(self):
ret = config.Config(self._filer).set_location(self._location)
self._filer.put.assert_called_once_with('/config/device/location', self._location)
self.assertEqual(ret, self._location)

def test_disable_first_time_wizard(self):
put_response = 'Success'
self._init_filer(put_response=put_response)
ret = config.Config(self._filer).disable_wizard()
self._filer.put.assert_called_once_with('/config/gui/openFirstTimeWizard', False)
self.assertEqual(ret, put_response)
25 changes: 25 additions & 0 deletions tests/ut/test_edge_shares.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def setUp(self):
('LU', 'admin', 'RW'),
('DG', 'CTERA\\Domain Admins', 'RW'),
('DU', 'walice@ctera.com', 'RW')]
self._share_block_files = ['exe', 'cmd', 'bat']

def test_get_all_shares(self):
get_response = 'Success'
Expand Down Expand Up @@ -124,6 +125,30 @@ def test_list_physical_folders_input_error(self):

self.assertEqual('Invalid root directory.', error.exception.message)

def test_set_share_winacls(self):
put_response = 'Success'
self._init_filer(put_response=put_response)
shares.Shares(self._filer).set_share_winacls(self._share_name)
self._filer.put.assert_called_once_with('/config/fileservices/share/' + self._share_name + '/access', Acl.WindowsNT)

def test_block_files_success(self):
get_response = self._get_share_object()
self._init_filer(get_response=get_response)
shares.Shares(self._filer).block_files(self._share_name, self._share_block_files)
self._filer.get.assert_called_once_with('/config/fileservices/share/' + self._share_name)
self._filer.put.assert_called_once_with(
'/config/fileservices/share/' + self._share_name + '/screenedFileTypes',
self._share_block_files
)

def test_block_files_invalid_share_access_type(self):
get_response = self._get_share_object(access='Expected Failure')
self._init_filer(get_response=get_response)
with self.assertRaises(exception.CTERAException) as error:
shares.Shares(self._filer).block_files(self._share_name, self._share_block_files)
self._filer.get.assert_called_once_with('/config/fileservices/share/' + self._share_name)
self.assertEqual('Cannot block file types on non Windows-ACL enabled shares', error.exception.message)

def test_delete_share_success(self):
self._init_filer()
shares.Shares(self._filer).delete(self._share_name)
Expand Down

0 comments on commit 36077a9

Please sign in to comment.