Skip to content

Commit

Permalink
Merge pull request #1 from openSUSE/master
Browse files Browse the repository at this point in the history
Issue agama-project#932 Fixed
  • Loading branch information
nagu165 authored Jan 1, 2024
2 parents 2ad5599 + d9b0131 commit f8f95ff
Show file tree
Hide file tree
Showing 44 changed files with 1,441 additions and 909 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/ci-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ jobs:
- name: Install Rust toolchains
run: rustup toolchain install stable

- name: Run clippy linter
run: cargo clippy

- name: Run rustfmt
run: cargo fmt --all -- --check

- name: Install cargo-binstall
uses: taiki-e/install-action@v2
with:
Expand All @@ -89,9 +95,6 @@ jobs:
- name: Run the tests
run: cargo tarpaulin --out xml

- name: Lint formatting
run: cargo fmt --all -- --check

# send the code coverage for the Rust part to the coveralls.io
- name: Coveralls GitHub Action
uses: coverallsapp/github-action@v2
Expand Down
5 changes: 3 additions & 2 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ members = [
"agama-derive",
"agama-lib",
"agama-locale-data",
"agama-settings"
"agama-settings",
]
resolver = "2"

[workspace.package]
rust-version = "1.74"
edition = "2021"
7 changes: 2 additions & 5 deletions rust/agama-cli/src/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ impl LogItem for LogCmd {

/// Collect existing / requested paths which should already exist in the system.
/// Turns them into list of log sources
fn paths_to_log_sources(paths: &Vec<String>, tmp_dir: &TempDir) -> Vec<Box<dyn LogItem>> {
fn paths_to_log_sources(paths: &[String], tmp_dir: &TempDir) -> Vec<Box<dyn LogItem>> {
let mut log_sources: Vec<Box<dyn LogItem>> = Vec::new();

for path in paths.iter() {
Expand All @@ -293,10 +293,7 @@ fn paths_to_log_sources(paths: &Vec<String>, tmp_dir: &TempDir) -> Vec<Box<dyn L
}

/// Some info can be collected via particular commands only, turn it into log sources
fn cmds_to_log_sources(
commands: &Vec<(String, String)>,
tmp_dir: &TempDir,
) -> Vec<Box<dyn LogItem>> {
fn cmds_to_log_sources(commands: &[(String, String)], tmp_dir: &TempDir) -> Vec<Box<dyn LogItem>> {
let mut log_sources: Vec<Box<dyn LogItem>> = Vec::new();

for cmd in commands.iter() {
Expand Down
6 changes: 4 additions & 2 deletions rust/agama-dbus-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
name = "agama-dbus-server"
version = "0.1.0"
edition = "2021"
rust-version.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0"
agama-locale-data = { path="../agama-locale-data" }
agama-lib = { path="../agama-lib" }
agama-locale-data = { path = "../agama-locale-data" }
agama-lib = { path = "../agama-lib" }
log = "0.4"
simplelog = "0.12.1"
systemd-journal-logger = "1.0"
Expand All @@ -25,3 +26,4 @@ gettext-rs = { version = "0.7.0", features = ["gettext-system"] }
regex = "1.10.2"
once_cell = "1.18.0"
macaddr = "1.0"
async-trait = "0.1.75"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,7 @@ mod tests {
fn test_read_timezone_without_country() {
let mut db = TimezonesDatabase::new();
db.read("es").unwrap();
let timezone = db
.entries()
.into_iter()
.find(|tz| tz.code == "UTC")
.unwrap();
let timezone = db.entries().iter().find(|tz| tz.code == "UTC").unwrap();
assert_eq!(timezone.country, None);
}

Expand All @@ -145,7 +141,7 @@ mod tests {
db.read("en").unwrap();
let timezone = db
.entries()
.into_iter()
.iter()
.find(|tz| tz.code == "Europe/Kiev")
.unwrap();
assert_eq!(timezone.country, Some("Ukraine".to_string()));
Expand Down
2 changes: 1 addition & 1 deletion rust/agama-dbus-server/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod error;
pub mod locale;
pub mod l10n;
pub mod network;
pub mod questions;
7 changes: 5 additions & 2 deletions rust/agama-dbus-server/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use agama_dbus_server::{locale, locale::helpers, network, questions};
use agama_dbus_server::{
l10n::{self, helpers},
network, questions,
};

use agama_lib::connection_to;
use anyhow::Context;
Expand Down Expand Up @@ -36,7 +39,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// When adding more services here, the order might be important.
questions::export_dbus_objects(&connection).await?;
log::info!("Started questions interface");
locale::export_dbus_objects(&connection, &locale).await?;
l10n::export_dbus_objects(&connection, &locale).await?;
log::info!("Started locale interface");
network::export_dbus_objects(&connection).await?;
log::info!("Started network interface");
Expand Down
21 changes: 18 additions & 3 deletions rust/agama-dbus-server/src/network/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::network::model::Connection;
use agama_lib::network::types::DeviceType;
use tokio::sync::oneshot;
use uuid::Uuid;
use zbus::zvariant::OwnedObjectPath;

use super::error::NetworkStateError;

Expand All @@ -15,19 +16,33 @@ pub type ControllerConnection = (Connection, Vec<String>);
#[derive(Debug)]
pub enum Action {
/// Add a new connection with the given name and type.
AddConnection(String, DeviceType),
AddConnection(
String,
DeviceType,
Responder<Result<OwnedObjectPath, NetworkStateError>>,
),
/// Gets a connection
GetConnection(Uuid, Responder<Option<Connection>>),
/// Gets a connection
GetConnectionPath(String, Responder<Option<OwnedObjectPath>>),
/// Get connections paths
GetConnectionsPaths(Responder<Vec<OwnedObjectPath>>),
/// Gets a controller connection
GetController(
Uuid,
Responder<Result<ControllerConnection, NetworkStateError>>,
),
/// Get devices paths
GetDevicesPaths(Responder<Vec<OwnedObjectPath>>),
/// Sets a controller's ports. It uses the Uuid of the controller and the IDs or interface names
/// of the ports.
SetPorts(Uuid, Vec<String>, Responder<Result<(), NetworkStateError>>),
SetPorts(
Uuid,
Box<Vec<String>>,
Responder<Result<(), NetworkStateError>>,
),
/// Update a connection (replacing the old one).
UpdateConnection(Connection),
UpdateConnection(Box<Connection>),
/// Remove the connection with the given Uuid.
RemoveConnection(String),
/// Apply the current configuration.
Expand Down
6 changes: 4 additions & 2 deletions rust/agama-dbus-server/src/network/adapter.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate::network::NetworkState;
use async_trait::async_trait;
use std::error::Error;

/// A trait for the ability to read/write from/to a network service
#[async_trait]
pub trait Adapter {
fn read(&self) -> Result<NetworkState, Box<dyn Error>>;
fn write(&self, network: &NetworkState) -> Result<(), Box<dyn Error>>;
async fn read(&self) -> Result<NetworkState, Box<dyn Error>>;
async fn write(&self, network: &NetworkState) -> Result<(), Box<dyn Error>>;
}
2 changes: 1 addition & 1 deletion rust/agama-dbus-server/src/network/dbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ pub mod service;
mod tree;

pub use service::NetworkService;
pub(crate) use tree::{ObjectsRegistry, Tree};
pub(crate) use tree::Tree;
Loading

0 comments on commit f8f95ff

Please sign in to comment.