Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

D-Bus API for registration #791

Merged
merged 68 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
b48ae86
[service] Some renames in Software D-Bus API
joseivanlopez Oct 4, 2023
8bbd567
[service] WIP Registration D-Bus API
joseivanlopez Oct 4, 2023
c39c376
add registration mock class
jreidinger Oct 4, 2023
e50337b
[service] Replace Validation by Issues interface
joseivanlopez Oct 5, 2023
c5535f7
[service] Fix names
joseivanlopez Oct 5, 2023
851e85f
[service] WIP return error number and message
joseivanlopez Oct 6, 2023
9300a72
initial forst working POC
jreidinger Oct 6, 2023
12102fd
[service] More fixes to adapt to changes in D-Bus API
joseivanlopez Oct 9, 2023
78c4df0
[web] Adapt UI to D-Bus API changes
joseivanlopez Oct 9, 2023
8ac9699
use suse connect directly without yast
jreidinger Oct 9, 2023
cdc9bb4
[service] Work on some tests
joseivanlopez Oct 9, 2023
f16b07e
[service] Small fixes
joseivanlopez Oct 9, 2023
94dd896
[service] Improve generation of connect result
joseivanlopez Oct 9, 2023
b0734a5
fix missing require
jreidinger Oct 9, 2023
551a643
make rubocop happy
jreidinger Oct 9, 2023
4098011
fix typo
jreidinger Oct 9, 2023
834a7dc
drop removed method from y2-registration
jreidinger Oct 9, 2023
d875395
try registation without release type
jreidinger Oct 10, 2023
861c202
[service] Small improvements
joseivanlopez Oct 10, 2023
719d421
[service] Fix tests
joseivanlopez Oct 10, 2023
9881d89
[service] Continue working on the D-Bus API
joseivanlopez Oct 10, 2023
4f90278
support deregister
jreidinger Oct 10, 2023
fe89d84
[service] Add registration issue
joseivanlopez Oct 10, 2023
7ccfa41
add to deregister also code
jreidinger Oct 10, 2023
60ab7ba
fix typo and order
jreidinger Oct 10, 2023
18f5de9
fix base product cannot be deactivated
jreidinger Oct 10, 2023
a4cc72b
remove credentials file
jreidinger Oct 10, 2023
895a092
properly uninitialize internal variables
jreidinger Oct 10, 2023
cd6a22b
[service] Add Product and ProductBuilder
joseivanlopez Oct 11, 2023
b50ac90
[service] Adapt manager to use products
joseivanlopez Oct 11, 2023
66c509a
[service] Register selected product instead of hardcoded
joseivanlopez Oct 11, 2023
b36e988
[service] Add version to config file
joseivanlopez Oct 11, 2023
c3a1422
Merge branch 'master' into registration-dbus-api
joseivanlopez Oct 11, 2023
3632f6a
[web] Fix pattern selector
joseivanlopez Oct 11, 2023
c4dcbb9
add pkg related stuff after registration
jreidinger Oct 12, 2023
61147b7
fix crash for unknown version
jreidinger Oct 12, 2023
72cbf53
fix crash for wrong namespace
jreidinger Oct 12, 2023
9275479
fix typos
jreidinger Oct 12, 2023
bede9c3
add service specific credentials file
jreidinger Oct 13, 2023
a7b856d
[service] Improve documentation
joseivanlopez Oct 16, 2023
db7567a
[service] Rubocop
joseivanlopez Oct 16, 2023
ef1a0f2
[service] Minor fixes and tests
joseivanlopez Oct 17, 2023
dfd547f
[service] Prevent change of product if needed
joseivanlopez Oct 17, 2023
dd866c7
[service] Document Registration D-Bus interface
joseivanlopez Oct 17, 2023
6c4c742
[service] Partially document Software D-Bus interface
joseivanlopez Oct 17, 2023
2bb1a00
[service] Fix D-Bus documentation
joseivanlopez Oct 17, 2023
cc4ba95
[web] Fix tests
joseivanlopez Oct 17, 2023
88141e1
[rust] Adapt to Software D-Bus changes
joseivanlopez Oct 18, 2023
4032595
[rust] Use better error name
joseivanlopez Oct 18, 2023
70b2def
move service operations to software and fix target init
jreidinger Oct 18, 2023
5a38dac
fix namespace
jreidinger Oct 18, 2023
254dfe4
add dependency on suse connect it is used
jreidinger Oct 18, 2023
6c6cba2
[service] Export a separate product object
joseivanlopez Oct 19, 2023
fe0d63b
[web] Adapt software client
joseivanlopez Oct 19, 2023
7b1cd3c
[service] Unit tests and minor fixes
joseivanlopez Oct 20, 2023
5c3809a
copy credentials in installation
jreidinger Oct 20, 2023
0b21ca7
[service] Registration tests and minor fixes
joseivanlopez Oct 20, 2023
0814460
[service] Add missing check
joseivanlopez Oct 20, 2023
691f71c
[service] Use ruby-dbus 0.23.1
joseivanlopez Oct 20, 2023
a2c702b
[service] Update D-Bus documentation
joseivanlopez Oct 20, 2023
7317e61
[web] Fix tests
joseivanlopez Oct 20, 2023
c99a98e
run probe and propose after registration/deregistration
jreidinger Oct 20, 2023
133acc8
fix return statement
jreidinger Oct 20, 2023
aa57609
[rust] Adapt software proxies and client
joseivanlopez Oct 23, 2023
847952e
[service] Rubocop
joseivanlopez Oct 23, 2023
56d8935
Merge branch 'master' into registration-dbus-api
joseivanlopez Oct 23, 2023
a78702b
Add missing package to setup script
joseivanlopez Oct 23, 2023
aa32a97
fix writting credentials to target system
jreidinger Oct 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions service/lib/agama/dbus/clients/software.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) [2022] SUSE LLC
# Copyright (c) [2022-2023] SUSE LLC
#
# All Rights Reserved.
#
Expand All @@ -20,18 +20,18 @@
# 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_issues"
require "agama/dbus/clients/with_progress"
require "agama/dbus/clients/with_validation"
require "agama/dbus/clients/with_service_status"

