Skip to content

Commit

Permalink
update repo url from scc data on sync (bsc#1218243)
Browse files Browse the repository at this point in the history
  • Loading branch information
digitaltom committed Dec 21, 2023
1 parent c890d5f commit 1356c65
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
13 changes: 13 additions & 0 deletions app/services/repository_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 3 additions & 10 deletions lib/rmt/scc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

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

Expand Down Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion spec/lib/rmt/scc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) { [] }
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1356c65

Please sign in to comment.