/// The caller also responsible for locking the configuration files.
/// Returns a `HttpError` if:
/// - an entity with the same name already exists (`400 Bad request`)
-/// - a referenced filter does not exist (`400 Bad request`)
/// - the configuration could not be saved (`500 Internal server error`)
/// - mailto *and* mailto_user are both set to `None`
pub fn add_endpoint(config: &mut Config, endpoint: &SendmailConfig) -> Result<(), HttpError> {
super::ensure_unique(config, &endpoint.name)?;
- if let Some(filter) = &endpoint.filter {
- // Check if filter exists
- super::filter::get_filter(config, filter)?;
- }
-
if endpoint.mailto.is_none() && endpoint.mailto_user.is_none() {
http_bail!(
BAD_REQUEST,
/// The caller is responsible for any needed permission checks.
/// The caller also responsible for locking the configuration files.
/// Returns a `HttpError` if:
-/// - a referenced filter does not exist (`400 Bad request`)
/// - the configuration could not be saved (`500 Internal server error`)
/// - mailto *and* mailto_user are both set to `None`
pub fn update_endpoint(
DeleteableSendmailProperty::FromAddress => endpoint.from_address = None,
DeleteableSendmailProperty::Author => endpoint.author = None,
DeleteableSendmailProperty::Comment => endpoint.comment = None,
- DeleteableSendmailProperty::Filter => endpoint.filter = None,
DeleteableSendmailProperty::Mailto => endpoint.mailto = None,
DeleteableSendmailProperty::MailtoUser => endpoint.mailto_user = None,
+ DeleteableSendmailProperty::Disable => endpoint.disable = None,
}
}
}
endpoint.comment = Some(comment.into());
}
- if let Some(filter) = &updater.filter {
- let _ = super::filter::get_filter(config, filter)?;
- endpoint.filter = Some(filter.into());
+ if let Some(disable) = &updater.disable {
+ endpoint.disable = Some(*disable);
}
if endpoint.mailto.is_none() && endpoint.mailto_user.is_none() {
pub fn delete_endpoint(config: &mut Config, name: &str) -> Result<(), HttpError> {
// Check if the endpoint exists
let _ = get_endpoint(config, name)?;
- super::ensure_unused(config, name)?;
+ super::ensure_safe_to_delete(config, name)?;
config.config.sections.remove(name);
Ok(())
}
-#[cfg(test)]
+#[cfg(all(feature = "pve-context", test))]
pub mod tests {
use super::*;
use crate::api::test_helpers::*;
author: Some("root".into()),
comment: Some("Comment".into()),
filter: None,
+ ..Default::default()
},
)?;
fn test_sendmail_create() -> Result<(), HttpError> {
let mut config = empty_config();
- assert_eq!(get_endpoints(&config)?.len(), 0);
add_sendmail_endpoint_for_test(&mut config, "sendmail-endpoint")?;
// Endpoints must have a unique name
assert!(add_sendmail_endpoint_for_test(&mut config, "sendmail-endpoint").is_err());
- assert_eq!(get_endpoints(&config)?.len(), 1);
Ok(())
}
from_address: Some("root@example.com".into()),
author: Some("newauthor".into()),
comment: Some("new comment".into()),
- filter: None,
+ ..Default::default()
},
None,
Some(&[0; 32]),
from_address: Some("root@example.com".into()),
author: Some("newauthor".into()),
comment: Some("new comment".into()),
- filter: None,
+ ..Default::default()
},
None,
Some(&digest),
delete_endpoint(&mut config, "sendmail-endpoint")?;
assert!(delete_endpoint(&mut config, "sendmail-endpoint").is_err());
- assert_eq!(get_endpoints(&config)?.len(), 0);
Ok(())
}