module Agama
module DBus
module Clients
# D-Bus client for software configuration
class Software < Base
include WithServiceStatus
include WithIssues
include WithProgress
include WithValidation
include WithServiceStatus

TYPES = [:package, :pattern].freeze
private_constant :TYPES
Expand All @@ -55,7 +55,7 @@ def service_name
#
# @return [Array<Array<String, String>>] name and display name of each product
def available_products
dbus_object["org.opensuse.Agama.Software1"]["AvailableBaseProducts"].map do |l|
dbus_object["org.opensuse.Agama.Software1"]["AvailableProducts"].map do |l|
l[0..1]
end
end
Expand All @@ -64,7 +64,7 @@ def available_products
#
# @return [String, nil] name of the product
def selected_product
product = dbus_object["org.opensuse.Agama.Software1"]["SelectedBaseProduct"]
product = dbus_object["org.opensuse.Agama.Software1"]["SelectedProduct"]
return nil if product.empty?

product
Expand Down Expand Up @@ -170,8 +170,8 @@ def remove_resolvables(unique_id, type, resolvables, optional: false)
# @param block [Proc] Callback to run when a product is selected
def on_product_selected(&block)
on_properties_change(dbus_object) do |_, changes, _|
base_product = changes["SelectedBaseProduct"]
block.call(base_product) unless base_product.nil?
product = changes["SelectedProduct"]
block.call(product) unless product.nil?
end
end

Expand Down
110 changes: 91 additions & 19 deletions service/lib/agama/dbus/software/manager.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) [2022] SUSE LLC
# Copyright (c) [2022-2023] SUSE LLC
#
# All Rights Reserved.
#
Expand All @@ -20,13 +20,14 @@
# find current contact information at www.suse.com.

