Handled possible exception in the entity_categories method and add a supported_entity_categories method.
This commit is contained in:
@@ -56,6 +56,8 @@ REQ2SRV = {
|
|||||||
|
|
||||||
|
|
||||||
ENTITYATTRIBUTES = "urn:oasis:names:tc:SAML:metadata:attribute&EntityAttributes"
|
ENTITYATTRIBUTES = "urn:oasis:names:tc:SAML:metadata:attribute&EntityAttributes"
|
||||||
|
ENTITY_CATEGORY = "http://macedir.org/entity-category"
|
||||||
|
ENTITY_CATEGORY_SUPPORT = "http://macedir.org/entity-category-support"
|
||||||
|
|
||||||
# ---------------------------------------------------
|
# ---------------------------------------------------
|
||||||
|
|
||||||
@@ -774,13 +776,35 @@ class MetadataStore(object):
|
|||||||
|
|
||||||
def entity_categories(self, entity_id):
|
def entity_categories(self, entity_id):
|
||||||
ent = self.__getitem__(entity_id)
|
ent = self.__getitem__(entity_id)
|
||||||
ext = ent["extensions"]
|
|
||||||
res = []
|
res = []
|
||||||
|
try:
|
||||||
|
ext = ent["extensions"]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
for elem in ext["extension_elements"]:
|
for elem in ext["extension_elements"]:
|
||||||
if elem["__class__"] == ENTITYATTRIBUTES:
|
if elem["__class__"] == ENTITYATTRIBUTES:
|
||||||
for attr in elem["attribute"]:
|
for attr in elem["attribute"]:
|
||||||
if attr["name"] == "http://macedir.org/entity-category":
|
if attr["name"] == ENTITY_CATEGORY:
|
||||||
res.extend([v["text"] for v in attr["attribute_value"]])
|
res.extend([v["text"] for v in
|
||||||
|
attr["attribute_value"]])
|
||||||
|
|
||||||
|
return res
|
||||||
|
|
||||||
|
def supported_entity_categories(self, entity_id):
|
||||||
|
ent = self.__getitem__(entity_id)
|
||||||
|
res = []
|
||||||
|
try:
|
||||||
|
ext = ent["extensions"]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
for elem in ext["extension_elements"]:
|
||||||
|
if elem["__class__"] == ENTITYATTRIBUTES:
|
||||||
|
for attr in elem["attribute"]:
|
||||||
|
if attr["name"] == ENTITY_CATEGORY_SUPPORT:
|
||||||
|
res.extend([v["text"] for v in
|
||||||
|
attr["attribute_value"]])
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user