mtncloud-cli 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.dockerignore +20 -0
- data/.github/pull_request_template.md +14 -0
- data/.github/workflows/ci.yml +56 -0
- data/.github/workflows/release.yml +46 -0
- data/.gitignore +25 -0
- data/CLAUDE.md +24 -0
- data/CONTRIBUTING.md +91 -0
- data/Dockerfile +19 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +23 -0
- data/README.md +187 -0
- data/Rakefile +26 -0
- data/bin/mcs +3 -0
- data/bin/mtncloud +27 -0
- data/lib/mtncloud/api/account_groups_interface.rb +48 -0
- data/lib/mtncloud/api/account_users_interface.rb +68 -0
- data/lib/mtncloud/api/accounts_interface.rb +9 -0
- data/lib/mtncloud/api/activity_interface.rb +9 -0
- data/lib/mtncloud/api/affinity_groups_interface.rb +46 -0
- data/lib/mtncloud/api/api_client.rb +1091 -0
- data/lib/mtncloud/api/appliance_settings_interface.rb +49 -0
- data/lib/mtncloud/api/approvals_interface.rb +32 -0
- data/lib/mtncloud/api/apps_interface.rb +180 -0
- data/lib/mtncloud/api/archive_buckets_interface.rb +116 -0
- data/lib/mtncloud/api/archive_files_interface.rb +173 -0
- data/lib/mtncloud/api/audit_interface.rb +9 -0
- data/lib/mtncloud/api/auth_interface.rb +58 -0
- data/lib/mtncloud/api/backup_jobs_interface.rb +13 -0
- data/lib/mtncloud/api/backup_restores_interface.rb +27 -0
- data/lib/mtncloud/api/backup_results_interface.rb +32 -0
- data/lib/mtncloud/api/backup_service_types_interface.rb +9 -0
- data/lib/mtncloud/api/backup_services_interface.rb +9 -0
- data/lib/mtncloud/api/backup_settings_interface.rb +20 -0
- data/lib/mtncloud/api/backup_types_interface.rb +9 -0
- data/lib/mtncloud/api/backups_interface.rb +21 -0
- data/lib/mtncloud/api/billing_interface.rb +34 -0
- data/lib/mtncloud/api/blueprints_interface.rb +70 -0
- data/lib/mtncloud/api/body_io.rb +22 -0
- data/lib/mtncloud/api/budgets_interface.rb +48 -0
- data/lib/mtncloud/api/catalog_item_types_interface.rb +29 -0
- data/lib/mtncloud/api/certificate_types_interface.rb +14 -0
- data/lib/mtncloud/api/certificates_interface.rb +9 -0
- data/lib/mtncloud/api/clients_interface.rb +41 -0
- data/lib/mtncloud/api/cloud_datastores_interface.rb +48 -0
- data/lib/mtncloud/api/cloud_folders_interface.rb +41 -0
- data/lib/mtncloud/api/cloud_policies_interface.rb +41 -0
- data/lib/mtncloud/api/cloud_resource_pools_interface.rb +66 -0
- data/lib/mtncloud/api/clouds_interface.rb +217 -0
- data/lib/mtncloud/api/clusters_interface.rb +471 -0
- data/lib/mtncloud/api/containers_interface.rb +145 -0
- data/lib/mtncloud/api/credential_types_interface.rb +9 -0
- data/lib/mtncloud/api/credentials_interface.rb +9 -0
- data/lib/mtncloud/api/custom_instance_types_interface.rb +99 -0
- data/lib/mtncloud/api/cypher_interface.rb +51 -0
- data/lib/mtncloud/api/dashboard_interface.rb +14 -0
- data/lib/mtncloud/api/datastores_interface.rb +21 -0
- data/lib/mtncloud/api/deploy_interface.rb +44 -0
- data/lib/mtncloud/api/deployments_interface.rb +79 -0
- data/lib/mtncloud/api/distributed_workers_interface.rb +41 -0
- data/lib/mtncloud/api/email_templates_interface.rb +53 -0
- data/lib/mtncloud/api/environments_interface.rb +48 -0
- data/lib/mtncloud/api/execute_schedules_interface.rb +71 -0
- data/lib/mtncloud/api/execution_request_interface.rb +27 -0
- data/lib/mtncloud/api/file_copy_request_interface.rb +68 -0
- data/lib/mtncloud/api/forgot_password_interface.rb +17 -0
- data/lib/mtncloud/api/group_policies_interface.rb +41 -0
- data/lib/mtncloud/api/groups_interface.rb +73 -0
- data/lib/mtncloud/api/guidance_interface.rb +44 -0
- data/lib/mtncloud/api/guidance_settings_interface.rb +17 -0
- data/lib/mtncloud/api/health_interface.rb +100 -0
- data/lib/mtncloud/api/host_vm_groups_interface.rb +37 -0
- data/lib/mtncloud/api/hub_interface.rb +25 -0
- data/lib/mtncloud/api/image_builder_boot_scripts_interface.rb +41 -0
- data/lib/mtncloud/api/image_builder_image_builds_interface.rb +73 -0
- data/lib/mtncloud/api/image_builder_interface.rb +20 -0
- data/lib/mtncloud/api/image_builder_preseed_scripts_interface.rb +41 -0
- data/lib/mtncloud/api/instance_types_interface.rb +20 -0
- data/lib/mtncloud/api/instances_interface.rb +453 -0
- data/lib/mtncloud/api/integration_types_interface.rb +14 -0
- data/lib/mtncloud/api/integrations_interface.rb +74 -0
- data/lib/mtncloud/api/invoice_line_items_interface.rb +9 -0
- data/lib/mtncloud/api/invoices_interface.rb +28 -0
- data/lib/mtncloud/api/jobs_interface.rb +83 -0
- data/lib/mtncloud/api/key_pairs_interface.rb +57 -0
- data/lib/mtncloud/api/library_cluster_layouts_interface.rb +47 -0
- data/lib/mtncloud/api/library_cluster_packages_interface.rb +60 -0
- data/lib/mtncloud/api/library_container_scripts_interface.rb +43 -0
- data/lib/mtncloud/api/library_container_templates_interface.rb +43 -0
- data/lib/mtncloud/api/library_container_types_interface.rb +59 -0
- data/lib/mtncloud/api/library_container_upgrades_interface.rb +60 -0
- data/lib/mtncloud/api/library_instance_types_interface.rb +74 -0
- data/lib/mtncloud/api/library_layouts_interface.rb +69 -0
- data/lib/mtncloud/api/library_operating_systems_interface.rb +63 -0
- data/lib/mtncloud/api/library_spec_template_types_interface.rb +43 -0
- data/lib/mtncloud/api/library_spec_templates_interface.rb +43 -0
- data/lib/mtncloud/api/license_interface.rb +30 -0
- data/lib/mtncloud/api/load_balancer_monitors_interface.rb +9 -0
- data/lib/mtncloud/api/load_balancer_pool_nodes_interface.rb +8 -0
- data/lib/mtncloud/api/load_balancer_pools_interface.rb +9 -0
- data/lib/mtncloud/api/load_balancer_pools_secondary_interface.rb +9 -0
- data/lib/mtncloud/api/load_balancer_profiles_interface.rb +9 -0
- data/lib/mtncloud/api/load_balancer_types_interface.rb +9 -0
- data/lib/mtncloud/api/load_balancer_virtual_servers_interface.rb +18 -0
- data/lib/mtncloud/api/load_balancers_interface.rb +14 -0
- data/lib/mtncloud/api/log_settings_interface.rb +44 -0
- data/lib/mtncloud/api/logs_interface.rb +37 -0
- data/lib/mtncloud/api/migrations_interface.rb +49 -0
- data/lib/mtncloud/api/monitoring_alerts_interface.rb +39 -0
- data/lib/mtncloud/api/monitoring_apps_interface.rb +69 -0
- data/lib/mtncloud/api/monitoring_checks_interface.rb +103 -0
- data/lib/mtncloud/api/monitoring_contacts_interface.rb +41 -0
- data/lib/mtncloud/api/monitoring_groups_interface.rb +77 -0
- data/lib/mtncloud/api/monitoring_incidents_interface.rb +107 -0
- data/lib/mtncloud/api/monitoring_interface.rb +35 -0
- data/lib/mtncloud/api/monitoring_settings_interface.rb +21 -0
- data/lib/mtncloud/api/network_dhcp_relays_interface.rb +36 -0
- data/lib/mtncloud/api/network_dhcp_servers_interface.rb +36 -0
- data/lib/mtncloud/api/network_domain_records_interface.rb +41 -0
- data/lib/mtncloud/api/network_domains_interface.rb +41 -0
- data/lib/mtncloud/api/network_edge_clusters_interface.rb +26 -0
- data/lib/mtncloud/api/network_floating_ips_interface.rb +40 -0
- data/lib/mtncloud/api/network_groups_interface.rb +41 -0
- data/lib/mtncloud/api/network_pool_ips_interface.rb +41 -0
- data/lib/mtncloud/api/network_pool_server_types_interface.rb +9 -0
- data/lib/mtncloud/api/network_pool_servers_interface.rb +48 -0
- data/lib/mtncloud/api/network_pools_interface.rb +41 -0
- data/lib/mtncloud/api/network_proxies_interface.rb +41 -0
- data/lib/mtncloud/api/network_routers_interface.rb +181 -0
- data/lib/mtncloud/api/network_security_server_types_interface.rb +9 -0
- data/lib/mtncloud/api/network_security_servers_interface.rb +27 -0
- data/lib/mtncloud/api/network_server_groups_interface.rb +7 -0
- data/lib/mtncloud/api/network_server_types_interface.rb +9 -0
- data/lib/mtncloud/api/network_servers_interface.rb +102 -0
- data/lib/mtncloud/api/network_services_interface.rb +63 -0
- data/lib/mtncloud/api/network_static_routes_interface.rb +36 -0
- data/lib/mtncloud/api/network_subnets_interface.rb +42 -0
- data/lib/mtncloud/api/network_types_interface.rb +20 -0
- data/lib/mtncloud/api/networks_interface.rb +48 -0
- data/lib/mtncloud/api/option_type_forms_interface.rb +9 -0
- data/lib/mtncloud/api/option_type_lists_interface.rb +53 -0
- data/lib/mtncloud/api/option_types_interface.rb +41 -0
- data/lib/mtncloud/api/options_interface.rb +17 -0
- data/lib/mtncloud/api/packages_interface.rb +112 -0
- data/lib/mtncloud/api/ping_interface.rb +22 -0
- data/lib/mtncloud/api/plugins_interface.rb +22 -0
- data/lib/mtncloud/api/policies_interface.rb +56 -0
- data/lib/mtncloud/api/power_schedules_interface.rb +71 -0
- data/lib/mtncloud/api/price_sets_interface.rb +39 -0
- data/lib/mtncloud/api/prices_interface.rb +71 -0
- data/lib/mtncloud/api/processes_interface.rb +40 -0
- data/lib/mtncloud/api/projects_interface.rb +33 -0
- data/lib/mtncloud/api/provision_types_interface.rb +24 -0
- data/lib/mtncloud/api/provisioning_license_types_interface.rb +31 -0
- data/lib/mtncloud/api/provisioning_licenses_interface.rb +60 -0
- data/lib/mtncloud/api/provisioning_settings_interface.rb +26 -0
- data/lib/mtncloud/api/read_interface.rb +24 -0
- data/lib/mtncloud/api/reports_interface.rb +70 -0
- data/lib/mtncloud/api/resource_pool_groups_interface.rb +51 -0
- data/lib/mtncloud/api/rest_interface.rb +37 -0
- data/lib/mtncloud/api/roles_interface.rb +151 -0
- data/lib/mtncloud/api/scale_thresholds_interface.rb +9 -0
- data/lib/mtncloud/api/search_interface.rb +13 -0
- data/lib/mtncloud/api/secondary_read_interface.rb +25 -0
- data/lib/mtncloud/api/secondary_rest_interface.rb +42 -0
- data/lib/mtncloud/api/security_group_rules_interface.rb +35 -0
- data/lib/mtncloud/api/security_groups_interface.rb +56 -0
- data/lib/mtncloud/api/security_package_types_interface.rb +9 -0
- data/lib/mtncloud/api/security_packages_interface.rb +9 -0
- data/lib/mtncloud/api/security_scans_interface.rb +9 -0
- data/lib/mtncloud/api/server_devices_interface.rb +30 -0
- data/lib/mtncloud/api/server_types_interface.rb +20 -0
- data/lib/mtncloud/api/servers_interface.rb +230 -0
- data/lib/mtncloud/api/service_catalog_interface.rb +89 -0
- data/lib/mtncloud/api/service_plans_interface.rb +62 -0
- data/lib/mtncloud/api/setup_interface.rb +46 -0
- data/lib/mtncloud/api/snapshots_interface.rb +19 -0
- data/lib/mtncloud/api/storage_datastores_interface.rb +44 -0
- data/lib/mtncloud/api/storage_providers_interface.rb +151 -0
- data/lib/mtncloud/api/storage_server_types_interface.rb +14 -0
- data/lib/mtncloud/api/storage_servers_interface.rb +9 -0
- data/lib/mtncloud/api/storage_volume_types_interface.rb +9 -0
- data/lib/mtncloud/api/storage_volumes_interface.rb +24 -0
- data/lib/mtncloud/api/subnet_types_interface.rb +20 -0
- data/lib/mtncloud/api/subnets_interface.rb +41 -0
- data/lib/mtncloud/api/support_bundles_interface.rb +46 -0
- data/lib/mtncloud/api/system_types_interface.rb +13 -0
- data/lib/mtncloud/api/systems_interface.rb +55 -0
- data/lib/mtncloud/api/task_sets_interface.rb +52 -0
- data/lib/mtncloud/api/tasks_interface.rb +66 -0
- data/lib/mtncloud/api/tokens_interface.rb +39 -0
- data/lib/mtncloud/api/usage_interface.rb +18 -0
- data/lib/mtncloud/api/user_groups_interface.rb +59 -0
- data/lib/mtncloud/api/user_settings_interface.rb +90 -0
- data/lib/mtncloud/api/user_sources_interface.rb +99 -0
- data/lib/mtncloud/api/users_interface.rb +33 -0
- data/lib/mtncloud/api/vdi_allocations_interface.rb +9 -0
- data/lib/mtncloud/api/vdi_apps_interface.rb +9 -0
- data/lib/mtncloud/api/vdi_gateways_interface.rb +9 -0
- data/lib/mtncloud/api/vdi_interface.rb +28 -0
- data/lib/mtncloud/api/vdi_pools_interface.rb +19 -0
- data/lib/mtncloud/api/virtual_images_interface.rb +210 -0
- data/lib/mtncloud/api/virtual_servers_interface.rb +9 -0
- data/lib/mtncloud/api/virtual_switches_interface.rb +9 -0
- data/lib/mtncloud/api/whitelabel_settings_interface.rb +57 -0
- data/lib/mtncloud/api/whoami_interface.rb +13 -0
- data/lib/mtncloud/api/wiki_interface.rb +48 -0
- data/lib/mtncloud/api.rb +12 -0
- data/lib/mtncloud/benchmarking.rb +259 -0
- data/lib/mtncloud/cli/cli_command.rb +2281 -0
- data/lib/mtncloud/cli/cli_registry.rb +337 -0
- data/lib/mtncloud/cli/commands/access_token_command.rb +201 -0
- data/lib/mtncloud/cli/commands/account_groups_command.rb +530 -0
- data/lib/mtncloud/cli/commands/activity_command.rb +149 -0
- data/lib/mtncloud/cli/commands/affinity_groups_command.rb +554 -0
- data/lib/mtncloud/cli/commands/alias_command.rb +278 -0
- data/lib/mtncloud/cli/commands/appliance_settings_command.rb +382 -0
- data/lib/mtncloud/cli/commands/approvals_command.rb +236 -0
- data/lib/mtncloud/cli/commands/apps.rb +2549 -0
- data/lib/mtncloud/cli/commands/archives_command.rb +2161 -0
- data/lib/mtncloud/cli/commands/audit.rb +188 -0
- data/lib/mtncloud/cli/commands/backup_jobs_command.rb +366 -0
- data/lib/mtncloud/cli/commands/backup_restores_command.rb +144 -0
- data/lib/mtncloud/cli/commands/backup_results_command.rb +149 -0
- data/lib/mtncloud/cli/commands/backup_services_command.rb +44 -0
- data/lib/mtncloud/cli/commands/backup_settings_command.rb +184 -0
- data/lib/mtncloud/cli/commands/backup_types_command.rb +53 -0
- data/lib/mtncloud/cli/commands/backups_command.rb +674 -0
- data/lib/mtncloud/cli/commands/benchmark_command.rb +458 -0
- data/lib/mtncloud/cli/commands/blueprints_command.rb +2297 -0
- data/lib/mtncloud/cli/commands/boot_scripts_command.rb +379 -0
- data/lib/mtncloud/cli/commands/budgets_command.rb +754 -0
- data/lib/mtncloud/cli/commands/cat_command.rb +45 -0
- data/lib/mtncloud/cli/commands/catalog_item_types_command.rb +858 -0
- data/lib/mtncloud/cli/commands/certificates_command.rb +575 -0
- data/lib/mtncloud/cli/commands/change_password_command.rb +132 -0
- data/lib/mtncloud/cli/commands/clients_command.rb +331 -0
- data/lib/mtncloud/cli/commands/cloud_datastores_command.rb +543 -0
- data/lib/mtncloud/cli/commands/cloud_folders_command.rb +512 -0
- data/lib/mtncloud/cli/commands/cloud_resource_pools_command.rb +870 -0
- data/lib/mtncloud/cli/commands/clouds.rb +2037 -0
- data/lib/mtncloud/cli/commands/clouds_types.rb +140 -0
- data/lib/mtncloud/cli/commands/cluster_types.rb +179 -0
- data/lib/mtncloud/cli/commands/clusters.rb +5855 -0
- data/lib/mtncloud/cli/commands/coloring_command.rb +82 -0
- data/lib/mtncloud/cli/commands/containers_command.rb +967 -0
- data/lib/mtncloud/cli/commands/credential_types_command.rb +36 -0
- data/lib/mtncloud/cli/commands/credentials_command.rb +124 -0
- data/lib/mtncloud/cli/commands/curl_command.rb +168 -0
- data/lib/mtncloud/cli/commands/cypher_command.rb +587 -0
- data/lib/mtncloud/cli/commands/dashboard_command.rb +300 -0
- data/lib/mtncloud/cli/commands/debug_command.rb +75 -0
- data/lib/mtncloud/cli/commands/deploy.rb +485 -0
- data/lib/mtncloud/cli/commands/deployments.rb +923 -0
- data/lib/mtncloud/cli/commands/deploys.rb +485 -0
- data/lib/mtncloud/cli/commands/distributed_workers_command.rb +282 -0
- data/lib/mtncloud/cli/commands/echo_command.rb +61 -0
- data/lib/mtncloud/cli/commands/edit_profile_command.rb +57 -0
- data/lib/mtncloud/cli/commands/edit_rc_command.rb +77 -0
- data/lib/mtncloud/cli/commands/email_templates_command.rb +373 -0
- data/lib/mtncloud/cli/commands/environments_command.rb +401 -0
- data/lib/mtncloud/cli/commands/execute_schedules_command.rb +735 -0
- data/lib/mtncloud/cli/commands/execution_request_command.rb +333 -0
- data/lib/mtncloud/cli/commands/exit_command.rb +34 -0
- data/lib/mtncloud/cli/commands/file_copy_request_command.rb +352 -0
- data/lib/mtncloud/cli/commands/forgot_password.rb +133 -0
- data/lib/mtncloud/cli/commands/get_prompt_command.rb +36 -0
- data/lib/mtncloud/cli/commands/groups.rb +818 -0
- data/lib/mtncloud/cli/commands/guidance_command.rb +529 -0
- data/lib/mtncloud/cli/commands/guidance_settings.rb +148 -0
- data/lib/mtncloud/cli/commands/health_command.rb +1046 -0
- data/lib/mtncloud/cli/commands/history_command.rb +60 -0
- data/lib/mtncloud/cli/commands/host_vm_groups_command.rb +423 -0
- data/lib/mtncloud/cli/commands/hosts.rb +2986 -0
- data/lib/mtncloud/cli/commands/hub.rb +215 -0
- data/lib/mtncloud/cli/commands/image_builder_command.rb +1197 -0
- data/lib/mtncloud/cli/commands/instance_types.rb +163 -0
- data/lib/mtncloud/cli/commands/instances.rb +5813 -0
- data/lib/mtncloud/cli/commands/integrations_command.rb +1412 -0
- data/lib/mtncloud/cli/commands/invoices_command.rb +1151 -0
- data/lib/mtncloud/cli/commands/jobs_command.rb +998 -0
- data/lib/mtncloud/cli/commands/key_pairs.rb +470 -0
- data/lib/mtncloud/cli/commands/library_cluster_layouts_command.rb +901 -0
- data/lib/mtncloud/cli/commands/library_cluster_packages_command.rb +552 -0
- data/lib/mtncloud/cli/commands/library_container_scripts_command.rb +446 -0
- data/lib/mtncloud/cli/commands/library_container_templates_command.rb +526 -0
- data/lib/mtncloud/cli/commands/library_container_types_command.rb +698 -0
- data/lib/mtncloud/cli/commands/library_forms_command.rb +625 -0
- data/lib/mtncloud/cli/commands/library_instance_types_command.rb +668 -0
- data/lib/mtncloud/cli/commands/library_layouts_command.rb +849 -0
- data/lib/mtncloud/cli/commands/library_operating_systems_command.rb +671 -0
- data/lib/mtncloud/cli/commands/library_option_lists_command.rb +503 -0
- data/lib/mtncloud/cli/commands/library_option_types_command.rb +329 -0
- data/lib/mtncloud/cli/commands/library_spec_templates_command.rb +547 -0
- data/lib/mtncloud/cli/commands/library_upgrades_command.rb +596 -0
- data/lib/mtncloud/cli/commands/license.rb +475 -0
- data/lib/mtncloud/cli/commands/load_balancer_monitors.rb +70 -0
- data/lib/mtncloud/cli/commands/load_balancer_pool_nodes.rb +87 -0
- data/lib/mtncloud/cli/commands/load_balancer_pools.rb +129 -0
- data/lib/mtncloud/cli/commands/load_balancer_profiles.rb +64 -0
- data/lib/mtncloud/cli/commands/load_balancer_types.rb +38 -0
- data/lib/mtncloud/cli/commands/load_balancer_virtual_servers.rb +147 -0
- data/lib/mtncloud/cli/commands/load_balancers.rb +189 -0
- data/lib/mtncloud/cli/commands/log_level_command.rb +54 -0
- data/lib/mtncloud/cli/commands/log_settings_command.rb +443 -0
- data/lib/mtncloud/cli/commands/login.rb +148 -0
- data/lib/mtncloud/cli/commands/logout.rb +63 -0
- data/lib/mtncloud/cli/commands/logs_command.rb +140 -0
- data/lib/mtncloud/cli/commands/man_command.rb +409 -0
- data/lib/mtncloud/cli/commands/migrations.rb +453 -0
- data/lib/mtncloud/cli/commands/monitoring_alerts_command.rb +791 -0
- data/lib/mtncloud/cli/commands/monitoring_apps_command.rb +716 -0
- data/lib/mtncloud/cli/commands/monitoring_checks_command.rb +766 -0
- data/lib/mtncloud/cli/commands/monitoring_contacts_command.rb +339 -0
- data/lib/mtncloud/cli/commands/monitoring_groups_command.rb +674 -0
- data/lib/mtncloud/cli/commands/monitoring_incidents_command.rb +835 -0
- data/lib/mtncloud/cli/commands/monitoring_settings.rb +212 -0
- data/lib/mtncloud/cli/commands/network_dhcp_relays_command.rb +375 -0
- data/lib/mtncloud/cli/commands/network_dhcp_servers_command.rb +366 -0
- data/lib/mtncloud/cli/commands/network_domains_command.rb +896 -0
- data/lib/mtncloud/cli/commands/network_edge_clusters_command.rb +288 -0
- data/lib/mtncloud/cli/commands/network_firewalls_command.rb +783 -0
- data/lib/mtncloud/cli/commands/network_floating_ips.rb +147 -0
- data/lib/mtncloud/cli/commands/network_groups_command.rb +654 -0
- data/lib/mtncloud/cli/commands/network_pool_server_types.rb +20 -0
- data/lib/mtncloud/cli/commands/network_pool_servers_command.rb +318 -0
- data/lib/mtncloud/cli/commands/network_pools_command.rb +903 -0
- data/lib/mtncloud/cli/commands/network_proxies_command.rb +578 -0
- data/lib/mtncloud/cli/commands/network_routers_command.rb +2628 -0
- data/lib/mtncloud/cli/commands/network_security_server_types.rb +20 -0
- data/lib/mtncloud/cli/commands/network_server_groups_command.rb +222 -0
- data/lib/mtncloud/cli/commands/network_server_types_command.rb +20 -0
- data/lib/mtncloud/cli/commands/network_servers_command.rb +398 -0
- data/lib/mtncloud/cli/commands/network_services_command.rb +198 -0
- data/lib/mtncloud/cli/commands/network_static_routes_command.rb +451 -0
- data/lib/mtncloud/cli/commands/network_transport_zones_command.rb +412 -0
- data/lib/mtncloud/cli/commands/networks_command.rb +1692 -0
- data/lib/mtncloud/cli/commands/open_command.rb +30 -0
- data/lib/mtncloud/cli/commands/options.rb +231 -0
- data/lib/mtncloud/cli/commands/packages_command.rb +822 -0
- data/lib/mtncloud/cli/commands/ping.rb +242 -0
- data/lib/mtncloud/cli/commands/plugins.rb +214 -0
- data/lib/mtncloud/cli/commands/policies_command.rb +990 -0
- data/lib/mtncloud/cli/commands/power_schedules_command.rb +731 -0
- data/lib/mtncloud/cli/commands/preseed_scripts_command.rb +378 -0
- data/lib/mtncloud/cli/commands/price_sets_command.rb +557 -0
- data/lib/mtncloud/cli/commands/prices_command.rb +692 -0
- data/lib/mtncloud/cli/commands/processes_command.rb +469 -0
- data/lib/mtncloud/cli/commands/projects_command.rb +537 -0
- data/lib/mtncloud/cli/commands/provisioning_licenses_command.rb +509 -0
- data/lib/mtncloud/cli/commands/provisioning_settings_command.rb +238 -0
- data/lib/mtncloud/cli/commands/recent_activity_command.rb +171 -0
- data/lib/mtncloud/cli/commands/remote.rb +1818 -0
- data/lib/mtncloud/cli/commands/reports_command.rb +724 -0
- data/lib/mtncloud/cli/commands/resource_pool_groups_command.rb +586 -0
- data/lib/mtncloud/cli/commands/rm_command.rb +14 -0
- data/lib/mtncloud/cli/commands/roles.rb +3120 -0
- data/lib/mtncloud/cli/commands/scale_thresholds.rb +103 -0
- data/lib/mtncloud/cli/commands/search_command.rb +184 -0
- data/lib/mtncloud/cli/commands/security_group_rules.rb +230 -0
- data/lib/mtncloud/cli/commands/security_groups.rb +1294 -0
- data/lib/mtncloud/cli/commands/security_package_types.rb +32 -0
- data/lib/mtncloud/cli/commands/security_packages.rb +84 -0
- data/lib/mtncloud/cli/commands/security_scans.rb +107 -0
- data/lib/mtncloud/cli/commands/self_service_command.rb +17 -0
- data/lib/mtncloud/cli/commands/server_devices_command.rb +207 -0
- data/lib/mtncloud/cli/commands/service_catalog_command.rb +1528 -0
- data/lib/mtncloud/cli/commands/service_plans_command.rb +895 -0
- data/lib/mtncloud/cli/commands/set_prompt_command.rb +51 -0
- data/lib/mtncloud/cli/commands/setup.rb +423 -0
- data/lib/mtncloud/cli/commands/shell.rb +717 -0
- data/lib/mtncloud/cli/commands/sleep_command.rb +43 -0
- data/lib/mtncloud/cli/commands/snapshots.rb +156 -0
- data/lib/mtncloud/cli/commands/source_command.rb +30 -0
- data/lib/mtncloud/cli/commands/ssl_verification_command.rb +47 -0
- data/lib/mtncloud/cli/commands/storage_datastores.rb +457 -0
- data/lib/mtncloud/cli/commands/storage_providers_command.rb +1401 -0
- data/lib/mtncloud/cli/commands/storage_server_types.rb +45 -0
- data/lib/mtncloud/cli/commands/storage_servers.rb +116 -0
- data/lib/mtncloud/cli/commands/storage_volume_types.rb +45 -0
- data/lib/mtncloud/cli/commands/storage_volumes.rb +236 -0
- data/lib/mtncloud/cli/commands/subnets_command.rb +819 -0
- data/lib/mtncloud/cli/commands/support_bundles_command.rb +606 -0
- data/lib/mtncloud/cli/commands/systems.rb +1203 -0
- data/lib/mtncloud/cli/commands/tasks.rb +1391 -0
- data/lib/mtncloud/cli/commands/tee_command.rb +14 -0
- data/lib/mtncloud/cli/commands/tenants_command.rb +315 -0
- data/lib/mtncloud/cli/commands/tokens_command.rb +391 -0
- data/lib/mtncloud/cli/commands/update_command.rb +46 -0
- data/lib/mtncloud/cli/commands/usage_command.rb +203 -0
- data/lib/mtncloud/cli/commands/user_groups_command.rb +512 -0
- data/lib/mtncloud/cli/commands/user_settings_command.rb +849 -0
- data/lib/mtncloud/cli/commands/user_sources_command.rb +1065 -0
- data/lib/mtncloud/cli/commands/users.rb +897 -0
- data/lib/mtncloud/cli/commands/vdi_allocations_command.rb +159 -0
- data/lib/mtncloud/cli/commands/vdi_apps_command.rb +317 -0
- data/lib/mtncloud/cli/commands/vdi_command.rb +359 -0
- data/lib/mtncloud/cli/commands/vdi_gateways_command.rb +290 -0
- data/lib/mtncloud/cli/commands/vdi_pools_command.rb +574 -0
- data/lib/mtncloud/cli/commands/version_command.rb +38 -0
- data/lib/mtncloud/cli/commands/view.rb +107 -0
- data/lib/mtncloud/cli/commands/virtual_images.rb +1362 -0
- data/lib/mtncloud/cli/commands/virtual_switches_command.rb +336 -0
- data/lib/mtncloud/cli/commands/whitelabel_settings_command.rb +653 -0
- data/lib/mtncloud/cli/commands/whoami.rb +323 -0
- data/lib/mtncloud/cli/commands/wiki_command.rb +448 -0
- data/lib/mtncloud/cli/commands/workflows.rb +1022 -0
- data/lib/mtncloud/cli/credentials.rb +482 -0
- data/lib/mtncloud/cli/dot_file.rb +180 -0
- data/lib/mtncloud/cli/error_handler.rb +307 -0
- data/lib/mtncloud/cli/errors.rb +53 -0
- data/lib/mtncloud/cli/expression_parser.rb +153 -0
- data/lib/mtncloud/cli/mixins/accounts_helper.rb +484 -0
- data/lib/mtncloud/cli/mixins/affinity_helper.rb +118 -0
- data/lib/mtncloud/cli/mixins/backups_helper.rb +200 -0
- data/lib/mtncloud/cli/mixins/deployments_helper.rb +163 -0
- data/lib/mtncloud/cli/mixins/execution_request_helper.rb +50 -0
- data/lib/mtncloud/cli/mixins/infrastructure_helper.rb +966 -0
- data/lib/mtncloud/cli/mixins/jobs_helper.rb +202 -0
- data/lib/mtncloud/cli/mixins/library_helper.rb +539 -0
- data/lib/mtncloud/cli/mixins/load_balancers_helper.rb +176 -0
- data/lib/mtncloud/cli/mixins/logs_helper.rb +131 -0
- data/lib/mtncloud/cli/mixins/monitoring_helper.rb +876 -0
- data/lib/mtncloud/cli/mixins/networks_helper.rb +62 -0
- data/lib/mtncloud/cli/mixins/operations_helper.rb +41 -0
- data/lib/mtncloud/cli/mixins/option_source_helper.rb +254 -0
- data/lib/mtncloud/cli/mixins/print_helper.rb +1631 -0
- data/lib/mtncloud/cli/mixins/processes_helper.rb +286 -0
- data/lib/mtncloud/cli/mixins/prompt_helper.rb +136 -0
- data/lib/mtncloud/cli/mixins/provisioning_helper.rb +2963 -0
- data/lib/mtncloud/cli/mixins/remote_helper.rb +139 -0
- data/lib/mtncloud/cli/mixins/rest_command.rb +994 -0
- data/lib/mtncloud/cli/mixins/secondary_rest_command.rb +700 -0
- data/lib/mtncloud/cli/mixins/storage_servers_helper.rb +93 -0
- data/lib/mtncloud/cli/mixins/storage_volumes_helper.rb +76 -0
- data/lib/mtncloud/cli/mixins/vdi_helper.rb +246 -0
- data/lib/mtncloud/cli/mixins/whoami_helper.rb +73 -0
- data/lib/mtncloud/cli/option_parser.rb +127 -0
- data/lib/mtncloud/cli/option_types.rb +1622 -0
- data/lib/mtncloud/cli/version.rb +6 -0
- data/lib/mtncloud/cli.rb +105 -0
- data/lib/mtncloud/currency.rb +184 -0
- data/lib/mtncloud/ext/hash.rb +109 -0
- data/lib/mtncloud/ext/nil_class.rb +5 -0
- data/lib/mtncloud/ext/rest_client.rb +37 -0
- data/lib/mtncloud/ext/string.rb +66 -0
- data/lib/mtncloud/formatters.rb +511 -0
- data/lib/mtncloud/logging.rb +185 -0
- data/lib/mtncloud/morpkg.rb +119 -0
- data/lib/mtncloud/rest_client.rb +104 -0
- data/lib/mtncloud/routes.rb +304 -0
- data/lib/mtncloud/terminal.rb +528 -0
- data/lib/mtncloud/util.rb +29 -0
- data/lib/mtncloud.rb +5 -0
- data/mtncloud-cli.gemspec +38 -0
- data/test/api/affinity_groups_interface_test.rb +43 -0
- data/test/api/clients_interface_test.rb +23 -0
- data/test/api/clouds_interface_test.rb +67 -0
- data/test/api/containers_interface_test.rb +68 -0
- data/test/api/host_vm_groups_interface_test.rb +35 -0
- data/test/api/instances_interface_test.rb +22 -0
- data/test/api/network_routers_interface_test.rb +22 -0
- data/test/api/systems_interface_test.rb +26 -0
- data/test/api/whoami_interface_test.rb +14 -0
- data/test/branding_test.rb +160 -0
- data/test/cli/access_token_test.rb +36 -0
- data/test/cli/affinity_groups_cloud_cluster_scope_test.rb +270 -0
- data/test/cli/affinity_groups_cluster_scope_test.rb +171 -0
- data/test/cli/affinity_groups_test.rb +57 -0
- data/test/cli/affinity_groups_violations_scope_test.rb +141 -0
- data/test/cli/affinity_helper_test.rb +367 -0
- data/test/cli/auth_test.rb +88 -0
- data/test/cli/backups_test.rb +212 -0
- data/test/cli/cli_test.rb +48 -0
- data/test/cli/clients_test.rb +45 -0
- data/test/cli/clusters_uuid_test.rb +146 -0
- data/test/cli/containers_test.rb +92 -0
- data/test/cli/distributed_workers_test.rb +68 -0
- data/test/cli/help_test.rb +25 -0
- data/test/cli/host_vm_groups_cluster_scope_test.rb +187 -0
- data/test/cli/host_vm_groups_test.rb +63 -0
- data/test/cli/infrastructure_helper_cluster_resolver_test.rb +250 -0
- data/test/cli/instances_test.rb +37 -0
- data/test/cli/man_test.rb +14 -0
- data/test/cli/migrations_test.rb +39 -0
- data/test/cli/network_routers_test.rb +65 -0
- data/test/cli/remote_test.rb +89 -0
- data/test/cli/roles_test.rb +47 -0
- data/test/cli/shell_test.rb +81 -0
- data/test/cli/storage_volumes_test.rb +79 -0
- data/test/cli/systems_test.rb +206 -0
- data/test/cli/version_test.rb +23 -0
- data/test/cli/view_test.rb +55 -0
- data/test/cli/whoami_test.rb +17 -0
- data/test/mtncloud_test.rb +16 -0
- data/test/test_case.rb +342 -0
- data/test/test_config.rb +137 -0
- data/test/test_data_helper.rb +97 -0
- metadata +807 -0
|
@@ -0,0 +1,3120 @@
|
|
|
1
|
+
require 'mtncloud/cli/cli_command'
|
|
2
|
+
|
|
3
|
+
class MtnCloud::Cli::Roles
|
|
4
|
+
include MtnCloud::Cli::CliCommand
|
|
5
|
+
include MtnCloud::Cli::AccountsHelper
|
|
6
|
+
include MtnCloud::Cli::ProvisioningHelper
|
|
7
|
+
include MtnCloud::Cli::WhoamiHelper
|
|
8
|
+
register_subcommands :list, :get, :add, :update, :remove, :validate,
|
|
9
|
+
:'list-permissions', :'update-feature-access',
|
|
10
|
+
:'update-group-access', :'update-global-group-access', :'update-default-group-access',
|
|
11
|
+
:'update-global-cloud-access', :'update-cloud-access', :'update-default-cloud-access',
|
|
12
|
+
:'update-global-instance-type-access', :'update-instance-type-access', :'update-default-instance-type-access',
|
|
13
|
+
:'update-global-blueprint-access', :'update-blueprint-access', :'update-default-blueprint-access',
|
|
14
|
+
:'update-global-catalog-item-type-access', :'update-catalog-item-type-access', :'update-default-catalog-item-type-access',
|
|
15
|
+
:'update-persona-access', :'update-default-persona-access',
|
|
16
|
+
:'update-global-vdi-pool-access', :'update-vdi-pool-access', :'update-default-vdi-pool-access',
|
|
17
|
+
:'update-global-report-type-access', :'update-report-type-access', :'update-default-report-type-access',
|
|
18
|
+
:'update-global-task-access', :'update-task-access', :'update-default-task-access',
|
|
19
|
+
:'update-global-workflow-access', :'update-workflow-access', :'update-default-workflow-access',
|
|
20
|
+
:'update-cluster-type-access', :'update-default-cluster-type-access'
|
|
21
|
+
set_subcommands_hidden(
|
|
22
|
+
subcommands.keys.select{|c|
|
|
23
|
+
c.include?('update-global')
|
|
24
|
+
})
|
|
25
|
+
alias_subcommand :details, :get
|
|
26
|
+
set_default_subcommand :list
|
|
27
|
+
|
|
28
|
+
def connect(opts)
|
|
29
|
+
@api_client = establish_remote_appliance_connection(opts)
|
|
30
|
+
@whoami_interface = @api_client.whoami
|
|
31
|
+
@account_users_interface = @api_client.account_users
|
|
32
|
+
@accounts_interface = @api_client.accounts
|
|
33
|
+
@roles_interface = @api_client.roles
|
|
34
|
+
@groups_interface = @api_client.groups
|
|
35
|
+
@options_interface = @api_client.options
|
|
36
|
+
@instances_interface = @api_client.instances
|
|
37
|
+
@instance_types_interface = @api_client.instance_types
|
|
38
|
+
@blueprints_interface = @api_client.blueprints
|
|
39
|
+
@active_group_id = MtnCloud::Cli::Groups.active_groups[@appliance_name]
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def handle(args)
|
|
43
|
+
handle_subcommand(args)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def list(args)
|
|
47
|
+
options = {}
|
|
48
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
49
|
+
opts.banner = subcommand_usage("[search phrase]")
|
|
50
|
+
opts.on( '--tenant TENANT', "Tenant Filter for list of Roles." ) do |val|
|
|
51
|
+
options[:account] = val
|
|
52
|
+
end
|
|
53
|
+
build_standard_list_options(opts, options)
|
|
54
|
+
opts.footer = "List roles."
|
|
55
|
+
end
|
|
56
|
+
optparse.parse!(args)
|
|
57
|
+
# verify_args!(args:args, optparse:optparse, count:0)
|
|
58
|
+
options[:phrase] = args.join(" ") if args.count > 0
|
|
59
|
+
connect(options)
|
|
60
|
+
|
|
61
|
+
account = find_account_from_options(options)
|
|
62
|
+
account_id = account ? account['id'] : nil
|
|
63
|
+
params = {}
|
|
64
|
+
params.merge!(parse_list_options(options))
|
|
65
|
+
@roles_interface.setopts(options)
|
|
66
|
+
if options[:dry_run]
|
|
67
|
+
print_dry_run @roles_interface.dry.list(account_id, params), options
|
|
68
|
+
return 0, nil
|
|
69
|
+
end
|
|
70
|
+
load_whoami()
|
|
71
|
+
json_response = @roles_interface.list(account_id, params)
|
|
72
|
+
|
|
73
|
+
render_response(json_response, options, "roles") do
|
|
74
|
+
roles = json_response['roles']
|
|
75
|
+
title = "Roles"
|
|
76
|
+
subtitles = []
|
|
77
|
+
subtitles += parse_list_subtitles(options)
|
|
78
|
+
print_h1 title, subtitles, options
|
|
79
|
+
if roles.empty?
|
|
80
|
+
print cyan,"No roles found.",reset,"\n"
|
|
81
|
+
else
|
|
82
|
+
print cyan
|
|
83
|
+
columns = @is_master_account ? role_column_definitions : subtenant_role_column_definitions
|
|
84
|
+
print as_pretty_table(roles, columns.upcase_keys!, options)
|
|
85
|
+
print_results_pagination(json_response)
|
|
86
|
+
end
|
|
87
|
+
print reset,"\n"
|
|
88
|
+
end
|
|
89
|
+
return 0, nil
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def get(args)
|
|
93
|
+
options = {}
|
|
94
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
95
|
+
opts.banner = subcommand_usage("[role]")
|
|
96
|
+
opts.on('-p','--permissions', "Display Permissions [deprecated]") do |val|
|
|
97
|
+
options[:include_feature_access] = true
|
|
98
|
+
end
|
|
99
|
+
opts.add_hidden_option('-p,')
|
|
100
|
+
opts.on('-f','--feature-access', "Display Feature Access") do |val|
|
|
101
|
+
options[:include_feature_access] = true
|
|
102
|
+
end
|
|
103
|
+
opts.on('-g','--group-access', "Display Group Access") do
|
|
104
|
+
options[:include_group_access] = true
|
|
105
|
+
end
|
|
106
|
+
opts.on('-c','--cloud-access', "Display Cloud Access") do
|
|
107
|
+
options[:include_cloud_access] = true
|
|
108
|
+
end
|
|
109
|
+
opts.on('-i','--instance-type-access', "Display Instance Type Access") do
|
|
110
|
+
options[:include_instance_type_access] = true
|
|
111
|
+
end
|
|
112
|
+
opts.on('-b','--blueprint-access', "Display Blueprint Access") do
|
|
113
|
+
options[:include_blueprint_access] = true
|
|
114
|
+
end
|
|
115
|
+
opts.on(nil,'--catalog-item-type-access', "Display Catalog Item Type Access") do
|
|
116
|
+
options[:include_catalog_item_type_access] = true
|
|
117
|
+
end
|
|
118
|
+
opts.on(nil,'--personas', "Display Persona Access") do
|
|
119
|
+
options[:include_persona_access] = true
|
|
120
|
+
end
|
|
121
|
+
opts.add_hidden_option('--personas')
|
|
122
|
+
opts.on(nil,'--persona-access', "Display Persona Access") do
|
|
123
|
+
options[:include_persona_access] = true
|
|
124
|
+
end
|
|
125
|
+
opts.on(nil,'--vdi-pool-access', "Display VDI Pool Access") do
|
|
126
|
+
options[:include_vdi_pool_access] = true
|
|
127
|
+
end
|
|
128
|
+
opts.on(nil,'--report-type-access', "Display Report Type Access") do
|
|
129
|
+
options[:include_report_type_access] = true
|
|
130
|
+
end
|
|
131
|
+
opts.on(nil,'--workflow-access', "Display Workflow Access") do
|
|
132
|
+
options[:include_workflow_access] = true
|
|
133
|
+
end
|
|
134
|
+
opts.on(nil,'--task-access', "Display Task Access") do
|
|
135
|
+
options[:include_task_access] = true
|
|
136
|
+
end
|
|
137
|
+
opts.on(nil,'--cluster-type-access', "Display Cluster Type Access") do
|
|
138
|
+
options[:include_cluster_type_access] = true
|
|
139
|
+
end
|
|
140
|
+
opts.on('-a','--all', "Display All Access Lists") do
|
|
141
|
+
options[:include_all_access] = true
|
|
142
|
+
end
|
|
143
|
+
opts.on(nil, '--include-default-access', "Include default access levels in the output (returns all available resources)") do
|
|
144
|
+
options[:include_default_access] = true
|
|
145
|
+
end
|
|
146
|
+
opts.on('--account-id ID', String, "Clarify Owner of Role") do |val|
|
|
147
|
+
options[:account_id] = val.to_s
|
|
148
|
+
end
|
|
149
|
+
build_standard_get_options(opts, options)
|
|
150
|
+
opts.footer = <<-EOT
|
|
151
|
+
Get details about a role.
|
|
152
|
+
[role] is required. This is the name (authority) or id of a role.
|
|
153
|
+
EOT
|
|
154
|
+
end
|
|
155
|
+
optparse.parse!(args)
|
|
156
|
+
verify_args!(args:args, optparse:optparse, min:1)
|
|
157
|
+
connect(options)
|
|
158
|
+
id_list = parse_id_list(args)
|
|
159
|
+
return run_command_for_each_arg(id_list) do |arg|
|
|
160
|
+
_get(arg, options)
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def _get(id, options={})
|
|
165
|
+
args = [id] # heh
|
|
166
|
+
params = {}
|
|
167
|
+
account = find_account_from_options(options)
|
|
168
|
+
account_id = account ? account['id'] : nil
|
|
169
|
+
|
|
170
|
+
params.merge!(parse_query_options(options))
|
|
171
|
+
params['includeDefaultAccess'] = true if options[:include_default_access]
|
|
172
|
+
@roles_interface.setopts(options)
|
|
173
|
+
if options[:dry_run]
|
|
174
|
+
if args[0].to_s =~ /\A\d{1,}\Z/
|
|
175
|
+
print_dry_run @roles_interface.dry.get(account_id, args[0].to_i)
|
|
176
|
+
else
|
|
177
|
+
print_dry_run @roles_interface.dry.list(account_id, {name: args[0]})
|
|
178
|
+
end
|
|
179
|
+
return
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
load_whoami()
|
|
183
|
+
json_response = nil
|
|
184
|
+
role = nil
|
|
185
|
+
if args[0].to_s =~ /\A\d{1,}\Z/
|
|
186
|
+
json_response = @roles_interface.get(account_id, args[0].to_i, params)
|
|
187
|
+
role = json_response['role']
|
|
188
|
+
else
|
|
189
|
+
role = find_role_by_name_or_id(account_id, args[0])
|
|
190
|
+
exit 1 if role.nil?
|
|
191
|
+
# refetch from show action, argh
|
|
192
|
+
json_response = @roles_interface.get(account_id, role['id'], params)
|
|
193
|
+
role = json_response['role']
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
render_response(json_response, options, 'role') do
|
|
197
|
+
|
|
198
|
+
print cyan
|
|
199
|
+
print_h1 "Role Details", options
|
|
200
|
+
print cyan
|
|
201
|
+
columns = @is_master_account ? role_column_definitions : subtenant_role_column_definitions
|
|
202
|
+
print_description_list(columns, role, options)
|
|
203
|
+
|
|
204
|
+
print_h2 "Permissions", options
|
|
205
|
+
print cyan
|
|
206
|
+
permissions = json_response['featurePermissions'] || role['permissions'] || []
|
|
207
|
+
if options[:include_feature_access] || options[:include_all_access]
|
|
208
|
+
rows = permissions.collect do |it|
|
|
209
|
+
{
|
|
210
|
+
code: it['code'],
|
|
211
|
+
name: it['name'],
|
|
212
|
+
category: it['subCategory'].to_s.titleize,
|
|
213
|
+
access: format_access_string(it['access']),
|
|
214
|
+
}
|
|
215
|
+
end
|
|
216
|
+
if options[:sort]
|
|
217
|
+
rows.sort! {|a,b| a[options[:sort]] <=> b[options[:sort]] }
|
|
218
|
+
else
|
|
219
|
+
rows.sort! {|a,b| [a[:category],a[:name],a[:code]] <=> [b[:category],b[:name],b[:code]] }
|
|
220
|
+
end
|
|
221
|
+
if options[:direction] == 'desc'
|
|
222
|
+
rows.reverse!
|
|
223
|
+
end
|
|
224
|
+
if options[:phrase]
|
|
225
|
+
phrase_regexp = /#{Regexp.escape(options[:phrase])}/i
|
|
226
|
+
rows = rows.select {|row| row[:code].to_s =~ phrase_regexp || row[:name].to_s =~ phrase_regexp }
|
|
227
|
+
end
|
|
228
|
+
print as_pretty_table(rows, [:category, :name, :code, :access], options)
|
|
229
|
+
# print reset,"\n"
|
|
230
|
+
else
|
|
231
|
+
print cyan,"Use --feature-access to list feature access","\n"
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
has_group_access = true
|
|
235
|
+
has_cloud_access = true
|
|
236
|
+
print_h2 "Default Access", options
|
|
237
|
+
global_access_columns = {
|
|
238
|
+
"Groups" => lambda {|it| get_access_string(it['globalSiteAccess']) },
|
|
239
|
+
"Clouds" => lambda {|it| get_access_string(it['globalZoneAccess']) },
|
|
240
|
+
"Instance Types" => lambda {|it| get_access_string(it['globalInstanceTypeAccess']) },
|
|
241
|
+
"Blueprints" => lambda {|it| get_access_string(it['globalAppTemplateAccess'] || it['globalBlueprintAccess']) },
|
|
242
|
+
"Personas" => lambda {|it| get_access_string(it['globalPersonaAccess']) },
|
|
243
|
+
"Report Types" => lambda {|it| get_access_string(it['globalReportTypeAccess']) },
|
|
244
|
+
"Catalog Item Types" => lambda {|it| get_access_string(it['globalCatalogItemTypeAccess']) },
|
|
245
|
+
"VDI Pools" => lambda {|it| get_access_string(it['globalVdiPoolAccess']) },
|
|
246
|
+
"Workflows" => lambda {|it| get_access_string(it['globalTaskSetAccess']) },
|
|
247
|
+
"Tasks" => lambda {|it| get_access_string(it['globalTaskAccess']) },
|
|
248
|
+
"Cluster Types" => lambda {|it| get_access_string(it['globalClusterTypeAccess']) },
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if role['roleType'].to_s.downcase == 'account'
|
|
252
|
+
global_access_columns.delete("Groups")
|
|
253
|
+
has_group_access = false
|
|
254
|
+
else
|
|
255
|
+
global_access_columns.delete("Clouds")
|
|
256
|
+
has_cloud_access = false
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
print as_pretty_table([json_response], global_access_columns, options)
|
|
260
|
+
|
|
261
|
+
if has_group_access
|
|
262
|
+
#print_h2 "Group Access: #{get_access_string(json_response['globalSiteAccess'])}", options
|
|
263
|
+
print cyan
|
|
264
|
+
print_h2 "Group Access", options
|
|
265
|
+
if options[:include_group_access] || options[:include_all_access]
|
|
266
|
+
rows = json_response['sites'].collect do |it|
|
|
267
|
+
{
|
|
268
|
+
name: it['name'],
|
|
269
|
+
access: format_access_string(it['access'], ["none","read","full"]),
|
|
270
|
+
}
|
|
271
|
+
end
|
|
272
|
+
if !options[:include_default_access]
|
|
273
|
+
rows = rows.select {|row| row[:access] && row[:access] != 'default '}
|
|
274
|
+
end
|
|
275
|
+
print as_pretty_table(rows, [:name, :access], options)
|
|
276
|
+
else
|
|
277
|
+
print cyan,"Use -g, --group-access to list custom access","\n"
|
|
278
|
+
end
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
if has_cloud_access
|
|
282
|
+
print cyan
|
|
283
|
+
#puts "Cloud Access: #{get_access_string(json_response['globalZoneAccess'])}"
|
|
284
|
+
#print "\n"
|
|
285
|
+
if json_response['sites'].find{|it| it['access'] && it['access'] != 'default'}
|
|
286
|
+
print_h2 "Cloud Access", options
|
|
287
|
+
if options[:include_cloud_access] || options[:include_all_access]
|
|
288
|
+
rows = json_response['zones'].collect do |it|
|
|
289
|
+
{
|
|
290
|
+
name: it['name'],
|
|
291
|
+
access: format_access_string(it['access'], ["none","read","full"]),
|
|
292
|
+
}
|
|
293
|
+
end
|
|
294
|
+
if !options[:include_default_access]
|
|
295
|
+
rows = rows.select {|row| row[:access] && row[:access] != 'default '}
|
|
296
|
+
end
|
|
297
|
+
print as_pretty_table(rows, [:name, :access], options)
|
|
298
|
+
else
|
|
299
|
+
print cyan,"Use -c, --cloud-access to list custom access","\n"
|
|
300
|
+
end
|
|
301
|
+
# print reset,"\n"
|
|
302
|
+
else
|
|
303
|
+
# print "\n"
|
|
304
|
+
# print cyan,bold,"Cloud Access: #{get_access_string(json_response['globalZoneAccess'])}",reset,"\n"
|
|
305
|
+
end
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
print cyan
|
|
309
|
+
# puts "Instance Type Access: #{get_access_string(json_response['globalInstanceTypeAccess'])}"
|
|
310
|
+
# print "\n"
|
|
311
|
+
instance_type_global_access = json_response['globalInstanceTypeAccess']
|
|
312
|
+
instance_type_permissions = role['instanceTypes'] ? role['instanceTypes'] : (json_response['instanceTypePermissions'] || [])
|
|
313
|
+
|
|
314
|
+
# if have any custom, then we want to show the flag indicator
|
|
315
|
+
# if including, show
|
|
316
|
+
|
|
317
|
+
if options[:include_instance_type_access] || options[:include_all_access]
|
|
318
|
+
print_h2 "Instance Type Access", options
|
|
319
|
+
rows = instance_type_permissions.collect do |it|
|
|
320
|
+
{
|
|
321
|
+
name: it['name'],
|
|
322
|
+
access: format_access_string(it['access'], ["none","read","full"]),
|
|
323
|
+
}
|
|
324
|
+
end
|
|
325
|
+
if !options[:include_default_access]
|
|
326
|
+
rows = rows.select {|row| row[:access] && row[:access] != 'default '}
|
|
327
|
+
end
|
|
328
|
+
print as_pretty_table(rows, [:name, :access], options)
|
|
329
|
+
elsif instance_type_permissions.find {|it| it['access'] && it['access'] != 'default'}
|
|
330
|
+
print_h2 "Instance Type Access", options
|
|
331
|
+
print cyan,"Use -i, --instance-type-access to list custom access","\n"
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
blueprint_global_access = json_response['globalAppTemplateAccess'] || json_response['globalBlueprintAccess']
|
|
335
|
+
blueprint_permissions = (role['appTemplates'] || role['blueprints']) ? (role['appTemplates'] || role['blueprints']) : (json_response['appTemplatePermissions'] || json_response['blueprintPermissions'] || [])
|
|
336
|
+
print cyan
|
|
337
|
+
if options[:include_blueprint_access] || options[:include_all_access]
|
|
338
|
+
print_h2 "Blueprint Access", options
|
|
339
|
+
rows = blueprint_permissions.collect do |it|
|
|
340
|
+
{
|
|
341
|
+
name: it['name'],
|
|
342
|
+
access: format_access_string(it['access'], ["none","read","full"]),
|
|
343
|
+
}
|
|
344
|
+
end
|
|
345
|
+
print as_pretty_table(rows, [:name, :access], options)
|
|
346
|
+
elsif blueprint_permissions.find {|it| it['access'] && it['access'] != 'default'}
|
|
347
|
+
print_h2 "Blueprint Access", options
|
|
348
|
+
print cyan,"Use -b, --blueprint-access to list custom access","\n"
|
|
349
|
+
end
|
|
350
|
+
|
|
351
|
+
catalog_item_type_global_access = json_response['globalCatalogItemTypeAccess']
|
|
352
|
+
catalog_item_type_permissions = role['catalogItemTypes'] ? role['catalogItemTypes'] : (json_response['catalogItemTypePermissions'] || [])
|
|
353
|
+
print cyan
|
|
354
|
+
if options[:include_catalog_item_type_access] || options[:include_all_access]
|
|
355
|
+
print_h2 "Catalog Item Type Access", options
|
|
356
|
+
rows = catalog_item_type_permissions.collect do |it|
|
|
357
|
+
{
|
|
358
|
+
name: it['name'],
|
|
359
|
+
access: format_access_string(it['access'], ["none","read","full"]),
|
|
360
|
+
}
|
|
361
|
+
end
|
|
362
|
+
if !options[:include_default_access]
|
|
363
|
+
rows = rows.select {|row| row[:access] && row[:access] != 'default '}
|
|
364
|
+
end
|
|
365
|
+
print as_pretty_table(rows, [:name, :access], options)
|
|
366
|
+
elsif catalog_item_type_permissions.find {|it| it['access'] && it['access'] != 'default'}
|
|
367
|
+
print_h2 "Catalog Item Type Access", options
|
|
368
|
+
print cyan,"Use --catalog-item-type-access to list access","\n"
|
|
369
|
+
end
|
|
370
|
+
|
|
371
|
+
persona_global_access = json_response['globalPersonaAccess']
|
|
372
|
+
persona_permissions = role['personas'] ? role['personas'] : (json_response['personaPermissions'] || [])
|
|
373
|
+
print cyan
|
|
374
|
+
if options[:include_persona_access] || options[:include_all_access]
|
|
375
|
+
print_h2 "Persona Access", options
|
|
376
|
+
rows = persona_permissions.collect do |it|
|
|
377
|
+
{
|
|
378
|
+
name: it['name'],
|
|
379
|
+
access: format_access_string(it['access'], ["none","full"]),
|
|
380
|
+
}
|
|
381
|
+
end
|
|
382
|
+
print as_pretty_table(rows, [:name, :access], options)
|
|
383
|
+
elsif persona_permissions.find {|it| it['access'] && it['access'] != 'default'}
|
|
384
|
+
print_h2 "Persona Access", options
|
|
385
|
+
print cyan,"Use --persona-access to list access","\n"
|
|
386
|
+
end
|
|
387
|
+
|
|
388
|
+
vdi_pool_global_access = json_response['globalVdiPoolAccess']
|
|
389
|
+
vdi_pool_permissions = role['vdiPools'] ? role['vdiPools'] : (json_response['vdiPoolPermissions'] || [])
|
|
390
|
+
print cyan
|
|
391
|
+
if options[:include_vdi_pool_access] || options[:include_all_access]
|
|
392
|
+
print_h2 "VDI Pool Access", options
|
|
393
|
+
rows = vdi_pool_permissions.collect do |it|
|
|
394
|
+
{
|
|
395
|
+
name: it['name'],
|
|
396
|
+
access: format_access_string(it['access'], ["none","full"]),
|
|
397
|
+
}
|
|
398
|
+
end
|
|
399
|
+
if !options[:include_default_access]
|
|
400
|
+
rows = rows.select {|row| row[:access] && row[:access] != 'default '}
|
|
401
|
+
end
|
|
402
|
+
print as_pretty_table(rows, [:name, :access], options)
|
|
403
|
+
elsif vdi_pool_permissions.find {|it| it['access'] && it['access'] != 'default'}
|
|
404
|
+
print_h2 "VDI Pool Access", options
|
|
405
|
+
print cyan,"Use --vdi-pool-access to list custom access","\n"
|
|
406
|
+
end
|
|
407
|
+
|
|
408
|
+
report_type_global_access = json_response['globalReportTypeAccess']
|
|
409
|
+
report_type_permissions = role['reportTypes'] ? role['reportTypes'] : (json_response['reportTypePermissions'] || [])
|
|
410
|
+
print cyan
|
|
411
|
+
if options[:include_report_type_access] || options[:include_all_access]
|
|
412
|
+
print_h2 "Report Type Access", options
|
|
413
|
+
rows = report_type_permissions.collect do |it|
|
|
414
|
+
{
|
|
415
|
+
name: it['name'],
|
|
416
|
+
access: format_access_string(it['access'], ["none","full"]),
|
|
417
|
+
}
|
|
418
|
+
end
|
|
419
|
+
if !options[:include_default_access]
|
|
420
|
+
rows = rows.select {|row| row[:access] && row[:access] != 'default '}
|
|
421
|
+
end
|
|
422
|
+
print as_pretty_table(rows, [:name, :access], options)
|
|
423
|
+
elsif report_type_permissions.find {|it| it['access'] && it['access'] != 'default'}
|
|
424
|
+
print_h2 "Report Type Access", options
|
|
425
|
+
print cyan,"Use --report-type-access to list custom access","\n"
|
|
426
|
+
end
|
|
427
|
+
|
|
428
|
+
task_global_access = json_response['globalTaskAccess']
|
|
429
|
+
task_permissions = role['tasks'] ? role['tasks'] : (json_response['taskPermissions'] || [])
|
|
430
|
+
print cyan
|
|
431
|
+
if options[:include_task_access] || options[:include_all_access]
|
|
432
|
+
print_h2 "Task Access", options
|
|
433
|
+
rows = task_permissions.collect do |it|
|
|
434
|
+
{
|
|
435
|
+
name: it['name'],
|
|
436
|
+
access: format_access_string(it['access'], ["none","full"]),
|
|
437
|
+
}
|
|
438
|
+
end
|
|
439
|
+
if !options[:include_default_access]
|
|
440
|
+
rows = rows.select {|row| row[:access] && row[:access] != 'default '}
|
|
441
|
+
end
|
|
442
|
+
print as_pretty_table(rows, [:name, :access], options)
|
|
443
|
+
elsif task_permissions.find {|it| it['access'] && it['access'] != 'default'}
|
|
444
|
+
print_h2 "Task Access", options
|
|
445
|
+
print cyan,"Use --task-access to list custom access","\n"
|
|
446
|
+
end
|
|
447
|
+
|
|
448
|
+
workflow_global_access = json_response['globalTaskSetAccess']
|
|
449
|
+
workflow_permissions = role['taskSets'] ? role['taskSets'] : (json_response['taskSetPermissions'] || [])
|
|
450
|
+
print cyan
|
|
451
|
+
if options[:include_workflow_access] || options[:include_all_access]
|
|
452
|
+
print_h2 "Workflow Access", options
|
|
453
|
+
rows = workflow_permissions.collect do |it|
|
|
454
|
+
{
|
|
455
|
+
name: it['name'],
|
|
456
|
+
access: format_access_string(it['access'], ["none","full"]),
|
|
457
|
+
}
|
|
458
|
+
end
|
|
459
|
+
if !options[:include_default_access]
|
|
460
|
+
rows = rows.select {|row| row[:access] && row[:access] != 'default '}
|
|
461
|
+
end
|
|
462
|
+
print as_pretty_table(rows, [:name, :access], options)
|
|
463
|
+
elsif workflow_permissions.find {|it| it['access'] && it['access'] != 'default'}
|
|
464
|
+
print_h2 "Workflow Access", options
|
|
465
|
+
print cyan,"Use --workflow-access to list custom access","\n"
|
|
466
|
+
end
|
|
467
|
+
|
|
468
|
+
cluster_type_global_access = json_response['globalClusterTypeAccess']
|
|
469
|
+
cluster_type_permissions = role['clusterTypes'] ? role['clusterTypes'] : (json_response['clusterTypePermissions'] || [])
|
|
470
|
+
print cyan
|
|
471
|
+
if options[:include_cluster_type_access] || options[:include_all_access]
|
|
472
|
+
print_h2 "Cluster Type Access", options
|
|
473
|
+
rows = cluster_type_permissions.collect do |it|
|
|
474
|
+
{
|
|
475
|
+
name: it['name'],
|
|
476
|
+
access: format_access_string(it['access'], ["none","full"]),
|
|
477
|
+
}
|
|
478
|
+
end
|
|
479
|
+
if !options[:include_default_access]
|
|
480
|
+
rows = rows.select {|row| row[:access] && row[:access] != 'default '}
|
|
481
|
+
end
|
|
482
|
+
print as_pretty_table(rows, [:name, :access], options)
|
|
483
|
+
elsif cluster_type_permissions.find {|it| it['access'] && it['access'] != 'default'}
|
|
484
|
+
print_h2 "Cluster Type Access", options
|
|
485
|
+
print cyan,"Use --cluster-type-access to list custom access","\n"
|
|
486
|
+
end
|
|
487
|
+
|
|
488
|
+
print reset,"\n"
|
|
489
|
+
return 0, nil
|
|
490
|
+
end
|
|
491
|
+
end
|
|
492
|
+
|
|
493
|
+
def list_permissions(args)
|
|
494
|
+
options = {}
|
|
495
|
+
available_categories = ['feature', 'group', 'cloud', 'instance-type', 'blueprint', 'report-type', 'persona', 'catalog-item-type', 'vdi-pool', 'workflow', 'task', 'cluster-type']
|
|
496
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
497
|
+
opts.banner = subcommand_usage("[role] [category]")
|
|
498
|
+
build_common_options(opts, options, [:list, :json, :yaml, :csv, :fields, :dry_run, :remote])
|
|
499
|
+
opts.footer = "List the access for a role.\n" +
|
|
500
|
+
"[role] is required. This is the name or id of a role.\n" +
|
|
501
|
+
"[category] is optional. Available categories: #{ored_list(available_categories)}"
|
|
502
|
+
end
|
|
503
|
+
|
|
504
|
+
optparse.parse!(args)
|
|
505
|
+
verify_args!(args:args, optparse:optparse, min: 1, max:2)
|
|
506
|
+
connect(options)
|
|
507
|
+
|
|
508
|
+
category = args[1].to_s.downcase if args[1]
|
|
509
|
+
|
|
510
|
+
if !category.nil? && !available_categories.include?(category)
|
|
511
|
+
raise_command_error("invalid category: #{category}", args, optparse)
|
|
512
|
+
end
|
|
513
|
+
|
|
514
|
+
account = find_account_from_options(options)
|
|
515
|
+
account_id = account ? account['id'] : nil
|
|
516
|
+
|
|
517
|
+
@roles_interface.setopts(options)
|
|
518
|
+
if options[:dry_run]
|
|
519
|
+
if args[0].to_s =~ /\A\d{1,}\Z/
|
|
520
|
+
print_dry_run @roles_interface.dry.get(account_id, args[0].to_i)
|
|
521
|
+
else
|
|
522
|
+
print_dry_run @roles_interface.dry.list(account_id, {name: args[0]})
|
|
523
|
+
end
|
|
524
|
+
return
|
|
525
|
+
end
|
|
526
|
+
|
|
527
|
+
if args[0].to_s =~ /\A\d{1,}\Z/
|
|
528
|
+
role = @roles_interface.get(account_id, args[0].to_i)
|
|
529
|
+
else
|
|
530
|
+
role = find_role_by_name_or_id(account_id, args[0])
|
|
531
|
+
exit 1 if role.nil?
|
|
532
|
+
role = @roles_interface.get(account_id, role['id'])
|
|
533
|
+
end
|
|
534
|
+
|
|
535
|
+
available_categories.reject! {|category| category == 'cloud'} if role['role']['roleType'] == 'user'
|
|
536
|
+
available_categories.reject! {|category| category == 'group'} if role['role']['roleType'] == 'account'
|
|
537
|
+
|
|
538
|
+
permission_name = -> (s) {
|
|
539
|
+
return 'sites' if s == 'group'
|
|
540
|
+
return 'zones' if s == 'cloud'
|
|
541
|
+
s = 'task-set' if s == 'workflow'
|
|
542
|
+
s = 'app-template' if s == 'blueprint'
|
|
543
|
+
s.split('-').map.with_index{|s,i| i == 0 ? s : s.capitalize}.join + 'Permissions'
|
|
544
|
+
}
|
|
545
|
+
permission_label = -> (s) {s.split('-').collect{|s| s.capitalize}.join(' ') + ' Permissions'}
|
|
546
|
+
|
|
547
|
+
if category.nil?
|
|
548
|
+
permissions = available_categories.reject{|category| role[permission_name.call(category)].nil?}.collect{|category|
|
|
549
|
+
role[permission_name.call(category)].map{|perm| perm.merge({'category' => permission_label.call(category)})}
|
|
550
|
+
}.flatten
|
|
551
|
+
else
|
|
552
|
+
permissions = role[permission_name.call(category)]
|
|
553
|
+
end
|
|
554
|
+
|
|
555
|
+
if options[:json]
|
|
556
|
+
puts as_json(permissions, options)
|
|
557
|
+
return 0
|
|
558
|
+
elsif options[:yaml]
|
|
559
|
+
puts as_yaml(permissions, options)
|
|
560
|
+
return 0
|
|
561
|
+
elsif options[:csv]
|
|
562
|
+
puts records_as_csv(permissions, :include_fields => ['category', 'id', 'code', 'name', 'access', 'sub category'])
|
|
563
|
+
return 0
|
|
564
|
+
end
|
|
565
|
+
|
|
566
|
+
print cyan
|
|
567
|
+
print_h1 "Role: [#{role['role']['id']}#{(role['role']['owner'].nil? ? ']' : ", #{role['role']['owner']['name']}]")} #{role['role']['authority']}", options
|
|
568
|
+
|
|
569
|
+
(category.nil? ? available_categories : [category]).each do |category|
|
|
570
|
+
permissions = role[permission_name.call(category)]
|
|
571
|
+
next if permissions.nil?
|
|
572
|
+
print_h2 "#{permission_label.call(category)}", options
|
|
573
|
+
if permissions.size > 0
|
|
574
|
+
rows = permissions.collect do |it|
|
|
575
|
+
{
|
|
576
|
+
code: it['code'],
|
|
577
|
+
name: it['name'],
|
|
578
|
+
category: it['subCategory'].to_s.titleize,
|
|
579
|
+
access: format_access_string(it['access']),
|
|
580
|
+
}
|
|
581
|
+
end
|
|
582
|
+
if options[:sort]
|
|
583
|
+
rows.sort! {|a,b| a[options[:sort]] <=> b[options[:sort]] }
|
|
584
|
+
else
|
|
585
|
+
rows.sort! {|a,b| [a[:category],a[:name],a[:code]] <=> [b[:category],b[:name],b[:code]] }
|
|
586
|
+
end
|
|
587
|
+
if options[:direction] == 'desc'
|
|
588
|
+
rows.reverse!
|
|
589
|
+
end
|
|
590
|
+
if options[:phrase]
|
|
591
|
+
phrase_regexp = /#{Regexp.escape(options[:phrase])}/i
|
|
592
|
+
rows = rows.select {|row| row[:code].to_s =~ phrase_regexp || row[:name].to_s =~ phrase_regexp }
|
|
593
|
+
end
|
|
594
|
+
print as_pretty_table(rows, [:category, :name, :code, :access], options)
|
|
595
|
+
else
|
|
596
|
+
puts "No permissions found"
|
|
597
|
+
end
|
|
598
|
+
end
|
|
599
|
+
print reset,"\n"
|
|
600
|
+
end
|
|
601
|
+
|
|
602
|
+
def add(args)
|
|
603
|
+
options = {}
|
|
604
|
+
params = {}
|
|
605
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
606
|
+
opts.banner = subcommand_usage("[name] [options]")
|
|
607
|
+
build_option_type_options(opts, options, add_role_option_types)
|
|
608
|
+
build_role_access_options(opts, options, params)
|
|
609
|
+
opts.on('--owner ID', String, "Set the owner/tenant/account for the role by account id. This option requires the admin permission to manage tenants." ) do |val|
|
|
610
|
+
params['owner'] = val
|
|
611
|
+
end
|
|
612
|
+
opts.on(nil, '--include-default-access', "Include default access levels in the response (returns all available resources)") do
|
|
613
|
+
options[:include_default_access] = true
|
|
614
|
+
end
|
|
615
|
+
build_standard_add_options(opts, options)
|
|
616
|
+
opts.footer = <<-EOT
|
|
617
|
+
Create a new role.
|
|
618
|
+
[name] is required. This is a unique name (authority) for the new role.
|
|
619
|
+
All the role permissions and access values can be configured.
|
|
620
|
+
Use --feature-access "CODE=ACCESS,CODE=ACCESS" to update access levels for specific feature permissions identified by code.
|
|
621
|
+
Use --default-instance-type-access custom --instance-types "CODE=ACCESS,CODE=ACCESS" to customize instance type access.
|
|
622
|
+
Only the specified permissions,instance types, etc. are updated.
|
|
623
|
+
Use --reset-feature-access to set access to "none" for all unspecified feature permissions.
|
|
624
|
+
Use --reset-all-access to set access to "none" for all unspecified feature permissions and default access values for groups, instance types, etc.
|
|
625
|
+
EOT
|
|
626
|
+
end
|
|
627
|
+
optparse.parse!(args)
|
|
628
|
+
verify_args!(args:args, optparse:optparse, max:1)
|
|
629
|
+
if args[0]
|
|
630
|
+
options[:options]['authority'] = args[0]
|
|
631
|
+
end
|
|
632
|
+
connect(options)
|
|
633
|
+
begin
|
|
634
|
+
|
|
635
|
+
load_whoami()
|
|
636
|
+
account = find_account_from_options(options)
|
|
637
|
+
account_id = account ? account['id'] : nil
|
|
638
|
+
|
|
639
|
+
passed_options = options[:options] ? options[:options].reject {|k,v| k.is_a?(Symbol) } : {}
|
|
640
|
+
payload = nil
|
|
641
|
+
if options[:payload]
|
|
642
|
+
payload = options[:payload]
|
|
643
|
+
payload.deep_merge!({'role' => passed_options}) unless passed_options.empty?
|
|
644
|
+
else
|
|
645
|
+
# merge -O options into normally parsed options
|
|
646
|
+
params.deep_merge!(passed_options)
|
|
647
|
+
|
|
648
|
+
# argh, some options depend on others here...eg. multitenant is only available when roleType == 'user'
|
|
649
|
+
#prompt_option_types = update_role_option_types()
|
|
650
|
+
|
|
651
|
+
v_prompt = MtnCloud::Cli::OptionTypes.prompt([{'fieldName' => 'authority', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'displayOrder' => 1}], options[:options])
|
|
652
|
+
params['authority'] = v_prompt['authority']
|
|
653
|
+
v_prompt = MtnCloud::Cli::OptionTypes.prompt([{'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'displayOrder' => 2}], options[:options])
|
|
654
|
+
params['description'] = v_prompt['description']
|
|
655
|
+
v_prompt = MtnCloud::Cli::OptionTypes.prompt([{'fieldName' => 'landingUrl', 'fieldLabel' => 'Landing URL', 'type' => 'text', 'displayOrder' => 3, 'description' => 'An optional override for the default landing page after login for a user.'}], options[:options])
|
|
656
|
+
params['landingUrl'] = v_prompt['landingUrl']
|
|
657
|
+
|
|
658
|
+
can_manage_accounts = @user_permissions.find { |it| it['code'] == 'admin-accounts' && it['access'] == 'full'}
|
|
659
|
+
|
|
660
|
+
if can_manage_accounts
|
|
661
|
+
v_prompt = MtnCloud::Cli::OptionTypes.prompt([{'fieldName' => 'owner', 'fieldLabel' => 'Owner', 'type' => 'select', 'selectOptions' => role_owner_options, 'defaultValue' => current_account['id'], 'displayOrder' => 3}], options[:options])
|
|
662
|
+
params['owner'] = v_prompt['owner']
|
|
663
|
+
else
|
|
664
|
+
params['owner'] = current_account['id']
|
|
665
|
+
end
|
|
666
|
+
|
|
667
|
+
if can_manage_accounts
|
|
668
|
+
v_prompt = MtnCloud::Cli::OptionTypes.prompt([{'fieldName' => 'roleType', 'fieldLabel' => 'Type', 'type' => 'select', 'selectOptions' => role_type_options, 'defaultValue' => 'user', 'displayOrder' => 4}], options[:options])
|
|
669
|
+
params['roleType'] = v_prompt['roleType']
|
|
670
|
+
else
|
|
671
|
+
params['roleType'] = 'user'
|
|
672
|
+
end
|
|
673
|
+
|
|
674
|
+
if options[:cloud_permissions] && params['roleType'] == 'user'
|
|
675
|
+
raise_command_error "The --clouds option is only available for user roles, not account roles"
|
|
676
|
+
end
|
|
677
|
+
if options[:group_permissions] && params['roleType'] == 'account'
|
|
678
|
+
raise_command_error "The --groups option is only available for account roles, not user roles"
|
|
679
|
+
end
|
|
680
|
+
if params['globalZoneAccess'] && params['roleType'] == 'user'
|
|
681
|
+
raise_command_error "The --default-cloud-access option is only available for account roles, not user roles"
|
|
682
|
+
end
|
|
683
|
+
if params['globalSiteAccess'] && params['roleType'] == 'account'
|
|
684
|
+
raise_command_error "The --default-group-access option is only available for user roles, not account roles"
|
|
685
|
+
end
|
|
686
|
+
|
|
687
|
+
v_prompt = MtnCloud::Cli::OptionTypes.prompt([{'fieldName' => 'baseRole', 'fieldLabel' => 'Copy From Role', 'type' => 'select', 'selectOptions' => base_role_options(params), 'displayOrder' => 5}], options[:options])
|
|
688
|
+
if v_prompt['baseRole'].to_s != ''
|
|
689
|
+
base_role = find_role_by_name_or_id(account_id, v_prompt['baseRole'])
|
|
690
|
+
exit 1 if base_role.nil?
|
|
691
|
+
params['baseRoleId'] = base_role['id']
|
|
692
|
+
end
|
|
693
|
+
|
|
694
|
+
if @is_master_account && params['owner'] == current_account['id']
|
|
695
|
+
if params['roleType'] == 'user'
|
|
696
|
+
v_prompt = MtnCloud::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])
|
|
697
|
+
params['multitenant'] = ['on','true'].include?(v_prompt['multitenant'].to_s)
|
|
698
|
+
if params['multitenant']
|
|
699
|
+
v_prompt = MtnCloud::Cli::OptionTypes.prompt([{'fieldName' => 'multitenantLocked', 'fieldLabel' => 'Multitenant Locked', 'type' => 'checkbox', 'defaultValue' => 'off', 'description' => 'Prevents subtenants from branching off this role/modifying it.'}], options[:options])
|
|
700
|
+
params['multitenantLocked'] = ['on','true'].include?(v_prompt['multitenantLocked'].to_s)
|
|
701
|
+
end
|
|
702
|
+
end
|
|
703
|
+
end
|
|
704
|
+
|
|
705
|
+
# v_prompt = MtnCloud::Cli::OptionTypes.prompt([{'fieldName' => 'defaultPersona', 'fieldLabel' => 'Default Persona', 'type' => 'select', 'optionSource' => 'personas', 'description' => 'Default Persona'}], options[:options], @api_client)
|
|
706
|
+
v_prompt = MtnCloud::Cli::OptionTypes.prompt([{'fieldName' => 'defaultPersona', 'fieldLabel' => 'Default Persona', 'type' => 'select', 'selectOptions' => get_persona_select_options(), 'description' => 'Default Persona'}], options[:options], @api_client)
|
|
707
|
+
params['defaultPersona'] = {'code' => v_prompt['defaultPersona']} unless v_prompt['defaultPersona'].to_s.strip.empty?
|
|
708
|
+
|
|
709
|
+
# bulk role permissions
|
|
710
|
+
parse_role_access_options(options, params)
|
|
711
|
+
payload = {"role" => params}
|
|
712
|
+
end
|
|
713
|
+
query_params = parse_query_options(options)
|
|
714
|
+
query_params['includeDefaultAccess'] = true if options[:include_default_access]
|
|
715
|
+
@roles_interface.setopts(options)
|
|
716
|
+
if options[:dry_run]
|
|
717
|
+
print_dry_run @roles_interface.dry.create(account_id, payload, query_params)
|
|
718
|
+
return
|
|
719
|
+
end
|
|
720
|
+
json_response = @roles_interface.create(account_id, payload, query_params)
|
|
721
|
+
|
|
722
|
+
if options[:json]
|
|
723
|
+
print JSON.pretty_generate(json_response)
|
|
724
|
+
print "\n"
|
|
725
|
+
return
|
|
726
|
+
end
|
|
727
|
+
|
|
728
|
+
role = json_response['role']
|
|
729
|
+
display_name = role['authority'] rescue ''
|
|
730
|
+
if account
|
|
731
|
+
print_green_success "Added role #{display_name} to account #{account['name']}"
|
|
732
|
+
else
|
|
733
|
+
print_green_success "Added role #{display_name}"
|
|
734
|
+
end
|
|
735
|
+
|
|
736
|
+
get_args = [role['id']] + (options[:remote] ? ["-r",options[:remote]] : [])
|
|
737
|
+
if account
|
|
738
|
+
get_args.push "--account-id", account['id'].to_s
|
|
739
|
+
end
|
|
740
|
+
|
|
741
|
+
details_options = [params["authority"]]
|
|
742
|
+
if account
|
|
743
|
+
details_options.push "--account-id", account['id'].to_s
|
|
744
|
+
end
|
|
745
|
+
|
|
746
|
+
if params['owner']
|
|
747
|
+
details_options.push "--account-id", params['owner'].to_s
|
|
748
|
+
end
|
|
749
|
+
get(details_options)
|
|
750
|
+
|
|
751
|
+
rescue RestClient::Exception => e
|
|
752
|
+
print_rest_exception(e, options)
|
|
753
|
+
exit 1
|
|
754
|
+
end
|
|
755
|
+
end
|
|
756
|
+
|
|
757
|
+
def update(args)
|
|
758
|
+
options = {}
|
|
759
|
+
params = {}
|
|
760
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
761
|
+
opts.banner = subcommand_usage("[role] [options]")
|
|
762
|
+
build_option_type_options(opts, options, update_role_option_types)
|
|
763
|
+
build_role_access_options(opts, options, params)
|
|
764
|
+
opts.on(nil, '--include-default-access', "Include default access levels in the output (returns all available resources)") do
|
|
765
|
+
options[:include_default_access] = true
|
|
766
|
+
end
|
|
767
|
+
build_standard_update_options(opts, options)
|
|
768
|
+
opts.footer = <<-EOT
|
|
769
|
+
Update a role.
|
|
770
|
+
[role] is required. This is the name (authority) or id of a role.
|
|
771
|
+
All the role permissions and access values can be configured.
|
|
772
|
+
Use --feature-access "CODE=ACCESS,CODE=ACCESS" to update access levels for specific feature permissions identified by code.
|
|
773
|
+
Use --default-instance-type-access custom --instance-types "CODE=ACCESS,CODE=ACCESS" to customize instance type access.
|
|
774
|
+
Only the specified permissions,instance types, etc. are updated.
|
|
775
|
+
Use --reset-feature-access to set access to "none" for all unspecified feature permissions.
|
|
776
|
+
Use --reset-all-access to set access to "none" for all unspecified feature permissions and global access values for groups, instance types, etc.
|
|
777
|
+
EOT
|
|
778
|
+
end
|
|
779
|
+
optparse.parse!(args)
|
|
780
|
+
|
|
781
|
+
verify_args!(args:args, optparse:optparse, count:1)
|
|
782
|
+
|
|
783
|
+
name = args[0]
|
|
784
|
+
connect(options)
|
|
785
|
+
begin
|
|
786
|
+
|
|
787
|
+
load_whoami()
|
|
788
|
+
|
|
789
|
+
account = find_account_from_options(options)
|
|
790
|
+
account_id = account ? account['id'] : nil
|
|
791
|
+
|
|
792
|
+
role = find_role_by_name_or_id(account_id, name)
|
|
793
|
+
exit 1 if role.nil?
|
|
794
|
+
|
|
795
|
+
passed_options = options[:options] ? options[:options].reject {|k,v| k.is_a?(Symbol) } : {}
|
|
796
|
+
payload = nil
|
|
797
|
+
if options[:payload]
|
|
798
|
+
payload = options[:payload]
|
|
799
|
+
payload.deep_merge!({'role' => passed_options}) unless passed_options.empty?
|
|
800
|
+
else
|
|
801
|
+
# merge -O options into normally parsed options
|
|
802
|
+
params.deep_merge!(passed_options)
|
|
803
|
+
prompt_option_types = update_role_option_types()
|
|
804
|
+
# if !has_complete_access
|
|
805
|
+
# prompt_option_types = prompt_option_types.reject {|it| ['roleType', 'multitenant','multitenantLocked'].include?(it['fieldName']) }
|
|
806
|
+
# end
|
|
807
|
+
if role['roleType'] != 'user'
|
|
808
|
+
prompt_option_types = prompt_option_types.reject {|it| ['multitenant','multitenantLocked'].include?(it['fieldName']) }
|
|
809
|
+
end
|
|
810
|
+
#params = MtnCloud::Cli::OptionTypes.prompt(prompt_option_types, options[:options], @api_client, options[:params])
|
|
811
|
+
if options[:cloud_permissions] && role['roleType'] == 'user'
|
|
812
|
+
raise_command_error "The --clouds option is only available for user roles, not account roles"
|
|
813
|
+
end
|
|
814
|
+
if options[:group_permissions] && role['roleType'] == 'account'
|
|
815
|
+
raise_command_error "The --groups option is only available for account roles, not user roles"
|
|
816
|
+
end
|
|
817
|
+
if params['globalZoneAccess'] && role['roleType'] == 'user'
|
|
818
|
+
raise_command_error "The --default-cloud-access option is only available for account roles, not user roles"
|
|
819
|
+
end
|
|
820
|
+
if params['globalSiteAccess'] && role['roleType'] == 'account'
|
|
821
|
+
raise_command_error "The --default-group-access option is only available for user roles, not account roles"
|
|
822
|
+
end
|
|
823
|
+
# bulk role permissions
|
|
824
|
+
parse_role_access_options(options, params)
|
|
825
|
+
|
|
826
|
+
if params.empty?
|
|
827
|
+
raise_command_error "Specify at least one option to update.\n#{optparse}"
|
|
828
|
+
end
|
|
829
|
+
payload = {"role" => params}
|
|
830
|
+
end
|
|
831
|
+
query_params = parse_query_options(options)
|
|
832
|
+
query_params['includeDefaultAccess'] = true if options[:include_default_access]
|
|
833
|
+
@roles_interface.setopts(options)
|
|
834
|
+
if options[:dry_run]
|
|
835
|
+
print_dry_run @roles_interface.dry.update(account_id, role['id'], payload, query_params)
|
|
836
|
+
return
|
|
837
|
+
end
|
|
838
|
+
json_response = @roles_interface.update(account_id, role['id'], payload, query_params)
|
|
839
|
+
render_response(json_response, options, "role") do
|
|
840
|
+
role = json_response['role']
|
|
841
|
+
display_name = role['authority'] rescue ''
|
|
842
|
+
print_green_success "Updated role #{display_name}"
|
|
843
|
+
|
|
844
|
+
get_args = [role['id']] + (options[:remote] ? ["-r",options[:remote]] : [])
|
|
845
|
+
if account
|
|
846
|
+
get_args.push "--account-id", account['id'].to_s
|
|
847
|
+
end
|
|
848
|
+
get(get_args)
|
|
849
|
+
end
|
|
850
|
+
return 0, nil
|
|
851
|
+
|
|
852
|
+
rescue RestClient::Exception => e
|
|
853
|
+
print_rest_exception(e, options)
|
|
854
|
+
exit 1
|
|
855
|
+
end
|
|
856
|
+
end
|
|
857
|
+
|
|
858
|
+
def remove(args)
|
|
859
|
+
options = {}
|
|
860
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
861
|
+
opts.banner = subcommand_usage("[role]")
|
|
862
|
+
build_common_options(opts, options, [:auto_confirm, :json, :dry_run, :remote])
|
|
863
|
+
opts.footer = <<-EOT
|
|
864
|
+
Delete a role.
|
|
865
|
+
[role] is required. This is the name (authority) or id of a role.
|
|
866
|
+
EOT
|
|
867
|
+
end
|
|
868
|
+
optparse.parse!(args)
|
|
869
|
+
if args.count < 1
|
|
870
|
+
puts optparse
|
|
871
|
+
exit 1
|
|
872
|
+
end
|
|
873
|
+
name = args[0]
|
|
874
|
+
connect(options)
|
|
875
|
+
begin
|
|
876
|
+
|
|
877
|
+
account = find_account_from_options(options)
|
|
878
|
+
account_id = account ? account['id'] : nil
|
|
879
|
+
|
|
880
|
+
role = find_role_by_name_or_id(account_id, name)
|
|
881
|
+
exit 1 if role.nil?
|
|
882
|
+
unless options[:yes] || MtnCloud::Cli::OptionTypes.confirm("Are you sure you want to delete the role #{role['authority']}?")
|
|
883
|
+
exit
|
|
884
|
+
end
|
|
885
|
+
@roles_interface.setopts(options)
|
|
886
|
+
if options[:dry_run]
|
|
887
|
+
print_dry_run @roles_interface.dry.destroy(account_id, role['id'])
|
|
888
|
+
return
|
|
889
|
+
end
|
|
890
|
+
json_response = @roles_interface.destroy(account_id, role['id'])
|
|
891
|
+
if options[:json]
|
|
892
|
+
print JSON.pretty_generate(json_response)
|
|
893
|
+
print "\n"
|
|
894
|
+
else
|
|
895
|
+
print_green_success "Role #{role['authority']} removed"
|
|
896
|
+
end
|
|
897
|
+
rescue RestClient::Exception => e
|
|
898
|
+
print_rest_exception(e, options)
|
|
899
|
+
exit 1
|
|
900
|
+
end
|
|
901
|
+
end
|
|
902
|
+
|
|
903
|
+
def validate(args)
|
|
904
|
+
options = {}
|
|
905
|
+
params = {}
|
|
906
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
907
|
+
opts.banner = subcommand_usage("[role] [options]")
|
|
908
|
+
build_option_type_options(opts, options, add_role_option_types)
|
|
909
|
+
build_role_access_options(opts, options, params)
|
|
910
|
+
build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
|
|
911
|
+
opts.footer = <<-EOT
|
|
912
|
+
Validate role permissions without creating or updating a role.
|
|
913
|
+
[role] is optional. This is the name (authority) or id of a role.
|
|
914
|
+
This is useful for testing permission configurations before applying them.
|
|
915
|
+
All the role permissions and access values can be validated.
|
|
916
|
+
Use --feature-access "CODE=ACCESS,CODE=ACCESS" to validate access levels for specific feature permissions.
|
|
917
|
+
Example: #{prog_name} roles validate --authority "Test Role" --feature-access "admin=full,activity=read"
|
|
918
|
+
Example: #{prog_name} roles validate "Existing Role" --feature-access "activity=full"
|
|
919
|
+
EOT
|
|
920
|
+
end
|
|
921
|
+
optparse.parse!(args)
|
|
922
|
+
|
|
923
|
+
# allow 0-1 arguments
|
|
924
|
+
verify_args!(args:args, optparse:optparse, max:1)
|
|
925
|
+
|
|
926
|
+
connect(options)
|
|
927
|
+
begin
|
|
928
|
+
account = find_account_from_options(options)
|
|
929
|
+
account_id = account ? account['id'] : nil
|
|
930
|
+
|
|
931
|
+
# load existing role if arg passed
|
|
932
|
+
role = nil
|
|
933
|
+
if args[0]
|
|
934
|
+
role = find_role_by_name_or_id(account_id, args[0])
|
|
935
|
+
exit 1 if role.nil?
|
|
936
|
+
end
|
|
937
|
+
|
|
938
|
+
passed_options = options[:options] ? options[:options].reject {|k,v| k.is_a?(Symbol) } : {}
|
|
939
|
+
payload = nil
|
|
940
|
+
|
|
941
|
+
if options[:payload]
|
|
942
|
+
payload = options[:payload]
|
|
943
|
+
payload.deep_merge!({'role' => passed_options}) unless passed_options.empty?
|
|
944
|
+
else
|
|
945
|
+
# merge -O options into normally parsed options
|
|
946
|
+
params.deep_merge!(passed_options)
|
|
947
|
+
|
|
948
|
+
# Parse role access options
|
|
949
|
+
parse_role_access_options(options, params)
|
|
950
|
+
|
|
951
|
+
# Validate role type constraints
|
|
952
|
+
role_type = role ? role['roleType'] : params['roleType']
|
|
953
|
+
if role_type
|
|
954
|
+
if params['globalZoneAccess'] && role_type == 'user'
|
|
955
|
+
raise_command_error "The --default-cloud-access option is only available for account roles, not user roles"
|
|
956
|
+
end
|
|
957
|
+
if params['globalSiteAccess'] && role_type == 'account'
|
|
958
|
+
raise_command_error "The --default-group-access option is only available for user roles, not account roles"
|
|
959
|
+
end
|
|
960
|
+
end
|
|
961
|
+
|
|
962
|
+
if params.empty? && passed_options.empty? && role.nil?
|
|
963
|
+
raise_command_error "Specify at least one role configuration option to validate.\n#{optparse}"
|
|
964
|
+
end
|
|
965
|
+
|
|
966
|
+
payload = {"role" => params}
|
|
967
|
+
end
|
|
968
|
+
|
|
969
|
+
if role
|
|
970
|
+
payload['role']['id'] = role['id']
|
|
971
|
+
end
|
|
972
|
+
|
|
973
|
+
query_params = parse_query_options(options)
|
|
974
|
+
@roles_interface.setopts(options)
|
|
975
|
+
|
|
976
|
+
if options[:dry_run]
|
|
977
|
+
print_dry_run @roles_interface.dry.validate(account_id, payload, query_params)
|
|
978
|
+
return 0, nil
|
|
979
|
+
end
|
|
980
|
+
|
|
981
|
+
json_response = @roles_interface.validate(account_id, payload, query_params)
|
|
982
|
+
|
|
983
|
+
render_response(json_response, options) do
|
|
984
|
+
if json_response['success'] && json_response['valid']
|
|
985
|
+
print_green_success json_response['msg'] || "Role permissions are valid"
|
|
986
|
+
else
|
|
987
|
+
print_red_alert "Validation failed: #{json_response['msg'] || 'Invalid role permissions'}"
|
|
988
|
+
if json_response['errors'] && !json_response['errors'].empty?
|
|
989
|
+
print_h2 "Validation Errors", options
|
|
990
|
+
json_response['errors'].each do |key, msg|
|
|
991
|
+
print red, " #{key}: #{msg}", reset, "\n"
|
|
992
|
+
end
|
|
993
|
+
end
|
|
994
|
+
end
|
|
995
|
+
end
|
|
996
|
+
|
|
997
|
+
# Return exit code based on validation result
|
|
998
|
+
return json_response['success'] && json_response['valid'] ? 0 : 1
|
|
999
|
+
|
|
1000
|
+
rescue RestClient::Exception => e
|
|
1001
|
+
print_rest_exception(e, options)
|
|
1002
|
+
return 1
|
|
1003
|
+
end
|
|
1004
|
+
end
|
|
1005
|
+
|
|
1006
|
+
def update_feature_access(args)
|
|
1007
|
+
options = {}
|
|
1008
|
+
allowed_access_values = ["full", "full_decrypted", "group", "listfiles", "managerules", "no", "none", "provision", "read", "rolemappings", "user", "view", "yes"]
|
|
1009
|
+
permission_code = nil
|
|
1010
|
+
access_value = nil
|
|
1011
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
1012
|
+
opts.banner = subcommand_usage("[role] [permission] [access]")
|
|
1013
|
+
opts.on( '-p', '--permission CODE', "Permission code or name" ) do |val|
|
|
1014
|
+
permission_code = val
|
|
1015
|
+
end
|
|
1016
|
+
opts.on( '--access VALUE', String, "Access value [#{allowed_access_values.join('|')}] (varies per permission)" ) do |val|
|
|
1017
|
+
access_value = val
|
|
1018
|
+
end
|
|
1019
|
+
build_common_options(opts, options, [:json, :dry_run, :remote])
|
|
1020
|
+
opts.footer = <<-EOT
|
|
1021
|
+
Update role access for a permission.
|
|
1022
|
+
[role] is required. This is the name (authority) or id of a role.
|
|
1023
|
+
[permission] is required. This is the code or name of a permission.
|
|
1024
|
+
[access] is required. This is the new access value: #{ored_list(allowed_access_values)}
|
|
1025
|
+
EOT
|
|
1026
|
+
end
|
|
1027
|
+
optparse.parse!(args)
|
|
1028
|
+
verify_args!(args:args, optparse:optparse, min:1, max:3)
|
|
1029
|
+
name = args[0]
|
|
1030
|
+
permission_code = args[1] if args[1]
|
|
1031
|
+
access_value = args[2].to_s.downcase if args[2]
|
|
1032
|
+
|
|
1033
|
+
if !permission_code
|
|
1034
|
+
raise_command_error("missing required argument: [permission]", args, optparse)
|
|
1035
|
+
end
|
|
1036
|
+
if !access_value
|
|
1037
|
+
raise_command_error("missing required argument: [access]", args, optparse)
|
|
1038
|
+
end
|
|
1039
|
+
# access_value = access_value.to_s.downcase
|
|
1040
|
+
# if !allowed_access_values.include?(access_value)
|
|
1041
|
+
# raise_command_error("invalid access value: #{access_value}", args, optparse)
|
|
1042
|
+
# end
|
|
1043
|
+
# need to load the permission and then split accessTypes, so just allows all for now, server validates...
|
|
1044
|
+
# if !['full_decrypted','full', 'read', 'custom', 'none'].include?(access_value)
|
|
1045
|
+
# puts optparse
|
|
1046
|
+
# exit 1
|
|
1047
|
+
# end
|
|
1048
|
+
|
|
1049
|
+
connect(options)
|
|
1050
|
+
begin
|
|
1051
|
+
account = find_account_from_options(options)
|
|
1052
|
+
account_id = account ? account['id'] : nil
|
|
1053
|
+
role = find_role_by_name_or_id(account_id, name)
|
|
1054
|
+
exit 1 if role.nil?
|
|
1055
|
+
|
|
1056
|
+
params = {permissionCode: permission_code, access: access_value}
|
|
1057
|
+
@roles_interface.setopts(options)
|
|
1058
|
+
if options[:dry_run]
|
|
1059
|
+
print_dry_run @roles_interface.dry.update_permission(account_id, role['id'], params)
|
|
1060
|
+
return
|
|
1061
|
+
end
|
|
1062
|
+
json_response = @roles_interface.update_permission(account_id, role['id'], params)
|
|
1063
|
+
|
|
1064
|
+
if options[:json]
|
|
1065
|
+
print JSON.pretty_generate(json_response)
|
|
1066
|
+
print "\n"
|
|
1067
|
+
else
|
|
1068
|
+
print_green_success "Role #{role['authority']} permission #{permission_code} set to #{access_value}"
|
|
1069
|
+
end
|
|
1070
|
+
rescue RestClient::Exception => e
|
|
1071
|
+
print_rest_exception(e, options)
|
|
1072
|
+
exit 1
|
|
1073
|
+
end
|
|
1074
|
+
end
|
|
1075
|
+
|
|
1076
|
+
def update_global_group_access(args)
|
|
1077
|
+
puts "#{yellow}DEPRECATED#{reset}"
|
|
1078
|
+
update_default_group_access(args)
|
|
1079
|
+
end
|
|
1080
|
+
|
|
1081
|
+
def update_default_group_access(args)
|
|
1082
|
+
options = {}
|
|
1083
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
1084
|
+
opts.banner = subcommand_usage("[role] [access]")
|
|
1085
|
+
build_common_options(opts, options, [:json, :dry_run, :remote])
|
|
1086
|
+
opts.footer = <<-EOT
|
|
1087
|
+
Update default group access for a role.
|
|
1088
|
+
[role] is required. This is the name (authority) or id of a role.
|
|
1089
|
+
[access] is required. This is the access level to assign: full, read, or none.
|
|
1090
|
+
Only applicable to User roles.
|
|
1091
|
+
EOT
|
|
1092
|
+
end
|
|
1093
|
+
optparse.parse!(args)
|
|
1094
|
+
|
|
1095
|
+
if args.count < 2
|
|
1096
|
+
puts optparse
|
|
1097
|
+
exit 1
|
|
1098
|
+
end
|
|
1099
|
+
name = args[0]
|
|
1100
|
+
access_value = args[1].to_s.downcase
|
|
1101
|
+
if !['full', 'read', 'none', 'custom'].include?(access_value)
|
|
1102
|
+
puts optparse
|
|
1103
|
+
exit 1
|
|
1104
|
+
end
|
|
1105
|
+
|
|
1106
|
+
connect(options)
|
|
1107
|
+
begin
|
|
1108
|
+
account = find_account_from_options(options)
|
|
1109
|
+
account_id = account ? account['id'] : nil
|
|
1110
|
+
role = find_role_by_name_or_id(account_id, name)
|
|
1111
|
+
exit 1 if role.nil?
|
|
1112
|
+
|
|
1113
|
+
if role['roleType'] == 'account'
|
|
1114
|
+
raise_command_error "The default-group-access command is only available for user roles, not account roles"
|
|
1115
|
+
end
|
|
1116
|
+
|
|
1117
|
+
params = {permissionCode: 'ComputeSite', access: access_value}
|
|
1118
|
+
@roles_interface.setopts(options)
|
|
1119
|
+
if options[:dry_run]
|
|
1120
|
+
print_dry_run @roles_interface.dry.update_permission(account_id, role['id'], params)
|
|
1121
|
+
return
|
|
1122
|
+
end
|
|
1123
|
+
json_response = @roles_interface.update_permission(account_id, role['id'], params)
|
|
1124
|
+
|
|
1125
|
+
if options[:json]
|
|
1126
|
+
print JSON.pretty_generate(json_response)
|
|
1127
|
+
print "\n"
|
|
1128
|
+
else
|
|
1129
|
+
print_green_success "Role #{role['authority']} default group access updated"
|
|
1130
|
+
end
|
|
1131
|
+
rescue RestClient::Exception => e
|
|
1132
|
+
print_rest_exception(e, options)
|
|
1133
|
+
exit 1
|
|
1134
|
+
end
|
|
1135
|
+
end
|
|
1136
|
+
|
|
1137
|
+
def update_group_access(args)
|
|
1138
|
+
options = {}
|
|
1139
|
+
name = nil
|
|
1140
|
+
group_id = nil
|
|
1141
|
+
access_value = nil
|
|
1142
|
+
do_all = false
|
|
1143
|
+
allowed_access_values = ['full', 'read', 'none', 'default']
|
|
1144
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
1145
|
+
opts.banner = subcommand_usage("[role] [group] [access]")
|
|
1146
|
+
opts.on( '-g', '--group GROUP', "Group name or id" ) do |val|
|
|
1147
|
+
group_id = val
|
|
1148
|
+
end
|
|
1149
|
+
opts.on( nil, '--all', "Update all groups at once." ) do
|
|
1150
|
+
do_all = true
|
|
1151
|
+
end
|
|
1152
|
+
opts.on( '--access VALUE', String, "Access value [#{allowed_access_values.join('|')}]" ) do |val|
|
|
1153
|
+
access_value = val
|
|
1154
|
+
end
|
|
1155
|
+
build_common_options(opts, options, [:json, :dry_run, :remote])
|
|
1156
|
+
opts.footer = <<-EOT
|
|
1157
|
+
Update role access for a group or all groups.
|
|
1158
|
+
[role] is required. This is the name or id of a role.
|
|
1159
|
+
--group or --all is required. This is the name or id of a group.
|
|
1160
|
+
--access is required. This is the new access value: #{ored_list(allowed_access_values)}
|
|
1161
|
+
EOT
|
|
1162
|
+
|
|
1163
|
+
end
|
|
1164
|
+
optparse.parse!(args)
|
|
1165
|
+
|
|
1166
|
+
# usage: update-group-access [role] [access] --all
|
|
1167
|
+
# update-group-access [role] [group] [access]
|
|
1168
|
+
name = args[0]
|
|
1169
|
+
if do_all
|
|
1170
|
+
verify_args!(args:args, optparse:optparse, min:1, max:2)
|
|
1171
|
+
access_value = args[1] if args[1]
|
|
1172
|
+
else
|
|
1173
|
+
verify_args!(args:args, optparse:optparse, min:1, max:3)
|
|
1174
|
+
group_id = args[1] if args[1]
|
|
1175
|
+
access_value = args[2] if args[2]
|
|
1176
|
+
end
|
|
1177
|
+
if !group_id && !do_all
|
|
1178
|
+
raise_command_error("missing required argument: [group] or --all", args, optparse)
|
|
1179
|
+
end
|
|
1180
|
+
if !access_value
|
|
1181
|
+
raise_command_error("missing required argument: [access]", args, optparse)
|
|
1182
|
+
end
|
|
1183
|
+
access_value = access_value.to_s.downcase
|
|
1184
|
+
if !allowed_access_values.include?(access_value)
|
|
1185
|
+
raise_command_error("invalid access value: #{access_value}", args, optparse)
|
|
1186
|
+
end
|
|
1187
|
+
|
|
1188
|
+
connect(options)
|
|
1189
|
+
begin
|
|
1190
|
+
account = find_account_from_options(options)
|
|
1191
|
+
account_id = account ? account['id'] : nil
|
|
1192
|
+
role = find_role_by_name_or_id(account_id, name)
|
|
1193
|
+
return 1 if role.nil?
|
|
1194
|
+
|
|
1195
|
+
group = nil
|
|
1196
|
+
if !do_all
|
|
1197
|
+
group = find_group_by_name_or_id_for_provisioning(group_id)
|
|
1198
|
+
return 1 if group.nil?
|
|
1199
|
+
group_id = group['id']
|
|
1200
|
+
end
|
|
1201
|
+
|
|
1202
|
+
params = {}
|
|
1203
|
+
if do_all
|
|
1204
|
+
params['allGroups'] = true
|
|
1205
|
+
else
|
|
1206
|
+
params['groupId'] = group_id
|
|
1207
|
+
end
|
|
1208
|
+
params['access'] = access_value
|
|
1209
|
+
@roles_interface.setopts(options)
|
|
1210
|
+
if options[:dry_run]
|
|
1211
|
+
print_dry_run @roles_interface.dry.update_group(account_id, role['id'], params)
|
|
1212
|
+
return
|
|
1213
|
+
end
|
|
1214
|
+
json_response = @roles_interface.update_group(account_id, role['id'], params)
|
|
1215
|
+
|
|
1216
|
+
if options[:json]
|
|
1217
|
+
print JSON.pretty_generate(json_response)
|
|
1218
|
+
print "\n"
|
|
1219
|
+
else
|
|
1220
|
+
if do_all
|
|
1221
|
+
print_green_success "Role #{role['authority']} access updated for all groups"
|
|
1222
|
+
else
|
|
1223
|
+
print_green_success "Role #{role['authority']} access updated for group #{group['name']}"
|
|
1224
|
+
end
|
|
1225
|
+
end
|
|
1226
|
+
return 0
|
|
1227
|
+
rescue RestClient::Exception => e
|
|
1228
|
+
print_rest_exception(e, options)
|
|
1229
|
+
exit 1
|
|
1230
|
+
end
|
|
1231
|
+
end
|
|
1232
|
+
|
|
1233
|
+
def update_global_cloud_access(args)
|
|
1234
|
+
puts "#{yellow}DEPRECATED#{reset}"
|
|
1235
|
+
update_default_cloud_access(args)
|
|
1236
|
+
end
|
|
1237
|
+
|
|
1238
|
+
def update_default_cloud_access(args)
|
|
1239
|
+
options = {}
|
|
1240
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
1241
|
+
opts.banner = subcommand_usage("[role] [access]")
|
|
1242
|
+
build_common_options(opts, options, [:json, :dry_run, :remote])
|
|
1243
|
+
opts.footer = <<-EOT
|
|
1244
|
+
Update default cloud access for a role.
|
|
1245
|
+
[role] is required. This is the name (authority) or id of a role.
|
|
1246
|
+
[access] is required. This is the access level to assign: full, read or none.
|
|
1247
|
+
Only applicable to Tenant roles.
|
|
1248
|
+
EOT
|
|
1249
|
+
end
|
|
1250
|
+
optparse.parse!(args)
|
|
1251
|
+
|
|
1252
|
+
if args.count < 2
|
|
1253
|
+
puts optparse
|
|
1254
|
+
exit 1
|
|
1255
|
+
end
|
|
1256
|
+
name = args[0]
|
|
1257
|
+
access_value = args[1].to_s.downcase
|
|
1258
|
+
if !['full', 'read', 'none', 'custom'].include?(access_value)
|
|
1259
|
+
puts optparse
|
|
1260
|
+
exit 1
|
|
1261
|
+
end
|
|
1262
|
+
|
|
1263
|
+
connect(options)
|
|
1264
|
+
begin
|
|
1265
|
+
account = find_account_from_options(options)
|
|
1266
|
+
account_id = account ? account['id'] : nil
|
|
1267
|
+
role = find_role_by_name_or_id(account_id, name)
|
|
1268
|
+
exit 1 if role.nil?
|
|
1269
|
+
|
|
1270
|
+
if role['roleType'] == 'user'
|
|
1271
|
+
raise_command_error "The default-cloud-access command is only available for account roles, not user roles"
|
|
1272
|
+
end
|
|
1273
|
+
|
|
1274
|
+
params = {permissionCode: 'ComputeZone', access: access_value}
|
|
1275
|
+
@roles_interface.setopts(options)
|
|
1276
|
+
if options[:dry_run]
|
|
1277
|
+
print_dry_run @roles_interface.dry.update_permission(account_id, role['id'], params)
|
|
1278
|
+
return
|
|
1279
|
+
end
|
|
1280
|
+
json_response = @roles_interface.update_permission(account_id, role['id'], params)
|
|
1281
|
+
|
|
1282
|
+
if options[:json]
|
|
1283
|
+
print JSON.pretty_generate(json_response)
|
|
1284
|
+
print "\n"
|
|
1285
|
+
else
|
|
1286
|
+
print_green_success "Role #{role['authority']} default cloud access updated"
|
|
1287
|
+
end
|
|
1288
|
+
rescue RestClient::Exception => e
|
|
1289
|
+
print_rest_exception(e, options)
|
|
1290
|
+
exit 1
|
|
1291
|
+
end
|
|
1292
|
+
end
|
|
1293
|
+
|
|
1294
|
+
def update_cloud_access(args)
|
|
1295
|
+
options = {}
|
|
1296
|
+
cloud_id = nil
|
|
1297
|
+
access_value = nil
|
|
1298
|
+
do_all = false
|
|
1299
|
+
allowed_access_values = ['full', 'read', 'none', 'default']
|
|
1300
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
1301
|
+
opts.banner = subcommand_usage("[role]")
|
|
1302
|
+
opts.on( '-c', '--cloud CLOUD', "Cloud name or id" ) do |val|
|
|
1303
|
+
cloud_id = val
|
|
1304
|
+
end
|
|
1305
|
+
opts.on( nil, '--all', "Update all clouds at once." ) do
|
|
1306
|
+
do_all = true
|
|
1307
|
+
end
|
|
1308
|
+
opts.on( '--access VALUE', String, "Access value [#{allowed_access_values.join('|')}]" ) do |val|
|
|
1309
|
+
access_value = val
|
|
1310
|
+
end
|
|
1311
|
+
build_common_options(opts, options, [:json, :dry_run, :remote])
|
|
1312
|
+
opts.footer = <<-EOT
|
|
1313
|
+
Update role access for a cloud or all clouds.
|
|
1314
|
+
[role] is required. This is the name or id of a role.
|
|
1315
|
+
--cloud or --all is required. This is the name or id of a cloud.
|
|
1316
|
+
--access is required. This is the new access value: #{ored_list(allowed_access_values)}
|
|
1317
|
+
EOT
|
|
1318
|
+
end
|
|
1319
|
+
optparse.parse!(args)
|
|
1320
|
+
|
|
1321
|
+
# usage: update-cloud-access [role] [access] --all
|
|
1322
|
+
# update-cloud-access [role] [cloud] [access]
|
|
1323
|
+
name = args[0]
|
|
1324
|
+
if do_all
|
|
1325
|
+
verify_args!(args:args, optparse:optparse, min:1, max:2)
|
|
1326
|
+
access_value = args[1] if args[1]
|
|
1327
|
+
else
|
|
1328
|
+
verify_args!(args:args, optparse:optparse, min:1, max:3)
|
|
1329
|
+
cloud_id = args[1] if args[1]
|
|
1330
|
+
access_value = args[2] if args[2]
|
|
1331
|
+
end
|
|
1332
|
+
if !cloud_id && !do_all
|
|
1333
|
+
raise_command_error("missing required argument: [cloud] or --all", args, optparse)
|
|
1334
|
+
end
|
|
1335
|
+
if !access_value
|
|
1336
|
+
raise_command_error("missing required argument: [access]", args, optparse)
|
|
1337
|
+
end
|
|
1338
|
+
access_value = access_value.to_s.downcase
|
|
1339
|
+
if !allowed_access_values.include?(access_value)
|
|
1340
|
+
raise_command_error("invalid access value: #{access_value}", args, optparse)
|
|
1341
|
+
end
|
|
1342
|
+
|
|
1343
|
+
connect(options)
|
|
1344
|
+
begin
|
|
1345
|
+
account = find_account_from_options(options)
|
|
1346
|
+
account_id = account ? account['id'] : nil
|
|
1347
|
+
role = find_role_by_name_or_id(account_id, name)
|
|
1348
|
+
exit 1 if role.nil?
|
|
1349
|
+
|
|
1350
|
+
role_json = @roles_interface.get(account_id, role['id'], {'includeDefaultAccess' => true})
|
|
1351
|
+
|
|
1352
|
+
cloud = nil
|
|
1353
|
+
if !do_all
|
|
1354
|
+
cloud = find_cloud_by_name_or_id_for_provisioning(nil, cloud_id)
|
|
1355
|
+
return 1 if cloud.nil?
|
|
1356
|
+
cloud_id = cloud['id']
|
|
1357
|
+
end
|
|
1358
|
+
params = {}
|
|
1359
|
+
if do_all
|
|
1360
|
+
params['allClouds'] = true
|
|
1361
|
+
else
|
|
1362
|
+
params['cloudId'] = cloud_id
|
|
1363
|
+
end
|
|
1364
|
+
params['access'] = access_value
|
|
1365
|
+
@roles_interface.setopts(options)
|
|
1366
|
+
if options[:dry_run]
|
|
1367
|
+
print_dry_run @roles_interface.dry.update_cloud(account_id, role['id'], params)
|
|
1368
|
+
return
|
|
1369
|
+
end
|
|
1370
|
+
json_response = @roles_interface.update_cloud(account_id, role['id'], params)
|
|
1371
|
+
|
|
1372
|
+
if options[:json]
|
|
1373
|
+
print JSON.pretty_generate(json_response)
|
|
1374
|
+
print "\n"
|
|
1375
|
+
else
|
|
1376
|
+
if do_all
|
|
1377
|
+
print_green_success "Role #{role['authority']} access updated for all clouds"
|
|
1378
|
+
else
|
|
1379
|
+
print_green_success "Role #{role['authority']} access updated for cloud #{cloud['name']}"
|
|
1380
|
+
end
|
|
1381
|
+
end
|
|
1382
|
+
return 0
|
|
1383
|
+
rescue RestClient::Exception => e
|
|
1384
|
+
print_rest_exception(e, options)
|
|
1385
|
+
exit 1
|
|
1386
|
+
end
|
|
1387
|
+
end
|
|
1388
|
+
|
|
1389
|
+
def update_global_instance_type_access(args)
|
|
1390
|
+
puts "#{yellow}DEPRECATED#{reset}"
|
|
1391
|
+
update_default_instance_type_access(args)
|
|
1392
|
+
end
|
|
1393
|
+
|
|
1394
|
+
def update_default_instance_type_access(args)
|
|
1395
|
+
options = {}
|
|
1396
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
1397
|
+
opts.banner = subcommand_usage("[role] [access]")
|
|
1398
|
+
build_common_options(opts, options, [:json, :dry_run, :remote])
|
|
1399
|
+
opts.footer = <<-EOT
|
|
1400
|
+
Update default instance type access for a role.
|
|
1401
|
+
[role] is required. This is the name (authority) or id of a role.
|
|
1402
|
+
[access] is required. This is the access level to assign: full or none.
|
|
1403
|
+
EOT
|
|
1404
|
+
end
|
|
1405
|
+
optparse.parse!(args)
|
|
1406
|
+
|
|
1407
|
+
if args.count < 2
|
|
1408
|
+
puts optparse
|
|
1409
|
+
exit 1
|
|
1410
|
+
end
|
|
1411
|
+
name = args[0]
|
|
1412
|
+
access_value = args[1].to_s.downcase
|
|
1413
|
+
if !['full', 'none', 'custom'].include?(access_value)
|
|
1414
|
+
puts optparse
|
|
1415
|
+
exit 1
|
|
1416
|
+
end
|
|
1417
|
+
|
|
1418
|
+
|
|
1419
|
+
connect(options)
|
|
1420
|
+
begin
|
|
1421
|
+
account = find_account_from_options(options)
|
|
1422
|
+
account_id = account ? account['id'] : nil
|
|
1423
|
+
role = find_role_by_name_or_id(account_id, name)
|
|
1424
|
+
exit 1 if role.nil?
|
|
1425
|
+
|
|
1426
|
+
params = {permissionCode: 'InstanceType', access: access_value}
|
|
1427
|
+
@roles_interface.setopts(options)
|
|
1428
|
+
if options[:dry_run]
|
|
1429
|
+
print_dry_run @roles_interface.dry.update_permission(account_id, role['id'], params)
|
|
1430
|
+
return
|
|
1431
|
+
end
|
|
1432
|
+
json_response = @roles_interface.update_permission(account_id, role['id'], params)
|
|
1433
|
+
|
|
1434
|
+
if options[:json]
|
|
1435
|
+
print JSON.pretty_generate(json_response)
|
|
1436
|
+
print "\n"
|
|
1437
|
+
else
|
|
1438
|
+
print_green_success "Role #{role['authority']} default instance type access updated"
|
|
1439
|
+
end
|
|
1440
|
+
rescue RestClient::Exception => e
|
|
1441
|
+
print_rest_exception(e, options)
|
|
1442
|
+
exit 1
|
|
1443
|
+
end
|
|
1444
|
+
end
|
|
1445
|
+
|
|
1446
|
+
def update_instance_type_access(args)
|
|
1447
|
+
options = {}
|
|
1448
|
+
instance_type_name = nil
|
|
1449
|
+
access_value = nil
|
|
1450
|
+
do_all = false
|
|
1451
|
+
allowed_access_values = ['full', 'none', 'default']
|
|
1452
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
1453
|
+
opts.banner = subcommand_usage("[role] [type] [access]")
|
|
1454
|
+
opts.on( '--instance-type INSTANCE_TYPE', String, "Instance Type name" ) do |val|
|
|
1455
|
+
instance_type_name = val
|
|
1456
|
+
end
|
|
1457
|
+
opts.on( nil, '--all', "Update all instance types at once." ) do
|
|
1458
|
+
do_all = true
|
|
1459
|
+
end
|
|
1460
|
+
opts.on( '--access VALUE', String, "Access value [#{allowed_access_values.join('|')}]" ) do |val|
|
|
1461
|
+
access_value = val
|
|
1462
|
+
end
|
|
1463
|
+
build_common_options(opts, options, [:json, :dry_run, :remote])
|
|
1464
|
+
opts.footer = "Update role access for an instance type or all instance types.\n" +
|
|
1465
|
+
"[role] is required. This is the name or id of a role.\n" +
|
|
1466
|
+
"--instance-type or --all is required. This is the name of an instance type.\n" +
|
|
1467
|
+
"--access is required. This is the new access value: #{ored_list(allowed_access_values)}"
|
|
1468
|
+
end
|
|
1469
|
+
optparse.parse!(args)
|
|
1470
|
+
|
|
1471
|
+
if args.count < 1
|
|
1472
|
+
puts optparse
|
|
1473
|
+
return 1
|
|
1474
|
+
end
|
|
1475
|
+
name = args[0]
|
|
1476
|
+
# support old usage: [role] [instance-type] [access]
|
|
1477
|
+
instance_type_name ||= args[1]
|
|
1478
|
+
access_value ||= args[2]
|
|
1479
|
+
|
|
1480
|
+
if (!instance_type_name && !do_all) || !access_value
|
|
1481
|
+
puts optparse
|
|
1482
|
+
return 1
|
|
1483
|
+
end
|
|
1484
|
+
|
|
1485
|
+
access_value = access_value.to_s.downcase
|
|
1486
|
+
|
|
1487
|
+
if !['full', 'none'].include?(access_value)
|
|
1488
|
+
puts optparse
|
|
1489
|
+
return 1
|
|
1490
|
+
end
|
|
1491
|
+
|
|
1492
|
+
connect(options)
|
|
1493
|
+
begin
|
|
1494
|
+
account = find_account_from_options(options)
|
|
1495
|
+
account_id = account ? account['id'] : nil
|
|
1496
|
+
role = find_role_by_name_or_id(account_id, name)
|
|
1497
|
+
return 1 if role.nil?
|
|
1498
|
+
|
|
1499
|
+
role_json = @roles_interface.get(account_id, role['id'], {'includeDefaultAccess' => true})
|
|
1500
|
+
instance_type = nil
|
|
1501
|
+
if !do_all
|
|
1502
|
+
instance_type = find_instance_type_by_name(instance_type_name)
|
|
1503
|
+
return 1 if instance_type.nil?
|
|
1504
|
+
end
|
|
1505
|
+
|
|
1506
|
+
params = {}
|
|
1507
|
+
if do_all
|
|
1508
|
+
params['allInstanceTypes'] = true
|
|
1509
|
+
else
|
|
1510
|
+
params['instanceTypeId'] = instance_type['id']
|
|
1511
|
+
end
|
|
1512
|
+
params['access'] = access_value
|
|
1513
|
+
@roles_interface.setopts(options)
|
|
1514
|
+
if options[:dry_run]
|
|
1515
|
+
print_dry_run @roles_interface.dry.update_instance_type(account_id, role['id'], params)
|
|
1516
|
+
return
|
|
1517
|
+
end
|
|
1518
|
+
json_response = @roles_interface.update_instance_type(account_id, role['id'], params)
|
|
1519
|
+
|
|
1520
|
+
if options[:json]
|
|
1521
|
+
print JSON.pretty_generate(json_response)
|
|
1522
|
+
print "\n"
|
|
1523
|
+
else
|
|
1524
|
+
if do_all
|
|
1525
|
+
print_green_success "Role #{role['authority']} access updated for all instance types"
|
|
1526
|
+
else
|
|
1527
|
+
print_green_success "Role #{role['authority']} access updated for instance type #{instance_type['name']}"
|
|
1528
|
+
end
|
|
1529
|
+
end
|
|
1530
|
+
return 0
|
|
1531
|
+
rescue RestClient::Exception => e
|
|
1532
|
+
print_rest_exception(e, options)
|
|
1533
|
+
exit 1
|
|
1534
|
+
end
|
|
1535
|
+
end
|
|
1536
|
+
|
|
1537
|
+
def update_global_blueprint_access(args)
|
|
1538
|
+
puts "#{yellow}DEPRECATED#{reset}"
|
|
1539
|
+
update_default_blueprint_access(args)
|
|
1540
|
+
end
|
|
1541
|
+
|
|
1542
|
+
def update_default_blueprint_access(args)
|
|
1543
|
+
options = {}
|
|
1544
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
1545
|
+
opts.banner = subcommand_usage("[role] [access]")
|
|
1546
|
+
build_common_options(opts, options, [:json, :dry_run, :remote])
|
|
1547
|
+
opts.footer = <<-EOT
|
|
1548
|
+
Update default blueprint access for a role.
|
|
1549
|
+
[role] is required. This is the name (authority) or id of a role.
|
|
1550
|
+
[access] is required. This is the access level to assign: full or none.
|
|
1551
|
+
EOT
|
|
1552
|
+
end
|
|
1553
|
+
optparse.parse!(args)
|
|
1554
|
+
|
|
1555
|
+
if args.count < 2
|
|
1556
|
+
puts optparse
|
|
1557
|
+
exit 1
|
|
1558
|
+
end
|
|
1559
|
+
name = args[0]
|
|
1560
|
+
access_value = args[1].to_s.downcase
|
|
1561
|
+
if !['full', 'none', 'custom'].include?(access_value)
|
|
1562
|
+
puts optparse
|
|
1563
|
+
exit 1
|
|
1564
|
+
end
|
|
1565
|
+
|
|
1566
|
+
|
|
1567
|
+
connect(options)
|
|
1568
|
+
begin
|
|
1569
|
+
account = find_account_from_options(options)
|
|
1570
|
+
account_id = account ? account['id'] : nil
|
|
1571
|
+
role = find_role_by_name_or_id(account_id, name)
|
|
1572
|
+
exit 1 if role.nil?
|
|
1573
|
+
|
|
1574
|
+
params = {permissionCode: 'AppTemplate', access: access_value}
|
|
1575
|
+
@roles_interface.setopts(options)
|
|
1576
|
+
if options[:dry_run]
|
|
1577
|
+
print_dry_run @roles_interface.dry.update_permission(account_id, role['id'], params)
|
|
1578
|
+
return
|
|
1579
|
+
end
|
|
1580
|
+
json_response = @roles_interface.update_permission(account_id, role['id'], params)
|
|
1581
|
+
|
|
1582
|
+
if options[:json]
|
|
1583
|
+
print JSON.pretty_generate(json_response)
|
|
1584
|
+
print "\n"
|
|
1585
|
+
else
|
|
1586
|
+
print_green_success "Role #{role['authority']} default blueprint access updated"
|
|
1587
|
+
end
|
|
1588
|
+
rescue RestClient::Exception => e
|
|
1589
|
+
print_rest_exception(e, options)
|
|
1590
|
+
exit 1
|
|
1591
|
+
end
|
|
1592
|
+
end
|
|
1593
|
+
|
|
1594
|
+
def update_blueprint_access(args)
|
|
1595
|
+
options = {}
|
|
1596
|
+
blueprint_id = nil
|
|
1597
|
+
access_value = nil
|
|
1598
|
+
do_all = false
|
|
1599
|
+
allowed_access_values = ['full', 'none', 'default']
|
|
1600
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
1601
|
+
opts.banner = subcommand_usage("[role] [blueprint] [access]")
|
|
1602
|
+
opts.on( '--blueprint ID', String, "Blueprint ID or Name" ) do |val|
|
|
1603
|
+
blueprint_id = val
|
|
1604
|
+
end
|
|
1605
|
+
opts.on( nil, '--all', "Update all blueprints at once." ) do
|
|
1606
|
+
do_all = true
|
|
1607
|
+
end
|
|
1608
|
+
opts.on( '--access VALUE', String, "Access value [#{allowed_access_values.join('|')}]" ) do |val|
|
|
1609
|
+
access_value = val
|
|
1610
|
+
end
|
|
1611
|
+
build_common_options(opts, options, [:json, :dry_run, :remote])
|
|
1612
|
+
opts.footer = "Update role access for a blueprint or all blueprints.\n" +
|
|
1613
|
+
"[role] is required. This is the name or id of a role.\n" +
|
|
1614
|
+
"--blueprint or --all is required. This is the name or id of a blueprint.\n" +
|
|
1615
|
+
"--access is required. This is the new access value: #{ored_list(allowed_access_values)}"
|
|
1616
|
+
end
|
|
1617
|
+
optparse.parse!(args)
|
|
1618
|
+
|
|
1619
|
+
# usage: update-blueprint-access [role] [access] --all
|
|
1620
|
+
# update-blueprint-access [role] [blueprint] [access]
|
|
1621
|
+
name = args[0]
|
|
1622
|
+
if do_all
|
|
1623
|
+
verify_args!(args:args, optparse:optparse, min:1, max:2)
|
|
1624
|
+
access_value = args[1] if args[1]
|
|
1625
|
+
else
|
|
1626
|
+
verify_args!(args:args, optparse:optparse, min:1, max:3)
|
|
1627
|
+
blueprint_id = args[1] if args[1]
|
|
1628
|
+
access_value = args[2] if args[2]
|
|
1629
|
+
end
|
|
1630
|
+
if !blueprint_id && !do_all
|
|
1631
|
+
raise_command_error("missing required argument: [blueprint] or --all", args, optparse)
|
|
1632
|
+
end
|
|
1633
|
+
if !access_value
|
|
1634
|
+
raise_command_error("missing required argument: [access]", args, optparse)
|
|
1635
|
+
end
|
|
1636
|
+
access_value = access_value.to_s.downcase
|
|
1637
|
+
if !allowed_access_values.include?(access_value)
|
|
1638
|
+
raise_command_error("invalid access value: #{access_value}", args, optparse)
|
|
1639
|
+
end
|
|
1640
|
+
|
|
1641
|
+
connect(options)
|
|
1642
|
+
begin
|
|
1643
|
+
account = find_account_from_options(options)
|
|
1644
|
+
account_id = account ? account['id'] : nil
|
|
1645
|
+
role = find_role_by_name_or_id(account_id, name)
|
|
1646
|
+
return 1 if role.nil?
|
|
1647
|
+
|
|
1648
|
+
role_json = @roles_interface.get(account_id, role['id'], {'includeDefaultAccess' => true})
|
|
1649
|
+
blueprint_global_access = role_json['globalAppTemplateAccess'] || role_json['globalBlueprintAccess']
|
|
1650
|
+
blueprint_permissions = role_json['appTemplatePermissions'] || role_json['blueprintPermissions'] || []
|
|
1651
|
+
|
|
1652
|
+
# hacky, but support name or code lookup via the list returned in the show payload
|
|
1653
|
+
blueprint = nil
|
|
1654
|
+
if !do_all
|
|
1655
|
+
if blueprint_id.to_s =~ /\A\d{1,}\Z/
|
|
1656
|
+
blueprint = blueprint_permissions.find {|b| b['id'] == blueprint_id.to_i }
|
|
1657
|
+
else
|
|
1658
|
+
blueprint = blueprint_permissions.find {|b| b['name'] == blueprint_id || b['code'] == blueprint_id }
|
|
1659
|
+
end
|
|
1660
|
+
if blueprint.nil?
|
|
1661
|
+
print_red_alert "Blueprint not found: '#{blueprint_id}'"
|
|
1662
|
+
return 1
|
|
1663
|
+
end
|
|
1664
|
+
end
|
|
1665
|
+
|
|
1666
|
+
params = {}
|
|
1667
|
+
if do_all
|
|
1668
|
+
params['allAppTemplates'] = true
|
|
1669
|
+
#params['allBlueprints'] = true
|
|
1670
|
+
else
|
|
1671
|
+
params['appTemplateId'] = blueprint['id']
|
|
1672
|
+
# params['blueprintId'] = blueprint['id']
|
|
1673
|
+
end
|
|
1674
|
+
params['access'] = access_value
|
|
1675
|
+
@roles_interface.setopts(options)
|
|
1676
|
+
if options[:dry_run]
|
|
1677
|
+
print_dry_run @roles_interface.dry.update_blueprint(account_id, role['id'], params)
|
|
1678
|
+
return
|
|
1679
|
+
end
|
|
1680
|
+
json_response = @roles_interface.update_blueprint(account_id, role['id'], params)
|
|
1681
|
+
|
|
1682
|
+
if options[:json]
|
|
1683
|
+
print JSON.pretty_generate(json_response)
|
|
1684
|
+
print "\n"
|
|
1685
|
+
else
|
|
1686
|
+
if do_all
|
|
1687
|
+
print_green_success "Role #{role['authority']} access updated for all blueprints"
|
|
1688
|
+
else
|
|
1689
|
+
print_green_success "Role #{role['authority']} access updated for blueprint #{blueprint['name']}"
|
|
1690
|
+
end
|
|
1691
|
+
end
|
|
1692
|
+
return 0
|
|
1693
|
+
rescue RestClient::Exception => e
|
|
1694
|
+
print_rest_exception(e, options)
|
|
1695
|
+
exit 1
|
|
1696
|
+
end
|
|
1697
|
+
end
|
|
1698
|
+
|
|
1699
|
+
def update_global_catalog_item_type_access(args)
|
|
1700
|
+
puts "#{yellow}DEPRECATED#{reset}"
|
|
1701
|
+
update_default_catalog_item_type_access(args)
|
|
1702
|
+
end
|
|
1703
|
+
|
|
1704
|
+
def update_default_catalog_item_type_access(args)
|
|
1705
|
+
options = {}
|
|
1706
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
1707
|
+
opts.banner = subcommand_usage("[role] [access]")
|
|
1708
|
+
build_common_options(opts, options, [:json, :dry_run, :remote])
|
|
1709
|
+
opts.footer = <<-EOT
|
|
1710
|
+
Update default catalog item type access for a role.
|
|
1711
|
+
[role] is required. This is the name (authority) or id of a role.
|
|
1712
|
+
[access] is required. This is the access level to assign: full or none.
|
|
1713
|
+
EOT
|
|
1714
|
+
end
|
|
1715
|
+
optparse.parse!(args)
|
|
1716
|
+
|
|
1717
|
+
if args.count < 2
|
|
1718
|
+
puts optparse
|
|
1719
|
+
exit 1
|
|
1720
|
+
end
|
|
1721
|
+
name = args[0]
|
|
1722
|
+
access_value = args[1].to_s.downcase
|
|
1723
|
+
if !['full', 'none', 'custom'].include?(access_value)
|
|
1724
|
+
puts optparse
|
|
1725
|
+
exit 1
|
|
1726
|
+
end
|
|
1727
|
+
|
|
1728
|
+
|
|
1729
|
+
connect(options)
|
|
1730
|
+
begin
|
|
1731
|
+
account = find_account_from_options(options)
|
|
1732
|
+
account_id = account ? account['id'] : nil
|
|
1733
|
+
role = find_role_by_name_or_id(account_id, name)
|
|
1734
|
+
exit 1 if role.nil?
|
|
1735
|
+
|
|
1736
|
+
params = {permissionCode: 'CatalogItemType', access: access_value}
|
|
1737
|
+
@roles_interface.setopts(options)
|
|
1738
|
+
if options[:dry_run]
|
|
1739
|
+
print_dry_run @roles_interface.dry.update_permission(account_id, role['id'], params)
|
|
1740
|
+
return
|
|
1741
|
+
end
|
|
1742
|
+
json_response = @roles_interface.update_permission(account_id, role['id'], params)
|
|
1743
|
+
|
|
1744
|
+
if options[:json]
|
|
1745
|
+
print JSON.pretty_generate(json_response)
|
|
1746
|
+
print "\n"
|
|
1747
|
+
else
|
|
1748
|
+
print_green_success "Role #{role['authority']} default catalog item type access updated"
|
|
1749
|
+
end
|
|
1750
|
+
rescue RestClient::Exception => e
|
|
1751
|
+
print_rest_exception(e, options)
|
|
1752
|
+
exit 1
|
|
1753
|
+
end
|
|
1754
|
+
end
|
|
1755
|
+
|
|
1756
|
+
def update_catalog_item_type_access(args)
|
|
1757
|
+
options = {}
|
|
1758
|
+
catalog_item_type_id = nil
|
|
1759
|
+
access_value = nil
|
|
1760
|
+
do_all = false
|
|
1761
|
+
allowed_access_values = ['full', 'none', 'default']
|
|
1762
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
1763
|
+
opts.banner = subcommand_usage("[role] [catalog-item-type] [access]")
|
|
1764
|
+
opts.on( '--catalog-item-type ID', String, "Catalog Item Type ID or Name" ) do |val|
|
|
1765
|
+
catalog_item_type_id = val
|
|
1766
|
+
end
|
|
1767
|
+
opts.on( nil, '--all', "Update all catalog item types at once." ) do
|
|
1768
|
+
do_all = true
|
|
1769
|
+
end
|
|
1770
|
+
opts.on( '--access VALUE', String, "Access value [#{allowed_access_values.join('|')}]" ) do |val|
|
|
1771
|
+
access_value = val
|
|
1772
|
+
end
|
|
1773
|
+
build_common_options(opts, options, [:json, :dry_run, :remote])
|
|
1774
|
+
opts.footer = "Update role access for a catalog item type or all types.\n" +
|
|
1775
|
+
"[role] is required. This is the name or id of a role.\n" +
|
|
1776
|
+
"--catalog-item-type or --all is required. This is the name or id of a catalog item type.\n" +
|
|
1777
|
+
"--access is required. This is the new access value: #{ored_list(allowed_access_values)}"
|
|
1778
|
+
end
|
|
1779
|
+
optparse.parse!(args)
|
|
1780
|
+
|
|
1781
|
+
# usage: update-catalog_item_type-access [role] [access] --all
|
|
1782
|
+
# update-catalog_item_type-access [role] [catalog-item-type] [access]
|
|
1783
|
+
name = args[0]
|
|
1784
|
+
if do_all
|
|
1785
|
+
verify_args!(args:args, optparse:optparse, min:1, max:2)
|
|
1786
|
+
access_value = args[1] if args[1]
|
|
1787
|
+
else
|
|
1788
|
+
verify_args!(args:args, optparse:optparse, min:1, max:3)
|
|
1789
|
+
catalog_item_type_id = args[1] if args[1]
|
|
1790
|
+
access_value = args[2] if args[2]
|
|
1791
|
+
end
|
|
1792
|
+
if !catalog_item_type_id && !do_all
|
|
1793
|
+
raise_command_error("missing required argument: [catalog-item-type] or --all", args, optparse)
|
|
1794
|
+
end
|
|
1795
|
+
if !access_value
|
|
1796
|
+
raise_command_error("missing required argument: [access]", args, optparse)
|
|
1797
|
+
end
|
|
1798
|
+
access_value = access_value.to_s.downcase
|
|
1799
|
+
if !allowed_access_values.include?(access_value)
|
|
1800
|
+
raise_command_error("invalid access value: #{access_value}", args, optparse)
|
|
1801
|
+
end
|
|
1802
|
+
|
|
1803
|
+
connect(options)
|
|
1804
|
+
begin
|
|
1805
|
+
account = find_account_from_options(options)
|
|
1806
|
+
account_id = account ? account['id'] : nil
|
|
1807
|
+
role = find_role_by_name_or_id(account_id, name)
|
|
1808
|
+
return 1 if role.nil?
|
|
1809
|
+
|
|
1810
|
+
role_json = @roles_interface.get(account_id, role['id'], {'includeDefaultAccess' => true})
|
|
1811
|
+
catalog_item_type_global_access = role_json['globalCatalogItemTypeAccess']
|
|
1812
|
+
catalog_item_type_permissions = role_json['catalogItemTypePermissions'] || role_json['catalogItemTypes'] []
|
|
1813
|
+
|
|
1814
|
+
# hacky, but support name or code lookup via the list returned in the show payload
|
|
1815
|
+
catalog_item_type = nil
|
|
1816
|
+
if !do_all
|
|
1817
|
+
if catalog_item_type_id.to_s =~ /\A\d{1,}\Z/
|
|
1818
|
+
catalog_item_type = catalog_item_type_permissions.find {|b| b['id'] == catalog_item_type_id.to_i }
|
|
1819
|
+
else
|
|
1820
|
+
catalog_item_type = catalog_item_type_permissions.find {|b| b['name'] == catalog_item_type_id }
|
|
1821
|
+
end
|
|
1822
|
+
if catalog_item_type.nil?
|
|
1823
|
+
print_red_alert "Catalog Item Type not found: '#{catalog_item_type_id}'"
|
|
1824
|
+
return 1
|
|
1825
|
+
end
|
|
1826
|
+
end
|
|
1827
|
+
|
|
1828
|
+
params = {}
|
|
1829
|
+
if do_all
|
|
1830
|
+
params['allCatalogItemTypes'] = true
|
|
1831
|
+
else
|
|
1832
|
+
params['catalogItemTypeId'] = catalog_item_type['id']
|
|
1833
|
+
end
|
|
1834
|
+
params['access'] = access_value
|
|
1835
|
+
@roles_interface.setopts(options)
|
|
1836
|
+
if options[:dry_run]
|
|
1837
|
+
print_dry_run @roles_interface.dry.update_catalog_item_type(account_id, role['id'], params)
|
|
1838
|
+
return
|
|
1839
|
+
end
|
|
1840
|
+
json_response = @roles_interface.update_catalog_item_type(account_id, role['id'], params)
|
|
1841
|
+
|
|
1842
|
+
if options[:json]
|
|
1843
|
+
print JSON.pretty_generate(json_response)
|
|
1844
|
+
print "\n"
|
|
1845
|
+
else
|
|
1846
|
+
if do_all
|
|
1847
|
+
print_green_success "Role #{role['authority']} access updated for all catalog item types"
|
|
1848
|
+
else
|
|
1849
|
+
print_green_success "Role #{role['authority']} access updated for catalog item type #{catalog_item_type['name']}"
|
|
1850
|
+
end
|
|
1851
|
+
end
|
|
1852
|
+
return 0
|
|
1853
|
+
rescue RestClient::Exception => e
|
|
1854
|
+
print_rest_exception(e, options)
|
|
1855
|
+
exit 1
|
|
1856
|
+
end
|
|
1857
|
+
end
|
|
1858
|
+
|
|
1859
|
+
def update_default_persona_access(args)
|
|
1860
|
+
options = {}
|
|
1861
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
1862
|
+
opts.banner = subcommand_usage("[role] [access]")
|
|
1863
|
+
build_common_options(opts, options, [:json, :dry_run, :remote])
|
|
1864
|
+
opts.footer = <<-EOT
|
|
1865
|
+
Update default persona access for a role.
|
|
1866
|
+
[role] is required. This is the name (authority) or id of a role.
|
|
1867
|
+
[access] is required. This is the access level to assign: full or none.
|
|
1868
|
+
EOT
|
|
1869
|
+
end
|
|
1870
|
+
optparse.parse!(args)
|
|
1871
|
+
|
|
1872
|
+
if args.count < 2
|
|
1873
|
+
puts optparse
|
|
1874
|
+
exit 1
|
|
1875
|
+
end
|
|
1876
|
+
name = args[0]
|
|
1877
|
+
access_value = args[1].to_s.downcase
|
|
1878
|
+
if !['full', 'none', 'custom'].include?(access_value)
|
|
1879
|
+
puts optparse
|
|
1880
|
+
exit 1
|
|
1881
|
+
end
|
|
1882
|
+
|
|
1883
|
+
connect(options)
|
|
1884
|
+
begin
|
|
1885
|
+
account = find_account_from_options(options)
|
|
1886
|
+
account_id = account ? account['id'] : nil
|
|
1887
|
+
role = find_role_by_name_or_id(account_id, name)
|
|
1888
|
+
exit 1 if role.nil?
|
|
1889
|
+
|
|
1890
|
+
params = {permissionCode: 'Persona', access: access_value}
|
|
1891
|
+
@roles_interface.setopts(options)
|
|
1892
|
+
if options[:dry_run]
|
|
1893
|
+
print_dry_run @roles_interface.dry.update_permission(account_id, role['id'], params)
|
|
1894
|
+
return
|
|
1895
|
+
end
|
|
1896
|
+
json_response = @roles_interface.update_permission(account_id, role['id'], params)
|
|
1897
|
+
|
|
1898
|
+
if options[:json]
|
|
1899
|
+
print JSON.pretty_generate(json_response)
|
|
1900
|
+
print "\n"
|
|
1901
|
+
else
|
|
1902
|
+
print_green_success "Role #{role['authority']} default persona access updated"
|
|
1903
|
+
end
|
|
1904
|
+
rescue RestClient::Exception => e
|
|
1905
|
+
print_rest_exception(e, options)
|
|
1906
|
+
exit 1
|
|
1907
|
+
end
|
|
1908
|
+
end
|
|
1909
|
+
|
|
1910
|
+
def update_persona_access(args)
|
|
1911
|
+
options = {}
|
|
1912
|
+
persona_id = nil
|
|
1913
|
+
name = nil
|
|
1914
|
+
access_value = nil
|
|
1915
|
+
do_all = false
|
|
1916
|
+
allowed_access_values = ['full', 'none', 'default']
|
|
1917
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
1918
|
+
opts.banner = subcommand_usage("[role] [persona] [access]")
|
|
1919
|
+
opts.on( '--persona CODE', String, "Persona Code" ) do |val|
|
|
1920
|
+
persona_id = val
|
|
1921
|
+
end
|
|
1922
|
+
opts.on( nil, '--all', "Update all personas at once." ) do
|
|
1923
|
+
do_all = true
|
|
1924
|
+
end
|
|
1925
|
+
opts.on( '--access VALUE', String, "Access value [#{allowed_access_values.join('|')}]" ) do |val|
|
|
1926
|
+
access_value = val
|
|
1927
|
+
end
|
|
1928
|
+
build_common_options(opts, options, [:json, :dry_run, :remote])
|
|
1929
|
+
opts.footer = "Update role access for a persona or all personas.\n" +
|
|
1930
|
+
"[role] is required. This is the name or id of a role.\n" +
|
|
1931
|
+
"--persona or --all is required. This is the code of a persona. Service Catalog, Standard, or Virtual Desktop\n" +
|
|
1932
|
+
"--access is required. This is the new access value: #{ored_list(allowed_access_values)}"
|
|
1933
|
+
end
|
|
1934
|
+
optparse.parse!(args)
|
|
1935
|
+
|
|
1936
|
+
# usage: update-persona-access [role] [access] --all
|
|
1937
|
+
# update-persona-access [role] [persona] [access]
|
|
1938
|
+
name = args[0]
|
|
1939
|
+
if do_all
|
|
1940
|
+
verify_args!(args:args, optparse:optparse, min:1, max:2)
|
|
1941
|
+
access_value = args[1] if args[1]
|
|
1942
|
+
else
|
|
1943
|
+
verify_args!(args:args, optparse:optparse, min:1, max:3)
|
|
1944
|
+
persona_id = args[1] if args[1]
|
|
1945
|
+
access_value = args[2] if args[2]
|
|
1946
|
+
end
|
|
1947
|
+
if !persona_id && !do_all
|
|
1948
|
+
raise_command_error("missing required argument: [persona] or --all", args, optparse)
|
|
1949
|
+
end
|
|
1950
|
+
if !access_value
|
|
1951
|
+
raise_command_error("missing required argument: [access]", args, optparse)
|
|
1952
|
+
end
|
|
1953
|
+
access_value = access_value.to_s.downcase
|
|
1954
|
+
if !allowed_access_values.include?(access_value)
|
|
1955
|
+
raise_command_error("invalid access value: #{access_value}", args, optparse)
|
|
1956
|
+
end
|
|
1957
|
+
|
|
1958
|
+
connect(options)
|
|
1959
|
+
begin
|
|
1960
|
+
account = find_account_from_options(options)
|
|
1961
|
+
account_id = account ? account['id'] : nil
|
|
1962
|
+
role = find_role_by_name_or_id(account_id, name)
|
|
1963
|
+
return 1 if role.nil?
|
|
1964
|
+
|
|
1965
|
+
role_json = @roles_interface.get(account_id, role['id'], {'includeDefaultAccess' => true})
|
|
1966
|
+
|
|
1967
|
+
# no lookup right now, pass the code serviceCatalog|standard
|
|
1968
|
+
persona_code = persona_id
|
|
1969
|
+
|
|
1970
|
+
params = {}
|
|
1971
|
+
if do_all
|
|
1972
|
+
params['allPersonas'] = true
|
|
1973
|
+
else
|
|
1974
|
+
params['personaCode'] = persona_code
|
|
1975
|
+
end
|
|
1976
|
+
params['access'] = access_value
|
|
1977
|
+
@roles_interface.setopts(options)
|
|
1978
|
+
if options[:dry_run]
|
|
1979
|
+
print_dry_run @roles_interface.dry.update_persona(account_id, role['id'], params)
|
|
1980
|
+
return
|
|
1981
|
+
end
|
|
1982
|
+
json_response = @roles_interface.update_persona(account_id, role['id'], params)
|
|
1983
|
+
|
|
1984
|
+
if options[:json]
|
|
1985
|
+
print JSON.pretty_generate(json_response)
|
|
1986
|
+
print "\n"
|
|
1987
|
+
else
|
|
1988
|
+
if do_all
|
|
1989
|
+
print_green_success "Role #{role['authority']} access updated for all personas"
|
|
1990
|
+
else
|
|
1991
|
+
print_green_success "Role #{role['authority']} access updated for persona #{persona_code}"
|
|
1992
|
+
end
|
|
1993
|
+
end
|
|
1994
|
+
return 0
|
|
1995
|
+
rescue RestClient::Exception => e
|
|
1996
|
+
print_rest_exception(e, options)
|
|
1997
|
+
exit 1
|
|
1998
|
+
end
|
|
1999
|
+
end
|
|
2000
|
+
|
|
2001
|
+
def update_global_vdi_pool_access(args)
|
|
2002
|
+
puts "#{yellow}DEPRECATED#{reset}"
|
|
2003
|
+
update_default_vdi_pool_access(args)
|
|
2004
|
+
end
|
|
2005
|
+
|
|
2006
|
+
def update_default_vdi_pool_access(args)
|
|
2007
|
+
options = {}
|
|
2008
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
2009
|
+
opts.banner = subcommand_usage("[role] [access]")
|
|
2010
|
+
build_common_options(opts, options, [:json, :dry_run, :remote])
|
|
2011
|
+
opts.footer = <<-EOT
|
|
2012
|
+
Update default VDI pool access for a role.
|
|
2013
|
+
[role] is required. This is the name (authority) or id of a role.
|
|
2014
|
+
[access] is required. This is the access level to assign: full or none.
|
|
2015
|
+
EOT
|
|
2016
|
+
end
|
|
2017
|
+
optparse.parse!(args)
|
|
2018
|
+
verify_args!(args:args, optparse:optparse, count: 2)
|
|
2019
|
+
name = args[0]
|
|
2020
|
+
access_value = args[1].to_s.downcase
|
|
2021
|
+
if !['full', 'none', 'custom'].include?(access_value)
|
|
2022
|
+
raise_command_error("invalid access value: #{args[1]}", args, optparse)
|
|
2023
|
+
end
|
|
2024
|
+
|
|
2025
|
+
|
|
2026
|
+
connect(options)
|
|
2027
|
+
begin
|
|
2028
|
+
account = find_account_from_options(options)
|
|
2029
|
+
account_id = account ? account['id'] : nil
|
|
2030
|
+
role = find_role_by_name_or_id(account_id, name)
|
|
2031
|
+
exit 1 if role.nil?
|
|
2032
|
+
# note: VdiPools being plural is odd, the others are singular
|
|
2033
|
+
params = {permissionCode: 'VdiPools', access: access_value}
|
|
2034
|
+
@roles_interface.setopts(options)
|
|
2035
|
+
if options[:dry_run]
|
|
2036
|
+
print_dry_run @roles_interface.dry.update_permission(account_id, role['id'], params)
|
|
2037
|
+
return
|
|
2038
|
+
end
|
|
2039
|
+
json_response = @roles_interface.update_permission(account_id, role['id'], params)
|
|
2040
|
+
|
|
2041
|
+
if options[:json]
|
|
2042
|
+
print JSON.pretty_generate(json_response)
|
|
2043
|
+
print "\n"
|
|
2044
|
+
else
|
|
2045
|
+
print_green_success "Role #{role['authority']} default vdi pool access updated"
|
|
2046
|
+
end
|
|
2047
|
+
rescue RestClient::Exception => e
|
|
2048
|
+
print_rest_exception(e, options)
|
|
2049
|
+
exit 1
|
|
2050
|
+
end
|
|
2051
|
+
end
|
|
2052
|
+
|
|
2053
|
+
def update_vdi_pool_access(args)
|
|
2054
|
+
options = {}
|
|
2055
|
+
vdi_pool_id = nil
|
|
2056
|
+
access_value = nil
|
|
2057
|
+
do_all = false
|
|
2058
|
+
allowed_access_values = ['full', 'none', 'default']
|
|
2059
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
2060
|
+
opts.banner = subcommand_usage("[role] [vdi-pool] [access]")
|
|
2061
|
+
opts.on( '--vdi-pool ID', String, "VDI Pool ID or Name" ) do |val|
|
|
2062
|
+
vdi_pool_id = val
|
|
2063
|
+
end
|
|
2064
|
+
opts.on( nil, '--all', "Update all VDI pools at once." ) do
|
|
2065
|
+
do_all = true
|
|
2066
|
+
end
|
|
2067
|
+
opts.on( '--access VALUE', String, "Access value [#{allowed_access_values.join('|')}]" ) do |val|
|
|
2068
|
+
access_value = val
|
|
2069
|
+
end
|
|
2070
|
+
build_common_options(opts, options, [:json, :dry_run, :remote])
|
|
2071
|
+
opts.footer = "Update role access for a VDI pool or all VDI pools.\n" +
|
|
2072
|
+
"[role] is required. This is the name or id of a role.\n" +
|
|
2073
|
+
"--vdi-pool or --all is required. This is the name or id of a VDI pool.\n" +
|
|
2074
|
+
"--access is required. This is the new access value: #{ored_list(allowed_access_values)}"
|
|
2075
|
+
end
|
|
2076
|
+
optparse.parse!(args)
|
|
2077
|
+
|
|
2078
|
+
name = args[0]
|
|
2079
|
+
if do_all
|
|
2080
|
+
verify_args!(args:args, optparse:optparse, min:1, max:2)
|
|
2081
|
+
access_value = args[1] if args[1]
|
|
2082
|
+
else
|
|
2083
|
+
verify_args!(args:args, optparse:optparse, min:1, max:3)
|
|
2084
|
+
vdi_pool_id = args[1] if args[1]
|
|
2085
|
+
access_value = args[2] if args[2]
|
|
2086
|
+
end
|
|
2087
|
+
if !vdi_pool_id && !do_all
|
|
2088
|
+
raise_command_error("missing required argument: [vdi-pool] or --all", args, optparse)
|
|
2089
|
+
end
|
|
2090
|
+
if !access_value
|
|
2091
|
+
raise_command_error("missing required argument: [access]", args, optparse)
|
|
2092
|
+
end
|
|
2093
|
+
access_value = access_value.to_s.downcase
|
|
2094
|
+
if !allowed_access_values.include?(access_value)
|
|
2095
|
+
raise_command_error("invalid access value: #{access_value}", args, optparse)
|
|
2096
|
+
puts optparse
|
|
2097
|
+
return 1
|
|
2098
|
+
end
|
|
2099
|
+
|
|
2100
|
+
connect(options)
|
|
2101
|
+
begin
|
|
2102
|
+
account = find_account_from_options(options)
|
|
2103
|
+
account_id = account ? account['id'] : nil
|
|
2104
|
+
role = find_role_by_name_or_id(account_id, name)
|
|
2105
|
+
return 1 if role.nil?
|
|
2106
|
+
|
|
2107
|
+
role_json = @roles_interface.get(account_id, role['id'], {'includeDefaultAccess' => true})
|
|
2108
|
+
vdi_pool_global_access = role_json['globalVdiPoolAccess']
|
|
2109
|
+
vdi_pool_permissions = role_json['vdiPoolPermissions'] || role_json['vdiPools'] || []
|
|
2110
|
+
|
|
2111
|
+
# hacky, but support name or code lookup via the list returned in the show payload
|
|
2112
|
+
vdi_pool = nil
|
|
2113
|
+
if !do_all
|
|
2114
|
+
if vdi_pool_id.to_s =~ /\A\d{1,}\Z/
|
|
2115
|
+
vdi_pool = vdi_pool_permissions.find {|b| b['id'] == vdi_pool_id.to_i }
|
|
2116
|
+
else
|
|
2117
|
+
vdi_pool = vdi_pool_permissions.find {|b| b['name'] == vdi_pool_id }
|
|
2118
|
+
end
|
|
2119
|
+
if vdi_pool.nil?
|
|
2120
|
+
print_red_alert "VDI Pool not found: '#{vdi_pool_id}'"
|
|
2121
|
+
return 1
|
|
2122
|
+
end
|
|
2123
|
+
end
|
|
2124
|
+
|
|
2125
|
+
params = {}
|
|
2126
|
+
if do_all
|
|
2127
|
+
params['allVdiPools'] = true
|
|
2128
|
+
else
|
|
2129
|
+
params['vdiPoolId'] = vdi_pool['id']
|
|
2130
|
+
end
|
|
2131
|
+
params['access'] = access_value
|
|
2132
|
+
@roles_interface.setopts(options)
|
|
2133
|
+
if options[:dry_run]
|
|
2134
|
+
print_dry_run @roles_interface.dry.update_vdi_pool(account_id, role['id'], params)
|
|
2135
|
+
return
|
|
2136
|
+
end
|
|
2137
|
+
json_response = @roles_interface.update_vdi_pool(account_id, role['id'], params)
|
|
2138
|
+
|
|
2139
|
+
if options[:json]
|
|
2140
|
+
print JSON.pretty_generate(json_response)
|
|
2141
|
+
print "\n"
|
|
2142
|
+
else
|
|
2143
|
+
if do_all
|
|
2144
|
+
print_green_success "Role #{role['authority']} access updated for all VDI pools"
|
|
2145
|
+
else
|
|
2146
|
+
print_green_success "Role #{role['authority']} access updated for VDI pool #{vdi_pool['name']}"
|
|
2147
|
+
end
|
|
2148
|
+
end
|
|
2149
|
+
return 0
|
|
2150
|
+
rescue RestClient::Exception => e
|
|
2151
|
+
print_rest_exception(e, options)
|
|
2152
|
+
exit 1
|
|
2153
|
+
end
|
|
2154
|
+
end
|
|
2155
|
+
|
|
2156
|
+
def update_global_report_type_access(args)
|
|
2157
|
+
puts "#{yellow}DEPRECATED#{reset}"
|
|
2158
|
+
update_default_report_type_access(args)
|
|
2159
|
+
end
|
|
2160
|
+
|
|
2161
|
+
def update_default_report_type_access(args)
|
|
2162
|
+
options = {}
|
|
2163
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
2164
|
+
opts.banner = subcommand_usage("[role] [access]")
|
|
2165
|
+
build_common_options(opts, options, [:json, :dry_run, :remote])
|
|
2166
|
+
opts.footer = <<-EOT
|
|
2167
|
+
Update default report type access for a role.
|
|
2168
|
+
[role] is required. This is the name (authority) or id of a role.
|
|
2169
|
+
[access] is required. This is the access level to assign: full or none.
|
|
2170
|
+
EOT
|
|
2171
|
+
end
|
|
2172
|
+
optparse.parse!(args)
|
|
2173
|
+
verify_args!(args:args, optparse:optparse, count: 2)
|
|
2174
|
+
name = args[0]
|
|
2175
|
+
access_value = args[1].to_s.downcase
|
|
2176
|
+
if !['full', 'none', 'custom'].include?(access_value)
|
|
2177
|
+
raise_command_error("invalid access value: #{args[1]}", args, optparse)
|
|
2178
|
+
end
|
|
2179
|
+
|
|
2180
|
+
connect(options)
|
|
2181
|
+
begin
|
|
2182
|
+
account = find_account_from_options(options)
|
|
2183
|
+
account_id = account ? account['id'] : nil
|
|
2184
|
+
role = find_role_by_name_or_id(account_id, name)
|
|
2185
|
+
exit 1 if role.nil?
|
|
2186
|
+
# note: ReportTypes being plural is odd, the others are singular
|
|
2187
|
+
params = {permissionCode: 'ReportTypes', access: access_value}
|
|
2188
|
+
@roles_interface.setopts(options)
|
|
2189
|
+
if options[:dry_run]
|
|
2190
|
+
print_dry_run @roles_interface.dry.update_permission(account_id, role['id'], params)
|
|
2191
|
+
return
|
|
2192
|
+
end
|
|
2193
|
+
json_response = @roles_interface.update_permission(account_id, role['id'], params)
|
|
2194
|
+
|
|
2195
|
+
if options[:json]
|
|
2196
|
+
print JSON.pretty_generate(json_response)
|
|
2197
|
+
print "\n"
|
|
2198
|
+
else
|
|
2199
|
+
print_green_success "Role #{role['authority']} default report type access updated"
|
|
2200
|
+
end
|
|
2201
|
+
rescue RestClient::Exception => e
|
|
2202
|
+
print_rest_exception(e, options)
|
|
2203
|
+
exit 1
|
|
2204
|
+
end
|
|
2205
|
+
end
|
|
2206
|
+
|
|
2207
|
+
def update_report_type_access(args)
|
|
2208
|
+
options = {}
|
|
2209
|
+
report_type_id = nil
|
|
2210
|
+
access_value = nil
|
|
2211
|
+
do_all = false
|
|
2212
|
+
allowed_access_values = ['full', 'none', 'default']
|
|
2213
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
2214
|
+
opts.banner = subcommand_usage("[role] [report-type] [access]")
|
|
2215
|
+
opts.on( '--report-type ID', String, "Report Type ID or Name" ) do |val|
|
|
2216
|
+
report_type_id = val
|
|
2217
|
+
end
|
|
2218
|
+
opts.on( nil, '--all', "Update all report types at once." ) do
|
|
2219
|
+
do_all = true
|
|
2220
|
+
end
|
|
2221
|
+
opts.on( '--access VALUE', String, "Access value [#{allowed_access_values.join('|')}]" ) do |val|
|
|
2222
|
+
access_value = val
|
|
2223
|
+
end
|
|
2224
|
+
build_common_options(opts, options, [:json, :dry_run, :remote])
|
|
2225
|
+
opts.footer = "Update role access for a report type or all report types.\n" +
|
|
2226
|
+
"[role] is required. This is the name or id of a role.\n" +
|
|
2227
|
+
"--report-type or --all is required. This is the name or id of a report type.\n" +
|
|
2228
|
+
"--access is required. This is the new access value: #{ored_list(allowed_access_values)}"
|
|
2229
|
+
end
|
|
2230
|
+
optparse.parse!(args)
|
|
2231
|
+
|
|
2232
|
+
# usage: update-report-type-access [role] [access] --all
|
|
2233
|
+
# update-report-type-access [role] [report-type] [access]
|
|
2234
|
+
name = args[0]
|
|
2235
|
+
if do_all
|
|
2236
|
+
verify_args!(args:args, optparse:optparse, min:1, max:2)
|
|
2237
|
+
access_value = args[1] if args[1]
|
|
2238
|
+
else
|
|
2239
|
+
verify_args!(args:args, optparse:optparse, min:1, max:3)
|
|
2240
|
+
report_type_id = args[1] if args[1]
|
|
2241
|
+
access_value = args[2] if args[2]
|
|
2242
|
+
end
|
|
2243
|
+
if !report_type_id && !do_all
|
|
2244
|
+
raise_command_error("missing required argument: [report-type] or --all", args, optparse)
|
|
2245
|
+
end
|
|
2246
|
+
if !access_value
|
|
2247
|
+
raise_command_error("missing required argument: [access]", args, optparse)
|
|
2248
|
+
end
|
|
2249
|
+
access_value = access_value.to_s.downcase
|
|
2250
|
+
if !allowed_access_values.include?(access_value)
|
|
2251
|
+
raise_command_error("invalid access value: #{access_value}", args, optparse)
|
|
2252
|
+
puts optparse
|
|
2253
|
+
return 1
|
|
2254
|
+
end
|
|
2255
|
+
|
|
2256
|
+
connect(options)
|
|
2257
|
+
begin
|
|
2258
|
+
account = find_account_from_options(options)
|
|
2259
|
+
account_id = account ? account['id'] : nil
|
|
2260
|
+
role = find_role_by_name_or_id(account_id, name)
|
|
2261
|
+
return 1 if role.nil?
|
|
2262
|
+
|
|
2263
|
+
role_json = @roles_interface.get(account_id, role['id'], {'includeDefaultAccess' => true})
|
|
2264
|
+
report_type_global_access = role_json['globalReportTypeAccess']
|
|
2265
|
+
report_type_permissions = role_json['reportTypePermissions'] || role_json['reportTypes'] || []
|
|
2266
|
+
|
|
2267
|
+
# hacky, but support name or code lookup via the list returned in the show payload
|
|
2268
|
+
report_type = nil
|
|
2269
|
+
if !do_all
|
|
2270
|
+
if report_type_id.to_s =~ /\A\d{1,}\Z/
|
|
2271
|
+
report_type = report_type_permissions.find {|b| b['id'] == report_type_id.to_i }
|
|
2272
|
+
else
|
|
2273
|
+
report_type = report_type_permissions.find {|b| b['name'] == report_type_id }
|
|
2274
|
+
end
|
|
2275
|
+
if report_type.nil?
|
|
2276
|
+
print_red_alert "Report Type not found: '#{report_type_id}'"
|
|
2277
|
+
return 1
|
|
2278
|
+
end
|
|
2279
|
+
end
|
|
2280
|
+
|
|
2281
|
+
params = {}
|
|
2282
|
+
if do_all
|
|
2283
|
+
params['allReportTypes'] = true
|
|
2284
|
+
else
|
|
2285
|
+
params['reportTypeId'] = report_type['id']
|
|
2286
|
+
end
|
|
2287
|
+
params['access'] = access_value
|
|
2288
|
+
@roles_interface.setopts(options)
|
|
2289
|
+
if options[:dry_run]
|
|
2290
|
+
print_dry_run @roles_interface.dry.update_report_type(account_id, role['id'], params)
|
|
2291
|
+
return
|
|
2292
|
+
end
|
|
2293
|
+
json_response = @roles_interface.update_report_type(account_id, role['id'], params)
|
|
2294
|
+
|
|
2295
|
+
if options[:json]
|
|
2296
|
+
print JSON.pretty_generate(json_response)
|
|
2297
|
+
print "\n"
|
|
2298
|
+
else
|
|
2299
|
+
if do_all
|
|
2300
|
+
print_green_success "Role #{role['authority']} access updated for all report types"
|
|
2301
|
+
else
|
|
2302
|
+
print_green_success "Role #{role['authority']} access updated for report type #{report_type['name']}"
|
|
2303
|
+
end
|
|
2304
|
+
end
|
|
2305
|
+
return 0
|
|
2306
|
+
rescue RestClient::Exception => e
|
|
2307
|
+
print_rest_exception(e, options)
|
|
2308
|
+
exit 1
|
|
2309
|
+
end
|
|
2310
|
+
end
|
|
2311
|
+
|
|
2312
|
+
def update_global_task_access(args)
|
|
2313
|
+
puts "#{yellow}DEPRECATED#{reset}"
|
|
2314
|
+
update_default_task_access(args)
|
|
2315
|
+
end
|
|
2316
|
+
|
|
2317
|
+
def update_default_task_access(args)
|
|
2318
|
+
options = {}
|
|
2319
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
2320
|
+
opts.banner = subcommand_usage("[role] [access]")
|
|
2321
|
+
build_common_options(opts, options, [:json, :dry_run, :remote])
|
|
2322
|
+
opts.footer = <<-EOT
|
|
2323
|
+
Update default task access for a role.
|
|
2324
|
+
[role] is required. This is the id of a role.
|
|
2325
|
+
[access] is required. This is the access level to assign: full or none.
|
|
2326
|
+
EOT
|
|
2327
|
+
end
|
|
2328
|
+
optparse.parse!(args)
|
|
2329
|
+
verify_args!(args:args, optparse:optparse, count: 2)
|
|
2330
|
+
name = args[0]
|
|
2331
|
+
access_value = args[1].to_s.downcase
|
|
2332
|
+
if !['full', 'none', 'custom'].include?(access_value)
|
|
2333
|
+
raise_command_error("invalid access value: #{args[1]}", args, optparse)
|
|
2334
|
+
end
|
|
2335
|
+
|
|
2336
|
+
connect(options)
|
|
2337
|
+
begin
|
|
2338
|
+
account = find_account_from_options(options)
|
|
2339
|
+
account_id = account ? account['id'] : nil
|
|
2340
|
+
role = find_role_by_name_or_id(account_id, name)
|
|
2341
|
+
exit 1 if role.nil?
|
|
2342
|
+
# note: ReportTypes being plural is odd, the others are singular
|
|
2343
|
+
params = {permissionCode: 'Task', access: access_value}
|
|
2344
|
+
@roles_interface.setopts(options)
|
|
2345
|
+
if options[:dry_run]
|
|
2346
|
+
print_dry_run @roles_interface.dry.update_permission(account_id, role['id'], params)
|
|
2347
|
+
return
|
|
2348
|
+
end
|
|
2349
|
+
json_response = @roles_interface.update_permission(account_id, role['id'], params)
|
|
2350
|
+
|
|
2351
|
+
if options[:json]
|
|
2352
|
+
print JSON.pretty_generate(json_response)
|
|
2353
|
+
print "\n"
|
|
2354
|
+
else
|
|
2355
|
+
print_green_success "Role #{role['authority']} default task access updated"
|
|
2356
|
+
end
|
|
2357
|
+
rescue RestClient::Exception => e
|
|
2358
|
+
print_rest_exception(e, options)
|
|
2359
|
+
exit 1
|
|
2360
|
+
end
|
|
2361
|
+
end
|
|
2362
|
+
|
|
2363
|
+
def update_task_access(args)
|
|
2364
|
+
options = {}
|
|
2365
|
+
task_id = nil
|
|
2366
|
+
access_value = nil
|
|
2367
|
+
do_all = false
|
|
2368
|
+
allowed_access_values = ['full', 'none', 'default']
|
|
2369
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
2370
|
+
opts.banner = subcommand_usage("[role] [task] [access]")
|
|
2371
|
+
opts.on( '--task ID', String, "Task ID, code or name" ) do |val|
|
|
2372
|
+
report_type_id = val
|
|
2373
|
+
end
|
|
2374
|
+
opts.on( nil, '--all', "Update all tasks at once." ) do
|
|
2375
|
+
do_all = true
|
|
2376
|
+
end
|
|
2377
|
+
opts.on( '--access VALUE', String, "Access value [#{allowed_access_values.join('|')}]" ) do |val|
|
|
2378
|
+
access_value = val
|
|
2379
|
+
end
|
|
2380
|
+
build_common_options(opts, options, [:json, :dry_run, :remote])
|
|
2381
|
+
opts.footer = "Update role access for a task or all tasks.\n" +
|
|
2382
|
+
"[role] is required. This is the name, code or id of a task.\n" +
|
|
2383
|
+
"--task or --all is required. This is the name, code or id of a task.\n" +
|
|
2384
|
+
"--access is required. This is the new access value: #{ored_list(allowed_access_values)}"
|
|
2385
|
+
end
|
|
2386
|
+
optparse.parse!(args)
|
|
2387
|
+
|
|
2388
|
+
name = args[0]
|
|
2389
|
+
if do_all
|
|
2390
|
+
verify_args!(args:args, optparse:optparse, min:1, max:2)
|
|
2391
|
+
access_value = args[1] if args[1]
|
|
2392
|
+
else
|
|
2393
|
+
verify_args!(args:args, optparse:optparse, min:1, max:3)
|
|
2394
|
+
task_id = args[1] if args[1]
|
|
2395
|
+
access_value = args[2] if args[2]
|
|
2396
|
+
end
|
|
2397
|
+
if !task_id && !do_all
|
|
2398
|
+
raise_command_error("missing required argument: [task] or --all", args, optparse)
|
|
2399
|
+
end
|
|
2400
|
+
if !access_value
|
|
2401
|
+
raise_command_error("missing required argument: [access]", args, optparse)
|
|
2402
|
+
end
|
|
2403
|
+
access_value = access_value.to_s.downcase
|
|
2404
|
+
if !allowed_access_values.include?(access_value)
|
|
2405
|
+
raise_command_error("invalid access value: #{access_value}", args, optparse)
|
|
2406
|
+
puts optparse
|
|
2407
|
+
return 1
|
|
2408
|
+
end
|
|
2409
|
+
|
|
2410
|
+
connect(options)
|
|
2411
|
+
begin
|
|
2412
|
+
account = find_account_from_options(options)
|
|
2413
|
+
account_id = account ? account['id'] : nil
|
|
2414
|
+
role = find_role_by_name_or_id(account_id, name)
|
|
2415
|
+
return 1 if role.nil?
|
|
2416
|
+
|
|
2417
|
+
role_json = @roles_interface.get(account_id, role['id'], {'includeDefaultAccess' => true})
|
|
2418
|
+
task_permissions = role_json['taskPermissions'] || role_json['tasks'] || []
|
|
2419
|
+
|
|
2420
|
+
# hacky, but support name or code lookup via the list returned in the show payload
|
|
2421
|
+
task = nil
|
|
2422
|
+
if !do_all
|
|
2423
|
+
if task_id.to_s =~ /\A\d{1,}\Z/
|
|
2424
|
+
task = task_permissions.find {|b| b['id'] == task_id.to_i }
|
|
2425
|
+
else
|
|
2426
|
+
task = task_permissions.find {|b| b['name'] == task_id || b['code'] == task_id }
|
|
2427
|
+
end
|
|
2428
|
+
if task.nil?
|
|
2429
|
+
print_red_alert "Task not found: '#{task_id}'"
|
|
2430
|
+
return 1
|
|
2431
|
+
end
|
|
2432
|
+
end
|
|
2433
|
+
|
|
2434
|
+
params = {}
|
|
2435
|
+
if do_all
|
|
2436
|
+
params['allTasks'] = true
|
|
2437
|
+
else
|
|
2438
|
+
params['taskId'] = task['id']
|
|
2439
|
+
end
|
|
2440
|
+
params['access'] = access_value == 'default' ? nil : access_value
|
|
2441
|
+
@roles_interface.setopts(options)
|
|
2442
|
+
if options[:dry_run]
|
|
2443
|
+
print_dry_run @roles_interface.dry.update_task(account_id, role['id'], params)
|
|
2444
|
+
return
|
|
2445
|
+
end
|
|
2446
|
+
json_response = @roles_interface.update_task(account_id, role['id'], params)
|
|
2447
|
+
|
|
2448
|
+
if options[:json]
|
|
2449
|
+
print JSON.pretty_generate(json_response)
|
|
2450
|
+
print "\n"
|
|
2451
|
+
else
|
|
2452
|
+
if do_all
|
|
2453
|
+
print_green_success "Role #{role['authority']} access updated for all tasks"
|
|
2454
|
+
else
|
|
2455
|
+
print_green_success "Role #{role['authority']} access updated for task #{task['name']}"
|
|
2456
|
+
end
|
|
2457
|
+
end
|
|
2458
|
+
return 0
|
|
2459
|
+
rescue RestClient::Exception => e
|
|
2460
|
+
print_rest_exception(e, options)
|
|
2461
|
+
exit 1
|
|
2462
|
+
end
|
|
2463
|
+
end
|
|
2464
|
+
|
|
2465
|
+
def update_global_workflow_access(args)
|
|
2466
|
+
puts "#{yellow}DEPRECATED#{reset}"
|
|
2467
|
+
update_default_workflow_access(args)
|
|
2468
|
+
end
|
|
2469
|
+
|
|
2470
|
+
def update_default_workflow_access(args)
|
|
2471
|
+
options = {}
|
|
2472
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
2473
|
+
opts.banner = subcommand_usage("[role] [access]")
|
|
2474
|
+
build_common_options(opts, options, [:json, :dry_run, :remote])
|
|
2475
|
+
opts.footer = <<-EOT
|
|
2476
|
+
Update default workflow access for a role.
|
|
2477
|
+
[role] is required. This is the id of a role.
|
|
2478
|
+
[access] is required. This is the access level to assign: full or none.
|
|
2479
|
+
EOT
|
|
2480
|
+
end
|
|
2481
|
+
optparse.parse!(args)
|
|
2482
|
+
verify_args!(args:args, optparse:optparse, count: 2)
|
|
2483
|
+
name = args[0]
|
|
2484
|
+
access_value = args[1].to_s.downcase
|
|
2485
|
+
if !['full', 'none', 'custom'].include?(access_value)
|
|
2486
|
+
raise_command_error("invalid access value: #{args[1]}", args, optparse)
|
|
2487
|
+
end
|
|
2488
|
+
|
|
2489
|
+
connect(options)
|
|
2490
|
+
begin
|
|
2491
|
+
account = find_account_from_options(options)
|
|
2492
|
+
account_id = account ? account['id'] : nil
|
|
2493
|
+
role = find_role_by_name_or_id(account_id, name)
|
|
2494
|
+
exit 1 if role.nil?
|
|
2495
|
+
params = {permissionCode: 'TaskSet', access: access_value}
|
|
2496
|
+
@roles_interface.setopts(options)
|
|
2497
|
+
if options[:dry_run]
|
|
2498
|
+
print_dry_run @roles_interface.dry.update_permission(account_id, role['id'], params)
|
|
2499
|
+
return
|
|
2500
|
+
end
|
|
2501
|
+
json_response = @roles_interface.update_permission(account_id, role['id'], params)
|
|
2502
|
+
|
|
2503
|
+
if options[:json]
|
|
2504
|
+
print JSON.pretty_generate(json_response)
|
|
2505
|
+
print "\n"
|
|
2506
|
+
else
|
|
2507
|
+
print_green_success "Role #{role['authority']} default workflow access updated"
|
|
2508
|
+
end
|
|
2509
|
+
rescue RestClient::Exception => e
|
|
2510
|
+
print_rest_exception(e, options)
|
|
2511
|
+
exit 1
|
|
2512
|
+
end
|
|
2513
|
+
end
|
|
2514
|
+
|
|
2515
|
+
def update_workflow_access(args)
|
|
2516
|
+
options = {}
|
|
2517
|
+
workflow_id = nil
|
|
2518
|
+
access_value = nil
|
|
2519
|
+
do_all = false
|
|
2520
|
+
allowed_access_values = ['full', 'none', 'default']
|
|
2521
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
2522
|
+
opts.banner = subcommand_usage("[role] [workflow] [access]")
|
|
2523
|
+
opts.on( '--workflow ID', String, "Workflow ID, code or Name" ) do |val|
|
|
2524
|
+
workflow_id = val
|
|
2525
|
+
end
|
|
2526
|
+
opts.on( nil, '--all', "Update all workflows at once." ) do
|
|
2527
|
+
do_all = true
|
|
2528
|
+
end
|
|
2529
|
+
opts.on( '--access VALUE', String, "Access value [#{allowed_access_values.join('|')}]" ) do |val|
|
|
2530
|
+
access_value = val
|
|
2531
|
+
end
|
|
2532
|
+
build_common_options(opts, options, [:json, :dry_run, :remote])
|
|
2533
|
+
opts.footer = "Update role access for a workflow or all workflows.\n" +
|
|
2534
|
+
"[role] is required. This is the name or id of a role.\n" +
|
|
2535
|
+
"--workflow or --all is required. This is the name, code or id of a workflow.\n" +
|
|
2536
|
+
"--access is required. This is the new access value: #{ored_list(allowed_access_values)}"
|
|
2537
|
+
end
|
|
2538
|
+
optparse.parse!(args)
|
|
2539
|
+
|
|
2540
|
+
name = args[0]
|
|
2541
|
+
if do_all
|
|
2542
|
+
verify_args!(args:args, optparse:optparse, min:1, max:2)
|
|
2543
|
+
access_value = args[1] if args[1]
|
|
2544
|
+
else
|
|
2545
|
+
verify_args!(args:args, optparse:optparse, min:1, max:3)
|
|
2546
|
+
workflow_id = args[1] if args[1]
|
|
2547
|
+
access_value = args[2] if args[2]
|
|
2548
|
+
end
|
|
2549
|
+
if !workflow_id && !do_all
|
|
2550
|
+
raise_command_error("missing required argument: [workflow] or --all", args, optparse)
|
|
2551
|
+
end
|
|
2552
|
+
if !access_value
|
|
2553
|
+
raise_command_error("missing required argument: [access]", args, optparse)
|
|
2554
|
+
end
|
|
2555
|
+
access_value = access_value.to_s.downcase
|
|
2556
|
+
if !allowed_access_values.include?(access_value)
|
|
2557
|
+
raise_command_error("invalid access value: #{access_value}", args, optparse)
|
|
2558
|
+
puts optparse
|
|
2559
|
+
return 1
|
|
2560
|
+
end
|
|
2561
|
+
|
|
2562
|
+
connect(options)
|
|
2563
|
+
begin
|
|
2564
|
+
account = find_account_from_options(options)
|
|
2565
|
+
account_id = account ? account['id'] : nil
|
|
2566
|
+
role = find_role_by_name_or_id(account_id, name)
|
|
2567
|
+
return 1 if role.nil?
|
|
2568
|
+
|
|
2569
|
+
role_json = @roles_interface.get(account_id, role['id'], {'includeDefaultAccess' => true})
|
|
2570
|
+
workflow_permissions = role_json['taskSetPermissions'] || role_json['taskSets'] || []
|
|
2571
|
+
|
|
2572
|
+
# hacky, but support name or code lookup via the list returned in the show payload
|
|
2573
|
+
workflow = nil
|
|
2574
|
+
if !do_all
|
|
2575
|
+
if workflow_id.to_s =~ /\A\d{1,}\Z/
|
|
2576
|
+
workflow = workflow_permissions.find {|b| b['id'] == workflow_id.to_i }
|
|
2577
|
+
else
|
|
2578
|
+
workflow = workflow_permissions.find {|b| b['name'] == workflow_id }
|
|
2579
|
+
end
|
|
2580
|
+
if workflow.nil?
|
|
2581
|
+
print_red_alert "Workflow not found: '#{workflow_id}'"
|
|
2582
|
+
return 1
|
|
2583
|
+
end
|
|
2584
|
+
end
|
|
2585
|
+
|
|
2586
|
+
params = {}
|
|
2587
|
+
if do_all
|
|
2588
|
+
params['allTaskSets'] = true
|
|
2589
|
+
else
|
|
2590
|
+
params['taskSetId'] = workflow['id']
|
|
2591
|
+
end
|
|
2592
|
+
params['access'] = access_value == 'default' ? nil : access_value
|
|
2593
|
+
@roles_interface.setopts(options)
|
|
2594
|
+
if options[:dry_run]
|
|
2595
|
+
print_dry_run @roles_interface.dry.update_task_set(account_id, role['id'], params)
|
|
2596
|
+
return
|
|
2597
|
+
end
|
|
2598
|
+
json_response = @roles_interface.update_task_set(account_id, role['id'], params)
|
|
2599
|
+
|
|
2600
|
+
if options[:json]
|
|
2601
|
+
print JSON.pretty_generate(json_response)
|
|
2602
|
+
print "\n"
|
|
2603
|
+
else
|
|
2604
|
+
if do_all
|
|
2605
|
+
print_green_success "Role #{role['authority']} access updated for all workflows"
|
|
2606
|
+
else
|
|
2607
|
+
print_green_success "Role #{role['authority']} access updated for workflow #{workflow['name']}"
|
|
2608
|
+
end
|
|
2609
|
+
end
|
|
2610
|
+
return 0
|
|
2611
|
+
rescue RestClient::Exception => e
|
|
2612
|
+
print_rest_exception(e, options)
|
|
2613
|
+
exit 1
|
|
2614
|
+
end
|
|
2615
|
+
end
|
|
2616
|
+
|
|
2617
|
+
def update_default_cluster_type_access(args)
|
|
2618
|
+
options = {}
|
|
2619
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
2620
|
+
opts.banner = subcommand_usage("[role] [access]")
|
|
2621
|
+
build_common_options(opts, options, [:json, :dry_run, :remote])
|
|
2622
|
+
opts.footer = <<-EOT
|
|
2623
|
+
Update default cluster type access for a role.
|
|
2624
|
+
[role] is required. This is the id of a role.
|
|
2625
|
+
[access] is required. This is the access level to assign: full or none.
|
|
2626
|
+
EOT
|
|
2627
|
+
end
|
|
2628
|
+
optparse.parse!(args)
|
|
2629
|
+
verify_args!(args:args, optparse:optparse, count: 2)
|
|
2630
|
+
name = args[0]
|
|
2631
|
+
access_value = args[1].to_s.downcase
|
|
2632
|
+
if !['full', 'none', 'custom'].include?(access_value)
|
|
2633
|
+
raise_command_error("invalid access value: #{args[1]}", args, optparse)
|
|
2634
|
+
end
|
|
2635
|
+
|
|
2636
|
+
connect(options)
|
|
2637
|
+
begin
|
|
2638
|
+
account = find_account_from_options(options)
|
|
2639
|
+
account_id = account ? account['id'] : nil
|
|
2640
|
+
role = find_role_by_name_or_id(account_id, name)
|
|
2641
|
+
exit 1 if role.nil?
|
|
2642
|
+
params = {permissionCode: 'ServerGroupType', access: access_value}
|
|
2643
|
+
@roles_interface.setopts(options)
|
|
2644
|
+
if options[:dry_run]
|
|
2645
|
+
print_dry_run @roles_interface.dry.update_permission(account_id, role['id'], params)
|
|
2646
|
+
return
|
|
2647
|
+
end
|
|
2648
|
+
json_response = @roles_interface.update_permission(account_id, role['id'], params)
|
|
2649
|
+
|
|
2650
|
+
if options[:json]
|
|
2651
|
+
print JSON.pretty_generate(json_response)
|
|
2652
|
+
print "\n"
|
|
2653
|
+
else
|
|
2654
|
+
print_green_success "Role #{role['authority']} default cluster type access updated"
|
|
2655
|
+
end
|
|
2656
|
+
rescue RestClient::Exception => e
|
|
2657
|
+
print_rest_exception(e, options)
|
|
2658
|
+
exit 1
|
|
2659
|
+
end
|
|
2660
|
+
end
|
|
2661
|
+
|
|
2662
|
+
def update_cluster_type_access(args)
|
|
2663
|
+
options = {}
|
|
2664
|
+
cluster_type_id = nil
|
|
2665
|
+
access_value = nil
|
|
2666
|
+
do_all = false
|
|
2667
|
+
allowed_access_values = ['full', 'none', 'default']
|
|
2668
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
2669
|
+
opts.banner = subcommand_usage("[role] [cluster-type] [access]")
|
|
2670
|
+
opts.on( '--cluster-type ID', String, "Cluster Type ID, code or Name" ) do |val|
|
|
2671
|
+
cluster_type_id = val
|
|
2672
|
+
end
|
|
2673
|
+
opts.on( nil, '--all', "Update all cluster types at once." ) do
|
|
2674
|
+
do_all = true
|
|
2675
|
+
end
|
|
2676
|
+
opts.on( '--access VALUE', String, "Access value [#{allowed_access_values.join('|')}]" ) do |val|
|
|
2677
|
+
access_value = val
|
|
2678
|
+
end
|
|
2679
|
+
build_common_options(opts, options, [:json, :dry_run, :remote])
|
|
2680
|
+
opts.footer = "Update role access for a cluster type or all cluster types.\n" +
|
|
2681
|
+
"[role] is required. This is the name or id of a role.\n" +
|
|
2682
|
+
"--cluster-type or --all is required. This is the name, code or id of a cluster type.\n" +
|
|
2683
|
+
"--access is required. This is the new access value: #{ored_list(allowed_access_values)}"
|
|
2684
|
+
end
|
|
2685
|
+
optparse.parse!(args)
|
|
2686
|
+
|
|
2687
|
+
name = args[0]
|
|
2688
|
+
if do_all
|
|
2689
|
+
verify_args!(args:args, optparse:optparse, min:1, max:2)
|
|
2690
|
+
access_value = args[1] if args[1]
|
|
2691
|
+
else
|
|
2692
|
+
verify_args!(args:args, optparse:optparse, min:1, max:3)
|
|
2693
|
+
cluster_type_id = args[1] if args[1]
|
|
2694
|
+
access_value = args[2] if args[2]
|
|
2695
|
+
end
|
|
2696
|
+
if !cluster_type_id && !do_all
|
|
2697
|
+
raise_command_error("missing required argument: [cluster-type] or --all", args, optparse)
|
|
2698
|
+
end
|
|
2699
|
+
if !access_value
|
|
2700
|
+
raise_command_error("missing required argument: [access]", args, optparse)
|
|
2701
|
+
end
|
|
2702
|
+
access_value = access_value.to_s.downcase
|
|
2703
|
+
if !allowed_access_values.include?(access_value)
|
|
2704
|
+
raise_command_error("invalid access value: #{access_value}", args, optparse)
|
|
2705
|
+
puts optparse
|
|
2706
|
+
return 1
|
|
2707
|
+
end
|
|
2708
|
+
|
|
2709
|
+
connect(options)
|
|
2710
|
+
begin
|
|
2711
|
+
account = find_account_from_options(options)
|
|
2712
|
+
account_id = account ? account['id'] : nil
|
|
2713
|
+
role = find_role_by_name_or_id(account_id, name)
|
|
2714
|
+
return 1 if role.nil?
|
|
2715
|
+
|
|
2716
|
+
role_json = @roles_interface.get(account_id, role['id'], {'includeDefaultAccess' => true})
|
|
2717
|
+
cluster_type_permissions = role_json['clusterTypePermissions'] || role_json['clusterTypes'] || []
|
|
2718
|
+
|
|
2719
|
+
# hacky, but support name or code lookup via the list returned in the show payload
|
|
2720
|
+
cluster_type = nil
|
|
2721
|
+
if !do_all
|
|
2722
|
+
if cluster_type_id.to_s =~ /\A\d{1,}\Z/
|
|
2723
|
+
cluster_type = cluster_type_permissions.find {|b| b['id'] == cluster_type_id.to_i }
|
|
2724
|
+
else
|
|
2725
|
+
cluster_type = cluster_type_permissions.find {|b| b['name'] == cluster_type_id }
|
|
2726
|
+
end
|
|
2727
|
+
if cluster_type.nil?
|
|
2728
|
+
print_red_alert "Cluster Type not found: '#{cluster_type_id}'"
|
|
2729
|
+
return 1
|
|
2730
|
+
end
|
|
2731
|
+
end
|
|
2732
|
+
|
|
2733
|
+
params = {}
|
|
2734
|
+
if do_all
|
|
2735
|
+
params['allClusterTypes'] = true
|
|
2736
|
+
else
|
|
2737
|
+
params['clusterTypeId'] = cluster_type['id']
|
|
2738
|
+
end
|
|
2739
|
+
params['access'] = access_value == 'default' ? nil : access_value
|
|
2740
|
+
@roles_interface.setopts(options)
|
|
2741
|
+
if options[:dry_run]
|
|
2742
|
+
print_dry_run @roles_interface.dry.update_cluster_type(account_id, role['id'], params)
|
|
2743
|
+
return
|
|
2744
|
+
end
|
|
2745
|
+
json_response = @roles_interface.update_cluster_type(account_id, role['id'], params)
|
|
2746
|
+
|
|
2747
|
+
if options[:json]
|
|
2748
|
+
print JSON.pretty_generate(json_response)
|
|
2749
|
+
print "\n"
|
|
2750
|
+
else
|
|
2751
|
+
if do_all
|
|
2752
|
+
print_green_success "Role #{role['authority']} access updated for all cluster types"
|
|
2753
|
+
else
|
|
2754
|
+
print_green_success "Role #{role['authority']} access updated for cluster type #{cluster_type['name']}"
|
|
2755
|
+
end
|
|
2756
|
+
end
|
|
2757
|
+
return 0
|
|
2758
|
+
rescue RestClient::Exception => e
|
|
2759
|
+
print_rest_exception(e, options)
|
|
2760
|
+
exit 1
|
|
2761
|
+
end
|
|
2762
|
+
end
|
|
2763
|
+
|
|
2764
|
+
private
|
|
2765
|
+
|
|
2766
|
+
def add_role_option_types
|
|
2767
|
+
[
|
|
2768
|
+
{'fieldName' => 'authority', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true},
|
|
2769
|
+
{'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text'},
|
|
2770
|
+
{'fieldName' => 'landingUrl', 'fieldLabel' => 'Landing URL', 'type' => 'text', 'description' => 'An optional override for the default landing page after login for a user.'},
|
|
2771
|
+
{'fieldName' => 'roleType', 'fieldLabel' => 'Role Type', 'type' => 'select', 'selectOptions' => [{'name' => 'User Role', 'value' => 'user'}, {'name' => 'Account Role', 'value' => 'account'}], 'defaultValue' => 'user'},
|
|
2772
|
+
{'fieldName' => 'baseRole', 'fieldLabel' => 'Copy From Role', 'type' => 'text'},
|
|
2773
|
+
{'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'},
|
|
2774
|
+
{'fieldName' => 'multitenantLocked', 'fieldLabel' => 'Multitenant Locked', 'type' => 'checkbox', 'defaultValue' => 'off', 'description' => 'Prevents subtenants from branching off this role/modifying it.'},
|
|
2775
|
+
{'fieldName' => 'defaultPersona', 'fieldLabel' => 'Default Persona', 'type' => 'select', 'selectOptions' => get_persona_select_options(), 'description' => 'Default Persona'}
|
|
2776
|
+
]
|
|
2777
|
+
end
|
|
2778
|
+
|
|
2779
|
+
def update_role_option_types
|
|
2780
|
+
add_role_option_types.reject {|it| ['roleType', 'baseRole'].include?(it['fieldName']) }
|
|
2781
|
+
end
|
|
2782
|
+
|
|
2783
|
+
def role_type_options
|
|
2784
|
+
[{'name' => 'User Role', 'value' => 'user'}, {'name' => 'Account Role', 'value' => 'account'}]
|
|
2785
|
+
end
|
|
2786
|
+
|
|
2787
|
+
def get_persona_select_options
|
|
2788
|
+
[
|
|
2789
|
+
{'name'=>'Service Catalog','value'=>'serviceCatalog'},
|
|
2790
|
+
{'name'=>'Standard','value'=>'standard'},
|
|
2791
|
+
{'name'=>'Virtual Desktop','value'=>'vdi'}
|
|
2792
|
+
]
|
|
2793
|
+
end
|
|
2794
|
+
|
|
2795
|
+
def role_owner_options
|
|
2796
|
+
@options_interface.options_for_source("tenants", {})['data']
|
|
2797
|
+
end
|
|
2798
|
+
|
|
2799
|
+
def base_role_options(role_payload)
|
|
2800
|
+
params = {"tenantId" => role_payload['owner'], "roleType" => role_payload['roleType'] }
|
|
2801
|
+
@options_interface.options_for_source("copyFromRole", params)['data']
|
|
2802
|
+
end
|
|
2803
|
+
|
|
2804
|
+
|
|
2805
|
+
def parse_access_csv(output, val)
|
|
2806
|
+
output ||= {}
|
|
2807
|
+
val.split(",").each do |value_pair|
|
|
2808
|
+
# split on '=' only because ':' is included in the permission name
|
|
2809
|
+
k,v = value_pair.include?("=") ? value_pair.strip.split("=") : [value_pair, ""]
|
|
2810
|
+
next if k.to_s.empty?
|
|
2811
|
+
k = k.to_s.strip
|
|
2812
|
+
v = v.to_s.strip
|
|
2813
|
+
if k.empty?
|
|
2814
|
+
# ignore blank values, extra comma maybe?
|
|
2815
|
+
next
|
|
2816
|
+
end
|
|
2817
|
+
if v == ""
|
|
2818
|
+
raise_command_error "permission '#{k}=#{v}' is invalid. The access value is required eg. [default|none|read|full]"
|
|
2819
|
+
end
|
|
2820
|
+
output[k] = v
|
|
2821
|
+
end
|
|
2822
|
+
return output
|
|
2823
|
+
end
|
|
2824
|
+
|
|
2825
|
+
# role permission access options shared by add and update
|
|
2826
|
+
def build_role_access_options(opts, options, params)
|
|
2827
|
+
opts.on('--permissions CODE=ACCESS', String, "Set feature permission access by permission code. Example: dashboard=read,operations-wiki=full" ) do |val|
|
|
2828
|
+
options[:permissions] ||= {}
|
|
2829
|
+
parse_access_csv(options[:permissions], val)
|
|
2830
|
+
end
|
|
2831
|
+
opts.add_hidden_option('--permissions')
|
|
2832
|
+
opts.on('--feature-access CODE=ACCESS', String, "Set feature permission access by permission code. Example: dashboard=read,operations-wiki=full" ) do |val|
|
|
2833
|
+
options[:permissions] ||= {}
|
|
2834
|
+
parse_access_csv(options[:permissions], val)
|
|
2835
|
+
end
|
|
2836
|
+
opts.on('--global-group-access ACCESS', String, "Update the global group (site) access: [none|read|full]" ) do |val|
|
|
2837
|
+
params['globalSiteAccess'] = val.to_s.downcase
|
|
2838
|
+
end
|
|
2839
|
+
opts.add_hidden_option('--global-group-access')
|
|
2840
|
+
opts.on('--default-group-access ACCESS', String, "Update the default group (site) access: [none|read|full]" ) do |val|
|
|
2841
|
+
params['globalSiteAccess'] = val.to_s.downcase
|
|
2842
|
+
end
|
|
2843
|
+
opts.on('--groups ID=ACCESS', String, "Set group (site) to a custom access by group id. Example: 1=none,2=full,3=read" ) do |val|
|
|
2844
|
+
options[:group_permissions] ||= {}
|
|
2845
|
+
parse_access_csv(options[:group_permissions], val)
|
|
2846
|
+
end
|
|
2847
|
+
opts.on('--global-cloud-access ACCESS', String, "Update the global cloud (zone) access: [none|read|full]" ) do |val|
|
|
2848
|
+
params['globalZoneAccess'] = val.to_s.downcase
|
|
2849
|
+
end
|
|
2850
|
+
opts.add_hidden_option('--global-cloud-access')
|
|
2851
|
+
opts.on('--default-cloud-access ACCESS', String, "Update the default cloud (zone) access: [none|read|full]" ) do |val|
|
|
2852
|
+
params['globalZoneAccess'] = val.to_s.downcase
|
|
2853
|
+
end
|
|
2854
|
+
opts.on('--clouds ID=ACCESS', String, "Set cloud (zone) to a custom access by cloud id. Example: 1=none,2=full,3=read" ) do |val|
|
|
2855
|
+
options[:cloud_permissions] ||= {}
|
|
2856
|
+
parse_access_csv(options[:cloud_permissions], val)
|
|
2857
|
+
end
|
|
2858
|
+
opts.on('--global-instance-type-access ACCESS', String, "Update the global instance type access: [none|full]" ) do |val|
|
|
2859
|
+
params['globalInstanceTypeAccess'] = val.to_s.downcase
|
|
2860
|
+
end
|
|
2861
|
+
opts.add_hidden_option('--global-instance-type-access')
|
|
2862
|
+
opts.on('--default-instance-type-access ACCESS', String, "Update the default instance type access: [none|full]" ) do |val|
|
|
2863
|
+
params['globalInstanceTypeAccess'] = val.to_s.downcase
|
|
2864
|
+
end
|
|
2865
|
+
opts.on('--instance-types CODE=ACCESS', String, "Set instance type to a custom access instance type code. Example: nginx=full,apache=none" ) do |val|
|
|
2866
|
+
options[:instance_type_permissions] ||= {}
|
|
2867
|
+
parse_access_csv(options[:instance_type_permissions], val)
|
|
2868
|
+
end
|
|
2869
|
+
opts.on('--global-blueprint-access ACCESS', String, "Update the global blueprint access: [none|full]" ) do |val|
|
|
2870
|
+
params['globalAppTemplateAccess'] = val.to_s.downcase
|
|
2871
|
+
end
|
|
2872
|
+
opts.add_hidden_option('--global-blueprint-access')
|
|
2873
|
+
opts.on('--default-blueprint-access ACCESS', String, "Update the default blueprint access: [none|full]" ) do |val|
|
|
2874
|
+
params['globalAppTemplateAccess'] = val.to_s.downcase
|
|
2875
|
+
end
|
|
2876
|
+
opts.on('--blueprints ID=ACCESS', String, "Set blueprint to a custom access by blueprint id. Example: 1=full,2=none" ) do |val|
|
|
2877
|
+
options[:blueprint_permissions] ||= {}
|
|
2878
|
+
parse_access_csv(options[:blueprint_permissions], val)
|
|
2879
|
+
end
|
|
2880
|
+
opts.on('--global-catalog-item-type-access ACCESS', String, "Update the global catalog item type access: [none|full]" ) do |val|
|
|
2881
|
+
params['globalCatalogItemTypeAccess'] = val.to_s.downcase
|
|
2882
|
+
end
|
|
2883
|
+
opts.add_hidden_option('--global-catalog-item-type-access')
|
|
2884
|
+
opts.on('--default-catalog-item-type-access ACCESS', String, "Update the default catalog item type access: [none|full]" ) do |val|
|
|
2885
|
+
params['globalCatalogItemTypeAccess'] = val.to_s.downcase
|
|
2886
|
+
end
|
|
2887
|
+
opts.on('--catalog-item-types CODE=ACCESS', String, "Set catalog item type to a custom access by catalog item type id. Example: 1=full,2=none" ) do |val|
|
|
2888
|
+
options[:catalog_item_type_permissions] ||= {}
|
|
2889
|
+
parse_access_csv(options[:catalog_item_type_permissions], val)
|
|
2890
|
+
end
|
|
2891
|
+
opts.on('--default-persona-access ACCESS', String, "Update the default persona access: [none|full]" ) do |val|
|
|
2892
|
+
params['globalPersonaAccess'] = val.to_s.downcase
|
|
2893
|
+
end
|
|
2894
|
+
opts.on('--personas CODE=ACCESS', String, "Set persona to a custom access by persona code. Example: standard=full,serviceCatalog=full,vdi=full" ) do |val|
|
|
2895
|
+
options[:persona_permissions] ||= {}
|
|
2896
|
+
parse_access_csv(options[:persona_permissions], val)
|
|
2897
|
+
end
|
|
2898
|
+
opts.on('--global-vdi-pool-access ACCESS', String, "Update the global VDI pool access: [none|full]" ) do |val|
|
|
2899
|
+
params['globalVdiPoolAccess'] = val.to_s.downcase
|
|
2900
|
+
end
|
|
2901
|
+
opts.add_hidden_option('--global-vdi-pool-access')
|
|
2902
|
+
opts.on('--default-vdi-pool-access ACCESS', String, "Update the default VDI pool access: [none|full]" ) do |val|
|
|
2903
|
+
params['globalVdiPoolAccess'] = val.to_s.downcase
|
|
2904
|
+
end
|
|
2905
|
+
opts.on('--vdi-pools ID=ACCESS', String, "Set VDI pool to a custom access by VDI pool id. Example: 1=full,2=none" ) do |val|
|
|
2906
|
+
options[:vdi_pool_permissions] ||= {}
|
|
2907
|
+
parse_access_csv(options[:vdi_pool_permissions], val)
|
|
2908
|
+
end
|
|
2909
|
+
opts.on('--global-report-type-access ACCESS', String, "Update the global report type access: [none|full]" ) do |val|
|
|
2910
|
+
params['globalReportTypeAccess'] = val.to_s.downcase
|
|
2911
|
+
end
|
|
2912
|
+
opts.on('--default-report-type-access ACCESS', String, "Update the default report type access: [none|full]" ) do |val|
|
|
2913
|
+
params['globalReportTypeAccess'] = val.to_s.downcase
|
|
2914
|
+
end
|
|
2915
|
+
opts.add_hidden_option('--default-report-type-access')
|
|
2916
|
+
opts.on('--report-types CODE=ACCESS', String, "Set report type to a custom access by report type code. Example: appCost=none,guidance=full" ) do |val|
|
|
2917
|
+
options[:report_type_permissions] ||= {}
|
|
2918
|
+
parse_access_csv(options[:report_type_permissions], val)
|
|
2919
|
+
end
|
|
2920
|
+
opts.on('--global-task-access ACCESS', String, "Set the global task access: [none|full]" ) do |val|
|
|
2921
|
+
params['globalTaskAccess'] = val.to_s.downcase
|
|
2922
|
+
end
|
|
2923
|
+
opts.add_hidden_option('--global-task-access')
|
|
2924
|
+
opts.on('--default-task-access ACCESS', String, "Set the default task access: [none|full]" ) do |val|
|
|
2925
|
+
params['globalTaskAccess'] = val.to_s.downcase
|
|
2926
|
+
end
|
|
2927
|
+
opts.on('--tasks ID=ACCESS', String, "Set task to a custom access by task id. Example: 1=none,2=full" ) do |val|
|
|
2928
|
+
options[:task_permissions] ||= {}
|
|
2929
|
+
parse_access_csv(options[:task_permissions], val)
|
|
2930
|
+
end
|
|
2931
|
+
opts.on('--global-workflow-access ACCESS', String, "Set the default workflow access: [none|full]" ) do |val|
|
|
2932
|
+
params['globalTaskSetAccess'] = val.to_s.downcase
|
|
2933
|
+
end
|
|
2934
|
+
opts.add_hidden_option('--global-workflow-access')
|
|
2935
|
+
opts.on('--default-workflow-access ACCESS', String, "Set the default workflow access: [none|full]" ) do |val|
|
|
2936
|
+
params['globalTaskSetAccess'] = val.to_s.downcase
|
|
2937
|
+
end
|
|
2938
|
+
opts.on('--workflows ID=ACCESS', String, "Set workflow to a custom access by workflow id. Example: 1=none,2=full" ) do |val|
|
|
2939
|
+
options[:workflow_permissions] ||= {}
|
|
2940
|
+
parse_access_csv(options[:workflow_permissions], val)
|
|
2941
|
+
end
|
|
2942
|
+
opts.on('--default-cluster-type-access ACCESS', String, "Set the default cluster type access: [none|full]" ) do |val|
|
|
2943
|
+
params['globalTaskSetAccess'] = val.to_s.downcase
|
|
2944
|
+
end
|
|
2945
|
+
opts.on('--cluster-types CODE=ACCESS', String, "Set cluster type to a custom access by cluster type code. Example: kubernetes-cluster=none,mvm-cluster=full" ) do |val|
|
|
2946
|
+
options[:cluster_type_permissions] ||= {}
|
|
2947
|
+
parse_access_csv(options[:cluster_type_permissions], val)
|
|
2948
|
+
end
|
|
2949
|
+
opts.on('--reset-permissions', "Reset all feature permission access to none. This can be used in conjunction with --permissions to recreate the feature permission access for the role." ) do
|
|
2950
|
+
options[:reset_permissions] = true
|
|
2951
|
+
end
|
|
2952
|
+
opts.add_hidden_option('--reset-permissions')
|
|
2953
|
+
opts.on('--reset-feature-access', "Reset all feature permission access to none. This can be used in conjunction with --feature-access to recreate the feature permission access for the role." ) do
|
|
2954
|
+
options[:reset_permissions] = true
|
|
2955
|
+
end
|
|
2956
|
+
opts.on('--reset-all-access', "Reset all access to none including permissions, global groups, instance types, etc. This can be used in conjunction with --feature-access to recreate the feature permission access for the role." ) do
|
|
2957
|
+
options[:reset_all_access] = true
|
|
2958
|
+
end
|
|
2959
|
+
end
|
|
2960
|
+
|
|
2961
|
+
# parse bulk permissions payload
|
|
2962
|
+
def parse_role_access_options(options, params)
|
|
2963
|
+
if options[:permissions]
|
|
2964
|
+
perms_array = []
|
|
2965
|
+
options[:permissions].each do |k,v|
|
|
2966
|
+
perm_code = k
|
|
2967
|
+
access_value = v.to_s.empty? ? "none" : v.to_s
|
|
2968
|
+
perms_array << {"code" => perm_code, "access" => access_value}
|
|
2969
|
+
end
|
|
2970
|
+
params['permissions'] = perms_array
|
|
2971
|
+
end
|
|
2972
|
+
if options[:group_permissions]
|
|
2973
|
+
perms_array = []
|
|
2974
|
+
options[:group_permissions].each do |k,v|
|
|
2975
|
+
site_id = k
|
|
2976
|
+
access_value = v.to_s.empty? ? "none" : v.to_s
|
|
2977
|
+
if site_id =~ /\A\d{1,}\Z/
|
|
2978
|
+
perms_array << {"id" => site_id.to_i, "access" => access_value}
|
|
2979
|
+
else
|
|
2980
|
+
perms_array << {"name" => site_id, "access" => access_value}
|
|
2981
|
+
end
|
|
2982
|
+
end
|
|
2983
|
+
params['sites'] = perms_array
|
|
2984
|
+
end
|
|
2985
|
+
if options[:cloud_permissions]
|
|
2986
|
+
perms_array = []
|
|
2987
|
+
options[:cloud_permissions].each do |k,v|
|
|
2988
|
+
zone_id = k
|
|
2989
|
+
access_value = v.to_s.empty? ? "none" : v.to_s
|
|
2990
|
+
if zone_id =~ /\A\d{1,}\Z/
|
|
2991
|
+
perms_array << {"id" => zone_id.to_i, "access" => access_value}
|
|
2992
|
+
else
|
|
2993
|
+
perms_array << {"name" => zone_id, "access" => access_value}
|
|
2994
|
+
end
|
|
2995
|
+
end
|
|
2996
|
+
params['zones'] = perms_array
|
|
2997
|
+
end
|
|
2998
|
+
if options[:instance_type_permissions]
|
|
2999
|
+
perms_array = []
|
|
3000
|
+
options[:instance_type_permissions].each do |k,v|
|
|
3001
|
+
instance_type_code = k
|
|
3002
|
+
access_value = v.to_s.empty? ? "none" : v.to_s
|
|
3003
|
+
if instance_type_code =~ /\A\d{1,}\Z/
|
|
3004
|
+
perms_array << {"id" => instance_type_code.to_i, "access" => access_value}
|
|
3005
|
+
else
|
|
3006
|
+
perms_array << {"code" => instance_type_code, "access" => access_value}
|
|
3007
|
+
end
|
|
3008
|
+
end
|
|
3009
|
+
params['instanceTypes'] = perms_array
|
|
3010
|
+
end
|
|
3011
|
+
if options[:blueprint_permissions]
|
|
3012
|
+
perms_array = []
|
|
3013
|
+
options[:blueprint_permissions].each do |k,v|
|
|
3014
|
+
blueprint_id = k
|
|
3015
|
+
access_value = v.to_s.empty? ? "none" : v.to_s
|
|
3016
|
+
if blueprint_id =~ /\A\d{1,}\Z/
|
|
3017
|
+
perms_array << {"id" => blueprint_id.to_i, "access" => access_value}
|
|
3018
|
+
else
|
|
3019
|
+
perms_array << {"name" => blueprint_id, "access" => access_value}
|
|
3020
|
+
end
|
|
3021
|
+
end
|
|
3022
|
+
params['appTemplates'] = perms_array
|
|
3023
|
+
end
|
|
3024
|
+
if options[:catalog_item_type_permissions]
|
|
3025
|
+
perms_array = []
|
|
3026
|
+
options[:catalog_item_type_permissions].each do |k,v|
|
|
3027
|
+
catalog_item_type_id = k
|
|
3028
|
+
access_value = v.to_s.empty? ? "none" : v.to_s
|
|
3029
|
+
if catalog_item_type_id =~ /\A\d{1,}\Z/
|
|
3030
|
+
perms_array << {"id" => catalog_item_type_id.to_i, "access" => access_value}
|
|
3031
|
+
else
|
|
3032
|
+
perms_array << {"name" => catalog_item_type_id, "access" => access_value}
|
|
3033
|
+
end
|
|
3034
|
+
end
|
|
3035
|
+
params['catalogItemTypes'] = perms_array
|
|
3036
|
+
|
|
3037
|
+
end
|
|
3038
|
+
if options[:persona_permissions]
|
|
3039
|
+
perms_array = []
|
|
3040
|
+
options[:persona_permissions].each do |k,v|
|
|
3041
|
+
persona_code = k
|
|
3042
|
+
access_value = v.to_s.empty? ? "none" : v.to_s
|
|
3043
|
+
perms_array << {"code" => persona_code, "access" => access_value}
|
|
3044
|
+
end
|
|
3045
|
+
params['personas'] = perms_array
|
|
3046
|
+
end
|
|
3047
|
+
if options[:vdi_pool_permissions]
|
|
3048
|
+
perms_array = []
|
|
3049
|
+
options[:vdi_pool_permissions].each do |k,v|
|
|
3050
|
+
vdi_pool_id = k
|
|
3051
|
+
access_value = v.to_s.empty? ? "none" : v.to_s
|
|
3052
|
+
if vdi_pool_id =~ /\A\d{1,}\Z/
|
|
3053
|
+
perms_array << {"id" => vdi_pool_id.to_i, "access" => access_value}
|
|
3054
|
+
else
|
|
3055
|
+
perms_array << {"name" => vdi_pool_id, "access" => access_value}
|
|
3056
|
+
end
|
|
3057
|
+
end
|
|
3058
|
+
params['vdiPools'] = perms_array
|
|
3059
|
+
end
|
|
3060
|
+
if options[:report_type_permissions]
|
|
3061
|
+
perms_array = []
|
|
3062
|
+
options[:report_type_permissions].each do |k,v|
|
|
3063
|
+
report_type_code = k
|
|
3064
|
+
access_value = v.to_s.empty? ? "none" : v.to_s
|
|
3065
|
+
if report_type_code =~ /\A\d{1,}\Z/
|
|
3066
|
+
perms_array << {"id" => report_type_code.to_i, "access" => access_value}
|
|
3067
|
+
else
|
|
3068
|
+
perms_array << {"code" => report_type_code, "access" => access_value}
|
|
3069
|
+
end
|
|
3070
|
+
end
|
|
3071
|
+
params['reportTypes'] = perms_array
|
|
3072
|
+
end
|
|
3073
|
+
if options[:task_permissions]
|
|
3074
|
+
perms_array = []
|
|
3075
|
+
options[:task_permissions].each do |k,v|
|
|
3076
|
+
task_id = k
|
|
3077
|
+
access_value = v.to_s.empty? ? "none" : v.to_s
|
|
3078
|
+
if task_id =~ /\A\d{1,}\Z/
|
|
3079
|
+
perms_array << {"id" => task_id.to_i, "access" => access_value}
|
|
3080
|
+
else
|
|
3081
|
+
perms_array << {"name" => task_id, "access" => access_value}
|
|
3082
|
+
end
|
|
3083
|
+
end
|
|
3084
|
+
params['tasks'] = perms_array
|
|
3085
|
+
end
|
|
3086
|
+
if options[:workflow_permissions]
|
|
3087
|
+
perms_array = []
|
|
3088
|
+
options[:workflow_permissions].each do |k,v|
|
|
3089
|
+
workflow_id = k
|
|
3090
|
+
access_value = v.to_s.empty? ? "none" : v.to_s
|
|
3091
|
+
if workflow_id =~ /\A\d{1,}\Z/
|
|
3092
|
+
perms_array << {"id" => workflow_id.to_i, "access" => access_value}
|
|
3093
|
+
else
|
|
3094
|
+
perms_array << {"name" => workflow_id, "access" => access_value}
|
|
3095
|
+
end
|
|
3096
|
+
end
|
|
3097
|
+
params['taskSets'] = perms_array
|
|
3098
|
+
end
|
|
3099
|
+
if options[:cluster_type_permissions]
|
|
3100
|
+
perms_array = []
|
|
3101
|
+
options[:cluster_type_permissions].each do |k,v|
|
|
3102
|
+
cluster_type_code = k
|
|
3103
|
+
access_value = v.to_s.empty? ? "none" : v.to_s
|
|
3104
|
+
if cluster_type_code =~ /\A\d{1,}\Z/
|
|
3105
|
+
perms_array << {"id" => cluster_type_code.to_i, "access" => access_value}
|
|
3106
|
+
else
|
|
3107
|
+
perms_array << {"code" => cluster_type_code, "access" => access_value}
|
|
3108
|
+
end
|
|
3109
|
+
end
|
|
3110
|
+
params['clusterTypes'] = perms_array
|
|
3111
|
+
end
|
|
3112
|
+
if options[:reset_permissions]
|
|
3113
|
+
params["resetPermissions"] = true
|
|
3114
|
+
end
|
|
3115
|
+
if options[:reset_all_access]
|
|
3116
|
+
params["resetAllAccess"] = true
|
|
3117
|
+
end
|
|
3118
|
+
end
|
|
3119
|
+
|
|
3120
|
+
end
|