require "dbus"
require "suse/connect"
require "agama/dbus/base_object"
require "agama/dbus/with_service_status"
require "agama/dbus/clients/locale"
require "agama/dbus/clients/network"
require "agama/dbus/interfaces/issues"
require "agama/dbus/interfaces/progress"
require "agama/dbus/interfaces/service_status"
require "agama/dbus/interfaces/validation"
require "agama/dbus/with_service_status"

module Agama
module DBus
Expand All @@ -36,7 +37,7 @@ class Manager < BaseObject
include WithServiceStatus
include Interfaces::Progress
include Interfaces::ServiceStatus
include Interfaces::Validation
include Interfaces::Issues

PATH = "/org/opensuse/Agama/Software1"
private_constant :PATH
Expand All @@ -54,20 +55,20 @@ def initialize(backend, logger)
@selected_patterns = {}
end

# List of issues, see {DBus::Interfaces::Issues}
#
# @return [Array<Agama::Issue>]
def issues
backend.issues
end

SOFTWARE_INTERFACE = "org.opensuse.Agama.Software1"
private_constant :SOFTWARE_INTERFACE

dbus_interface SOFTWARE_INTERFACE do
dbus_reader :available_base_products, "a(ssa{sv})"

dbus_reader :selected_base_product, "s"
dbus_reader :available_products, "a(ssa{sv})"

# documented way to be able to write to patterns and trigger signal
attr_writer :selected_patterns

# selected patterns is hash with pattern name as id and 0 for user selected and
# 1 for auto selected. Can be extended in future e.g. for mandatory patterns
dbus_attr_reader :selected_patterns, "a{sy}"
dbus_reader :selected_product, "s"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when we touch it we probably also need to solve issue with version...as there can be two products with same name and different version like it happen with micro based on some SP. And registration need version....maybe product should be tuple of strings with name and version?


dbus_method :SelectProduct, "in ProductID:s" do |product_id|
old_product_id = backend.product
Expand All @@ -80,7 +81,6 @@ def initialize(backend, logger)
logger.info "Selecting product #{product_id}"
select_product(product_id)
dbus_properties_changed(SOFTWARE_INTERFACE, { "SelectedBaseProduct" => product_id }, [])
update_validation # as different product means different software selection
end

# value of result hash is category, description, icon, summary and order
Expand All @@ -101,6 +101,13 @@ def initialize(backend, logger)
]
end

# documented way to be able to write to patterns and trigger signal
joseivanlopez marked this conversation as resolved.
Show resolved Hide resolved
attr_writer :selected_patterns

# selected patterns is hash with pattern name as id and 0 for user selected and
# 1 for auto selected. Can be extended in future e.g. for mandatory patterns
dbus_attr_reader :selected_patterns, "a{sy}"

dbus_method(:AddPattern, "in id:s") { |p| backend.add_pattern(p) }
dbus_method(:RemovePattern, "in id:s") { |p| backend.remove_pattern(p) }
dbus_method(:SetUserPatterns, "in ids:as") { |ids| backend.user_patterns = ids }
Expand All @@ -121,7 +128,7 @@ def initialize(backend, logger)
dbus_method(:Finish) { finish }
end

def available_base_products
def available_products
backend.products.map do |id, data|
[id, data["name"], { "description" => data["description"] }].freeze
end
Expand All @@ -130,7 +137,7 @@ def available_base_products
# Returns the selected base product
#
# @return [String] Product ID or an empty string if no product is selected
def selected_base_product
def selected_product
backend.product || ""
end

Expand All @@ -140,13 +147,10 @@ def select_product(product_id)

def probe
busy_while { backend.probe }

update_validation # probe do force proposal
end

def propose
busy_while { backend.propose }
update_validation

