Class: Morpheus::Cli::Roles

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

Instance Attribute Summary

Attributes included from CliCommand

#no_prompt

Instance Method Summary collapse

Methods included from WhoamiHelper

#current_account, #current_user, #current_user_permissions, included, #is_master_account, #load_whoami

Methods included from ProvisioningHelper

#accounts_interface, #add_perms_options, #api_client, #apps_interface, #cloud_datastores_interface, #clouds_interface, #datastores_interface, #find_app_by_id, #find_app_by_name, #find_app_by_name_or_id, #find_cloud_by_id_for_provisioning, #find_cloud_by_name_for_provisioning, #find_cloud_by_name_or_id_for_provisioning, #find_cloud_resource_pool_by_name_or_id, #find_group_by_id_for_provisioning, #find_group_by_name_for_provisioning, #find_group_by_name_or_id_for_provisioning, #find_host_by_id, #find_host_by_name, #find_host_by_name_or_id, #find_instance_by_id, #find_instance_by_name, #find_instance_by_name_or_id, #find_instance_type_by_code, #find_instance_type_by_id, #find_instance_type_by_name, #find_instance_type_by_name_or_id, #find_instance_type_layout_by_id, #find_server_by_id, #find_server_by_name, #find_server_by_name_or_id, #find_workflow_by_id, #find_workflow_by_name, #find_workflow_by_name_or_id, #format_app_status, #format_blueprint_type, #format_container_connection_string, #format_container_status, #format_instance_connection_string, #format_instance_container_display_name, #format_instance_status, #format_metadata, #format_snapshot_status, #get_available_accounts, #get_available_clouds, #get_available_environments, #get_available_groups, #get_available_plans, #get_provision_type_for_zone_type, #get_static_environments, included, #instance_type_layouts_interface, #instance_types_interface, #instances_interface, #load_balance_protocols_dropdown, #options_interface, #parse_blueprint_type, #parse_host_id_list, #parse_instance_id_list, #parse_metadata, #parse_resource_id_list, #parse_server_id_list, #print_permissions, #prompt_evars, #prompt_exposed_ports, #prompt_instance_load_balancer, #prompt_metadata, #prompt_network_interfaces, #prompt_new_instance, #prompt_permissions, #prompt_permissions_v2, #prompt_resize_volumes, #prompt_security_groups, #prompt_service_plan_options, #prompt_volumes, #provision_types_interface, #reject_service_plan_option_types, #servers_interface

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

Instance Method Details

#_get(id, options = {}) ⇒ Object



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
317
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
420
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
# File 'lib/morpheus/cli/commands/roles.rb', line 165

def _get(id, options={})
  args = [id] # heh
  params = {}
   = (options)
   =  ? ['id'] : nil

  params.merge!(parse_query_options(options))
  params['includeDefaultAccess'] = true if options[:include_default_access]
  @roles_interface.setopts(options)
  if options[:dry_run]
    if args[0].to_s =~ /\A\d{1,}\Z/
      print_dry_run @roles_interface.dry.get(, args[0].to_i)
    else
      print_dry_run @roles_interface.dry.list(, {name: args[0]})
    end
    return
  end

  load_whoami()
  json_response = nil
  role = nil
  if args[0].to_s =~ /\A\d{1,}\Z/
    json_response = @roles_interface.get(, args[0].to_i, params)
    role = json_response['role']
  else
    role = find_role_by_name_or_id(, args[0])
    exit 1 if role.nil?
    # refetch from show action, argh
    json_response = @roles_interface.get(, role['id'], params)
    role = json_response['role']
  end

  render_response(json_response, options, 'role') do

    print cyan
    print_h1 "Role Details", options
    print cyan
    columns = @is_master_account ? role_column_definitions : subtenant_role_column_definitions
    print_description_list(columns, role, options)

    print_h2 "Permissions", options
    print cyan
    permissions = json_response['featurePermissions'] || role['permissions'] || []
    if options[:include_feature_access] || options[:include_all_access]
      rows = permissions.collect do |it|
        {
          code: it['code'],
          name: it['name'],
          category: it['subCategory'].to_s.titleize,
          access: format_access_string(it['access']),
        }
      end
      if options[:sort]
        rows.sort! {|a,b| a[options[:sort]] <=> b[options[:sort]] }
      else
        rows.sort! {|a,b| [a[:category],a[:name],a[:code]] <=> [b[:category],b[:name],b[:code]] }
      end
      if options[:direction] == 'desc'
        rows.reverse!
      end
      if options[:phrase]
        phrase_regexp = /#{Regexp.escape(options[:phrase])}/i
        rows = rows.select {|row| row[:code].to_s =~ phrase_regexp || row[:name].to_s =~ phrase_regexp }
      end
      print as_pretty_table(rows, [:category, :name, :code, :access], options)
      # print reset,"\n"
    else
      print cyan,"Use --feature-access to list feature access","\n"
    end

    has_group_access = true
    has_cloud_access = true
    print_h2 "Default Access", options
    global_access_columns = {
      "Groups" => lambda {|it| get_access_string(it['globalSiteAccess']) },
      "Clouds" => lambda {|it| get_access_string(it['globalZoneAccess']) },
      "Instance Types" => lambda {|it| get_access_string(it['globalInstanceTypeAccess']) },
      "Blueprints" => lambda {|it| get_access_string(it['globalAppTemplateAccess'] || it['globalBlueprintAccess']) },
      "Personas" => lambda {|it| get_access_string(it['globalPersonaAccess']) },
      "Report Types" => lambda {|it| get_access_string(it['globalReportTypeAccess']) },
      "Catalog Item Types" => lambda {|it| get_access_string(it['globalCatalogItemTypeAccess']) },
      "VDI Pools" => lambda {|it| get_access_string(it['globalVdiPoolAccess']) },
      "Workflows" => lambda {|it| get_access_string(it['globalTaskSetAccess']) },
      "Tasks" => lambda {|it| get_access_string(it['globalTaskAccess']) },
    }

    if role['roleType'].to_s.downcase == 'account'
      global_access_columns.delete("Groups")
      has_group_access = false
    else
      global_access_columns.delete("Clouds")
      has_cloud_access = false
    end

    print as_pretty_table([json_response], global_access_columns, options)

    if has_group_access
      #print_h2 "Group Access: #{get_access_string(json_response['globalSiteAccess'])}", options
      print cyan
      print_h2 "Group Access", options
      if options[:include_group_access] || options[:include_all_access]
        rows = json_response['sites'].collect do |it|
          {
            name: it['name'],
            access: format_access_string(it['access'], ["none","read","full"]),
          }
        end
        if !options[:include_default_access]
          rows = rows.select {|row| row[:access] && row[:access] != 'default '}
        end
        print as_pretty_table(rows, [:name, :access], options)
      else
        print cyan,"Use -g, --group-access to list custom access","\n"
      end
    end

    if has_cloud_access
      print cyan
      #puts "Cloud Access: #{get_access_string(json_response['globalZoneAccess'])}"
      #print "\n"
      if json_response['sites'].find{|it| it['access'] && it['access'] != 'default'}
        print_h2 "Cloud Access", options
        if options[:include_cloud_access] || options[:include_all_access]
          rows = json_response['zones'].collect do |it|
            {
              name: it['name'],
              access: format_access_string(it['access'], ["none","read","full"]),
            }
          end
          if !options[:include_default_access]
            rows = rows.select {|row| row[:access] && row[:access] != 'default '}
          end
          print as_pretty_table(rows, [:name, :access], options)
        else
          print cyan,"Use -c, --cloud-access to list custom access","\n"
        end
        # print reset,"\n"
      else
        # print "\n"
        # print cyan,bold,"Cloud Access: #{get_access_string(json_response['globalZoneAccess'])}",reset,"\n"
      end
    end

    print cyan
    # puts "Instance Type Access: #{get_access_string(json_response['globalInstanceTypeAccess'])}"
    # print "\n"
    instance_type_global_access = json_response['globalInstanceTypeAccess']
    instance_type_permissions = role['instanceTypes'] ? role['instanceTypes'] : (json_response['instanceTypePermissions'] || [])

    # if have any custom, then we want to show the flag indicator
    # if including, show

    if options[:include_instance_type_access] || options[:include_all_access]
      print_h2 "Instance Type Access", options
      rows = instance_type_permissions.collect do |it|
        {
          name: it['name'],
          access: format_access_string(it['access'], ["none","read","full"]),
        }
      end
      if !options[:include_default_access]
        rows = rows.select {|row| row[:access] && row[:access] != 'default '}
      end
      print as_pretty_table(rows, [:name, :access], options)
    elsif instance_type_permissions.find {|it| it['access'] && it['access'] != 'default'}
      print_h2 "Instance Type Access", options
      print cyan,"Use -i, --instance-type-access to list custom access","\n"
    end

    blueprint_global_access = json_response['globalAppTemplateAccess'] || json_response['globalBlueprintAccess']
    blueprint_permissions = (role['appTemplates'] || role['blueprints']) ? (role['appTemplates'] || role['blueprints']) : (json_response['appTemplatePermissions'] || json_response['blueprintPermissions'] || [])
    print cyan
    if options[:include_blueprint_access] || options[:include_all_access]
      print_h2 "Blueprint Access", options
      rows = blueprint_permissions.collect do |it|
        {
          name: it['name'],
          access: format_access_string(it['access'], ["none","read","full"]),
        }
      end
      print as_pretty_table(rows, [:name, :access], options)
    elsif blueprint_permissions.find {|it| it['access'] && it['access'] != 'default'}
      print_h2 "Blueprint Access", options
      print cyan,"Use -b, --blueprint-access to list custom access","\n"
    end

    catalog_item_type_global_access = json_response['globalCatalogItemTypeAccess']
    catalog_item_type_permissions = role['catalogItemTypes'] ? role['catalogItemTypes'] : (json_response['catalogItemTypePermissions'] || [])
    print cyan
    if options[:include_catalog_item_type_access] || options[:include_all_access]
      print_h2 "Catalog Item Type Access", options
      rows = catalog_item_type_permissions.collect do |it|
        {
          name: it['name'],
          access: format_access_string(it['access'], ["none","read","full"]),
        }
      end
      if !options[:include_default_access]
        rows = rows.select {|row| row[:access] && row[:access] != 'default '}
      end
      print as_pretty_table(rows, [:name, :access], options)
    elsif catalog_item_type_permissions.find {|it| it['access'] && it['access'] != 'default'}
      print_h2 "Catalog Item Type Access", options
      print cyan,"Use --catalog-item-type-access to list access","\n"
    end

    persona_global_access = json_response['globalPersonaAccess']
    persona_permissions = role['personas'] ? role['personas'] : (json_response['personaPermissions'] || [])
    print cyan
    if options[:include_persona_access] || options[:include_all_access]
      print_h2 "Persona Access", options
      rows = persona_permissions.collect do |it|
        {
          name: it['name'],
          access: format_access_string(it['access'], ["none","full"]),
        }
      end
      print as_pretty_table(rows, [:name, :access], options)
    elsif persona_permissions.find {|it| it['access'] && it['access'] != 'default'}
      print_h2 "Persona Access", options
      print cyan,"Use --persona-access to list access","\n"
    end

    vdi_pool_global_access = json_response['globalVdiPoolAccess']
    vdi_pool_permissions = role['vdiPools'] ? role['vdiPools'] : (json_response['vdiPoolPermissions'] || [])
    print cyan
    if options[:include_vdi_pool_access] || options[:include_all_access]
      print_h2 "VDI Pool Access", options
      rows = vdi_pool_permissions.collect do |it|
        {
          name: it['name'],
          access: format_access_string(it['access'], ["none","full"]),
        }
      end
      if !options[:include_default_access]
        rows = rows.select {|row| row[:access] && row[:access] != 'default '}
      end
      print as_pretty_table(rows, [:name, :access], options)
    elsif vdi_pool_permissions.find {|it| it['access'] && it['access'] != 'default'}
      print_h2 "VDI Pool Access", options
      print cyan,"Use --vdi-pool-access to list custom access","\n"
    end

    report_type_global_access = json_response['globalReportTypeAccess']
    report_type_permissions = role['reportTypes'] ? role['reportTypes'] : (json_response['reportTypePermissions'] || [])
    print cyan
    if options[:include_report_type_access] || options[:include_all_access]
      print_h2 "Report Type Access", options
      rows = report_type_permissions.collect do |it|
        {
          name: it['name'],
          access: format_access_string(it['access'], ["none","full"]),
        }
      end
      if !options[:include_default_access]
        rows = rows.select {|row| row[:access] && row[:access] != 'default '}
      end
      print as_pretty_table(rows, [:name, :access], options)
    elsif report_type_permissions.find {|it| it['access'] && it['access'] != 'default'}
      print_h2 "Report Type Access", options
      print cyan,"Use --report-type-access to list custom access","\n"
    end

    task_global_access = json_response['globalTaskAccess']
    task_permissions = role['tasks'] ? role['tasks'] : (json_response['taskPermissions'] || [])
    print cyan
    if options[:include_task_access] || options[:include_all_access]
      print_h2 "Task Access", options
      rows = task_permissions.collect do |it|
        {
          name: it['name'],
          access: format_access_string(it['access'], ["none","full"]),
        }
      end
      if !options[:include_default_access]
        rows = rows.select {|row| row[:access] && row[:access] != 'default '}
      end
      print as_pretty_table(rows, [:name, :access], options)
    elsif task_permissions.find {|it| it['access'] && it['access'] != 'default'}
      print_h2 "Task Access", options
      print cyan,"Use --task-access to list custom access","\n"
    end

    workflow_global_access = json_response['globalTaskSetAccess']
    workflow_permissions = role['taskSets'] ? role['taskSets'] : (json_response['taskSetPermissions'] || [])
    print cyan
    if options[:include_workflow_access] || options[:include_all_access]
      print_h2 "Workflow", options
      rows = workflow_permissions.collect do |it|
        {
          name: it['name'],
          access: format_access_string(it['access'], ["none","full"]),
        }
      end
      if !options[:include_default_access]
        rows = rows.select {|row| row[:access] && row[:access] != 'default '}
      end
      print as_pretty_table(rows, [:name, :access], options)
    elsif workflow_permissions.find {|it| it['access'] && it['access'] != 'default'}
      print_h2 "Workflow", options
      print cyan,"Use --workflow-access to list custom access","\n"
    end
    print reset,"\n"
    return 0, nil
  end
