mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 17:33:54 +00:00
Merge branch 'linux_acl_recursive' of https://github.com/rominf/salt into rominf-linux_acl_recursive
This commit is contained in:
commit
3b8a9874f4
@ -41,7 +41,7 @@ def _raise_on_no_files(*args):
|
||||
raise CommandExecutionError('You need to specify at least one file or directory to work with!')
|
||||
|
||||
|
||||
def getfacl(*args):
|
||||
def getfacl(*args, **kwargs):
|
||||
'''
|
||||
Return (extremely verbose) map of FACLs on specified file(s)
|
||||
|
||||
@ -51,11 +51,16 @@ def getfacl(*args):
|
||||
|
||||
salt '*' acl.getfacl /tmp/house/kitchen
|
||||
salt '*' acl.getfacl /tmp/house/kitchen /tmp/house/livingroom
|
||||
salt '*' acl.getfacl /tmp/house/kitchen /tmp/house/livingroom recursive=True
|
||||
'''
|
||||
recursive = kwargs.pop('recursive', False)
|
||||
|
||||
_raise_on_no_files(*args)
|
||||
|
||||
ret = {}
|
||||
cmd = 'getfacl -p'
|
||||
if recursive:
|
||||
cmd += ' -R'
|
||||
for dentry in args:
|
||||
cmd += ' {0}'.format(dentry)
|
||||
out = __salt__['cmd.run'](cmd).splitlines()
|
||||
@ -155,7 +160,7 @@ def _parse_acl(acl, user, group):
|
||||
return vals
|
||||
|
||||
|
||||
def wipefacls(*args):
|
||||
def wipefacls(*args, **kwargs):
|
||||
'''
|
||||
Remove all FACLs from the specified file(s)
|
||||
|
||||
@ -165,16 +170,21 @@ def wipefacls(*args):
|
||||
|
||||
salt '*' acl.wipefacls /tmp/house/kitchen
|
||||
salt '*' acl.wipefacls /tmp/house/kitchen /tmp/house/livingroom
|
||||
salt '*' acl.wipefacls /tmp/house/kitchen /tmp/house/livingroom recursive=True
|
||||
'''
|
||||
recursive = kwargs.pop('recursive', False)
|
||||
|
||||
_raise_on_no_files(*args)
|
||||
cmd = 'setfacl -b'
|
||||
if recursive:
|
||||
cmd += ' -R'
|
||||
for dentry in args:
|
||||
cmd += ' {0}'.format(dentry)
|
||||
__salt__['cmd.run'](cmd)
|
||||
return True
|
||||
|
||||
|
||||
def modfacl(acl_type, acl_name, perms, *args):
|
||||
def modfacl(acl_type, acl_name, perms, *args, **kwargs):
|
||||
'''
|
||||
Add or modify a FACL for the specified file(s)
|
||||
|
||||
@ -186,10 +196,15 @@ def modfacl(acl_type, acl_name, perms, *args):
|
||||
salt '*' acl.modfacl default:group mygroup rx /tmp/house/kitchen
|
||||
salt '*' acl.modfacl d:u myuser 7 /tmp/house/kitchen
|
||||
salt '*' acl.modfacl g mygroup 0 /tmp/house/kitchen /tmp/house/livingroom
|
||||
salt '*' acl.modfacl user myuser rwx /tmp/house/kitchen recursive=True
|
||||
'''
|
||||
recursive = kwargs.pop('recursive', False)
|
||||
|
||||
_raise_on_no_files(*args)
|
||||
|
||||
cmd = 'setfacl -m'
|
||||
if recursive:
|
||||
cmd += ' -R'
|
||||
|
||||
prefix = ''
|
||||
if acl_type.startswith('d'):
|
||||
@ -208,7 +223,7 @@ def modfacl(acl_type, acl_name, perms, *args):
|
||||
return True
|
||||
|
||||
|
||||
def delfacl(acl_type, acl_name, *args):
|
||||
def delfacl(acl_type, acl_name, *args, **kwargs):
|
||||
'''
|
||||
Remove specific FACL from the specified file(s)
|
||||
|
||||
@ -220,10 +235,15 @@ def delfacl(acl_type, acl_name, *args):
|
||||
salt '*' acl.delfacl default:group mygroup /tmp/house/kitchen
|
||||
salt '*' acl.delfacl d:u myuser /tmp/house/kitchen
|
||||
salt '*' acl.delfacl g myuser /tmp/house/kitchen /tmp/house/livingroom
|
||||
salt '*' acl.delfacl user myuser /tmp/house/kitchen recursive=True
|
||||
'''
|
||||
recursive = kwargs.pop('recursive', False)
|
||||
|
||||
_raise_on_no_files(*args)
|
||||
|
||||
cmd = 'setfacl -x'
|
||||
if recursive:
|
||||
cmd += ' -R'
|
||||
|
||||
prefix = ''
|
||||
if acl_type.startswith('d'):
|
||||
|
@ -45,6 +45,21 @@ class LinuxAclTestCase(TestCase):
|
||||
linux_acl.getfacl(*self.files)
|
||||
self.cmdrun.assert_called_once_with('getfacl -p ' + ' '.join(self.files))
|
||||
|
||||
def test_getfacl_wo_args(self):
|
||||
self.assertRaises(CommandExecutionError, linux_acl.getfacl)
|
||||
|
||||
def test_getfacl_w_single_arg(self):
|
||||
linux_acl.getfacl(self.file)
|
||||
self.cmdrun.assert_called_once_with('getfacl -p ' + self.file)
|
||||
|
||||
def test_getfacl_w_multiple_args(self):
|
||||
linux_acl.getfacl(*self.files)
|
||||
self.cmdrun.assert_called_once_with('getfacl -p ' + ' '.join(self.files))
|
||||
|
||||
def test_getfacl__recursive_w_multiple_args(self):
|
||||
linux_acl.getfacl(*self.files, recursive=True)
|
||||
self.cmdrun.assert_called_once_with('getfacl -p -R ' + ' '.join(self.files))
|
||||
|
||||
def test_wipefacls_wo_args(self):
|
||||
self.assertRaises(CommandExecutionError, linux_acl.wipefacls)
|
||||
|
||||
@ -56,6 +71,10 @@ class LinuxAclTestCase(TestCase):
|
||||
linux_acl.wipefacls(*self.files)
|
||||
self.cmdrun.assert_called_once_with('setfacl -b ' + ' '.join(self.files))
|
||||
|
||||
def test_wipefacls__recursive_w_multiple_args(self):
|
||||
linux_acl.wipefacls(*self.files, recursive=True)
|
||||
self.cmdrun.assert_called_once_with('setfacl -b -R ' + ' '.join(self.files))
|
||||
|
||||
def test_modfacl_wo_args(self):
|
||||
for acl in [self.u_acl, self.user_acl, self.g_acl, self.group_acl]:
|
||||
self.assertRaises(CommandExecutionError, linux_acl.modfacl, *acl)
|
||||
@ -116,6 +135,10 @@ class LinuxAclTestCase(TestCase):
|
||||
linux_acl.modfacl(*(self.default_user_acl + self.files))
|
||||
self.cmdrun.assert_called_once_with('setfacl -m ' + ' '.join([self.default_user_acl_cmd] + self.files))
|
||||
|
||||
def test_modfacl__recursive_w_multiple_args(self):
|
||||
linux_acl.modfacl(*(self.user_acl + self.files), recursive=True)
|
||||
self.cmdrun.assert_called_once_with('setfacl -m -R ' + ' '.join([self.user_acl_cmd] + self.files))
|
||||
|
||||
def test_delfacl_wo_args(self):
|
||||
for acl in [self.u_acl, self.user_acl, self.g_acl, self.group_acl]:
|
||||
self.assertRaises(CommandExecutionError, linux_acl.delfacl, *acl[:-1])
|
||||
@ -175,3 +198,7 @@ class LinuxAclTestCase(TestCase):
|
||||
def test_delfacl__default_user_w_multiple_args(self):
|
||||
linux_acl.delfacl(*(self.default_user_acl[:-1] + self.files))
|
||||
self.cmdrun.assert_called_once_with('setfacl -x ' + ' '.join([self.default_user_acl_cmd.rpartition(':')[0]] + self.files))
|
||||
|
||||
def test_delfacl__recursive_w_multiple_args(self):
|
||||
linux_acl.delfacl(*(self.default_user_acl[:-1] + self.files), recursive=True)
|
||||
self.cmdrun.assert_called_once_with('setfacl -x -R ' + ' '.join([self.default_user_acl_cmd.rpartition(':')[0]] + self.files))
|
||||
|
Loading…
Reference in New Issue
Block a user