Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 3 additions & 6 deletions rust/agama-cli/src/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ pub async fn run(client: BaseHTTPClient, subcommand: LogsCommands) -> anyhow::Re
// feed internal options structure by what was received from user
// for now we always use / add defaults if any
let dst_file = parse_destination(destination)?;
let result = client
.store(dst_file.as_path())
.await
.map_err(|e| anyhow::Error::new(e))?;
let result = client.store(dst_file.as_path()).await?;

println!("{}", result.clone().display());

Expand Down Expand Up @@ -83,9 +80,9 @@ pub async fn run(client: BaseHTTPClient, subcommand: LogsCommands) -> anyhow::Re
/// * destination
/// - if None then a default is returned
/// - if a path to a directory then a default file name for the archive will be appended to the
/// path
/// path
/// - if path with a file name then it is used as is for resulting archive, just extension will
/// be appended later on (depends on used compression)
/// be appended later on (depends on used compression)
fn parse_destination(destination: Option<PathBuf>) -> Result<PathBuf, io::Error> {
let err = io::Error::new(io::ErrorKind::InvalidInput, "Invalid destination path");
let mut buffer = destination.unwrap_or(PathBuf::from(format!(
Expand Down
9 changes: 2 additions & 7 deletions rust/agama-cli/src/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,12 @@ fn validate(path: &PathBuf) -> anyhow::Result<()> {
.context(format!("Could not validate the profile {:?}", path))?;
match result {
ValidationResult::Valid => {
println!(
"{} {}",
style("\u{2713}").bold().green(),
"The profile is valid."
);
println!("{} The profile is valid.", style("\u{2713}").bold().green(),);
}
ValidationResult::NotValid(errors) => {
eprintln!(
"{} {}",
"{} The profile is not valid. Please, check the following errors:\n",
style("\u{2717}").bold().red(),
"The profile is not valid. Please, check the following errors:\n"
);
for error in errors {
println!("\t* {error}")
Expand Down
8 changes: 4 additions & 4 deletions rust/agama-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
//! Each of those modules contains, at least:
//!
//! * A settings model: it is a representation of the installation settings for the given topic. It
//! is expected to implement the [serde::Serialize], [serde::Deserialize] and
//! [agama_settings::settings::Settings] traits.
//! is expected to implement the [serde::Serialize], [serde::Deserialize] and
//! [agama_settings::settings::Settings] traits.
//! * A store: it is the responsible for reading/writing the settings to the service. Usually, it
//! relies on a D-Bus client for communicating with the service, although it could implement that
//! logic itself. Note: we are considering defining a trait for stores too.
//! relies on a D-Bus client for communicating with the service, although it could implement that
//! logic itself. Note: we are considering defining a trait for stores too.
//!
//! As said, those modules might implement additional stuff, like specific types, clients, etc.

Expand Down
4 changes: 2 additions & 2 deletions rust/agama-lib/src/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,12 @@ impl LogItem for LogCmd {
.args(cmd_parts[1..].iter())
.output()?;

if output.stdout.len() > 0 {
if !output.stdout.is_empty() {
let mut file_stdout = File::create(format!("{}.out.log", file_path.display()))?;

file_stdout.write_all(&output.stdout)?;
}
if output.stderr.len() > 0 {
if !output.stderr.is_empty() {
let mut file_stderr = File::create(format!("{}.err.log", file_path.display()))?;

file_stderr.write_all(&output.stderr)?;
Expand Down
2 changes: 1 addition & 1 deletion rust/agama-lib/src/manager/http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl ManagerHTTPClient {
/// Asks backend for lists of log files and commands used for creating logs archive returned by
/// store (/logs/store) backed HTTP API command
pub async fn list(&self) -> Result<LogsLists, ServiceError> {
Ok(self.client.get("/manager/logs/list").await?)
self.client.get("/manager/logs/list").await
}

/// Returns the installer status.
Expand Down
4 changes: 2 additions & 2 deletions rust/agama-lib/src/proxies/questions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
// To contact SUSE LLC about this file by physical or electronic mail, you may
// find current contact information at www.suse.com.

mod questions;
pub use questions::QuestionsProxy;
mod base;
pub use base::QuestionsProxy;

mod generic;
pub use generic::GenericProxy as GenericQuestionProxy;
Expand Down
15 changes: 5 additions & 10 deletions rust/agama-lib/src/scripts/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub struct BaseScript {
impl BaseScript {
fn write<P: AsRef<Path>>(&self, workdir: P) -> Result<(), ScriptError> {
let script_path = workdir.as_ref().join(&self.name);
std::fs::create_dir_all(&script_path.parent().unwrap())?;
std::fs::create_dir_all(script_path.parent().unwrap())?;

let mut file = fs::OpenOptions::new()
.create(true)
Expand Down Expand Up @@ -109,7 +109,7 @@ impl Script {
///
/// The name of the script depends on the work directory and the script's group.
pub fn write<P: AsRef<Path>>(&self, workdir: P) -> Result<(), ScriptError> {
let path = workdir.as_ref().join(&self.group().to_string());
let path = workdir.as_ref().join(self.group().to_string());
self.base().write(&path)
}

Expand Down Expand Up @@ -145,7 +145,7 @@ impl Script {
return Ok(());
};

return runner.run(&path);
runner.run(&path)
}
}

Expand Down Expand Up @@ -316,6 +316,7 @@ impl Default for ScriptsRepository {
///
/// At this point, it only supports running a command in a chroot environment. In the future, it
/// might implement support for other features, like progress reporting (like AutoYaST does).
#[derive(Default)]
struct ScriptRunner {
chroot: bool,
}
Expand All @@ -337,7 +338,7 @@ impl ScriptRunner {
.args(["/mnt", &path.to_string_lossy()])
.output()?
} else {
process::Command::new(&path).output()?
process::Command::new(path).output()?
};

fs::write(path.with_extension("log"), output.stdout)?;
Expand All @@ -348,12 +349,6 @@ impl ScriptRunner {
}
}

impl Default for ScriptRunner {
fn default() -> Self {
Self { chroot: false }
}
}

#[cfg(test)]
mod test {
use tempfile::TempDir;
Expand Down
3 changes: 1 addition & 2 deletions rust/agama-lib/src/software/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,8 @@ impl<'a> SoftwareClient<'a> {
resolvables: &[&str],
optional: bool,
) -> Result<(), ServiceError> {
let names: Vec<_> = resolvables.iter().map(|r| r.as_ref()).collect();
self.proposal_proxy
.set_resolvables(id, r#type as u8, &names, optional)
.set_resolvables(id, r#type as u8, resolvables, optional)
.await?;
Ok(())
}
Expand Down
8 changes: 3 additions & 5 deletions rust/agama-lib/src/users/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,13 @@ impl UsersStore {
full_name: settings.full_name.clone().unwrap_or_default(),
autologin: settings.autologin.unwrap_or_default(),
password: settings.password.clone().unwrap_or_default(),
encrypted_password: settings.encrypted_password.clone().unwrap_or_default(),
..Default::default()
encrypted_password: settings.encrypted_password.unwrap_or_default(),
};
self.users_client.set_first_user(&first_user).await?;
Ok(())
self.users_client.set_first_user(&first_user).await
}

async fn store_root_user(&self, settings: &RootUserSettings) -> Result<(), ServiceError> {
let encrypted_password = settings.encrypted_password.clone().unwrap_or_default();
let encrypted_password = settings.encrypted_password.unwrap_or_default();

if let Some(root_password) = &settings.password {
self.users_client
Expand Down
10 changes: 2 additions & 8 deletions rust/agama-server/src/l10n.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,10 @@
mod dbus;
pub mod error;
pub mod helpers;
mod keyboard;
pub mod l10n;
mod locale;
mod timezone;
mod model;
pub mod web;

pub use agama_lib::localization::model::LocaleConfig;
pub use dbus::export_dbus_objects;
pub use error::LocaleError;
pub use keyboard::Keymap;
pub use l10n::L10n;
pub use locale::LocaleEntry;
pub use timezone::TimezoneEntry;
pub use model::{Keymap, L10n, LocaleEntry, TimezoneEntry};
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,18 @@ use agama_locale_data::{KeymapId, LocaleId};
use regex::Regex;
use subprocess::{Popen, PopenConfig, PopenError, Redirection};

use super::keyboard::KeymapsDatabase;
use super::locale::LocalesDatabase;
use super::timezone::TimezonesDatabase;
pub mod keyboard;
pub mod locale;
pub mod timezone;

pub use keyboard::Keymap;
pub use locale::LocaleEntry;
pub use timezone::TimezoneEntry;

use super::{helpers, LocaleError};
use keyboard::KeymapsDatabase;
use locale::LocalesDatabase;
use timezone::TimezonesDatabase;

pub struct L10n {
pub timezone: String,
Expand Down
3 changes: 2 additions & 1 deletion rust/agama-server/src/l10n/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
//! This module implements the web API for the localization module.

use super::{
error::LocaleError, keyboard::Keymap, locale::LocaleEntry, timezone::TimezoneEntry, L10n,
error::LocaleError,
model::{keyboard::Keymap, locale::LocaleEntry, timezone::TimezoneEntry, L10n},
};
use crate::{
error::Error,
Expand Down
10 changes: 5 additions & 5 deletions rust/agama-server/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
//! D-Bus interfaces depending on its type:
//!
//! * `org.opensuse.Agama1.Network.Connection` exposes common information across all connection
//! types.
//! * `org.opensuse.Agama1.Network.Connection.IPv4` includes IPv4 settings, like the configuration method
//! (DHCP, manual, etc.), IP addresses, name servers and so on.
//! types.
//! * `org.opensuse.Agama1.Network.Connection.IPv4` includes IPv4 settings, like the configuration
//! method (DHCP, manual, etc.), IP addresses, name servers and so on.
//! * `org.opensuse.Agama1.Network.Connection.Wireless` exposes the configuration for wireless
//! connections.
//! connections.
//!
//! Analogous to the devices API, there is a special `/org/opensuse/Agama1/Network/connections`
//! object that implements a few methods that are related to the collection of connections like
Expand All @@ -55,7 +55,7 @@
//! them in mind:
//!
//! * The devices list does not reflect the changes in the system. For instance, it is not updated
//! when a device is connected to the system.
//! when a device is connected to the system.
//! * Many configuration types are still missing (bridges, bonding, etc.).

mod action;
Expand Down
2 changes: 1 addition & 1 deletion rust/agama-server/src/network/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
//! Representation of the network configuration
//!
//! * This module contains the types that represent the network concepts. They are supposed to be
//! agnostic from the real network service (e.g., NetworkManager).
//! agnostic from the real network service (e.g., NetworkManager).
use crate::network::error::NetworkStateError;
use agama_lib::network::settings::{
BondSettings, IEEE8021XSettings, NetworkConnection, WirelessSettings,
Expand Down
8 changes: 2 additions & 6 deletions rust/agama-server/src/network/nm/dbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,6 @@ fn bridge_config_from_dbus(conn: &OwnedNestedHash) -> Result<Option<BridgeConfig
hello_time: get_optional_property(bridge, "hello-time")?,
max_age: get_optional_property(bridge, "max-age")?,
ageing_time: get_optional_property(bridge, "ageing-time")?,
..Default::default()
}))
}

Expand All @@ -545,7 +544,6 @@ fn bridge_port_config_from_dbus(
Ok(Some(BridgePortConfig {
priority: get_optional_property(bridge_port, "priority")?,
path_cost: get_optional_property(bridge_port, "path_cost")?,
..Default::default()
}))
}

Expand Down Expand Up @@ -614,7 +612,6 @@ fn tun_config_from_dbus(conn: &OwnedNestedHash) -> Result<Option<TunConfig>, NmE
mode,
group: get_optional_property(tun, "group")?,
owner: get_optional_property(tun, "owner")?,
..Default::default()
}))
}

Expand Down Expand Up @@ -1329,7 +1326,7 @@ mod test {
metric: Some(100)
}]
);
assert_eq!(connection.autoconnect, false);
assert!(!connection.autoconnect);

Ok(())
}
Expand Down Expand Up @@ -1574,7 +1571,6 @@ mod test {
pairwise_algorithms: vec![PairwiseAlgorithm::Tkip, PairwiseAlgorithm::Ccmp],
wpa_protocol_versions: vec![WPAProtocolVersion::Wpa],
pmf: 1,
..Default::default()
};
let mut wireless = build_base_connection();
wireless.config = ConnectionConfig::Wireless(config);
Expand Down Expand Up @@ -1933,7 +1929,7 @@ mod test {
.unwrap()
.downcast_ref()
.unwrap();
assert_eq!(autoconnect, false);
assert!(!autoconnect);

let ethernet_connection = conn_dbus.get(ETHERNET_KEY).unwrap();
let mac_address: &str = ethernet_connection
Expand Down
2 changes: 2 additions & 0 deletions rust/agama-server/src/web/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ mod users;
pub use users::UsersApiDocBuilder;
mod misc;
pub use misc::MiscApiDocBuilder;
mod scripts;
pub use scripts::ScriptsApiDocBuilder;
pub mod common;

pub trait ApiDocBuilder {
Expand Down
5 changes: 3 additions & 2 deletions rust/agama-server/src/web/docs/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ use utoipa::openapi::{
};

/// Implements a builder for the issues API documentation.
#[derive(Default)]
pub struct IssuesApiDocBuilder {
paths: Vec<(String, PathItem)>,
}

impl IssuesApiDocBuilder {
pub fn new() -> Self {
Self { paths: vec![] }
Default::default()
}

/// Adds a new issues API path.
Expand All @@ -47,7 +48,7 @@ impl IssuesApiDocBuilder {
pub fn add(self, path: &str, summary: &str, operation_id: &str) -> Self {
let mut paths = self.paths;
paths.push((path.to_string(), Self::issues_path(summary, operation_id)));
Self { paths, ..self }
Self { paths }
}

fn issues_path(summary: &'_ str, operation_id: &'_ str) -> PathItem {
Expand Down
Loading