From 5a434147064ee05338feccfeb8692c968d2deadb Mon Sep 17 00:00:00 2001
From: Davide Vaghetti <davide.vaghetti@garr.it>
Date: Fri, 4 Dec 2020 11:47:52 +0100
Subject: [PATCH] README and script names updated

---
 README.md                                     | 22 +++++-
 edugain_contacts.py                           | 69 -------------------
 ...ntacts.py => entities_security_contacts.py |  0
 ... identity_federations_security_contacts.py |  0
 4 files changed, 20 insertions(+), 71 deletions(-)
 delete mode 100644 edugain_contacts.py
 rename sirtfi_contacts.py => entities_security_contacts.py (100%)
 rename edugain_security_contacts.py => identity_federations_security_contacts.py (100%)

diff --git a/README.md b/README.md
index d7ef386..19440f4 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,22 @@
 # eduGAIN Contacts
 
-This script will download the current edugain metadata aggregate XML and parse it
-to derive a list of contacts in CSV format. The list will be printed to stdout.
+This repository contains tools to parse contacts from eduGAIN metadata and from 
+the eduGAIN APIs published on https://technical.edugain.org/api.php.
+
+## Identity federations security contacts
+
+Script name :`identity_federations_security_contacts.py`
+
+This script consume the eduGAIN API to retrieve the details of all the eduGAIN identity 
+federations and parse it to create a list of security email addresses, if available, and 
+the corresponding federation name in CSV format. This list will be printed to stdout.
+
+
+## Entities security contacts
+
+Script: `entities_security_contacts.py`
+
+This script will download the current edugain metadata aggregate XML and parse all the 
+identity providers found in order to derive a list of Organization names, domains and 
+security contacts in CSV format. This list will be printed to stdout.
+
diff --git a/edugain_contacts.py b/edugain_contacts.py
deleted file mode 100644
index 85daa84..0000000
--- a/edugain_contacts.py
+++ /dev/null
@@ -1,69 +0,0 @@
-#!/usr/bin/env python3
-
-# This script will download the current edugain metadata aggregate XML
-# and parse it to derive a list of contacts in CSV format.
-# This list will be printed to stdout.
-
-import requests
-from xml.etree import ElementTree as ET
-from urllib.parse import urlparse
-
-
-def strip_start(s, start):
-    if s.startswith(start):
-        return s[len(start):]
-    return s
-
-
-xml_req = requests.get('https://mds.edugain.org/edugain-v1.xml')
-root = ET.fromstring(xml_req.content)
-
-contacts = set()
-seen_doms_mails = set()
-
-ns = {
-    'md': 'urn:oasis:names:tc:SAML:2.0:metadata',
-    'mdui': 'urn:oasis:names:tc:SAML:metadata:ui',
-    'shibmd': 'urn:mace:shibboleth:metadata:1.0',
-    'remd': 'http://refeds.org/metadata',
-    'icmd': 'http://id.incommon.org/metadata'
-}
-
-
-entities = root.findall('./md:EntityDescriptor', ns)
-
-for entity in entities:
-    sec_mails = set()
-    orgname = entity.find('./md:Organization/md:OrganizationDisplayName', ns).text.strip()
-    if not orgname:
-        continue
-    sec_contact_els = entity.findall('./md:ContactPerson[@remd:contactType="http://refeds.org/metadata/contactType/security"]', ns) + \
-    entity.findall('./md:ContactPerson[@icmd:contactType="http://id.incommon.org/metadata/contactType/security"]', ns)    
-    for sec_contact_el in sec_contact_els:
-        mail_el = sec_contact_el.find('./md:EmailAddress', ns)
-        name_el = sec_contact_el.find('./md:GivenName', ns)
-        surname_el = sec_contact_el.find('./md:SurName', ns)
-        if mail_el is None:
-            continue
-        mail = strip_start(mail_el.text, 'mailto:')
-        if name_el is not None:
-            name = name_el.text.strip()
-            if surname_el is not None:
-                surname = surname_el.text.strip()
-                sec_mails.add('"{} {}" <{}>'.format(name, surname, mail))
-            else:
-                sec_mails.add('"{}" <{}>'.format(name, mail))
-        else:
-            sec_mails.add(mail)
-    doms = entity.findall('./md:IDPSSODescriptor/md:Extensions/shibmd:Scope[@regexp="false"]', ns)
-    doms_set = set()
-    for dom in doms:
-        doms_set.add(dom.text)
-    for domain in doms_set:
-        for mail in sec_mails:
-            if (domain,mail) not in seen_doms_mails:
-                seen_doms_mails.add((domain, mail))
-                contacts.add('{},{},{}'.format(domain, mail, orgname))
-
-for contact in sorted(contacts):
-    print(contact)
diff --git a/sirtfi_contacts.py b/entities_security_contacts.py
similarity index 100%
rename from sirtfi_contacts.py
rename to entities_security_contacts.py
diff --git a/edugain_security_contacts.py b/identity_federations_security_contacts.py
similarity index 100%
rename from edugain_security_contacts.py
rename to identity_federations_security_contacts.py
-- 
GitLab