Prevent default rules from being deleted

This commit is contained in:
Pierre HUBERT 2024-01-02 15:58:39 +01:00
parent 06ddf57b5c
commit 2b145ebeff

View File

@ -100,6 +100,13 @@ pub async fn update(
/// Delete a network filter /// Delete a network filter
pub async fn delete(client: LibVirtReq, path: web::Path<NetworkFilterID>) -> HttpResult { pub async fn delete(client: LibVirtReq, path: web::Path<NetworkFilterID>) -> HttpResult {
// Prevent deletion of default rules
let network = client.get_single_network_filter(path.uid).await?;
if constants::BUILTIN_NETWORK_FILTER_RULES.contains(&network.name.as_str()) {
return Ok(HttpResponse::ExpectationFailed()
.json("Builtin network filter rules shall not be deleted!"));
}
client.delete_network_filter(path.uid).await?; client.delete_network_filter(path.uid).await?;
Ok(HttpResponse::Ok().json("Network deleted")) Ok(HttpResponse::Ok().json("Network deleted"))