Class: Morpheus::Cli::WhitelabelSettingsCommand

Inherits:
Object
  • Object
show all
Includes:
AccountsHelper, CliCommand
Defined in:
lib/morpheus/cli/commands/whitelabel_settings_command.rb

Instance Attribute Summary

Attributes included from CliCommand

#no_prompt

Instance Method Summary collapse

Methods included from AccountsHelper

#account_column_definitions, #account_users_interface, #accounts_interface, #find_account_by_id, #find_account_by_name, #find_account_by_name_or_id, #find_account_from_options, #find_all_user_ids, #find_role_by_id, #find_role_by_name, #find_role_by_name_or_id, #find_user_by_id, #find_user_by_username, #find_user_by_username_or_id, #find_user_group_by_id, #find_user_group_by_name, #find_user_group_by_name_or_id, #format_access_string, #format_role_type, #format_user_role_names, #format_user_status, #get_access_color, #get_access_string, included, #list_account_column_definitions, #list_user_column_definitions, #list_user_group_column_definitions, #role_column_definitions, #roles_interface, #subtenant_role_column_definitions, #user_column_definitions, #user_group_column_definitions, #user_groups_interface

Methods included from CliCommand

#add_query_parameter, #apply_options, #build_common_options, #build_get_options, #build_list_options, #build_option_type_options, #build_standard_add_many_options, #build_standard_add_options, #build_standard_api_options, #build_standard_delete_options, #build_standard_get_options, #build_standard_list_options, #build_standard_post_options, #build_standard_put_options, #build_standard_remove_options, #build_standard_update_options, #command_description, #command_name, #confirm, #confirm!, #default_refresh_interval, #default_sigdig, #default_subcommand, #establish_remote_appliance_connection, #execute_api, #execute_api_payload, #execute_api_request, #find_all, #find_all_json, #find_by_id, #find_by_name, #find_by_name_or_id, #find_record, #find_record_json, #full_command_usage, #get_interface, #get_list_key, #get_object_key, #get_subcommand_description, #handle_each_payload, #handle_subcommand, included, #interactive?, #my_help_command, #my_terminal, #my_terminal=, #parse_array, #parse_bytes_param, #parse_get_options!, #parse_id_list, #parse_labels, #parse_list_options, #parse_list_options!, #parse_list_subtitles, #parse_options, #parse_parameter_as_resource_id!, #parse_passed_options, #parse_payload, #parse_query_options, #print, #print_error, #println, #prog_name, #puts, #puts_error, #raise_args_error, #raise_command_error, #render_response, #run_command_for_each_arg, #subcommand_aliases, #subcommand_description, #subcommand_usage, #subcommands, #usage, #validate_outfile, #verify_args!, #visible_subcommands

Constructor Details

#initializeWhitelabelSettingsCommand

Returns a new instance of WhitelabelSettingsCommand.



13
14
15
# File 'lib/morpheus/cli/commands/whitelabel_settings_command.rb', line 13

def initialize()
  @image_types = {'header-logo' => 'headerLogo', 'footer-logo' => 'footerLogo', 'login-logo' => 'loginLogo', 'favicon' => 'favicon'}
end

Instance Method Details

#connect(opts) ⇒ Object



17
18
19
20
21
# File 'lib/morpheus/cli/commands/whitelabel_settings_command.rb', line 17

def connect(opts)
  @api_client = establish_remote_appliance_connection(opts)
  @whitelabel_settings_interface = @api_client.whitelabel_settings
  @accounts_interface = @api_client.accounts
end

#download_image(args) ⇒ Object



549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
# File 'lib/morpheus/cli/commands/whitelabel_settings_command.rb', line 549

