morpheus-cli 4.2.11 → 4.2.16

Sign up to get free protection for your applications and to get access to all the features.
@@ -186,49 +186,42 @@ class Morpheus::Cli::LibraryOptionListsCommand
186
186
  my_option_types = nil
187
187
  list_type = nil
188
188
  optparse = Morpheus::Cli::OptionParser.new do |opts|
189
- opts.banner = subcommand_usage("[type] [options]")
190
- opts.on( '-t', '--type TYPE', "Option List Type. (rest, manual)" ) do |val|
191
- list_type = val
192
- # options[:options] ||= {}
193
- # options[:options]['type'] = val
194
- end
189
+ opts.banner = subcommand_usage("[name] [options]")
195
190
  build_option_type_options(opts, options, new_option_type_list_option_types())
196
191
  build_standard_add_options(opts, options)
197
192
  opts.footer = "Create a new option list."
198
193
  end
199
194
  optparse.parse!(args)
200
-
201
-
195
+ verify_args!(args:args, optparse:optparse, max:1)
196
+ if args.count == 1
197
+ options[:options]['name'] = args[0]
198
+ end
199
+
202
200
  connect(options)
203
201
  begin
204
- passed_options = options[:options].reject {|k,v| k.is_a?(Symbol) }
205
202
  payload = nil
206
203
  if options[:payload]
207
204
  payload = options[:payload]
208
- # support -O OPTION switch on top of --payload
209
- if !passed_options.empty?
210
- payload['optionTypeList'] ||= {}
211
- payload['optionTypeList'].deep_merge!(passed_options)
212
- end
205
+ payload.deep_merge!({'optionTypeList' => parse_passed_options(options)})
213
206
  else
214
- if !list_type
215
- v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'type', 'fieldLabel' => 'Type', 'type' => 'select', 'selectOptions' => get_available_option_list_types, 'defaultValue' => 'rest', 'required' => true}], options[:options], @api_client, {})
216
- list_type = v_prompt['type']
217
- end
218
- params = passed_options
219
- v_prompt = Morpheus::Cli::OptionTypes.prompt(new_option_type_list_option_types(list_type), options[:options], @api_client, options[:params])
220
- params.deep_merge!(v_prompt)
221
- params['type'] = list_type
222
- if params['type'] == 'rest'
207
+ payload = {}
208
+ payload.deep_merge!({'optionTypeList' => parse_passed_options(options)})
209
+ list_payload = Morpheus::Cli::OptionTypes.prompt(new_option_type_list_option_types(), options[:options], @api_client, options[:params])
210
+ if list_payload['type'] == 'rest'
223
211
  # prompt for Source Headers
224
- source_headers = prompt_source_headers(options)
225
- if !source_headers.empty?
226
- params['config'] ||= {}
227
- params['config']['sourceHeaders'] = source_headers
212
+ if !(payload['optionTypeList']['config'] && payload['optionTypeList']['config']['sourceHeaders'])
213
+ source_headers = prompt_source_headers(options)
214
+ if !source_headers.empty?
215
+ list_payload['config'] ||= {}
216
+ list_payload['config']['sourceHeaders'] = source_headers
217
+ end
228
218
  end
229
219
  end
230
- list_payload = params
231
- payload = {'optionTypeList' => list_payload}
220
+ # tweak payload for API
221
+ ['ignoreSSLErrors', 'realTime'].each { |k|
222
+ list_payload[k] = ['on','true'].include?(list_payload[k].to_s) if list_payload.key?(k)
223
+ }
224
+ payload.deep_merge!({'optionTypeList' => list_payload})
232
225
  end
233
226
  @option_type_lists_interface.setopts(options)
234
227
  if options[:dry_run]
@@ -262,41 +255,31 @@ class Morpheus::Cli::LibraryOptionListsCommand
262
255
  begin
263
256
  option_type_list = find_option_type_list_by_name_or_id(args[0])
264
257
  exit 1 if option_type_list.nil?
265
- passed_options = options[:options].reject {|k,v| k.is_a?(Symbol) }
266
258
  payload = nil
267
259
  if options[:payload]
268
260
  payload = options[:payload]
269
- # support -O OPTION switch on top of --payload
270
- if !passed_options.empty?
271
- payload['optionTypeList'] ||= {}
272
- payload['optionTypeList'].deep_merge!(passed_options)
273
- end
261
+ payload.deep_merge!({'optionTypeList' => parse_passed_options(options)})
274
262
  else
275
- list_type = option_type_list['type']
276
- prompt_options = update_option_type_list_option_types(list_type)
277
- params = passed_options
278
- v_prompt = Morpheus::Cli::OptionTypes.no_prompt(prompt_options, options[:options], @api_client, options[:params])
279
- params.deep_merge!(v_prompt)
280
-
281
- if list_type == 'rest'
263
+ payload = {}
264
+ payload.deep_merge!({'optionTypeList' => parse_passed_options(options)})
265
+ list_payload = Morpheus::Cli::OptionTypes.no_prompt(update_option_type_option_types(), options[:options], @api_client)
266
+ if list_payload['type'] == 'rest'
282
267
  # parse Source Headers
283
- source_headers = prompt_source_headers(options.merge({no_prompt: true}))
284
- if !source_headers.empty?
285
- #params['config'] ||= option_type_list['config'] || {}
286
- params['config'] ||= {}
287
- params['config']['sourceHeaders'] = source_headers
268
+ if !(payload['optionTypeList']['config'] && payload['optionTypeList']['config']['sourceHeaders'])
269
+ source_headers = prompt_source_headers(options.merge({no_prompt: true}))
270
+ if !source_headers.empty?
271
+ #params['config'] ||= option_type_list['config'] || {}
272
+ params['config'] ||= {}
273
+ params['config']['sourceHeaders'] = source_headers
274
+ end
288
275
  end
289
276
  end
290
- if params.empty?
291
- print_red_alert "Specify at least one option to update"
292
- puts optparse
293
- exit 1
294
- end
295
- if params.key?('required')
296
- params['required'] = ['on','true'].include?(params['required'].to_s)
297
- end
298
- list_payload = params
299
- payload = {'optionTypeList' => list_payload}
277
+ # tweak payload for API
278
+ ['ignoreSSLErrors', 'realTime'].each { |k|
279
+ list_payload[k] = ['on','true'].include?(list_payload[k].to_s) if list_payload.key?(k)
280
+ }
281
+ payload.deep_merge!({'optionTypeList' => list_payload})
282
+ raise_command_error "Specify at least one option to update.\n#{optparse}" if payload['optionTypeList'].empty?
300
283
  end
301
284
  @option_type_lists_interface.setopts(options)
302
285
  if options[:dry_run]
@@ -355,42 +338,13 @@ class Morpheus::Cli::LibraryOptionListsCommand
355
338
 
356
339
  private
357
340
 
358
- def find_option_type_list_by_name_or_id(val)
359
- if val.to_s =~ /\A\d{1,}\Z/
360
- return find_option_type_list_by_id(val)
361
- else
362
- return find_option_type_list_by_name(val)
363
- end
364
- end
365
-
366
- def find_option_type_list_by_id(id)
367
- begin
368
- json_response = @option_type_lists_interface.get(id.to_i)
369
- return json_response['optionTypeList']
370
- rescue RestClient::Exception => e
371
- if e.response && e.response.code == 404
372
- print_red_alert "Option List not found by id #{id}"
373
- exit 1
374
- else
375
- raise e
376
- end
377
- end
378
- end
379
-
380
- def find_option_type_list_by_name(name)
381
- json_results = @option_type_lists_interface.list({name: name.to_s})
382
- if json_results['optionTypeLists'].empty?
383
- print_red_alert "Option List not found by name #{name}"
384
- exit 1
385
- end
386
- option_type_list = json_results['optionTypeLists'][0]
387
- return option_type_list
388
- end
341
+ # finders are in LibraryHelper
389
342
 
390
343
  def get_available_option_list_types
391
344
  [
392
345
  {'name' => 'REST', 'value' => 'rest'},
393
346
  {'name' => 'Morpheus Api', 'value' => 'api'},
347
+ {'name' => 'LDAP', 'value' => 'ldap'},
394
348
  {'name' => 'Manual', 'value' => 'manual'}
395
349
  ]
396
350
  end
@@ -399,49 +353,31 @@ class Morpheus::Cli::LibraryOptionListsCommand
399
353
  get_available_option_list_types.find {|it| code == it['value'] || code == it['name'] }
400
354
  end
401
355
 
