class RHC::Commands::Sshkey
Public Instance Methods
add(name, key_path=nil)
click to toggle source
# File lib/rhc/commands/sshkey.rb, line 51 def add(name, key_path=nil) if key_path type, content, comment = ssh_key_triple_for(key_path) elsif options[:type].present? and options[:content].present? type = options[:type] content = options[:content] else raise ArgumentError, "You must either provide a key file, or the key type and content" end if type == 'krb5-principal' # TODO: validate krb5? else # validate the user input before sending it to the server begin Net::SSH::KeyFactory.load_data_public_key "#{type} #{content}" rescue NotImplementedError, OpenSSL::PKey::PKeyError, Net::SSH::Exception => e debug e.inspect if options.confirm warn 'The key you are uploading is not recognized. You may not be able to authenticate to your application through Git or SSH.' else raise ::RHC::KeyDataInvalidException.new("File '#{key_path}' does not appear to be a recognizable key file (#{e}). You may specify the '--confirm' flag to add the key anyway.") if key_path raise ::RHC::KeyDataInvalidException.new("The provided type and content does not appear to be a recognizable key (#{e}). You may specify the '--confirm' flag to add the key anyway.") end end end rest_client.add_key(name, content, type) results { say key_path ? "SSH key #{key_path} has been added as '#{name}'" : "SSH key '#{name}' has been added" } 0 end
list()
click to toggle source
# File lib/rhc/commands/sshkey.rb, line 26 def list keys = rest_client.sshkeys.each{ |key| paragraph{ display_key(key) } } success "You have #{keys.length} SSH keys associated with your account." 0 end
remove(name)
click to toggle source
# File lib/rhc/commands/sshkey.rb, line 89 def remove(name) say "Removing the key '#{name} ... " rest_client.delete_key(name) success "removed" 0 end
show(name)
click to toggle source
# File lib/rhc/commands/sshkey.rb, line 37 def show(name) key = rest_client.find_key(name) display_key(key) 0 end