You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by se...@apache.org on 2017/02/02 15:09:08 UTC

[whimsy] branch master updated: Initial stab at extracting LDAP projects data

This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/whimsy.git

The following commit(s) were added to refs/heads/master by this push:
       new  705f45f   Initial stab at extracting LDAP projects data
705f45f is described below

commit 705f45f024151b4ffc02f0768a9a715655142689
Author: Sebb <se...@apache.org>
AuthorDate: Thu Feb 2 15:08:15 2017 +0000

    Initial stab at extracting LDAP projects data
---
 lib/whimsy/asf/ldap.rb             | 25 +++++++++++++
 www/roster/public_ldap_projects.rb | 75 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 100 insertions(+)

diff --git a/lib/whimsy/asf/ldap.rb b/lib/whimsy/asf/ldap.rb
index 3b6b650..94b930f 100644
--- a/lib/whimsy/asf/ldap.rb
+++ b/lib/whimsy/asf/ldap.rb
@@ -701,10 +701,35 @@ module ASF
       ASF.search_one(base, filter, 'cn').flatten
     end
 
+    def self.preload
+      Hash[ASF.search_one(base, "cn=*", %w(dn member owner modifyTimestamp createTimestamp)).map do |results|
+        cn = results['dn'].first[/^cn=(.*?),/, 1]
+        project = self.find(cn)
+        project.modifyTimestamp = results['modifyTimestamp'].first # it is returned as an array of 1 entry
+        project.createTimestamp = results['createTimestamp'].first # it is returned as an array of 1 entry
+        members = results['member'] || []
+        owners = results['owner'] || []
+        project.members = members
+        project.owners = owners
+        [project, [members, owners]] # TODO is this correct? it seems to work...
+      end]
+    end
+
+    attr_accessor :modifyTimestamp, :createTimestamp
+
+
     def dn
       @dn ||= ASF.search_one(base, "cn=#{name}", 'dn').first.first rescue nil
     end
 
+    def members=(members)
+      @members = WeakRef.new(members)
+    end
+
+    def owners=(owners)
+      @owners = WeakRef.new(owners)
+    end
+
     def members
       members = weakref(:members) do
         ASF.search_one(base, "cn=#{name}", 'member').flatten
diff --git a/www/roster/public_ldap_projects.rb b/www/roster/public_ldap_projects.rb
new file mode 100644
index 0000000..ad71933
--- /dev/null
+++ b/www/roster/public_ldap_projects.rb
@@ -0,0 +1,75 @@
+# Creates JSON output with the following format:
+#
+# {
+#   "lastTimestamp": "20160119171152Z", // most recent modifyTimestamp
+#   "projects": {
+#     "airflow": {
+#       "createTimestamp": "20170118154251Z",
+#       "modifyTimestamp": "20170118154251Z",
+#       "members": [
+#         "abcd",
+#       ],
+#       "owners": [
+#         "abcd",
+#       ]
+#     },
+#     ...
+#   },
+# }
+#
+
+# ##################################################################################################
+# TODO this is a preliminary version. Subject to change/removal. 
+# The output format may change or may be dropped entirely - e.g. if it is merged into existing files
+# ##################################################################################################
+
+require_relative 'public_json_common'
+
+# gather project group info
+entries = {}
+
+projects = ASF::Project.preload # for performance
+
+if projects.empty?
+  Wunderbar.error "No results retrieved, output not created"
+  exit 0
+end
+
+lastStamp = ''
+projects.keys.sort_by {|a| a.name}.each do |entry|
+    next if entry.name == 'apldap' # infra team would prefer this not be publicized
+
+    m = []
+    entry.members.sort_by {|a| a.name}.each do |e|
+        m << e.name
+    end
+    o = []
+    entry.owners.sort_by {|a| a.name}.each do |e|
+        o << e.name
+    end
+    lastStamp = entry.modifyTimestamp if entry.modifyTimestamp > lastStamp
+    entries[entry.name] = {
+        createTimestamp: entry.createTimestamp,
+        modifyTimestamp: entry.modifyTimestamp,
+        members: m,
+        owners: o 
+    }
+end
+
+info = {
+  # Is there a use case for the last createTimestamp ?
+  lastTimestamp: lastStamp,
+  projects: entries,
+}
+
+public_json_output(info)
+
+if changed? and @old_file
+  # for validating UIDs
+  uids = ASF::Person.list().map(&:id)
+  entries.each do |name, entry|
+    entry[:roster].each do |id|
+      Wunderbar.warn "#{name}: unknown uid #{id}" unless uids.include?(id)      
+    end
+  end
+end

-- 
To stop receiving notification emails like this one, please contact
['"commits@whimsical.apache.org" <co...@whimsical.apache.org>'].