end

#add(args) ⇒ Object



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
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
# File 'lib/morpheus/cli/commands/roles.rb', line 581

def add(args)
  options = {}
  params = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[name] [options]")
    build_option_type_options(opts, options, add_role_option_types)
    build_role_access_options(opts, options, params)
    opts.on('--owner ID', String, "Set the owner/tenant/account for the role by account id. Only master tenants with full permission for Tenant and Role may use this option." ) do |val|
      params['owner'] = val
    end
    opts.on(nil, '--include-default-access', "Include default access levels in the response (returns all available resources)") do
      options[:include_default_access] = true
    end
    build_standard_add_options(opts, options)
    opts.footer = <<-EOT
Create a new role.
[name] is required. This is a unique name (authority) for the new role.
All the role permissions and access values can be configured.
Use --feature-access "CODE=ACCESS,CODE=ACCESS" to update access levels for specific feature permissions identified by code. 
Use --default-instance-type-access custom --instance-types "CODE=ACCESS,CODE=ACCESS" to customize instance type access.
Only the specified permissions,instance types, etc. are updated.
Use --reset-feature-access to set access to "none" for all unspecified feature permissions.
Use --reset-all-access to set access to "none" for all unspecified feature permissions and default access values for groups, instance types, etc.
EOT
  end
  optparse.parse!(args)
  verify_args!(args:args, optparse:optparse, max:1)
  if args[0]
    options[:options]['authority'] = args[0]
  end
  connect(options)
  begin

    load_whoami()
     = (options)
     =  ? ['id'] : nil

    passed_options = options[:options] ? options[:options].reject {|k,v| k.is_a?(Symbol) } : {}
    payload = nil
    if options[:payload]
      payload = options[:payload]
      payload.deep_merge!({'role' => passed_options}) unless passed_options.empty?
    else
      # merge -O options into normally parsed options
      params.deep_merge!(passed_options)

      # argh, some options depend on others here...eg. multitenant is only available when roleType == 'user'
      #prompt_option_types = update_role_option_types()

      v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'authority', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'displayOrder' => 1}], options[:options])
      params['authority'] = v_prompt['authority']
      v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'displayOrder' => 2}], options[:options])
      params['description'] = v_prompt['description']
      v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'landingUrl', 'fieldLabel' => 'landingUrl', 'type' => 'text', 'displayOrder' => 3, 'description' => 'An optional override for the default landing page after login for a user.'}], options[:options])
      params['landingUrl'] = v_prompt['landingUrl']

      if params['owner']
        if @is_master_account && has_complete_access
          params['owner'] = params['owner']
        else
          print_red_alert "You do not have the necessary authority to use owner option"
          return
        end
      elsif @is_master_account && has_complete_access
        v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'owner', 'fieldLabel' => 'Owner', 'type' => 'select', 'selectOptions' => role_owner_options, 'defaultValue' => ['id'], 'displayOrder' => 3}], options[:options])
        params['owner'] = v_prompt['owner']
      else
        params['owner'] = ['id']
      end  

      if @is_master_account && params['owner'] == ['id']
        v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'roleType', 'fieldLabel' => 'Type', 'type' => 'select', 'selectOptions' => role_type_options, 'defaultValue' => 'user', 'displayOrder' => 4}], options[:options])
        params['roleType'] = v_prompt['roleType']
      else
        params['roleType'] = 'user'
      end

      if options[:cloud_permissions] && params['roleType'] == 'user'
        raise_command_error "The --clouds option is only available for user roles, not account roles"
      end
      if options[:group_permissions] && params['roleType'] == 'account'
        raise_command_error "The --groups option is only available for account roles, not user roles"
      end

      v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'baseRole', 'fieldLabel' => 'Copy From Role', 'type' => 'select', 'selectOptions' => base_role_options(params), 'displayOrder' => 5}], options[:options])
      if v_prompt['baseRole'].to_s != ''
        base_role = find_role_by_name_or_id(, v_prompt['baseRole'])
        exit 1 if base_role.nil?
        params['baseRoleId'] = base_role['id']
      end

      if @is_master_account && params['owner'] == ['id']
        if params['roleType'] == 'user'
          v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'multitenant', 'fieldLabel' => 'Multitenant', 'type' => 'checkbox', 'defaultValue' => 'off', 'description' => 'A Multitenant role is automatically copied into all existing subaccounts as well as placed into a subaccount when created. Useful for providing a set of predefined roles a Customer can use', 'displayOrder' => 5}], options[:options])
          params['multitenant'] = ['on','true'].include?(v_prompt['multitenant'].to_s)
          if params['multitenant']
            v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'multitenantLocked', 'fieldLabel' => 'Multitenant Locked', 'type' => 'checkbox', 'defaultValue' => 'off', 'description' => 'Prevents subtenants from branching off this role/modifying it.'}], options[:options])
            params['multitenantLocked'] = ['on','true'].include?(v_prompt['multitenantLocked'].to_s)
          end
        end
      end

      # v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'defaultPersona', 'fieldLabel' => 'Default Persona', 'type' => 'select', 'optionSource' => 'personas', 'description' => 'Default Persona'}], options[:options], @api_client)
      v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'defaultPersona', 'fieldLabel' => 'Default Persona', 'type' => 'select', 'selectOptions' => get_persona_select_options(), 'description' => 'Default Persona'}], options[:options], @api_client)
      params['defaultPersona'] = {'code' => v_prompt['defaultPersona']} unless v_prompt['defaultPersona'].to_s.strip.empty?

      # bulk role permissions
      parse_role_access_options(options, params)
      payload = {"role" => params}
    end
    query_params = parse_query_options(options)
    query_params['includeDefaultAccess'] = true if options[:include_default_access]
    @roles_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @roles_interface.dry.create(, payload, query_params)
      return
    end
    json_response = @roles_interface.create(, payload, query_params)

    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
      return
    end

    role = json_response['role']
    display_name = role['authority'] rescue ''
    if 
      print_green_success "Added role #{display_name} to account #{['name']}"
    else
      print_green_success "Added role #{display_name}"
    end

    get_args = [role['id']] + (options[:remote] ? ["-r",options[:remote]] : [])
    if 
      get_args.push "--account-id", ['id'].to_s
    end

    details_options = [params["authority"]]
    if 
      details_options.push "--account-id", ['id'].to_s
    end

    if params['owner']
      details_options.push "--account-id", params['owner'].to_s
    end
    get(details_options)

  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#connect(opts) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/morpheus/cli/commands/roles.rb', line 27

