def add_or_update_key(command, identifier, pub_key_file_path, rhlogin, password)
if pub_key_file_path
if File.readable?(pub_key_file_path)
begin
ssh_keyfile_contents = File.open(pub_key_file_path).gets.chomp.split(' ')
ssh_key = ssh_keyfile_contents[1]
ssh_key_type = ssh_keyfile_contents[0]
rescue Exception => e
puts "Invalid public keyfile format! Please specify a valid user public keyfile."
exit 1
end
else
puts "Unable to read user public keyfile #{pub_key_file_path}"
exit 1
end
else
key_name = identifier
puts "Generating ssh key pair for user '#{key_name}' in the dir '#{Dir.pwd}/'"
ssh_pub_key_file = generate_ssh_key_ruby()
ssh_keyfile_contents = File.open(ssh_pub_key_file).gets.chomp.split(' ')
ssh_key = ssh_keyfile_contents[1]
ssh_key_type = ssh_keyfile_contents[0]
end
data = {}
data[:rhlogin] = rhlogin
data[:key_name] = identifier
data[:ssh] = ssh_key
data[:action] = 'add-key'
data[:key_type] = ssh_key_type
if command == 'add'
data[:action] = 'add-key'
elsif command == 'update'
data[:action] = 'update-key'
end
url = URI.parse("https://#{RHC::Config['libra_server']}/broker/ssh_keys")
handle_key_mgmt_response(url, data, password)
end