-
Notifications
You must be signed in to change notification settings - Fork 897
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix EmbeddedAnsible ScmCredential parent class
All EmbeddedAnisble credentials should derive from the `EmbeddedAnsible::AutomationManager::Credential` class.
- Loading branch information
Showing
3 changed files
with
74 additions
and
67 deletions.
There are no files selected for viewing
4 changes: 3 additions & 1 deletion
4
app/models/manageiq/providers/embedded_ansible/automation_manager/scm_credential.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
66 changes: 0 additions & 66 deletions
66
app/models/manageiq/providers/embedded_automation_manager/scm_credential.rb
This file was deleted.
Oops, something went wrong.
71 changes: 71 additions & 0 deletions
71
app/models/manageiq/providers/embedded_automation_manager/scm_credential_mixin.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |