Skip to content

Commit

Permalink
Merge pull request #869 from openSUSE/registration
Browse files Browse the repository at this point in the history
Registration support
  • Loading branch information
joseivanlopez authored Nov 15, 2023
2 parents 57a31cb + 4b55006 commit ab65300
Show file tree
Hide file tree
Showing 89 changed files with 5,131 additions and 1,089 deletions.
53 changes: 53 additions & 0 deletions doc/dbus/bus/org.opensuse.Agama.Software1.Product.bus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<node name="/org/opensuse/Agama/Software1/Product">
<interface name="org.freedesktop.DBus.Introspectable">
<method name="Introspect">
<arg name="xml_data" direction="out" type="s"/>
</method>
</interface>
<interface name="org.freedesktop.DBus.Properties">
<method name="Get">
<arg name="interface_name" direction="in" type="s"/>
<arg name="property_name" direction="in" type="s"/>
<arg name="value" direction="out" type="v"/>
</method>
<method name="Set">
<arg name="interface_name" direction="in" type="s"/>
<arg name="property_name" direction="in" type="s"/>
<arg name="val" direction="in" type="v"/>
</method>
<method name="GetAll">
<arg name="interface_name" direction="in" type="s"/>
<arg name="value" direction="out" type="a{sv}"/>
</method>
<signal name="PropertiesChanged">
<arg name="interface" type="s"/>
<arg name="changed_properties" type="a{sv}"/>
<arg name="invalidated_properties" type="as"/>
</signal>
</interface>
<interface name="org.opensuse.Agama.Software1.Product">
<method name="SelectProduct">
<arg name="id" direction="in" type="s"/>
<arg name="result" direction="out" type="(us)"/>
</method>
<property type="a(ssa{sv})" name="AvailableProducts" access="read"/>
<property type="s" name="SelectedProduct" access="read"/>
</interface>
<interface name="org.opensuse.Agama1.Issues">
<property type="a(ssuu)" name="All" access="read"/>
</interface>
<interface name="org.opensuse.Agama1.Registration">
<method name="Register">
<arg name="reg_code" direction="in" type="s"/>
<arg name="options" direction="in" type="a{sv}"/>
<arg name="result" direction="out" type="(us)"/>
</method>
<method name="Deregister">
<arg name="result" direction="out" type="(us)"/>
</method>
<property type="s" name="RegCode" access="read"/>
<property type="s" name="Email" access="read"/>
<property type="u" name="Requirement" access="read"/>
</interface>
</node>
25 changes: 15 additions & 10 deletions doc/dbus/bus/org.opensuse.Agama.Software1.bus.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<node name="/org/opensuse/Agama/Software1">
<node name="Product"/>
<node name="Proposal"/>
<interface name="org.freedesktop.DBus.Introspectable">
<method name="Introspect">
Expand Down Expand Up @@ -28,12 +29,18 @@
</signal>
</interface>
<interface name="org.opensuse.Agama.Software1">
<method name="SelectProduct">
<arg name="ProductID" direction="in" type="s"/>
</method>
<method name="ListPatterns">
<arg name="Filtered" direction="in" type="b"/>
<arg name="Result" direction="out" type="a{s(ssssi)}"/>
<arg name="Result" direction="out" type="a{s(sssss)}"/>
</method>
<method name="AddPattern">
<arg name="id" direction="in" type="s"/>
</method>
<method name="RemovePattern">
<arg name="id" direction="in" type="s"/>
</method>
<method name="SetUserPatterns">
<arg name="ids" direction="in" type="as"/>
</method>
<method name="ProvisionsSelected">
<arg name="Provisions" direction="in" type="as"/>
Expand All @@ -54,8 +61,10 @@
</method>
<method name="Finish">
</method>
<property type="a(ssa{sv})" name="AvailableBaseProducts" access="read"/>
<property type="s" name="SelectedBaseProduct" access="read"/>
<property type="a{sy}" name="SelectedPatterns" access="read"/>
</interface>
<interface name="org.opensuse.Agama1.Issues">
<property type="a(ssuu)" name="All" access="read"/>
</interface>
<interface name="org.opensuse.Agama1.Progress">
<property type="u" name="TotalSteps" access="read"/>
Expand All @@ -66,8 +75,4 @@
<property type="aa{sv}" name="All" access="read"/>
<property type="u" name="Current" access="read"/>
</interface>
<interface name="org.opensuse.Agama1.Validation">
<property type="as" name="Errors" access="read"/>
<property type="b" name="Valid" access="read"/>
</interface>
</node>
1 change: 1 addition & 0 deletions doc/dbus/bus/org.opensuse.Agama1.Registration.bus.xml
38 changes: 38 additions & 0 deletions doc/dbus/org.opensuse.Agama.Software1.Product.doc.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<node name="/org/opensuse/Agama/Software1/Product">
<interface name="org.opensuse.Agama.Software1.Product">
<!--
Selects a product.
-->
<method name="SelectProduct">
<!--
Product ID. See #AvailableProducts.
-->
<arg name="id" direction="in" type="s"/>
<!--
Result code and description.
Possible result codes are:
# 0: successfully selected
# 1: given product is already selected
# 2: current product must be deregistered before selecting a new product
# 3: given product is unknown
-->
<arg name="result" direction="out" type="(us)"/>
</method>
<!--
Available products for installation.
For each product, it returns:
s (product ID)
s (product name)
a{sv}
description s
-->
<property type="a(ssa{sv})" name="AvailableProducts" access="read"/>
<!--
ID of the currently selected product.
-->
<property type="s" name="SelectedProduct" access="read"/>
</interface>
</node>
41 changes: 41 additions & 0 deletions doc/dbus/org.opensuse.Agama.Software1.doc.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<node name="/org/opensuse/Agama/Software1">
<node name="Product"/>
<node name="Proposal"/>

