module Tapjoy::LDAP::API::User
Public Class Methods
create(fname, lname, type, group)
click to toggle source
# File lib/tapjoy/ldap/api/user.rb, line 8 def create(fname, lname, type, group) # Properly capitalize names fname, lname = [fname, lname].map(&:capitalize) Tapjoy::LDAP.client.add( distinguished_name(fname, lname, type), ldap_attr(fname, lname, type, group) ) end
destroy(username, type)
click to toggle source
# File lib/tapjoy/ldap/api/user.rb, line 18 def destroy(username, type) Tapjoy::LDAP.client.delete( distinguished_name(*name_of_user(username), type) ) end
index()
click to toggle source
# File lib/tapjoy/ldap/api/user.rb, line 24 def index Tapjoy::LDAP.client.search('*', filter(uid: '*')) end
show(username)
click to toggle source
# File lib/tapjoy/ldap/api/user.rb, line 28 def show(username) Tapjoy::LDAP.client.search('*', filter(uid: username)) end
Private Class Methods
create_password()
click to toggle source
# File lib/tapjoy/ldap/api/user.rb, line 100 def create_password # Super-Salt: bad for blood pressure, good for secure passwords # We can get away with this, since we're not planning on using passwords salt = SecureRandom.base64(32) password = SecureRandom.base64(64) password = Digest::SHA1.base64digest(password + salt) end
distinguished_name(fname, lname, type)
click to toggle source
# File lib/tapjoy/ldap/api/user.rb, line 51 def distinguished_name(fname, lname, type) %W( uid=#{username(fname, lname)} ou=#{organizational_unit(type)} #{Tapjoy::LDAP.client.basedn}).join(',') end
filter(uid: '*')
click to toggle source
Filter users for show and index
# File lib/tapjoy/ldap/api/user.rb, line 35 def filter(uid: '*') Net::LDAP::Filter.eq('uid', uid) end
gidnumber(group)
click to toggle source
# File lib/tapjoy/ldap/api/user.rb, line 95 def gidnumber(group) Tapjoy::LDAP::API::Group.lookup_id(group) end
ldap_attr(fname, lname, type, group)
click to toggle source
# File lib/tapjoy/ldap/api/user.rb, line 71 def ldap_attr(fname, lname, type, group) uid = username(fname, lname) { uid: uid, cn: [fname, lname].join(' '), objectclass: %w(top posixAccount shadowAccount inetOrgPerson organizationalPerson person ldapPublicKey), sn: lname, givenname: fname, # Empty string is an alias for the root of the FS homedirectory: File.join('','home', uid), loginshell: File.join('','bin', 'bash'), mail: "#{uid}@tapjoy.com", uidnumber: uidnumber(type), gidnumber: gidnumber(group), userpassword: '{SSHA}' + create_password } end
name_of_user(username)
click to toggle source
Given a username, return First and Last names
# File lib/tapjoy/ldap/api/user.rb, line 40 def name_of_user(username) username.split('.').map(&:capitalize) end
organizational_unit(type)
click to toggle source
# File lib/tapjoy/ldap/api/user.rb, line 59 def organizational_unit(type) case type when 'user' 'People' when 'service' Tapjoy::LDAP.client.service_ou else puts 'Unknown type' end end
uidnumber(type)
click to toggle source
# File lib/tapjoy/ldap/api/user.rb, line 91 def uidnumber(type) Tapjoy::LDAP.client.get_max_id('user', type) end
username(fname, lname)
click to toggle source
Given First and Last names, return a username
# File lib/tapjoy/ldap/api/user.rb, line 46 def username(fname, lname) [fname, lname].join('.').downcase end