def connect(opts)
  @api_client = establish_remote_appliance_connection(opts)
  @whoami_interface = @api_client.whoami
  @account_users_interface = @api_client.
  @accounts_interface = @api_client.accounts
  @roles_interface = @api_client.roles
  @groups_interface = @api_client.groups
  @options_interface = @api_client.options
  @instances_interface = @api_client.instances
  @instance_types_interface = @api_client.instance_types
  @blueprints_interface = @api_client.blueprints
  @active_group_id = Morpheus::Cli::Groups.active_groups[@appliance_name]
end

#get(args) ⇒ Object



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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/morpheus/cli/commands/roles.rb', line 94

def get(args)
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[role]")
    opts.on('-p','--permissions', "Display Permissions [deprecated]") do |val|
      options[:include_feature_access] = true
    end
    opts.add_hidden_option('-p,')
    opts.on('-f','--feature-access', "Display Feature Access") do |val|
      options[:include_feature_access] = true
    end
    opts.on('-g','--group-access', "Display Group Access") do
      options[:include_group_access] = true
    end
    opts.on('-c','--cloud-access', "Display Cloud Access") do
      options[:include_cloud_access] = true
    end
    opts.on('-i','--instance-type-access', "Display Instance Type Access") do
      options[:include_instance_type_access] = true
    end
    opts.on('-b','--blueprint-access', "Display Blueprint Access") do
      options[:include_blueprint_access] = true
    end
    opts.on(nil,'--catalog-item-type-access', "Display Catalog Item Type Access") do
      options[:include_catalog_item_type_access] = true
    end
    opts.on(nil,'--personas', "Display Persona Access") do
      options[:include_persona_access] = true
    end
    opts.add_hidden_option('--personas')
    opts.on(nil,'--persona-access', "Display Persona Access") do
      options[:include_persona_access] = true
    end
    opts.on(nil,'--vdi-pool-access', "Display VDI Pool Access") do
      options[:include_vdi_pool_access] = true
    end
    opts.on(nil,'--report-type-access', "Display Report Type Access") do
      options[:include_report_type_access] = true
    end
    opts.on(nil,'--workflow-access', "Display Workflow Access") do
      options[:include_workflow_access] = true
    end
    opts.on(nil,'--task-access', "Display Task Access") do
      options[:include_task_access] = true
    end
    opts.on('-a','--all', "Display All Access Lists") do
      options[:include_all_access] = true
    end
    opts.on(nil, '--include-default-access', "Include default access levels in the output (returns all available resources)") do
      options[:include_default_access] = true
    end
    opts.on('--account-id ID', String, "Clarify Owner of Role") do |val|
      if has_complete_access
        options[:account_id] = val.to_s
      end
    end
    build_standard_get_options(opts, options)
    opts.footer = <<-EOT
Get details about a role.
[role] is required. This is the name (authority) or id of a role.
EOT
  end
  optparse.parse!(args)
  verify_args!(args:args, optparse:optparse, min:1)
  connect(options)
  id_list = parse_id_list(args)
  return run_command_for_each_arg(id_list) do |arg|
    _get(arg, options)
  end
end

#handle(args) ⇒ Object



41
42
43
# File 'lib/morpheus/cli/commands/roles.rb', line 41

def handle(args)
  handle_subcommand(args)
end

#list(args) ⇒ Object



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
# File 'lib/morpheus/cli/commands/roles.rb', line 45

def list(args)
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[search phrase]")
    opts.on( '--tenant TENANT', "Tenant Filter for list of Roles." ) do |val|
      options[:tenant] = val
    end
    build_standard_list_options(opts, options)
    opts.footer = "List roles."
  end
  optparse.parse!(args)
  # verify_args!(args:args, optparse:optparse, count:0)
  options[:phrase] = args.join(" ") if args.count > 0
  connect(options)

   = (options)
   =  ? ['id'] : nil
  params = {}
  params.merge!(parse_list_options(options))
  @roles_interface.setopts(options)
  if options[:dry_run]
    print_dry_run @roles_interface.dry.list(, params), options
    return 0, nil
  end
  load_whoami()
  if options[:tenant]
    params[:tenant] = options[:tenant]
  end
  json_response = @roles_interface.list(, params)

  render_response(json_response, options, "roles") do
    roles = json_response['roles']
    title = "Morpheus Roles"
    subtitles = []
    subtitles += parse_list_subtitles(options)
    print_h1 title, subtitles, options
    if roles.empty?
      print cyan,"No roles found.",reset,"\n"
    else
      print cyan
      columns = @is_master_account ? role_column_definitions : subtenant_role_column_definitions
      print as_pretty_table(roles, columns.upcase_keys!, options)
      print_results_pagination(json_response)
    end
    print reset,"\n"
  end
  return 0, nil
end

#list_permissions(args) ⇒ Object



472
473
474
475
476
477
478
479
480
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
548
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
# File 'lib/morpheus/cli/commands/roles.rb', line 472

def list_permissions(args)
  options = {}
  available_categories = ['feature', 'group', 'cloud', 'instance-type', 'blueprint', 'report-type', 'persona', 'catalog-item-type', 'vdi-pool', 'workflow', 'task']
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[role] [category]")
    build_common_options(opts, options, [:list, :json, :yaml, :csv, :fields, :dry_run, :remote])
    opts.footer = "List the access for a role.\n" +
      "[role] is required. This is the name or id of a role.\n" +
      "[category] is optional. Available categories: #{ored_list(available_categories)}"
  end

  optparse.parse!(args)
  verify_args!(args:args, optparse:optparse, min: 1, max:2)
  connect(options)

  category = args[1].to_s.downcase if args[1]

  if !category.nil? && !available_categories.include?(category)
    raise_command_error("invalid category: #{category}", args, optparse)
  end

   = (options)
   =  ? ['id'] : nil

  @roles_interface.setopts(options)
  if options[:dry_run]
    if args[0].to_s =~ /\A\d{1,}\Z/
      print_dry_run @roles_interface.dry.get(, args[0].to_i)
    else
      print_dry_run @roles_interface.dry.list(, {name: args[0]})
    end
    return
  end

  if args[0].to_s =~ /\A\d{1,}\Z/
    role = @roles_interface.get(, args[0].to_i)
  else
    role = find_role_by_name_or_id(, args[0])
    exit 1 if role.nil?
    role = @roles_interface.get(, role['id'])
  end

  available_categories.reject! {|category| category == 'cloud'} if role['role']['roleType'] == 'user'
  available_categories.reject! {|category| category == 'group'} if role['role']['roleType'] == 'account'

  permission_name = -> (s) {
    return 'sites' if s == 'group'
    return 'zones' if s == 'cloud'
    s = 'task-set' if s == 'workflow'
    s = 'app-template' if s == 'blueprint'
    s.split('-').map.with_index{|s,i| i == 0 ? s : s.capitalize}.join + 'Permissions'
  }
  permission_label = -> (s) {s.split('-').collect{|s| s.capitalize}.join(' ') + ' Permissions'}

  if category.nil?
    permissions = available_categories.reject{|category| role[permission_name.call(category)].nil?}.collect{|category|
      role[permission_name.call(category)].map{|perm| perm.merge({'category' => permission_label.call(category)})}
    }.flatten
  else
    permissions = role[permission_name.call(category)]
  end

  if options[:json]
    puts as_json(permissions, options)
    return 0
  elsif options[:yaml]
    puts as_yaml(permissions, options)
    return 0
  elsif options[:csv]
    puts records_as_csv(permissions, :include_fields => ['category', 'id', 'code', 'name', 'access', 'sub category'])
    return 0
  end

  print cyan
  print_h1 "Role: [#{role['role']['id']}#{(role['role']['owner'].nil? ? ']' : ", #{role['role']['owner']['name']}]")} #{role['role']['authority']}", options

  (category.nil? ? available_categories : [category]).each do |category|
    permissions = role[permission_name.call(category)]
    next if permissions.nil?
    print_h2 "#{permission_label.call(category)}", options
    if permissions.size > 0
      rows = permissions.collect do |it|
        {
          code: it['code'],
          name: it['name'],
          category: it['subCategory'].to_s.titleize,
          access: format_access_string(it['access']),
        }
      end
      if options[:sort]
        rows.sort! {|a,b| a[options[:sort]] <=> b[options[:sort]] }
      else
        rows.sort! {|a,b| [a[:category],a[:name],a[:code]] <=> [b[:category],b[:name],b[:code]] }
      end
      if options[:direction] == 'desc'
        rows.reverse!
      end
      if options[:phrase]
        phrase_regexp = /#{Regexp.escape(options[:phrase])}/i
        rows = rows.select {|row| row[:code].to_s =~ phrase_regexp || row[:name].to_s =~ phrase_regexp }
      end
      print as_pretty_table(rows, [:category, :name, :code, :access], options)
    else
      puts "No permissions found"
    end
  end
  print reset,"\n"
end

#remove(args) ⇒ Object



830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
# File 'lib/morpheus/cli/commands/roles.rb', line 830

def remove(args)
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[role]")
    build_common_options(opts, options, [:auto_confirm, :json, :dry_run, :remote])
    opts.footer = <<-EOT