def download_image(args)
  params = {}
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = opts.banner = subcommand_usage("[image-type] [local-file]")
    opts.on( '--tenant TENANT', String, "Tenant Name or ID" ) do |val|
      options[:account] = val
    end
    opts.on( '-a', '--account ACCOUNT', "Tenant Name or ID" ) do |val|
      options[:account] = val
    end
    opts.add_hidden_option('-a, --account') if opts.is_a?(Morpheus::Cli::OptionParser)
    opts.on( '-f', '--force', "Overwrite existing [local-file] if it exists." ) do
      options[:overwrite] = true
    end
    opts.on( '-p', '--mkdir', "Create missing directories for [local-file] if they do not exist." ) do
      options[:mkdir] = true
    end
    build_common_options(opts, options, [:dry_run, :quiet, :remote])
    opts.footer = "Download an image file.\n" +
        "[image-type] is required. This is the whitelabel image type (#{@image_types.collect {|k,v| k}.join('|')}) to be downloaded.\n" +
        "[local-file] is required. This is the full local filepath for the downloaded file."
  end

  optparse.parse!(args)
  connect(options)

  if args.count != 2
    raise_command_error "wrong number of arguments, expected 2 and got (#{args.count}) #{args}\n#{optparse}"
    return 1
  end
  if !@image_types[args[0]]
    raise_command_error "Invalid image type specified: #{args[0]}. Must be one of the following (#{@image_types.collect {|k,v| k}.join('|')})"
    return 1
  end

  begin
     = nil
    if options[:account]
       = (options[:account])
      if .nil?
        return 1
      else
        params['accountId'] = ['id']
      end
    end
    image_type = @image_types[args[0]]
    outfile = File.expand_path(args[1])
    outdir = File.dirname(outfile)

    if Dir.exist?(outfile)
      print_red_alert "[local-file] is invalid. It is the name of an existing directory: #{outfile}"
      return 1
    end
    if !Dir.exist?(outdir)
      if options[:mkdir]
        print cyan,"Creating local directory #{outdir}",reset,"\n"
        FileUtils.mkdir_p(outdir)
      else
        print_red_alert "[local-file] is invalid. Directory not found: #{outdir}"
        return 1
      end
    end
    if File.exist?(outfile) && !options[:overwrite]
      print_red_alert "[local-file] is invalid. File already exists: #{outfile}\nUse -f to overwrite the existing file."
      return 1
    end

    @whitelabel_settings_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @whitelabel_settings_interface.dry.download_image(image_type, outfile, params)
      return
    end

    if !options[:quite]
      print cyan + "Downloading #{args[0]} to #{outfile} ... "
    end

    http_response = @whitelabel_settings_interface.download_image(image_type, outfile, params)

    success = http_response.code.to_i == 200
    if success
      if !options[:quiet]
        print green + "SUCCESS" + reset + "\n"
      end
      return 0
    else
      if !options[:quiet]
        print red + "ERROR" + reset + " HTTP #{http_response.code}" + "\n"
      end
      if File.exist?(outfile) && File.file?(outfile)
        Morpheus::Logging::DarkPrinter.puts "Deleting bad file download: #{outfile}" if Morpheus::Logging.debug?
        File.delete(outfile)
      end
      if options[:debug]
        puts_error http_response.inspect
      end
      return 1
    end
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    return 1
  end
end

#get(args) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/morpheus/cli/commands/whitelabel_settings_command.rb', line 27

