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
.committers ⇒ Object
193
194
195
|
# File 'lib/whimsy/asf/ldap.rb', line 193
def self.committers
weakref(:committers) {Group.find('committers').members}
end
|
.dereference_weakref(object, attr, &block) ⇒ Object
safely dereference a weakref array attribute. Block provided is used when reference is not set or has been reclaimed.
171
172
173
174
175
176
177
178
179
180
181
182
183
|
# File 'lib/whimsy/asf/ldap.rb', line 171
def self.dereference_weakref(object, attr, &block)
attr = "@#{attr}"
value = object.instance_variable_get(attr) || block.call
value[0..-1]
rescue WeakRef::RefError
value = block.call
ensure
if not value or RUBY_VERSION.start_with? '1'
object.instance_variable_set(attr, value)
elsif value and not value.instance_of? WeakRef
object.instance_variable_set(attr, WeakRef.new(value))
end
end
|
.init_ldap(reset = false) ⇒ Object
public entry point for establishing a connection safely
116
117
118
119
120
121
|
# File 'lib/whimsy/asf/ldap.rb', line 116
def self.init_ldap(reset = false)
ASF::LDAP::CONNECT_LOCK.synchronize do
@ldap = nil if reset
@ldap ||= ASF::LDAP.connect(!reset)
end
end
|
.ldap ⇒ Object
130
131
132
|
# File 'lib/whimsy/asf/ldap.rb', line 130
def self.ldap
@ldap || self.init_ldap
end
|
.library_gitinfo ⇒ Object
20
21
22
23
|
# File 'lib/whimsy/asf.rb', line 20
def self.library_gitinfo
return @info if @info
@info = `git show --format="%h %ci" -s HEAD`.chomp
end
|
.library_mtime ⇒ Object
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
|
.members ⇒ Object
197
198
199
|
# File 'lib/whimsy/asf/ldap.rb', line 197
def self.members
weakref(:members) {Group.find('member').members}
end
|
.pmc_chairs ⇒ Object
189
190
191
|
# File 'lib/whimsy/asf/ldap.rb', line 189
def self.pmc_chairs
weakref(:pmc_chairs) {Service.find('pmc-chairs').members}
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).
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
# File 'lib/whimsy/asf/icla.rb', line 231
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, with automatic retry/failover
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
# File 'lib/whimsy/asf/ldap.rb', line 135
def self.search_one(base, filter, attrs=nil)
cmd = "ldapsearch -x -LLL -b #{base} -s one #{filter} " +
"#{[attrs].flatten.join(' ')}"
attempts_left = [ASF::LDAP.hosts.length, 2].max
begin
attempts_left -= 1
init_ldap unless @ldap
return [] unless @ldap
target = @ldap.get_option(::LDAP::LDAP_OPT_HOST_NAME) rescue '?'
Wunderbar.info "[#{target}] #{cmd}"
result = @ldap.search2(base, ::LDAP::LDAP_SCOPE_ONELEVEL, filter, attrs)
rescue Exception => re
if attempts_left <= 0
Wunderbar.error "[#{target}] => #{re.inspect} for #{cmd}"
raise
else
Wunderbar.warn "[#{target}] => #{re.inspect} for #{cmd}, retrying ..."
@ldap.unbind if @ldap.bound? rescue nil
@ldap = nil
sleep 1
retry
end
end
result.map! {|hash| hash[attrs]} if String === attrs
result.compact
end
|
.weakref(attr, &block) ⇒ Object
185
186
187
|
# File 'lib/whimsy/asf/ldap.rb', line 185
def self.weakref(attr, &block)
self.dereference_weakref(self, attr, &block)
end
|