Delete a role.
[role] is required. This is the name (authority) or id of a role.
EOT
  end
  optparse.parse!(args)
  if args.count < 1
    puts optparse
    exit 1
  end
  name = args[0]
  connect(options)
  begin

     = (options)
     =  ? ['id'] : nil

    role = find_role_by_name_or_id(, name)
    exit 1 if role.nil?
    unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the role #{role['authority']}?")
      exit
    end
    @roles_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @roles_interface.dry.destroy(, role['id'])
      return
    end
    json_response = @roles_interface.destroy(, role['id'])
    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
    else
      print_green_success "Role #{role['authority']} removed"
    end
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#update(args) ⇒ Object



735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
# File 'lib/morpheus/cli/commands/roles.rb', line 735

def update(args)
  options = {}
  params = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[role] [options]")
    build_option_type_options(opts, options, update_role_option_types)
    build_role_access_options(opts, options, params)
    opts.on(nil, '--include-default-access', "Include default access levels in the output (returns all available resources)") do
      options[:include_default_access] = true
    end
    build_standard_update_options(opts, options)
    opts.footer = <<-EOT
Update a role.
[role] is required. This is the name (authority) or id of a role.
All the role permissions and access values can be configured.
Use --feature-access "CODE=ACCESS,CODE=ACCESS" to update access levels for specific feature permissions identified by code. 
Use --default-instance-type-access custom --instance-types "CODE=ACCESS,CODE=ACCESS" to customize instance type access.
Only the specified permissions,instance types, etc. are updated.
Use --reset-feature-access to set access to "none" for all unspecified feature permissions.
Use --reset-all-access to set access to "none" for all unspecified feature permissions and global access values for groups, instance types, etc.
EOT
  end
  optparse.parse!(args)

  verify_args!(args:args, optparse:optparse, count:1)
  
  name = args[0]
  connect(options)
  begin

    load_whoami()

     = (options)
     =  ? ['id'] : nil

    role = find_role_by_name_or_id(, name)
    exit 1 if role.nil?

    passed_options = options[:options] ? options[:options].reject {|k,v| k.is_a?(Symbol) } : {}
    payload = nil
    if options[:payload]
      payload = options[:payload]
      payload.deep_merge!({'role' => passed_options}) unless passed_options.empty?
    else
      # merge -O options into normally parsed options
      params.deep_merge!(passed_options)
      prompt_option_types = update_role_option_types()
      if !@is_master_account
        prompt_option_types = prompt_option_types.reject {|it| ['roleType', 'multitenant','multitenantLocked'].include?(it['fieldName']) }
      end
      if role['roleType'] != 'user'
        prompt_option_types = prompt_option_types.reject {|it| ['multitenant','multitenantLocked'].include?(it['fieldName']) }
      end
      #params = Morpheus::Cli::OptionTypes.prompt(prompt_option_types, options[:options], @api_client, options[:params])
      if options[:cloud_permissions] && role['roleType'] == 'user'
        raise_command_error "The --clouds option is only available for user roles, not account roles"
      end
      if options[:group_permissions] && role['roleType'] == 'account'
        raise_command_error "The --groups option is only available for account roles, not user roles"
      end
      # bulk role permissions
      parse_role_access_options(options, params)

      if params.empty?
        raise_command_error "Specify at least one option to update.\n#{optparse}"
      end
      payload = {"role" => params}
    end
    query_params = parse_query_options(options)
    query_params['includeDefaultAccess'] = true if options[:include_default_access]
    @roles_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @roles_interface.dry.update(, role['id'], payload, query_params)
      return
    end
    json_response = @roles_interface.update(, role['id'], payload, query_params)
    render_response(json_response, options, "role") do
      role = json_response['role']
      display_name = role['authority'] rescue ''
      print_green_success "Updated role #{display_name}"

      get_args = [role['id']] + (options[:remote] ? ["-r",options[:remote]] : [])
      if 
        get_args.push "--account-id", ['id'].to_s
      end
      get(get_args)
    end
    return 0, nil

  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#update_blueprint_access(args) ⇒ Object



1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
# File 'lib/morpheus/cli/commands/roles.rb', line 1455

def update_blueprint_access(args)
  options = {}
  blueprint_id = nil
  access_value = nil
  do_all = false
  allowed_access_values = ['full', 'none', 'default']
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[role] [blueprint] [access]")
    opts.on( '--blueprint ID', String, "Blueprint ID or Name" ) do |val|
      blueprint_id = val
    end
    opts.on( nil, '--all', "Update all blueprints at once." ) do
      do_all = true
    end
    opts.on( '--access VALUE', String, "Access value [#{allowed_access_values.join('|')}]" ) do |val|
      access_value = val
    end
    build_common_options(opts, options, [:json, :dry_run, :remote])
    opts.footer = "Update role access for a blueprint or all blueprints.\n" +
                  "[role] is required. This is the name or id of a role.\n" + 
                  "--blueprint or --all is required. This is the name or id of a blueprint.\n" + 
                  "--access is required. This is the new access value: #{ored_list(allowed_access_values)}"
  end
  optparse.parse!(args)

  # usage: update-blueprint-access [role] [access] --all
  #        update-blueprint-access [role] [blueprint] [access]
  name = args[0]
  if do_all
    verify_args!(args:args, optparse:optparse, min:1, max:2)
    access_value = args[1] if args[1]
  else
    verify_args!(args:args, optparse:optparse, min:1, max:3)
    blueprint_id = args[1] if args[1]
    access_value = args[2] if args[2]
  end
  if !blueprint_id && !do_all
    raise_command_error("missing required argument: [blueprint] or --all", args, optparse)
  end
  if !access_value
    raise_command_error("missing required argument: [access]", args, optparse)
  end
  access_value = access_value.to_s.downcase
  if !allowed_access_values.include?(access_value)
    raise_command_error("invalid access value: #{access_value}", args, optparse)
  end

  connect(options)
  begin
     = (options)
     =  ? ['id'] : nil
    role = find_role_by_name_or_id(, name)
    return 1 if role.nil?

    role_json = @roles_interface.get(, role['id'], {'includeDefaultAccess' => true})
    blueprint_global_access = role_json['globalAppTemplateAccess'] || role_json['globalBlueprintAccess']
    blueprint_permissions = role_json['appTemplatePermissions'] || role_json['blueprintPermissions'] || []

    # hacky, but support name or code lookup via the list returned in the show payload
    blueprint = nil
    if !do_all
      if blueprint_id.to_s =~ /\A\d{1,}\Z/
        blueprint = blueprint_permissions.find {|b| b['id'] == blueprint_id.to_i }
      else
        blueprint = blueprint_permissions.find {|b| b['name'] == blueprint_id || b['code'] == blueprint_id }
      end
      if blueprint.nil?
        print_red_alert "Blueprint not found: '#{blueprint_id}'"
        return 1
      end
    end

    params = {}
    if do_all
      params['allAppTemplates'] = true
      #params['allBlueprints'] = true
    else
      params['appTemplateId'] = blueprint['id']
      # params['blueprintId'] = blueprint['id']
    end
    params['access'] = access_value
    @roles_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @roles_interface.dry.update_blueprint(, role['id'], params)
      return
    end
    json_response = @roles_interface.update_blueprint(, role['id'], params)

    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
    else
      if do_all
        print_green_success "Role #{role['authority']} access updated for all blueprints"
      else
        print_green_success "Role #{role['authority']} access updated for blueprint #{blueprint['name']}"
      end
    end
    return 0
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#update_catalog_item_type_access(args) ⇒ Object



1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
# File 'lib/morpheus/cli/commands/roles.rb', line 1617

def update_catalog_item_type_access(args)
  options = {}
  catalog_item_type_id = nil
  access_value = nil
  do_all = false
  allowed_access_values = ['full', 'none', 'default']
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[role] [catalog-item-type] [access]")
    opts.on( '--catalog-item-type ID', String, "Catalog Item Type ID or Name" ) do |val|
      catalog_item_type_id = val
    end
    opts.on( nil, '--all', "Update all catalog item types at once." ) do
      do_all = true
    end
    opts.on( '--access VALUE', String, "Access value [#{allowed_access_values.join('|')}]" ) do |val|
      access_value = val
    end
    build_common_options(opts, options, [:json, :dry_run, :remote])
    opts.footer = "Update role access for a catalog item type or all types.\n" +
                  "[role] is required. This is the name or id of a role.\n" + 
                  "--catalog-item-type or --all is required. This is the name or id of a catalog item type.\n" + 
                  "--access is required. This is the new access value: #{ored_list(allowed_access_values)}"
  end
  optparse.parse!(args)

  # usage: update-catalog_item_type-access [role] [access] --all
  #        update-catalog_item_type-access [role] [catalog-item-type] [access]
  name = args[0]
  if do_all
    verify_args!(args:args, optparse:optparse, min:1, max:2)
    access_value = args[1] if args[1]
  else
    verify_args!(args:args, optparse:optparse, min:1, max:3)
    catalog_item_type_id = args[1] if args[1]
    access_value = args[2] if args[2]
  end
  if !catalog_item_type_id && !do_all
    raise_command_error("missing required argument: [catalog-item-type] or --all", args, optparse)
  end
  if !access_value
    raise_command_error("missing required argument: [access]", args, optparse)
  end
  access_value = access_value.to_s.downcase
  if !allowed_access_values.include?(access_value)
    raise_command_error("invalid access value: #{access_value}", args, optparse)
  end

  connect(options)
  begin
     = (options)
     =  ? ['id'] : nil
    role = find_role_by_name_or_id(, name)
    return 1 if role.nil?

    role_json = @roles_interface.get(, role['id'], {'includeDefaultAccess' => true})
    catalog_item_type_global_access = role_json['globalCatalogItemTypeAccess']
    catalog_item_type_permissions = role_json['catalogItemTypePermissions'] || role_json['catalogItemTypes'] []

    # hacky, but support name or code lookup via the list returned in the show payload
    catalog_item_type = nil
    if !do_all
      if catalog_item_type_id.to_s =~ /\A\d{1,}\Z/
        catalog_item_type = catalog_item_type_permissions.find {|b| b['id'] == catalog_item_type_id.to_i }
      else
        catalog_item_type = catalog_item_type_permissions.find {|b| b['name'] == catalog_item_type_id }
      end
      if catalog_item_type.nil?
        print_red_alert "Catalog Item Type not found: '#{catalog_item_type_id}'"
        return 1
      end
    end

    params = {}
    if do_all
      params['allCatalogItemTypes'] = true
    else
      params['catalogItemTypeId'] = catalog_item_type['id']
    end
    params['access'] = access_value
    @roles_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @roles_interface.dry.update_catalog_item_type(, role['id'], params)
      return
    end
    json_response = @roles_interface.update_catalog_item_type(, role['id'], params)

    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
    else
      if do_all
        print_green_success "Role #{role['authority']} access updated for all catalog item types"
      else
        print_green_success "Role #{role['authority']} access updated for catalog item type #{catalog_item_type['name']}"
      end
    end
    return 0
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#update_cloud_access(args) ⇒ Object



