class Morpheus::Cli::Logout

Public Instance Methods

connect(options) click to toggle source
# File lib/morpheus/cli/commands/logout.rb, line 6
def connect(options)
  @api_client = establish_remote_appliance_connection(options.merge({:no_prompt => true, :skip_verify_access_token => true, :skip_login => true}))
end
handle(args) click to toggle source
# File lib/morpheus/cli/commands/logout.rb, line 14
def handle(args)
  logout(args)
end
logout(args) click to toggle source
# File lib/morpheus/cli/commands/logout.rb, line 18
  def logout(args)
    options = {}
    optparse = Morpheus::Cli::OptionParser.new do |opts|
      opts.banner = usage
      build_common_options(opts, options, [:remote, :quiet])
      opts.footer = <<-EOT
Logout of a remote appliance.
This clears your credentials so that you will need to login again.
EOT
    end
    optparse.parse!(args)
    verify_args!(args:args,count:0,optpare:optparse)
    connect(options)

    if !@appliance_name
      print_error Morpheus::Terminal.angry_prompt
      puts_error "Please specify a Morpheus Appliance to logout of with -r or see the command `remote use`"
      return 1
    end
    wallet = Morpheus::Cli::Credentials.new(@appliance_name, @appliance_url).load_saved_credentials
    token = wallet ? wallet['access_token'] : nil
    if !token
      if !options[:quiet]
        puts "You are not currently logged in to #{display_appliance(@appliance_name, @appliance_url)}"
      end
    else
      # todo: need to tell the server to delete the token too..
      # delete token from credentials file
      # note: this also handles updating appliance session info
      Morpheus::Cli::Credentials.new(@appliance_name, @appliance_url).logout()
      if !options[:quiet]
        puts "#{cyan}Logged out of #{@appliance_name}. Goodbye #{wallet['username']}!#{reset}"
      end
    end
    # recalcuate echo vars
    Morpheus::Cli::Echo.recalculate_variable_map()
    # recalculate shell prompt after this change
    if Morpheus::Cli::Shell.has_instance?
      Morpheus::Cli::Shell.instance.reinitialize()
    end
    return 0

  end
usage() click to toggle source
# File lib/morpheus/cli/commands/logout.rb, line 10
def usage
  "Usage: morpheus logout"
end