class Tapjoy::LDAP::Key::Add

Add user key to user profile

Public Instance Methods

add() click to toggle source

Add key to LDAP

# File lib/tapjoy/ldap/key/add.rb, line 7
def add
  filter_users.each  do |result|
    confirm_ldap_schema(result)
    keys.each do |key|
      puts Tapjoy::LDAP.client.add_attribute(result.dn, :sshPublicKey, key)
    end
  end
end

Private Instance Methods

confirm_ldap_schema(result) click to toggle source
# File lib/tapjoy/ldap/key/add.rb, line 42
def confirm_ldap_schema(result)
  unless result.objectclass.include?('ldapPublicKey')
    puts 'LDAP Public Key Object Class not found.'
    abort 'Please ensure user was created correctly.'
  end
end
filter_users() click to toggle source
# File lib/tapjoy/ldap/key/add.rb, line 33
def filter_users
  filter = Net::LDAP::Filter.eq('uid', opts[:username])
  results = Tapjoy::LDAP.client.search(attributes = ['*'], filter = filter)

  Tapjoy::LDAP::Key.verify_user(opts[:username], results)

  results
end
keys() click to toggle source
# File lib/tapjoy/ldap/key/add.rb, line 29
def keys
  @keys ||= Tapjoy::LDAP::Key.get_keys_from_commandline(opts[:filename] || nil)
end
opts() click to toggle source
# File lib/tapjoy/ldap/key/add.rb, line 17
def opts
  @opts ||= Optimist.options do
      # Set help message
      usage 'key add [options]'
      synopsis "\nThis command is for adding user keys to a given user's profile"

      opt :username, 'Specify username to add key to', type: :string,
        required: true
      opt :filename, 'File to load keys from', type: :string
  end
end