class Tapjoy::LDAP::Key::Install
Install
key on localhost
Public Instance Methods
install()
click to toggle source
# File lib/tapjoy/ldap/key/install.rb, line 6 def install Tapjoy::LDAP::Key.get_keys_from_ldap.each do |user, values| directory = directory(user) FileUtils.mkdir_p(directory) unless File.exists?directory authorized_keys_file = "#{directory}/authorized_keys" keys = load_keys_from_file(authorized_keys_file) insert_keys(authorized_keys_file, keys, values) end end
Private Instance Methods
directory(user)
click to toggle source
# File lib/tapjoy/ldap/key/install.rb, line 40 def directory(user) File.join('etc', 'ssh', 'users', user) end
insert_keys(authorized_keys_file, keys, values)
click to toggle source
# File lib/tapjoy/ldap/key/install.rb, line 34 def insert_keys(authorized_keys_file, keys, values) File.open(authorized_keys_file, 'a+') do |file| file.puts values.reject { |value| keys.include?(value) } end end
load_keys_from_file(authorized_keys_file)
click to toggle source
# File lib/tapjoy/ldap/key/install.rb, line 26 def load_keys_from_file(authorized_keys_file) if File.exists?(authorized_keys_file) keys = File.read(authorized_keys_file) else keys = [] end end
opts()
click to toggle source
# File lib/tapjoy/ldap/key/install.rb, line 17 def opts @opts ||= Optimist.options do # Set help message usage 'key install' synopsis "\nThis command is for adding keys to the appropriate authorized_keys file" end end