402
- def new_option_type_list_option_types(list_type='rest')
403
- if list_type.to_s.downcase == 'rest'
404
- [
356
+ def new_option_type_list_option_types()
357
+ [
358
+ # rest
405
359
  {'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'displayOrder' => 1},
406
360
  {'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'displayOrder' => 2},
407
- #{'fieldName' => 'type', 'fieldLabel' => 'Type', 'type' => 'select', 'selectOptions' => get_available_option_list_types, 'defaultValue' => 'rest', 'required' => true, 'displayOrder' => 3},
408
- {'fieldName' => 'visibility', 'fieldLabel' => 'Visibility', 'type' => 'select', 'selectOptions' => [{'name' => 'Private', 'value' => 'private'}, {'name' => 'Public', 'value' => 'public'}], 'defaultValue' => 'private', 'displayOrder' => 3},
409
- {'fieldName' => 'sourceUrl', 'fieldLabel' => 'Source Url', 'type' => 'text', 'required' => true, 'description' => "A REST URL can be used to fetch list data and is cached in the appliance database.", 'displayOrder' => 4},
410
- {'fieldName' => 'ignoreSSLErrors', 'fieldLabel' => 'Ignore SSL Errors', 'type' => 'checkbox', 'defaultValue' => 'off', 'displayOrder' => 5},
411
- {'fieldName' => 'realTime', 'fieldLabel' => 'Real Time', 'type' => 'checkbox', 'defaultValue' => 'off', 'displayOrder' => 6},
412
- {'fieldName' => 'sourceMethod', 'fieldLabel' => 'Source Method', 'type' => 'select', 'selectOptions' => [{'name' => 'GET', 'value' => 'GET'}, {'name' => 'POST', 'value' => 'POST'}], 'defaultValue' => 'GET', 'required' => true, 'displayOrder' => 7},
361
+ {'code' => 'optionTypeList.type', 'fieldName' => 'type', 'fieldLabel' => 'Type', 'type' => 'select', 'selectOptions' => get_available_option_list_types, 'defaultValue' => 'rest', 'required' => true, 'description' => 'Option List Type. eg. rest, api, ldap, manual', 'displayOrder' => 3},
362
+ {'fieldName' => 'visibility', 'fieldLabel' => 'Visibility', 'type' => 'select', 'selectOptions' => [{'name' => 'Private', 'value' => 'private'}, {'name' => 'Public', 'value' => 'public'}], 'defaultValue' => 'private', 'displayOrder' => 4},
363
+ {'dependsOnCode' => 'optionTypeList.type:rest', 'fieldName' => 'sourceUrl', 'fieldLabel' => 'Source Url', 'type' => 'text', 'required' => true, 'description' => "A REST URL can be used to fetch list data and is cached in the appliance database.", 'displayOrder' => 5},
364
+ {'dependsOnCode' => 'optionTypeList.type:rest', 'fieldName' => 'ignoreSSLErrors', 'fieldLabel' => 'Ignore SSL Errors', 'type' => 'checkbox', 'defaultValue' => false, 'displayOrder' => 6},
365
+ {'dependsOnCode' => 'optionTypeList.type:rest', 'fieldName' => 'realTime', 'fieldLabel' => 'Real Time', 'type' => 'checkbox', 'defaultValue' => false, 'displayOrder' => 7},
366
+ {'dependsOnCode' => 'optionTypeList.type:rest', 'fieldName' => 'sourceMethod', 'fieldLabel' => 'Source Method', 'type' => 'select', 'selectOptions' => [{'name' => 'GET', 'value' => 'GET'}, {'name' => 'POST', 'value' => 'POST'}], 'defaultValue' => 'GET', 'required' => true, 'displayOrder' => 8},
413
367
  # sourceHeaders component (is done afterwards manually)
414
- {'fieldName' => 'initialDataset', 'fieldLabel' => 'Initial Dataset', 'type' => 'code-editor', 'description' => "Create an initial json dataset to be used as the collection for this option list. It should be a list containing objects with properties 'name', and 'value'. However, if there is a translation script, that will also be passed through.", 'displayOrder' => 8},
415
- {'fieldName' => 'translationScript', 'fieldLabel' => 'Translation Script', 'type' => 'code-editor', 'description' => "Create a js script to translate the result data object into an Array containing objects with properties name, and value. The input data is provided as data and the result should be put on the global variable results.", 'displayOrder' => 9},
416
- {'fieldName' => 'requestScript', 'fieldLabel' => 'Request Script', 'type' => 'code-editor', 'description' => "Create a js script to prepare the request. Return a data object as the body for a post, and return an array containing properties name and value for a get. The input data is provided as data and the result should be put on the global variable results.", 'displayOrder' => 10},
417
-
368
+ {'dependsOnCode' => 'optionTypeList.type:api', 'fieldName' => 'apiType', 'fieldLabel' => 'Option List', 'type' => 'select', 'optionSource' => 'apiOptionLists', 'required' => true, 'description' => 'The code of the api list to use, eg. clouds, servers, etc.', 'displayOrder' => 9},
369
+ {'dependsOnCode' => 'optionTypeList.type:ldap', 'fieldName' => 'sourceUsername', 'fieldLabel' => 'Source Username', 'type' => 'text', 'description' => "An LDAP Username for use when type is 'ldap'.", 'displayOrder' => 10},
370
+ {'dependsOnCode' => 'optionTypeList.type:ldap', 'fieldName' => 'sourcePassword', 'fieldLabel' => 'Source Username', 'type' => 'text', 'description' => "An LDAP Password for use when type is 'ldap'.", 'displayOrder' => 11},
371
+ {'dependsOnCode' => 'optionTypeList.type:ldap', 'fieldName' => 'ldapQuery', 'fieldLabel' => 'LDAP Query', 'type' => 'text', 'description' => "LDAP Queries are standard LDAP formatted queries where different objects can be searched. Dependent parameters can be loaded into the query using the <%=phrase%> syntax.", 'displayOrder' => 12},
372
+ {'dependsOnCode' => 'optionTypeList.type:rest|api|manual', 'fieldName' => 'initialDataset', 'fieldLabel' => 'Initial Dataset', 'type' => 'code-editor', 'description' => "Create an initial json dataset to be used as the collection for this option list. It should be a list containing objects with properties 'name', and 'value'. However, if there is a translation script, that will also be passed through.", 'displayOrder' => 13},
373
+ {'dependsOnCode' => 'optionTypeList.type:rest|api|ldap', 'fieldName' => 'translationScript', 'fieldLabel' => 'Translation Script', 'type' => 'code-editor', 'description' => "Create a js script to translate the result data object into an Array containing objects with properties name, and value. The input data is provided as data and the result should be put on the global variable results.", 'displayOrder' => 14},
374
+ {'dependsOnCode' => 'optionTypeList.type:rest|api', 'fieldName' => 'requestScript', 'fieldLabel' => 'Request Script', 'type' => 'code-editor', 'description' => "Create a js script to prepare the request. Return a data object as the body for a post, and return an array containing properties name and value for a get. The input data is provided as data and the result should be put on the global variable results.", 'displayOrder' => 15},
418
375
  ]
419
- elsif list_type.to_s.downcase == 'api'
420
- [
421
- {'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'displayOrder' => 1},
422
- {'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'displayOrder' => 2},
423
- #{'fieldName' => 'type', 'fieldLabel' => 'Type', 'type' => 'select', 'selectOptions' => [{'name' => 'Rest', 'value' => 'rest'}, {'name' => 'Manual', 'value' => 'manual'}], 'defaultValue' => 'rest', 'required' => true, 'displayOrder' => 3},
424
- {'fieldName' => 'visibility', 'fieldLabel' => 'Visibility', 'type' => 'select', 'selectOptions' => [{'name' => 'Private', 'value' => 'private'}, {'name' => 'Public', 'value' => 'public'}], 'defaultValue' => 'private', 'displayOrder' => 3},
425
- {'fieldName' => 'apiType', 'fieldLabel' => 'Option List', 'type' => 'select', 'optionSource' => 'apiOptionLists', 'required' => true, 'description' => 'The code of the api list to use, eg. clouds, servers, etc.', 'displayOrder' => 6},
426
- {'fieldName' => 'translationScript', 'fieldLabel' => 'Translation Script', 'type' => 'code-editor', 'description' => "Create a js script to translate the result data object into an Array containing objects with properties name, and value. The input data is provided as data and the result should be put on the global variable results.", 'displayOrder' => 9},
427
- {'fieldName' => 'requestScript', 'fieldLabel' => 'Request Script', 'type' => 'code-editor', 'description' => "Create a js script to prepare the request. Return a data object as the body for a post, and return an array containing properties name and value for a get. The input data is provided as data and the result should be put on the global variable results.", 'displayOrder' => 10},
428
- ]
429
- elsif list_type.to_s.downcase == 'manual'
430
- [
431
- {'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'displayOrder' => 1},
432
- {'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'displayOrder' => 2},
433
- #{'fieldName' => 'type', 'fieldLabel' => 'Type', 'type' => 'select', 'selectOptions' => [{'name' => 'Rest', 'value' => 'rest'}, {'name' => 'Manual', 'value' => 'manual'}], 'defaultValue' => 'rest', 'required' => true, 'displayOrder' => 3},
434
- {'fieldName' => 'visibility', 'fieldLabel' => 'Visibility', 'type' => 'select', 'selectOptions' => [{'name' => 'Private', 'value' => 'private'}, {'name' => 'Public', 'value' => 'public'}], 'defaultValue' => 'private', 'displayOrder' => 3},
435
- {'fieldName' => 'initialDataset', 'fieldLabel' => 'Dataset', 'type' => 'code-editor', 'required' => true, 'description' => "Create an initial JSON or CSV dataset to be used as the collection for this option list. It should be a list containing objects with properties 'name', and 'value'.", 'displayOrder' => 4},
436
- ]
437
- else
438
- print_red_alert "Unknown Option List type '#{list_type}'"
439
- exit 1
440
- end
376
+
441
377
  end
442
378
 
443
- def update_option_type_list_option_types(list_type='rest')
444
- list = new_option_type_list_option_types(list_type)
379
+ def update_option_type_list_option_types()
380
+ list = new_option_type_list_option_types()
445
381
  list.each {|it|
446
382
  it.delete('required')
447
383
  it.delete('defaultValue')
@@ -65,7 +65,8 @@ class Morpheus::Cli::LibraryOptionTypesCommand
65
65
  fieldLabel: option_type['fieldLabel'],
66
66
  fieldName: option_type['fieldName'],
67
67
  default: option_type['defaultValue'],
68
- required: option_type['required'] ? 'yes' : 'no'
68
+ required: (option_type['required'].nil? ? '' : format_boolean(option_type['required'])),
69
+ export: (option_type['exportMeta'].nil? ? '' : format_boolean(option_type['exportMeta']))
69
70
  }
70
71
  end
71
72
  print cyan
@@ -76,7 +77,8 @@ class Morpheus::Cli::LibraryOptionTypesCommand
76
77
  {:fieldLabel => {:display_name => "Field Label"} },
77
78
  {:fieldName => {:display_name => "Field Name"} },
78
79
  :default,
79
- :required
80
+ :required,
81
+ :export,
80
82
  ], options)
81
83
  print reset
82
84
  print_results_pagination(json_response)
@@ -139,6 +141,7 @@ class Morpheus::Cli::LibraryOptionTypesCommand
139
141
  "Placeholder" => 'placeHolder',
140
142
  "Default Value" => 'defaultValue',
141
143
  "Required" => lambda {|it| format_boolean(it['required']) },
144
+ "Export As Tag" => lambda {|it| it['exportMeta'].nil? ? '' : format_boolean(it['exportMeta']) },
142
145
  }, option_type)
143
146
  print reset,"\n"
144
147
  return 0
@@ -162,18 +165,16 @@ class Morpheus::Cli::LibraryOptionTypesCommand
162
165
  payload = nil
163
166
  if options[:payload]
164
167
  payload = options[:payload]
165
- # support -O OPTION switch on top of --payload
166
- if options[:options]
167
- payload['optionType'] ||= {}
168
- payload['optionType'].deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) })
169
- end
168
+ payload.deep_merge!({'optionType' => parse_passed_options(options)})
170
169
  else
