From b27645f23e9a3be2b44d4a2f396d8164abe0b9a4 Mon Sep 17 00:00:00 2001 From: Jorik Cronenberg Date: Tue, 5 Dec 2023 12:22:51 +0100 Subject: [PATCH] Move MacAddress string conversion to dbus interface --- rust/agama-dbus-server/src/network/dbus/interfaces.rs | 8 +++++--- rust/agama-dbus-server/src/network/model.rs | 5 ++--- rust/agama-dbus-server/src/network/nm/dbus.rs | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/rust/agama-dbus-server/src/network/dbus/interfaces.rs b/rust/agama-dbus-server/src/network/dbus/interfaces.rs index 9e101dbae9..23ebdbb784 100644 --- a/rust/agama-dbus-server/src/network/dbus/interfaces.rs +++ b/rust/agama-dbus-server/src/network/dbus/interfaces.rs @@ -6,11 +6,13 @@ use super::ObjectsRegistry; use crate::network::{ action::Action, error::NetworkStateError, - model::{Connection as NetworkConnection, Device as NetworkDevice, WirelessConnection}, + model::{ + Connection as NetworkConnection, Device as NetworkDevice, MacAddress, WirelessConnection, + }, }; use agama_lib::network::types::SSID; -use std::sync::Arc; +use std::{str::FromStr, sync::Arc}; use tokio::sync::mpsc::UnboundedSender; use tokio::sync::{MappedMutexGuard, Mutex, MutexGuard}; use zbus::{ @@ -248,7 +250,7 @@ impl Connection { #[dbus_interface(property)] pub async fn set_mac_address(&mut self, mac_address: &str) -> zbus::fdo::Result<()> { let mut connection = self.get_connection().await; - connection.set_mac_address(mac_address)?; + connection.set_mac_address(MacAddress::from_str(mac_address)?); self.update_connection(connection).await } } diff --git a/rust/agama-dbus-server/src/network/model.rs b/rust/agama-dbus-server/src/network/model.rs index f38c0c32a7..b413284999 100644 --- a/rust/agama-dbus-server/src/network/model.rs +++ b/rust/agama-dbus-server/src/network/model.rs @@ -319,9 +319,8 @@ impl Connection { self.base().mac_address.to_string() } - pub fn set_mac_address(&mut self, mac_address: &str) -> Result<(), InvalidMacAddress> { - self.base_mut().mac_address = MacAddress::from_str(mac_address)?; - Ok(()) + pub fn set_mac_address(&mut self, mac_address: MacAddress) { + self.base_mut().mac_address = mac_address; } } diff --git a/rust/agama-dbus-server/src/network/nm/dbus.rs b/rust/agama-dbus-server/src/network/nm/dbus.rs index b941a7964e..11cc97c19a 100644 --- a/rust/agama-dbus-server/src/network/nm/dbus.rs +++ b/rust/agama-dbus-server/src/network/nm/dbus.rs @@ -863,7 +863,7 @@ mod test { let mut updated = Connection::Ethernet(EthernetConnection::default()); updated.set_interface(""); - assert!(updated.set_mac_address("").is_ok()); + updated.set_mac_address(MacAddress::Unset); let updated = connection_to_dbus(&updated); let merged = merge_dbus_connections(&original, &updated);