Commits

Ollivier Robert committed 6541373 Merge

Automated merge with file:///Users/roberto/Dropbox/HG/EEC/ldap-proxy-tq

Comments (0)

Files changed (4)

+2012-03-14  Ollivier Robert  <roberto@keltia.net>
+
+	* Gemfile, ldap-proxy.gemspec, ldap-proxy.rb, lib/eec-ldap.rb, lib
+	/ldap-proxy.rb:
+	Automated merge with file:///Users/roberto/Src/ERC/HG/ldap-proxy
+	[6209d3bec0a1] [tip]
+
+2012-03-05  Ollivier Robert  <roberto@keltia.net>
+
+	* Gemfile, ldap-proxy.gemspec:
+	Add missing files.
+	[89aaed592916]
+
+2011-08-17  Ollivier Robert  <roberto@keltia.net>
+
+	* ldap-proxy.rb:
+	Helpers are only visible within handlers/templates.
+	[7c2118f0a2c4]
+
+2012-03-14  Ollivier Robert  <roberto@keltia.net>
+
+	* lib/ldap-proxy.rb:
+	Back to using a custom class for results, needed for ldif.
+	[642a89456471]
+
+2012-03-12  Ollivier Robert  <roberto@keltia.net>
+
+	* lib/ldap-proxy.rb:
+	Add /help.
+	[859be317de11]
+
+	* lib/ldap-proxy.rb:
+	Remove :provides which are padrino-specific.
+	[40ae1a38c4a7]
+
+	* lib/views/persons.erb:
+	Catch more empty values.
+	[fcde56577856]
+
+	* .hgignore:
+	Ignore this too.
+	[829b15b9715b]
+
+	* .hgignore:
+	For convenience.
+	[13b72b8fd477]
+
+	* lib/ldap-proxy.rb:
+	Default output is ERB.
+	[dced6a889863]
+
+	* lib/ldap-proxy.rb:
+	Rename myrender into my_render.
+	[56c29bd22649]
+
+	* lib/ldap-proxy.rb:
+	Fix other usages of myrender.
+	[d9ecb33bc209]
+
+	* config.ru, ldap-proxy.rb, lib/ldap-proxy.rb, lib/views/persons.erb,
+	lib/views/persons.rabl:
+	Move ldap-proxy.rb under lib/, adjust config.ru. Massive rewrite of
+	the output rendering:
+	- Use rabl for json/xml/ldif
+	- Use ERB for text output
+	[f27b8f117a3f]
+
+	* ldap-proxy.gemspec:
+	Register all dependencies.
+	[3e4eeba2b976]
+
+	* bin/lookfor.rb:
+	Consumer example, empty for now.
+	[043fd422d70e]
+
+	* lib/ldap-proxy/version.rb:
+	Gem generation infra.
+	[9c3c0a74d570]
+
+	* Gemfile, ldap-proxy.gemspec:
+	Add a proper .gemspec file. Move deps from Gemfile into it.
+	[f0f78405b3ca]
+
+2012-03-06  Ollivier Robert  <roberto@keltia.net>
+
+	* Rakefile:
+	Add minimal Rakefile.
+	[c5e88710fa06]
+
+2012-03-05  Ollivier Robert  <roberto@keltia.net>
+
+	* ldap-proxy.rb:
+	Refactoring: rename @result into @results.
+	[e8422b783c43]
+
 2011-08-31  Ollivier Robert  <roberto@keltia.net>
 
+	* ChangeLog:
+	Sync ChangeLog.
+	[64ac80ad372d]
+
 	* ldap-proxy.rb:
 	Rewrite using Treequel to connect to LDAP instead of ActiveLdap.
-	[cea2b18702af] [tip]
+	[cea2b18702af]
 
 	* ldap-proxy.rb:
 	Add a Response class to handle all formatting and output.

Gemfile

File contents unchanged.

ldap-proxy.gemspec

File contents unchanged.

lib/ldap-proxy.rb

 #
 # Description:: a small daemon to handle the overhead of LDAP connections as a RESTful service
 # Author:: Ollivier Robert <roberto@keltia.net>
-# Copyright:: © 2011 by Ollivier Robert
+# Copyright:: © 2011-2012 by Ollivier Robert
 #
 
 # BUGS
 BASE_DIR = File.expand_path(File.dirname(__FILE__))
 
 class EECLdap
-  attr_reader :conn
+  attr_reader :conn, :results, :ldif
 
   def initialize
     puts("Initial connection to #{LDAP_SERVER}")
     begin
       my_filter = "(%s=*%s*)" % [attr, string]
       t1 = Time.now
-      @results = conn.ou("eurousers").filter(my_filter).select(*LDAP_ATTRS).to_hash("uid")
+      @results = conn.ou("eurousers").filter(my_filter).select(*LDAP_ATTRS)
       t2 = Time.now - t1
-      puts(">>>> Found #{@results.length} matches by #{attr} in #{t2}s\n")
+#      puts(">>>> Found #{@results.length} matches by #{attr} in #{t2}s\n")
 
     rescue LDAP::ResultError => msg
       $stderr.print(msg)
     rescue Treequel::ParseError => msg
       $stderr.print(msg)
     end
-    return @results
+    return Result.new(@results)
   end # -- search_attr
 
 end # -- EECLdap
 
+class Result
+  include Enumerable
+
+  attr_reader :results, :ldif
+
+  def initialize(r)
+    @results = r.to_hash("uid")
+    @ldif = Array.new
+    r.each do |e|
+      @ldif << e.to_ldif
+    end
+  end
+
+  def length
+    @results.length
+  end
+
+  def merge(two)
+    @results = @results.merge(two.results)
+    @ldif << two.ldif
+  end
+
+  def [](key)
+    @results[key]
+  end
+
+  def keys
+    @results.keys
+  end
+end # -- Result
+
 Rabl.register!
 
 Rabl.configure do |config|
 def my_render(obj, how = "erb")
   if obj.length != 0 then
     case how
-      when /json|xml|ldif/
-        @persons = obj
+      when /json|xml/
+        @persons = obj.results
         render :rabl, :persons, :format => how
+      when /ldif/
+        @persons = obj.ldif
       when /yaml/
         obj.keys.sort{|a,b| a <=> b}.collect do |key|
           obj[key].to_yaml
         end
       else # erb by default
         begin
-          @persons = obj
+          @persons = obj.results
           tmpl = ERB.new(File.read(BASE_DIR + "/../lib/views/persons.erb"), 0, "%<>")
           tmpl.result(binding())
         rescue Errno::EPIPE