Skip to content

Commit

Permalink
BZ #1984890 - Ansible collection repo validate both auth url and toke…
Browse files Browse the repository at this point in the history
…n are supplied

Fixes #33208 - Allow Auth token without Auth URL (Katello#9529)

(cherry picked from commit 7253124)
  • Loading branch information
sjha4 authored and Odilhao committed Aug 16, 2021
1 parent a6544f5 commit 61fb634
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/models/katello/repository.rb
Expand Up @@ -407,7 +407,7 @@ def full_path(smart_proxy = nil, force_http = false)
elsif ostree?
"#{scheme}://#{pulp_uri.host.downcase}/pulp/content/web/#{relative_path}"
elsif ansible_collection?
"#{scheme}://#{pulp_uri.host.downcase}/pulp_ansible/galaxy/#{relative_path}/api"
"#{scheme}://#{pulp_uri.host.downcase}/pulp_ansible/galaxy/#{relative_path}/api/"
else
"#{scheme}://#{pulp_uri.host.downcase}/pulp/content/#{relative_path}/"
end
Expand Down
6 changes: 2 additions & 4 deletions app/models/katello/root_repository.rb
Expand Up @@ -271,9 +271,7 @@ def ensure_valid_auth_url_token
return
end

if self.ansible_collection_auth_url.blank?
errors.add(:base, N_("Auth token requires Auth URL be set."))
elsif !self.ansible_collection_auth_token
if !self.ansible_collection_auth_url.blank? && self.ansible_collection_auth_token.blank?
errors.add(:base, N_("Auth URL requires Auth token be set."))
end
end
Expand Down Expand Up @@ -335,7 +333,7 @@ def pulp_update_needed?
ssl_ca_cert_id ssl_client_cert_id ssl_client_key_id http_proxy_policy http_proxy_id download_concurrency)
changeable_attributes += %w(name container_repository_name docker_tags_whitelist) if docker?
changeable_attributes += %w(deb_releases deb_components deb_architectures gpg_key_id) if deb?
changeable_attributes += %w(ansible_collection_requirements) if ansible_collection?
changeable_attributes += %w(ansible_collection_requirements ansible_collection_auth_url ansible_collection_auth_token) if ansible_collection?
changeable_attributes.any? { |key| previous_changes.key?(key) }
end

Expand Down
Expand Up @@ -96,7 +96,7 @@ <h4 translate>Sync Settings</h4>
<input id="requirementFile" type="file" name="file_path" onclick="this.value = null" onchange="angular.element(this).scope().handleFiles(this)"/>
<p bst-alert='info' ng-show="repository.content_type == 'ansible_collection'">
<span translate>
You can upload a requirements.yml file above to auto-fill contents <b>OR</b> paste contents of <a ng-href="https://docs.ansible.com/ansible/devel/dev_guide/collections_tech_preview.html#install-multiple-collections-with-a-requirements-file" target="_blank"> Requirements.yml </a>below.
You can upload a requirements.yml file above to auto-fill contents <b>OR</b> paste contents of <a ng-href="https://docs.ansible.com/ansible/latest/galaxy/user_guide.html#install-multiple-collections-with-a-requirements-file" target="_blank"> Requirements.yml </a>below.
</span>
</p>
</dd>
Expand Down
4 changes: 3 additions & 1 deletion test/models/root_repository_test.rb
Expand Up @@ -673,7 +673,9 @@ def test_valid_ansible_collection_auth_params
assert ansible_repo_root.valid?
assert_nil ansible_repo_root.ansible_collection_auth_url
assert_nil ansible_repo_root.ansible_collection_auth_token
assert ansible_repo_root.valid?

ansible_repo_root.ansible_collection_auth_token = '12345'
assert ansible_repo_root.valid? # Should be able to specify token only
end
end

Expand Down

0 comments on commit 61fb634

Please sign in to comment.