1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
# File 'lib/morpheus/cli/commands/roles.rb', line 1155

def update_cloud_access(args)
  options = {}
  cloud_id = nil
  access_value = nil
  do_all = false
  allowed_access_values = ['full', 'read', 'none', 'default']
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[role]")
    opts.on( '-c', '--cloud CLOUD', "Cloud name or id" ) do |val|
      cloud_id = val
    end
    opts.on( nil, '--all', "Update all clouds at once." ) do
      do_all = true
    end
    opts.on( '--access VALUE', String, "Access value [#{allowed_access_values.join('|')}]" ) do |val|
      access_value = val
    end
    build_common_options(opts, options, [:json, :dry_run, :remote])
    opts.footer = <<-EOT
Update role access for a cloud or all clouds.
[role] is required. This is the name or id of a role.
--cloud or --all is required. This is the name or id of a cloud.
--access is required. This is the new access value: #{ored_list(allowed_access_values)}
EOT
  end
  optparse.parse!(args)

  # usage: update-cloud-access [role] [access] --all
  #        update-cloud-access [role] [cloud] [access]
  name = args[0]
  if do_all
    verify_args!(args:args, optparse:optparse, min:1, max:2)
    access_value = args[1] if args[1]
  else
    verify_args!(args:args, optparse:optparse, min:1, max:3)
    cloud_id = args[1] if args[1]
    access_value = args[2] if args[2]
  end
  if !cloud_id && !do_all
    raise_command_error("missing required argument: [cloud] or --all", args, optparse)
  end
  if !access_value
    raise_command_error("missing required argument: [access]", args, optparse)
  end
  access_value = access_value.to_s.downcase
  if !allowed_access_values.include?(access_value)
    raise_command_error("invalid access value: #{access_value}", args, optparse)
  end

  connect(options)
  begin
     = (options)
     =  ? ['id'] : nil
    role = find_role_by_name_or_id(, name)
    exit 1 if role.nil?

    role_json = @roles_interface.get(, role['id'], {'includeDefaultAccess' => true})

    cloud = nil
    if !do_all
      cloud = find_cloud_by_name_or_id_for_provisioning(nil, cloud_id)
      return 1 if cloud.nil?
      cloud_id = cloud['id']
    end
    params = {}
    if do_all
      params['allClouds'] = true
    else
      params['cloudId'] = cloud_id
    end
    params['access'] = access_value
    @roles_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @roles_interface.dry.update_cloud(, role['id'], params)
      return
    end
    json_response = @roles_interface.update_cloud(, role['id'], params)

    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
    else
      if do_all
        print_green_success "Role #{role['authority']} access updated for all clouds"
      else
        print_green_success "Role #{role['authority']} access updated for cloud #{cloud['name']}"
      end
    end
    return 0
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#update_default_blueprint_access(args) ⇒ Object



1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
# File 'lib/morpheus/cli/commands/roles.rb', line 1403

def update_default_blueprint_access(args)
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[role] [access]")
    build_common_options(opts, options, [:json, :dry_run, :remote])
          opts.footer = <<-EOT
Update default blueprint access for a role.
[role] is required. This is the name (authority) or id of a role.
[access] is required. This is the access level to assign: full or none.
EOT
  end
  optparse.parse!(args)

  if args.count < 2
    puts optparse
    exit 1
  end
  name = args[0]
  access_value = args[1].to_s.downcase
  if !['full', 'none', 'custom'].include?(access_value)
    puts optparse
    exit 1
  end


  connect(options)
  begin
     = (options)
     =  ? ['id'] : nil
    role = find_role_by_name_or_id(, name)
    exit 1 if role.nil?

    params = {permissionCode: 'AppTemplate', access: access_value}
    @roles_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @roles_interface.dry.update_permission(, role['id'], params)
      return
    end
    json_response = @roles_interface.update_permission(, role['id'], params)

    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
    else
      print_green_success "Role #{role['authority']} default blueprint access updated"
    end
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#update_default_catalog_item_type_access(args) ⇒ Object



1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
# File 'lib/morpheus/cli/commands/roles.rb', line 1565

def update_default_catalog_item_type_access(args)
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[role] [access]")
    build_common_options(opts, options, [:json, :dry_run, :remote])
          opts.footer = <<-EOT
Update default catalog item type access for a role.
[role] is required. This is the name (authority) or id of a role.
[access] is required. This is the access level to assign: full or none.
EOT
  end
  optparse.parse!(args)

  if args.count < 2
    puts optparse
    exit 1
  end
  name = args[0]
  access_value = args[1].to_s.downcase
  if !['full', 'none', 'custom'].include?(access_value)
    puts optparse
    exit 1
  end


  connect(options)
  begin
     = (options)
     =  ? ['id'] : nil
    role = find_role_by_name_or_id(, name)
    exit 1 if role.nil?

    params = {permissionCode: 'CatalogItemType', access: access_value}
    @roles_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @roles_interface.dry.update_permission(, role['id'], params)
      return
    end
    json_response = @roles_interface.update_permission(, role['id'], params)

    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
    else
      print_green_success "Role #{role['authority']} default catalog item type access updated"
    end
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#update_default_cloud_access(args) ⇒ Object



1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
# File 'lib/morpheus/cli/commands/roles.rb', line 1103

def update_default_cloud_access(args)
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[role] [access]")
    build_common_options(opts, options, [:json, :dry_run, :remote])
    opts.footer = <<-EOT
Update default cloud access for a role.
[role] is required. This is the name (authority) or id of a role.
[access] is required. This is the access level to assign: full, read or none.
Only applicable to Tenant roles.
EOT
  end
  optparse.parse!(args)

  if args.count < 2
    puts optparse
    exit 1
  end
  name = args[0]
  access_value = args[1].to_s.downcase
  if !['full', 'read', 'none', 'custom'].include?(access_value)
    puts optparse
    exit 1
  end

  connect(options)
  begin
     = (options)
     =  ? ['id'] : nil
    role = find_role_by_name_or_id(, name)
    exit 1 if role.nil?

    params = {permissionCode: 'ComputeZone', access: access_value}
    @roles_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @roles_interface.dry.update_permission(, role['id'], params)
      return
    end
    json_response = @roles_interface.update_permission(, role['id'], params)

    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
    else
      print_green_success "Role #{role['authority']} default cloud access updated"
    end
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#update_default_group_access(args) ⇒ Object



950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# File 'lib/morpheus/cli/commands/roles.rb', line 950

def update_default_group_access(args)
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[role] [access]")
    build_common_options(opts, options, [:json, :dry_run, :remote])
    opts.footer = <<-EOT
Update default group access for a role.
[role] is required. This is the name (authority) or id of a role.
[access] is required. This is the access level to assign: full, read, or none.
Only applicable to User roles.
EOT
  end
  optparse.parse!(args)

  if args.count < 2
    puts optparse
    exit 1
  end
  name = args[0]
  access_value = args[1].to_s.downcase
  if !['full', 'read', 'none', 'custom'].include?(access_value)
    puts optparse
    exit 1
  end

  connect(options)
  begin
     = (options)
     =  ? ['id'] : nil
    role = find_role_by_name_or_id(, name)
    exit 1 if role.nil?

    params = {permissionCode: 'ComputeSite', access: access_value}
    @roles_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @roles_interface.dry.update_permission(, role['id'], params)
      return
    end
    json_response = @roles_interface.update_permission(, role['id'], params)

    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
    else
      print_green_success "Role #{role['authority']} default group access updated"
    end
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#update_default_instance_type_access(args) ⇒ Object



1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
# File 'lib/morpheus/cli/commands/roles.rb', line 1255

def update_default_instance_type_access(args)
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[role] [access]")
    build_common_options(opts, options, [:json, :dry_run, :remote])
          opts.footer = <<-EOT
Update default instance type access for a role.
[role] is required. This is the name (authority) or id of a role.
[access] is required. This is the access level to assign: full or none.
EOT
  end
  optparse.parse!(args)

  if args.count < 2
    puts optparse
    exit 1
  end
  name = args[0]
  access_value = args[1].to_s.downcase
  if !['full', 'none', 'custom'].include?(access_value)
    puts optparse
    exit 1
  end


  connect(options)
  begin
     = (options)
     =  ? ['id'] : nil
    role = find_role_by_name_or_id(, name)
    exit 1 if role.nil?

    params = {permissionCode: 'InstanceType', access: access_value}
    @roles_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @roles_interface.dry.update_permission(, role['id'], params)
      return
    end
    json_response = @roles_interface.update_permission(, role['id'], params)

    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
    else
      print_green_success "Role #{role['authority']} default instance type access updated"
    end
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#update_default_persona_access(args) ⇒ Object



1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
# File 'lib/morpheus/cli/commands/roles.rb', line 1720

def update_default_persona_access(args)
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[role] [access]")
    build_common_options(opts, options, [:json, :dry_run, :remote])
    opts.footer = <<-EOT
Update default persona access for a role.
[role] is required. This is the name (authority) or id of a role.
[access] is required. This is the access level to assign: full or none.
    EOT
  end
  optparse.parse!(args)

  if args.count < 2
    puts optparse
    exit 1
  end
  name = args[0]
  access_value = args[1].to_s.downcase
  if !['full', 'none', 'custom'].include?(access_value)
    puts optparse
    exit 1
  end

  connect(options)
  begin
     = (options)
     =  ? ['id'] : nil
    role = find_role_by_name_or_id(, name)
    exit 1 if role.nil?

    params = {permissionCode: 'Persona', access: access_value}
    @roles_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @roles_interface.dry.update_permission(, role['id'], params)
      return
    end
    json_response = @roles_interface.update_permission(, role['id'], params)

    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
    else
      print_green_success "Role #{role['authority']} default persona access updated"
    end
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#update_default_report_type_access(args) ⇒ Object



