You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by ru...@apache.org on 2016/07/17 17:42:40 UTC

[whimsy] branch master updated: initial (read-only) support for app groups

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

rubys 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  2cce0f1   initial (read-only) support for app groups
2cce0f1 is described below

commit 2cce0f16cd32edf0cce2768fdd0c4374530b4436
Author: Sam Ruby <ru...@intertwingly.net>
AuthorDate: Sun Jul 17 13:42:15 2016 -0400

    initial (read-only) support for app groups
---
 lib/whimsy/asf/ldap.rb     | 40 +++++++++++++++++++++++++++++++++++++++-
 www/roster/models/group.rb |  8 ++++++++
 2 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/lib/whimsy/asf/ldap.rb b/lib/whimsy/asf/ldap.rb
index e1361fc..8a3918d 100644
--- a/lib/whimsy/asf/ldap.rb
+++ b/lib/whimsy/asf/ldap.rb
@@ -283,6 +283,16 @@ module ASF
 
   # search with a scope of one, with automatic retry/failover
   def self.search_one(base, filter, attrs=nil)
+    self.search_scope(::LDAP::LDAP_SCOPE_ONELEVEL, base, filter, attrs)
+  end
+
+  # search with a scope of subtree, with automatic retry/failover
+  def self.search_subtree(base, filter, attrs=nil)
+    self.search_scope(::LDAP::LDAP_SCOPE_SUBTREE, base, filter, attrs)
+  end
+
+  # search with a specified scope, with automatic retry/failover
+  def self.search_scope(scope, base, filter, attrs=nil)
 
     cmd = "ldapsearch -x -LLL -b #{base} -s one #{filter} " +
       "#{[attrs].flatten.join(' ')}"
@@ -297,7 +307,7 @@ module ASF
       target = @ldap.get_option(::LDAP::LDAP_OPT_HOST_NAME) rescue '?'
       Wunderbar.info "[#{target}] #{cmd}"
 
-      result = @ldap.search2(base, ::LDAP::LDAP_SCOPE_ONELEVEL, filter, attrs)
+      result = @ldap.search2(base, scope, filter, attrs)
     rescue Exception => re
       if attempts_left <= 0
         Wunderbar.error "[#{target}] => #{re.inspect} for #{cmd}"
@@ -795,6 +805,34 @@ module ASF
     end
   end
 
+  class AppGroup < Service
+    @base = 'ou=apps,ou=groups,dc=apache,dc=org'
+
+    def dn
+      @dn ||= ASF.search_subtree(self.class.base, "cn=#{name}", 'dn').first.first
+    end
+
+    def base
+      @base = dn.sub(/^cn=.*?,/, '')
+    end
+
+    def self.list(filter='cn=*')
+      ASF.search_subtree(base, filter, 'cn').flatten
+    end
+
+    def self.preload
+      Hash[ASF.search_subtree(base, "cn=*", %w(dn member modifyTimestamp createTimestamp)).map do |results|
+        cn = results['dn'].first[/^cn=(.*?),/, 1]
+        service = ASF::Service.find(cn)
+        service.modifyTimestamp = results['modifyTimestamp'].first # it is returned as an array of 1 entry
+        service.createTimestamp = results['createTimestamp'].first # it is returned as an array of 1 entry
+        members = results['member'] || []
+        service.members = members
+        [service, members]
+      end]
+    end
+  end
+
 end
 
 if __FILE__ == $0
diff --git a/www/roster/models/group.rb b/www/roster/models/group.rb
index acc40e9..fc660cd 100644
--- a/www/roster/models/group.rb
+++ b/www/roster/models/group.rb
@@ -19,6 +19,9 @@ class Group
     groups += ASF::Authorization.new('pit').to_h.
       map {|id, list| [id, "PIT Auth"]}
 
+    # add app groups
+    groups += ASF::AppGroup.list.map {|app| [app, "LDAP app group"]}
+
     groups.sort
   end
 
@@ -33,6 +36,11 @@ class Group
       group = ASF::Service.find(id)
     end
 
+    if group.members.empty?
+      type = 'LDAP app group'
+      group = ASF::AppGroup.find(id)
+    end
+
     if not group.members.empty?
       # LDAP group
 

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