171
- params = Morpheus::Cli::OptionTypes.prompt(new_option_type_option_types, options[:options], @api_client, options[:params])
172
- if params.key?('required')
173
- params['required'] = ['on','true'].include?(params['required'].to_s)
174
- end
175
- option_type_payload = params
176
- payload = {optionType: option_type_payload}
170
+ payload = {}
171
+ payload.deep_merge!({'optionType' => parse_passed_options(options)})
172
+ option_type_payload = Morpheus::Cli::OptionTypes.prompt(new_option_type_option_types, options[:options], @api_client)
173
+ # tweak payload for API
174
+ option_type_payload['optionList'] = {'id' => option_type_payload['optionList'].to_i} if option_type_payload['optionList'].is_a?(String) || option_type_payload['optionList'].is_a?(Numeric)
175
+ option_type_payload['required'] = ['on','true'].include?(option_type_payload['required'].to_s) if option_type_payload.key?('required')
176
+ option_type_payload['exportMeta'] = ['on','true'].include?(option_type_payload['exportMeta'].to_s) if option_type_payload.key?('exportMeta')
177
+ payload.deep_merge!({'optionType' => option_type_payload})
177
178
  end
178
179
  @option_types_interface.setopts(options)
179
180
  if options[:dry_run]
@@ -207,27 +208,19 @@ class Morpheus::Cli::LibraryOptionTypesCommand
207
208
  begin
