-
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
Support EmbeddedAnsible SCM credentials #19027
Conversation
Note that this PR doesn't work as is, since authentication_id is coming in during create!, and it's failing since the git_repository doesn't exist yet. |
My original plan was to just have the caller set the git_repository.authentication directly, but then never save it, to make it "temporary", however if anything subsequently calls a git_repository method, then the authentication is lost and that feels wrong. |
Where and how will we handle if the SCM credential changes for a configuration script source? |
...models/manageiq/providers/embedded_ansible/automation_manager/configuration_script_source.rb
Outdated
Show resolved
Hide resolved
@@ -8,7 +8,14 @@ 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 |
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)
5c791c4
to
0fa2244
Compare
@@ -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 comment
The 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.
This PR is ready-to-go codewise, but I want to add some tests around the configuration_script_source -> git_repository interactions. I did a lot of testing manually in rails console, and want to reflect those in real specs. |
0fa2244
to
bee5eb0
Compare
Ok specs added. I had to wrap the existing spec in a context because it always created a rugged repo, but these new tests didn't need it. So, view this with whitespace diff hidden. @carbonin Please review. |
e16af35
to
5cd1fb3
Compare
...s/manageiq/providers/embedded_ansible/automation_manager/configuration_script_source_spec.rb
Outdated
Show resolved
Hide resolved
...models/manageiq/providers/embedded_ansible/automation_manager/configuration_script_source.rb
Show resolved
Hide resolved
end | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
FYI I really tried to DRY this up with respect to the attrs_for_sync_git_repository
, by using something like changed.include_any?
, but because one side has :url
and the other side has :scm_url
it got really ugly, so I'd prefer to just leave it this way for now.
5cd1fb3
to
1043290
Compare
1043290
to
0deca62
Compare
@carbonin This is ready to go. |
Some comments on commit Fryguy@0deca62 spec/models/manageiq/providers/embedded_ansible/automation_manager/configuration_script_source_spec.rb
|
Checked commit Fryguy@0deca62 with ruby 2.4.6, rubocop 0.69.0, haml-lint 0.20.0, and yamllint 1.10.0 app/models/manageiq/providers/embedded_ansible/automation_manager/configuration_script_source.rb
|
Support EmbeddedAnsible SCM credentials (cherry picked from commit c262959)
Ivanchuk backport details:
|
This is an attempt (along with
ManageIQ/manageiq-schema#394ManageIQ/manageiq-schema#395) to deal with the "double ownership problem" with ConfigurationScriptSource#authentication and GitRepository. The idea is that in the model we can delegate authentication stuff to the GitRepository. Thus, we ensure a git_repository exists, then sync the authentication and other git attributes over to it.In GitRepository model, while it might have it's own authentication via AuthenticationMixin, we also add a separate belongs_to :authentication which is a referenced authentication. This way we can support both directly owned authentications and not-owned authentications.
cc @gtanzillo @carbonin @NickLaMuro @agrare