diff --git a/rust/agama-lib/src/product.rs b/rust/agama-lib/src/product.rs index f4f57f31bf..c1ba89cd83 100644 --- a/rust/agama-lib/src/product.rs +++ b/rust/agama-lib/src/product.rs @@ -26,7 +26,6 @@ pub mod proxies; mod settings; mod store; -pub use crate::software::model::RegistrationRequirement; pub use client::{Product, ProductClient}; pub use http_client::ProductHTTPClient; pub use settings::ProductSettings; diff --git a/rust/agama-lib/src/product/client.rs b/rust/agama-lib/src/product/client.rs index 4eac5e5e33..f652554c1c 100644 --- a/rust/agama-lib/src/product/client.rs +++ b/rust/agama-lib/src/product/client.rs @@ -23,7 +23,6 @@ use std::str::FromStr; use crate::dbus::{get_optional_property, get_property}; use crate::error::ServiceError; -use crate::software::model::RegistrationRequirement; use crate::software::proxies::SoftwareProductProxy; use serde::Serialize; use zbus::Connection; diff --git a/rust/agama-lib/src/product/proxies.rs b/rust/agama-lib/src/product/proxies.rs index 8207560c0d..23e37962d3 100644 --- a/rust/agama-lib/src/product/proxies.rs +++ b/rust/agama-lib/src/product/proxies.rs @@ -63,8 +63,4 @@ pub trait Registration { /// RegCode property #[zbus(property)] fn reg_code(&self) -> zbus::Result; - - /// Requirement property - #[zbus(property)] - fn requirement(&self) -> zbus::Result; } diff --git a/rust/agama-lib/src/product/store.rs b/rust/agama-lib/src/product/store.rs index c1a3f42297..e077ced587 100644 --- a/rust/agama-lib/src/product/store.rs +++ b/rust/agama-lib/src/product/store.rs @@ -121,8 +121,7 @@ mod test { .body( r#"{ "key": "", - "email": "", - "requirement": "NotRequired" + "email": "" }"#, ); }); diff --git a/rust/agama-lib/src/software/model/registration.rs b/rust/agama-lib/src/software/model/registration.rs index 8f2e143b63..2d0dbb9441 100644 --- a/rust/agama-lib/src/software/model/registration.rs +++ b/rust/agama-lib/src/software/model/registration.rs @@ -39,28 +39,6 @@ pub struct RegistrationInfo { pub email: String, } -#[derive( - Clone, - Default, - Debug, - Serialize, - Deserialize, - strum::Display, - strum::EnumString, - utoipa::ToSchema, -)] -#[strum(serialize_all = "camelCase")] -#[serde(rename_all = "camelCase")] -pub enum RegistrationRequirement { - /// Product does not require registration - #[default] - No = 0, - /// Product has optional registration - Optional = 1, - /// It is mandatory to register the product - Mandatory = 2, -} - #[derive(Clone, Serialize, Deserialize, utoipa::ToSchema)] pub struct RegistrationError { /// ID of error. See dbus API for possible values diff --git a/rust/agama-server/src/web/docs/software.rs b/rust/agama-server/src/web/docs/software.rs index 0062b56295..0eccb3d8cd 100644 --- a/rust/agama-server/src/web/docs/software.rs +++ b/rust/agama-server/src/web/docs/software.rs @@ -53,7 +53,6 @@ impl ApiDocBuilder for SoftwareApiDocBuilder { fn components(&self) -> Components { ComponentsBuilder::new() .schema_from::() - .schema_from::() .schema_from::() .schema_from::() .schema_from::() diff --git a/rust/agama-server/src/web/event.rs b/rust/agama-server/src/web/event.rs index 1fb4d08697..acb304bd49 100644 --- a/rust/agama-server/src/web/event.rs +++ b/rust/agama-server/src/web/event.rs @@ -23,7 +23,6 @@ use agama_lib::{ jobs::Job, localization::model::LocaleConfig, manager::InstallationPhase, - product::RegistrationRequirement, progress::Progress, software::SelectedBy, storage::{ @@ -59,9 +58,6 @@ pub enum Event { ProductChanged { id: String, }, - RegistrationRequirementChanged { - requirement: RegistrationRequirement, - }, RegistrationChanged, FirstUserChanged(FirstUser), RootChanged { diff --git a/service/lib/agama/cmdline_args.rb b/service/lib/agama/cmdline_args.rb index 2863f86856..963abf401e 100644 --- a/service/lib/agama/cmdline_args.rb +++ b/service/lib/agama/cmdline_args.rb @@ -35,6 +35,10 @@ def initialize(data = {}) @data = data end + def self.read + read_from("/proc/cmdline") + end + # Reads the kernel command line options def self.read_from(path) options = File.read(path) diff --git a/service/lib/agama/dbus/software/product.rb b/service/lib/agama/dbus/software/product.rb index 966f10dbca..8ed8cb193b 100644 --- a/service/lib/agama/dbus/software/product.rb +++ b/service/lib/agama/dbus/software/product.rb @@ -114,7 +114,6 @@ def select_product(id) if code == 0 dbus_properties_changed(PRODUCT_INTERFACE, { "SelectedProduct" => id }, []) - dbus_properties_changed(REGISTRATION_INTERFACE, { "Requirement" => requirement }, []) # FIXME: Product issues might change after selecting a product. Nevertheless, # #on_issues_change callbacks should be used for emitting issues signals, ensuring # they are emitted every time the backend changes its issues. Currently, @@ -136,23 +135,6 @@ def email backend.registration.email || "" end - # Registration requirement. - # - # @return [Integer] Possible values: - # 0: not required - # 1: optional - # 2: mandatory - def requirement - case backend.registration.requirement - when Agama::Registration::Requirement::MANDATORY - 2 - when Agama::Registration::Requirement::OPTIONAL - 1 - else - 0 - end - end - # Tries to register with the given registration code. # # @note Software is not automatically probed after registering the product. The reason is @@ -227,8 +209,6 @@ def deregister dbus_reader(:email, "s") - dbus_reader(:requirement, "u") - dbus_method(:Register, "in reg_code:s, in options:a{sv}, out result:(us)") do |*args| [register(args[0], email: args[1]["Email"])] end diff --git a/service/lib/agama/registration.rb b/service/lib/agama/registration.rb index 7eb4ef60be..5ef3d6ea6d 100644 --- a/service/lib/agama/registration.rb +++ b/service/lib/agama/registration.rb @@ -24,6 +24,7 @@ require "ostruct" require "suse/connect" require "y2packager/new_repository_setup" +require "agama/cmdline_args" Yast.import "Arch" @@ -50,12 +51,6 @@ class Registration # @return [String, nil] attr_reader :email - module Requirement - NO = :no - OPTIONAL = :optional - MANDATORY = :mandatory - end - # @param software_manager [Agama::Software::Manager] # @param logger [Logger] def initialize(software_manager, logger) @@ -76,12 +71,9 @@ def initialize(software_manager, logger) def register(code, email: "") return if product.nil? || reg_code - connect_params = { - token: code, - email: email - } + reg_params = connect_params(token: code, email: email) - login, password = SUSE::Connect::YaST.announce_system(connect_params, target_distro) + login, password = SUSE::Connect::YaST.announce_system(reg_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, GLOBAL_CREDENTIALS_PATH) @@ -122,11 +114,8 @@ def deregister Y2Packager::NewRepositorySetup.instance.services.delete(@service.name) @software.remove_service(@service) - connect_params = { - token: reg_code, - email: email - } - SUSE::Connect::YaST.deactivate_system(connect_params) + reg_params = connect_params(token: reg_code, email: email) + SUSE::Connect::YaST.deactivate_system(reg_params) FileUtils.rm(GLOBAL_CREDENTIALS_PATH) # connect does not remove it itself if @credentials_file FileUtils.rm(File.join(TARGET_DIR, credentials_path(@credentials_file))) @@ -157,16 +146,6 @@ def finish end end - # Indicates whether the registration is optional, mandatory or not required. - # - # @return [Symbol] See {Requirement}. - def requirement - return Requirement::NO unless product - return Requirement::MANDATORY if product.repositories.none? - - Requirement::NO - end - # Callbacks to be called when registration changes (e.g., a different product is selected). def on_change(&block) @on_change_callbacks ||= [] @@ -211,5 +190,25 @@ def credentials_from_url(url) def credentials_path(file) File.join(SUSE::Connect::YaST::DEFAULT_CREDENTIALS_DIR, file) end + + # Returns the arguments to connect to the registration server + # + # @param params [Hash] additional parameters (e.g., email and token) + # @return [Hash] + def connect_params(params = {}) + default_params = {} + default_params[:url] = registration_url if registration_url + default_params.merge(params) + end + + # Returns the URL of the registration server + # + # At this point, it just checks the kernel's command-line. + # + # @return [String, nil] + def registration_url + cmdline_args = CmdlineArgs.read + cmdline_args.data["register_url"] + end end end diff --git a/service/package/rubygem-agama-yast.changes b/service/package/rubygem-agama-yast.changes index 42130329fd..50946863b6 100644 --- a/service/package/rubygem-agama-yast.changes +++ b/service/package/rubygem-agama-yast.changes @@ -1,3 +1,8 @@ +------------------------------------------------------------------- +Tue Feb 18 11:27:04 UTC 2025 - Imobach Gonzalez Sosa + +- Implement basic support for RMT/SCC proxies (gh#agama-project/agama#2007). + ------------------------------------------------------------------- Mon Feb 17 09:17:47 UTC 2025 - Imobach Gonzalez Sosa diff --git a/service/test/agama/dbus/software/product_test.rb b/service/test/agama/dbus/software/product_test.rb index dff355ab20..9bd6d12423 100644 --- a/service/test/agama/dbus/software/product_test.rb +++ b/service/test/agama/dbus/software/product_test.rb @@ -152,36 +152,6 @@ end end - describe "#requirement" do - before do - allow(backend.registration).to receive(:requirement).and_return(requirement) - end - - context "if the registration is not required" do - let(:requirement) { Agama::Registration::Requirement::NO } - - it "returns 0" do - expect(subject.requirement).to eq(0) - end - end - - context "if the registration is optional" do - let(:requirement) { Agama::Registration::Requirement::OPTIONAL } - - it "returns 1" do - expect(subject.requirement).to eq(1) - end - end - - context "if the registration is mandatory" do - let(:requirement) { Agama::Registration::Requirement::MANDATORY } - - it "returns 2" do - expect(subject.requirement).to eq(2) - end - end - end - describe "#register" do before do allow(backend.registration).to receive(:reg_code).and_return(nil) diff --git a/service/test/agama/registration_test.rb b/service/test/agama/registration_test.rb index 1efb802ab5..e83dd2b506 100644 --- a/service/test/agama/registration_test.rb +++ b/service/test/agama/registration_test.rb @@ -49,9 +49,11 @@ allow(SUSE::Connect::YaST).to receive(:create_credentials_file) allow(SUSE::Connect::YaST).to receive(:activate_product).and_return(service) allow(Y2Packager::NewRepositorySetup.instance).to receive(:add_service) + allow(Agama::CmdlineArgs).to receive(:read).and_return(cmdline_args) end let(:service) { OpenStruct.new(name: "test-service", url: nil) } + let(:cmdline_args) { Agama::CmdlineArgs.new({}) } describe "#register" do context "if there is no product selected yet" do @@ -89,6 +91,21 @@ subject.register("11112222", email: "test@test.com") end + context "when a registration URL is set through the cmdline" do + let(:cmdline_args) do + Agama::CmdlineArgs.new("register_url" => "http://scc.example.net") + end + + it "registers using the given URL" do + expect(SUSE::Connect::YaST).to receive(:announce_system).with( + { token: "11112222", email: "test@test.com", url: "http://scc.example.net" }, + "test-5-x86_64" + ) + + subject.register("11112222", email: "test@test.com") + end + end + it "creates credentials file" do expect(SUSE::Connect::YaST).to receive(:create_credentials_file) .with("test-user", "12345", "/etc/zypp/credentials.d/SCCcredentials") @@ -345,38 +362,6 @@ end end - describe "#requirement" do - context "if there is not product selected yet" do - let(:product) { nil } - - it "returns not required" do - expect(subject.requirement).to eq(Agama::Registration::Requirement::NO) - end - end - - context "if there is a selected product" do - let(:product) do - Agama::Software::Product.new("test").tap { |p| p.repositories = repositories } - end - - context "and the product has repositories" do - let(:repositories) { ["https://repo"] } - - it "returns not required" do - expect(subject.requirement).to eq(Agama::Registration::Requirement::NO) - end - end - - context "and the product has no repositories" do - let(:repositories) { [] } - - it "returns mandatory" do - expect(subject.requirement).to eq(Agama::Registration::Requirement::MANDATORY) - end - end - end - end - describe "#finish" do context "system is not registered" do before do diff --git a/web/src/types/registration.ts b/web/src/types/registration.ts index bb31e80435..fa4c9dd326 100644 --- a/web/src/types/registration.ts +++ b/web/src/types/registration.ts @@ -21,8 +21,6 @@ */ type Registration = { - /** Registration requirement (i.e., "not-required", "optional", "mandatory") */ - requirement: "no" | "optional" | "mandatory"; /** Registration code, if any */ code?: string; /** Registration email, if any */