2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
# File 'lib/morpheus/cli/commands/roles.rb', line 2022

def update_default_report_type_access(args)
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[role] [access]")
    build_common_options(opts, options, [:json, :dry_run, :remote])
    opts.footer = <<-EOT
Update default report type access for a role.
[role] is required. This is the name (authority) or id of a role.
[access] is required. This is the access level to assign: full or none.
EOT
  end
  optparse.parse!(args)
  verify_args!(args:args, optparse:optparse, count: 2)
  name = args[0]
  access_value = args[1].to_s.downcase
  if !['full', 'none', 'custom'].include?(access_value)
    raise_command_error("invalid access value: #{args[1]}", args, optparse)
  end

  connect(options)
  begin
     = (options)
     =  ? ['id'] : nil
    role = find_role_by_name_or_id(, name)
    exit 1 if role.nil?
    # note: ReportTypes being plural is odd, the others are singular
    params = {permissionCode: 'ReportTypes', access: access_value}
    @roles_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @roles_interface.dry.update_permission(, role['id'], params)
      return
    end
    json_response = @roles_interface.update_permission(, role['id'], params)

    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
    else
      print_green_success "Role #{role['authority']} default report type access updated"
    end
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#update_default_task_access(args) ⇒ Object



2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
# File 'lib/morpheus/cli/commands/roles.rb', line 2178

def update_default_task_access(args)
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[role] [access]")
    build_common_options(opts, options, [:json, :dry_run, :remote])
    opts.footer = <<-EOT
Update default task access for a role.
[role] is required. This is the id of a role.
[access] is required. This is the access level to assign: full or none.
    EOT
  end
  optparse.parse!(args)
  verify_args!(args:args, optparse:optparse, count: 2)
  name = args[0]
  access_value = args[1].to_s.downcase
  if !['full', 'none', 'custom'].include?(access_value)
    raise_command_error("invalid access value: #{args[1]}", args, optparse)
  end

  connect(options)
  begin
     = (options)
     =  ? ['id'] : nil
    role = find_role_by_name_or_id(, name)
    exit 1 if role.nil?
    # note: ReportTypes being plural is odd, the others are singular
    params = {permissionCode: 'Task', access: access_value}
    @roles_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @roles_interface.dry.update_permission(, role['id'], params)
      return
    end
    json_response = @roles_interface.update_permission(, role['id'], params)

    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
    else
      print_green_success "Role #{role['authority']} default task access updated"
    end
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#update_default_vdi_pool_access(args) ⇒ Object



1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
# File 'lib/morpheus/cli/commands/roles.rb', line 1867

def update_default_vdi_pool_access(args)
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[role] [access]")
    build_common_options(opts, options, [:json, :dry_run, :remote])
          opts.footer = <<-EOT
Update default VDI pool access for a role.
[role] is required. This is the name (authority) or id of a role.
[access] is required. This is the access level to assign: full or none.
EOT
  end
  optparse.parse!(args)
  verify_args!(args:args, optparse:optparse, count: 2)
  name = args[0]
  access_value = args[1].to_s.downcase
  if !['full', 'none', 'custom'].include?(access_value)
    raise_command_error("invalid access value: #{args[1]}", args, optparse)
  end


  connect(options)
  begin
     = (options)
     =  ? ['id'] : nil
    role = find_role_by_name_or_id(, name)
    exit 1 if role.nil?
    # note: VdiPools being plural is odd, the others are singular
    params = {permissionCode: 'VdiPools', access: access_value}
    @roles_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @roles_interface.dry.update_permission(, role['id'], params)
      return
    end
    json_response = @roles_interface.update_permission(, role['id'], params)

    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
    else
      print_green_success "Role #{role['authority']} default vdi pool access updated"
    end
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#update_default_workflow_access(args) ⇒ Object



2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
# File 'lib/morpheus/cli/commands/roles.rb', line 2331

def update_default_workflow_access(args)
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[role] [access]")
    build_common_options(opts, options, [:json, :dry_run, :remote])
    opts.footer = <<-EOT
Update default workflow access for a role.
[role] is required. This is the id of a role.
[access] is required. This is the access level to assign: full or none.
    EOT
  end
  optparse.parse!(args)
  verify_args!(args:args, optparse:optparse, count: 2)
  name = args[0]
  access_value = args[1].to_s.downcase
  if !['full', 'none', 'custom'].include?(access_value)
    raise_command_error("invalid access value: #{args[1]}", args, optparse)
  end

  connect(options)
  begin
     = (options)
     =  ? ['id'] : nil
    role = find_role_by_name_or_id(, name)
    exit 1 if role.nil?
    params = {permissionCode: 'TaskSet', access: access_value}
    @roles_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @roles_interface.dry.update_permission(, role['id'], params)
      return
    end
    json_response = @roles_interface.update_permission(, role['id'], params)

    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
    else
      print_green_success "Role #{role['authority']} default workflow access updated"
    end
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#update_feature_access(args) ⇒ Object



875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
# File 'lib/morpheus/cli/commands/roles.rb', line 875

def update_feature_access(args)
  options = {}
  allowed_access_values = ["full", "full_decrypted", "group", "listfiles", "managerules", "no", "none", "provision", "read", "rolemappings", "user", "view", "yes"]
  permission_code = nil
  access_value = nil
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[role] [permission] [access]")
    opts.on( '-p', '--permission CODE', "Permission code or name" ) do |val|
      permission_code = val
    end
    opts.on( '--access VALUE', String, "Access value [#{allowed_access_values.join('|')}] (varies per permission)" ) do |val|
      access_value = val
    end
    build_common_options(opts, options, [:json, :dry_run, :remote])
    opts.footer = <<-EOT
Update role access for a permission.
[role] is required. This is the name (authority) or id of a role.
[permission] is required. This is the code or name of a permission.
[access] is required. This is the new access value: #{ored_list(allowed_access_values)}
EOT
  end
  optparse.parse!(args)
  verify_args!(args:args, optparse:optparse, min:1, max:3)
  name = args[0]
  permission_code = args[1] if args[1]
  access_value = args[2].to_s.downcase if args[2]

  if !permission_code
    raise_command_error("missing required argument: [permission]", args, optparse)
  end
  if !access_value
    raise_command_error("missing required argument: [access]", args, optparse)
  end
  # access_value = access_value.to_s.downcase
  # if !allowed_access_values.include?(access_value)
  #   raise_command_error("invalid access value: #{access_value}", args, optparse)
  # end
  # need to load the permission and then split accessTypes, so just allows all for now, server validates...
  # if !['full_decrypted','full', 'read', 'custom', 'none'].include?(access_value)
  #   puts optparse
  #   exit 1
  # end

  connect(options)
  begin
     = (options)
     =  ? ['id'] : nil
    role = find_role_by_name_or_id(, name)
    exit 1 if role.nil?

    params = {permissionCode: permission_code, access: access_value}
    @roles_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @roles_interface.dry.update_permission(, role['id'], params)
      return
    end
    json_response = @roles_interface.update_permission(, role['id'], params)

    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
    else
      print_green_success "Role #{role['authority']} permission #{permission_code} set to #{access_value}"
    end
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#update_global_blueprint_access(args) ⇒ Object



1398
1399
1400
1401
# File 'lib/morpheus/cli/commands/roles.rb', line 1398

def update_global_blueprint_access(args)
  puts "#{yellow}DEPRECATED#{reset}"
  update_default_blueprint_access(args)
end

#update_global_catalog_item_type_access(args) ⇒ Object



1560
1561
1562
1563
# File 'lib/morpheus/cli/commands/roles.rb', line 1560

def update_global_catalog_item_type_access(args)
  puts "#{yellow}DEPRECATED#{reset}"
  update_default_catalog_item_type_access(args)
end

#update_global_cloud_access(args) ⇒ Object



1098
1099
1100
1101
# File 'lib/morpheus/cli/commands/roles.rb', line 1098

def update_global_cloud_access(args)
  puts "#{yellow}DEPRECATED#{reset}"
  update_default_cloud_access(args)
end

#update_global_group_access(args) ⇒ Object



945
946
947
948
# File 'lib/morpheus/cli/commands/roles.rb', line 945

def update_global_group_access(args)
  puts "#{yellow}DEPRECATED#{reset}"
  update_default_group_access(args)
end

#update_global_instance_type_access(args) ⇒ Object



1250
1251
1252
1253
# File 'lib/morpheus/cli/commands/roles.rb', line 1250

def update_global_instance_type_access(args)
  puts "#{yellow}DEPRECATED#{reset}"
  update_default_instance_type_access(args)
end

#update_global_report_type_access(args) ⇒ Object



2017
2018
2019
2020
# File 'lib/morpheus/cli/commands/roles.rb', line 2017

def update_global_report_type_access(args)
  puts "#{yellow}DEPRECATED#{reset}"
  update_default_report_type_access(args)
end

#update_global_task_access(args) ⇒ Object



2173
2174
2175
2176
# File 'lib/morpheus/cli/commands/roles.rb', line 2173

def update_global_task_access(args)
  puts "#{yellow}DEPRECATED#{reset}"
  update_default_task_access(args)
end

#update_global_vdi_pool_access(args) ⇒ Object



1862
1863
1864
1865
# File 'lib/morpheus/cli/commands/roles.rb', line 1862

def update_global_vdi_pool_access(args)
  puts "#{yellow}DEPRECATED#{reset}"
  update_default_vdi_pool_access(args)
end

#update_global_workflow_access(args) ⇒ Object



2326
2327
2328
2329
# File 'lib/morpheus/cli/commands/roles.rb', line 2326

def update_global_workflow_access(args)
  puts "#{yellow}DEPRECATED#{reset}"
  update_default_workflow_access(args)
end

#update_group_access(args) ⇒ Object



1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
# File 'lib/morpheus/cli/commands/roles.rb', line 1002

