Class: Morpheus::Cli::AuthCommand
- Inherits:
-
Object
- Object
- Morpheus::Cli::AuthCommand
show all
- Includes:
- CliCommand
- Defined in:
- lib/morpheus/cli/auth_command.rb
Overview
This provides commands for authentication This also includes credential management.
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_refresh_interval, #default_subcommand, #establish_remote_appliance_connection, #full_command_usage, #handle_subcommand, included, #interactive?, #my_help_command, #my_terminal, #my_terminal=, #parse_id_list, #parse_list_options, #parse_list_subtitles, #print, #print_error, #puts, #puts_error, #raise_command_error, #render_with_format, #run_command_for_each_arg, #subcommand_aliases, #subcommand_usage, #subcommands, #usage, #verify_access_token!
Constructor Details
Returns a new instance of AuthCommand.
19
20
21
|
# File 'lib/morpheus/cli/auth_command.rb', line 19
def initialize()
end
|
Instance Method Details
#connect(options) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/morpheus/cli/auth_command.rb', line 23
def connect(options)
@api_client = establish_remote_appliance_connection(options.merge({:no_prompt => true, :skip_verify_access_token => true}))
if !@appliance_name
unless options[:quiet]
print yellow,"Please specify a Morpheus Appliance with -r or see the command `remote use`#{reset}\n"
end
return 1
end
if !@appliance_url
unless options[:quiet]
print red,"Unable to determine remote appliance url. Review your remote configuration.#{reset}\n"
end
return 1
end
if @wallet.nil? || @wallet['access_token'].nil?
unless options[:quiet]
print_error yellow,"You are not currently logged in to #{display_appliance(@appliance_name, @appliance_url)}",reset,"\n"
print_error yellow,"Use the 'login' command.",reset,"\n"
end
return 1
end
end
|
#get(args) ⇒ Object
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
77
78
79
80
81
82
83
84
85
|
# File 'lib/morpheus/cli/auth_command.rb', line 52
def get(args)
options = {}
params = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage()
build_common_options(opts, options, [:remote, :quiet])
opts. = "Print your current authentication info.\n" +
"This contains tokens that should be kept secret, be careful."
end
optparse.parse!(args)
if args.count != 0
raise_command_error "wrong number of arguments, expected 0 and got (#{args.count}) #{args.join(' ')}\n#{optparse}"
end
connect_result = connect(options)
return connect_result if (connect_result.is_a?(Numeric) && connect_result != 0)
print_h1 "Morpheus Credentials", [], options
description_cols = {
"Remote" => lambda {|wallet| @appliance_name },
"Username" => lambda {|wallet| wallet['username'] },
"Access Token" => lambda {|wallet| wallet['access_token'] },
"Refresh Token" => lambda {|wallet| wallet['refresh_token'] },
"Login Date" => lambda {|wallet| format_local_dt(wallet['login_date']) },
"Expire Date" => lambda {|wallet| wallet['expire_date'] ? format_local_dt(wallet['expire_date']) : "" },
}
print cyan
puts as_description_list(@wallet, description_cols)
print reset
return 0
end
|
#handle(args) ⇒ Object
48
49
50
|
# File 'lib/morpheus/cli/auth_command.rb', line 48
def handle(args)
handle_subcommand(args)
end
|
#login(args) ⇒ Object
these are all just aliases, heh
#login_test(args) ⇒ Object
93
94
95
|
# File 'lib/morpheus/cli/auth_command.rb', line 93
def login_test(args)
::Morpheus::Cli::Login.new.handle(['--test'] + args)
end
|
#print_access_token(args) ⇒ Object
#use_refresh_token(args) ⇒ Object