Skip to content

Commit e849ceb

Browse files
committed
feat: saml name and logo collected as arrays
1 parent 1d77df4 commit e849ceb

3 files changed

Lines changed: 52 additions & 16 deletions

File tree

src/swamid_plugins/metainfo/collectors/oidc.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
def collect_entity_metadata(mdstore, entity_id):
22
metadata = {
33
"display_name": get_display_name(mdstore, entity_id),
4+
"display_names": get_display_names_lang(mdstore, entity_id),
45
"logo": get_logo(mdstore, entity_id),
56
"privacy_statement": get_privacy_statement(mdstore, entity_id),
67
"contacts": get_contacts(mdstore, entity_id),
78
"entity_categories": get_entity_categories(mdstore, entity_id),
8-
"supported_entity_categories": get_supported_entity_categories(mdstore, entity_id),
9+
"supported_entity_categories": get_supported_entity_categories(
10+
mdstore, entity_id
11+
),
912
"assurance_certifications": get_assurance_certifications(mdstore, entity_id),
1013
"registration_info": get_registration_info(mdstore, entity_id),
1114
"error_url": get_error_url(mdstore, entity_id),
@@ -19,9 +22,24 @@ def get_display_name(mdstore, entity_id):
1922
return display_name
2023

2124

25+
def get_display_names_lang(mdstore, entity_id):
26+
langs = ["en", "cs"]
27+
display_names = []
28+
for lang in langs:
29+
if mdstore.get("client_name#" + lang, None):
30+
display_names.append(
31+
{"text": mdstore.get("client_name#" + lang), "lang": lang}
32+
)
33+
return display_names
34+
35+
2236
def get_logo(mdstore, entity_id):
37+
ret_logo = []
2338
logo = mdstore.get("logo_uri")
24-
return logo
39+
width = mdstore.get("logo_width")
40+
height = mdstore.get("logo_height")
41+
ret_logo.append({"text": logo, "height": height, "width": width})
42+
return ret_logo
2543

2644

2745
def get_privacy_statement(mdstore, entity_id):
@@ -39,23 +57,23 @@ def get_contacts(mdstore, entity_id):
3957
"mailto:{contact}".format(contact=email)
4058
for email in (mdstore.get("contacts") or [])
4159
],
42-
"given_name": ""
60+
"given_name": "",
4361
},
4462
{
4563
"contact_type": "technical",
4664
"email_address": [
4765
"mailto:{contact}".format(contact=email)
4866
for email in (mdstore.get("technical_contacts") or [])
4967
],
50-
"given_name": ""
68+
"given_name": "",
5169
},
5270
{
5371
"contact_type": "security",
5472
"email_address": [
5573
"mailto:{contact}".format(contact=email)
5674
for email in (mdstore.get("security_contacts") or [])
5775
],
58-
"given_name": ""
76+
"given_name": "",
5977
},
6078
]
6179
if contact["email_address"]
@@ -65,8 +83,8 @@ def get_contacts(mdstore, entity_id):
6583

6684
def get_entity_categories(mdstore, entity_id):
6785
entity_categories_translation = {
68-
'research_and_scholarship': 'http://refeds.org/category/research-and-scholarship',
69-
'geant_coco': 'http://www.geant.net/uri/dataprotection-code-of-conduct/v1',
86+
"research_and_scholarship": "http://refeds.org/category/research-and-scholarship",
87+
"geant_coco": "http://www.geant.net/uri/dataprotection-code-of-conduct/v1",
7088
}
7189
entity_categories = [
7290
category
@@ -83,7 +101,7 @@ def get_supported_entity_categories(mdstore, entity_id):
83101

84102
def get_assurance_certifications(mdstore, entity_id):
85103
assurance_certifications_translations = {
86-
'sirtfi': 'https://refeds.org/sirtfi',
104+
"sirtfi": "https://refeds.org/sirtfi",
87105
}
88106
assurance_certifications = [
89107
certification

src/swamid_plugins/metainfo/collectors/saml.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
def collect_entity_metadata(mdstore, entity_id):
22
metadata = {
33
"display_name": get_display_name(mdstore, entity_id),
4+
"display_names": get_display_names_lang(mdstore, entity_id),
45
"logo": get_logo(mdstore, entity_id),
56
"privacy_statement": get_privacy_statement(mdstore, entity_id),
67
"contacts": get_contacts(mdstore, entity_id),
@@ -16,15 +17,31 @@ def collect_entity_metadata(mdstore, entity_id):
1617

1718
def get_display_name(mdstore, entity_id):
1819
display_name = (
19-
next(mdstore.mdui_uiinfo_display_name(entity_id, langpref="en"), None)
20-
or mdstore.name(entity_id)
20+
next(mdstore.mdui_uiinfo_display_name(entity_id, langpref="en"), None)
21+
or mdstore.name(entity_id)
2122
)
2223
return display_name
2324

2425

26+
def get_display_names_lang(mdstore, entity_id):
27+
uiinfos = mdstore.mdui_uiinfo(entity_id)
28+
cls = "urn:oasis:names:tc:SAML:metadata:ui&DisplayName"
29+
elements = list((
30+
element
31+
for uiinfo in uiinfos
32+
for element_key, elements in uiinfo.items()
33+
if element_key != "__class__"
34+
for element in elements
35+
if element.get("__class__") == cls
36+
))
37+
list(map(lambda name: name.pop("__class__", None), elements))
38+
return elements
39+
40+
2541
def get_logo(mdstore, entity_id):
26-
logo = next(mdstore.mdui_uiinfo_logo(entity_id), None)
27-
return logo
42+
logos = list(mdstore.mdui_uiinfo_logo(entity_id))
43+
list(map(lambda logo: logo.pop("__class__", None), logos))
44+
return logos
2845

2946

3047
def get_privacy_statement(mdstore, entity_id):

src/swamid_plugins/metainfo/metainfo.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,18 @@
1818
)
1919

2020

21-
def is_oidc_client(entity_id):
22-
result = entity_id.startswith("APP-") or bool(UUID4HEX.match(entity_id))
23-
return result
21+
def is_oidc_client(entity_id, mdstore):
22+
return type(mdstore) == type(dict)
23+
# result = entity_id.startswith("APP-") or bool(UUID4HEX.match(entity_id))
24+
# return result
2425

2526

2627
def collect_entity_metadata(mdstore, metadata, entity_id):
2728
entity_metadata = (
2829
{}
2930
if not mdstore
3031
else collect_oidc_entity_metadata(mdstore, entity_id)
31-
if is_oidc_client(entity_id)
32+
if is_oidc_client(entity_id, mdstore)
3233
else collect_saml_entity_metadata(mdstore, entity_id)
3334
)
3435
return entity_metadata

0 commit comments

Comments
 (0)