Module: ASF

Defined in:
lib/whimsy/asf.rb,
lib/whimsy/asf/svn.rb,
lib/whimsy/asf/auth.rb,
lib/whimsy/asf/icla.rb,
lib/whimsy/asf/ldap.rb,
lib/whimsy/asf/mail.rb,
lib/whimsy/asf/rack.rb,
lib/whimsy/asf/site.rb,
lib/whimsy/asf/watch.rb,
lib/whimsy/asf/agenda.rb,
lib/whimsy/asf/config.rb,
lib/whimsy/asf/member.rb,
lib/whimsy/asf/nominees.rb,
lib/whimsy/asf/podlings.rb,
lib/whimsy/asf/committee.rb

Defined Under Namespace

Modules: Auth, Board, LDAP Classes: Authorization, AutoGC, Base, Committee, Config, Group, HTTPS_workarounds, ICLA, LazyHash, Mail, Member, Person, Podlings, SVN, Service, Site

Constant Summary collapse

ETCLDAP =
'/etc/ldap'

Class Method Summary collapse

Class Method Details

.committersObject



85
86
87
88
# File 'lib/whimsy/asf/ldap.rb', line 85

def self.committers
  refresh(:@committers)
  @committers ||= Group.find('committers').members
end

.init_ldapObject

determine whether or not the LDAP API can be used



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/whimsy/asf/ldap.rb', line 26

def self.init_ldap
  @ldap = nil
  @mtime = Time.now

  host = ASF::LDAP.host

  Wunderbar.info "Connecting to LDAP server: #{host}"

  begin
    uri = URI.parse(host)
    if uri.scheme == 'ldaps'
      @ldap = ::LDAP::SSLConn.new(uri.host, uri.port)
    else
      @ldap = ::LDAP::Conn.new(uri.host, uri.port)
    end
  rescue ::LDAP::ResultError=>re
    Wunderbar.error "Error binding to LDAP server: message: ["+ re.message + "]"
  end
end

.ldapObject



46
47
48
# File 'lib/whimsy/asf/ldap.rb', line 46

def self.ldap
  @ldap || self.init_ldap
end

.library_mtimeObject



14
15
16
17
18
19
# File 'lib/whimsy/asf.rb', line 14

def self.library_mtime
  parent_dir = File.dirname(File.expand_path(__FILE__))
  sources = Dir.glob("#{parent_dir}/**/*")
  times = sources.map {|source| File.mtime(source)}
  times.max.gmtime
end

.membersObject



90
91
92
93
# File 'lib/whimsy/asf/ldap.rb', line 90

def self.members
  refresh(:@members)
  @members ||= Group.find('member').members
end

.pmc_chairsObject



80
81
82
83
# File 'lib/whimsy/asf/ldap.rb', line 80

def self.pmc_chairs
  refresh(:@pmc_chairs)
  @pmc_chairs ||= Service.find('pmc-chairs').members
end

.refresh(symbol) ⇒ Object



69
70
71
72
73
74
75
76
77
78
# File 'lib/whimsy/asf/ldap.rb', line 69

def self.refresh(symbol)
  if not @mtime or Time.now - @mtime > 300.0
    @mtime = Time.now
  end

  if instance_variable_get("#{symbol}_mtime") != @mtime
    instance_variable_set("#{symbol}_mtime", @mtime)
    instance_variable_set(symbol, nil)
  end
end

.search_archive_by_id(value) ⇒ Object

Search archive for historical records of people who were committers but never submitted an ICLA (some of which are still ASF members or members of a PMC).



216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/whimsy/asf/icla.rb', line 216

def self.search_archive_by_id(value)
  require 'net/http'
  require 'nokogiri'
  historical_committers = 'http://people.apache.org/~rubys/committers.html'
  doc = Nokogiri::HTML(Net::HTTP.get(URI.parse(historical_committers)))
  doc.search('tr').each do |tr|
    tds = tr.search('td')
    next unless tds.length == 3
    return tds[1].text if tds[0].text == value
  end
  nil
rescue
  nil
end

.search_one(base, filter, attrs = nil) ⇒ Object

search with a scope of one



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/whimsy/asf/ldap.rb', line 51

def self.search_one(base, filter, attrs=nil)
  init_ldap unless defined? @ldap
  return [] unless @ldap

  Wunderbar.info "ldapsearch -x -LLL -b #{base} -s one #{filter} " +
    "#{[attrs].flatten.join(' ')}"
  
  begin
    result = @ldap.search2(base, ::LDAP::LDAP_SCOPE_ONELEVEL, filter, attrs)
  rescue
    result = []
  end

  result.map! {|hash| hash[attrs]} if String === attrs

  result
end