Skip to content

Commit

Permalink
Fix EmbeddedAnsible ScmCredential parent class
Browse files Browse the repository at this point in the history
All EmbeddedAnisble credentials should derive from the
`EmbeddedAnsible::AutomationManager::Credential` class.
  • Loading branch information
agrare committed Jun 23, 2023
1 parent a928eaa commit 8b8c1b6
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 67 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
class ManageIQ::Providers::EmbeddedAnsible::AutomationManager::ScmCredential < ManageIQ::Providers::EmbeddedAutomationManager::ScmCredential
class ManageIQ::Providers::EmbeddedAnsible::AutomationManager::ScmCredential < ManageIQ::Providers::EmbeddedAnsible::AutomationManager::Credential
include ManageIQ::Providers::EmbeddedAutomationManager::ScmCredentialMixin

FRIENDLY_NAME = "Embedded Ansible Credential".freeze
end

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
module ManageIQ::Providers::EmbeddedAutomationManager::ScmCredentialMixin
extend ActiveSupport::Concern

included do
const_set("COMMON_ATTRIBUTES",
[
{
:component => 'text-field',
:label => N_('Username'),
:helperText => N_('Username for this credential'),
:name => 'userid',
:id => 'userid',
},
{
:component => 'password-field',
:label => N_('Password'),
:helperText => N_('Password for this credential'),
:name => 'password',
:id => 'password',
:type => 'password',
},
].freeze
)

const_set("EXTRA_ATTRIBUTES",
[
{
:component => 'password-field',
:label => N_('Private key'),
:helperText => N_('RSA or DSA private key to be used instead of password'),
:componentClass => 'textarea',
:name => 'ssh_key_data',
:id => 'ssh_key_data',
:type => 'password',
},
{
:component => 'password-field',
:label => N_('Private key passphrase'),
:helperText => N_('Passphrase to unlock SSH private key if encrypted'),
:name => 'ssh_key_unlock',
:id => 'ssh_key_unlock',
:maxLength => 1024,
:type => 'password',
},
].freeze
)

const_set("API_ATTRIBUTES", (const_get("COMMON_ATTRIBUTES") + const_get("EXTRA_ATTRIBUTES")).freeze)
const_set("API_OPTIONS", {:label => N_('Scm'), :type => 'scm', :attributes => const_get("API_ATTRIBUTES")}.freeze)

alias ssh_key_data auth_key
alias ssh_key_unlock auth_key_password

before_validation :ensure_newline_for_ssh_key
end

class_methods do
def display_name(number = 1)
n_('Credential (SCM)', 'Credentials (SCM)', number)
end

def params_to_attributes(params)
attrs = super.dup

attrs[:auth_key] = attrs.delete(:ssh_key_data) if attrs.key?(:ssh_key_data)
attrs[:auth_key_password] = attrs.delete(:ssh_key_unlock) if attrs.key?(:ssh_key_unlock)

attrs
end
end
end

0 comments on commit 8b8c1b6

Please sign in to comment.