morpheus-cli 3.1.2.1 → 3.2.0
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/api/api_client.rb +6 -2
- data/lib/morpheus/api/license_interface.rb +7 -0
- data/lib/morpheus/api/monitoring_apps_interface.rb +15 -2
- data/lib/morpheus/api/{checks_interface.rb → monitoring_checks_interface.rb} +8 -21
- data/lib/morpheus/api/monitoring_groups_interface.rb +23 -2
- data/lib/morpheus/api/{incidents_interface.rb → monitoring_incidents_interface.rb} +5 -5
- data/lib/morpheus/api/monitoring_interface.rb +4 -4
- data/lib/morpheus/api/user_groups_interface.rb +65 -0
- data/lib/morpheus/cli.rb +1 -0
- data/lib/morpheus/cli/curl_command.rb +9 -7
- data/lib/morpheus/cli/dot_file.rb +11 -5
- data/lib/morpheus/cli/echo_command.rb +27 -3
- data/lib/morpheus/cli/license.rb +109 -20
- data/lib/morpheus/cli/login.rb +2 -0
- data/lib/morpheus/cli/logout.rb +2 -0
- data/lib/morpheus/cli/mixins/monitoring_helper.rb +97 -37
- data/lib/morpheus/cli/mixins/print_helper.rb +5 -2
- data/lib/morpheus/cli/monitoring_apps_command.rb +564 -9
- data/lib/morpheus/cli/monitoring_checks_command.rb +326 -93
- data/lib/morpheus/cli/monitoring_contacts_command.rb +2 -2
- data/lib/morpheus/cli/monitoring_groups_command.rb +540 -10
- data/lib/morpheus/cli/monitoring_incidents_command.rb +88 -56
- data/lib/morpheus/cli/remote.rb +6 -0
- data/lib/morpheus/cli/roles.rb +1 -1
- data/lib/morpheus/cli/set_prompt_command.rb +1 -0
- data/lib/morpheus/cli/shell.rb +17 -8
- data/lib/morpheus/cli/user_groups_command.rb +574 -0
- data/lib/morpheus/cli/users.rb +221 -115
- data/lib/morpheus/cli/version.rb +1 -1
- data/morpheus-cli.gemspec +1 -2
- metadata +11 -8
data/lib/morpheus/cli/users.rb
CHANGED
@@ -11,6 +11,7 @@ class Morpheus::Cli::Users
|
|
11
11
|
include Morpheus::Cli::CliCommand
|
12
12
|
include Morpheus::Cli::AccountsHelper
|
13
13
|
register_subcommands :list, :get, :add, :update, :remove
|
14
|
+
register_subcommands :'passwd' => :change_password
|
14
15
|
alias_subcommand :details, :get
|
15
16
|
set_default_subcommand :list
|
16
17
|
|
@@ -32,9 +33,10 @@ class Morpheus::Cli::Users
|
|
32
33
|
|
33
34
|
def list(args)
|
34
35
|
options = {}
|
35
|
-
optparse = OptionParser.new do|opts|
|
36
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
36
37
|
opts.banner = subcommand_usage()
|
37
|
-
build_common_options(opts, options, [:account, :list, :json, :dry_run])
|
38
|
+
build_common_options(opts, options, [:account, :list, :json, :yaml, :csv, :fields, :json, :dry_run, :remote])
|
39
|
+
opts.footer = "List users."
|
38
40
|
end
|
39
41
|
optparse.parse!(args)
|
40
42
|
connect(options)
|
@@ -53,10 +55,18 @@ class Morpheus::Cli::Users
|
|
53
55
|
end
|
54
56
|
json_response = @users_interface.list(account_id, params)
|
55
57
|
users = json_response['users']
|
56
|
-
|
58
|
+
if options[:include_fields]
|
59
|
+
json_response = {"users" => filter_data(users, options[:include_fields]) }
|
60
|
+
end
|
57
61
|
if options[:json]
|
58
|
-
|
59
|
-
|
62
|
+
puts as_json(json_response, options)
|
63
|
+
return 0
|
64
|
+
elsif options[:yaml]
|
65
|
+
puts as_yaml(json_response, options)
|
66
|
+
return 0
|
67
|
+
elsif options[:csv]
|
68
|
+
puts records_as_csv(users, options)
|
69
|
+
return 0
|
60
70
|
else
|
61
71
|
title = "Morpheus Users"
|
62
72
|
subtitles = []
|
@@ -77,15 +87,15 @@ class Morpheus::Cli::Users
|
|
77
87
|
end
|
78
88
|
rescue RestClient::Exception => e
|
79
89
|
print_rest_exception(e, options)
|
80
|
-
|
90
|
+
return 1
|
81
91
|
end
|
82
92
|
end
|
83
93
|
|
84
94
|
def get(args)
|
85
95
|
options = {}
|
86
|
-
optparse = OptionParser.new do|opts|
|
96
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
87
97
|
opts.banner = subcommand_usage("[username]")
|
88
|
-
opts.on(
|
98
|
+
opts.on('-f','--feature-access', "Display Feature Access") do |val|
|
89
99
|
options[:include_feature_access] = true
|
90
100
|
end
|
91
101
|
# opts.on(nil,'--group-access', "Display Group Access") do
|
@@ -103,13 +113,15 @@ class Morpheus::Cli::Users
|
|
103
113
|
options[:include_cloud_access] = true
|
104
114
|
options[:include_instance_type_access] = true
|
105
115
|
end
|
106
|
-
build_common_options(opts, options, [:account, :json, :dry_run])
|
116
|
+
build_common_options(opts, options, [:account, :json, :yaml, :csv, :fields, :dry_run, :remote])
|
117
|
+
opts.footer = "Get details about a user." + "\n" +
|
118
|
+
"[username] is required. This is the username or id of a user."
|
107
119
|
end
|
108
120
|
optparse.parse!(args)
|
109
121
|
|
110
122
|
if args.count < 1
|
111
123
|
puts optparse
|
112
|
-
|
124
|
+
return 1
|
113
125
|
end
|
114
126
|
|
115
127
|
connect(options)
|
@@ -130,24 +142,32 @@ class Morpheus::Cli::Users
|
|
130
142
|
# todo: users_response = @users_interface.list(account_id, {name: name})
|
131
143
|
# there may be response data outside of user that needs to be displayed
|
132
144
|
user = find_user_by_username_or_id(account_id, args[0])
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
user_feature_permissions = nil
|
138
|
-
if options[:include_feature_access]
|
139
|
-
user_feature_permissions_json = @users_interface.feature_permissions(account_id, user['id'])
|
140
|
-
user_feature_permissions = user_feature_permissions_json['featurePermissions']
|
141
|
-
end
|
145
|
+
return 1 if user.nil?
|
146
|
+
|
147
|
+
json_response = {'user' => user}
|
148
|
+
# json_response['user']['featurePermissions'] = user_feature_permissions if options[:include_feature_access]
|
142
149
|
|
150
|
+
if options[:include_fields]
|
151
|
+
json_response = {'user' => filter_data(user, options[:include_fields]) }
|
152
|
+
end
|
143
153
|
if options[:json]
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
154
|
+
puts as_json(json_response, options)
|
155
|
+
puts as_json(@users_interface.feature_permissions(account_id, user['id']), options) if options[:include_feature_access]
|
156
|
+
return 0
|
157
|
+
elsif options[:yaml]
|
158
|
+
puts as_yaml(json_response, options)
|
159
|
+
puts as_yaml(@users_interface.feature_permissions(account_id, user['id']), options) if options[:include_feature_access]
|
160
|
+
return 0
|
161
|
+
elsif options[:csv]
|
162
|
+
puts records_as_csv([user], options)
|
163
|
+
return 0
|
150
164
|
else
|
165
|
+
user_feature_permissions_json = nil
|
166
|
+
user_feature_permissions = nil
|
167
|
+
if options[:include_feature_access]
|
168
|
+
user_feature_permissions_json = @users_interface.feature_permissions(account_id, user['id'])
|
169
|
+
user_feature_permissions = user_feature_permissions_json['featurePermissions']
|
170
|
+
end
|
151
171
|
print_h1 "User Details"
|
152
172
|
print cyan
|
153
173
|
description_cols = {
|
@@ -191,16 +211,17 @@ class Morpheus::Cli::Users
|
|
191
211
|
end
|
192
212
|
rescue RestClient::Exception => e
|
193
213
|
print_rest_exception(e, options)
|
194
|
-
|
214
|
+
return 1
|
195
215
|
end
|
196
216
|
end
|
197
217
|
|
198
218
|
def add(args)
|
199
219
|
options = {}
|
200
|
-
|
220
|
+
params = {}
|
221
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
201
222
|
opts.banner = subcommand_usage("[options]")
|
202
223
|
build_option_type_options(opts, options, add_user_option_types)
|
203
|
-
build_common_options(opts, options, [:account, :options, :json, :dry_run])
|
224
|
+
build_common_options(opts, options, [:account, :options, :payload, :json, :dry_run])
|
204
225
|
end
|
205
226
|
optparse.parse!(args)
|
206
227
|
|
@@ -210,27 +231,32 @@ class Morpheus::Cli::Users
|
|
210
231
|
account = find_account_from_options(options)
|
211
232
|
account_id = account ? account['id'] : nil
|
212
233
|
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
234
|
+
payload = nil
|
235
|
+
if options[:payload]
|
236
|
+
payload = options[:payload]
|
237
|
+
else
|
238
|
+
# merge -O options into normally parsed options
|
239
|
+
params.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
|
240
|
+
# remove role option_type, it is just for help display, the role prompt is separate down below
|
241
|
+
prompt_option_types = add_user_option_types().reject {|it| 'role' == it['fieldName'] }
|
242
|
+
v_prompt = Morpheus::Cli::OptionTypes.prompt(prompt_option_types, options[:options], @api_client, options[:params])
|
243
|
+
params.deep_merge!(v_prompt)
|
244
|
+
if params['instanceLimits']
|
245
|
+
params['instanceLimits']['maxStorage'] = params['instanceLimits']['maxStorage'].to_i if params['instanceLimits']['maxStorage'].to_s.strip != ''
|
246
|
+
params['instanceLimits']['maxMemory'] = params['instanceLimits']['maxMemory'].to_i if params['instanceLimits']['maxMemory'].to_s.strip != ''
|
247
|
+
params['instanceLimits']['maxCpu'] = params['instanceLimits']['maxCpu'].to_i if params['instanceLimits']['maxCpu'].to_s.strip != ''
|
248
|
+
end
|
249
|
+
# prompt for roles
|
250
|
+
selected_roles = []
|
251
|
+
selected_roles += params.delete('role').split(',').collect {|r| r.strip.empty? ? nil : r.strip}.uniq if params['role']
|
252
|
+
selected_roles += params.delete('roles').split(',').collect {|r| r.strip.empty? ? nil : r.strip}.uniq if params['roles']
|
253
|
+
roles = prompt_user_roles(account_id, nil, selected_roles, options)
|
254
|
+
if !roles.empty?
|
255
|
+
params['roles'] = roles.collect {|r| {id: r['id']} }
|
256
|
+
end
|
257
|
+
payload = {'user' => params}
|
230
258
|
end
|
231
259
|
|
232
|
-
payload = {user: user_payload}
|
233
|
-
|
234
260
|
if options[:dry_run]
|
235
261
|
print_dry_run @users_interface.dry.create(account_id, payload)
|
236
262
|
return
|
@@ -240,38 +266,40 @@ class Morpheus::Cli::Users
|
|
240
266
|
print JSON.pretty_generate(json_response)
|
241
267
|
print "\n"
|
242
268
|
else
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
get(details_options)
|
269
|
+
username = "" # json_response['user']['username']
|
270
|
+
username = payload['user']['username'] if payload['user'] && payload['user']['username']
|
271
|
+
if account
|
272
|
+
print_green_success "Added user #{username} to account #{account['name']}"
|
273
|
+
else
|
274
|
+
print_green_success "Added user #{username}"
|
275
|
+
end
|
276
|
+
details_options = [username]
|
277
|
+
if account
|
278
|
+
details_options.push "--account-id", account['id'].to_s
|
254
279
|
end
|
280
|
+
get(details_options)
|
281
|
+
end
|
282
|
+
|
255
283
|
|
256
284
|
rescue RestClient::Exception => e
|
257
285
|
print_rest_exception(e, options)
|
258
|
-
|
286
|
+
return 1
|
259
287
|
end
|
260
288
|
end
|
261
289
|
|
262
290
|
def update(args)
|
263
291
|
options = {}
|
264
|
-
|
292
|
+
params = {}
|
293
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
265
294
|
opts.banner = subcommand_usage("[username] [options]")
|
266
295
|
build_option_type_options(opts, options, update_user_option_types)
|
267
|
-
build_common_options(opts, options, [:account, :options, :json, :dry_run])
|
296
|
+
build_common_options(opts, options, [:account, :options, :payload, :json, :dry_run])
|
268
297
|
end
|
269
298
|
optparse.parse!(args)
|
270
299
|
|
271
300
|
if args.count < 1
|
272
|
-
print_red_alert "Specify atleast one option to update"
|
273
301
|
puts optparse
|
274
|
-
|
302
|
+
return 1
|
275
303
|
end
|
276
304
|
|
277
305
|
connect(options)
|
@@ -281,47 +309,59 @@ class Morpheus::Cli::Users
|
|
281
309
|
account_id = account ? account['id'] : nil
|
282
310
|
|
283
311
|
user = find_user_by_username_or_id(account_id, args[0])
|
284
|
-
|
312
|
+
return 1 if user.nil?
|
285
313
|
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
314
|
+
payload = nil
|
315
|
+
if options[:payload]
|
316
|
+
payload = options[:payload]
|
317
|
+
else
|
318
|
+
#params = Morpheus::Cli::OptionTypes.prompt(update_user_option_types, options[:options], @api_client, options[:params])
|
319
|
+
# merge -O options into normally parsed options
|
320
|
+
params.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
|
321
|
+
# if params.empty?
|
322
|
+
# print_red_alert "Specify atleast one option to update"
|
323
|
+
# puts optparse
|
324
|
+
# return 1
|
325
|
+
# end
|
326
|
+
# prompt_option_types = update_user_option_types().reject {|it| 'role' == it['fieldName'] }
|
327
|
+
# params = Morpheus::Cli::OptionTypes.prompt(prompt_option_types, params, @api_client)
|
328
|
+
selected_roles = []
|
329
|
+
selected_roles += params.delete('role').split(',').collect {|r| r.strip.empty? ? nil : r.strip}.uniq if params['role']
|
330
|
+
selected_roles += params.delete('roles').split(',').collect {|r| r.strip.empty? ? nil : r.strip}.uniq if params['roles']
|
331
|
+
roles = prompt_user_roles(account_id, user['id'], selected_roles, options.merge(no_prompt: true))
|
332
|
+
if !roles.empty?
|
333
|
+
params['roles'] = roles.collect {|r| {id: r['id']} }
|
334
|
+
end
|
335
|
+
if params.empty?
|
336
|
+
puts optparse.banner
|
337
|
+
puts Morpheus::Cli::OptionTypes.display_option_types_help(update_user_option_types)
|
338
|
+
return 1
|
339
|
+
end
|
340
|
+
|
341
|
+
#puts "parsed params is : #{params.inspect}"
|
342
|
+
if params['instanceLimits']
|
343
|
+
params['instanceLimits']['maxStorage'] = params['instanceLimits']['maxStorage'].to_i if params['instanceLimits']['maxStorage'].to_s.strip != ''
|
344
|
+
params['instanceLimits']['maxMemory'] = params['instanceLimits']['maxMemory'].to_i if params['instanceLimits']['maxMemory'].to_s.strip != ''
|
345
|
+
params['instanceLimits']['maxCpu'] = params['instanceLimits']['maxCpu'].to_i if params['instanceLimits']['maxCpu'].to_s.strip != ''
|
346
|
+
end
|
301
347
|
|
302
|
-
|
303
|
-
user_keys = ['username', 'firstName', 'lastName', 'email', 'password', 'instanceLimits', 'roles']
|
304
|
-
user_payload = params.select {|k,v| user_keys.include?(k) }
|
305
|
-
if !user_payload['instanceLimits']
|
306
|
-
user_payload['instanceLimits'] = {}
|
307
|
-
user_payload['instanceLimits']['maxStorage'] = params['instanceLimits.maxStorage'].to_i if params['instanceLimits.maxStorage'].to_s.strip != ''
|
308
|
-
user_payload['instanceLimits']['maxMemory'] = params['instanceLimits.maxMemory'].to_i if params['instanceLimits.maxMemory'].to_s.strip != ''
|
309
|
-
user_payload['instanceLimits']['maxCpu'] = params['instanceLimits.maxCpu'].to_i if params['instanceLimits.maxCpu'].to_s.strip != ''
|
348
|
+
payload = {'user' => params}
|
310
349
|
end
|
311
350
|
|
312
|
-
payload = {user: user_payload}
|
313
|
-
json_response = @users_interface.update(account_id, user['id'], payload)
|
314
351
|
if options[:dry_run]
|
315
352
|
print_dry_run @users_interface.dry.update(account_id, user['id'], payload)
|
316
353
|
return
|
317
354
|
end
|
355
|
+
json_response = @users_interface.update(account_id, user['id'], payload)
|
318
356
|
|
319
357
|
if options[:json]
|
320
358
|
print JSON.pretty_generate(json_response)
|
321
359
|
print "\n"
|
322
360
|
else
|
323
|
-
|
324
|
-
|
361
|
+
username = user['username'] # json_response['user']['username']
|
362
|
+
username = payload['user']['username'] if payload['user'] && payload['user']['username']
|
363
|
+
print_green_success "Updated user #{username}"
|
364
|
+
details_options = [username]
|
325
365
|
if account
|
326
366
|
details_options.push "--account-id", account['id'].to_s
|
327
367
|
end
|
@@ -330,14 +370,83 @@ class Morpheus::Cli::Users
|
|
330
370
|
|
331
371
|
rescue RestClient::Exception => e
|
332
372
|
print_rest_exception(e, options)
|
333
|
-
|
373
|
+
return 1
|
374
|
+
end
|
375
|
+
end
|
376
|
+
|
377
|
+
def change_password(args)
|
378
|
+
options = {}
|
379
|
+
new_password = nil
|
380
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
381
|
+
opts.banner = subcommand_usage("[username] [options]")
|
382
|
+
opts.on('--password VALUE', String, "New password") do |val|
|
383
|
+
new_password = val
|
384
|
+
end
|
385
|
+
build_common_options(opts, options, [:account, :options, :json, :dry_run, :remote])
|
386
|
+
end
|
387
|
+
optparse.parse!(args)
|
388
|
+
|
389
|
+
if args.count < 1
|
390
|
+
# print_error Morpheus::Terminal.angry_prompt
|
391
|
+
# puts_error "wrong number of arguments, expected 1 and got #{args.count}\n#{optparse}"
|
392
|
+
puts optparse
|
393
|
+
return 1
|
394
|
+
end
|
395
|
+
|
396
|
+
connect(options)
|
397
|
+
begin
|
398
|
+
|
399
|
+
account = find_account_from_options(options)
|
400
|
+
account_id = account ? account['id'] : nil
|
401
|
+
|
402
|
+
user = find_user_by_username_or_id(account_id, args[0])
|
403
|
+
return 1 if user.nil?
|
404
|
+
|
405
|
+
if new_password.nil?
|
406
|
+
|
407
|
+
password_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'password', 'fieldLabel' => 'New Password', 'type' => 'password', 'required' => true}], options[:options], @api_client)
|
408
|
+
new_password = password_prompt['password']
|
409
|
+
|
410
|
+
confirm_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'passwordConfirmation', 'fieldLabel' => 'Confirm Password', 'type' => 'password', 'required' => true}], options[:options], @api_client)
|
411
|
+
confirm_password = confirm_prompt['passwordConfirmation']
|
412
|
+
if confirm_password != new_password
|
413
|
+
print_red_alert "Confirm password did not match."
|
414
|
+
return 1
|
415
|
+
end
|
416
|
+
end
|
417
|
+
|
418
|
+
if new_password.nil? || new_password.empty?
|
419
|
+
print_red_alert "A new password is required"
|
420
|
+
return 1
|
421
|
+
end
|
422
|
+
|
423
|
+
payload = {
|
424
|
+
'user' => {
|
425
|
+
'password' => new_password,
|
426
|
+
'passwordConfirmation' => new_password
|
427
|
+
}
|
428
|
+
}
|
429
|
+
json_response = @users_interface.update(account_id, user['id'], payload)
|
430
|
+
if options[:dry_run]
|
431
|
+
print_dry_run @users_interface.dry.update(account_id, user['id'], payload)
|
432
|
+
return
|
433
|
+
end
|
434
|
+
|
435
|
+
if options[:json]
|
436
|
+
puts JSON.pretty_generate(json_response)
|
437
|
+
else
|
438
|
+
print_green_success "Updated password for user #{user['username']}"
|
439
|
+
end
|
440
|
+
|
441
|
+
rescue RestClient::Exception => e
|
442
|
+
print_rest_exception(e, options)
|
443
|
+
return 1
|
334
444
|
end
|
335
445
|
end
|
336
446
|
|
337
447
|
def remove(args)
|
338
|
-
usage = "Usage: morpheus users remove [username]"
|
339
448
|
options = {}
|
340
|
-
optparse = OptionParser.new do|opts|
|
449
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
341
450
|
opts.banner = subcommand_usage("[username]")
|
342
451
|
build_common_options(opts, options, [:account, :auto_confirm, :json, :dry_run])
|
343
452
|
end
|
@@ -345,7 +454,7 @@ class Morpheus::Cli::Users
|
|
345
454
|
|
346
455
|
if args.count < 1
|
347
456
|
puts optparse
|
348
|
-
|
457
|
+
return 1
|
349
458
|
end
|
350
459
|
|
351
460
|
connect(options)
|
@@ -355,7 +464,7 @@ class Morpheus::Cli::Users
|
|
355
464
|
account_id = account ? account['id'] : nil
|
356
465
|
|
357
466
|
user = find_user_by_username_or_id(account_id, args[0])
|
358
|
-
|
467
|
+
return 1 if user.nil?
|
359
468
|
unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the user #{user['username']}?")
|
360
469
|
exit
|
361
470
|
end
|
@@ -374,7 +483,7 @@ class Morpheus::Cli::Users
|
|
374
483
|
end
|
375
484
|
rescue RestClient::Exception => e
|
376
485
|
print_rest_exception(e, options)
|
377
|
-
|
486
|
+
return 1
|
378
487
|
end
|
379
488
|
end
|
380
489
|
|
@@ -388,9 +497,9 @@ class Morpheus::Cli::Users
|
|
388
497
|
{'fieldName' => 'email', 'fieldLabel' => 'Email', 'type' => 'text', 'required' => true, 'displayOrder' => 4},
|
389
498
|
{'fieldName' => 'password', 'fieldLabel' => 'Password', 'type' => 'password', 'required' => true, 'displayOrder' => 6},
|
390
499
|
{'fieldName' => 'passwordConfirmation', 'fieldLabel' => 'Confirm Password', 'type' => 'password', 'required' => true, 'displayOrder' => 7},
|
391
|
-
{'fieldName' => '
|
392
|
-
{'fieldName' => '
|
393
|
-
{'fieldName' => '
|
500
|
+
{'fieldContext' => 'instanceLimits', 'fieldName' => 'maxStorage', 'fieldLabel' => 'Max Storage (bytes)', 'type' => 'text', 'displayOrder' => 8},
|
501
|
+
{'fieldContext' => 'instanceLimits', 'fieldName' => 'maxMemory', 'fieldLabel' => 'Max Memory (bytes)', 'type' => 'text', 'displayOrder' => 9},
|
502
|
+
{'fieldContext' => 'instanceLimits', 'fieldName' => 'maxCpu', 'fieldLabel' => 'CPU Count', 'type' => 'text', 'displayOrder' => 10},
|
394
503
|
{'fieldName' => 'role', 'fieldLabel' => 'Role', 'type' => 'text', 'displayOrder' => 11, 'description' => "Role names (comma separated)"},
|
395
504
|
]
|
396
505
|
end
|
@@ -403,9 +512,9 @@ class Morpheus::Cli::Users
|
|
403
512
|
{'fieldName' => 'email', 'fieldLabel' => 'Email', 'type' => 'text', 'required' => false, 'displayOrder' => 4},
|
404
513
|
{'fieldName' => 'password', 'fieldLabel' => 'Password', 'type' => 'password', 'required' => false, 'displayOrder' => 6},
|
405
514
|
{'fieldName' => 'passwordConfirmation', 'fieldLabel' => 'Confirm Password', 'type' => 'password', 'required' => false, 'displayOrder' => 7},
|
406
|
-
{'fieldName' => '
|
407
|
-
{'fieldName' => '
|
408
|
-
{'fieldName' => '
|
515
|
+
{'fieldContext' => 'instanceLimits', 'fieldName' => 'maxStorage', 'fieldLabel' => 'Max Storage (bytes)', 'type' => 'text', 'displayOrder' => 8},
|
516
|
+
{'fieldContext' => 'instanceLimits', 'fieldName' => 'maxMemory', 'fieldLabel' => 'Max Memory (bytes)', 'type' => 'text', 'displayOrder' => 9},
|
517
|
+
{'fieldContext' => 'instanceLimits', 'fieldName' => 'maxCpu', 'fieldLabel' => 'CPU Count', 'type' => 'text', 'displayOrder' => 10},
|
409
518
|
{'fieldName' => 'role', 'fieldLabel' => 'Role', 'type' => 'text', 'displayOrder' => 11, 'description' => "Role names (comma separated)"},
|
410
519
|
]
|
411
520
|
end
|
@@ -414,36 +523,33 @@ class Morpheus::Cli::Users
|
|
414
523
|
# options['role'] can be passed as comma separated role names
|
415
524
|
# if so, it will be used instead of prompting
|
416
525
|
# returns array of role objects
|
417
|
-
def prompt_user_roles(account_id, user_id, options={})
|
418
|
-
|
419
|
-
passed_role_string = nil
|
420
|
-
if options['role'] || (options[:options] && (options[:options]['role'] || options[:options]['roles']))
|
421
|
-
passed_role_string = options['role'] || (options[:options] && (options[:options]['role'] || options[:options]['roles']))
|
422
|
-
end
|
526
|
+
def prompt_user_roles(account_id, user_id, selected_roles=[], options={})
|
423
527
|
passed_role_names = []
|
424
|
-
if !
|
425
|
-
|
528
|
+
if !selected_roles.empty?
|
529
|
+
if selected_roles.is_a?(String)
|
530
|
+
passed_role_names = selected_roles.split(',').uniq.compact.collect {|r| r.strip}
|
531
|
+
else
|
532
|
+
passed_role_names = selected_roles
|
533
|
+
end
|
426
534
|
end
|
427
535
|
|
428
536
|
available_roles = @users_interface.available_roles(account_id, user_id)['roles']
|
429
537
|
|
430
538
|
if available_roles.empty?
|
431
539
|
print_red_alert "No available roles found."
|
432
|
-
|
540
|
+
return 1
|
433
541
|
end
|
434
542
|
role_options = available_roles.collect {|role|
|
435
543
|
{'name' => role['authority'], 'value' => role['id']}
|
436
544
|
}
|
437
545
|
|
438
|
-
# found_roles = []
|
439
546
|
roles = []
|
440
547
|
|
441
548
|
if !passed_role_names.empty?
|
442
549
|
invalid_role_names = []
|
443
550
|
passed_role_names.each do |role_name|
|
444
|
-
found_role = available_roles.find {|ar| ar['authority'] == role_name}
|
551
|
+
found_role = available_roles.find {|ar| ar['authority'] == role_name || ar['id'] == role_name.to_i}
|
445
552
|
if found_role
|
446
|
-
# found_roles << found_role
|
447
553
|
roles << found_role
|
448
554
|
else
|
449
555
|
invalid_role_names << role_name
|