<interface name="org.opensuse.Agama.Software1">
<method name="ListPatterns">
<arg name="Filtered" direction="in" type="b"/>
<arg name="Result" direction="out" type="a{s(sssss)}"/>
</method>
<method name="AddPattern">
<arg name="id" direction="in" type="s"/>
</method>
<method name="RemovePattern">
<arg name="id" direction="in" type="s"/>
</method>
<method name="SetUserPatterns">
<arg name="ids" direction="in" type="as"/>
</method>
<method name="ProvisionsSelected">
<arg name="Provisions" direction="in" type="as"/>
<arg name="Result" direction="out" type="ab"/>
</method>
<method name="IsPackageInstalled">
<arg name="Name" direction="in" type="s"/>
<arg name="Result" direction="out" type="b"/>
</method>
<method name="UsedDiskSpace">
<arg name="SpaceSize" direction="out" type="s"/>
</method>
<method name="Probe">
</method>
<method name="Propose">
</method>
<method name="Install">
</method>
<method name="Finish">
</method>
<property type="a{sy}" name="SelectedPatterns" access="read"/>
</interface>
</node>
4 changes: 3 additions & 1 deletion doc/dbus/org.opensuse.Agama1.Progress.doc.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node name="/org/opensuse/Agama/Software1">
<node name="Proposal"></node>
<node name="Product"/>
<node name="Proposal"/>

