whimsy-asf 0.0.43 → 0.0.44

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/asf.version +1 -1
  3. data/lib/whimsy/asf/ldap.rb +53 -0
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 87007616ab9dc536c51a6b80133d606df7f49592
4
- data.tar.gz: 1438b5ff08f544b7d7f86e9d1e138806228e1b31
3
+ metadata.gz: 7a6eaa3a6a967e8b9b0dc268e4ec2bd4ff268ea0
4
+ data.tar.gz: b39573a643e6d010cff645ec29319b23097d22b7
5
5
  SHA512:
6
- metadata.gz: ece30f2772dbfebe48a2f621048391e85e86280e901ab84830d2c8f153f9c54fdd1ae41ae722d140e391c73e369be3d426e890cf21bb1591c460a70955898cc2
7
- data.tar.gz: 0cd0ed8d12e8577361f01c30293ed8822730e9bb7e92342c0add047a5354e436ab262d592a9964585a1d970ad00ab3e3b9f38bff26ead0e093ef49c3a1f1b526
6
+ metadata.gz: 6b120875f62fb4f48222adefc3125a847feda1750c72676eb5ff8798e0ea50c651ff358a9d870c031a0880dcdedcc46e486341a0610696eac737bc6f670c74cc
7
+ data.tar.gz: 9a0ea08eb4c7a7c23f436090294ed597945da108c31ae3c963f49b691c853b1fc820d040e38507096ead6de64d0b7d8f5cdf324873679072186a1653f0efdb86
data/asf.version CHANGED
@@ -1 +1 @@
1
- 0.0.43
1
+ 0.0.44
@@ -29,6 +29,10 @@ module ASF
29
29
  end
30
30
  end
31
31
 
32
+ def self.ldap
33
+ @ldap || self.init_ldap
34
+ end
35
+
32
36
  # search with a scope of one
33
37
  def self.search_one(base, filter, attrs=nil)
34
38
  init_ldap unless defined? @ldap
@@ -198,6 +202,42 @@ module ASF
198
202
  def groups
199
203
  Group.list("memberUid=#{name}")
200
204
  end
205
+
206
+ def dn
207
+ attrs['dn']
208
+ end
209
+
210
+ def method_missing(name, *args)
211
+ if name.to_s.end_with? '=' and args.length == 1
212
+ return modify(name.to_s[0..-2], args)
213
+ end
214
+
215
+ return super unless args.empty?
216
+ result = self.attrs[name.to_s]
217
+ return super unless result
218
+
219
+ if result.empty?
220
+ return nil
221
+ else
222
+ result.map! do |value|
223
+ value = value.dup.force_encoding('utf-8') if String === value
224
+ value
225
+ end
226
+
227
+ if result.length == 1
228
+ result.first
229
+ else
230
+ result
231
+ end
232
+ end
233
+ end
234
+
235
+ def modify(attr, value)
236
+ value = Array(value) unless Hash === value
237
+ mod = ::LDAP::Mod.new(::LDAP::LDAP_MOD_REPLACE, attr.to_s, value)
238
+ ASF.ldap.modify(self.dn, [mod])
239
+ attrs[attr.to_s] = value
240
+ end
201
241
  end
202
242
 
203
243
  class Group < Base
@@ -233,6 +273,10 @@ module ASF
233
273
  ASF.search_one(base, "cn=#{name}", 'member').flatten.
234
274
  map {|uid| Person.find uid[/uid=(.*?),/,1]}
235
275
  end
276
+
277
+ def dn
278
+ @dn ||= ASF.search_one(base, "cn=#{name}", 'dn').first.first
279
+ end
236
280
  end
237
281
 
238
282
  class Service < Base
@@ -249,6 +293,15 @@ module ASF
249
293
  end
250
294
 
251
295
  module LDAP
296
+ def self.bind(user, password, &block)
297
+ dn = ASF::Person.new(user).dn
298
+ if block
299
+ ASF.ldap.bind(dn, password, &block)
300
+ else
301
+ ASF.ldap.bind(dn, password)
302
+ end
303
+ end
304
+
252
305
  # select LDAP host
253
306
  def self.host
254
307
  # try whimsy config
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whimsy-asf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.43
4
+ version: 0.0.44
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Ruby
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-29 00:00:00.000000000 Z
11
+ date: 2015-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -146,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
146
  version: '0'
147
147
  requirements: []
148
148
  rubyforge_project:
149
- rubygems_version: 2.4.5
149
+ rubygems_version: 2.4.5.1
150
150
  signing_key:
151
151
  specification_version: 4
152
152
  summary: Whimsy 'model' of the ASF