# File lib/rhc/commands/sshkey.rb, line 52
    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