示例#1
0
def entity_display_name(entity: Element, langs=None) -> str:
    """Utility-method for computing a displayable string for a given entity.

    :param entity: An EntityDescriptor element
    :param langs: The list of languages to search in priority order
    """
    for displayName in filter_lang(entity.iter("{%s}DisplayName" % NS['mdui']),
                                   langs=langs):
        return displayName.text.strip()

    for serviceName in filter_lang(entity.iter("{%s}ServiceName" % NS['md']),
                                   langs=langs):
        return serviceName.text.strip()

    for organizationDisplayName in filter_lang(entity.iter(
            "{%s}OrganizationDisplayName" % NS['md']),
                                               langs=langs):
        return organizationDisplayName.text.strip()

    for organizationName in filter_lang(entity.iter("{%s}OrganizationName" %
                                                    NS['md']),
                                        langs=langs):
        return organizationName.text.strip()

    return entity.get('entityID').strip()
示例#2
0
def entity_info(e, langs=None):
    d = entity_simple_summary(e)
    keywords = filter_lang(e.iter("{%s}Keywords" % NS['mdui']), langs=langs)
    if keywords is not None:
        lst = [elt.text for elt in keywords]
        if len(lst) > 0:
            d['keywords'] = ",".join(lst)

    d['privacy_statement_url'] = privacy_statement_url(e, langs)
    d['geo'] = entity_geoloc(e)
    d['orgurl'] = entity_orgurl(e, langs)
    d['service_name'] = entity_service_name(e, langs)
    d['service_descr'] = entity_service_description(e, langs)
    d['requested_attributes'] = entity_requested_attributes(e, langs)
    d['entity_attributes'] = entity_attribute_dict(e)
    d['contacts'] = entity_contacts(e)
    d['name_id_formats'] = entity_nameid_formats(e)
    d['is_idp'] = is_idp(e)
    d['is_sp'] = is_sp(e)
    d['is_aa'] = is_aa(e)
    d['xml'] = (dumptree(e, xml_declaration=False,
                         pretty_print=True).decode('utf8').replace(
                             '<', '&lt;').replace('>', '&gt;'))
    if d['is_idp']:
        d['protocols'] = entity_idp(e).get('protocolSupportEnumeration',
                                           "").split()

    return d
示例#3
0
文件: mdrepo.py 项目: GEANT/met
    def display(self, entity):
        """Utility-method for computing a displayable string for a given entity.

:param entity: An EntityDescriptor element
        """
        for displayName in filter_lang(entity.findall(".//{%s}DisplayName" % NS['mdui'])):
            return displayName.text

        for serviceName in filter_lang(entity.findall(".//{%s}ServiceName" % NS['md'])):
            return serviceName.text

        for organizationDisplayName in filter_lang(entity.findall(".//{%s}OrganizationDisplayName" % NS['md'])):
            return organizationDisplayName.text

        for organizationName in filter_lang(entity.findall(".//{%s}OrganizationName" % NS['md'])):
            return organizationName.text

        return entity.get('entityID')
示例#4
0
    def display(self, entity):
        """Utility-method for computing a displayable string for a given entity.

:param entity: An EntityDescriptor element
        """
        for displayName in filter_lang(entity.findall(".//{%s}DisplayName" % NS['mdui'])):
            return displayName.text

        for serviceName in filter_lang(entity.findall(".//{%s}ServiceName" % NS['md'])):
            return serviceName.text

        for organizationDisplayName in filter_lang(entity.findall(".//{%s}OrganizationDisplayName" % NS['md'])):
            return organizationDisplayName.text

        for organizationName in filter_lang(entity.findall(".//{%s}OrganizationName" % NS['md'])):
            return organizationName.text

        return entity.get('entityID')
