From 716019cdfee87b9aa6ccd31b469450ced755edd7 Mon Sep 17 00:00:00 2001 From: Ivan Kanakarakis Date: Tue, 28 Jun 2022 15:11:53 +0300 Subject: Add registration_info_typ to get the registration information from EntityDescriptor services Signed-off-by: Ivan Kanakarakis --- src/saml2/mdstore.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/saml2/mdstore.py b/src/saml2/mdstore.py index ce4c8789..8fadadbd 100644 --- a/src/saml2/mdstore.py +++ b/src/saml2/mdstore.py @@ -1190,8 +1190,7 @@ class MetadataStore(MetaData): def service(self, entity_id, typ, service, binding=None): known_entity = False - logger.debug("service(%s, %s, %s, %s)", entity_id, typ, service, - binding) + logger.debug("service(%s, %s, %s, %s)", entity_id, typ, service, binding) for key, _md in self.metadata.items(): srvs = _md.service(entity_id, typ, service, binding) if srvs: @@ -1522,6 +1521,29 @@ class MetadataStore(MetaData): } return res + def registration_info_typ(self, entity_id, typ): + try: + md = self.__getitem__(entity_id) + except KeyError: + md = {} + + services_of_type = md.get(typ) or [] + typ_reg_info = ( + { + "registration_authority": elem.get("registration_authority"), + "registration_instant": elem.get("registration_instant"), + "registration_policy": { + policy["lang"]: policy["text"] + for policy in elem.get("registration_policy", []) + if policy.get("__class__") == classnames["mdrpi_registration_policy"] + }, + } + for srv in services_of_type + for elem in srv.get("extensions", {}).get("extension_elements", []) + if elem.get("__class__") == classnames["mdrpi_registration_info"] + ) + return typ_reg_info + def _lookup_elements_by_cls(self, root, cls): elements = ( element -- cgit v1.2.1