Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
2064e0c
first WIP commit
jreidinger Dec 4, 2023
eb93fc7
more code and patch from @imobachgs
jreidinger Dec 4, 2023
a37c783
more code and adapt schema
jreidinger Dec 5, 2023
81e5813
final push for testing
jreidinger Dec 6, 2023
7c170a8
fix dbus path and update example profile for TW
jreidinger Dec 6, 2023
8b59f23
fix product key reading and fix ruby dbus crash
jreidinger Dec 6, 2023
e3b6946
add example for registration and also fix bug that single product med…
jreidinger Dec 7, 2023
a9f6e25
format rust
jreidinger Dec 7, 2023
0a39902
Apply clippy suggestions
jreidinger Dec 7, 2023
73d4256
more clippy suggestions
jreidinger Dec 7, 2023
e5152ec
and final clippy suggestions
jreidinger Dec 7, 2023
7b6ca59
one more suggestion applied
jreidinger Dec 7, 2023
4d75eec
fix name of registration email to match schema
jreidinger Dec 7, 2023
e980cbe
avoid unnecessary clone
jreidinger Dec 7, 2023
1832b5e
Merge remote-tracking branch 'origin/master' into auto_register
jreidinger Dec 8, 2023
6ffe581
Apply suggestions from code review
jreidinger Dec 8, 2023
3689a22
implement passing email
jreidinger Dec 8, 2023
8741ad6
changes
jreidinger Dec 8, 2023
3d2aad1
fix email handling
jreidinger Dec 8, 2023
5a8cba6
report properly registration errors
jreidinger Dec 8, 2023
d4b2a87
remove unnecessary ending
jreidinger Dec 8, 2023
6980229
Apply suggestions from code review
jreidinger Dec 8, 2023
b75a6e1
document list of patterns dbus call
jreidinger Dec 8, 2023
cef4857
Return SCC error details, don't just log them
mvidner Dec 11, 2023
a3c3140
'Product does not require registration' will not fail the whole thing
mvidner Dec 11, 2023
9861060
add error values for pattern selection
jreidinger Dec 12, 2023
915ace5
document dbus API change
jreidinger Dec 12, 2023
9899866
regenerate proxy to fit new return values
jreidinger Dec 13, 2023
607cfe2
handle wrong patterns and update bus
jreidinger Dec 13, 2023
e84aada
fix typo
jreidinger Dec 13, 2023
f32952c
fix dbus marshalling
jreidinger Dec 13, 2023
9e5ed68
fix condition
jreidinger Dec 13, 2023
d34f255
make formatting happy
jreidinger Dec 13, 2023
9b8f086
Apply suggestions from code review
jreidinger Dec 14, 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
3 changes: 3 additions & 0 deletions doc/dbus/bus/org.opensuse.Agama.Software1.bus.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@
</method>
<method name="AddPattern">
<arg name="id" direction="in" type="s"/>
<arg name="result" direction="out" type="b"/>
</method>
<method name="RemovePattern">
<arg name="id" direction="in" type="s"/>
<arg name="result" direction="out" type="b"/>
</method>
<method name="SetUserPatterns">
<arg name="ids" direction="in" type="as"/>
<arg name="wrong" direction="out" type="as"/>
</method>
<method name="ProvisionsSelected">
<arg name="Provisions" direction="in" type="as"/>
Expand Down
50 changes: 50 additions & 0 deletions doc/dbus/org.opensuse.Agama.Software1.doc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,68 @@
<node name="Proposal"/>

