morpheus-cli 5.2.2 → 5.3.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -33,7 +33,6 @@ class Morpheus::Cli::InvoicesCommand
33
33
  options[:show_estimates] = true
34
34
  # options[:show_costs] = true
35
35
  options[:show_prices] = true
36
- # options[:show_raw_data] = true
37
36
  end
38
37
  opts.on('--dates', "Display Ref Start, Ref End, etc.") do |val|
39
38
  options[:show_dates] = true
@@ -117,9 +116,6 @@ class Morpheus::Cli::InvoicesCommand
117
116
  options[:tags][k] << (v || '')
118
117
  end
119
118
  end
120
- opts.on('--raw-data', '--raw-data', "Display Raw Data, the cost data from the cloud provider's API.") do |val|
121
- options[:show_raw_data] = true
122
- end
123
119
  opts.on('--totals', "View total costs and prices for all the invoices found.") do |val|
124
120
  params['includeTotals'] = true
125
121
  options[:show_invoice_totals] = true
@@ -144,36 +140,35 @@ class Morpheus::Cli::InvoicesCommand
144
140
  # construct params
145
141
  params.merge!(parse_list_options(options))
146
142
  if options[:clouds]
147
- cloud_ids = parse_cloud_id_list(options[:clouds])
143
+ cloud_ids = parse_cloud_id_list(options[:clouds], {}, false, true)
148
144
  return 1, "clouds not found for #{options[:clouds]}" if cloud_ids.nil?
149
145
  params['zoneId'] = cloud_ids
150
146
  end
151
147
  if options[:groups]
152
- group_ids = parse_group_id_list(options[:groups])
148
+ group_ids = parse_group_id_list(options[:groups], {}, false, true)
153
149
  return 1, "groups not found for #{options[:groups]}" if group_ids.nil?
154
150
  params['siteId'] = group_ids
155
151
  end
156
152
  if options[:instances]
157
- instance_ids = parse_instance_id_list(options[:instances])
153
+ instance_ids = parse_instance_id_list(options[:instances], {}, false, true)
158
154
  return 1, "instances not found for #{options[:instances]}" if instance_ids.nil?
159
155
  params['instanceId'] = instance_ids
160
156
  end
161
157
  if options[:servers]
162
- server_ids = parse_server_id_list(options[:servers])
158
+ server_ids = parse_server_id_list(options[:servers], {}, false, true)
163
159
  return 1, "servers not found for #{options[:servers]}" if server_ids.nil?
164
160
  params['serverId'] = server_ids
165
161
  end
166
162
  if options[:users]
167
- user_ids = parse_user_id_list(options[:users])
163
+ user_ids = parse_user_id_list(options[:users], {}, false, true)
168
164
  return 1, "users not found for #{options[:users]}" if user_ids.nil?
169
165
  params['userId'] = user_ids
170
166
  end
171
167
  if options[:projects]
172
- project_ids = parse_project_id_list(options[:projects])
168
+ project_ids = parse_project_id_list(options[:projects], {}, false, true)
173
169
  return 1, "projects not found for #{options[:projects]}" if project_ids.nil?
174
170
  params['projectId'] = project_ids
175
171
  end
176
- params['rawData'] = true if options[:show_raw_data]
177
172
  params['refId'] = ref_ids unless ref_ids.empty?
178
173
  if options[:tags] && !options[:tags].empty?
179
174
  options[:tags].each do |k,v|
@@ -271,7 +266,7 @@ class Morpheus::Cli::InvoicesCommand
271
266
  columns += [
272
267
  {"ESTIMATE" => lambda {|it| format_boolean(it['estimate']) } },
273
268
  {"ACTIVE" => lambda {|it| format_boolean(it['active']) } },
274
- {"ITEMS" => lambda {|it| it['lineItems'].size rescue '' } },
269
+ {"ITEMS" => lambda {|it| (it['lineItemCount'] ? it['lineItemCount'] : it['lineItems'].size) rescue '' } },
275
270
  {"TAGS" => lambda {|it| (it['metadata'] || it['tags']) ? (it['metadata'] || it['tags']).collect {|m| "#{m['name']}: #{m['value']}" }.join(', ') : '' } },
276
271
  ]
277
272
  if show_projects
@@ -291,9 +286,6 @@ class Morpheus::Cli::InvoicesCommand
291
286
  {"CREATED" => lambda {|it| format_local_dt(it['dateCreated']) } },
292
287
  {"UPDATED" => lambda {|it| format_local_dt(it['lastUpdated']) } },
293
288
  ]
294
- if options[:show_raw_data]
295
- columns += [{"RAW DATA" => lambda {|it| truncate_string(it['rawData'].to_s, 10) } }]
296
- end
297
289
  unless options[:totals_only]
298
290
  print as_pretty_table(invoices, columns, options)
299
291
  print_results_pagination(json_response, {:label => "invoice", :n_label => "invoices"})
@@ -361,7 +353,6 @@ class Morpheus::Cli::InvoicesCommand
361
353
  options[:show_estimates] = true
362
354
  # options[:show_costs] = true
363
355
  options[:show_prices] = true
364
- # options[:show_raw_data] = true
365
356
  options[:max_line_items] = 10000
366
357
  end
367
358
  opts.on('--prices', '--prices', "Display prices: Total, Compute, Storage, Network, Extra" ) do
@@ -370,13 +361,6 @@ class Morpheus::Cli::InvoicesCommand
370
361
  opts.on('--estimates', '--estimates', "Display all estimated costs, from usage info: Compute, Storage, Network, Extra" ) do
371
362
  options[:show_estimates] = true
372
363
  end