def update_group_access(args)
  options = {}
  name = nil
  group_id = nil
  access_value = nil
  do_all = false
  allowed_access_values = ['full', 'read', 'none', 'default']
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[role] [group] [access]")
    opts.on( '-g', '--group GROUP', "Group name or id" ) do |val|
      group_id = val
    end
    opts.on( nil, '--all', "Update all groups at once." ) do
      do_all = true
    end
    opts.on( '--access VALUE', String, "Access value [#{allowed_access_values.join('|')}]" ) do |val|
      access_value = val
    end
    build_common_options(opts, options, [:json, :dry_run, :remote])
    opts.footer = <<-EOT
Update role access for a group or all groups.
[role] is required. This is the name or id of a role.
--group or --all is required. This is the name or id of a group.
--access is required. This is the new access value: #{ored_list(allowed_access_values)}
EOT
    
  end
  optparse.parse!(args)

  # usage: update-group-access [role] [access] --all
  #        update-group-access [role] [group] [access]
  name = args[0]
  if do_all
    verify_args!(args:args, optparse:optparse, min:1, max:2)
    access_value = args[1] if args[1]
  else
    verify_args!(args:args, optparse:optparse, min:1, max:3)
    group_id = args[1] if args[1]
    access_value = args[2] if args[2]
  end
  if !group_id && !do_all
    raise_command_error("missing required argument: [group] or --all", args, optparse)
  end
  if !access_value
    raise_command_error("missing required argument: [access]", args, optparse)
  end
  access_value = access_value.to_s.downcase
  if !allowed_access_values.include?(access_value)
    raise_command_error("invalid access value: #{access_value}", args, optparse)
  end

  connect(options)
  begin
     = (options)
     =  ? ['id'] : nil
    role = find_role_by_name_or_id(, name)
    return 1 if role.nil?

    group = nil
    if !do_all
      group = find_group_by_name_or_id_for_provisioning(group_id)
      return 1 if group.nil?
      group_id = group['id']
    end

    params = {}
    if do_all
      params['allGroups'] = true
    else
      params['groupId'] = group_id
    end
    params['access'] = access_value
    @roles_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @roles_interface.dry.update_group(, role['id'], params)
      return
    end
    json_response = @roles_interface.update_group(, role['id'], params)

    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
    else
      if do_all
        print_green_success "Role #{role['authority']} access updated for all groups"
      else
        print_green_success "Role #{role['authority']} access updated for group #{group['name']}"
      end
    end
    return 0
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#update_instance_type_access(args) ⇒ Object



1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
# File 'lib/morpheus/cli/commands/roles.rb', line 1307

def update_instance_type_access(args)
  options = {}
  instance_type_name = nil
  access_value = nil
  do_all = false
  allowed_access_values = ['full', 'none', 'default']
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[role] [type] [access]")
    opts.on( '--instance-type INSTANCE_TYPE', String, "Instance Type name" ) do |val|
      instance_type_name = val
    end
    opts.on( nil, '--all', "Update all instance types at once." ) do
      do_all = true
    end
    opts.on( '--access VALUE', String, "Access value [#{allowed_access_values.join('|')}]" ) do |val|
      access_value = val
    end
    build_common_options(opts, options, [:json, :dry_run, :remote])
    opts.footer = "Update role access for an instance type or all instance types.\n" +
                  "[role] is required. This is the name or id of a role.\n" + 
                  "--instance-type or --all is required. This is the name of an instance type.\n" + 
                  "--access is required. This is the new access value: #{ored_list(allowed_access_values)}"
  end
  optparse.parse!(args)

  if args.count < 1
    puts optparse
    return 1
  end
  name = args[0]
  # support old usage: [role] [instance-type] [access]
  instance_type_name ||= args[1]
  access_value ||= args[2]

  if (!instance_type_name && !do_all) || !access_value
    puts optparse
    return 1
  end
  
  access_value = access_value.to_s.downcase

  if !['full', 'none'].include?(access_value)
    puts optparse
    return 1
  end

  connect(options)
  begin
     = (options)
     =  ? ['id'] : nil
    role = find_role_by_name_or_id(, name)
    return 1 if role.nil?

    role_json = @roles_interface.get(, role['id'], {'includeDefaultAccess' => true})
    instance_type = nil
    if !do_all
      instance_type = find_instance_type_by_name(instance_type_name)
      return 1 if instance_type.nil?
    end

    params = {}
    if do_all
      params['allInstanceTypes'] = true
    else
      params['instanceTypeId'] = instance_type['id']
    end
    params['access'] = access_value
    @roles_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @roles_interface.dry.update_instance_type(, role['id'], params)
      return
    end
    json_response = @roles_interface.update_instance_type(, role['id'], params)

    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
    else
      if do_all
        print_green_success "Role #{role['authority']} access updated for all instance types"
      else
        print_green_success "Role #{role['authority']} access updated for instance type #{instance_type['name']}"
      end
    end
    return 0
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#update_persona_access(args) ⇒ Object



1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
# File 'lib/morpheus/cli/commands/roles.rb', line 1771

def update_persona_access(args)
  options = {}
  persona_id = nil
  name = nil
  access_value = nil
  do_all = false
  allowed_access_values = ['full', 'none', 'default']
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[role] [persona] [access]")
    opts.on( '--persona CODE', String, "Persona Code" ) do |val|
      persona_id = val
    end
    opts.on( nil, '--all', "Update all personas at once." ) do
      do_all = true
    end
    opts.on( '--access VALUE', String, "Access value [#{allowed_access_values.join('|')}]" ) do |val|
      access_value = val
    end
    build_common_options(opts, options, [:json, :dry_run, :remote])
    opts.footer = "Update role access for a persona or all personas.\n" +
                  "[role] is required. This is the name or id of a role.\n" + 
                  "--persona or --all is required. This is the code of a persona. Service Catalog, Standard, or Virtual Desktop\n" + 
                  "--access is required. This is the new access value: #{ored_list(allowed_access_values)}"
  end
  optparse.parse!(args)

  # usage: update-persona-access [role] [access] --all
  #        update-persona-access [role] [persona] [access]
  name = args[0]
  if do_all
    verify_args!(args:args, optparse:optparse, min:1, max:2)
    access_value = args[1] if args[1]
  else
    verify_args!(args:args, optparse:optparse, min:1, max:3)
    persona_id = args[1] if args[1]
    access_value = args[2] if args[2]
  end
  if !persona_id && !do_all
    raise_command_error("missing required argument: [persona] or --all", args, optparse)
  end
  if !access_value
    raise_command_error("missing required argument: [access]", args, optparse)
  end
  access_value = access_value.to_s.downcase
  if !allowed_access_values.include?(access_value)
    raise_command_error("invalid access value: #{access_value}", args, optparse)
  end

  connect(options)
  begin
     = (options)
     =  ? ['id'] : nil
    role = find_role_by_name_or_id(, name)
    return 1 if role.nil?

    role_json = @roles_interface.get(, role['id'], {'includeDefaultAccess' => true})
    
    # no lookup right now, pass the code serviceCatalog|standard
    persona_code = persona_id

    params = {}
    if do_all
      params['allPersonas'] = true
    else
      params['personaCode'] = persona_code
    end
    params['access'] = access_value
    @roles_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @roles_interface.dry.update_persona(, role['id'], params)
      return
    end
    json_response = @roles_interface.update_persona(, role['id'], params)

    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
    else
      if do_all
        print_green_success "Role #{role['authority']} access updated for all personas"
      else
        print_green_success "Role #{role['authority']} access updated for persona #{persona_code}"
      end
    end
    return 0
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#update_report_type_access(args) ⇒ Object



2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
# File 'lib/morpheus/cli/commands/roles.rb', line 2068

def update_report_type_access(args)
  options = {}
  report_type_id = nil
  access_value = nil
  do_all = false
  allowed_access_values = ['full', 'none', 'default']
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[role] [report-type] [access]")
    opts.on( '--report-type ID', String, "Report Type ID or Name" ) do |val|
      report_type_id = val
    end
    opts.on( nil, '--all', "Update all report types at once." ) do
      do_all = true
    end
    opts.on( '--access VALUE', String, "Access value [#{allowed_access_values.join('|')}]" ) do |val|
      access_value = val
    end
    build_common_options(opts, options, [:json, :dry_run, :remote])
    opts.footer = "Update role access for a report type or all report types.\n" +
                  "[role] is required. This is the name or id of a role.\n" + 
                  "--report-type or --all is required. This is the name or id of a report type.\n" + 
                  "--access is required. This is the new access value: #{ored_list(allowed_access_values)}"
  end
  optparse.parse!(args)

  # usage: update-report-type-access [role] [access] --all
  #        update-report-type-access [role] [report-type] [access]
  name = args[0]
  if do_all
    verify_args!(args:args, optparse:optparse, min:1, max:2)
    access_value = args[1] if args[1]
  else
    verify_args!(args:args, optparse:optparse, min:1, max:3)
    report_type_id = args[1] if args[1]
    access_value = args[2] if args[2]
  end
  if !report_type_id && !do_all
    raise_command_error("missing required argument: [report-type] or --all", args, optparse)
  end
  if !access_value
    raise_command_error("missing required argument: [access]", args, optparse)
  end
  access_value = access_value.to_s.downcase
  if !allowed_access_values.include?(access_value)
    raise_command_error("invalid access value: #{access_value}", args, optparse)
    puts optparse
    return 1
  end

  connect(options)
  begin
     = (options)
     =  ? ['id'] : nil
    role = find_role_by_name_or_id(, name)
    return 1 if role.nil?

    role_json = @roles_interface.get(, role['id'], {'includeDefaultAccess' => true})
    report_type_global_access = role_json['globalReportTypeAccess']
    report_type_permissions = role_json['reportTypePermissions'] || role_json['reportTypes'] || []

    # hacky, but support name or code lookup via the list returned in the show payload
    report_type = nil
    if !do_all
      if report_type_id.to_s =~ /\A\d{1,}\Z/
        report_type = report_type_permissions.find {|b| b['id'] == report_type_id.to_i }
      else
        report_type = report_type_permissions.find {|b| b['name'] == report_type_id }
      end
      if report_type.nil?
        print_red_alert "Report Type not found: '#{report_type_id}'"
        return 1
      end
    end

    params = {}
    if do_all
      params['allReportTypes'] = true
    else
      params['reportTypeId'] = report_type['id']
    end
    params['access'] = access_value
    @roles_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @roles_interface.dry.update_report_type(, role['id'], params)
      return
    end
    json_response = @roles_interface.update_report_type(, role['id'], params)

    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
    else
      if do_all
        print_green_success "Role #{role['authority']} access updated for all report types"
      else
        print_green_success "Role #{role['authority']} access updated for report type #{report_type['name']}"
      end
    end
    return 0
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#update_task_access(args) ⇒ Object



