community-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1858393 - /comdev/reporter.apache.org/trunk/scripts/ldap_info.py
Date Mon, 29 Apr 2019 20:10:19 GMT
Author: sebb
Date: Mon Apr 29 20:10:19 2019
New Revision: 1858393

URL: http://svn.apache.org/viewvc?rev=1858393&view=rev
Log:
LDAP access module

Added:
    comdev/reporter.apache.org/trunk/scripts/ldap_info.py   (with props)

Added: comdev/reporter.apache.org/trunk/scripts/ldap_info.py
URL: http://svn.apache.org/viewvc/comdev/reporter.apache.org/trunk/scripts/ldap_info.py?rev=1858393&view=auto
==============================================================================
--- comdev/reporter.apache.org/trunk/scripts/ldap_info.py (added)
+++ comdev/reporter.apache.org/trunk/scripts/ldap_info.py Mon Apr 29 20:10:19 2019
@@ -0,0 +1,52 @@
+"""
+
+Module to give access to LDAP data from Whimsy public JSON files
+
+This module acts as the gatekeeper for all access to Whimsy LDAP json data
+which is cached from https://whimsy.apache.org/public/
+
+"""
+
+import json
+from urlutils import UrlCache
+
+GROUPS = 'https://whimsy.apache.org/public/public_ldap_groups.json'
+PROJECTS= 'https://whimsy.apache.org/public/public_ldap_projects.json'
+
+
+# Don't check more often than every minute (used by webapp as well as cronjobs)
+uc = UrlCache(interval=60, silent=True)
+
+def loadJson(url):
+    resp = uc.get(url, name=None, encoding='utf-8', errors=None)
+    try:
+        content = resp.read() # json.load() does this anyway
+        try:
+            j = json.loads(content)
+        except Exception as e:
+            # The Proxy error response is around 4800 bytes
+            print("Error parsing response:\n%s" % content[0:4800])
+            raise e
+    finally:
+        resp.close()
+    return j
+
+def getPMCownership(uid):
+    """Returns the array of LDAP project groups where the uid is in the owner list. Excludes
incubator"""
+    projects = loadJson(PROJECTS)['projects']
+    groups = []
+    for group in projects:
+        if group != "incubator" and 'pmc' in projects[group]:
+            if uid in projects[group]['owners']:
+                groups.append(group)
+    return groups
+
+def isMember(uid):
+    """Determine if the uid is in the member Unix group"""
+    return uid in loadJson(GROUPS)['groups']['member']['roster']
+
+if __name__ == '__main__':
+    import sys
+    for arg in sys.argv[1:]:
+        print("%s isMember: %s" % (arg, isMember(arg)))
+        print("%s PMCownership: %s" % (arg, getPMCownership(arg)))

Propchange: comdev/reporter.apache.org/trunk/scripts/ldap_info.py
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message