-
Notifications
You must be signed in to change notification settings - Fork 897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support EmbeddedAnsible SCM credentials #19027
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,8 @@ class ManageIQ::Providers::EmbeddedAnsible::AutomationManager::ConfigurationScri | |
default_value_for :scm_type, "git" | ||
default_value_for :scm_branch, "master" | ||
|
||
belongs_to :git_repository, :dependent => :destroy | ||
belongs_to :git_repository, :autosave => true, :dependent => :destroy | ||
before_validation :sync_git_repository | ||
|
||
include ManageIQ::Providers::EmbeddedAnsible::CrudCommon | ||
|
||
|
@@ -46,12 +47,35 @@ def raw_delete_in_provider | |
end | ||
|
||
def git_repository | ||
super || begin | ||
transaction do | ||
update!(:git_repository => GitRepository.create!(:url => scm_url)) | ||
(super || (ensure_git_repository && super)).tap { |r| sync_git_repository(r) } | ||
carbonin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end | ||
|
||
private def ensure_git_repository | ||
transaction do | ||
repo = GitRepository.create!(attrs_for_sync_git_repository) | ||
if new_record? | ||
self.git_repository_id = repo.id | ||
elsif !update_columns(:git_repository_id => repo.id) # rubocop:disable Rails/SkipsModelValidations | ||
raise ActiveRecord::RecordInvalid, "git_repository_id could not be set" | ||
end | ||
super | ||
end | ||
true | ||
end | ||
|
||
private def sync_git_repository(git_repository = nil) | ||
return unless name_changed? || scm_url_changed? || authentication_id_changed? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI I really tried to DRY this up with respect to the |
||
|
||
git_repository ||= self.git_repository | ||
git_repository.attributes = attrs_for_sync_git_repository | ||
end | ||
|
||
private def attrs_for_sync_git_repository | ||
{ | ||
:name => name, | ||
:url => scm_url, | ||
:authentication_id => authentication_id, | ||
:verify_ssl => OpenSSL::SSL::VERIFY_NONE | ||
} | ||
end | ||
|
||
def sync | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,7 @@ | |
|
||
factory :embedded_ansible_configuration_script_source, | ||
:parent => :configuration_script_source, | ||
:class => "ManageIQ::Providers::EmbeddedAnsible::AutomationManager::ConfigurationScriptSource" | ||
:class => "ManageIQ::Providers::EmbeddedAnsible::AutomationManager::ConfigurationScriptSource" do | ||
scm_url { "https://example.com/foo.git" } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PR effectively makes scm_url a required attribute for a ManageIQ::Providers::EmbeddedAnsible::AutomationManager::ConfigurationScriptSource, which I think is ok. Without this line you will consistently get a validation error on a GitRepository#url format. |
||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just caught this re: #19027 (comment)