From f45eea58cd46541c920557197dff1cea513886d4 Mon Sep 17 00:00:00 2001 From: Jillian Tullo Date: Thu, 16 Feb 2017 13:35:27 -0500 Subject: [PATCH 1/5] add ansible cloud types to authentication options adding sort --- .../api/authentications_controller.rb | 10 ++++++++++ .../automation_manager/cloud_credential.rb | 6 ++++++ spec/requests/api/arbitration_rule_spec.rb | 18 +++--------------- spec/requests/api/authentications_spec.rb | 11 +++++++++++ spec/support/api_helper.rb | 17 +++++++++++++++++ 5 files changed, 47 insertions(+), 15 deletions(-) diff --git a/app/controllers/api/authentications_controller.rb b/app/controllers/api/authentications_controller.rb index 552f8915d56..8f1300f7808 100644 --- a/app/controllers/api/authentications_controller.rb +++ b/app/controllers/api/authentications_controller.rb @@ -9,10 +9,20 @@ def delete_resource(type, id, _data = {}) action_result(false, err.to_s) end + def options + render_options(:authentications, build_additional_fields) + end + private def authentication_ident(auth) "Authentication id:#{auth.id} name: '#{auth.name}'" end + + def build_additional_fields + { + :cloud_types => ManageIQ::Providers::AnsibleTower::AutomationManager::CloudCredential.credential_types + } + end end end diff --git a/app/models/manageiq/providers/ansible_tower/automation_manager/cloud_credential.rb b/app/models/manageiq/providers/ansible_tower/automation_manager/cloud_credential.rb index 23850b73957..97e70b320ca 100644 --- a/app/models/manageiq/providers/ansible_tower/automation_manager/cloud_credential.rb +++ b/app/models/manageiq/providers/ansible_tower/automation_manager/cloud_credential.rb @@ -1,2 +1,8 @@ class ManageIQ::Providers::AnsibleTower::AutomationManager::CloudCredential < ManageIQ::Providers::AnsibleTower::AutomationManager::Credential + def self.credential_types + subclasses.sort_by(&:name).each_with_object({}) do |subclass, credential_types| + provider_name = subclass.name.demodulize.split('Credential').first + credential_types[provider_name] = subclass.name + end + end end diff --git a/spec/requests/api/arbitration_rule_spec.rb b/spec/requests/api/arbitration_rule_spec.rb index a9738541e00..67aac77e9b0 100644 --- a/spec/requests/api/arbitration_rule_spec.rb +++ b/spec/requests/api/arbitration_rule_spec.rb @@ -183,22 +183,10 @@ it 'returns arbitration rule field_values' do api_basic_authorize - attributes = (ArbitrationRule.attribute_names - ArbitrationRule.virtual_attribute_names).sort.as_json - reflections = (ArbitrationRule.reflections.keys | ArbitrationRule.virtual_reflections.keys.collect(&:to_s)).sort - subcollections = Array(Api::ApiConfig.collections[:arbitration_rules].subcollections).collect(&:to_s).sort - expected = { - 'attributes' => attributes, - 'virtual_attributes' => ArbitrationRule.virtual_attribute_names.sort.as_json, - 'relationships' => reflections, - 'subcollections' => subcollections, - 'data' => { - 'field_values' => ArbitrationRule.field_values - } - } - run_options(arbitration_rules_url) - expect(response.parsed_body).to eq(expected) - expect(response.headers['Access-Control-Allow-Methods']).to include('OPTIONS') + + additional_options = { 'field_values' => ArbitrationRule.field_values } + expect_options_results(:arbitration_rules, additional_options) end end end diff --git a/spec/requests/api/authentications_spec.rb b/spec/requests/api/authentications_spec.rb index 934895fb9e4..4d2a52cce47 100644 --- a/spec/requests/api/authentications_spec.rb +++ b/spec/requests/api/authentications_spec.rb @@ -165,4 +165,15 @@ expect(response).to have_http_status(:forbidden) end end + + describe 'OPTIONS /api/authentications' do + it 'returns expected and additional attributes' do + api_basic_authorize + + run_options(authentications_url) + + additional_options = { 'cloud_types' => ManageIQ::Providers::AnsibleTower::AutomationManager::CloudCredential.credential_types} + expect_options_results(:authentications, additional_options) + end + end end diff --git a/spec/support/api_helper.rb b/spec/support/api_helper.rb index 4082fa19401..09fd14ede60 100644 --- a/spec/support/api_helper.rb +++ b/spec/support/api_helper.rb @@ -266,6 +266,23 @@ def expect_tagging_result(tag_results) ) end end + + def expect_options_results(type, data = {}) + klass = Api::ApiConfig.collections[type].klass.constantize + attributes = (klass.attribute_names - klass.virtual_attribute_names).sort.as_json + attributes.delete('password') + reflections = (klass.reflections.keys | klass.virtual_reflections.keys.collect(&:to_s)).sort + subcollections = Array(Api::ApiConfig.collections[type].subcollections).collect(&:to_s).sort + expected = { + 'attributes' => attributes, + 'virtual_attributes' => klass.virtual_attribute_names.sort.as_json, + 'relationships' => reflections, + 'subcollections' => subcollections, + 'data' => data + } + expect(response.parsed_body).to eq(expected) + expect(response.headers['Access-Control-Allow-Methods']).to include('OPTIONS') + end end end end From 09464929ef0891b5ec7e4b9a9b0e72b51fa9b968 Mon Sep 17 00:00:00 2001 From: Jillian Tullo Date: Tue, 28 Feb 2017 14:03:04 -0500 Subject: [PATCH 2/5] utilize new API options stay consistent with label --- app/controllers/api/authentications_controller.rb | 6 +++--- .../automation_manager/cloud_credential.rb | 6 ------ .../shared/automation_manager/amazon_credential.rb | 6 ++++++ .../shared/automation_manager/machine_credential.rb | 6 ++++++ .../shared/automation_manager/scm_credential.rb | 6 ++++++ .../shared/automation_manager/vmware_credential.rb | 6 ++++++ spec/requests/api/authentications_spec.rb | 10 +++++++++- spec/support/api_helper.rb | 4 ++-- 8 files changed, 38 insertions(+), 12 deletions(-) diff --git a/app/controllers/api/authentications_controller.rb b/app/controllers/api/authentications_controller.rb index 8f1300f7808..7916d5eff1e 100644 --- a/app/controllers/api/authentications_controller.rb +++ b/app/controllers/api/authentications_controller.rb @@ -20,9 +20,9 @@ def authentication_ident(auth) end def build_additional_fields - { - :cloud_types => ManageIQ::Providers::AnsibleTower::AutomationManager::CloudCredential.credential_types - } + ::Authentication.descendants.each_with_object({}) do |klass, fields| + fields[klass.name] = klass::API_OPTIONS if defined? klass::API_OPTIONS + end end end end diff --git a/app/models/manageiq/providers/ansible_tower/automation_manager/cloud_credential.rb b/app/models/manageiq/providers/ansible_tower/automation_manager/cloud_credential.rb index 97e70b320ca..23850b73957 100644 --- a/app/models/manageiq/providers/ansible_tower/automation_manager/cloud_credential.rb +++ b/app/models/manageiq/providers/ansible_tower/automation_manager/cloud_credential.rb @@ -1,8 +1,2 @@ class ManageIQ::Providers::AnsibleTower::AutomationManager::CloudCredential < ManageIQ::Providers::AnsibleTower::AutomationManager::Credential - def self.credential_types - subclasses.sort_by(&:name).each_with_object({}) do |subclass, credential_types| - provider_name = subclass.name.demodulize.split('Credential').first - credential_types[provider_name] = subclass.name - end - end end diff --git a/app/models/manageiq/providers/ansible_tower/shared/automation_manager/amazon_credential.rb b/app/models/manageiq/providers/ansible_tower/shared/automation_manager/amazon_credential.rb index 66bf71107e7..34a1624e2ea 100644 --- a/app/models/manageiq/providers/ansible_tower/shared/automation_manager/amazon_credential.rb +++ b/app/models/manageiq/providers/ansible_tower/shared/automation_manager/amazon_credential.rb @@ -23,4 +23,10 @@ module ManageIQ::Providers::AnsibleTower::Shared::AutomationManager::AmazonCrede }.freeze API_ATTRIBUTES = COMMON_ATTRIBUTES.merge(EXTRA_ATTRIBUTES).freeze + + API_OPTIONS = { + :type => 'cloud', + :label => 'Amazon', + :attributes => API_ATTRIBUTES + }.freeze end diff --git a/app/models/manageiq/providers/ansible_tower/shared/automation_manager/machine_credential.rb b/app/models/manageiq/providers/ansible_tower/shared/automation_manager/machine_credential.rb index 204d079fe68..ebedcf32660 100644 --- a/app/models/manageiq/providers/ansible_tower/shared/automation_manager/machine_credential.rb +++ b/app/models/manageiq/providers/ansible_tower/shared/automation_manager/machine_credential.rb @@ -52,4 +52,10 @@ module ManageIQ::Providers::AnsibleTower::Shared::AutomationManager::MachineCred }.freeze API_ATTRIBUTES = COMMON_ATTRIBUTES.merge(EXTRA_ATTRIBUTES).freeze + + API_OPTIONS = { + :label => 'Machine', + :type => 'machine', + :attributes => API_ATTRIBUTES + }.freeze end diff --git a/app/models/manageiq/providers/ansible_tower/shared/automation_manager/scm_credential.rb b/app/models/manageiq/providers/ansible_tower/shared/automation_manager/scm_credential.rb index 0dc17eb3084..d517cc7d9dd 100644 --- a/app/models/manageiq/providers/ansible_tower/shared/automation_manager/scm_credential.rb +++ b/app/models/manageiq/providers/ansible_tower/shared/automation_manager/scm_credential.rb @@ -28,4 +28,10 @@ module ManageIQ::Providers::AnsibleTower::Shared::AutomationManager::ScmCredenti }.freeze API_ATTRIBUTES = COMMON_ATTRIBUTES.merge(EXTRA_ATTRIBUTES).freeze + + API_OPTIONS = { + :label => 'Scm', + :type => 'scm', + :attributes => API_ATTRIBUTES + }.freeze end diff --git a/app/models/manageiq/providers/ansible_tower/shared/automation_manager/vmware_credential.rb b/app/models/manageiq/providers/ansible_tower/shared/automation_manager/vmware_credential.rb index d601f0d3bec..43bbab47774 100644 --- a/app/models/manageiq/providers/ansible_tower/shared/automation_manager/vmware_credential.rb +++ b/app/models/manageiq/providers/ansible_tower/shared/automation_manager/vmware_credential.rb @@ -23,4 +23,10 @@ module ManageIQ::Providers::AnsibleTower::Shared::AutomationManager::VmwareCrede }.freeze API_ATTRIBUTES = COMMON_ATTRIBUTES.merge(EXTRA_ATTRIBUTES).freeze + + API_OPTIONS = { + :label => 'VMware', + :type => 'cloud', + :attributes => API_ATTRIBUTES + }.freeze end diff --git a/spec/requests/api/authentications_spec.rb b/spec/requests/api/authentications_spec.rb index 4d2a52cce47..5ad536a020c 100644 --- a/spec/requests/api/authentications_spec.rb +++ b/spec/requests/api/authentications_spec.rb @@ -172,7 +172,15 @@ run_options(authentications_url) - additional_options = { 'cloud_types' => ManageIQ::Providers::AnsibleTower::AutomationManager::CloudCredential.credential_types} + additional_options = Authentication.descendants.each_with_object({}) do |klass, fields| + next unless defined? klass::API_OPTIONS + klass::API_OPTIONS.tap do |options| + options[:attributes].each do |_k, v| + v[:type] = v[:type].to_s if v[:type] + end + fields[klass.name] = options + end + end.deep_stringify_keys expect_options_results(:authentications, additional_options) end end diff --git a/spec/support/api_helper.rb b/spec/support/api_helper.rb index 09fd14ede60..ae1a90dd3bc 100644 --- a/spec/support/api_helper.rb +++ b/spec/support/api_helper.rb @@ -269,12 +269,12 @@ def expect_tagging_result(tag_results) def expect_options_results(type, data = {}) klass = Api::ApiConfig.collections[type].klass.constantize - attributes = (klass.attribute_names - klass.virtual_attribute_names).sort.as_json + attributes = (klass.attribute_names - klass.virtual_attribute_names).sort attributes.delete('password') reflections = (klass.reflections.keys | klass.virtual_reflections.keys.collect(&:to_s)).sort subcollections = Array(Api::ApiConfig.collections[type].subcollections).collect(&:to_s).sort expected = { - 'attributes' => attributes, + 'attributes' => attributes.as_json, 'virtual_attributes' => klass.virtual_attribute_names.sort.as_json, 'relationships' => reflections, 'subcollections' => subcollections, From 875fcde83f4adcdb463107b3595a5f7767d6b4ba Mon Sep 17 00:00:00 2001 From: Jillian Tullo Date: Fri, 10 Mar 2017 08:39:48 -0500 Subject: [PATCH 3/5] select only unencrypted update to include credential_types translations --- app/controllers/api/authentications_controller.rb | 2 +- .../automation_manager/amazon_credential.rb | 2 +- .../automation_manager/machine_credential.rb | 2 +- .../shared/automation_manager/scm_credential.rb | 2 +- .../automation_manager/vmware_credential.rb | 2 +- spec/requests/api/authentications_spec.rb | 2 +- spec/support/api_helper.rb | 15 +++++++++++---- 7 files changed, 17 insertions(+), 10 deletions(-) diff --git a/app/controllers/api/authentications_controller.rb b/app/controllers/api/authentications_controller.rb index 7916d5eff1e..0b4080e8993 100644 --- a/app/controllers/api/authentications_controller.rb +++ b/app/controllers/api/authentications_controller.rb @@ -10,7 +10,7 @@ def delete_resource(type, id, _data = {}) end def options - render_options(:authentications, build_additional_fields) + render_options(:authentications, :credential_types => build_additional_fields) end private diff --git a/app/models/manageiq/providers/ansible_tower/shared/automation_manager/amazon_credential.rb b/app/models/manageiq/providers/ansible_tower/shared/automation_manager/amazon_credential.rb index 34a1624e2ea..b5ab8fbda5f 100644 --- a/app/models/manageiq/providers/ansible_tower/shared/automation_manager/amazon_credential.rb +++ b/app/models/manageiq/providers/ansible_tower/shared/automation_manager/amazon_credential.rb @@ -26,7 +26,7 @@ module ManageIQ::Providers::AnsibleTower::Shared::AutomationManager::AmazonCrede API_OPTIONS = { :type => 'cloud', - :label => 'Amazon', + :label => N_('Amazon'), :attributes => API_ATTRIBUTES }.freeze end diff --git a/app/models/manageiq/providers/ansible_tower/shared/automation_manager/machine_credential.rb b/app/models/manageiq/providers/ansible_tower/shared/automation_manager/machine_credential.rb index ebedcf32660..bae4a799b53 100644 --- a/app/models/manageiq/providers/ansible_tower/shared/automation_manager/machine_credential.rb +++ b/app/models/manageiq/providers/ansible_tower/shared/automation_manager/machine_credential.rb @@ -54,7 +54,7 @@ module ManageIQ::Providers::AnsibleTower::Shared::AutomationManager::MachineCred API_ATTRIBUTES = COMMON_ATTRIBUTES.merge(EXTRA_ATTRIBUTES).freeze API_OPTIONS = { - :label => 'Machine', + :label => N_('Machine'), :type => 'machine', :attributes => API_ATTRIBUTES }.freeze diff --git a/app/models/manageiq/providers/ansible_tower/shared/automation_manager/scm_credential.rb b/app/models/manageiq/providers/ansible_tower/shared/automation_manager/scm_credential.rb index d517cc7d9dd..55b4f0e9a89 100644 --- a/app/models/manageiq/providers/ansible_tower/shared/automation_manager/scm_credential.rb +++ b/app/models/manageiq/providers/ansible_tower/shared/automation_manager/scm_credential.rb @@ -30,7 +30,7 @@ module ManageIQ::Providers::AnsibleTower::Shared::AutomationManager::ScmCredenti API_ATTRIBUTES = COMMON_ATTRIBUTES.merge(EXTRA_ATTRIBUTES).freeze API_OPTIONS = { - :label => 'Scm', + :label => N_('Scm'), :type => 'scm', :attributes => API_ATTRIBUTES }.freeze diff --git a/app/models/manageiq/providers/ansible_tower/shared/automation_manager/vmware_credential.rb b/app/models/manageiq/providers/ansible_tower/shared/automation_manager/vmware_credential.rb index 43bbab47774..4f61f4f3bcc 100644 --- a/app/models/manageiq/providers/ansible_tower/shared/automation_manager/vmware_credential.rb +++ b/app/models/manageiq/providers/ansible_tower/shared/automation_manager/vmware_credential.rb @@ -25,7 +25,7 @@ module ManageIQ::Providers::AnsibleTower::Shared::AutomationManager::VmwareCrede API_ATTRIBUTES = COMMON_ATTRIBUTES.merge(EXTRA_ATTRIBUTES).freeze API_OPTIONS = { - :label => 'VMware', + :label => N_('VMware'), :type => 'cloud', :attributes => API_ATTRIBUTES }.freeze diff --git a/spec/requests/api/authentications_spec.rb b/spec/requests/api/authentications_spec.rb index 5ad536a020c..d4541c13955 100644 --- a/spec/requests/api/authentications_spec.rb +++ b/spec/requests/api/authentications_spec.rb @@ -181,7 +181,7 @@ fields[klass.name] = options end end.deep_stringify_keys - expect_options_results(:authentications, additional_options) + expect_options_results(:authentications, 'credential_types' => additional_options) end end end diff --git a/spec/support/api_helper.rb b/spec/support/api_helper.rb index ae1a90dd3bc..0c96c87cec0 100644 --- a/spec/support/api_helper.rb +++ b/spec/support/api_helper.rb @@ -269,13 +269,12 @@ def expect_tagging_result(tag_results) def expect_options_results(type, data = {}) klass = Api::ApiConfig.collections[type].klass.constantize - attributes = (klass.attribute_names - klass.virtual_attribute_names).sort - attributes.delete('password') + attributes = select_attributes(klass.attribute_names - klass.virtual_attribute_names) reflections = (klass.reflections.keys | klass.virtual_reflections.keys.collect(&:to_s)).sort subcollections = Array(Api::ApiConfig.collections[type].subcollections).collect(&:to_s).sort expected = { - 'attributes' => attributes.as_json, - 'virtual_attributes' => klass.virtual_attribute_names.sort.as_json, + 'attributes' => attributes, + 'virtual_attributes' => select_attributes(klass.virtual_attribute_names), 'relationships' => reflections, 'subcollections' => subcollections, 'data' => data @@ -283,6 +282,14 @@ def expect_options_results(type, data = {}) expect(response.parsed_body).to eq(expected) expect(response.headers['Access-Control-Allow-Methods']).to include('OPTIONS') end + + def select_attributes(attrlist) + attrlist.sort.select { |attr| !encrypted_attribute?(attr) } + end + + def encrypted_attribute?(attr) + Api::Environment.normalized_attributes[:encrypted].key?(attr.to_s) || attr.to_s.include?('password') + end end end end From c44afb3a5c404744c9884df32cfde4080be40aed Mon Sep 17 00:00:00 2001 From: Jillian Tullo Date: Tue, 14 Mar 2017 14:46:21 -0400 Subject: [PATCH 4/5] update format to separate embedded and tower --- .../api/authentications_controller.rb | 15 ++++++- spec/requests/api/authentications_spec.rb | 41 ++++++++++++++----- 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/app/controllers/api/authentications_controller.rb b/app/controllers/api/authentications_controller.rb index 0b4080e8993..ba9fc9bc331 100644 --- a/app/controllers/api/authentications_controller.rb +++ b/app/controllers/api/authentications_controller.rb @@ -20,7 +20,20 @@ def authentication_ident(auth) end def build_additional_fields - ::Authentication.descendants.each_with_object({}) do |klass, fields| + { + :ansible_tower_credentials => build_ansible_tower_creds, + :embedded_ansible_credentials => build_embedded_ansible_creds + } + end + + def build_ansible_tower_creds + ManageIQ::Providers::AnsibleTower::AutomationManager::Credential.descendants.each_with_object({}) do |klass, fields| + fields[klass.name] = klass::API_OPTIONS if defined? klass::API_OPTIONS + end + end + + def build_embedded_ansible_creds + ManageIQ::Providers::EmbeddedAnsible::AutomationManager::Credential.descendants.each_with_object({}) do |klass, fields| fields[klass.name] = klass::API_OPTIONS if defined? klass::API_OPTIONS end end diff --git a/spec/requests/api/authentications_spec.rb b/spec/requests/api/authentications_spec.rb index d4541c13955..c9485e3ceb1 100644 --- a/spec/requests/api/authentications_spec.rb +++ b/spec/requests/api/authentications_spec.rb @@ -172,16 +172,37 @@ run_options(authentications_url) - additional_options = Authentication.descendants.each_with_object({}) do |klass, fields| - next unless defined? klass::API_OPTIONS - klass::API_OPTIONS.tap do |options| - options[:attributes].each do |_k, v| - v[:type] = v[:type].to_s if v[:type] - end - fields[klass.name] = options - end - end.deep_stringify_keys - expect_options_results(:authentications, 'credential_types' => additional_options) + additional_options = { + 'credential_types' => { + 'ansible_tower_credentials' => build_ansible_tower_creds, + 'embedded_ansible_credentials' => build_embedded_ansible_creds + } + } + expect_options_results(:authentications, additional_options) end end + + def build_ansible_tower_creds + ManageIQ::Providers::AnsibleTower::AutomationManager::Credential.descendants.each_with_object({}) do |klass, fields| + next unless defined? klass::API_OPTIONS + klass::API_OPTIONS.tap do |options| + options[:attributes].each do |_k, v| + v[:type] = v[:type].to_s if v[:type] + end + fields[klass.name] = options + end + end.deep_stringify_keys + end + + def build_embedded_ansible_creds + ManageIQ::Providers::EmbeddedAnsible::AutomationManager::Credential.descendants.each_with_object({}) do |klass, fields| + next unless defined? klass::API_OPTIONS + klass::API_OPTIONS.tap do |options| + options[:attributes].each do |_k, v| + v[:type] = v[:type].to_s if v[:type] + end + fields[klass.name] = options + end + end.deep_stringify_keys + end end From 2a74dc17acf11ca7878c33b58155993483b9a50d Mon Sep 17 00:00:00 2001 From: Jillian Tullo Date: Thu, 16 Mar 2017 08:23:22 -0400 Subject: [PATCH 5/5] move creation of options to the model --- .../api/authentications_controller.rb | 17 ++-------- app/models/authentication.rb | 13 ++++++++ spec/requests/api/authentications_spec.rb | 33 ++++++------------- 3 files changed, 25 insertions(+), 38 deletions(-) diff --git a/app/controllers/api/authentications_controller.rb b/app/controllers/api/authentications_controller.rb index ba9fc9bc331..2be1ba026bb 100644 --- a/app/controllers/api/authentications_controller.rb +++ b/app/controllers/api/authentications_controller.rb @@ -10,7 +10,7 @@ def delete_resource(type, id, _data = {}) end def options - render_options(:authentications, :credential_types => build_additional_fields) + render_options(:authentications, build_additional_fields) end private @@ -21,21 +21,8 @@ def authentication_ident(auth) def build_additional_fields { - :ansible_tower_credentials => build_ansible_tower_creds, - :embedded_ansible_credentials => build_embedded_ansible_creds + :credential_types => ::Authentication.build_credential_options } end - - def build_ansible_tower_creds - ManageIQ::Providers::AnsibleTower::AutomationManager::Credential.descendants.each_with_object({}) do |klass, fields| - fields[klass.name] = klass::API_OPTIONS if defined? klass::API_OPTIONS - end - end - - def build_embedded_ansible_creds - ManageIQ::Providers::EmbeddedAnsible::AutomationManager::Credential.descendants.each_with_object({}) do |klass, fields| - fields[klass.name] = klass::API_OPTIONS if defined? klass::API_OPTIONS - end - end end end diff --git a/app/models/authentication.rb b/app/models/authentication.rb index 7f812635f86..096f40a45b5 100644 --- a/app/models/authentication.rb +++ b/app/models/authentication.rb @@ -50,6 +50,11 @@ def self.new(*args, &block) RETRYABLE_STATUS = %w(error unreachable).freeze + CREDENTIAL_TYPES = { + :external_credential_types => 'ManageIQ::Providers::ExternalAutomationManager::Authentication', + :embedded_ansible_credential_types => 'ManageIQ::Providers::EmbeddedAutomationManager::Authentication' + }.freeze + # FIXME: To address problem with url resolution when displayed as a quadicon, # but it's not *really* the db_name. Might be more proper to override `to_partial_path` def self.db_name @@ -105,6 +110,14 @@ def assign_values(options) self.attributes = options end + def self.build_credential_options + CREDENTIAL_TYPES.each_with_object({}) do |(k, v), hash| + hash[k] = v.constantize.descendants.each_with_object({}) do |klass, fields| + fields[klass.name] = klass::API_OPTIONS if defined? klass::API_OPTIONS + end + end + end + private def set_credentials_changed_on diff --git a/spec/requests/api/authentications_spec.rb b/spec/requests/api/authentications_spec.rb index c9485e3ceb1..e0afcc4cfd9 100644 --- a/spec/requests/api/authentications_spec.rb +++ b/spec/requests/api/authentications_spec.rb @@ -173,35 +173,22 @@ run_options(authentications_url) additional_options = { - 'credential_types' => { - 'ansible_tower_credentials' => build_ansible_tower_creds, - 'embedded_ansible_credentials' => build_embedded_ansible_creds - } + 'credential_types' => build_credential_options } expect_options_results(:authentications, additional_options) end end - def build_ansible_tower_creds - ManageIQ::Providers::AnsibleTower::AutomationManager::Credential.descendants.each_with_object({}) do |klass, fields| - next unless defined? klass::API_OPTIONS - klass::API_OPTIONS.tap do |options| - options[:attributes].each do |_k, v| - v[:type] = v[:type].to_s if v[:type] + def build_credential_options + Authentication::CREDENTIAL_TYPES.each_with_object({}) do |(description, klass), hash| + hash[description] = klass.constantize.descendants.each_with_object({}) do |subklass, fields| + next unless defined? subklass::API_OPTIONS + subklass::API_OPTIONS.tap do |options| + options[:attributes].each do |_k, val| + val[:type] = val[:type].to_s if val[:type] + end + fields[subklass.name] = options end - fields[klass.name] = options - end - end.deep_stringify_keys - end - - def build_embedded_ansible_creds - ManageIQ::Providers::EmbeddedAnsible::AutomationManager::Credential.descendants.each_with_object({}) do |klass, fields| - next unless defined? klass::API_OPTIONS - klass::API_OPTIONS.tap do |options| - options[:attributes].each do |_k, v| - v[:type] = v[:type].to_s if v[:type] - end - fields[klass.name] = options end end.deep_stringify_keys end