def get(args)
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage()
    opts.on( '--tenant TENANT', String, "Tenant Name or ID" ) do |val|
      options[:account] = val
    end
    opts.on( '-a', '--account ACCOUNT', "Tenant Name or ID" ) do |val|
      options[:account] = val
    end
    opts.add_hidden_option('-a, --account') if opts.is_a?(Morpheus::Cli::OptionParser)
    opts.on('--details', "Show full (not truncated) contents of Terms of Use, Privacy Policy, Override CSS" ) do
      options[:details] = true
    end
    build_common_options(opts, options, [:query, :json, :yaml, :csv, :fields, :dry_run, :remote])
    opts.footer = "Get whitelabel settings."
  end

  optparse.parse!(args)
  connect(options)

  if args.count != 0
    raise_command_error "wrong number of arguments, expected 0 and got (#{args.count}) #{args}\n#{optparse}"
    return 1
  end
  
  begin
    params = parse_list_options(options)
     = nil
    if options[:account]
       = (options[:account])
      if .nil?
        return 1
      else
        params['accountId'] = ['id']
      end
    end
    @whitelabel_settings_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @whitelabel_settings_interface.dry.get(params)
      return
    end
    json_response = @whitelabel_settings_interface.get(params)
    if options[:json]
      puts as_json(json_response, options, "whitelabelSettings")
      return 0
    elsif options[:yaml]
      puts as_yaml(json_response, options, "whitelabelSettings")
      return 0
    elsif options[:csv]
      puts records_as_csv([json_response['whitelabelSettings']], options)
      return 0
    end

    whitelabel_settings = json_response['whitelabelSettings']

    print_h1 "Whitelabel Settings"
    print cyan
    description_cols = {
      "Tenant" => lambda {|it| it['account']['name'] rescue '' },
      "Enabled" => lambda {|it| format_boolean(it['enabled']) },
      "Appliance Name" => lambda {|it| it['applianceName'] },
      "Disable Support Menu" => lambda {|it| format_boolean(it['disableSupportMenu'])},
      "Header Logo" => lambda {|it| it['headerLogo'] ? it['headerLogo'].split('/').last : '' },
      "Footer Logo" => lambda {|it| it['footerLogo'] ? it['footerLogo'].split('/').last : '' },
      "Login Logo" => lambda {|it| it['loginLogo'] ? it['loginLogo'].split('/').last : '' },
      "Favicon" => lambda {|it| it['favicon'] ? it['favicon'].split('/').last : '' },
      "Header Background" => lambda {|it| it['headerBgColor']},
      "Header Foreground" => lambda {|it| it['headerFgColor']},
      "Nav Background" => lambda {|it| it['navBgColor']},
      "Nav Foreground" => lambda {|it| it['navFgColor']},
      "Nav Hover" => lambda {|it| it['navHoverColor']},
      "Primary Button Background" => lambda {|it| it['primaryButtonBgColor']},
      "Primary Button Foreground" => lambda {|it| it['primaryButtonFgColor']},
      "Primary Button Hover Background" => lambda {|it| it['primaryButtonHoverBgColor']},
      "Primary Button Hover Foreground" => lambda {|it| it['primaryButtonHoverFgColor']},
      "Footer Background" => lambda {|it| it['footerBgColor']},
      "Footer Foreground" => lambda {|it| it['footerFgColor']},
      "Login Background" => lambda {|it| it['loginBgColor']},
      "Copyright String" => lambda {|it| it['copyrightString']}
    }

    print_description_list(description_cols, whitelabel_settings)

    # Support Menu Links
    if !whitelabel_settings['supportMenuLinks'].empty?
      print_h2 "Support Menu Links"
      print cyan
      print as_pretty_table(whitelabel_settings['supportMenuLinks'], [:url, :label, :labelCode])
    end

    trunc_len = 80
    if !(content = whitelabel_settings['overrideCss']).nil? && content.length
      title = "Override CSS"
      title = title + ' (truncated, use --details for all content)' if content && content.length > trunc_len && !options[:details]
      print_h2 title
      print cyan
      print options[:details] ? content : truncate_string(content, trunc_len), "\n"
    end
    if !(content = whitelabel_settings['termsOfUse']).nil? && content.length
      title = "Terms of Use"
      title = title + ' (truncated, use --details for all content)' if content && content.length > trunc_len && !options[:details]
      print_h2 title
      print cyan
      print options[:details] ? content : truncate_string(content, trunc_len), "\n"
    end
    if !(content = whitelabel_settings['privacyPolicy']).nil? && content.length
      title = "Privacy Policy"
      title = title + ' (truncated, use --details for all content)' if content && content.length > trunc_len && !options[:details]
      print_h2 title
      print cyan
      print options[:details] ? content : truncate_string(content, trunc_len), "\n"
    end
    print reset, "\n"
    return 0
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    return 1
  end
end

#handle(args) ⇒ Object



23
24
25
# File 'lib/morpheus/cli/commands/whitelabel_settings_command.rb', line 23

def handle(args)
  handle_subcommand(args)
end

#reset_image(args) ⇒ Object



421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
# File 'lib/morpheus/cli/commands/whitelabel_settings_command.rb', line 421

def reset_image(args)
  query_params = {}
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = opts.banner = subcommand_usage("[image-type]")
    opts.on( '--tenant TENANT', String, "Tenant Name or ID" ) do |val|
      options[:account] = val
    end
    opts.on( '-a', '--account ACCOUNT', "Tenant Name or ID" ) do |val|
      options[:account] = val
    end
    opts.add_hidden_option('-a, --account') if opts.is_a?(Morpheus::Cli::OptionParser)
    build_common_options(opts, options, [:json, :dry_run, :quiet, :remote])
    opts.footer = "Reset your whitelabel image.\n" +
        "[image-type] is required. This is the whitelabel image type (#{@image_types.collect {|k,v| k}.join('|')})"
  end

  optparse.parse!(args)
  connect(options)

  if args.count != 1
    raise_command_error "wrong number of arguments, expected 1 and got (#{args.count}) #{args}\n#{optparse}"
    return 1
  end
  if !@image_types[args[0]]
    raise_command_error "Invalid image type specified: #{args[0]}. Must be one of the following (#{@image_types.collect {|k,v| k}.join('|')})"
    return 1
  end

  begin
     = nil
    if options[:account]
       = (options[:account])
      if .nil?
        return 1
      else
        query_params['accountId'] = ['id']
      end
    end
    image_type = @image_types[args[0]]
    @whitelabel_settings_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @whitelabel_settings_interface.dry.reset_image(image_type, query_params)
      return
    end

    json_response = @whitelabel_settings_interface.reset_image(image_type, query_params)

    if options[:json]
      puts as_json(json_response, options)
    elsif !options[:quiet]
      print_red_alert "Error resetting whitelabel image: #{json_response['msg'] || json_response['errors']}" if json_response['success'] == false
      print_green_success "Reset whitelabel image" if json_response['success'] == true
    end
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#update(args) ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'lib/morpheus/cli/commands/whitelabel_settings_command.rb', line 148

