Skip to content

Commit

Permalink
quick POC to fix registration: (#1807)
Browse files Browse the repository at this point in the history
not tested!
  • Loading branch information
imobachgs authored Dec 4, 2024
2 parents 0063a08 + 56fa368 commit 5aec29f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
19 changes: 14 additions & 5 deletions service/lib/agama/registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
module Agama
# Handles everything related to registration of system to SCC, RMT or similar.
class Registration
# NOTE: identical and keep in sync with Software::Manager::TARGET_DIR
TARGET_DIR = "/run/agama/zypp"
private_constant :TARGET_DIR

GLOBAL_CREDENTIALS_PATH = File.join(TARGET_DIR,
SUSE::Connect::YaST::GLOBAL_CREDENTIALS_FILE)
private_constant :GLOBAL_CREDENTIALS_PATH

# Code used for registering the product.
#
# @return [String, nil] nil if the product is not registered yet.
Expand Down Expand Up @@ -74,7 +82,7 @@ def register(code, email: "")
login, password = SUSE::Connect::YaST.announce_system(connect_params, target_distro)
# write the global credentials
# TODO: check if we can do it in memory for libzypp
SUSE::Connect::YaST.create_credentials_file(login, password)
SUSE::Connect::YaST.create_credentials_file(login, password, GLOBAL_CREDENTIALS_PATH)

target_product = OpenStruct.new(
arch: Yast::Arch.rpm_arch,
Expand All @@ -86,7 +94,8 @@ def register(code, email: "")
# if service require specific credentials file, store it
@credentials_file = credentials_from_url(@service.url)
if @credentials_file
SUSE::Connect::YaST.create_credentials_file(login, password, @credentials_file)
SUSE::Connect::YaST.create_credentials_file(login, password,
File.join(TARGET_DIR, credentials_path(@credentials_file)))
end
Y2Packager::NewRepositorySetup.instance.add_service(@service.name)
@software.add_service(@service)
Expand Down Expand Up @@ -116,9 +125,9 @@ def deregister
email: email
}
SUSE::Connect::YaST.deactivate_system(connect_params)
FileUtils.rm(SUSE::Connect::YaST::GLOBAL_CREDENTIALS_FILE) # connect does not remove it itself
FileUtils.rm(GLOBAL_CREDENTIALS_PATH) # connect does not remove it itself
if @credentials_file
FileUtils.rm(credentials_path(@credentials_file))
FileUtils.rm(File.join(TARGET_DIR, credentials_path(@credentials_file)))
@credentials_file = nil
end

Expand All @@ -131,7 +140,7 @@ def deregister
def finish
return unless reg_code

files = [credentials_path(@credentials_file), SUSE::Connect::YaST::GLOBAL_CREDENTIALS_FILE]
files = [credentials_path(@credentials_file), SUSE::Connect::YaST::GLOBAL_CREDENTIALS_PATH]
files.each do |file|
dest = File.join(Yast::Installation.destdir, file)
FileUtils.cp(file, dest)
Expand Down
7 changes: 4 additions & 3 deletions service/test/agama/registration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@

it "creates credentials file" do
expect(SUSE::Connect::YaST).to receive(:create_credentials_file)
.with("test-user", "12345")
.with("test-user", "12345", "/run/agama/zypp/etc/zypp/credentials.d/SCCcredentials")

subject.register("11112222", email: "[email protected]")
end
Expand All @@ -117,13 +117,14 @@

before do
allow(subject).to receive(:credentials_from_url)
.with("https://credentials/file").and_return("credentials")
.with("https://credentials/file")
.and_return("productA")
end

it "creates the credentials file" do
expect(SUSE::Connect::YaST).to receive(:create_credentials_file)
expect(SUSE::Connect::YaST).to receive(:create_credentials_file)
.with("test-user", "12345", "credentials")
.with("test-user", "12345", "/run/agama/zypp/etc/zypp/credentials.d/productA")

subject.register("11112222", email: "[email protected]")
end
Expand Down

0 comments on commit 5aec29f

Please sign in to comment.