208
209
  option_type = find_option_type_by_name_or_id(args[0])
209
210
  exit 1 if option_type.nil?
210
-
211
211
  if options[:payload]
212
212
  payload = options[:payload]
213
- # support -O OPTION switch on top of --payload
214
- if options[:options]
215
- payload['optionType'] ||= {}
216
- payload['optionType'].deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) })
217
- end
213
+ payload.deep_merge!({'optionType' => parse_passed_options(options)})
218
214
  else
219
- #params = options[:options] || {}
220
- params = Morpheus::Cli::OptionTypes.no_prompt(update_option_type_option_types, options[:options], @api_client, options[:params])
221
- if params.empty?
222
- print_red_alert "Specify at least one option to update"
223
- puts optparse
224
- exit 1
225
- end
226
- if params.key?('required')
227
- params['required'] = ['on','true'].include?(params['required'].to_s)
228
- end
229
- option_type_payload = params
230
- payload = {optionType: option_type_payload}
215
+ payload = {}
216
+ payload.deep_merge!({'optionType' => parse_passed_options(options)})
217
+ option_type_payload = Morpheus::Cli::OptionTypes.no_prompt(update_option_type_option_types, options[:options], @api_client)
218
+ # tweak payload for API
219
+ option_type_payload['optionList'] = {'id' => option_type_payload['optionList'].to_i} if option_type_payload['optionList'].is_a?(String) || option_type_payload['optionList'].is_a?(Numeric)
220
+ option_type_payload['required'] = ['on','true'].include?(option_type_payload['required'].to_s) if option_type_payload.key?('required')
221
+ option_type_payload['exportMeta'] = ['on','true'].include?(option_type_payload['exportMeta'].to_s) if option_type_payload.key?('exportMeta')
222
+ payload.deep_merge!({'optionType' => option_type_payload})
223
+ raise_command_error "Specify at least one option to update.\n#{optparse}" if payload['optionType'].empty?
231
224
  end
