Skip to content

Commit

Permalink
Refactor SUSE repo cleanup and local path generation logic supporting…
Browse files Browse the repository at this point in the history
… akamai url
  • Loading branch information
paragjain0910 committed Dec 16, 2024
1 parent 926de21 commit d81ee4b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/models/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions lib/rmt/scc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
7 changes: 6 additions & 1 deletion spec/lib/rmt/scc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d81ee4b

Please sign in to comment.