373
- opts.on('--raw-data', '--raw-data', "Display Raw Data, the cost data from the cloud provider's API.") do |val|
374
- options[:show_raw_data] = true
375
- end
376
- opts.on('--pretty-raw-data', '--raw-data', "Display Raw Data that is a bit more pretty") do |val|
377
- options[:show_raw_data] = true
378
- options[:pretty_json] = true
379
- end
380
364
  opts.on('--no-line-items', '--no-line-items', "Do not display line items.") do |val|
381
365
  options[:hide_line_items] = true
382
366
  end
@@ -401,9 +385,6 @@ EOT
401
385
 
402
386
  def _get(id, options)
403
387
  params = {}
404
- if options[:show_raw_data]
405
- params['rawData'] = true
406
- end
407
388
  begin
408
389
  @invoices_interface.setopts(options)
409
390
  if options[:dry_run]
@@ -412,6 +393,9 @@ EOT
412
393
  end
413
394
  json_response = @invoices_interface.get(id, params)
414
395
  invoice = json_response['invoice']
396
+ if options[:hide_line_items]
397
+ json_response['invoice'].delete('lineItems') rescue nil
398
+ end
415
399
  render_result = render_with_format(json_response, options, 'invoice')
416
400
  return 0 if render_result
417
401
 
@@ -437,7 +421,7 @@ EOT
437
421
  "End" => lambda {|it| format_date(it['endDate']) },
438
422
  "Ref Start" => lambda {|it| format_dt(it['refStart']) },
439
423
  "Ref End" => lambda {|it| format_dt(it['refEnd']) },
440
- "Items" => lambda {|it| it['lineItems'].size rescue '' },
424
+ "Items" => lambda {|it| (it['lineItemCount'] ? it['lineItemCount'] : it['lineItems'].size) rescue '' },
441
425
  "Tags" => lambda {|it| (it['metadata'] || it['tags']) ? (it['metadata'] || it['tags']).collect {|m| "#{m['name']}: #{m['value']}" }.join(', ') : '' },
442
426
  "Project ID" => lambda {|it| it['project'] ? it['project']['id'] : '' },
443
427
  "Project Name" => lambda {|it| it['project'] ? it['project']['name'] : '' },
@@ -523,9 +507,6 @@ EOT
523
507
  {"CREATED" => lambda {|it| format_local_dt(it['dateCreated']) } },
524
508
  {"UPDATED" => lambda {|it| format_local_dt(it['lastUpdated']) } }
525
509
  ]
526
- if options[:show_raw_data]
527
- line_items_columns += [{"RAW DATA" => lambda {|it| truncate_string(it['rawData'].to_s, 10) } }]
528
- end
529
510
  print_h2 "Line Items"
530
511
  #max_line_items = options[:max_line_items] ? options[:max_line_items].to_i : 5
531
512
  paged_line_items = line_items #.first(max_line_items)
@@ -578,10 +559,7 @@ EOT
578
559
  end
579
560
  print as_pretty_table(cost_rows, cost_columns, options)
580
561
 
581
- if options[:show_raw_data]
582
- print_h2 "Raw Data"
583
- puts as_json(invoice['rawData'], {pretty_json:false}.merge(options))
584
- end
562
+
585
563
 
586
564
  print reset,"\n"
587
565
  return 0
@@ -658,37 +636,20 @@ Update an invoice.
658
636
  params = {}
659
637
  payload = {}
660
638
  optparse = Morpheus::Cli::OptionParser.new do |opts|
661
- opts.banner = subcommand_usage("[--daily] [--costing] [--current] [-c CLOUD]")
662
- opts.on( '--daily', "Refresh Daily Invoices" ) do
663
- payload[:daily] = true
664
- end
665
- opts.on( '--costing', "Refresh Costing Data" ) do
666
- payload[:costing] = true
667
- end
668
- opts.on( '--current', "Collect the most up to date costing data." ) do
669
- payload[:current] = true
670
- end
671
- opts.on( '--date DATE', String, "Date to collect costing for. By default the cost data is collected for the end of the previous period." ) do |val|
672
- payload[:date] = val.to_s
673
- end
674
- opts.on( '-c', '--cloud CLOUD', "Specify cloud(s) to refresh costing for." ) do |val|
639
+ opts.banner = subcommand_usage("[-c CLOUD]")
640
+ opts.on( '-c', '--clouds CLOUD', "Specify clouds to refresh costing for." ) do |val|
675
641
  payload[:clouds] ||= []
676
642
  payload[:clouds] << val
677
643
  end
678
- opts.on( '--all', "Refresh costing for all clouds." ) do
644
+ opts.on( '--all', "Refresh costing for all clouds. This can be used instead of --clouds" ) do
679
645
  payload[:all] = true
680
646
  end
681
- # opts.on( '-f', '--force', "Force Refresh" ) do
682
- # query_params[:force] = 'true'
683
- # end
647
+ opts.on( '--date DATE', String, "Date to collect costing for. By default the cost data is collected for the end of the previous job interval (hour or day)." ) do |val|
648
+ payload[:date] = val.to_s
649
+ end
684
650
  build_standard_update_options(opts, options, [:query, :auto_confirm])
685
651
  opts.footer = <<-EOT
686
- Refresh invoices.
687
- By default, nothing is changed.
688
- Include --daily to regenerate invoice records.
689
- Include --costing to refresh actual costing data.
690
- Include --current to refresh costing data for the actual current time.
691
- To get the latest invoice costing data, include --daily --costing --current --all
652
+ Refresh invoice costing data for the specified clouds.
692
653
  EOT
693
654
  end
694
655
  optparse.parse!(args)
@@ -699,17 +660,11 @@ EOT
699
660
  payload = options[:payload]
