示例#1
0
文件: acl.py 项目: HideoYamauchi/pcs
def _get_permission_list(role_el):
    """
    Return list of all permissions of role element role_el.
    Format of item of output list (if attribute is misssing in element under its
    key there is None):
        {
            "id": <id of permission element>,
            "description": <permission description>,
            "kind": <read|write|deny>,
            "xpath": <xpath string>,
            "reference": <cib element id>,
            "object-type": <>,
            "attribute": <>,
        }

    role_el -- acl_role etree element of which permissions whould be returned
    """
    output_list = []
    for permission in role_el.findall("./acl_permission"):
        output_list.append(etree_element_attibutes_to_dict(
            permission,
            [
                "id", "description", "kind", "xpath", "reference",
                "object-type", "attribute"
            ]
        ))
    return output_list
示例#2
0
 def test_only_existing(self):
     self.assertEqual(
         {
             "id": "test_id",
             "attribute": "value",
         },
         lib.etree_element_attibutes_to_dict(self.el, ["id", "attribute"])
     )
示例#3
0
 def test_only_existing(self):
     self.assertEqual(
         {
             "id": "test_id",
             "attribute": "value",
         },
         lib.etree_element_attibutes_to_dict(self.el, ["id", "attribute"])
     )
示例#4
0
 def test_mix(self):
     self.assertEqual(
         {
             "id": "test_id",
             "attribute": "value",
             "not_existing": None,
         },
         lib.etree_element_attibutes_to_dict(
             self.el, ["id", "not_existing", "attribute"]))
示例#5
0
 def test_only_not_existing(self):
     self.assertEqual(
         {
             "_id": None,
             "not_existing": None,
         },
         lib.etree_element_attibutes_to_dict(
             self.el, ["_id", "not_existing"]
         )
     )
示例#6
0
 def test_only_not_existing(self):
     self.assertEqual(
         {
             "_id": None,
             "not_existing": None,
         },
         lib.etree_element_attibutes_to_dict(
             self.el, ["_id", "not_existing"]
         )
     )
示例#7
0
 def test_mix(self):
     self.assertEqual(
         {
             "id": "test_id",
             "attribute": "value",
             "not_existing": None,
         },
         lib.etree_element_attibutes_to_dict(
             self.el, ["id", "not_existing", "attribute"]
         )
     )
示例#8
0
文件: acl.py 项目: HideoYamauchi/pcs
def get_role_list(acl_section):
    """
    Returns list of all acl_role elements from acl_section.
    Format of items of output list:
        {
            "id": <role-id>,
            "description": <role-description>,
            "permission_list": [<see function _get_all_permission_list>, ...]
        }

    acl_section -- etree node
    """
    output_list = []
    for role_el in acl_section.findall("./{0}".format(TAG_ROLE)):
        role = etree_element_attibutes_to_dict(
            role_el, ["id", "description"]
        )
        role["permission_list"] = _get_permission_list(role_el)
        output_list.append(role)
    return output_list
示例#9
0
def get_role_list(tree):
    """
    Returns list of all acl_role elements from tree.
    Format of items of output list:
        {
            "id": <role-id>,
            "description": <role-description>,
            "permission_list": [<see function _get_all_permission_list>, ...]
        }

    tree -- etree node
    """
    output_list = []
    for role_el in get_acls(tree).findall("./acl_role"):
        role = etree_element_attibutes_to_dict(
            role_el, ["id", "description"]
        )
        role["permission_list"] = _get_permission_list(role_el)
        output_list.append(role)
    return output_list