示例#5
0
def discojson(e, langs=None, fallback_to_favicon=False, icon_store=None):
    if e is None:
        return dict()

    title, descr = entity_extended_display(e)
    entity_id = e.get('entityID')
    title_langs, descr_langs = entity_extended_display_i18n(e)

    d = dict(
        title=title,
        descr=descr,
        title_langs=title_langs,
        descr_langs=descr_langs,
        auth='saml',
        entity_id=entity_id,
        entityID=entity_id,
    )

    eattr = entity_attribute_dict(e)
    if 'idp' in eattr[ATTRS['role']]:
        d['type'] = 'idp'
        d['hidden'] = 'true'
        if 'http://pyff.io/category/discoverable' in eattr[
                ATTRS['entity-category']]:
            d['hidden'] = 'false'
    elif 'sp' in eattr[ATTRS['role']]:
        d['type'] = 'sp'

    scopes = entity_scopes(e)
    if scopes is not None and len(scopes) > 0:
        d['scope'] = ",".join(scopes)
        if len(scopes) == 1:
            d['domain'] = scopes[0]
            d['name_tag'] = (scopes[0].split('.'))[0].upper()

    icon_info = entity_icon_url(e)
    if icon_info is not None:
        if icon_store is not None and 'url' in icon_info:
            ico = icon_store.lookup(icon_info['url'])
            if ico is not None:
                icon_info['url'] = ico
        d['entity_icon_url'] = icon_info

    keywords = filter_lang(e.iter("{%s}Keywords" % NS['mdui']), langs=langs)
    if keywords is not None:
        lst = [elt.text for elt in keywords]
        if len(lst) > 0:
            d['keywords'] = ",".join(lst)
    psu = privacy_statement_url(e, langs)
    if psu:
        d['privacy_statement_url'] = psu
    geo = entity_geoloc(e)
    if geo:
        d['geo'] = geo

    return d
示例#6
0
def entity_simple_info(e, langs=None):
    d = entity_simple_summary(e)
    d['service_name'] = entity_service_name(e, langs)
    d['service_descr'] = entity_service_description(e, langs)
    d['entity_attributes'] = entity_attribute_dict(e)
    keywords = filter_lang(e.iter("{%s}Keywords" % NS['mdui']), langs=langs)
    if keywords is not None:
        lst = [elt.text for elt in keywords]
        if len(lst) > 0:
            d['keywords'] = ",".join(lst)
    return d
示例#7
0
def entity_extended_display(entity, langs=None):
    """Utility-method for computing a displayable string for a given entity.

    :param entity: An EntityDescriptor element
    :param langs: The list of languages to search in priority order
    """
    display = entity.get('entityID')
    info = ''

    for organizationName in filter_lang(entity.iter("{%s}OrganizationName" %
                                                    NS['md']),
                                        langs=langs):
        info = display
        display = organizationName.text
        break

    for organizationDisplayName in filter_lang(entity.iter(
            "{%s}OrganizationDisplayName" % NS['md']),
                                               langs=langs):
        info = display
        display = organizationDisplayName.text
        break

    for serviceName in filter_lang(entity.iter("{%s}ServiceName" % NS['md']),
                                   langs=langs):
        info = display
        display = serviceName.text
        break

    for displayName in filter_lang(entity.iter("{%s}DisplayName" % NS['mdui']),
                                   langs=langs):
        info = display
        display = displayName.text
        break

    for organizationUrl in filter_lang(entity.iter("{%s}OrganizationURL" %
                                                   NS['md']),
                                       langs=langs):
        info = organizationUrl.text
        break

    for description in filter_lang(entity.iter("{%s}Description" % NS['mdui']),
                                   langs=langs):
        info = description.text
        break

    if info == entity.get('entityID'):
        info = ''

    return display.strip(), info.strip()
示例#8
0
def entity_requested_attributes(entity, langs=None):
    return [(a.get('Name'), bool(a.get('isRequired'))) for a in filter_lang(
        entity.iter("{%s}RequestedAttribute" % NS['md']), langs=langs)]
示例#9
0
def entity_service_description(entity, langs=None):
    for serviceName in filter_lang(entity.iter("{%s}ServiceDescription" %
                                               NS['md']),
                                   langs=langs):
        return serviceName.text
    return None
示例#10
0
def entity_service_name(entity, langs=None):
    for serviceName in filter_lang(entity.iter("{%s}ServiceName" % NS['md']),
                                   langs=langs):
        return serviceName.text
    return None
示例#11
0
def entity_orgurl(entity, langs=None):
    for organizationUrl in filter_lang(entity.iter("{%s}OrganizationURL" %
                                                   NS['md']),
                                       langs=langs):
        return organizationUrl.text
    return None
示例#12
0
def privacy_statement_url(entity, langs):
    for url in filter_lang(entity.iter("{%s}PrivacyStatementURL" % NS['mdui']),
                           langs=langs):
        return url.text
示例#13
0
def entity_icon_url(e, langs=None):
    for ico in filter_lang(e.iter("{%s}Logo" % NS['mdui']), langs=langs):
        return dict(url=ico.text,
                    width=ico.get('width'),
                    height=ico.get('height'))