700
661
  end
701
662
  payload.deep_merge!(parse_passed_options(options))
702
- # --clouds
663
+ # --clouds lookup ID for name
703
664
  if payload[:clouds]
704
- payload[:clouds] = parse_id_list(payload[:clouds]).collect {|cloud_id|
705
- if cloud_id.to_s =~ /\A\d{1,}\Z/
706
- cloud_id
707
- else
708
- cloud = find_cloud_option(cloud_id)
709
- return 1 if cloud.nil?
710
- cloud['id']
711
- end
712
- }
665
+ cloud_ids = parse_cloud_id_list(payload[:clouds], {}, false, true)
666
+ return 1, "clouds not found for #{payload[:clouds]}" if cloud_ids.nil?
667
+ payload[:clouds] = cloud_ids
713
668
  end
714
669
  # are you sure?
715
670
  unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to refresh invoices?")
@@ -740,7 +695,6 @@ EOT
740
695
  options[:show_actual_costs] = true
741
696
  options[:show_costs] = true
742
697
  options[:show_prices] = true
743
- # options[:show_raw_data] = true
744
698
  end
745
699
  # opts.on('--actuals', '--actuals', "Display all actual costs: Compute, Storage, Network, Extra" ) do
746
700
  # options[:show_actual_costs] = true
@@ -829,9 +783,6 @@ EOT
829
783
  options[:tags][k] << (v || '')
830
784
  end
831
785
  end
832
- opts.on('--raw-data', '--raw-data', "Display Raw Data, the cost data from the cloud provider's API.") do |val|
833
- options[:show_raw_data] = true
834
- end
835
786
  opts.on('--totals', "View total costs and prices for all the invoices found.") do |val|
836
787
  params['includeTotals'] = true
837
788
  options[:show_invoice_totals] = true
@@ -857,36 +808,35 @@ EOT
857
808
  # construct params
858
809
  params.merge!(parse_list_options(options))
859
810
  if options[:clouds]
860
- cloud_ids = parse_cloud_id_list(options[:clouds])
811
+ cloud_ids = parse_cloud_id_list(options[:clouds], {}, false, true)
861
812
  return 1, "clouds not found for #{options[:clouds]}" if cloud_ids.nil?
862
813
  params['zoneId'] = cloud_ids
863
814
  end
864
815
  if options[:groups]
865
- group_ids = parse_group_id_list(options[:groups])
816
+ group_ids = parse_group_id_list(options[:groups], {}, false, true)
866
817
  return 1, "groups not found for #{options[:groups]}" if group_ids.nil?
867
818
  params['siteId'] = group_ids
868
819
  end
869
820
  if options[:instances]
870
- instance_ids = parse_instance_id_list(options[:instances])
821
+ instance_ids = parse_instance_id_list(options[:instances], {}, false, true)
871
822
  return 1, "instances not found for #{options[:instances]}" if instance_ids.nil?
872
823
  params['instanceId'] = instance_ids
873
824
  end
874
825
  if options[:servers]
875
- server_ids = parse_server_id_list(options[:servers])
826
+ server_ids = parse_server_id_list(options[:servers], {}, false, true)
876
827
  return 1, "servers not found for #{options[:servers]}" if server_ids.nil?
877
828
  params['serverId'] = server_ids
878
829
  end
879
830
  if options[:users]
880
- user_ids = parse_user_id_list(options[:users])
831
+ user_ids = parse_user_id_list(options[:users], {}, false, true)
881
832
  return 1, "users not found for #{options[:users]}" if user_ids.nil?
882
833
  params['userId'] = user_ids
883
834
  end
884
835
  if options[:projects]
885
- project_ids = parse_project_id_list(options[:projects])
836
+ project_ids = parse_project_id_list(options[:projects], {}, false, true)
886
837
  return 1, "projects not found for #{options[:projects]}" if project_ids.nil?
887
838
  params['projectId'] = project_ids
888
839
  end
889
- params['rawData'] = true if options[:show_raw_data]
890
840
  params['refId'] = ref_ids unless ref_ids.empty?
891
841
  if options[:tags] && !options[:tags].empty?
892
842
  options[:tags].each do |k,v|
@@ -944,9 +894,6 @@ EOT
944
894
  "UPDATED" => lambda {|it| format_local_dt(it['lastUpdated']) }
945
895
  ]
946
896
 
947
- if options[:show_raw_data]
948
- columns += [{"RAW DATA" => lambda {|it| truncate_string(it['rawData'].to_s, 10) } }]
949
- end
950
897
  # if options[:show_invoice_totals]
951
898
  # line_item_totals = json_response['lineItemTotals']
952
899
  # if line_item_totals
@@ -995,13 +942,6 @@ EOT
995
942
  options = {}
996
943
  optparse = Morpheus::Cli::OptionParser.new do |opts|
997
944
  opts.banner = subcommand_usage("[id]")
998
- opts.on('--raw-data', '--raw-data', "Display Raw Data, the cost data from the cloud provider's API.") do |val|
999
- options[:show_raw_data] = true
1000
- end
1001
- opts.on('--pretty-raw-data', '--raw-data', "Display Raw Data that is a bit more pretty") do |val|
1002
- options[:show_raw_data] = true
1003
- options[:pretty_json] = true
1004
- end
1005
945
  opts.on('--sigdig DIGITS', "Significant digits when rounding cost values for display as currency. Default is 2. eg. $3.50") do |val|
1006
946
  options[:sigdig] = val.to_i
1007
947
  end
@@ -1023,9 +963,6 @@ EOT
1023
963
 
1024
964
  def _get_line_item(id, options)
1025
965
  params = {}
