diff --git a/rust/agama-lib/src/users/proxies.rs b/rust/agama-lib/src/users/proxies.rs index 4a2850a8f3..f1a71a2825 100644 --- a/rust/agama-lib/src/users/proxies.rs +++ b/rust/agama-lib/src/users/proxies.rs @@ -5,7 +5,7 @@ use zbus::dbus_proxy; #[dbus_proxy( interface = "org.opensuse.Agama.Users1", - default_service = "org.opensuse.Agama.Users1", + default_service = "org.opensuse.Agama.Manager1", default_path = "/org/opensuse/Agama/Users1" )] trait Users1 { diff --git a/rust/package/agama-cli.changes b/rust/package/agama-cli.changes index 9999eb7733..bb5e037ee4 100644 --- a/rust/package/agama-cli.changes +++ b/rust/package/agama-cli.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Thu Sep 14 10:10:37 UTC 2023 - Imobach Gonzalez Sosa + +- Use a single D-Bus service to connect to the manager and the + users API (gh#openSUSE/agama#753, follow-up of + gh#openSUSE/agama#729). + ------------------------------------------------------------------- Wed Sep 13 09:27:22 UTC 2023 - Knut Anderssen diff --git a/rust/share/dbus-test.conf b/rust/share/dbus-test.conf index 99da927d20..19d576b6b3 100644 --- a/rust/share/dbus-test.conf +++ b/rust/share/dbus-test.conf @@ -37,14 +37,12 @@ - - contexts/dbus_contexts diff --git a/service/lib/agama/dbus/clients/users.rb b/service/lib/agama/dbus/clients/users.rb deleted file mode 100644 index 59e548b865..0000000000 --- a/service/lib/agama/dbus/clients/users.rb +++ /dev/null @@ -1,115 +0,0 @@ -# frozen_string_literal: true - -# Copyright (c) [2022-2023] SUSE LLC -# -# All Rights Reserved. -# -# This program is free software; you can redistribute it and/or modify it -# under the terms of version 2 of the GNU General Public License as published -# by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -# more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, contact SUSE LLC. -# -# To contact SUSE LLC about this file by physical or electronic mail, you may -# find current contact information at www.suse.com. - -require "agama/dbus/clients/base" -require "agama/dbus/clients/with_service_status" -require "agama/dbus/clients/with_validation" - -module Agama - module DBus - module Clients - # D-Bus client for users configuration - class Users < Base - include WithServiceStatus - include WithValidation - - def initialize - super - - @dbus_object = service["/org/opensuse/Agama/Users1"] - @dbus_object.introspect - end - - # @return [String] - def service_name - @service_name ||= "org.opensuse.Agama.Users1" - end - - # Configuration of the first user to create during the installation - # - # @return [Array] full name, name, password and autologin - def first_user - dbus_object["org.opensuse.Agama.Users1"]["FirstUser"][0..3] - end - - # Configures the first user to create during the installation - # - # @param name [String] - # @param fullname [String, nil] - # @param password [String, nil] - # @param autologin [Boolean] - # @return [Array] - def create_first_user(name, fullname: nil, password: nil, autologin: false) - dbus_object.SetFirstUser(fullname.to_s, name, password.to_s, !!autologin, {}) - end - - # Removes the configuration of the first user - def remove_first_user - dbus_object.RemoveFirstUser - end - - # SSH key for root - # - # @return [String] empty if no SSH key set - def root_ssh_key - dbus_object["org.opensuse.Agama.Users1"]["RootSSHKey"] - end - - # Sets the SSH key for root - # - # @param value [String] - def root_ssh_key=(value) - dbus_object.SetRootSSHKey(value) - end - - # Whether the root password is set - # - # @return [Boolean] - def root_password? - dbus_object["org.opensuse.Agama.Users1"]["RootPasswordSet"] - end - - # Sets the root password - # - # @param value [String] - def root_password=(value) - dbus_object.SetRootPassword(value, false) - end - - # Removes the SSH key and password for root - def remove_root_info - dbus_object.RemoveRootPassword - dbus_object.SetRootSSHKey("") - end - - # Commit the changes - def write - dbus_object.Write - end - - private - - # @return [::DBus::Object] - attr_reader :dbus_object - end - end - end -end diff --git a/service/lib/agama/dbus/manager_service.rb b/service/lib/agama/dbus/manager_service.rb index 147d12ff02..1e39c41620 100644 --- a/service/lib/agama/dbus/manager_service.rb +++ b/service/lib/agama/dbus/manager_service.rb @@ -37,16 +37,9 @@ module DBus # It connects to the system D-Bus and answers requests on objects below # `/org/opensuse/Agama1`. class ManagerService - # List of D-Bus services exposed by this class - # - # This basically allows to define "aliases" - all exposed services holds the same objects - # but under different names - # - # @return [Array] - MANAGER_SERVICE = "org.opensuse.Agama.Manager1" - USERS_SERVICE = "org.opensuse.Agama.Users1" - private_constant :MANAGER_SERVICE - private_constant :USERS_SERVICE + # D-Bus service (org.opensuse.Agama.Manager1) + SERVICE_NAME = "org.opensuse.Agama.Manager1" + private_constant :SERVICE_NAME # Agama D-Bus # @@ -94,9 +87,6 @@ def export paths = dbus_objects.map(&:path).join(", ") logger.info "Exported #{paths} objects" - - # Request our service names only when we're ready to serve the objects - service_aliases.each { |s| bus.request_name(s) } end # Call this from some main loop to dispatch the D-Bus messages @@ -117,16 +107,9 @@ def setup_cockpit cockpit.setup(config.data["web"]) end - def service_aliases - @service_aliases ||= [ - MANAGER_SERVICE, - USERS_SERVICE - ] - end - # @return [::DBus::ObjectServer] def service - @service ||= bus.object_server + @service ||= bus.request_service(SERVICE_NAME) end # @return [Array<::DBus::Object>] diff --git a/service/lib/agama/manager.rb b/service/lib/agama/manager.rb index f3153aac34..4f445aad79 100644 --- a/service/lib/agama/manager.rb +++ b/service/lib/agama/manager.rb @@ -30,7 +30,6 @@ require "agama/dbus/clients/locale" require "agama/dbus/clients/software" require "agama/dbus/clients/storage" -require "agama/dbus/clients/users" require "agama/helpers" Yast.import "Stage" @@ -160,11 +159,7 @@ def language # # @return [DBus::Clients::Users] def users - @users ||= DBus::Clients::Users.new.tap do |client| - client.on_service_status_change do |status| - service_status_recorder.save(client.service.name, status) - end - end + @users ||= Users.new(logger) end # Network manager diff --git a/service/lib/agama/users.rb b/service/lib/agama/users.rb index eb73aee7be..898a72239f 100644 --- a/service/lib/agama/users.rb +++ b/service/lib/agama/users.rb @@ -30,7 +30,6 @@ module Agama # Backend class using YaST code. # # {Agama::DBus::Users} wraps it with a D-Bus interface and - # {Agama::DBus::Clients::Users} is a D-Bus client for that. class Users include Helpers @@ -141,6 +140,13 @@ def validate ] end + # Determines whether the users configuration is valid + # + # @return [Boolean] + def valid? + validate.empty? + end + private attr_reader :logger diff --git a/service/package/rubygem-agama.changes b/service/package/rubygem-agama.changes index 87c4c04a57..cb7f1ea4cc 100644 --- a/service/package/rubygem-agama.changes +++ b/service/package/rubygem-agama.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Thu Sep 14 09:04:29 UTC 2023 - Imobach Gonzalez Sosa + +- Use a single D-Bus service to expose the manager and the users + settings (gh#openSUSE/agama#753, follow-up of + gh#openSUSE/agama#729). + ------------------------------------------------------------------- Tue Sep 12 12:27:33 UTC 2023 - Imobach Gonzalez Sosa diff --git a/service/share/dbus.conf b/service/share/dbus.conf index 5033e30ab3..e7dcecf975 100644 --- a/service/share/dbus.conf +++ b/service/share/dbus.conf @@ -39,14 +39,12 @@ - - contexts/dbus_contexts diff --git a/service/share/org.opensuse.Agama.Users1.service b/service/share/org.opensuse.Agama.Users1.service deleted file mode 100644 index 0d32b94598..0000000000 --- a/service/share/org.opensuse.Agama.Users1.service +++ /dev/null @@ -1,4 +0,0 @@ -[D-BUS Service] -Name=org.opensuse.Agama.Users1 -Exec=/usr/bin/agamactl manager -User=root diff --git a/service/test/agama/dbus/clients/users_test.rb b/service/test/agama/dbus/clients/users_test.rb deleted file mode 100644 index b84beaf7f1..0000000000 --- a/service/test/agama/dbus/clients/users_test.rb +++ /dev/null @@ -1,162 +0,0 @@ -# frozen_string_literal: true - -# Copyright (c) [2022-2023] SUSE LLC -# -# All Rights Reserved. -# -# This program is free software; you can redistribute it and/or modify it -# under the terms of version 2 of the GNU General Public License as published -# by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -# more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, contact SUSE LLC. -# -# To contact SUSE LLC about this file by physical or electronic mail, you may -# find current contact information at www.suse.com. - -require_relative "../../../test_helper" -require "agama/dbus/clients/users" -require "agama/dbus/service_status" -require "agama/dbus/interfaces/service_status" -require_relative "with_validation_examples" -require "dbus" - -describe Agama::DBus::Clients::Users do - before do - allow(Agama::DBus::Bus).to receive(:current).and_return(bus) - allow(bus).to receive(:service).with("org.opensuse.Agama.Users1").and_return(service) - allow(service).to receive(:[]).with("/org/opensuse/Agama/Users1") - .and_return(dbus_object) - allow(dbus_object).to receive(:introspect) - allow(dbus_object).to receive(:[]).with("org.opensuse.Agama.Users1") - .and_return(users_iface) - allow(dbus_object).to receive(:[]).with("org.opensuse.Agama1.ServiceStatus") - .and_return(service_status_iface) - end - - let(:bus) { instance_double(Agama::DBus::Bus) } - let(:service) { instance_double(::DBus::ProxyService) } - let(:dbus_object) { instance_double(::DBus::ProxyObject) } - let(:users_iface) { instance_double(::DBus::ProxyObjectInterface) } - let(:service_status_iface) { instance_double(::DBus::ProxyObjectInterface) } - - subject { described_class.new } - - describe "#service_status" do - before do - allow(service_status_iface).to receive(:[]).with("Current") - .and_return(Agama::DBus::Interfaces::ServiceStatus::SERVICE_STATUS_BUSY) - end - - it "returns the value of the service status" do - expect(subject.service_status).to eq(Agama::DBus::ServiceStatus::BUSY) - end - end - - describe "#first_user" do - before do - allow(users_iface).to receive(:[]).with("FirstUser").and_return( - ["Test user", "user", "12345", true, {}] - ) - end - - it "returns the configuration of the first user" do - expect(subject.first_user).to contain_exactly("Test user", "user", "12345", true) - end - end - - describe "#create_first_user" do - # Using partial double because methods are dynamically added to the proxy object - let(:dbus_object) { double(::DBus::ProxyObject) } - - it "configures the first user" do - expect(dbus_object).to receive(:SetFirstUser).with("Test user", "user", "n0ts3cr3t", true, {}) - - subject.create_first_user("user", - fullname: "Test user", password: "n0ts3cr3t", autologin: true) - end - end - - describe "#remove_first_user" do - # Using partial double because methods are dynamically added to the proxy object - let(:dbus_object) { double(::DBus::ProxyObject) } - - it "removes the configuration of the first user" do - expect(dbus_object).to receive(:RemoveFirstUser) - - subject.remove_first_user - end - end - - describe "#root_ssh_key" do - before do - allow(users_iface).to receive(:[]).with("RootSSHKey").and_return("1234-abcd") - end - - it "returns SSH key for root" do - expect(subject.root_ssh_key).to eq("1234-abcd") - end - end - - describe "#root_ssh_key=" do - # Using partial double because methods are dynamically added to the proxy object - let(:dbus_object) { double(::DBus::ProxyObject) } - - it "sets the SSH key for root" do - expect(dbus_object).to receive(:SetRootSSHKey).with("1234-abcd") - - subject.root_ssh_key = "1234-abcd" - end - end - - describe "#root_password?" do - before do - allow(users_iface).to receive(:[]).with("RootPasswordSet").and_return(true) - end - - it "returns whether the root password is set" do - expect(subject.root_password?).to eq(true) - end - end - - describe "#root_password=" do - # Using partial double because methods are dynamically added to the proxy object - let(:dbus_object) { double(::DBus::ProxyObject) } - - it "sets the password for root" do - expect(dbus_object).to receive(:SetRootPassword).with("n0ts3cr3t", false) - - subject.root_password = "n0ts3cr3t" - end - end - - describe "#remove_root_info" do - # Using partial double because methods are dynamically added to the proxy object - let(:dbus_object) { double(::DBus::ProxyObject) } - - it "removes the SSH key and password for root" do - expect(dbus_object).to receive(:RemoveRootPassword) - expect(dbus_object).to receive(:SetRootSSHKey).with("") - - subject.remove_root_info - end - end - - describe "#write" do - # Using partial double because methods are dynamically added to the proxy object - let(:dbus_object) { double(::DBus::ProxyObject) } - - it "applies changes into the system" do - expect(dbus_object).to receive(:Write) - - subject.write - end - end - - include_examples "validation" -end diff --git a/service/test/agama/dbus/manager_service_test.rb b/service/test/agama/dbus/manager_service_test.rb index c46b5402a1..8de02632b6 100644 --- a/service/test/agama/dbus/manager_service_test.rb +++ b/service/test/agama/dbus/manager_service_test.rb @@ -29,25 +29,28 @@ let(:config) { Agama::Config.new } let(:logger) { Logger.new($stdout, level: :warn) } let(:manager) { Agama::Manager.new(config, logger) } - let(:locale_interface) { double("[]" => "en", on_signal: nil) } - let(:locale_service) do - double(object: double(introspect: nil, path: "test", "[]": locale_interface)) - end - let(:bus) { instance_double(Agama::DBus::Bus, request_name: nil, service: locale_service) } - let(:bus_service) do - instance_double(::DBus::ObjectServer, export: nil) - end + + let(:object_server) { instance_double(DBus::ObjectServer, export: nil) } + let(:bus) { instance_double(Agama::DBus::Bus, request_name: nil) } + let(:cockpit) { instance_double(Agama::CockpitManager, setup: nil) } - let(:software_client) do - instance_double(Agama::DBus::Clients::Software, on_product_selected: nil) + + let(:manager_obj) { instance_double(Agama::DBus::Manager, path: "/org/opensuse/Agama/Users1") } + let(:users_obj) { instance_double(Agama::DBus::Users, path: "/org/opensuse/Agama/Users1") } + + let(:locale_client) do + instance_double(Agama::DBus::Clients::Locale, ui_locale: "en_US", on_ui_locale_change: nil) end before do allow(Agama::DBus::Bus).to receive(:current).and_return(bus) - allow(bus).to receive(:object_server).and_return(bus_service) + allow(bus).to receive(:request_service).with("org.opensuse.Agama.Manager1") + .and_return(object_server) allow(Agama::Manager).to receive(:new).with(config, logger).and_return(manager) allow(Agama::CockpitManager).to receive(:new).and_return(cockpit) - allow(manager).to receive(:software).and_return(software_client) + allow(Agama::DBus::Clients::Locale).to receive(:new).and_return(locale_client) + allow(Agama::DBus::Manager).to receive(:new).with(manager, logger).and_return(manager_obj) + allow(Agama::DBus::Users).to receive(:new).and_return(users_obj) end describe "#start" do @@ -58,12 +61,9 @@ end describe "#export" do - it "exports the manager object" do - manager_obj = instance_double(Agama::DBus::Manager, path: nil) - allow(Agama::DBus::Manager).to receive(:new) - .with(manager, logger).and_return(manager_obj) - - expect(bus_service).to receive(:export).with(manager_obj) + it "exports the manager and the user objects" do + expect(object_server).to receive(:export).with(manager_obj) + expect(object_server).to receive(:export).with(users_obj) service.export end end diff --git a/service/test/agama/dbus/manager_test.rb b/service/test/agama/dbus/manager_test.rb index 6fb2c1912d..627bb57962 100644 --- a/service/test/agama/dbus/manager_test.rb +++ b/service/test/agama/dbus/manager_test.rb @@ -215,11 +215,11 @@ describe "#busy_services" do before do - allow(backend).to receive(:busy_services).and_return(["org.opensuse.Agama.Users1"]) + allow(backend).to receive(:busy_services).and_return(["org.opensuse.Agama.Software1"]) end it "returns the names of the busy services" do - expect(subject.busy_services).to contain_exactly("org.opensuse.Agama.Users1") + expect(subject.busy_services).to contain_exactly("org.opensuse.Agama.Software1") end end diff --git a/service/test/agama/manager_test.rb b/service/test/agama/manager_test.rb index b050600515..e63d6595f4 100644 --- a/service/test/agama/manager_test.rb +++ b/service/test/agama/manager_test.rb @@ -47,8 +47,7 @@ end let(:users) do instance_double( - Agama::DBus::Clients::Users, - write: nil, on_service_status_change: nil, valid?: true + Agama::Users, write: nil, valid?: true ) end let(:locale) { instance_double(Agama::DBus::Clients::Locale, finish: nil) } @@ -68,7 +67,7 @@ allow(Agama::DBus::Clients::Locale).to receive(:new).and_return(locale) allow(Agama::DBus::Clients::Software).to receive(:new).and_return(software) allow(Agama::DBus::Clients::Storage).to receive(:new).and_return(storage) - allow(Agama::DBus::Clients::Users).to receive(:new).and_return(users) + allow(Agama::Users).to receive(:new).and_return(users) end describe "#startup_phase" do diff --git a/web/package/cockpit-agama.changes b/web/package/cockpit-agama.changes index 59e8331d58..187fa506a9 100644 --- a/web/package/cockpit-agama.changes +++ b/web/package/cockpit-agama.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Thu Sep 14 10:09:07 UTC 2023 - Imobach Gonzalez Sosa + +- Use a single D-Bus service to connect to the manager and the + users API (gh#openSUSE/agama#753, follow-up of + gh#openSUSE/agama#729). + ------------------------------------------------------------------- Mon Sep 11 11:56:56 UTC 2023 - David Diaz diff --git a/web/src/client/users.js b/web/src/client/users.js index 2401674eb0..109d9c71d8 100644 --- a/web/src/client/users.js +++ b/web/src/client/users.js @@ -24,7 +24,7 @@ import DBusClient from "./dbus"; import { WithValidation } from "./mixins"; -const USERS_SERVICE = "org.opensuse.Agama.Users1"; +const USERS_SERVICE = "org.opensuse.Agama.Manager1"; const USERS_IFACE = "org.opensuse.Agama.Users1"; const USERS_PATH = "/org/opensuse/Agama/Users1";