From 1356c658e16445045e1b6ac05b24d519cedd5711 Mon Sep 17 00:00:00 2001 From: Thomas Schmidt Date: Thu, 21 Dec 2023 15:19:05 +0100 Subject: [PATCH] update repo url from scc data on sync (bsc#1218243) --- app/services/repository_service.rb | 13 +++++++++++++ lib/rmt/scc.rb | 13 +++---------- spec/lib/rmt/scc_spec.rb | 14 +++++++++++++- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/app/services/repository_service.rb b/app/services/repository_service.rb index 8e4dfdfe2..d967feb7b 100644 --- a/app/services/repository_service.rb +++ b/app/services/repository_service.rb @@ -37,6 +37,19 @@ def create_repository!(product, url, attributes, custom: false) repository end + def update_repository!(repo_data) + uri = URI(repo_data[:url]) + auth_token = uri.query + + Repository.find_by!(scc_id: repo_data[:id]).update!( + auth_token: auth_token, + enabled: repo_data[:enabled], + autorefresh: repo_data[:autorefresh], + external_url: "#{uri.scheme}://#{uri.host}#{uri.path}", + local_path: Repository.make_local_path(uri) + ) + end + def attach_product!(product, repository) RepositoriesServicesAssociation.find_or_create_by!( service_id: product.service.id, diff --git a/lib/rmt/scc.rb b/lib/rmt/scc.rb index 05a5595c1..1ba9158ff 100644 --- a/lib/rmt/scc.rb +++ b/lib/rmt/scc.rb @@ -18,8 +18,8 @@ def sync @logger.info(_('Downloading data from SCC')) scc_api_client = SUSE::Connect::Api.new(Settings.scc.username, Settings.scc.password) - @logger.info(_('Updating products')) data = scc_api_client.list_products + @logger.info(_('Updating products')) data.each { |item| create_product(item) } data.each { |item| migration_paths(item) } @@ -132,8 +132,8 @@ def credentials_set? def update_repositories(repos) @logger.info _('Updating repositories') - repos.each do |item| - update_auth_token_enabled_attr(item) + repos.each do |repo| + repository_service.update_repository!(repo) end end @@ -191,13 +191,6 @@ def create_service(item, product) end end - def update_auth_token_enabled_attr(item) - uri = URI(item[:url]) - auth_token = uri.query - - Repository.find_by!(scc_id: item[:id]).update! auth_token: auth_token, enabled: item[:enabled] - end - def migration_paths(item) product = get_product(item[:id]) ProductPredecessorAssociation.where(product_id: product.id).destroy_all diff --git a/spec/lib/rmt/scc_spec.rb b/spec/lib/rmt/scc_spec.rb index 04d062d7b..a4732b0cd 100644 --- a/spec/lib/rmt/scc_spec.rb +++ b/spec/lib/rmt/scc_spec.rb @@ -113,6 +113,17 @@ include_examples 'saves in database' end + context 'with changed repo url in SCC' do + before do + allow(Settings).to receive(:scc).and_return OpenStruct.new(username: 'foo', password: 'bar') + described_class.new.sync + Repository.first.update(external_url: 'https://outdated.com/') + described_class.new.sync + end + + include_examples 'saves in database' + end + context 'with SLES15 product tree' do let(:products) { JSON.parse(file_fixture('products/sle15_tree.json').read, symbolize_names: true) } let(:subscriptions) { [] } @@ -155,7 +166,8 @@ id: 999999, url: 'http://example.com/extension-without-base', name: 'Repo of an extension without base', - enabled: true + enabled: true, + autorefresh: true } end let(:extra_product) do