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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8d494a00b196af210b1c23ccf1de41b2e069f0ad
4
- data.tar.gz: dabfc1813d542df60e0905187499f7dbe8b210ee
3
+ metadata.gz: e36f51274524a0ee48ba3f6c51e224d29bc42118
4
+ data.tar.gz: dadbf3df8aa4ff8fd29d28ffc1b3407d22e2d02b
5
5
  SHA512:
6
- metadata.gz: dd186cffdf47d09863722bdcc0fd8f5e62f247afb49195d7b900d1315594c063ddaeee13bbcfa7169778218d0a8f130296f42da1018727559dc1b1e13def9d3a
7
- data.tar.gz: e396de94d79b666b423c4745f5e4c04f62aa2fcbb14f9ad972058fb7e88f43b9e115f81127b74ad1b2a8fc162e531d22d16f516401c502b99483cdf33d46ed06
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
- # We should return an access Key for Morpheus CLI Here
28
- if !opts[:remote_username].nil?
29
- username = opts[:remote_username]
30
- password = opts[:remote_password]
31
- skip_save = opts[:remote_url] ? true : false
32
- else
33
- access_token = load_saved_credentials
34
- end
35
- if access_token
36
- return access_token
37
- end
38
- unless opts[:quiet] || opts[:no_prompt]
39
- # if username.empty? || password.empty?
40
- print "Enter Morpheus Credentials for #{display_appliance(@appliance_name, @appliance_url)}\n",reset
41
- # end
42
- if username.empty?
43
- print "Username: #{required_blue_prompt} "
44
- username = $stdin.gets.chomp!
45
- else
46
- print "Username: #{required_blue_prompt} #{username}\n"
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
- if password.empty?
49
- print "Password: #{required_blue_prompt} "
50
- password = STDIN.noecho(&:gets).chomp!
51
- print "\n"
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
- print "Password: #{required_blue_prompt} \n"
63
+ access_token = load_saved_credentials
54
64
  end
55
- end
56
- if username.empty? || password.empty?
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
- access_token = json_response['access_token']
68
- if access_token && access_token != ""
69
- unless skip_save
70
- save_credentials(@appliance_name, access_token)
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
- # return access_token
73
- else
74
- print_red_alert "Credentials not verified."
75
- # return nil
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
- rescue ::RestClient::Exception => e
78
- #raise e
79
- if (e.response && e.response.code == 400)
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
- else
87
- print_rest_exception(e, opts)
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
- access_token = nil
121
+
90
122
  end
91
123
 
92
124
 
@@ -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
@@ -1,6 +1,6 @@
1
1
 
2
2
  module Morpheus
3
3
  module Cli
4
- VERSION = "3.4.1.3"
4
+ VERSION = "3.4.1.4"
5
5
  end
6
6
  end
@@ -98,7 +98,7 @@ class Morpheus::Cli::Whoami
98
98
  end
99
99
 
100
100
 
101
- load_whoami()
101
+ json_response = load_whoami()
102
102
 
103
103
  user = @current_user # from load_whoami() meh
104
104
 
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.3
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-09 00:00:00.000000000 Z
14
+ date: 2018-07-11 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler