Class: Morpheus::Cli::Login

Inherits:
Object
  • Object
show all
Includes:
CliCommand
Defined in:
lib/morpheus/cli/login.rb

Instance Attribute Summary

Attributes included from CliCommand

#no_prompt

Instance Method Summary collapse

Methods included from CliCommand

#build_common_options, #build_option_type_options, #command_name, #default_subcommand, #establish_remote_appliance_connection, #handle_subcommand, included, #interactive?, #noninteractive, #print_usage, #subcommand_aliases, #subcommand_usage, #subcommands, #verify_access_token!

Constructor Details

#initializeLogin

include Morpheus::Cli::WhoamiHelper include Morpheus::Cli::AccountsHelper



12
13
14
# File 'lib/morpheus/cli/login.rb', line 12

def initialize()
  
end

Instance Method Details

#connect(opts) ⇒ Object



16
17
18
# File 'lib/morpheus/cli/login.rb', line 16

def connect(opts)
  #@api_client = establish_remote_appliance_connection(opts)
end

#handle(args) ⇒ Object



24
25
26
# File 'lib/morpheus/cli/login.rb', line 24

def handle(args)
  (args)
end

#login(args) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/morpheus/cli/login.rb', line 28

def (args)
  options = {}
  username, password = nil, nil
  optparse = OptionParser.new do|opts|
    opts.banner = usage
    opts.on( '-u', '--username USERNAME', "Username" ) do |val|
      username = val
    end
    opts.on( '-p', '--password PASSWORD', "Password" ) do |val|
      password = val
    end
    build_common_options(opts, options, [:json, :remote, :quiet])
  end
  optparse.parse!(args)

  # connect(options)
  if options[:remote]
    appliance = Morpheus::Cli::Remote.appliances[options[:remote].to_sym]
    if appliance
      @appliance_name, @appliance_url = options[:remote].to_sym, appliance[:host]
    else
      @appliance_name, @appliance_url = nil, nil
    end
  else
    @appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
  end

  begin
    if !@appliance_name
      print yellow,"Please specify a remote appliance with -r or see the command `remote use`#{reset}\n"
      return false
    end
    if options[:quiet]
      if username.empty? || password.empty?
        print yellow,"You have not specified username and password\n"
        return false
      end
    end
    options[:remote_username] = username if username
    options[:remote_password] = password if password
    #options[:remote_url] = true # will skip credentials save
    Morpheus::Cli::Credentials.new(@appliance_name, @appliance_url).(options)

  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end

end

#usageObject



20
21
22
# File 'lib/morpheus/cli/login.rb', line 20

def usage
  "Usage: morpheus login"
end