module Tapjoy::LDAP::API::Group

API methods for managing LDAP Groups

Public Class Methods

create(group_name, group_type) click to toggle source
# File lib/tapjoy/ldap/api/group.rb, line 7
def create(group_name, group_type)
  Tapjoy::LDAP.client.add(
    distinguished_name(group_name),
    ldap_attr(group_name, group_type)
  )
end
destroy(group_name) click to toggle source
# File lib/tapjoy/ldap/api/group.rb, line 14
def destroy(group_name)
  Tapjoy::LDAP.client.delete(distinguished_name(group_name))
end
index() click to toggle source
# File lib/tapjoy/ldap/api/group.rb, line 25
def index
  Tapjoy::LDAP.client.search('*', group_object_class_filter)
end
lookup_id(groupname) click to toggle source

Lookup GID for the given group

# File lib/tapjoy/ldap/api/group.rb, line 30
def lookup_id(groupname)
  gidnumber = []

  cn_filter = Net::LDAP::Filter.eq('cn', groupname)
  filter    = Net::LDAP::Filter.join(
    group_object_class_filter, cn_filter)

  results = Tapjoy::LDAP.client.search(['gidNumber'], filter)

  # Make sure we return one, and only one group
  if results.size < 1
    abort('Group not found')
  elsif results.size > 1
    abort('Multiple groups found. Please narrow your search.')
  end

  results.each { |result| gidnumber = result.gidnumber }
  return gidnumber[0]
end
update(group_name, username, operation) click to toggle source
# File lib/tapjoy/ldap/api/group.rb, line 18
def update(group_name, username, operation)
  Tapjoy::LDAP.client.modify(
    distinguished_name(group_name),
    [[operation, :memberUid, username]]
  )
end

Private Class Methods

distinguished_name(group_name) click to toggle source
# File lib/tapjoy/ldap/api/group.rb, line 57
def distinguished_name(group_name)
  %W(
    cn=#{group_name}
    ou=Group
    #{Tapjoy::LDAP.client.basedn}).join(',')
end
group_object_class_filter() click to toggle source
# File lib/tapjoy/ldap/api/group.rb, line 52
def group_object_class_filter
  Net::LDAP::Filter.eq('objectClass', 'posixGroup')
end
ldap_attr(group_name, group_type) click to toggle source
# File lib/tapjoy/ldap/api/group.rb, line 65
def ldap_attr(group_name, group_type)
  {
    cn:          group_name,
    objectclass: %w(top posixGroup),
    gidnumber:   Tapjoy::LDAP.client.get_max_id('group', group_type)
  }
end