From 666c17946d2d19af70421ed61154bae268323d5a Mon Sep 17 00:00:00 2001 From: lgalis <lgalis@redhat.com> Date: Fri, 23 Feb 2018 18:52:30 -0500 Subject: [PATCH 1/9] Add vault credentials to the Embedded Ansible UI --- .../catalog/catalog_item_form_controller.js | 7 +++++++ .../miq_ae_class/ae_method_form_controller.js | 3 +++ .../controllers/playbook-reusable-code-mixin.js | 10 ++++++++++ app/controllers/catalog_controller.rb | 2 ++ app/controllers/miq_ae_class_controller.rb | 1 + app/helpers/service_helper/textual_summary.rb | 10 ++++++++-- app/views/catalog/_sandt_tree_show.html.haml | 5 +++++ .../angular/_ansible_form_options_angular.html.haml | 13 +++++++++++++ app/views/miq_ae_class/_method_inputs.html.haml | 2 ++ spec/helpers/service_helper/textual_summary_spec.rb | 12 ++++++++++++ 10 files changed, 63 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/controllers/catalog/catalog_item_form_controller.js b/app/assets/javascripts/controllers/catalog/catalog_item_form_controller.js index 2f5d0d6c86a..b4b49b73d9b 100644 --- a/app/assets/javascripts/controllers/catalog/catalog_item_form_controller.js +++ b/app/assets/javascripts/controllers/catalog/catalog_item_form_controller.js @@ -14,6 +14,7 @@ ManageIQ.angular.app.controller('catalogItemFormController', ['$scope', 'catalog provisioning_machine_credential_id: '', provisioning_network_credential_id: '', provisioning_cloud_credential_id: '', + provisioning_vault_credential_id: '', provisioning_execution_ttl: '', provisioning_inventory: 'localhost', provisioning_dialog_existing: '', @@ -31,6 +32,7 @@ ManageIQ.angular.app.controller('catalogItemFormController', ['$scope', 'catalog retirement_machine_credential_id: '', retirement_network_credential_id: '', retirement_cloud_credential_id: '', + retirement_vault_credential_id: '', retirement_execution_ttl: '', retirement_inventory: 'localhost', retirement_key: '', @@ -82,6 +84,7 @@ ManageIQ.angular.app.controller('catalogItemFormController', ['$scope', 'catalog vm.catalogItemModel.provisioning_machine_credential_id = configData.provision.credential_id; vm.catalogItemModel.provisioning_network_credential_id = configData.provision.network_credential_id; vm.catalogItemModel.provisioning_cloud_credential_id = playbookReusableCodeMixin.setIfDefined(configData.provision.cloud_credential_id); + vm.catalogItemModel.provisioning_vault_credential_id = configData.provision.vault_credential_id; vm.catalogItemModel.provisioning_execution_ttl = configData.provision.execution_ttl; vm.catalogItemModel.provisioning_inventory = configData.provision.hosts; if (configData.provision.hosts !== 'localhost') { @@ -115,6 +118,7 @@ ManageIQ.angular.app.controller('catalogItemFormController', ['$scope', 'catalog playbookReusableCodeMixin.getRemoveResourcesTypes(vm); vm.catalogItemModel.retirement_remove_resources = configData.retirement.remove_resources; vm.catalogItemModel.retirement_machine_credential_id = configData.retirement.credential_id; + vm.catalogItemModel.retirement_vault_credential_id = configData.retirement.vault_credential_id; } if (configData.retirement.become_enabled === undefined) { vm.catalogItemModel.retirement_become_enabled = false; @@ -213,6 +217,7 @@ ManageIQ.angular.app.controller('catalogItemFormController', ['$scope', 'catalog repository_id: configData.provisioning_repository_id, playbook_id: configData.provisioning_playbook_id, credential_id: configData.provisioning_machine_credential_id, + vault_credential_id: configData.provisioning_vault_credential_id, hosts: configData.provisioning_inventory, verbosity: configData.provisioning_verbosity, log_output: configData.provisioning_log_output, @@ -247,6 +252,7 @@ ManageIQ.angular.app.controller('catalogItemFormController', ['$scope', 'catalog retirement['repository_id'] = configData.retirement_repository_id; retirement['playbook_id'] = configData.retirement_playbook_id; retirement['credential_id'] = configData.retirement_machine_credential_id; + retirement['vault_credential_id'] = configData.retirement_vault_credential_id; } if (vm.catalogItemModel.retirement_playbook_id !== undefined && configData.retirement_playbook_id !== '') { if (vm.catalogItemModel.retirement_execution_ttl !== undefined) @@ -429,6 +435,7 @@ ManageIQ.angular.app.controller('catalogItemFormController', ['$scope', 'catalog vm.catalogItemModel.retirement_playbook_id = vm.catalogItemModel.provisioning_playbook_id; vm.catalogItemModel.retirement_machine_credential_id = vm.catalogItemModel.provisioning_machine_credential_id; vm.catalogItemModel.retirement_network_credential_id = vm.catalogItemModel.provisioning_network_credential_id; + vm.catalogItemModel.retirement_vault_credential_id = vm.catalogItemModel.provisioning_vault_credential_id; vm.retirement_cloud_type = vm.provisioning_cloud_type; vm._retirement_cloud_type = vm.provisioning_cloud_type; vm.catalogItemModel.retirement_cloud_credential_id = vm.catalogItemModel.provisioning_cloud_credential_id; diff --git a/app/assets/javascripts/controllers/miq_ae_class/ae_method_form_controller.js b/app/assets/javascripts/controllers/miq_ae_class/ae_method_form_controller.js index c46cdf2b885..6e0da7a2705 100644 --- a/app/assets/javascripts/controllers/miq_ae_class/ae_method_form_controller.js +++ b/app/assets/javascripts/controllers/miq_ae_class/ae_method_form_controller.js @@ -21,6 +21,7 @@ function aeMethodFormController($http, $scope, aeMethodFormId, currentRegion, mi provisioning_machine_credential_id: '', provisioning_network_credential_id: '', provisioning_cloud_credential_id: '', + provisioning_vault_credential_id: '', provisioning_key: '', provisioning_value: '', provisioning_type: 'string', @@ -75,6 +76,7 @@ function aeMethodFormController($http, $scope, aeMethodFormId, currentRegion, mi vm.aeMethodModel.provisioning_machine_credential_id = configData.credential_id; vm.aeMethodModel.provisioning_network_credential_id = configData.network_credential_id; vm.aeMethodModel.provisioning_cloud_credential_id = playbookReusableCodeMixin.setIfDefined(configData.cloud_credential_id); + vm.aeMethodModel.provisioning_vault_credential_id = playbookReusableCodeMixin.setIfDefined(configData.vault_credential_id); vm.aeMethodModel.provisioning_become_enabled = configData.become_enabled === true; vm.aeMethodModel.provisioning_key = ''; vm.aeMethodModel.provisioning_value = ''; @@ -143,6 +145,7 @@ function aeMethodFormController($http, $scope, aeMethodFormId, currentRegion, mi repository_id: configData.provisioning_repository_id, playbook_id: configData.provisioning_playbook_id, credential_id: configData.provisioning_machine_credential_id, + vault_credential_id: configData.provisioning_vault_credential_id, verbosity: configData.provisioning_verbosity, become_enabled: configData.provisioning_become_enabled, execution_ttl: configData.provisioning_execution_ttl, diff --git a/app/assets/javascripts/controllers/playbook-reusable-code-mixin.js b/app/assets/javascripts/controllers/playbook-reusable-code-mixin.js index c48066c0fc8..f344721f1b8 100644 --- a/app/assets/javascripts/controllers/playbook-reusable-code-mixin.js +++ b/app/assets/javascripts/controllers/playbook-reusable-code-mixin.js @@ -143,6 +143,16 @@ function playbookReusableCodeMixin(API, $q, miqService) { .catch(miqService.handleFailure) ); + // list of machine credentials + allApiPromises.push(API.get('/api/authentications?collection_class=ManageIQ::Providers::EmbeddedAnsible::AutomationManager::VaultCredential&expand=resources&attributes=id,name' + sortOptions) + .then(function(data) { + vm.vault_credentials = data.resources; + vm._vault_credential = _.find(vm.vault_credentials, {id: vm[vm.model].retirement_vault_credential_id}); + vm._provisioning_vault_credential = _.find(vm.vault_credentials, {id: vm[vm.model].provisioning_vault_credential_id}); + }) + .catch(miqService.handleFailure) + ); + // list of network credentials allApiPromises.push(API.get('/api/authentications?collection_class=ManageIQ::Providers::EmbeddedAnsible::AutomationManager::NetworkCredential&expand=resources&attributes=id,name' + sortOptions) .then(function(data) { diff --git a/app/controllers/catalog_controller.rb b/app/controllers/catalog_controller.rb index 771acd31e42..16f1cf1657e 100644 --- a/app/controllers/catalog_controller.rb +++ b/app/controllers/catalog_controller.rb @@ -1865,6 +1865,7 @@ def fetch_playbook_details playbook_details[:provisioning][:machine_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::MachineCredential, provision[:credential_id]) playbook_details[:provisioning][:network_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::NetworkCredential, provision[:network_credential_id]) if provision[:network_credential_id] playbook_details[:provisioning][:cloud_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::CloudCredential, provision[:cloud_credential_id]) if provision[:cloud_credential_id] + playbook_details[:provisioning][:vault_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::VaultCredential, provision[:vault_credential_id]) if provision[:vault_credential_id] fetch_dialog(playbook_details, provision[:dialog_id], :provisioning) playbook_details[:provisioning][:execution_ttl] = provision[:execution_ttl] playbook_details[:provisioning][:verbosity] = provision[:verbosity] @@ -1881,6 +1882,7 @@ def fetch_playbook_details playbook_details[:retirement][:machine_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::MachineCredential, retirement[:credential_id]) playbook_details[:retirement][:network_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::NetworkCredential, retirement[:network_credential_id]) if retirement[:network_credential_id] playbook_details[:retirement][:cloud_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::CloudCredential, retirement[:cloud_credential_id]) if retirement[:cloud_credential_id] + playbook_details[:retirement][:vault_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::VaultCredential, retirement[:vault_credential_id]) if retirement[:vault_credential_id] end playbook_details[:retirement][:execution_ttl] = retirement[:execution_ttl] playbook_details[:retirement][:verbosity] = retirement[:verbosity] diff --git a/app/controllers/miq_ae_class_controller.rb b/app/controllers/miq_ae_class_controller.rb index 16f34ea3f09..3aac5bee9f1 100644 --- a/app/controllers/miq_ae_class_controller.rb +++ b/app/controllers/miq_ae_class_controller.rb @@ -2709,6 +2709,7 @@ def fetch_playbook_details @playbook_details[:machine_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::MachineCredential, options[:credential_id]) @playbook_details[:network_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::NetworkCredential, options[:network_credential_id]) if options[:network_credential_id] @playbook_details[:cloud_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::CloudCredential, options[:cloud_credential_id]) if options[:cloud_credential_id] + @playbook_details[:vault_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::VautCredential, options[:vault_credential_id]) if options[:vault_credential_id] @playbook_details[:verbosity] = options[:verbosity] @playbook_details[:become_enabled] = options[:become_enabled] == true ? _("Yes") : _("No") @playbook_details[:execution_ttl] = options[:execution_ttl] diff --git a/app/helpers/service_helper/textual_summary.rb b/app/helpers/service_helper/textual_summary.rb index 6aac70a0bbf..651454081ee 100644 --- a/app/helpers/service_helper/textual_summary.rb +++ b/app/helpers/service_helper/textual_summary.rb @@ -24,7 +24,7 @@ def textual_group_provisioning_details def textual_group_provisioning_credentials return nil unless provisioning_get_job - TextualGroup.new(_("Credentials"), %i(machine_credential network_credential cloud_credential)) + TextualGroup.new(_("Credentials"), %i(machine_credential vault_credential network_credential cloud_credential)) end def textual_group_provisioning_plays @@ -44,7 +44,7 @@ def textual_group_retirement_details def textual_group_retirement_credentials return nil unless retirement_get_job - TextualGroup.new(_("Credentials"), %i(machine_credential network_credential cloud_credential)) + TextualGroup.new(_("Credentials"), %i(machine_credential vault_credential network_credential cloud_credential)) end def textual_group_retirement_plays @@ -228,6 +228,12 @@ def textual_machine_credential credential(credential, _("Machine")) end + def textual_vault_credential + credential = @job.authentications.find_by(:type => 'ManageIQ::Providers::EmbeddedAnsible::AutomationManager::VaultCredential') + return nil unless credential + credential(credential, _("Vault")) + end + def textual_network_credential credential = @job.authentications.find_by(:type => 'ManageIQ::Providers::EmbeddedAnsible::AutomationManager::NetworkCredential') return nil unless credential diff --git a/app/views/catalog/_sandt_tree_show.html.haml b/app/views/catalog/_sandt_tree_show.html.haml index c9a97572480..6fdc88d32d5 100644 --- a/app/views/catalog/_sandt_tree_show.html.haml +++ b/app/views/catalog/_sandt_tree_show.html.haml @@ -227,6 +227,11 @@ = _('Machine Credential') .col-md-9 = h(provisioning[:machine_credential]) + .form-group + %label.col-md-3.control-label + = _('Vault Credential') + .col-md-9 + = h(provisioning[:vault_credential]) -#.form-group -# %label.col-md-3.control-label -# = _('Network Credential') diff --git a/app/views/layouts/angular/_ansible_form_options_angular.html.haml b/app/views/layouts/angular/_ansible_form_options_angular.html.haml index c9710dfcc7a..5fcb959b5ce 100644 --- a/app/views/layouts/angular/_ansible_form_options_angular.html.haml +++ b/app/views/layouts/angular/_ansible_form_options_angular.html.haml @@ -58,6 +58,19 @@ 'pf-select' => true} %option{"value" => ""} = "<#{_('Choose')}>" + .form-group{"ng-class" => "{'has-error': angularForm.#{prefix}_vault_credential_id.$invalid}"} + %label.col-md-3.control-label{"for" => "#{prefix}_vault_credential_id"} + = _('Vault Credential') + .col-md-9 + %select{"ng-model" => "vm._#{prefix}_vault_credential", + "name" => "#{prefix}_vault_credential_id", + 'ng-options' => 'vault_credential as vault_credential.name for vault_credential in vm.vault_credentials', + "required" => "", + :miqrequired => true, + "data-live-search" => "true", + 'pf-select' => true} + %option{"value" => ""} + = "<#{_('Choose')}>" -#.form-group -# %label.col-md-3.control-label{"for" => "vm.#{prefix}_network_credential_id"} -# = _('Network Credential') diff --git a/app/views/miq_ae_class/_method_inputs.html.haml b/app/views/miq_ae_class/_method_inputs.html.haml index 5ff95bb9ffc..1664417555f 100644 --- a/app/views/miq_ae_class/_method_inputs.html.haml +++ b/app/views/miq_ae_class/_method_inputs.html.haml @@ -46,6 +46,8 @@ = format_form_group(_('Playbook'), @playbook_details[:playbook]) .form-group = format_form_group(_('Machine Credential'), @playbook_details[:machine_credential]) + .form-group + = format_form_group(_('Vault Credential'), @playbook_details[:vault_credential]) .form-group = format_form_group(_('Cloud Credential'), @playbook_details[:cloud_credential]) .form-group diff --git a/spec/helpers/service_helper/textual_summary_spec.rb b/spec/helpers/service_helper/textual_summary_spec.rb index a3920b19e56..6c118d49f76 100644 --- a/spec/helpers/service_helper/textual_summary_spec.rb +++ b/spec/helpers/service_helper/textual_summary_spec.rb @@ -84,4 +84,16 @@ expect(textual_cloud_credential).to eq({:label=>"Cloud", :value=>nil, :title=>"Credential (Amazon)", :link=>"link"}) end end + + describe ".textual_vault_credential" do + subject { textual_vault_credential } + it 'displays only vault credentials if available' do + @job = FactoryGirl.create(:embedded_ansible_job) + machine_credential = FactoryGirl.create(:embedded_ansible_machine_credential) + vault_credential = FactoryGirl.create(:embedded_ansible_vault_credential) + allow(@job).to receive(:authentications).and_return([vault_credential, machine_credential]) + allow(self).to receive(:url_for_only_path).and_return('link') + expect(textual_cloud_credential).to eq(:label => "Vault", :value => nil, :title => "Credential (Vault)", :link => "link") + end + end end From 0980bdd2b435844bffc18545b5a38b15a9dabad0 Mon Sep 17 00:00:00 2001 From: lgalis <lgalis@redhat.com> Date: Tue, 27 Feb 2018 14:01:59 -0500 Subject: [PATCH 2/9] Added vault credentials to the textual summary --- app/helpers/service_helper/textual_summary.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/helpers/service_helper/textual_summary.rb b/app/helpers/service_helper/textual_summary.rb index 651454081ee..754b4eb6eec 100644 --- a/app/helpers/service_helper/textual_summary.rb +++ b/app/helpers/service_helper/textual_summary.rb @@ -243,6 +243,7 @@ def textual_network_credential def textual_cloud_credential cloud_credential = nil excluded_types = ["ManageIQ::Providers::EmbeddedAnsible::AutomationManager::MachineCredential", + "ManageIQ::Providers::EmbeddedAnsible::AutomationManager::VaultCredential", "ManageIQ::Providers::EmbeddedAnsible::AutomationManager::NetworkCredential"] @job.authentications.each do |authentication| cloud_credential = authentication unless excluded_types.include?(authentication.type) From 76e0f3a2b2b0a39d8a416f1ab4aee9717eff48dc Mon Sep 17 00:00:00 2001 From: lgalis <lgalis@redhat.com> Date: Tue, 27 Feb 2018 14:02:54 -0500 Subject: [PATCH 3/9] Update catalog item specs with the vault credentials --- spec/helpers/service_helper/textual_summary_spec.rb | 5 ++--- .../controllers/catalog/catalog_item_form_controller_spec.js | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/helpers/service_helper/textual_summary_spec.rb b/spec/helpers/service_helper/textual_summary_spec.rb index 6c118d49f76..d74e6041156 100644 --- a/spec/helpers/service_helper/textual_summary_spec.rb +++ b/spec/helpers/service_helper/textual_summary_spec.rb @@ -89,11 +89,10 @@ subject { textual_vault_credential } it 'displays only vault credentials if available' do @job = FactoryGirl.create(:embedded_ansible_job) - machine_credential = FactoryGirl.create(:embedded_ansible_machine_credential) vault_credential = FactoryGirl.create(:embedded_ansible_vault_credential) - allow(@job).to receive(:authentications).and_return([vault_credential, machine_credential]) + allow(@job).to receive(:authentications).and_return(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::VaultCredential.where(:id => vault_credential.id)) allow(self).to receive(:url_for_only_path).and_return('link') - expect(textual_cloud_credential).to eq(:label => "Vault", :value => nil, :title => "Credential (Vault)", :link => "link") + expect(textual_vault_credential).to eq(:label => "Vault", :value => nil, :title => "Credential (Vault)", :link => "link") end end end diff --git a/spec/javascripts/controllers/catalog/catalog_item_form_controller_spec.js b/spec/javascripts/controllers/catalog/catalog_item_form_controller_spec.js index f5f23df3624..35a7c3bf6a9 100644 --- a/spec/javascripts/controllers/catalog/catalog_item_form_controller_spec.js +++ b/spec/javascripts/controllers/catalog/catalog_item_form_controller_spec.js @@ -28,6 +28,7 @@ describe('catalogItemFormController', function() { repository_id: undefined, playbook_id: 10000000000493, credential_id: 10000000000090, + vault_credential_id: 10000000000100, execution_ttl: 100, hosts: 'localhost', verbosity: '0', From 518d12686010ae3be487df7591bf80c576a514ce Mon Sep 17 00:00:00 2001 From: lgalis <lgalis@redhat.com> Date: Wed, 28 Feb 2018 11:34:32 -0500 Subject: [PATCH 4/9] Remove a few comment lines and spaces --- app/helpers/service_helper/textual_summary.rb | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/app/helpers/service_helper/textual_summary.rb b/app/helpers/service_helper/textual_summary.rb index 754b4eb6eec..f7a832ff69e 100644 --- a/app/helpers/service_helper/textual_summary.rb +++ b/app/helpers/service_helper/textual_summary.rb @@ -4,9 +4,7 @@ module ServiceHelper::TextualSummary include TextualMixins::TextualName include GenericObjectHelper::TextualSummary - # # Groups - # def textual_group_properties TextualGroup.new(_("Properties"), %i(name description guid)) @@ -79,9 +77,8 @@ def textual_group_generic_objects TextualGroup.new(_("Generic Objects"), %i(generic_object_instances)) end - # # Items - # + def textual_guid {:label => _("Management Engine GUID"), :value => @record.guid} end @@ -148,12 +145,10 @@ def textual_parent_service def textual_orchestration_stack ost = @record.try(:orchestration_stack) if ost && !ost.id.present? - { - :label => _("Orchestration Stack"), - :image => "100/orchestration_stack.png", - :value => ost.name, - :title => _("Invalid Stack") - } + {:label => _("Orchestration Stack"), + :image => "100/orchestration_stack.png", + :value => ost.name, + :title => _("Invalid Stack")} elsif ost ost end @@ -284,12 +279,10 @@ def fetch_job(type) def fetch_job_plays items = @job.job_plays.sort_by(&:start_time).collect do |play| - [ - play.name, - format_timezone(play.start_time), - format_timezone(play.finish_time), - play.finish_time && play.start_time ? calculate_elapsed_time(play.start_time, play.finish_time) : '/A' - ] + [play.name, + format_timezone(play.start_time), + format_timezone(play.finish_time), + play.finish_time && play.start_time ? calculate_elapsed_time(play.start_time, play.finish_time) : '/A'] end.sort TextualTable.new( From 3dceef3d844726fe3d362e782d336565acee27fa Mon Sep 17 00:00:00 2001 From: lgalis <lgalis@redhat.com> Date: Wed, 28 Feb 2018 16:01:14 -0500 Subject: [PATCH 5/9] Refactor getting the credential list --- .../playbook-reusable-code-mixin.js | 43 ++++++++----------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/app/assets/javascripts/controllers/playbook-reusable-code-mixin.js b/app/assets/javascripts/controllers/playbook-reusable-code-mixin.js index f344721f1b8..e8ee0a3cbe5 100644 --- a/app/assets/javascripts/controllers/playbook-reusable-code-mixin.js +++ b/app/assets/javascripts/controllers/playbook-reusable-code-mixin.js @@ -98,6 +98,20 @@ function playbookReusableCodeMixin(API, $q, miqService) { ); }; + var getCredentialsForType = function(type, credentialUrl, vm) { + var prefixes = ['retirement', 'provisioning']; + var prefixLen = prefixes.length; + allApiPromises.push(API.get(credentialUrl + sortOptions) + .then(function(data) { + vm[type + '_credentials'] = data.resources; + for (var i = 0; i < prefixLen; i++) { + vm['_' + prefixes[i] + type + '_credential'] = _.find(vm[type + '_credentials'], {id: vm[vm.model][prefixes[i] + '_' + type + '_credential_id']}); + } + }) + .catch(miqService.handleFailure) + ); + }; + // list of service catalogs var formOptions = function(vm) { miqService.sparkleOn(); @@ -134,34 +148,13 @@ function playbookReusableCodeMixin(API, $q, miqService) { ); // list of machine credentials - allApiPromises.push(API.get('/api/authentications?collection_class=ManageIQ::Providers::EmbeddedAnsible::AutomationManager::MachineCredential&expand=resources&attributes=id,name' + sortOptions) - .then(function(data) { - vm.machine_credentials = data.resources; - vm._retirement_machine_credential = _.find(vm.machine_credentials, {id: vm[vm.model].retirement_machine_credential_id}); - vm._provisioning_machine_credential = _.find(vm.machine_credentials, {id: vm[vm.model].provisioning_machine_credential_id}); - }) - .catch(miqService.handleFailure) - ); + getCredentialsForType('machine', '/api/authentications?collection_class=ManageIQ::Providers::EmbeddedAnsible::AutomationManager::MachineCredential&expand=resources&attributes=id,name', vm); - // list of machine credentials - allApiPromises.push(API.get('/api/authentications?collection_class=ManageIQ::Providers::EmbeddedAnsible::AutomationManager::VaultCredential&expand=resources&attributes=id,name' + sortOptions) - .then(function(data) { - vm.vault_credentials = data.resources; - vm._vault_credential = _.find(vm.vault_credentials, {id: vm[vm.model].retirement_vault_credential_id}); - vm._provisioning_vault_credential = _.find(vm.vault_credentials, {id: vm[vm.model].provisioning_vault_credential_id}); - }) - .catch(miqService.handleFailure) - ); + // list of vault credentials + getCredentialsForType('vault', '/api/authentications?collection_class=ManageIQ::Providers::EmbeddedAnsible::AutomationManager::VaultCredential&expand=resources&attributes=id,name', vm); // list of network credentials - allApiPromises.push(API.get('/api/authentications?collection_class=ManageIQ::Providers::EmbeddedAnsible::AutomationManager::NetworkCredential&expand=resources&attributes=id,name' + sortOptions) - .then(function(data) { - vm.network_credentials = data.resources; - vm._retirement_network_credential = _.find(vm.network_credentials, {id: vm[vm.model].retirement_network_credential_id}); - vm._provisioning_network_credential = _.find(vm.network_credentials, {id: vm[vm.model].provisioning_network_credential_id}); - }) - .catch(miqService.handleFailure) - ); + getCredentialsForType('network', '/api/authentications?collection_class=ManageIQ::Providers::EmbeddedAnsible::AutomationManager::NetworkCredential&expand=resources&attributes=id,name', vm); }; function retrievedFormData(vm) { From 406c116d7d97b3ca44cd87af698fd408080f17e1 Mon Sep 17 00:00:00 2001 From: lgalis <lgalis@redhat.com> Date: Thu, 1 Mar 2018 12:14:05 -0500 Subject: [PATCH 6/9] Add vault credentials to data --- .../catalog/catalog_item_form_controller.js | 3 +- .../miq_ae_class/ae_method_form_controller.js | 4 +-- .../playbook-reusable-code-mixin.js | 2 +- app/controllers/miq_ae_class_controller.rb | 28 +++++++++---------- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/app/assets/javascripts/controllers/catalog/catalog_item_form_controller.js b/app/assets/javascripts/controllers/catalog/catalog_item_form_controller.js index b4b49b73d9b..52c990d217a 100644 --- a/app/assets/javascripts/controllers/catalog/catalog_item_form_controller.js +++ b/app/assets/javascripts/controllers/catalog/catalog_item_form_controller.js @@ -133,6 +133,7 @@ ManageIQ.angular.app.controller('catalogItemFormController', ['$scope', 'catalog } vm.catalogItemModel.retirement_network_credential_id = configData.retirement.network_credential_id; + vm.catalogItemModel.retirement_vault_credential_id = configData.retirement.vault_credential_id; vm.catalogItemModel.retirement_cloud_credential_id = playbookReusableCodeMixin.setIfDefined(configData.retirement.cloud_credential_id); vm.catalogItemModel.retirement_execution_ttl = configData.retirement.execution_ttl; vm.catalogItemModel.retirement_inventory = configData.retirement.hosts; @@ -399,7 +400,7 @@ ManageIQ.angular.app.controller('catalogItemFormController', ['$scope', 'catalog }; // watch for all the drop downs on screen - 'catalog provisioning_playbook retirement_playbook provisioning_machine_credential retirement_machine_credential provisioning_network_credential retirement_network_credential provisioning_cloud_credential retirement_cloud_credential provisioning_dialog'.split(' ').forEach(idWatch); + 'catalog provisioning_playbook retirement_playbook provisioning_machine_credential retirement_machine_credential provisioning_vault_credential retirement_vault_credential provisioning_network_credential retirement_network_credential provisioning_cloud_credential retirement_cloud_credential provisioning_dialog'.split(' ').forEach(idWatch); function idWatch(name) { var fieldName = 'vm._' + name; diff --git a/app/assets/javascripts/controllers/miq_ae_class/ae_method_form_controller.js b/app/assets/javascripts/controllers/miq_ae_class/ae_method_form_controller.js index 6e0da7a2705..a2874850c4e 100644 --- a/app/assets/javascripts/controllers/miq_ae_class/ae_method_form_controller.js +++ b/app/assets/javascripts/controllers/miq_ae_class/ae_method_form_controller.js @@ -75,8 +75,8 @@ function aeMethodFormController($http, $scope, aeMethodFormId, currentRegion, mi vm.aeMethodModel.provisioning_playbook_id = configData.playbook_id; vm.aeMethodModel.provisioning_machine_credential_id = configData.credential_id; vm.aeMethodModel.provisioning_network_credential_id = configData.network_credential_id; + vm.aeMethodModel.provisioning_vault_credential_id = configData.vault_credential_id; vm.aeMethodModel.provisioning_cloud_credential_id = playbookReusableCodeMixin.setIfDefined(configData.cloud_credential_id); - vm.aeMethodModel.provisioning_vault_credential_id = playbookReusableCodeMixin.setIfDefined(configData.vault_credential_id); vm.aeMethodModel.provisioning_become_enabled = configData.become_enabled === true; vm.aeMethodModel.provisioning_key = ''; vm.aeMethodModel.provisioning_value = ''; @@ -262,7 +262,7 @@ function aeMethodFormController($http, $scope, aeMethodFormId, currentRegion, mi }; // watch for all the drop downs on screen - "provisioning_playbook provisioning_machine_credential provisioning_network_credential provisioning_cloud_credential".split(" ").forEach(idWatch); + "provisioning_playbook provisioning_machine_credential provisioning_vault_credential provisioning_network_credential provisioning_cloud_credential".split(" ").forEach(idWatch); function idWatch(name) { var fieldName = "vm._" + name; diff --git a/app/assets/javascripts/controllers/playbook-reusable-code-mixin.js b/app/assets/javascripts/controllers/playbook-reusable-code-mixin.js index e8ee0a3cbe5..0bf21fc9dae 100644 --- a/app/assets/javascripts/controllers/playbook-reusable-code-mixin.js +++ b/app/assets/javascripts/controllers/playbook-reusable-code-mixin.js @@ -105,7 +105,7 @@ function playbookReusableCodeMixin(API, $q, miqService) { .then(function(data) { vm[type + '_credentials'] = data.resources; for (var i = 0; i < prefixLen; i++) { - vm['_' + prefixes[i] + type + '_credential'] = _.find(vm[type + '_credentials'], {id: vm[vm.model][prefixes[i] + '_' + type + '_credential_id']}); + vm['_' + prefixes[i] + '_' + type + '_credential'] = _.find(vm[type + '_credentials'], {id: vm[vm.model][prefixes[i] + '_' + type + '_credential_id']}); } }) .catch(miqService.handleFailure) diff --git a/app/controllers/miq_ae_class_controller.rb b/app/controllers/miq_ae_class_controller.rb index 3aac5bee9f1..e7409fb2f78 100644 --- a/app/controllers/miq_ae_class_controller.rb +++ b/app/controllers/miq_ae_class_controller.rb @@ -985,19 +985,18 @@ def method_form_fields :language => 'ruby', :scope => "instance", :available_datatypes => MiqAeField.available_datatypes_for_ui, - :config_info => { - :repository_id => method.options[:repository_id] || '', - :playbook_id => method.options[:playbook_id] || '', - :credential_id => method.options[:credential_id] || '', - :network_credential_id => method.options[:network_credential_id] || '', - :cloud_credential_id => method.options[:cloud_credential_id] || '', - :verbosity => method.options[:verbosity], - :become_enabled => method.options[:become_enabled] || false, - :execution_ttl => method.options[:execution_ttl] || '', - :hosts => method.options[:hosts] || 'localhost', - :log_output => method.options[:log_output] || 'on_error', - :extra_vars => method.inputs - } + :config_info => { :repository_id => method.options[:repository_id] || '', + :playbook_id => method.options[:playbook_id] || '', + :credential_id => method.options[:credential_id] || '', + :vault_credential_id => method.options[:vault_credential_id] || '', + :network_credential_id => method.options[:network_credential_id] || '', + :cloud_credential_id => method.options[:cloud_credential_id] || '', + :verbosity => method.options[:verbosity], + :become_enabled => method.options[:become_enabled] || false, + :execution_ttl => method.options[:execution_ttl] || '', + :hosts => method.options[:hosts] || 'localhost', + :log_output => method.options[:log_output] || 'on_error', + :extra_vars => method.inputs } } render :json => method_hash end @@ -1749,6 +1748,7 @@ def set_playbook_data params_list = %i(repository_id playbook_id credential_id + vault_credential_id verbosity network_credential_id cloud_credential_id @@ -2709,7 +2709,7 @@ def fetch_playbook_details @playbook_details[:machine_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::MachineCredential, options[:credential_id]) @playbook_details[:network_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::NetworkCredential, options[:network_credential_id]) if options[:network_credential_id] @playbook_details[:cloud_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::CloudCredential, options[:cloud_credential_id]) if options[:cloud_credential_id] - @playbook_details[:vault_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::VautCredential, options[:vault_credential_id]) if options[:vault_credential_id] + @playbook_details[:vault_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::VaultCredential, options[:vault_credential_id]) if options[:vault_credential_id] @playbook_details[:verbosity] = options[:verbosity] @playbook_details[:become_enabled] = options[:become_enabled] == true ? _("Yes") : _("No") @playbook_details[:execution_ttl] = options[:execution_ttl] From b3a2eed7b63845db402c1dc15ce214677d80705b Mon Sep 17 00:00:00 2001 From: lgalis <lgalis@redhat.com> Date: Thu, 22 Mar 2018 17:43:52 -0400 Subject: [PATCH 7/9] Set Vault Credential to optional --- .../layouts/angular/_ansible_form_options_angular.html.haml | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/views/layouts/angular/_ansible_form_options_angular.html.haml b/app/views/layouts/angular/_ansible_form_options_angular.html.haml index 5fcb959b5ce..f033ae5a231 100644 --- a/app/views/layouts/angular/_ansible_form_options_angular.html.haml +++ b/app/views/layouts/angular/_ansible_form_options_angular.html.haml @@ -65,8 +65,6 @@ %select{"ng-model" => "vm._#{prefix}_vault_credential", "name" => "#{prefix}_vault_credential_id", 'ng-options' => 'vault_credential as vault_credential.name for vault_credential in vm.vault_credentials', - "required" => "", - :miqrequired => true, "data-live-search" => "true", 'pf-select' => true} %option{"value" => ""} From 814de5ae0560ae4ea74013fe9b81836dd439a63f Mon Sep 17 00:00:00 2001 From: lgalis <lgalis@redhat.com> Date: Fri, 23 Mar 2018 13:10:24 -0400 Subject: [PATCH 8/9] Detect the change to nil for id fields. Allow nil vault credentials. --- .../catalog/catalog_item_form_controller.js | 18 ++++++++++-------- .../miq_ae_class/ae_method_form_controller.js | 4 +--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/controllers/catalog/catalog_item_form_controller.js b/app/assets/javascripts/controllers/catalog/catalog_item_form_controller.js index 52c990d217a..91c29a3b70d 100644 --- a/app/assets/javascripts/controllers/catalog/catalog_item_form_controller.js +++ b/app/assets/javascripts/controllers/catalog/catalog_item_form_controller.js @@ -84,7 +84,7 @@ ManageIQ.angular.app.controller('catalogItemFormController', ['$scope', 'catalog vm.catalogItemModel.provisioning_machine_credential_id = configData.provision.credential_id; vm.catalogItemModel.provisioning_network_credential_id = configData.provision.network_credential_id; vm.catalogItemModel.provisioning_cloud_credential_id = playbookReusableCodeMixin.setIfDefined(configData.provision.cloud_credential_id); - vm.catalogItemModel.provisioning_vault_credential_id = configData.provision.vault_credential_id; + vm.catalogItemModel.provisioning_vault_credential_id = playbookReusableCodeMixin.setIfDefined(configData.provision.vault_credential_id); vm.catalogItemModel.provisioning_execution_ttl = configData.provision.execution_ttl; vm.catalogItemModel.provisioning_inventory = configData.provision.hosts; if (configData.provision.hosts !== 'localhost') { @@ -133,7 +133,7 @@ ManageIQ.angular.app.controller('catalogItemFormController', ['$scope', 'catalog } vm.catalogItemModel.retirement_network_credential_id = configData.retirement.network_credential_id; - vm.catalogItemModel.retirement_vault_credential_id = configData.retirement.vault_credential_id; + vm.catalogItemModel.retirement_vault_credential_id = playbookReusableCodeMixin.setIfDefined(configData.retirement.vault_credential_id); vm.catalogItemModel.retirement_cloud_credential_id = playbookReusableCodeMixin.setIfDefined(configData.retirement.cloud_credential_id); vm.catalogItemModel.retirement_execution_ttl = configData.retirement.execution_ttl; vm.catalogItemModel.retirement_inventory = configData.retirement.hosts; @@ -218,7 +218,6 @@ ManageIQ.angular.app.controller('catalogItemFormController', ['$scope', 'catalog repository_id: configData.provisioning_repository_id, playbook_id: configData.provisioning_playbook_id, credential_id: configData.provisioning_machine_credential_id, - vault_credential_id: configData.provisioning_vault_credential_id, hosts: configData.provisioning_inventory, verbosity: configData.provisioning_verbosity, log_output: configData.provisioning_log_output, @@ -230,6 +229,9 @@ ManageIQ.angular.app.controller('catalogItemFormController', ['$scope', 'catalog catalog_item['config_info']['provision']['execution_ttl'] = configData.provisioning_execution_ttl; } catalog_item['config_info']['provision']['become_enabled'] = configData.provisioning_become_enabled; + if (configData.provisioning_vault_credential_id !== '') { + catalog_item['config_info']['provision']['vault_credential_id'] = configData.provisioning_vault_credential_id; + } if (configData.provisioning_network_credential_id !== '') { catalog_item['config_info']['provision']['network_credential_id'] = configData.provisioning_network_credential_id; } @@ -253,7 +255,6 @@ ManageIQ.angular.app.controller('catalogItemFormController', ['$scope', 'catalog retirement['repository_id'] = configData.retirement_repository_id; retirement['playbook_id'] = configData.retirement_playbook_id; retirement['credential_id'] = configData.retirement_machine_credential_id; - retirement['vault_credential_id'] = configData.retirement_vault_credential_id; } if (vm.catalogItemModel.retirement_playbook_id !== undefined && configData.retirement_playbook_id !== '') { if (vm.catalogItemModel.retirement_execution_ttl !== undefined) @@ -262,6 +263,9 @@ ManageIQ.angular.app.controller('catalogItemFormController', ['$scope', 'catalog retirement['extra_vars'] = formatExtraVars(configData.retirement_variables); catalog_item['config_info']['retirement']['become_enabled'] = configData.retirement_become_enabled; } + if (configData.retirement_vault_credential_id !== '') + catalog_item['config_info']['retirement']['vault_credential_id'] = configData.retirement_vault_credential_id; + if (configData.retirement_network_credential_id !== '') catalog_item['config_info']['retirement']['network_credential_id'] = configData.retirement_network_credential_id; @@ -405,14 +409,12 @@ ManageIQ.angular.app.controller('catalogItemFormController', ['$scope', 'catalog function idWatch(name) { var fieldName = 'vm._' + name; $scope.$watch(fieldName, function(value) { - if (value) { - vm.catalogItemModel[name + '_id'] = value.id; - } + vm.catalogItemModel[name + '_id'] = value ? value.id : ''; playbookReusableCodeMixin.checkFormPristine(vm.catalogItemModel, vm.modelCopy, $scope.angularForm); }); } - // watch for all the drop downs on screen + // watch for all the drop downs on screen 'retirement_remove_resources'.split(' ').forEach(typeWatch); function typeWatch(name) { diff --git a/app/assets/javascripts/controllers/miq_ae_class/ae_method_form_controller.js b/app/assets/javascripts/controllers/miq_ae_class/ae_method_form_controller.js index a2874850c4e..ed9acee2d28 100644 --- a/app/assets/javascripts/controllers/miq_ae_class/ae_method_form_controller.js +++ b/app/assets/javascripts/controllers/miq_ae_class/ae_method_form_controller.js @@ -267,9 +267,7 @@ function aeMethodFormController($http, $scope, aeMethodFormId, currentRegion, mi function idWatch(name) { var fieldName = "vm._" + name; $scope.$watch(fieldName, function(value) { - if (value) { - vm.aeMethodModel[name + '_id'] = value.id; - } + vm.aeMethodModel[name + '_id'] = value ? value.id : ''; playbookReusableCodeMixin.checkFormPristine(vm.aeMethodModel, vm.modelCopy, $scope.angularForm); }); } From 774c9feccb2865fb39a66c10ab957d5943022df8 Mon Sep 17 00:00:00 2001 From: lgalis <lgalis@redhat.com> Date: Fri, 23 Mar 2018 14:22:29 -0400 Subject: [PATCH 9/9] Fix infinite spiner for reset button on Ansible method Edit page. --- .../controllers/miq_ae_class/ae_method_form_controller.js | 1 + 1 file changed, 1 insertion(+) diff --git a/app/assets/javascripts/controllers/miq_ae_class/ae_method_form_controller.js b/app/assets/javascripts/controllers/miq_ae_class/ae_method_form_controller.js index ed9acee2d28..7b731d3d417 100644 --- a/app/assets/javascripts/controllers/miq_ae_class/ae_method_form_controller.js +++ b/app/assets/javascripts/controllers/miq_ae_class/ae_method_form_controller.js @@ -110,6 +110,7 @@ function aeMethodFormController($http, $scope, aeMethodFormId, currentRegion, mi vm.aeMethodModel = angular.copy(vm.modelCopy); playbookReusableCodeMixin.formOptions(vm); playbookReusableCodeMixin.cloudCredentialsList(vm, vm.aeMethodModel.provisioning_cloud_credential_id); + playbookReusableCodeMixin.checkFormDataRetrieval(vm); $scope.angularForm.$setUntouched(true); $scope.angularForm.$setPristine(true); miqService.miqFlash("warn", __("All changes have been reset"));