<interface name="org.opensuse.Agama.Software1">
<!--
List available patterns.
-->
<method name="ListPatterns">
<!--
Flag if all or filtered only patterns. Way how it is filtered
is internal details and basically it can change anytime.
Filtered patterns are the one to show users for selection.
For validation if patterns are valid, unfiltered should be used.
-->
<arg name="Filtered" direction="in" type="b"/>
<!--
Result of search for patterns. It is Map with pattern id as key and those values
1. category of pattern. Useful for grouping patterns if needed
2. description of pattern
3. path to icon on local system
4. summary of pattern
5. order value for sorting patterns
-->
<arg name="Result" direction="out" type="a{s(sssss)}"/>
</method>
<!--
Adds pattern to explicitelly selected ones.
-->
<method name="AddPattern">
<!--
Identifier of pattern.
-->
<arg name="id" direction="in" type="s"/>
<!--
Returns false if pattern does not exist in current list of repositories.
Otherwise it returns true.
-->
<arg name="result" direction="out" type="b"/>
</method>
<!--
Removes pattern from explicit selection. It can still be installed as dependency.
-->
<method name="RemovePattern">
<!--
Identifier of pattern.
-->
<arg name="id" direction="in" type="s"/>
<!--
Returns false if pattern does not exist in current list of repositories.
Otherwise it returns true including case when pattern was not previously selected.
-->
<arg name="result" direction="out" type="b"/>
</method>
<!--
Sets explicitly selected patterns.
-->
<method name="SetUserPatterns">
<!--
List of pattern ids.
-->
<arg name="ids" direction="in" type="as"/>
<!--
Return list of non existing patterns.
Operation was basically cancelled if result is not empty.
-->
<arg name="wrong" direction="out" type="as"/>
</method>
<method name="ProvisionsSelected">
<arg name="Provisions" direction="in" type="as"/>
Expand Down
4 changes: 2 additions & 2 deletions rust/agama-cli/src/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ impl LogItem for LogCmd {
};

file_name.retain(|c| c != ' ');
self.dst_path.as_path().join(format!("{}", file_name))
self.dst_path.as_path().join(&file_name)
}

fn store(&self) -> Result<(), io::Error> {
Expand Down Expand Up @@ -420,7 +420,7 @@ fn store(options: LogOptions) -> Result<(), io::Error> {
Err(_e) => "[Failed]",
};

showln(verbose, format!("{}", res).as_str());
showln(verbose, res.to_string().as_str());
}

compress_logs(&tmp_dir, &result)
Expand Down
1 change: 0 additions & 1 deletion rust/agama-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use std::{
thread::sleep,
time::Duration,
};
use tokio;

