class ASF::Service

Access to LDAP services (ou=groups,ou=services,dc=apache,dc=org)

Attributes

createTimestamp[RW]

Date this committee was initially created in LDAP.

modifyTimestamp[RW]

Date this committee was last modified in LDAP.

Public Class Methods

list(filter='cn=*') click to toggle source

return a list of services, from LDAP.

# File lib/whimsy/asf/ldap.rb, line 1270
def self.list(filter='cn=*')
  ASF.search_one(base, filter, 'cn').flatten
end
preload() click to toggle source

fetch dn, member, modifyTimestamp, and createTimestamp for all services in LDAP.

# File lib/whimsy/asf/ldap.rb, line 1293
def self.preload
  Hash[ASF.search_one(base, "cn=*", %w(dn member modifyTimestamp createTimestamp)).map do |results|
    cn = results['dn'].first[/^cn=(.*?),/, 1]
    service = self.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

Public Instance Methods

add(people) click to toggle source

add people to this service in LDAP

# File lib/whimsy/asf/ldap.rb, line 1335
def add(people)
  @members = nil
  people = (Array(people) - members).map(&:dn)
  ASF::LDAP.modify(self.dn, [ASF::Base.mod_add('member', people)])
ensure
  @members = nil
end
base() click to toggle source

base subtree for this service

Calls superclass method ASF::Base.base
# File lib/whimsy/asf/ldap.rb, line 1283
def base
  if dn
    dn.sub(/^cn=.*?,/, '')
  else
    super
  end
end
dn() click to toggle source

Designated Name from LDAP

# File lib/whimsy/asf/ldap.rb, line 1275
def dn
  return @dn if @dn
  dns = ASF.search_subtree(self.class.base, "cn=#{name}", 'dn')
  @dn = dns.first.first unless dns.empty?
  @dn
end
members() click to toggle source

list of members for this service in LDAP

# File lib/whimsy/asf/ldap.rb, line 1317
def members
  members = weakref(:members) do
    ASF.search_one(base, "cn=#{name}", 'member').flatten
  end

  members.map {|uid| Person.find uid[/uid=(.*?),/,1]}
end
members=(members) click to toggle source

setters for members. Should only be called by preload

# File lib/whimsy/asf/ldap.rb, line 1312
def members=(members)
  @members = WeakRef.new(members)
end
remove(people) click to toggle source

remove people from this service in LDAP

# File lib/whimsy/asf/ldap.rb, line 1326
def remove(people)
  @members = nil
  people = (Array(people) & members).map(&:dn)
  ASF::LDAP.modify(self.dn, [ASF::Base.mod_delete('member', people)])
ensure
  @members = nil
end