1026
- if options[:show_raw_data]
1027
- params['rawData'] = true
1028
- end
1029
966
  @invoice_line_items_interface.setopts(options)
1030
967
  if options[:dry_run]
1031
968
  print_dry_run @invoice_line_items_interface.dry.get(id, params)
@@ -1063,11 +1000,6 @@ EOT
1063
1000
  }
1064
1001
  print_description_list(description_cols, line_item, options)
1065
1002
 
1066
- if options[:show_raw_data]
1067
- print_h2 "Raw Data"
1068
- puts as_json(line_item['rawData'], {pretty_json:false}.merge(options))
1069
- end
1070
-
1071
1003
  print reset,"\n"
1072
1004
  end
1073
1005
  return 0, nil
@@ -720,6 +720,7 @@ module Morpheus::Cli::PrintHelper
720
720
  columns.each do |column_def|
721
721
  # r << column_def.display_method.respond_to?(:call) ? column_def.display_method.call(row_data) : get_object_value(row_data, column_def.display_method)
722
722
  value = column_def.display_method.call(row_data)
723
+ value = JSON.fast_generate(value) if value.is_a?(Hash) || value.is_a?(Array)
723
724
  row << value
724
725
  end
725
726
  rows << row
@@ -802,6 +803,7 @@ module Morpheus::Cli::PrintHelper
802
803
  columns.each do |column_def|
803
804
  # r << column_def.display_method.respond_to?(:call) ? column_def.display_method.call(row_data) : get_object_value(row_data, column_def.display_method)
804
805
  value = column_def.display_method.call(row_data)
806
+ value = JSON.fast_generate(value) if value.is_a?(Hash) || value.is_a?(Array)
805
807
  row << value
806
808
  end
807
809
  rows << row
@@ -879,6 +881,7 @@ module Morpheus::Cli::PrintHelper
879
881
  label = label.upcase if ALL_LABELS_UPCASE
880
882
  # value = get_object_value(obj, column_def.display_method)
881
883
  value = column_def.display_method.call(obj)
884
+ value = JSON.fast_generate(value) if value.is_a?(Hash) || value.is_a?(Array)
882
885
  if label.size > max_label_width
883
886
  max_label_width = label.size
884
887
  end
@@ -42,7 +42,7 @@ class Morpheus::Cli::Projects
42
42
  opts.on('--owners [LIST]', Array, "Owner, comma separated list of usernames or IDs.") do |list|
43
43
  owner_ids = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
44
44
  end
45
- build_standard_get_options(opts, options)
45
+ build_standard_list_options(opts, options)
46
46
  opts.footer = <<-EOT
47
47
  List projects.
48
48
  EOT
@@ -1276,7 +1276,8 @@ EOT
1276
1276
 
1277
1277
  def format_remote_details(appliance, options={})