def update(args)
  options = {}
  params = {}
  query_params = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = opts.banner = subcommand_usage()
    opts.on( '--tenant TENANT', String, "Tenant Name or ID" ) do |val|
      options[:account] = val
    end
    opts.on( '-a', '--account ACCOUNT', "Tenant Name or ID" ) do |val|
      options[:account] = val
    end
    opts.add_hidden_option('-a, --account') if opts.is_a?(Morpheus::Cli::OptionParser)
    opts.on('--active [on|off]', String, "Can be used to enable / disable whitelabel feature") do |val|
      params['enabled'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == '1' || val.to_s == ''
    end
    opts.on("--appliance-name NAME", String, "Appliance name. Only available to master tenant") do |val|
      params['applianceName'] = val == 'null' ? nil : val
    end
    opts.on("--disable-support-menu [on|off]", ['on','off'], "Can be used to disable support menu") do |val|
      params['disableSupportMenu'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == '1' || val.to_s == ''
    end
    opts.on("--reset-header-logo", String, "Resets header logo to default header logo") do |val|
      params['resetHeaderLogo'] = true
    end
    opts.on("--reset-footer-logo", String, "Resets footer logo to default footer logo") do |val|
      params['resetFooterLogo'] = true
    end
    opts.on("--reset-login-logo", String, "Resets login logo to default login logo") do |val|
      params['resetLoginLogo'] = true
    end
    opts.on("--reset-favicon", String, "Resets favicon default favicon") do |val|
      params['resetFavicon'] = true
    end
    opts.on("--header-bg-color VALUE", String, "Header background color") do |val|
      params['headerBgColor'] = val == 'null' ? nil : val
    end
    opts.on("--header-fg-color VALUE", String, "Header foreground color") do |val|
      params['headerFgColor'] = val == 'null' ? nil : val
    end
    opts.on("--nav-bg-color VALUE", String, "Nav background color") do |val|
      params['navBgColor'] = val == 'null' ? nil : val
    end
    opts.on("--nav-fg-color VALUE", String, "Nav foreground color") do |val|
      params['navFgColor'] = val == 'null' ? nil : val
    end
    opts.on("--nav-hover-color VALUE", String, "Nav hover color") do |val|
      params['navHoverColor'] = val == 'null' ? nil : val
    end
    opts.on("--primary-button-bg-color VALUE", String, "Primary button background color") do |val|
      params['primaryButtonBgColor'] = val == 'null' ? nil : val
    end
    opts.on("--primary-button-fg-color VALUE", String, "Primary button foreground color") do |val|
      params['primaryButtonFgColor'] = val == 'null' ? nil : val
    end
    opts.on("--primary-button-hover-bg-color VALUE", String, "Primary button hover background color") do |val|
      params['primaryButtonHoverBgColor'] = val == 'null' ? nil : val
    end
    opts.on("--primary-button-hover-fg-color VALUE", String, "Primary button hover foreground color") do |val|
      params['primaryButtonHoverFgColor'] = val == 'null' ? nil : val
    end
    opts.on("--footer-bg-color VALUE", String, "Footer background color") do |val|
      params['footerBgColor'] = val == 'null' ? nil : val
    end
    opts.on("--footer-fg-color VALUE", String, "Footer foreground color") do |val|
      params['footerFgColor'] = val == 'null' ? nil : val
    end
    opts.on("--login-bg-color VALUE", String, "Login background color") do |val|
      params['loginBgColor'] = val == 'null' ? nil : val
    end
    opts.on("--copyright TEXT", String, "Copyright String") do |val|
      params['copyrightString'] = val == 'null' ? nil : val
    end
    opts.on("--css TEXT", String, "Override CSS") do |val|
      params['overrideCss'] = val == 'null' ? nil : val
    end
    opts.on("--css-file FILE", String, "Override CSS from local file") do |val|
      options[:overrideCssFile] = val
    end
    opts.on("--terms TEXT", String, "Terms of use content") do |val|
      params['termsOfUse'] = val == 'null' ? nil : val
    end
    opts.on("--terms-file FILE", String, "Terms of use content from local file") do |val|
      options[:termsOfUseFile] = val
    end
    opts.on("--privacy-policy TEXT", String, "Privacy policy content") do |val|
      params['privacyPolicy'] = val == 'null' ? nil : val
    end
    opts.on("--privacy-policy-file FILE", String, "Privacy policy content from local file") do |val|
      options[:privacyPolicyFile] = val
    end
    opts.on('--support-menu-links JSON', String, "Support menu links JSON") do |val|
      begin
        support_menu_links = JSON.parse(val.to_s)
        params['supportMenuLinks'] = support_menu_links.kind_of?(Array) ? support_menu_links : [support_menu_links]
      rescue JSON::ParserError => e
        print_red_alert "Unable to parse support menu links JSON"
        exit 1
      end
    end
    opts.on('--support-menu-links-list LIST', Array, "Support menu links list. Comma delimited list of menu links. Each menu link is pipe delimited url1|label1|code1,url2|label2|code2") do |val|
      params['supportMenuLinks'] = val.collect { |link|
        parts = link.split('|')
        {'url' => parts[0].strip, 'label' => (parts.count > 1 ? parts[1].strip : ''), 'labelCode' => (parts.count > 2 ? parts[2].strip : '')}
      }
    end
    build_common_options(opts, options, [:json, :payload, :dry_run, :quiet, :remote])
  end

  optparse.parse!(args)
  connect(options)

  if args.count != 0
    raise_command_error "wrong number of arguments, expected 0 and got (#{args.count}) #{args}\n#{optparse}"
    return 1
  end

  begin
     = nil
    if options[:account]
       = (options[:account])
      if .nil?
        return 1
      else
        query_params['accountId'] = ['id']
      end
    end
    payload = parse_payload(options)
    image_files = {}

    if !payload
      [:overrideCssFile, :termsOfUseFile, :privacyPolicyFile].each do |sym|
        if options[sym]
          filename = File.expand_path(options[sym])

          if filename && File.file?(filename)
            params[sym.to_s.delete_suffix('File')] = File.read(filename)
          else
            print_red_alert("File not found: #{filename}")
            exit 1
          end
        end
      end
      payload = {'whitelabelSettings' => params}
    end

    @whitelabel_settings_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @whitelabel_settings_interface.dry.update(payload, query_params)
      return
    end
    json_response = @whitelabel_settings_interface.update(payload, query_params)

    if options[:json]
      puts as_json(json_response, options)
    elsif !options[:quiet]
      if json_response['success']
        print_green_success "Updated whitelabel settings"
        get([] + (options[:account] ? ["-a",options[:account]] : []) + (options[:remote] ? ["-r",options[:remote]] : []))
      else
        print_red_alert "Error updating whitelabel settings: #{json_response['msg'] || json_response['errors']}"
      end
    end
    return 0
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#update_images(args) ⇒ Object



318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
# File 'lib/morpheus/cli/commands/whitelabel_settings_command.rb', line 318

def update_images(args)
  params = {}
  query_params = {}
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = opts.banner = subcommand_usage()
    opts.on( '--tenant TENANT', String, "Tenant Name or ID" ) do |val|
      options[:account] = val
    end
    opts.on( '-a', '--account ACCOUNT', "Tenant Name or ID" ) do |val|
      options[:account] = val
    end
    opts.add_hidden_option('-a, --account') if opts.is_a?(Morpheus::Cli::OptionParser)
    opts.on("--header-logo FILE", String, "Header logo image. Local path of a file to upload (png|jpg|svg)") do |val|
      options[:headerLogo] = val
    end
    opts.on("--reset-header-logo", String, "Resets header logo to default header logo") do |val|
      params['resetHeaderLogo'] = true
    end
    opts.on("--footer-logo FILE", String, "Footer logo image. Local path of a file to upload (png|jpg|svg)") do |val|
      options[:footerLogo] = val
    end
    opts.on("--reset-footer-logo", String, "Resets footer logo to default footer logo") do |val|
      params['resetFooterLogo'] = true
    end
    opts.on("--login-logo FILE", String, "Login logo image. Local path of a file to upload (png|jpg|svg)") do |val|
      options[:loginLogo] = val
    end
    opts.on("--reset-login-logo", String, "Resets login logo to default login logo") do |val|
      params['resetLoginLogo'] = true
    end
    opts.on("--favicon FILE", String, "Favicon icon image. Local path of a file to upload") do |val|
      options[:favicon] = val
    end
    opts.on("--reset-favicon", String, "Resets favicon default favicon") do |val|
      params['resetFavicon'] = true
    end
    build_common_options(opts, options, [:json, :payload, :dry_run, :quiet, :remote])
    opts.footer = "Update your whitelabel images."
  end

  optparse.parse!(args)
  connect(options)

  if args.count != 0
    raise_command_error "wrong number of arguments, expected 0 and got (#{args.count}) #{args}\n#{optparse}"
    return 1
  end

  begin
     = nil
    if options[:account]
       = (options[:account])
      if .nil?
        return 1
      else
        query_params['accountId'] = ['id']
      end
    end
    payload = parse_payload(options)

    if !payload
      payload = params

      [:headerLogo, :footerLogo, :loginLogo, :favicon].each do |sym|
        if options[sym]
          filename = File.expand_path(options[sym])

          if filename && File.file?(filename)
            payload["#{sym.to_s}.file"] = File.new(filename, 'rb')
          else
            print_red_alert("File not found: #{filename}")
            exit 1
          end
        end
      end
    end

    if payload.empty?
      print_green_success "Nothing to update"
      exit 1
    end

    @whitelabel_settings_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @whitelabel_settings_interface.dry.update_images(payload, query_params)
      return
    end

    json_response = @whitelabel_settings_interface.update_images(payload, query_params)

    if options[:json]
      puts as_json(json_response, options)
    elsif !options[:quiet]
      print_red_alert "Error updating whitelabel image: #{json_response['msg'] || json_response['errors']}" if json_response['success'] == false
      print_green_success "Updated whitelabel image" if json_response['success'] == true
    end
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#view_image(args) ⇒ Object



481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
# File 'lib/morpheus/cli/commands/whitelabel_settings_command.rb', line 481

def view_image(args)
  params = {}
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = opts.banner = subcommand_usage("[image-type]")
    opts.on( '--tenant TENANT', String, "Tenant Name or ID" ) do |val|
      options[:account] = val
    end
    opts.on( '-a', '--account ACCOUNT', "Tenant Name or ID" ) do |val|
      options[:account] = val
    end
    opts.add_hidden_option('-a, --account') if opts.is_a?(Morpheus::Cli::OptionParser)
    build_common_options(opts, options, [:json, :dry_run, :quiet, :remote])
    opts.footer = "View your image of specified [image-type].\n" +
        "[image-type] is required. This is the whitelabel image type (#{@image_types.collect {|k,v| k}.join('|')})\n" +
        "This opens the image url with a web browser."
  end

  optparse.parse!(args)
  connect(options)

  if args.count != 1
    raise_command_error "wrong number of arguments, expected 1 and got (#{args.count}) #{args}\n#{optparse}"
    return 1
  end
  if !@image_types[args[0]]
    raise_command_error "Invalid image type specified: #{args[0]}. Must be one of the following (#{@image_types.collect {|k,v| k}.join('|')})"
    return 1
  end

  begin
     = nil
    if options[:account]
       = (options[:account])
      if .nil?
        return 1
      else
        params['accountId'] = ['id']
      end
    end
    image_type = @image_types[args[0]]
    @whitelabel_settings_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @whitelabel_settings_interface.dry.get(params)
      return
    end

    whitelabel_settings = @whitelabel_settings_interface.get(params)['whitelabelSettings']

    if link = whitelabel_settings[image_type]
      if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
        system "start #{link}"
      elsif RbConfig::CONFIG['host_os'] =~ /darwin/
        system "open #{link}"
      elsif RbConfig::CONFIG['host_os'] =~ /linux|bsd/
        system "xdg-open #{link}"
      end
      return 0, nil
    else
      print_error red,"No image found for #{image_type}.",reset,"\n"
      return 1
    end
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    return 1
  end
end