232
225
  @option_types_interface.setopts(options)
233
226
  if options[:dry_run]
@@ -296,12 +289,14 @@ class Morpheus::Cli::LibraryOptionTypesCommand
296
289
  [
297
290
  {'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'displayOrder' => 1},
298
291
  {'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'displayOrder' => 2},
299
- {'fieldName' => 'fieldName', 'fieldLabel' => 'Field Name', 'type' => 'text', 'required' => true, 'description' => 'This is the input fieldName property that the value gets assigned to.', 'displayOrder' => 3},
300
- {'fieldName' => 'type', 'fieldLabel' => 'Type', 'type' => 'select', 'selectOptions' => [{'name' => 'Text', 'value' => 'text'}, {'name' => 'Password', 'value' => 'password'}, {'name' => 'Number', 'value' => 'number'}, {'name' => 'Checkbox', 'value' => 'checkbox'}, {'name' => 'Select', 'value' => 'select'}, {'name' => 'Hidden', 'value' => 'hidden'}], 'defaultValue' => 'text', 'required' => true, 'displayOrder' => 4},
301
- {'fieldName' => 'fieldLabel', 'fieldLabel' => 'Field Label', 'type' => 'text', 'required' => true, 'description' => 'This is the input label that shows typically to the left of a custom option.', 'displayOrder' => 5},
302
- {'fieldName' => 'placeHolder', 'fieldLabel' => 'Placeholder', 'type' => 'text', 'displayOrder' => 6},
303
- {'fieldName' => 'defaultValue', 'fieldLabel' => 'Default Value', 'type' => 'text', 'displayOrder' => 7},
304
- {'fieldName' => 'required', 'fieldLabel' => 'Required', 'type' => 'checkbox', 'defaultValue' => 'off', 'displayOrder' => 8},
292
+ {'fieldName' => 'fieldName', 'fieldLabel' => 'Field Name', 'type' => 'text', 'required' => true, 'description' => 'This is the input property that the value gets assigned to.', 'displayOrder' => 3},
293
+ {'code' => 'optionType.type', 'fieldName' => 'type', 'fieldLabel' => 'Type', 'type' => 'select', 'selectOptions' => [{'name' => 'Text', 'value' => 'text'}, {'name' => 'Password', 'value' => 'password'}, {'name' => 'Number', 'value' => 'number'}, {'name' => 'Checkbox', 'value' => 'checkbox'}, {'name' => 'Select', 'value' => 'select'}, {'name' => 'Hidden', 'value' => 'hidden'}], 'defaultValue' => 'text', 'required' => true, 'displayOrder' => 4},
294
+ {'fieldName' => 'optionList', 'fieldLabel' => 'Option List', 'type' => 'select', 'optionSource' => 'optionTypeLists', 'required' => true, 'dependsOnCode' => 'optionType.type:select', 'description' => "The Option List to be the source of options when type is 'select'.", 'displayOrder' => 5},
295
+ {'fieldName' => 'fieldLabel', 'fieldLabel' => 'Field Label', 'type' => 'text', 'required' => true, 'description' => 'This is the input label that shows typically to the left of a custom option.', 'displayOrder' => 6},
296
+ {'fieldName' => 'placeHolder', 'fieldLabel' => 'Placeholder', 'type' => 'text', 'displayOrder' => 7},
297
+ {'fieldName' => 'defaultValue', 'fieldLabel' => 'Default Value', 'type' => 'text', 'displayOrder' => 8},
298
+ {'fieldName' => 'required', 'fieldLabel' => 'Required', 'type' => 'checkbox', 'defaultValue' => false, 'displayOrder' => 9},
299
+ {'fieldName' => 'exportMeta', 'fieldLabel' => 'Export As Tag', 'type' => 'checkbox', 'defaultValue' => false, 'description' => 'Export as Tag.', 'displayOrder' => 10},
305
300
  ]
306
301
  end
307
302
 
@@ -63,9 +63,9 @@ class Morpheus::Cli::LogsCommand
63
63
  # options[:interval] = parse_time(val).utc.iso8601
64
64
  # end
65
65
  opts.on('--level VALUE', String, "Log Level. DEBUG,INFO,WARN,ERROR") do |val|
66
- params['level'] = params['level'] ? [params['level'], val].flatten : val
66
+ params['level'] = params['level'] ? [params['level'], val].flatten : [val]
67
67
  end
68
- opts.on('--table', '--table', "Format ouput as a table.") do
68
+ opts.on('-t', '--table', "Format ouput as a table.") do
69
69
  options[:table] = true
70
70
  end
71
71
  opts.on('-a', '--all', "Display all details: entire message." ) do
@@ -81,6 +81,7 @@ class Morpheus::Cli::LogsCommand
81
81
  end
82
82
  connect(options)
83
83
  begin
84
+ params['level'] = params['level'].collect {|it| it.to_s.upcase }.join('|') if params['level'] # api works with INFO|WARN
84
85
  params.merge!(parse_list_options(options))
85
86
  params['query'] = params.delete('phrase') if params['phrase']
86
87
  params['order'] = params['direction'] unless params['direction'].nil? # old api version expects order instead of direction
@@ -502,4 +502,36 @@ module Morpheus::Cli::LibraryHelper
502
502
  return {success:true, data: spec_template_ids}
503
503
  end
504
504
 
505
+ def find_option_type_list_by_name_or_id(val)
506
+ if val.to_s =~ /\A\d{1,}\Z/
507
+ return find_option_type_list_by_id(val)
508
+ else
509
+ return find_option_type_list_by_name(val)
510
+ end
511
+ end
512
+
513
+ def find_option_type_list_by_id(id)
514
+ begin
515
+ json_response = @option_type_lists_interface.get(id.to_i)
516
+ return json_response['optionTypeList']
517
+ rescue RestClient::Exception => e
518
+ if e.response && e.response.code == 404
519
+ print_red_alert "Option List not found by id #{id}"
520
+ exit 1
521
+ else
522
+ raise e
523
+ end
524
+ end
525
+ end
526
+
527
+ def find_option_type_list_by_name(name)
528
+ json_results = @option_type_lists_interface.list({name: name.to_s})
529
+ if json_results['optionTypeLists'].empty?
530
+ print_red_alert "Option List not found by name #{name}"
531
+ exit 1
532
+ end
533
+ option_type_list = json_results['optionTypeLists'][0]
534
+ return option_type_list
535
+ end
536
+
505
537
  end
@@ -45,6 +45,8 @@ module Morpheus::Cli::LogsHelper
45
45
  end
46
46
  out = ""
47
47
  table_color = options.key?(:color) ? options[:color] : cyan
48
+ term_width = current_terminal_width()
49
+ message_col_width = current_terminal_width() - (show_object ? 56 : 36)
48
50
  log_records.each do |log_entry|
49
51
  log_level = format_log_level(log_entry['level'], table_color, 6)
50
52
  out << table_color if table_color
@@ -52,15 +54,20 @@ module Morpheus::Cli::LogsHelper
52
54
  out << "#{log_level} "
53
55
  out << "[#{log_entry['ts']}] "
54
56
  if show_object
55
- out << "(#{log_entry['typeCode']} #{log_entry['objectId']}) "
57
+ log_src = "#{log_entry['typeCode']} #{log_entry['objectId']}"
58
+ if options[:details] || options[:all]
59
+ # log_src = "#{log_entry['typeCode']} #{log_entry['objectId']}"
60
+ else
61
+ log_src = truncate_string(log_src, 20)
62
+ end
63
+ out << "(#{log_src}) "
56
64
  end
57
65
  log_msg = ""
58
66
  if options[:details] || options[:all]
59
- log_msg = log_entry['message'].to_s.strip
60
- else
61
- # truncate_string(log_entry['message'].to_s.split.select {|it| it.to_s.strip != "" }.first, 100)
62
- log_msg = truncate_string(log_entry['message'].to_s.gsub("\r\n", " ").gsub("\n", " "), 100)
63
- end
67
+ log_msg = log_entry['message'].to_s.strip
68
+ else
69
+ log_msg = truncate_string(log_entry['message'].to_s.strip.gsub(/\r?\n/, " "), message_col_width)
70
+ end
64
71
  out << "- #{log_msg}"
65
72
  out << table_color if table_color
66
73
  out << "\n"
@@ -71,15 +78,17 @@ module Morpheus::Cli::LogsHelper
71
78
  def format_log_table(logs, options={}, show_object=true)
72
79
  out = ""
73
80
  table_color = options.key?(:color) ? options[:color] : cyan
81
+ term_width = current_terminal_width()
82
+ message_col_width = current_terminal_width() - (show_object ? 56 : 36)
74
83
  log_columns = [
75
84
  {"LEVEL" => lambda {|log_entry| format_log_level(log_entry['level'], table_color) } },
76
85
  {"DATE" => lambda {|log_entry| log_entry['ts'] } },
77
86
  {"SOURCE" => lambda {|log_entry| "#{log_entry['typeCode']} #{log_entry['objectId']}" } },
78
87
  {"MESSAGE" => lambda {|log_entry|
79
88
  if options[:details] || options[:all]
80
- log_entry['message'].to_s
89
+ log_entry['message'].to_s.strip
81
90
  else
82
- truncate_string(log_entry['message'].to_s.split.first, 100)
91
+ truncate_string(log_entry['message'].to_s.strip.gsub(/\r?\n/, " "), message_col_width)
83
92
  end
84
93
  } }
85
94
  ]
@@ -89,7 +98,7 @@ module Morpheus::Cli::LogsHelper
89
98
  # if options[:include_fields]
90
99
  # columns = options[:include_fields]
91
100
  # end
92
- out << as_pretty_table(logs, log_columns, options.merge(responsive_table:false))
101
+ out << as_pretty_table(logs, log_columns, options.merge(wrap:true))
93
102
  # out << "\n"
94
103
  return out
95
104
  end