<!--
org.opensuse.Agama1.Progress:
The main object of a service implements the Progress interface
Expand Down
76 changes: 76 additions & 0 deletions doc/dbus/org.opensuse.Agama1.Registration.doc.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<node name="/org/opensuse/Agama/Software1/Product">
<!--
Interface for registering a product.
-->
<interface name="org.opensuse.Agama1.Registration">
<!--
Registers the currently selected product.
-->
<method name="Register">
<!--
Registration code.
-->
<arg name="reg_code" direction="in" type="s"/>
<!--
Email s
-->
<arg name="options" direction="in" type="a{sv}"/>
<!--
Result code and description.
Possible result codes are:
0: success
1: missing product
2: already registered
3: registration not required
4: network error
5: timeout error
6: api error
7: missing credentials
8: incorrect credentials
8: invalid certificate
10: internal error (e.g., parsing json data)
-->
<arg name="result" direction="out" type="(us)"/>
</method>
<!--
Deregisters the currently selected product.
-->
<method name="Deregister">
<!--
Result code and description.
Possible result codes are:
0: success
1: missing product
2: not registered yet
3: network error
4: timeout error
5: api error
6: missing credentials
7: incorrect credentials
8: invalid certificate
9: internal error (e.g., parsing json data)
-->
<arg name="result" direction="out" type="(us)"/>
</method>
<!--
Registration code. Empty if the current product is not registered yet.
-->
<property type="s" name="RegCode" access="read"/>
<!--
Email used for the registration. Empty if the current product is not registered yet.
-->
<property type="s" name="Email" access="read"/>
<!--
Indicates the registration requirement of the currently selected product.
Possible values:
0: registration is not required.
1: registration is optional.
2: registration is mandatory.
-->
<property type="u" name="Requirement" access="read"/>
</interface>
</node>
10 changes: 0 additions & 10 deletions products.d/ALP-Dolomite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,6 @@ translations:
bezpečnost pro poskytování úplného minima ke spuštění úloh a služeb v
kontejnerech nebo virtuálních strojích.
software:
installation_repositories:
- url: https://updates.suse.com/SUSE/Products/ALP-Dolomite/1.0/x86_64/product/
archs: x86_64
- url: https://updates.suse.com/SUSE/Products/ALP-Dolomite/1.0/aarch64/product/
archs: aarch64
- url: https://updates.suse.com/SUSE/Products/ALP-Dolomite/1.0/s390x/product/
archs: s390
- url: https://updates.suse.com/SUSE/Products/ALP-Dolomite/1.0/ppc64le/product/
archs: ppc

mandatory_patterns:
- alp_base_zypper
- alp_cockpit
Expand Down
4 changes: 2 additions & 2 deletions rust/agama-lib/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ pub enum ServiceError {
DBus(#[from] zbus::Error),
#[error("Could not connect to Agama bus at '{0}'")]
DBusConnectionError(String, #[source] zbus::Error),
#[error("Unknown product '{0}'. Available products: '{1:?}'")]
UnknownProduct(String, Vec<String>),
// it's fine to say only "Error" because the original
// specific error will be printed too
#[error("Error: {0}")]
Anyhow(#[from] anyhow::Error),
#[error("Wrong user parameters: '{0:?}'")]
WrongUser(Vec<String>),
#[error("Error: {0}")]
UnsuccessfulAction(String),
}

#[derive(Error, Debug)]
Expand Down
25 changes: 18 additions & 7 deletions rust/agama-lib/src/software/client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::proxies::Software1Proxy;
use super::proxies::SoftwareProductProxy;
use crate::error::ServiceError;
use serde::Serialize;
use zbus::Connection;
Expand All @@ -16,21 +16,21 @@ pub struct Product {

/// D-Bus client for the software service
pub struct SoftwareClient<'a> {
software_proxy: Software1Proxy<'a>,
product_proxy: SoftwareProductProxy<'a>,
}

impl<'a> SoftwareClient<'a> {
pub async fn new(connection: Connection) -> Result<SoftwareClient<'a>, ServiceError> {
Ok(Self {
software_proxy: Software1Proxy::new(&connection).await?,
product_proxy: SoftwareProductProxy::new(&connection).await?,
})
}

/// Returns the available products
pub async fn products(&self) -> Result<Vec<Product>, ServiceError> {
let products: Vec<Product> = self
.software_proxy
.available_base_products()
.product_proxy
.available_products()
.await?
.into_iter()
.map(|(id, name, data)| {
Expand All @@ -50,11 +50,22 @@ impl<'a> SoftwareClient<'a> {

/// Returns the selected product to install
pub async fn product(&self) -> Result<String, ServiceError> {
Ok(self.software_proxy.selected_base_product().await?)
Ok(self.product_proxy.selected_product().await?)
}

/// Selects the product to install
pub async fn select_product(&self, product_id: &str) -> Result<(), ServiceError> {
Ok(self.software_proxy.select_product(product_id).await?)
let result = self.product_proxy.select_product(product_id).await?;

match result {
(0, _) => Ok(()),
(3, description) => {
let products = self.products().await?;
let ids: Vec<String> = products.into_iter().map(|p| p.id).collect();
let error = format!("{0}. Available products: '{1:?}'", description, ids);
Err(ServiceError::UnsuccessfulAction(error))
}
(_, description) => Err(ServiceError::UnsuccessfulAction(description)),
}
}
}
Loading

0 comments on commit ab65300

Please sign in to comment.