morpheus-cli 3.4.1.3 → 3.4.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/morpheus/cli/credentials.rb +84 -52
- data/lib/morpheus/cli/login.rb +4 -1
- data/lib/morpheus/cli/version.rb +1 -1
- data/lib/morpheus/cli/whoami.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e36f51274524a0ee48ba3f6c51e224d29bc42118
|
4
|
+
data.tar.gz: dadbf3df8aa4ff8fd29d28ffc1b3407d22e2d02b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e526f9adc5da2b3cadd57ea97ffa63ad89052383e8e0ecbe373edf6dd948503d078a0c302186365af8e07c1f769fdbf1b7c24dd441f0024ff97c4cad1de66fb
|
7
|
+
data.tar.gz: 1ccc01cfd9fbc9a5785b41dc5ce294cc3b0b27a9e3e875777aa60db2f68d64594f3a6371154ecfce61bdc6b3c4db144271caeecb262b50864ac21086b2155e00
|
@@ -24,69 +24,101 @@ module Morpheus
|
|
24
24
|
password = nil
|
25
25
|
access_token = nil
|
26
26
|
skip_save = false
|
27
|
-
|
28
|
-
if
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
27
|
+
|
28
|
+
if opts[:remote_token]
|
29
|
+
begin
|
30
|
+
whoami_interface = Morpheus::WhoamiInterface.new(opts[:remote_token], nil, nil, @appliance_url)
|
31
|
+
whoami_response = whoami_interface.get()
|
32
|
+
if opts[:json]
|
33
|
+
print JSON.pretty_generate(whoami_response)
|
34
|
+
print reset, "\n"
|
35
|
+
end
|
36
|
+
access_token = opts[:remote_token]
|
37
|
+
username = whoami_response['user']['username']
|
38
|
+
unless skip_save
|
39
|
+
save_credentials(@appliance_name, access_token)
|
40
|
+
end
|
41
|
+
rescue ::RestClient::Exception => e
|
42
|
+
#raise e
|
43
|
+
if (e.response && e.response.code == 400)
|
44
|
+
print_red_alert "Token not valid."
|
45
|
+
if opts[:json]
|
46
|
+
whoami_response = JSON.parse(e.response.to_s)
|
47
|
+
print JSON.pretty_generate(whoami_response)
|
48
|
+
print reset, "\n"
|
49
|
+
end
|
50
|
+
else
|
51
|
+
#print_rest_exception(e, opts)
|
52
|
+
print_red_alert "Token not valid."
|
53
|
+
end
|
54
|
+
access_token = nil
|
47
55
|
end
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
56
|
+
else
|
57
|
+
|
58
|
+
if !opts[:remote_username].nil?
|
59
|
+
username = opts[:remote_username]
|
60
|
+
password = opts[:remote_password]
|
61
|
+
skip_save = opts[:remote_url] ? true : false
|
52
62
|
else
|
53
|
-
|
63
|
+
access_token = load_saved_credentials
|
54
64
|
end
|
55
|
-
|
56
|
-
|
57
|
-
print_red_alert "Username and password are required to login."
|
58
|
-
return nil
|
59
|
-
end
|
60
|
-
begin
|
61
|
-
auth_interface = Morpheus::AuthInterface.new(@appliance_url)
|
62
|
-
json_response = auth_interface.login(username, password)
|
63
|
-
if opts[:json]
|
64
|
-
print JSON.pretty_generate(json_response)
|
65
|
-
print reset, "\n"
|
65
|
+
if access_token
|
66
|
+
return access_token
|
66
67
|
end
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
68
|
+
unless opts[:quiet] || opts[:no_prompt]
|
69
|
+
# if username.empty? || password.empty?
|
70
|
+
print "Enter Morpheus Credentials for #{display_appliance(@appliance_name, @appliance_url)}\n",reset
|
71
|
+
# end
|
72
|
+
if username.empty?
|
73
|
+
print "Username: #{required_blue_prompt} "
|
74
|
+
username = $stdin.gets.chomp!
|
75
|
+
else
|
76
|
+
print "Username: #{required_blue_prompt} #{username}\n"
|
71
77
|
end
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
78
|
+
if password.empty?
|
79
|
+
print "Password: #{required_blue_prompt} "
|
80
|
+
password = STDIN.noecho(&:gets).chomp!
|
81
|
+
print "\n"
|
82
|
+
else
|
83
|
+
print "Password: #{required_blue_prompt} \n"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
if username.empty? || password.empty?
|
87
|
+
print_red_alert "Username and password are required to login."
|
88
|
+
return nil
|
76
89
|
end
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
print_red_alert "Credentials not verified."
|
90
|
+
begin
|
91
|
+
auth_interface = Morpheus::AuthInterface.new(@appliance_url)
|
92
|
+
json_response = auth_interface.login(username, password)
|
81
93
|
if opts[:json]
|
82
|
-
json_response = JSON.parse(e.response.to_s)
|
83
94
|
print JSON.pretty_generate(json_response)
|
84
95
|
print reset, "\n"
|
85
96
|
end
|
86
|
-
|
87
|
-
|
97
|
+
access_token = json_response['access_token']
|
98
|
+
if access_token && access_token != ""
|
99
|
+
unless skip_save
|
100
|
+
save_credentials(@appliance_name, access_token)
|
101
|
+
end
|
102
|
+
# return access_token
|
103
|
+
else
|
104
|
+
print_red_alert "Credentials not verified."
|
105
|
+
# return nil
|
106
|
+
end
|
107
|
+
rescue ::RestClient::Exception => e
|
108
|
+
#raise e
|
109
|
+
if (e.response && e.response.code == 400)
|
110
|
+
print_red_alert "Credentials not verified."
|
111
|
+
if opts[:json]
|
112
|
+
json_response = JSON.parse(e.response.to_s)
|
113
|
+
print JSON.pretty_generate(json_response)
|
114
|
+
print reset, "\n"
|
115
|
+
end
|
116
|
+
else
|
117
|
+
print_rest_exception(e, opts)
|
118
|
+
end
|
119
|
+
access_token = nil
|
88
120
|
end
|
89
|
-
|
121
|
+
|
90
122
|
end
|
91
123
|
|
92
124
|
|
data/lib/morpheus/cli/login.rb
CHANGED
@@ -36,6 +36,9 @@ class Morpheus::Cli::Login
|
|
36
36
|
opts.on( '-p', '--password PASSWORD', "Password" ) do |val|
|
37
37
|
password = val
|
38
38
|
end
|
39
|
+
opts.on( '-T', '--token ACCESS_TOKEN', "Use an existing access token instead of authenticating with a username and password." ) do |val|
|
40
|
+
options[:remote_token] = val
|
41
|
+
end
|
39
42
|
build_common_options(opts, options, [:json, :remote, :quiet])
|
40
43
|
end
|
41
44
|
optparse.parse!(args)
|
@@ -62,7 +65,7 @@ class Morpheus::Cli::Login
|
|
62
65
|
|
63
66
|
begin
|
64
67
|
if options[:quiet]
|
65
|
-
if username.empty? || password.empty?
|
68
|
+
if !options[:remote_token] && (username.empty? || password.empty?)
|
66
69
|
print yellow,"You have not specified username and password\n"
|
67
70
|
return false
|
68
71
|
end
|
data/lib/morpheus/cli/version.rb
CHANGED
data/lib/morpheus/cli/whoami.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: morpheus-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.4.1.
|
4
|
+
version: 3.4.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Estes
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2018-07-
|
14
|
+
date: 2018-07-11 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|