nil # explicit nil as return value
end
Expand All @@ -159,6 +163,48 @@ def finish
busy_while { backend.finish }
end

REGISTRATION_INTERFACE = "org.opensuse.Agama1.Registration"
private_constant :REGISTRATION_INTERFACE

dbus_interface REGISTRATION_INTERFACE do
dbus_reader(:reg_code, "s")

dbus_reader(:email, "s")

dbus_reader(:state, "u")

dbus_method(:Register, "in reg_code:s, in options:a{sv}, out result:(us)") do |*args|
[register(*args)]
end

dbus_method(:Deregister, "out result:(us)") { [deregister] }
end

def reg_code
backend.registration.reg_code || ""
end

def email
backend.registration.email || ""
end

def state
# TODO
0
end

def register(reg_code, options)
connect_result do
backend.registration.register(reg_code, email: options["Email"])
end
end

def deregister
connect_result do
backend.registration.deregister
end
end
joseivanlopez marked this conversation as resolved.
Show resolved Hide resolved

private

# @return [Agama::Software]
Expand All @@ -179,6 +225,8 @@ def register_callbacks
backend.on_selected_patterns_change do
self.selected_patterns = compute_patterns
end

backend.on_issues_change { issues_properties_changed }
end

USER_SELECTED_PATTERN = 0
Expand All @@ -191,6 +239,30 @@ def compute_patterns

patterns
end

# @return [Array<Integer, String>]
def connect_result(&block)
block.call
[0, ""]
rescue SocketError => e
logger.error("Network error: #{e}")
[1, "Connection to registration server failed (network error)"]
rescue Timeout::Error => e
logger.error("Timeout error: #{e}")
[2, "Connection to registration server failed (timeout)"]
rescue SUSE::Connect::ApiError => e
[3, "Connection to registration server failed"]
rescue SUSE::Connect::MissingSccCredentialsFile => e
[4, "Connection to registration server failed (missing credentials)"]
rescue SUSE::Connect::MalformedSccCredentialsFile => e
[5, "Connection to registration server failed (incorrect credentials)"]
rescue OpenSSL::SSL::SSLError => e
[6, "Connection to registration server failed (invalid certificate)"]
rescue JSON::ParserError => e
[7, "Connection to registration server failed"]
rescue StandardError => e
[8, "Connection to registration server failed"]
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion service/lib/agama/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def on_services_status_change(&block)
#
# @return [Boolean]
def valid?
[users, software].all?(&:valid?) && !storage.errors?
users.valid? && !software.errors? && !storage.errors?
end

# Collects the logs and stores them into an archive
Expand Down
71 changes: 71 additions & 0 deletions service/lib/agama/registration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright (c) [2024] 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 "yast"
require "openstruct"

require "registration/registration"
require "y2packager/new_repository_setup"

module Agama
# Handles everything related to registration of system to SCC, RMT or similar
class Registration
attr_reader :reg_code
attr_reader :email

# initializes registration with instance of software manager for query about products
def initialize(software_manager)
@software = software_manager
@on_state_change_callbacks = []
end

def register(code, email: "")
target_distro = "ALP-Dolomite-1-x86_64" # TODO read it
registration = Registration::Registration.new # intentional no url yet
joseivanlopez marked this conversation as resolved.
Show resolved Hide resolved
registration.register(email, code, target_distro)
# TODO: fill it properly for scc
target_product = OpenStruct.new(
arch: "x86_64",
identifier: "ALP-Dolomite",
version: "1.0",
release_type: "ALPHA"
)
activate_params = {}
service = SUSE::Connect::YaST.activate_product(target_product, activate_params, email)
Y2Packager::NewRepositorySetup.instance.add_service(service.name)

@reg_code = code
@email = email
end

def deregister
end

def disabled?
end

def optional?
end

# callback when state changed like when different product is selected
def on_state_change(&block)
@on_state_change_callbacks << block
end
end
end
Loading