#[derive(Parser)]
#[command(name = "agama", version, about, long_about = None)]
Expand Down
2 changes: 1 addition & 1 deletion rust/agama-dbus-server/src/locale/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn init_locale() -> Result<LocaleCode, Box<dyn std::error::Error>> {
///
pub fn set_service_locale(locale: &LocaleCode) {
// Let's force the encoding to be 'UTF-8'.
let locale = format!("{}.UTF-8", locale.to_string());
let locale = format!("{}.UTF-8", locale);
if setlocale(LocaleCategory::LcAll, locale).is_none() {
log::warn!("Could not set the locale");
}
Expand Down
11 changes: 4 additions & 7 deletions rust/agama-dbus-server/src/locale/locale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl LocalesDatabase {
.lines()
.filter_map(|line| TryInto::<LocaleCode>::try_into(line).ok())
.collect();
self.locales = self.get_locales(&ui_language)?;
self.locales = self.get_locales(ui_language)?;
Ok(())
}

Expand Down Expand Up @@ -82,7 +82,7 @@ impl LocalesDatabase {

let names = &language.names;
let language_label = names
.name_for(&ui_language)
.name_for(ui_language)
.or_else(|| names.name_for(DEFAULT_LANG))
.unwrap_or(language.id.to_string());

Expand All @@ -92,7 +92,7 @@ impl LocalesDatabase {

let names = &territory.names;
let territory_label = names
.name_for(&ui_language)
.name_for(ui_language)
.or_else(|| names.name_for(DEFAULT_LANG))
.unwrap_or(territory.id.to_string());

Expand Down Expand Up @@ -120,10 +120,7 @@ mod tests {
db.read("de").unwrap();
let found_locales = db.entries();
let spanish: LocaleCode = "es_ES".try_into().unwrap();
let found = found_locales
.into_iter()
.find(|l| l.code == spanish)
.unwrap();
let found = found_locales.iter().find(|l| l.code == spanish).unwrap();
assert_eq!(&found.language, "Spanisch");
assert_eq!(&found.territory, "Spanien");
}
Expand Down
8 changes: 4 additions & 4 deletions rust/agama-dbus-server/src/locale/timezone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl TimezonesDatabase {
let ret = timezones
.into_iter()
.map(|tz| {
let parts = translate_parts(&tz, &ui_language, &tz_parts);
let parts = translate_parts(&tz, ui_language, &tz_parts);
TimezoneEntry { code: tz, parts }
})
.collect();
Expand All @@ -62,10 +62,10 @@ impl TimezonesDatabase {

fn translate_parts(timezone: &str, ui_language: &str, tz_parts: &TimezoneIdParts) -> Vec<String> {
timezone
.split("/")
.split('/')
.map(|part| {
tz_parts
.localize_part(part, &ui_language)
.localize_part(part, ui_language)
.unwrap_or(part.to_owned())
})
.collect()
Expand All @@ -82,7 +82,7 @@ mod tests {
let found_timezones = db.entries();
dbg!(&found_timezones);
let found = found_timezones
.into_iter()
.iter()
.find(|tz| tz.code == "Europe/Berlin")
.unwrap();
assert_eq!(&found.code, "Europe/Berlin");
Expand Down
1 change: 0 additions & 1 deletion rust/agama-dbus-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use agama_lib::connection_to;
use anyhow::Context;
use log::{self, LevelFilter};
use std::future::pending;
use tokio;

const ADDRESS: &str = "unix:path=/run/agama/bus";
const SERVICE_NAME: &str = "org.opensuse.Agama1";
Expand Down
2 changes: 1 addition & 1 deletion rust/agama-dbus-server/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ pub async fn export_dbus_objects(
let adapter = NetworkManagerAdapter::from_system()
.await
.expect("Could not connect to NetworkManager to read the configuration.");
NetworkService::start(&connection, adapter).await
NetworkService::start(connection, adapter).await
}
34 changes: 8 additions & 26 deletions rust/agama-dbus-server/src/network/nm/dbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,7 @@ pub fn merge_dbus_connections<'a>(
/// * `conn`: connection represented as a NestedHash.
fn cleanup_dbus_connection(conn: &mut NestedHash) {
if let Some(connection) = conn.get_mut("connection") {
if connection
.get("interface-name")
.is_some_and(|v| is_empty_value(&v))
{
if connection.get("interface-name").is_some_and(is_empty_value) {
connection.remove("interface-name");
}
}
Expand Down Expand Up @@ -254,28 +251,13 @@ fn wireless_config_to_dbus(conn: &WirelessConnection) -> NestedHash {
///
/// * `match_config`: MatchConfig to convert.
fn match_config_to_dbus(match_config: &MatchConfig) -> HashMap<&str, zvariant::Value> {
let drivers: Value = match_config
.driver
.iter()
.cloned()
.collect::<Vec<_>>()
.into();
let drivers: Value = match_config.driver.to_vec().into();

let kernels: Value = match_config
.kernel
.iter()
.cloned()
.collect::<Vec<_>>()
.into();
let kernels: Value = match_config.kernel.to_vec().into();

let paths: Value = match_config.path.iter().cloned().collect::<Vec<_>>().into();
let paths: Value = match_config.path.to_vec().into();

let interfaces: Value = match_config
.interface
.iter()
.cloned()
.collect::<Vec<_>>()
.into();
let interfaces: Value = match_config.interface.to_vec().into();

HashMap::from([
("driver", drivers),
Expand Down Expand Up @@ -314,7 +296,7 @@ fn base_connection_from_dbus(conn: &OwnedNestedHash) -> Option<BaseConnection> {
base_connection.mac_address = mac_address_from_dbus(wireless_config)?;
}

base_connection.ip_config = ip_config_from_dbus(&conn)?;
base_connection.ip_config = ip_config_from_dbus(conn)?;

Some(base_connection)
}
Expand Down Expand Up @@ -381,7 +363,7 @@ fn ip_config_from_dbus(conn: &OwnedNestedHash) -> Option<IpConfig> {
ip_config.method4 = NmMethod(method4.to_string()).try_into().ok()?;

let address_data = ipv4.get("address-data")?;
let mut addresses = addresses_with_prefix_from_dbus(&address_data)?;
let mut addresses = addresses_with_prefix_from_dbus(address_data)?;

ip_config.addresses.append(&mut addresses);

Expand All @@ -405,7 +387,7 @@ fn ip_config_from_dbus(conn: &OwnedNestedHash) -> Option<IpConfig> {
ip_config.method6 = NmMethod(method6.to_string()).try_into().ok()?;

let address_data = ipv6.get("address-data")?;
let mut addresses = addresses_with_prefix_from_dbus(&address_data)?;
let mut addresses = addresses_with_prefix_from_dbus(address_data)?;

ip_config.addresses.append(&mut addresses);

Expand Down
2 changes: 1 addition & 1 deletion rust/agama-dbus-server/src/questions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ pub async fn export_dbus_objects(
const PATH: &str = "/org/opensuse/Agama1/Questions";

// When serving, request the service name _after_ exposing the main object
let questions = Questions::new(&connection);
let questions = Questions::new(connection);
connection.object_server().at(PATH, questions).await?;
connection.object_server().at(PATH, ObjectManager).await?;

Expand Down
6 changes: 3 additions & 3 deletions rust/agama-dbus-server/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
process::{Child, Command},
time::Duration,
};
use tokio;

use tokio_stream::StreamExt;
use uuid::Uuid;
use zbus::{MatchRule, MessageStream, MessageType};
Expand Down Expand Up @@ -101,7 +101,7 @@ impl NameOwnerChangedStream {
.sender("org.freedesktop.DBus")?
.member("NameOwnerChanged")?
.build();
let stream = MessageStream::for_match_rule(rule, &connection, None).await?;
let stream = MessageStream::for_match_rule(rule, connection, None).await?;
Ok(Self(stream))
}

Expand Down Expand Up @@ -137,7 +137,7 @@ where
if retry > RETRIES {
return Err(error);
}
retry = retry + 1;
retry += 1;
let wait_time = Duration::from_millis(INTERVAL);
tokio::time::sleep(wait_time).await;
}
Expand Down
6 changes: 3 additions & 3 deletions rust/agama-dbus-server/tests/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async fn test_read_connections() -> Result<(), Box<dyn Error>> {
let state = NetworkState::new(vec![device], vec![eth0]);
let adapter = NetworkTestAdapter(state);

let _service = NetworkService::start(&server.connection(), adapter).await?;
NetworkService::start(&server.connection(), adapter).await?;
server.request_name().await?;

let client = NetworkClient::new(server.connection()).await?;
Expand All @@ -54,7 +54,7 @@ async fn test_add_connection() -> Result<(), Box<dyn Error>> {

let adapter = NetworkTestAdapter(NetworkState::default());

let _service = NetworkService::start(&server.connection(), adapter).await?;
NetworkService::start(&server.connection(), adapter).await?;
server.request_name().await?;

let client = NetworkClient::new(server.connection().clone()).await?;
Expand Down Expand Up @@ -103,7 +103,7 @@ async fn test_update_connection() -> Result<(), Box<dyn Error>> {
let state = NetworkState::new(vec![device], vec![eth0]);
let adapter = NetworkTestAdapter(state);

let _service = NetworkService::start(&server.connection(), adapter).await?;
NetworkService::start(&server.connection(), adapter).await?;
server.request_name().await?;

let client = NetworkClient::new(server.connection()).await?;
Expand Down
2 changes: 1 addition & 1 deletion rust/agama-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ fn parse_setting_fields(fields: Vec<&syn::Field>) -> SettingFieldsList {
SettingFieldsList(settings)
}

fn quote_fields_aliases(nested_fields: &Vec<&SettingField>) -> Vec<TokenStream2> {
fn quote_fields_aliases(nested_fields: &[&SettingField]) -> Vec<TokenStream2> {
nested_fields
.iter()
.map(|f| {
Expand Down
43 changes: 43 additions & 0 deletions rust/agama-lib/share/examples/profile_Dolomite.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"localization": {
"keyboard": "en_US",
"language": "en_US"
},
"product": {
"id": "ALP-Dolomite",
"registrationCode": "FILL IT UP",
"registrationEmail": "jreidinger@suse.com"
},
"storage": {
"bootDevice": "/dev/dm-1"
},
"user": {
"fullName": "Jane Doe",
"password": "123456",
"userName": "jane.doe"
},
"root": {
"password": "nots3cr3t",
"sshKey": "..."
},
"network": {
"connections": [
{
"id": "Ethernet network device 1",
"method4": "manual",
"method6": "manual",
"interface": "eth0",
"addresses": [
"192.168.122.100/24",
"::ffff:c0a8:7ac7/64"
],
"gateway4": "192.168.122.1",
"gateway6": "::ffff:c0a8:7a01",
"nameservers": [
"192.168.122.1",
"2001:4860:4860::8888"
]
}
]
}
}
Loading