forked from Georg/pyacl
Rename functions
Use function names which are both more uniform and more easily understandable by humans. Drop parsefromfile_throughstring() as it does not serve a good use case, if still needed, it can be easily constructed by the user. Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
This commit is contained in:
parent
722fec83b3
commit
63fe0597c1
30
pyacl/acl.py
30
pyacl/acl.py
@ -58,7 +58,7 @@ def reduce_entries(acl):
|
|||||||
return entries
|
return entries
|
||||||
|
|
||||||
|
|
||||||
def parsestrpermission(strpermission):
|
def parse_permission_string(strpermission):
|
||||||
if len(strpermission) != MAX_PERMBITS:
|
if len(strpermission) != MAX_PERMBITS:
|
||||||
return ValueError('Invalid permission')
|
return ValueError('Invalid permission')
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ def parsestrpermission(strpermission):
|
|||||||
return outmap
|
return outmap
|
||||||
|
|
||||||
|
|
||||||
def parsestrentry(strentry):
|
def parse_entry_string(strentry):
|
||||||
if not strentry:
|
if not strentry:
|
||||||
raise ValueError('Got empty string')
|
raise ValueError('Got empty string')
|
||||||
|
|
||||||
@ -111,12 +111,12 @@ def parsestrentry(strentry):
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
entrytype: {
|
entrytype: {
|
||||||
entryvalue: parsestrpermission(permissions),
|
entryvalue: parse_permission_string(permissions),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def parsefromacl(acl): # noqa PLR0912, FIXME: uncomplexify this
|
def parse_acl(acl): # noqa PLR0912, FIXME: uncomplexify this
|
||||||
permap = {
|
permap = {
|
||||||
permission: False for permission in DEFAULT_PERMISSIONS.keys()
|
permission: False for permission in DEFAULT_PERMISSIONS.keys()
|
||||||
}
|
}
|
||||||
@ -171,18 +171,18 @@ def parsefromacl(acl): # noqa PLR0912, FIXME: uncomplexify this
|
|||||||
return outmap
|
return outmap
|
||||||
|
|
||||||
|
|
||||||
def parse_entries(acl):
|
def parse_acl_via_string(acl):
|
||||||
outmap = {
|
outmap = {
|
||||||
group: DEFAULT_PERMISSIONS for group in DEFAULT_ENTRYTYPES
|
group: DEFAULT_PERMISSIONS for group in DEFAULT_ENTRYTYPES
|
||||||
}
|
}
|
||||||
|
|
||||||
for entry in acl:
|
for entry in acl:
|
||||||
outmap.update(parsestrentry(entry))
|
outmap.update(parse_entry_string(entry))
|
||||||
|
|
||||||
return outmap
|
return outmap
|
||||||
|
|
||||||
|
|
||||||
def buildacl(target_name, target_type, read=False, write=False, execute=False):
|
def build_acl(target_name, target_type, read=False, write=False, execute=False):
|
||||||
target_types = ['user', 'group']
|
target_types = ['user', 'group']
|
||||||
if target_type not in target_types or not isinstance(target_name, str):
|
if target_type not in target_types or not isinstance(target_name, str):
|
||||||
return ValueError('Invalid use of buildacl()')
|
return ValueError('Invalid use of buildacl()')
|
||||||
@ -209,23 +209,19 @@ def buildacl(target_name, target_type, read=False, write=False, execute=False):
|
|||||||
return myacl
|
return myacl
|
||||||
|
|
||||||
|
|
||||||
def acltofile(acl, path):
|
def apply_acl_to_path(acl, path):
|
||||||
if acl.valid() is not True:
|
if acl.valid() is not True:
|
||||||
return ValueError('ACL is not ready to be applied.')
|
return ValueError('ACL is not ready to be applied.')
|
||||||
acl.applyto(path)
|
acl.applyto(path)
|
||||||
|
|
||||||
|
|
||||||
def aclfromfile(path):
|
def read_acl_from_path(path):
|
||||||
return ACL(file=path)
|
return ACL(file=path)
|
||||||
|
|
||||||
|
|
||||||
def entriesfromfile(path):
|
def parse_acl_from_path_via_string(path):
|
||||||
return reduce_entries(aclfromfile(path))
|
return parse_acl_via_string(reduce_entries(read_acl_from_path(path)))
|
||||||
|
|
||||||
|
|
||||||
def parsefromfile_throughstring(path):
|
def parse_acl_from_path(path):
|
||||||
return parse_entries(reduce_entries(aclfromfile(path)))
|
return parse_acl(read_acl_from_path(path))
|
||||||
|
|
||||||
|
|
||||||
def parsefromfile(path):
|
|
||||||
return parsefromacl(aclfromfile(path))
|
|
||||||
|
@ -25,20 +25,20 @@ def load_yaml(file):
|
|||||||
|
|
||||||
@mark.parametrize('aclin, aclout', load_yaml('matrix.yaml'))
|
@mark.parametrize('aclin, aclout', load_yaml('matrix.yaml'))
|
||||||
def test_parse_acl_through_string(sample_file_with_acl, aclin, aclout):
|
def test_parse_acl_through_string(sample_file_with_acl, aclin, aclout):
|
||||||
have = acl.parsefromfile_throughstring(sample_file_with_acl)
|
have = acl.parse_acl_from_path_via_string(sample_file_with_acl)
|
||||||
assert aclout == have
|
assert aclout == have
|
||||||
|
|
||||||
|
|
||||||
@mark.parametrize('aclin, aclout', load_yaml('matrix.yaml'))
|
@mark.parametrize('aclin, aclout', load_yaml('matrix.yaml'))
|
||||||
def test_parse_acl_native(sample_file_with_acl, aclin, aclout):
|
def test_parse_acl_native(sample_file_with_acl, aclin, aclout):
|
||||||
have = acl.parsefromfile(sample_file_with_acl)
|
have = acl.parse_acl_from_path(sample_file_with_acl)
|
||||||
assert aclout == have
|
assert aclout == have
|
||||||
|
|
||||||
|
|
||||||
@mark.parametrize('scenario, data', load_yaml('matrix-apply.yaml'))
|
@mark.parametrize('scenario, data', load_yaml('matrix-apply.yaml'))
|
||||||
def test_build_and_apply_acl(sample_file, scenario, data):
|
def test_build_and_apply_acl(sample_file, scenario, data):
|
||||||
built_acl = acl.buildacl(**data['args'])
|
built_acl = acl.build_acl(**data['args'])
|
||||||
assert len(list(built_acl)) == 5 # noqa PLR2004, this is the expected size of the built ACL
|
assert len(list(built_acl)) == 5 # noqa PLR2004, this is the expected size of the built ACL
|
||||||
assert acl.acltofile(built_acl, sample_file) is None
|
assert acl.apply_acl_to_path(built_acl, sample_file) is None
|
||||||
read_acl = acl.parsefromfile(sample_file)
|
read_acl = acl.parse_acl_from_path(sample_file)
|
||||||
assert read_acl == data['expect']
|
assert read_acl == data['expect']
|
||||||
|
Loading…
Reference in New Issue
Block a user