module Tapjoy::LDAP::Key

Entry point for all key subcommands

Constants

SUB_COMMANDS

Public Class Methods

add() click to toggle source
# File lib/tapjoy/ldap/key.rb, line 32
def add
  key = Tapjoy::LDAP::Key::Add.new
  key.add
end
commands() click to toggle source
# File lib/tapjoy/ldap/key.rb, line 14
def commands
  Optimist.options do
    usage 'key [SUB_COMMAND] [options]'
    synopsis "\nThis object is used for user key management\nAvailable subcommands are: #{SUB_COMMANDS}"

    stop_on SUB_COMMANDS
  end

  cmd = ARGV.shift

  case cmd
  when 'add', 'remove', 'install', 'list', 'show'
    send(cmd) # call method with respective name
  else
    raise Tapjoy::LDAP::InvalidArgument
  end
end
get_keys_from_commandline(filename=nil) click to toggle source

Retrieve keys from file/stdin

# File lib/tapjoy/ldap/key.rb, line 66
def get_keys_from_commandline(filename=nil)
  ARGV << filename unless filename.nil?
  return_keys = []

  ARGF.each do |line|
    return_keys << line.chomp!
  end
  ARGV << '-'  # close ARGF
  return_keys.each { |key| verify_key(key) }
  return_keys
end
get_keys_from_ldap() click to toggle source
# File lib/tapjoy/ldap/key.rb, line 56
def get_keys_from_ldap
  key_results = {}
  filter = Net::LDAP::Filter.eq('sshPublicKey', '*')
  attributes = %w(uid sshPublicKey)
  results = Tapjoy::LDAP.client.search(attributes, filter)
  results.each {|result| key_results[result.uid[0]] = result.sshpublickey}
  key_results
end
install() click to toggle source
# File lib/tapjoy/ldap/key.rb, line 42
def install
  key = Tapjoy::LDAP::Key::Install.new
  key.install
end
list() click to toggle source
# File lib/tapjoy/ldap/key.rb, line 47
def list
  puts JSON.pretty_generate(Tapjoy::LDAP::Key.get_keys_from_ldap)
end
remove() click to toggle source
# File lib/tapjoy/ldap/key.rb, line 37
def remove
  key = Tapjoy::LDAP::Key::Remove.new
  key.remove
end
show() click to toggle source
# File lib/tapjoy/ldap/key.rb, line 51
def show
  key = Tapjoy::LDAP::Key::Show.new
  key.show
end
verify_key(key) click to toggle source
# File lib/tapjoy/ldap/key.rb, line 78
def verify_key(key)
  unless key.start_with?('ssh')
    puts "Invalid key due to missing ssh key type:\n\n"
    puts "\t#{ key }\n\n"
    abort "Please verify your key and try again"
  end
end
verify_user(user, results) click to toggle source
# File lib/tapjoy/ldap/key.rb, line 86
def verify_user(user, results)
  # Make sure we return one, and only one user DN
  if results.size < 1
    puts "User (#{user}) not found."
    abort 'Please check the username and try again'
  elsif results.size > 1
    abort 'Multiple users found. Please narrow your search.'
  end
end