def add(name, key)
begin
file = File.open(key)
rescue Errno::ENOENT => e
raise ::RHC::KeyFileNotExistentException.new("File '#{key}' does not exist.")
rescue Errno::EACCES => e
raise ::RHC::KeyFileAccessDeniedException.new("Access denied to '#{key}'.")
end
type, content, comment = file.gets.chomp.split
begin
Net::SSH::KeyFactory.load_data_public_key "#{type} #{content}"
rescue NotImplementedError, Net::SSH::Exception => e
raise ::RHC::KeyDataInvalidException.new("File '#{key}' contains invalid data")
end
rest_client.add_key(name, content, type)
results { say "SSH key #{key} has been added as '#{name}'" }
0
end