release: NX9-WG v1.0.0
This commit is contained in:
1 parent
c8a9b7cde6
commit
4dfe42fe68
42 files changed
+4689
-336
No files matched your search
@@ -38,6 +38,7 @@ pub struct UpdateInterfaceRequest {
|
||||
pub address_v6: Option<String>,
|
||||
pub mtu: Option<u16>,
|
||||
pub dns: Option<String>,
|
||||
pub enabled: Option<bool>,
|
||||
pub pre_up: Option<String>,
|
||||
pub post_up: Option<String>,
|
||||
pub pre_down: Option<String>,
|
||||
@@ -144,8 +145,18 @@ pub async fn update_interface_handler(
|
||||
.ok_or_else(|| ApiError::NotFound(format!("Interface '{id}' not found")))?;
|
||||
|
||||
if let Some(ref name) = payload.name {
|
||||
validate_interface_name(name)?;
|
||||
iface.name = name.clone();
|
||||
let trimmed = name.trim();
|
||||
validate_interface_name(trimmed)?;
|
||||
if iface.name != trimmed {
|
||||
if let Ok(Some(existing)) = state.store.get_interface_by_name(trimmed).await
|
||||
&& existing.id != iface.id
|
||||
{
|
||||
return Err(ApiError::Validation(format!(
|
||||
"Interface with name '{trimmed}' already exists"
|
||||
)));
|
||||
}
|
||||
iface.name = trimmed.to_string();
|
||||
}
|
||||
}
|
||||
if let Some(port) = payload.listen_port {
|
||||
validate_listen_port(port)?;
|
||||
@@ -155,14 +166,25 @@ pub async fn update_interface_handler(
|
||||
iface.address_v4 = validate_cidr(v4)?;
|
||||
}
|
||||
if let Some(ref v6) = payload.address_v6 {
|
||||
iface.address_v6 = Some(validate_cidr(v6)?);
|
||||
if v6.trim().is_empty() {
|
||||
iface.address_v6 = None;
|
||||
} else {
|
||||
iface.address_v6 = Some(validate_cidr(v6.trim())?);
|
||||
}
|
||||
}
|
||||
if let Some(m) = payload.mtu {
|
||||
validate_mtu(m)?;
|
||||
iface.mtu = Some(m);
|
||||
}
|
||||
if let Some(ref dns) = payload.dns {
|
||||
iface.dns = Some(dns.clone());
|
||||
if dns.trim().is_empty() {
|
||||
iface.dns = None;
|
||||
} else {
|
||||
iface.dns = Some(dns.trim().to_string());
|
||||
}
|
||||
}
|
||||
if let Some(en) = payload.enabled {
|
||||
iface.enabled = en;
|
||||
}
|
||||
if payload.pre_up.is_some() {
|
||||
iface.pre_up = payload.pre_up;
|
||||
@@ -177,6 +199,8 @@ pub async fn update_interface_handler(
|
||||
iface.post_down = payload.post_down;
|
||||
}
|
||||
|
||||
iface.updated_at = Utc::now().naive_utc();
|
||||
|
||||
state.store.update_interface(&iface).await?;
|
||||
|
||||
state.broadcast(SystemEvent::InterfaceChanged {
|
||||
|
||||
Reference in new issue
Block a user