Return-Path: X-Original-To: apmail-community-commits-archive@minotaur.apache.org Delivered-To: apmail-community-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5583C179F5 for ; Tue, 17 Nov 2015 11:39:20 +0000 (UTC) Received: (qmail 56775 invoked by uid 500); 17 Nov 2015 11:39:20 -0000 Delivered-To: apmail-community-commits-archive@community.apache.org Received: (qmail 56750 invoked by uid 500); 17 Nov 2015 11:39:20 -0000 Mailing-List: contact commits-help@community.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@community.apache.org Delivered-To: mailing list commits@community.apache.org Received: (qmail 56741 invoked by uid 99); 17 Nov 2015 11:39:20 -0000 Received: from Unknown (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 17 Nov 2015 11:39:20 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 46BAB180A63 for ; Tue, 17 Nov 2015 11:39:19 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.99 X-Spam-Level: X-Spam-Status: No, score=0.99 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id G4fGsKBlAfRX for ; Tue, 17 Nov 2015 11:39:17 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with ESMTP id 7C86720271 for ; Tue, 17 Nov 2015 11:39:17 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id A544DE0354 for ; Tue, 17 Nov 2015 11:39:16 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 9E2DD3A024F for ; Tue, 17 Nov 2015 11:39:16 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1714759 - /comdev/projects.apache.org/scripts/cronjobs/readldap.py Date: Tue, 17 Nov 2015 11:39:16 -0000 To: commits@community.apache.org From: sebb@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20151117113916.9E2DD3A024F@svn01-us-west.apache.org> Author: sebb Date: Tue Nov 17 11:39:16 2015 New Revision: 1714759 URL: http://svn.apache.org/viewvc?rev=1714759&view=rev Log: Some more fixes (still needs some work) Modified: comdev/projects.apache.org/scripts/cronjobs/readldap.py Modified: comdev/projects.apache.org/scripts/cronjobs/readldap.py URL: http://svn.apache.org/viewvc/comdev/projects.apache.org/scripts/cronjobs/readldap.py?rev=1714759&r1=1714758&r2=1714759&view=diff ============================================================================== --- comdev/projects.apache.org/scripts/cronjobs/readldap.py (original) +++ comdev/projects.apache.org/scripts/cronjobs/readldap.py Tue Nov 17 11:39:16 2015 @@ -45,7 +45,7 @@ def _getPMC(cn, ts=None): members = [] response = conn.response if not len(response) == 1: - raise Error("Invalid Response - only expecting a single entry") + raise RuntimeError("Invalid Response - only expecting a single entry") for c in response: att = c['attributes'] created = att['createTimestamp'][0] # returned as an array of one (!?) @@ -65,20 +65,26 @@ def _getPMC(cn, ts=None): def _getUnix(cn, ts=None): base = 'ou=groups,dc=apache,dc=org' filter = '(&(cn=%s)(!(modifyTimestamp<=%s)))' % (cn, ts) if ts else '(cn=%s)' % cn - attributes=['memberUid','createTimestamp','modifyTimestamp','cn'] + # Note: 1st attribute is used for the key + if cn == '*': + attributes=['cn', 'createTimestamp','modifyTimestamp'] + else: + attributes=['memberUid','createTimestamp','modifyTimestamp','cn'] success = conn.search(base, filter, attributes=attributes, search_scope=LEVEL) if not success: return success, {'base': base, 'filter': filter, 'attributes': attributes} members = [] response = conn.response - if not len(response) == 1: - raise Error("Invalid Response - only expecting a single entry") + if not len(response) == 1 and not cn == '*': + raise RuntimeError("Invalid Response - only expecting a single entry") for c in response: att = c['attributes'] created = att['createTimestamp'][0] # returned as an array of one (!?) modified = att['modifyTimestamp'][0] - members.extend(att['memberUid']) - return success, {'name': cn, + members.extend(att[attributes[0]]) +# print(att) + return success, { + 'name': cn, 'type': 'unix', 'roster': sorted(members), 'created': created, @@ -95,10 +101,9 @@ def _getPerson(uid, ts=None): data = {} response = conn.response if not len(response) == 1: - raise Error("Invalid Response - only expecting a single entry") + raise RuntimeError("Invalid Response - only expecting a single entry") for c in response: att = c['attributes'] - data = {} for a in att: data[a] = att[a][0] return success, data @@ -208,10 +213,10 @@ class LdapCache(object): else: diff = int(time.time() - getmtime(filename)) if diff < self.__interval: - print("Recently checked: %d < %d, skip download" % (diff, self.__interval)) + print("Recently checked: %d < %d, skip download for %s" % (diff, self.__interval, filename)) return old else: - print("Not recently checked: %d > %d" % (diff, self.__interval)) + print("Not recently checked: %d > %d (%s)" % (diff, self.__interval, filename)) try: modified = old['modified'] except KeyError: @@ -257,6 +262,10 @@ class LdapCache(object): return {} if __name__ == '__main__': +# print(_getPMC('jmeter')) +# print(_getUnix('jmeter')) + print(_getUnix('*','20151113163652Z')) + die # test the code by checking group consistency lc = LdapCache(None) members = lc.getUnix('member')['roster']