Skip to content

Commit

Permalink
Use 'id' instead of 'name' to identify network connections
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Jul 4, 2023
1 parent 08351ea commit 0aea744
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion rust/agama-lib/share/examples/profile.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"network": {
"connections": [
{
"name": "Ethernet network device 1",
"id": "Ethernet network device 1",
"method": "manual",
"addresses": [
"192.168.122.100/24"
Expand Down
4 changes: 2 additions & 2 deletions rust/agama-lib/share/examples/profile.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ local findBiggestDisk(disks) =
network: {
connections: [
{
name: 'AgamaNetwork',
id: 'AgamaNetwork',
wireless: {
password: 'agama.test',
security: 'wpa-psk',
ssid: 'AgamaNetwork'
}
},
{
name: 'Etherned device 1',
id: 'Etherned device 1',
method: 'manual',
gateway: '192.168.122.1',
addresses: [
Expand Down
4 changes: 2 additions & 2 deletions rust/agama-lib/share/profile.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"type": "object",
"additionalProperties": false,
"properties": {
"name": {
"id": {
"description": "Connection ID",
"type": "string"
},
Expand Down Expand Up @@ -89,7 +89,7 @@
}
},
"required": [
"name"
"id"
]
}
}
Expand Down
10 changes: 5 additions & 5 deletions rust/agama-lib/src/network/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl<'a> NetworkClient<'a> {
.path(path)?
.build()
.await?;
let name = connection_proxy.id().await?;
let id = connection_proxy.id().await?;

let ipv4_proxy = IPv4Proxy::builder(&self.connection)
.path(path)?
Expand All @@ -68,7 +68,7 @@ impl<'a> NetworkClient<'a> {
let addresses = ipv4_proxy.addresses().await?;

Ok(NetworkConnection {
name,
id,
method: Some(method.to_string()),
gateway,
addresses,
Expand Down Expand Up @@ -105,7 +105,7 @@ impl<'a> NetworkClient<'a> {
&self,
conn: &NetworkConnection,
) -> Result<(), ServiceError> {
let path = match self.connections_proxy.get_connection(&conn.name).await {
let path = match self.connections_proxy.get_connection(&conn.id).await {
Ok(path) => path,
Err(_) => self.add_connection(&conn).await?,
};
Expand All @@ -121,9 +121,9 @@ impl<'a> NetworkClient<'a> {
conn: &NetworkConnection,
) -> Result<OwnedObjectPath, ServiceError> {
self.connections_proxy
.add_connection(&conn.name, conn.device_type() as u8)
.add_connection(&conn.id, conn.device_type() as u8)
.await?;
Ok(self.connections_proxy.get_connection(&conn.name).await?)
Ok(self.connections_proxy.get_connection(&conn.id).await?)
}

/// Updates a network connection.
Expand Down
14 changes: 7 additions & 7 deletions rust/agama-lib/src/network/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub struct WirelessSettings {

#[derive(Clone, Debug, Default, Serialize, Deserialize)]
pub struct NetworkConnection {
pub name: String,
pub id: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub method: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -73,15 +73,15 @@ impl TryFrom<SettingObject> for NetworkConnection {
type Error = &'static str;

fn try_from(value: SettingObject) -> Result<Self, Self::Error> {
let Some(name) = value.get("name") else {
return Err("The 'name' key is missing");
let Some(id) = value.get("id") else {
return Err("The 'id' key is missing");
};

let default_method = SettingValue("disabled".to_string());
let method = value.get("method").unwrap_or(&default_method);

let conn = NetworkConnection {
name: name.clone().try_into()?,
id: id.clone().try_into()?,
method: method.clone().try_into()?,
..Default::default()
};
Expand Down Expand Up @@ -112,7 +112,7 @@ mod tests {
fn test_add_connection_to_setting() {
let name = SettingValue("Ethernet 1".to_string());
let method = SettingValue("auto".to_string());
let conn = HashMap::from([("name".to_string(), name), ("method".to_string(), method)]);
let conn = HashMap::from([("id".to_string(), name), ("method".to_string(), method)]);
let conn = SettingObject(conn);

let mut settings = NetworkSettings::default();
Expand All @@ -124,10 +124,10 @@ mod tests {
fn test_setting_object_to_network_connection() {
let name = SettingValue("Ethernet 1".to_string());
let method = SettingValue("auto".to_string());
let settings = HashMap::from([("name".to_string(), name), ("method".to_string(), method)]);
let settings = HashMap::from([("id".to_string(), name), ("method".to_string(), method)]);
let settings = SettingObject(settings);
let conn: NetworkConnection = settings.try_into().unwrap();
assert_eq!(conn.name, "Ethernet 1");
assert_eq!(conn.id, "Ethernet 1");
assert_eq!(conn.method, Some("auto".to_string()));
}
}

0 comments on commit 0aea744

Please sign in to comment.