From d81ee4b82a8591e2f56203236418116524a6fb74 Mon Sep 17 00:00:00 2001 From: "parag.jain" Date: Mon, 16 Dec 2024 14:08:21 +0530 Subject: [PATCH] Refactor SUSE repo cleanup and local path generation logic supporting akamai url --- app/models/repository.rb | 5 +++++ lib/rmt/scc.rb | 6 ++++++ spec/lib/rmt/scc_spec.rb | 7 ++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/models/repository.rb b/app/models/repository.rb index ff09674e0..347ec5548 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -21,6 +21,11 @@ class Repository < ApplicationRecord before_destroy :ensure_destroy_possible class << self + + def remove_suse_repos_without_tokens! + where(auth_token: nil).where("external_url LIKE '%.suse.com%'").where(installer_updates: 0).delete_all + end + # Mangles remote repo URL to make a nicer local path, see specs for examples def make_local_path(url) uri = URI(url) diff --git a/lib/rmt/scc.rb b/lib/rmt/scc.rb index 63cbe5106..59fccdf2a 100644 --- a/lib/rmt/scc.rb +++ b/lib/rmt/scc.rb @@ -24,6 +24,9 @@ def sync data.each { |item| migration_paths(item) } update_repositories(scc_api_client.list_repositories) + + Repository.remove_suse_repos_without_tokens! + update_subscriptions(scc_api_client.list_subscriptions) end @@ -65,6 +68,9 @@ def import(path) data.each { |item| migration_paths(item) } update_repositories(JSON.parse(File.read(File.join(path, 'organizations_repositories.json')), symbolize_names: true)) + + Repository.remove_suse_repos_without_tokens! + update_subscriptions(JSON.parse(File.read(File.join(path, 'organizations_subscriptions.json')), symbolize_names: true)) end diff --git a/spec/lib/rmt/scc_spec.rb b/spec/lib/rmt/scc_spec.rb index 496730e56..a62077d00 100644 --- a/spec/lib/rmt/scc_spec.rb +++ b/spec/lib/rmt/scc_spec.rb @@ -261,7 +261,8 @@ :repository, :with_products, auth_token: nil, - external_url: 'https://example.com/repos/not/updates.suse.com/' + external_url: 'https://installer-updates.suse.com/repos/not/updates', + installer_updates: true ) end @@ -290,6 +291,10 @@ def scc expect { suse_repo_with_token.reload }.not_to raise_error end + it 'SUSE repos without auth_tokens are removed' do + expect { suse_repo_without_token.reload }.to raise_error(ActiveRecord::RecordNotFound) + end + it 'other repos without auth_tokens persist' do expect { other_repo_without_token.reload }.not_to raise_error end