1278
1278
  columns = {
1279
- "Name" => :name,
1279
+ #"Name" => :name,
1280
+ "Name" => lambda {|it| it[:name].to_s },
1280
1281
  #"Name" => lambda {|it| it[:active] ? "#{it[:name]} #{bold}(current)#{reset}#{cyan}" : it[:name] },
1281
1282
  "URL" => lambda {|it| it[:url] || it[:host] },
1282
1283
  #"Status" => lambda {|it| format_appliance_status(it, cyan) },
@@ -427,7 +427,10 @@ class Morpheus::Cli::ServicePlanCommand
427
427
  # permissions
428
428
  if !options[:no_prompt]
429
429
  perms = prompt_permissions(options, ['plans', 'groupDefaults'])
430
- params['visibility'] = perms.delete('resourcePool')['visibility']
430
+ if perms['resourcePool'] && !perms['resourcePool']['visibility'].nil?
431
+ params['visibility'] = perms['resourcePool']['visibility']
432
+ end
433
+ perms.delete('resourcePool')
431
434
  params['permissions'] = perms
432
435
  end
433
436
  payload = {'servicePlan' => params}
@@ -6,6 +6,7 @@ class Morpheus::Cli::UserSourcesCommand
6
6
  include Morpheus::Cli::AccountsHelper
7
7
 
8
8
  set_command_name :'user-sources'
9
+ set_command_description "View and manage user identity sources"
9
10
 
10
11
  register_subcommands :list, :get, :add, :update, :remove
11
12
  register_subcommands :activate, :deactivate
@@ -43,49 +44,32 @@ class Morpheus::Cli::UserSourcesCommand
43
44
  account_id = val
44
45
  end
45
46
  opts.add_hidden_option('-a, --account') if opts.is_a?(Morpheus::Cli::OptionParser)
46
- # opts.on('--technology VALUE', String, "Filter by technology") do |val|
47
- # params['provisionType'] = val
48
- # end
49
- build_common_options(opts, options, [:list, :query, :json, :yaml, :csv, :fields, :dry_run, :remote])
50
- opts.footer = "List user sources."
47
+ build_standard_list_options(opts, options)
48
+ opts.footer = "List identity sources."
51
49
  end
52
50
  optparse.parse!(args)
53
51
  connect(options)
54
- # instance is required right now.
55
- # account_id = args[0] if !account_id
52
+ # verify_args!(args:args, optparse:optparse, count:0)
56
53
  if args.count > 0
57
- print_error Morpheus::Terminal.angry_prompt
58
- puts_error "wrong number of arguments, expected 1 and got (#{args.count}) #{args.inspect}\n#{optparse}"
59
- return 1
54
+ options[:phrase] = args.join(" ")
60
55
  end
61
- begin
62
- # construct payload
63
- if account_id
64
- account = find_account_by_name_or_id(account_id)
65
- return 1 if account.nil?
66
- account_id = account['id']
67
- end
68
-
69
- params.merge!(parse_list_options(options))
70
- @user_sources_interface.setopts(options)
71
- if options[:dry_run]
72
- print_dry_run @user_sources_interface.dry.list(account_id, params)
73
- return
74
- end
75
-
76
- json_response = @user_sources_interface.list(account_id, params)
77
- if options[:json]
78
- puts as_json(json_response, options, "userSources")
79
- return 0
80
- elsif options[:csv]
81
- puts records_as_csv(json_response['userSources'], options)
82
- return 0
83
- elsif options[:yaml]
84
- puts as_yaml(json_response, options, "userSources")
85
- return 0
56
+ if account_id
57
+ account = find_account_by_name_or_id(account_id)
58
+ if account.nil?
59
+ return 1, "Tenant not found for '#{account_id}'"
86
60
  end
87
- user_sources = json_response['userSources']
88
- title = "Morpheus User Sources"
61
+ account_id = account['id']
62
+ end
63
+ params.merge!(parse_list_options(options))
64
+ @user_sources_interface.setopts(options)
65
+ if options[:dry_run]
66
+ print_dry_run @user_sources_interface.dry.list(account_id, params)
67
+ return 0, nil
68
+ end
69
+ json_response = @user_sources_interface.list(account_id, params)
70
+ render_response(json_response, options, "userSources") do
71
+ user_sources = json_response["userSources"]
72
+ title = "Morpheus Identity Sources"
89
73
  subtitles = []
90
74
  if account
91
75
  subtitles << "Tenant: #{account['name']}".strip
@@ -93,82 +77,77 @@ class Morpheus::Cli::UserSourcesCommand
93
77
  subtitles += parse_list_subtitles(options)
94
78
  print_h1 title, subtitles
95
79
  if user_sources.empty?
96
- if account
97
- print cyan,"No user sources found for account #{account['name']}.",reset,"\n"
98
- else
99
- print cyan,"No user sources found.",reset,"\n"
100
- end
80
+ print cyan,"No identity sources found.",reset,"\n"
101
81
  else
102
82
  print_user_sources_table(user_sources, options)
103
- print_results_pagination(json_response, {:label => "user source", :n_label => "user sources"})
83
+ print_results_pagination(json_response)
104
84
  end
105
85
  print reset,"\n"
106
- rescue RestClient::Exception => e
107
- print_rest_exception(e, options)
108
- return 1
109
86
  end
87
+ return 0, nil
88
+
110
89
  end
111
90
 
112
91
  def get(args)
113
- options = {}
114
92
  params = {}
93
+ options = {}
115
94
  optparse = Morpheus::Cli::OptionParser.new do |opts|
116
95
  opts.banner = subcommand_usage("[name]")
117
- build_common_options(opts, options, [:json, :yaml, :csv, :fields, :dry_run, :remote])
118
- opts.footer = "Get details about an user source." + "\n" +
119
- "[name] is required. This is the name or id of an user source."
96
+ # opts.on( '-c', '--config', "Display raw config only. Default is YAML. Combine with -j for JSON instead." ) do
97
+ # options[:show_config] = true
98
+ # end
99
+ # opts.on('--no-config', "Do not display Config YAML." ) do
100
+ # options[:no_config] = true
101
+ # end
102
+ build_standard_get_options(opts, options)
103
+ opts.footer = <<-EOT
104
+ Get details about an identity source.
105
+ [name] is required. This is the name or id of an identity source.
106
+ EOT
120
107
  end
121
108
  optparse.parse!(args)
109
+ verify_args!(args:args, optparse:optparse, min:1)
122
110
  connect(options)
123
- if args.count != 1
124
- print_error Morpheus::Terminal.angry_prompt
125
- puts_error "wrong number of arguments, expected 1 and got (#{args.count}) #{args.inspect}\n#{optparse}"
126
- return 1
111
+ id_list = parse_id_list(args)
112
+ return run_command_for_each_arg(id_list) do |arg|
113
+ _get(arg, params, options)
127
114
  end
115
+ end
116
+
117
+ def _get(user_source_id, params, options)
128
118
  account_id = nil
129
119
  account = nil
130
- user_source_id = args[0]
131
120
  # account_id = args[0]
132
121
  # account = find_account_by_name_or_id(account_id)
133
122
  # exit 1 if account.nil?
134
123
  # account_id = account['id']
135
124
  # user_source_id = args[1]
136
- begin
137
- @user_sources_interface.setopts(options)
138
- if options[:dry_run]
139
- if user_source_id.to_s =~ /\A\d{1,}\Z/
140
- print_dry_run @user_sources_interface.dry.get(account_id, user_source_id.to_i)
141
- else
142
- print_dry_run @user_sources_interface.dry.list(account_id, {name:user_source_id})
143
- end
144
- return
145
- end
146
- user_source = find_user_source_by_name_or_id(account_id, user_source_id)
147
- if user_source.nil?
148
- return 1
149
- end
150
- # fetch by id to get config too
151
- json_response = nil
125
+
126
+ @user_sources_interface.setopts(options)
127
+ if options[:dry_run]
152
128
  if user_source_id.to_s =~ /\A\d{1,}\Z/
153
- json_response = {'userSource' => user_source}
129
+ print_dry_run @user_sources_interface.dry.get(account_id, user_source_id.to_i)
154
130
  else
155
- json_response = @user_sources_interface.get(account_id, user_source['id'])
156
- user_source = json_response['userSource']
131
+ print_dry_run @user_sources_interface.dry.list(account_id, {name:user_source_id})
157
132
  end
133
+ return
134
+ end
135
+ user_source = find_user_source_by_name_or_id(account_id, user_source_id)
136
+ if user_source.nil?
137
+ return 1
138
+ end
139
+ # fetch by id to get config too
140
+ json_response = nil
141
+ if user_source_id.to_s =~ /\A\d{1,}\Z/
142
+ json_response = {'userSource' => user_source}
143
+ else
144
+ json_response = @user_sources_interface.get(account_id, user_source['id'])
145
+ user_source = json_response['userSource']
146
+ end
158
147
 
159
- #user_source = json_response['userSource']
160
- if options[:json]
161
- puts as_json(json_response, options, "userSource")
162
- return 0
163
- elsif options[:yaml]
164
- puts as_yaml(json_response, options, "userSource")
165
- return 0
166
- elsif options[:csv]
167
- puts records_as_csv([json_response['userSource']], options)
168
- return 0
169
- end
170
-
171
- print_h1 "User Source Details"
148
+ #user_source = json_response['userSource']
149
+ render_response(json_response, options, "userSource") do
150
+ print_h1 "Identity Source Details"
172
151
  print cyan
173
152
  description_cols = {
174
153
  "ID" => lambda {|it| it['id'] },
@@ -187,7 +166,7 @@ class Morpheus::Cli::UserSourcesCommand
187
166
 
188
167
  # show config settings...
189
168
  user_source_config = user_source['config']
190
- print_h2 "User Source Config (#{user_source['type']})"
169
+ print_h2 "Configuration"
191
170
  if user_source_config
192
171
  columns = user_source_config.keys #.sort
193
172
  print_description_list(columns, user_source_config)
@@ -208,15 +187,27 @@ class Morpheus::Cli::UserSourcesCommand
208
187
  {"SOURCE ROLE FQN" => lambda {|it| it['sourceRoleFqn'] } },
209
188
  ]
210
189
  print as_pretty_table(role_mappings, role_mapping_columns)
190
+ else
191
+ print cyan,"No role mappings found for this identity source.","\n",reset
192
+ end
193
+
194
+ provider_settings = user_source['providerSettings']
195
+ if provider_settings && !provider_settings.empty?
196
+ print_h2 "Provider Settings"
197
+ print_description_list({
198
+ "Entity ID" => lambda {|it| it['entityId'] },
199
+ "ACS URL" => lambda {|it| it['acsUrl'] }
200
+ }, provider_settings)
201
+ print_h2 "SP Metadata"
202
+ print cyan
203
+ print provider_settings['spMetadata']
211
204
  print "\n",reset
212
205
  else
213
- print cyan,"No role mappings found for this user source.","\n",reset
206
+ # print cyan,"No provider settings found.","\n",reset
214
207
  end
215
- return 0
216
- rescue RestClient::Exception => e
217
- print_rest_exception(e, options)
218
- return 1
208
+ print "\n",reset
219
209
  end
210
+ return 0, nil
220
211
  end
221
212
 
222
213
  def add(args)
@@ -229,17 +220,17 @@ class Morpheus::Cli::UserSourcesCommand
229
220
  default_role_id = nil
230
221
  optparse = Morpheus::Cli::OptionParser.new do|opts|
231
222
  opts.banner = subcommand_usage("[account] [name]")
232
- opts.on( '--tenant TENANT', String, "Tenant Name or ID the user source will belong to, default is your own." ) do |val|
223
+ opts.on( '--tenant TENANT', String, "Tenant Name or ID the identity source will belong to, default is your own." ) do |val|
233
224
  account_id = val
234
225
  end
235
- opts.on( '-a', '--account ACCOUNT', "Tenant Name or ID the user source will belong to, default is your own." ) do |val|
226
+ opts.on( '-a', '--account ACCOUNT', "Tenant Name or ID the identity source will belong to, default is your own." ) do |val|
236
227
  account_id = val
237
228
  end
238
229
  opts.add_hidden_option('-a, --account') if opts.is_a?(Morpheus::Cli::OptionParser)
239
- opts.on('--type CODE', String, "User Source Type") do |val|
230
+ opts.on('--type CODE', String, "Identity Source Type") do |val|
240
231
  type_code = val
241
232
  end
242
- opts.on('--name VALUE', String, "Name for this user source") do |val|
233
+ opts.on('--name VALUE', String, "Name for this identity source") do |val|
243
234
  params['name'] = val
244
235
  end
245
236
  opts.on('--description VALUE', String, "Description") do |val|
@@ -276,7 +267,7 @@ class Morpheus::Cli::UserSourcesCommand
276
267
  end
277
268
  #build_option_type_options(opts, options, add_user_source_option_types())
278
269
  build_standard_add_options(opts, options)
279
- opts.footer = "Create a new user source." + "\n" +
270
+ opts.footer = "Create a new identity source." + "\n" +
280
271
  "[account] is required. This is the name or id of an account."
281
272
  end
282
273
  optparse.parse!(args)
@@ -313,10 +304,10 @@ class Morpheus::Cli::UserSourcesCommand
313
304
  else
314
305
  payload.deep_merge!({'userSource' => parse_passed_options(options)})
315
306
 
316
- # User Source Type
307
+ # Identity Source Type
317
308
  user_source_types = @user_sources_interface.list_types({userSelectable: true})['userSourceTypes']
318
309
  if user_source_types.empty?
319
- print_red_alert "No available User Source Types found"
310
+ print_red_alert "No available Identity Source Types found"
320
311
  return 1
321
312
  end
322
313
  user_source_type = nil
@@ -328,7 +319,7 @@ class Morpheus::Cli::UserSourcesCommand
328
319
  user_source_type = user_source_types.find { |it| it['type'] == type_code }
329
320
 
330
321
  if user_source_type.nil?
331
- print_red_alert "User Source Type not found for '#{type_code}'"
322
+ print_red_alert "Identity Source Type not found for '#{type_code}'"
332
323
  return 1
333
324
  end
334
325
 
@@ -393,7 +384,7 @@ class Morpheus::Cli::UserSourcesCommand
393
384
  return 0
394
385
  end
395
386
  user_source = json_response['userSource']
396
- print_green_success "Added User Source #{user_source['name']}"
387
+ print_green_success "Added Identity Source #{user_source['name']}"
397
388
  get([user_source['id']] + (options[:remote] ? ["-r",options[:remote]] : []))
398
389
  return 0
399
390
  end
@@ -406,7 +397,7 @@ class Morpheus::Cli::UserSourcesCommand
406
397
  role_mapping_names = nil
407
398
  optparse = Morpheus::Cli::OptionParser.new do|opts|
408
399
  opts.banner = subcommand_usage("[name] [options]")
409
- opts.on('--name VALUE', String, "Name for this user source") do |val|
400
+ opts.on('--name VALUE', String, "Name for this identity source") do |val|
410
401
  params['name'] = val
411
402
  end
412
403
  opts.on('--description VALUE', String, "Description") do |val|
@@ -438,8 +429,8 @@ class Morpheus::Cli::UserSourcesCommand
438
429
  end
439
430
  end
440
431
  build_standard_update_options(opts, options)
441
- opts.footer = "Update a user source." + "\n" +
442
- "[name] is required. This is the name or id of a user source."
432
+ opts.footer = "Update an identity source." + "\n" +
433
+ "[name] is required. This is the name or id of an identity source."
443
434
  end
444
435
  optparse.parse!(args)
445
436
  if args.count < 1
@@ -494,7 +485,7 @@ class Morpheus::Cli::UserSourcesCommand
494
485
  return
495
486
  end
496
487
 
497
- print_green_success "Updated User Source #{params['name'] || user_source['name']}"
488
+ print_green_success "Updated Identity Source #{params['name'] || user_source['name']}"
498
489
  get([user_source['id']] + (options[:remote] ? ["-r",options[:remote]] : []))
499
490
  rescue RestClient::Exception => e
500
491
  print_rest_exception(e, options)
@@ -511,8 +502,8 @@ class Morpheus::Cli::UserSourcesCommand
511
502
  optparse = Morpheus::Cli::OptionParser.new do|opts|
512
503
  opts.banner = subcommand_usage("[name]")
513
504
  build_common_options(opts, options, [:options, :json, :dry_run, :remote])
514
- opts.footer = "Activate a user source." + "\n" +
515
- "[name] is required. This is the name or id of a user source."
505
+ opts.footer = "Activate an identity source." + "\n" +
506
+ "[name] is required. This is the name or id of an identity source."
516
507
  end
517
508
  optparse.parse!(args)
518
509
  if args.count < 1
@@ -544,7 +535,7 @@ class Morpheus::Cli::UserSourcesCommand
544
535
  return
545
536
  end
546
537
 
547
- print_green_success "Activated User Source #{user_source['name']}"
538
+ print_green_success "Activated Identity Source #{user_source['name']}"
548
539
  get([user_source['id']] + (options[:remote] ? ["-r",options[:remote]] : []))
549
540
  rescue RestClient::Exception => e
550
541
  print_rest_exception(e, options)
@@ -561,8 +552,8 @@ class Morpheus::Cli::UserSourcesCommand
561
552
  optparse = Morpheus::Cli::OptionParser.new do|opts|
562
553
  opts.banner = subcommand_usage("[name]")
563
554
  build_common_options(opts, options, [:options, :json, :dry_run, :remote])
564
- opts.footer = "Deactivate a user source." + "\n" +
565
- "[name] is required. This is the name or id of a user source."
555
+ opts.footer = "Deactivate an identity source." + "\n" +
556
+ "[name] is required. This is the name or id of an identity source."
566
557
  end
567
558
  optparse.parse!(args)
568
559
  if args.count < 1
@@ -594,7 +585,7 @@ class Morpheus::Cli::UserSourcesCommand
594
585
  return
595
586
  end
596
587
 
597
- print_green_success "Activated User Source #{user_source['name']}"
588
+ print_green_success "Activated Identity Source #{user_source['name']}"
598
589
  get([user_source['id']] + (options[:remote] ? ["-r",options[:remote]] : []))
599
590
  rescue RestClient::Exception => e
600
591
  print_rest_exception(e, options)
@@ -608,12 +599,12 @@ class Morpheus::Cli::UserSourcesCommand
608
599
  account_id = nil
609
600
  optparse = Morpheus::Cli::OptionParser.new do|opts|
610
601
  opts.banner = subcommand_usage("[name]")
611
- opts.on('--subdomain VALUE', String, "New subdomain for this user source") do |val|
602
+ opts.on('--subdomain VALUE', String, "New subdomain for this identity source") do |val|
612
603
  params['subdomain'] = (val == 'null') ? nil : val
613
604
  end
614
605
  build_common_options(opts, options, [:options, :json, :dry_run, :remote])
615
- opts.footer = "Update subdomain for a user source." + "\n" +
616
- "[name] is required. This is the name or id of a user source."
606
+ opts.footer = "Update subdomain for an identity source." + "\n" +
607
+ "[name] is required. This is the name or id of an identity source."
617
608
  end
618
609
  optparse.parse!(args)
619
610
  if args.count < 1
@@ -645,8 +636,8 @@ class Morpheus::Cli::UserSourcesCommand
645
636
  puts JSON.pretty_generate(json_response)
646
637
  return
647
638
  end
648
- # JD: uhh this updates the account too, it cannot be set per user source ...yet
649
- print_green_success "Updated User Source #{user_source['name']} subdomain to '#{payload['subdomain']}'"
639
+ # JD: uhh this updates the account too, it cannot be set per identity source ...yet
640
+ print_green_success "Updated Identity Source #{user_source['name']} subdomain to '#{payload['subdomain']}'"
650
641
  get([user_source['id']] + (options[:remote] ? ["-r",options[:remote]] : []))
651
642
  rescue RestClient::Exception => e
652
643
  print_rest_exception(e, options)
@@ -672,7 +663,7 @@ class Morpheus::Cli::UserSourcesCommand
672
663
  user_source = find_user_source_by_name_or_id(nil, args[0])
673
664
  exit 1 if user_source.nil?
674
665
 
675
- unless Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the user source #{user_source['name']}?", options)
666
+ unless Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the identity source #{user_source['name']}?", options)
676
667
  exit
677
668
  end
678
669
  @user_sources_interface.setopts(options)
@@ -687,7 +678,7 @@ class Morpheus::Cli::UserSourcesCommand
687
678
  return
688
679
  end
689
680
 
690
- print_green_success "Removed User Source #{user_source['name']}"
681
+ print_green_success "Removed Identity Source #{user_source['name']}"
691
682
  #list([])
692
683
  rescue RestClient::Exception => e
693
684
  print_rest_exception(e, options)
@@ -703,7 +694,7 @@ class Morpheus::Cli::UserSourcesCommand
703
694
  optparse = Morpheus::Cli::OptionParser.new do |opts|
704
695
  opts.banner = subcommand_usage()
705
696
  build_common_options(opts, options, [:list, :json, :yaml, :csv, :fields, :dry_run, :remote])
706
- opts.footer = "List user source types."
697
+ opts.footer = "List identity source types."
707
698
  end
708
699
  optparse.parse!(args)
709
700
  connect(options)
@@ -735,7 +726,7 @@ class Morpheus::Cli::UserSourcesCommand
735
726
  return 0
736
727
  end
737
728
  user_source_types = json_response['userSourceTypes']
738
- title = "Morpheus User Source Types"
729
+ title = "Morpheus Identity Source Types"
739
730
  subtitles = []
740
731
  subtitles += parse_list_subtitles(options)
741
732
  print_h1 title, subtitles
@@ -760,7 +751,7 @@ class Morpheus::Cli::UserSourcesCommand
760
751
  optparse = Morpheus::Cli::OptionParser.new do |opts|
761
752
  opts.banner = subcommand_usage("[type]")
762
753
  build_common_options(opts, options, [:json, :yaml, :csv, :fields, :dry_run, :remote])
763
- opts.footer = "Get details about a user source type." + "\n" +
754
+ opts.footer = "Get details about an identity source type." + "\n" +
764
755
  "[type] is required. This is the type identifier."
765
756
  end
766
757
  optparse.parse!(args)
@@ -776,13 +767,6 @@ class Morpheus::Cli::UserSourcesCommand
776
767
  begin
777
768
  user_source_type_id = args[0]
778
769
 
779
- # all_user_source_types = @user_sources_interface.dry.list_types({})['userSourceTypes']
780
- # user_source_type = all_user_source_types.find {|it| it['type'] == user_source_type_id }
781
- # if !user_source_type
782
- # print_red_alert "User Source Type not found by id '#{user_source_type_id}'"
783
- # return 1
784
- # end
785
-
786
770
  # construct payload
787
771
  @user_sources_interface.setopts(options)
788
772
  if options[:dry_run]
@@ -801,7 +785,7 @@ class Morpheus::Cli::UserSourcesCommand
801
785
  puts records_as_csv([user_source_type], options)
802
786
  return 0
803
787
  end
804
- title = "User Source Type"
788
+ title = "Identity Source Type"
805
789
  subtitles = []
806
790
  print_h1 title, subtitles
807
791
  print cyan
@@ -860,7 +844,7 @@ class Morpheus::Cli::UserSourcesCommand
860
844
  return json_response['userSource']
861
845
  rescue RestClient::Exception => e
862
846
  if e.response && e.response.code == 404
863
- print_red_alert "User Source not found by id #{id}"
847
+ print_red_alert "Identity Source not found by id #{id}"
864
848
  else
865
849
  raise e
866
850
  end
@@ -870,10 +854,10 @@ class Morpheus::Cli::UserSourcesCommand
870
854
  def find_user_source_by_name(account_id, name)
871
855
  user_sources = @user_sources_interface.list(account_id, {name: name.to_s})['userSources']
872
856
  if user_sources.empty?
873
- print_red_alert "User Source not found by name #{name}"
857
+ print_red_alert "Identity Source not found by name #{name}"
874
858
  return nil
875
859
  elsif user_sources.size > 1
876
- print_red_alert "#{user_sources.size} user sources found by name #{name}"
860
+ print_red_alert "#{user_sources.size} identity sources found by name #{name}"
877
861
  print_user_sources_table(user_sources, {color: red})
878
862
  print_red_alert "Try using ID instead"
879
863
  print reset,"\n"
@@ -979,7 +963,7 @@ class Morpheus::Cli::UserSourcesCommand
979
963
  {'fieldContext' => 'config', 'fieldName' => 'encryptionKey', 'type' => 'text', 'fieldLabel' => 'Encryption Key', 'required' => true, 'description' => ''},
980
964
  ]
981
965
  else
982
- print "unknown user source type: #{type_code}"
966
+ print "unknown identity source type: #{type_code}"
983
967
  []
984
968
  end
985
969
  end