2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
# File 'lib/morpheus/cli/commands/roles.rb', line 2224

def update_task_access(args)
  options = {}
  task_id = nil
  access_value = nil
  do_all = false
  allowed_access_values = ['full', 'none', 'default']
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[role] [task] [access]")
    opts.on( '--task ID', String, "Task ID, code or name" ) do |val|
      report_type_id = val
    end
    opts.on( nil, '--all', "Update all tasks at once." ) do
      do_all = true
    end
    opts.on( '--access VALUE', String, "Access value [#{allowed_access_values.join('|')}]" ) do |val|
      access_value = val
    end
    build_common_options(opts, options, [:json, :dry_run, :remote])
    opts.footer = "Update role access for a task or all tasks.\n" +
      "[role] is required. This is the name, code or id of a task.\n" +
      "--task or --all is required. This is the name, code or id of a task.\n" +
      "--access is required. This is the new access value: #{ored_list(allowed_access_values)}"
  end
  optparse.parse!(args)

  name = args[0]
  if do_all
    verify_args!(args:args, optparse:optparse, min:1, max:2)
    access_value = args[1] if args[1]
  else
    verify_args!(args:args, optparse:optparse, min:1, max:3)
    task_id = args[1] if args[1]
    access_value = args[2] if args[2]
  end
  if !task_id && !do_all
    raise_command_error("missing required argument: [task] or --all", args, optparse)
  end
  if !access_value
    raise_command_error("missing required argument: [access]", args, optparse)
  end
  access_value = access_value.to_s.downcase
  if !allowed_access_values.include?(access_value)
    raise_command_error("invalid access value: #{access_value}", args, optparse)
    puts optparse
    return 1
  end

  connect(options)
  begin
     = (options)
     =  ? ['id'] : nil
    role = find_role_by_name_or_id(, name)
    return 1 if role.nil?

    role_json = @roles_interface.get(, role['id'], {'includeDefaultAccess' => true})
    task_permissions = role_json['taskPermissions'] || role_json['tasks'] || []

    # hacky, but support name or code lookup via the list returned in the show payload
    task = nil
    if !do_all
      if task_id.to_s =~ /\A\d{1,}\Z/
        task = task_permissions.find {|b| b['id'] == task_id.to_i }
      else
        task = task_permissions.find {|b| b['name'] == task_id || b['code'] == task_id }
      end
      if task.nil?
        print_red_alert "Task not found: '#{task_id}'"
        return 1
      end
    end

    params = {}
    if do_all
      params['allTasks'] = true
    else
      params['taskId'] = task['id']
    end
    params['access'] = access_value == 'default' ? nil : access_value
    @roles_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @roles_interface.dry.update_task(, role['id'], params)
      return
    end
    json_response = @roles_interface.update_task(, role['id'], params)

    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
    else
      if do_all
        print_green_success "Role #{role['authority']} access updated for all tasks"
      else
        print_green_success "Role #{role['authority']} access updated for task #{task['name']}"
      end
    end
    return 0
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#update_vdi_pool_access(args) ⇒ Object



1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
# File 'lib/morpheus/cli/commands/roles.rb', line 1914

def update_vdi_pool_access(args)
  options = {}
  vdi_pool_id = nil
  access_value = nil
  do_all = false
  allowed_access_values = ['full', 'none', 'default']
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[role] [vdi-pool] [access]")
    opts.on( '--vdi-pool ID', String, "VDI Pool ID or Name" ) do |val|
      vdi_pool_id = val
    end
    opts.on( nil, '--all', "Update all VDI pools at once." ) do
      do_all = true
    end
    opts.on( '--access VALUE', String, "Access value [#{allowed_access_values.join('|')}]" ) do |val|
      access_value = val
    end
    build_common_options(opts, options, [:json, :dry_run, :remote])
    opts.footer = "Update role access for a VDI pool or all VDI pools.\n" +
                  "[role] is required. This is the name or id of a role.\n" + 
                  "--vdi-pool or --all is required. This is the name or id of a VDI pool.\n" + 
                  "--access is required. This is the new access value: #{ored_list(allowed_access_values)}"
  end
  optparse.parse!(args)

  name = args[0]
  if do_all
    verify_args!(args:args, optparse:optparse, min:1, max:2)
    access_value = args[1] if args[1]
  else
    verify_args!(args:args, optparse:optparse, min:1, max:3)
    vdi_pool_id = args[1] if args[1]
    access_value = args[2] if args[2]
  end
  if !vdi_pool_id && !do_all
    raise_command_error("missing required argument: [vdi-pool] or --all", args, optparse)
  end
  if !access_value
    raise_command_error("missing required argument: [access]", args, optparse)
  end
  access_value = access_value.to_s.downcase
  if !allowed_access_values.include?(access_value)
    raise_command_error("invalid access value: #{access_value}", args, optparse)
    puts optparse
    return 1
  end

  connect(options)
  begin
     = (options)
     =  ? ['id'] : nil
    role = find_role_by_name_or_id(, name)
    return 1 if role.nil?

    role_json = @roles_interface.get(, role['id'], {'includeDefaultAccess' => true})
    vdi_pool_global_access = role_json['globalVdiPoolAccess']
    vdi_pool_permissions = role_json['vdiPoolPermissions'] || role_json['vdiPools'] || []

    # hacky, but support name or code lookup via the list returned in the show payload
    vdi_pool = nil
    if !do_all
      if vdi_pool_id.to_s =~ /\A\d{1,}\Z/
        vdi_pool = vdi_pool_permissions.find {|b| b['id'] == vdi_pool_id.to_i }
      else
        vdi_pool = vdi_pool_permissions.find {|b| b['name'] == vdi_pool_id }
      end
      if vdi_pool.nil?
        print_red_alert "VDI Pool not found: '#{vdi_pool_id}'"
        return 1
      end
    end

    params = {}
    if do_all
      params['allVdiPools'] = true
    else
      params['vdiPoolId'] = vdi_pool['id']
    end
    params['access'] = access_value
    @roles_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @roles_interface.dry.update_vdi_pool(, role['id'], params)
      return
    end
    json_response = @roles_interface.update_vdi_pool(, role['id'], params)

    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
    else
      if do_all
        print_green_success "Role #{role['authority']} access updated for all VDI pools"
      else
        print_green_success "Role #{role['authority']} access updated for VDI pool #{vdi_pool['name']}"
      end
    end
    return 0
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#update_workflow_access(args) ⇒ Object



2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
# File 'lib/morpheus/cli/commands/roles.rb', line 2376

def update_workflow_access(args)
  options = {}
  workflow_id = nil
  access_value = nil
  do_all = false
  allowed_access_values = ['full', 'none', 'default']
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[role] [workflow] [access]")
    opts.on( '--workflow ID', String, "Workflow ID, code or Name" ) do |val|
      workflow_id = val
    end
    opts.on( nil, '--all', "Update all workflows at once." ) do
      do_all = true
    end
    opts.on( '--access VALUE', String, "Access value [#{allowed_access_values.join('|')}]" ) do |val|
      access_value = val
    end
    build_common_options(opts, options, [:json, :dry_run, :remote])
    opts.footer = "Update role access for a workflow or all workflows.\n" +
      "[role] is required. This is the name or id of a role.\n" +
      "--workflow or --all is required. This is the name, code or id of a workflow.\n" +
      "--access is required. This is the new access value: #{ored_list(allowed_access_values)}"
  end
  optparse.parse!(args)

  name = args[0]
  if do_all
    verify_args!(args:args, optparse:optparse, min:1, max:2)
    access_value = args[1] if args[1]
  else
    verify_args!(args:args, optparse:optparse, min:1, max:3)
    workflow_id = args[1] if args[1]
    access_value = args[2] if args[2]
  end
  if !workflow_id && !do_all
    raise_command_error("missing required argument: [workflow] or --all", args, optparse)
  end
  if !access_value
    raise_command_error("missing required argument: [access]", args, optparse)
  end
  access_value = access_value.to_s.downcase
  if !allowed_access_values.include?(access_value)
    raise_command_error("invalid access value: #{access_value}", args, optparse)
    puts optparse
    return 1
  end

  connect(options)
  begin
     = (options)
     =  ? ['id'] : nil
    role = find_role_by_name_or_id(, name)
    return 1 if role.nil?

    role_json = @roles_interface.get(, role['id'], {'includeDefaultAccess' => true})
    workflow_permissions = role_json['taskSetPermissions'] || role_json['taskSets'] || []

    # hacky, but support name or code lookup via the list returned in the show payload
    workflow = nil
    if !do_all
      if workflow_id.to_s =~ /\A\d{1,}\Z/
        workflow = workflow_permissions.find {|b| b['id'] == workflow_id.to_i }
      else
        workflow = workflow_permissions.find {|b| b['name'] == workflow_id }
      end
      if workflow.nil?
        print_red_alert "Workflow not found: '#{workflow_id}'"
        return 1
      end
    end

    params = {}
    if do_all
      params['allTaskSets'] = true
    else
      params['taskSetId'] = workflow['id']
    end
    params['access'] = access_value == 'default' ? nil : access_value
    @roles_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @roles_interface.dry.update_task_set(, role['id'], params)
      return
    end
    json_response = @roles_interface.update_task_set(, role['id'], params)

    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
    else
      if do_all
        print_green_success "Role #{role['authority']} access updated for all workflows"
      else
        print_green_success "Role #{role['authority']} access updated for workflow #{workflow['name']}"
      end
    end
    return 0
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end