Skip to content

Commit

Permalink
Populate extra attributes of Ansible credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
jameswnl committed Mar 7, 2017
1 parent 6d90d8d commit 5557603
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
class ManageIQ::Providers::AnsibleTower::AutomationManager::Credential < ManageIQ::Providers::ExternalAutomationManager::Authentication
COMMON_ATTRIBUTES = {}.freeze
EXTRA_ATTRIBUTES = {}.freeze
API_ATTRIBUTES = COMMON_ATTRIBUTES.merge(EXTRA_ATTRIBUTES).freeze
end
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,6 @@ def credentials
inventory_object = persister.credentials.find_or_build(credential.id.to_s)
inventory_object.name = credential.name
inventory_object.userid = credential.username
# credential.description
# credential.host
# credential.password
# credential.security_token
# credential.project
# credential.domain
# credential.ssh_key_data
# credential.ssh_key_unlock
# credential.organization
# credential.become_method # '', 'sudo', 'su', 'pbrun', 'pfexec'
# credential.become_username
# credential.become_password
# credential.vault_password
# credential.subscription
# credential.tenant
# credential.secret
# credential.client
# credential.authorize
# credential.authorize_password
provider_module = ManageIQ::Providers::Inflector.provider_module(collector.manager.class).name
inventory_object.type = case credential.kind
when 'net' then "#{provider_module}::AutomationManager::NetworkCredential"
Expand All @@ -99,6 +80,9 @@ def credentials
when 'openstack' then "#{provider_module}::AutomationManager::OpenstackCredential"
else "#{provider_module}::AutomationManager::Credential"
end
inventory_object.options = inventory_object.type.constantize::EXTRA_ATTRIBUTES.keys.each_with_object({}) do |k, h|
h[k] = credential.public_send(k)
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
class ManageIQ::Providers::EmbeddedAnsible::AutomationManager::Credential <
ManageIQ::Providers::EmbeddedAutomationManager::Authentication
COMMON_ATTRIBUTES = {}.freeze
EXTRA_ATTRIBUTES = {}.freeze
API_ATTRIBUTES = COMMON_ATTRIBUTES.merge(EXTRA_ATTRIBUTES).freeze
end
2 changes: 1 addition & 1 deletion app/models/manager_refresh/inventory/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def has_authentications(options = {})
has_inventory({
:model_class => ::Authentication,
:manager_ref => [:manager_ref],
:inventory_object_attributes => %i(name userid type),
:inventory_object_attributes => %i(name userid type options),
}.merge(options))
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,27 @@ def assert_credentials
:name => "Demo Credential",
:userid => "admin",
)
expect(machine_credential.options.keys).to match_array(machine_credential.class::EXTRA_ATTRIBUTES.keys)
expect(machine_credential.options[:become_method]).to eq('su')
expect(machine_credential.options[:become_username]).to eq('root')

network_credential = expected_configuration_script.authentications.find_by(
:type => ManageIQ::Providers::AnsibleTower::AutomationManager::NetworkCredential
)
expect(network_credential).to have_attributes(
:name => "Demo Creds 2",
:userid => "awdd",
)
expect(network_credential.options.keys).to match_array(network_credential.class::EXTRA_ATTRIBUTES.keys)

cloud_credential = expected_configuration_script.authentications.find_by(
:type => ManageIQ::Providers::AnsibleTower::AutomationManager::VmwareCredential
)
expect(cloud_credential).to have_attributes(
:name => "dev-vc60",
:userid => "MiqAnsibleUser@vsphere.local",
)
expect(cloud_credential.options.keys).to match_array(cloud_credential.class::EXTRA_ATTRIBUTES.keys)
end

def assert_playbooks
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5557603

Please sign in to comment.