public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Lukas Wagner <l.wagner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH proxmox-mail-forward] do not forward on PBS systems if co-installed with PVE
Date: Tue, 21 Nov 2023 16:53:03 +0100	[thread overview]
Message-ID: <20231121155303.284443-1-l.wagner@proxmox.com> (raw)

With the newly built-in targets/matchers, we should not add
a target/matcher manually any more. In fact, this broke mail
forwarding on PBS because 'default-matcher' already existed as a
built-in and could thus not be created.
We now simply do an early return.

Also initialize notify-context before instantiating the config,
since that already requires the context to be set.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 src/main.rs | 38 ++++++++++++++------------------------
 1 file changed, 14 insertions(+), 24 deletions(-)

diff --git a/src/main.rs b/src/main.rs
index e56bc1e..4662ffa 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -25,8 +25,6 @@ use anyhow::Error;
 
 use proxmox_notify::context::pbs::PBS_CONTEXT;
 use proxmox_notify::context::pve::PVE_CONTEXT;
-use proxmox_notify::endpoints::sendmail::SendmailConfig;
-use proxmox_notify::matcher::MatcherConfig;
 use proxmox_notify::Config;
 use proxmox_sys::fs;
 
@@ -74,48 +72,40 @@ fn forward_common(mail: &[u8], config: &Config) -> Result<(), Error> {
 
 /// Forward a mail to PVE's notification system
 fn forward_for_pve(mail: &[u8]) -> Result<(), Error> {
+    proxmox_notify::context::set_context(&PVE_CONTEXT);
     let config = attempt_file_read(PVE_PUB_NOTIFICATION_CFG_FILENAME).unwrap_or_default();
     let priv_config = attempt_file_read(PVE_PRIV_NOTIFICATION_CFG_FILENAME).unwrap_or_default();
 
     let config = Config::new(&config, &priv_config)?;
 
-    proxmox_notify::context::set_context(&PVE_CONTEXT);
     forward_common(mail, &config)
 }
 
 /// Forward a mail to PBS's notification system
 fn forward_for_pbs(mail: &[u8], has_pve: bool) -> Result<(), Error> {
+    proxmox_notify::context::set_context(&PBS_CONTEXT);
+
     let config = if Path::new(PBS_PUB_NOTIFICATION_CFG_FILENAME).exists() {
         let config = attempt_file_read(PBS_PUB_NOTIFICATION_CFG_FILENAME).unwrap_or_default();
         let priv_config = attempt_file_read(PBS_PRIV_NOTIFICATION_CFG_FILENAME).unwrap_or_default();
 
         Config::new(&config, &priv_config)?
     } else {
-        // TODO: This can be removed once PBS has full notification integration
-        let mut config = Config::new("", "")?;
-        if !has_pve {
-            proxmox_notify::api::sendmail::add_endpoint(
-                &mut config,
-                &SendmailConfig {
-                    name: "default-target".to_string(),
-                    mailto_user: Some(vec!["root@pam".to_string()]),
-                    ..Default::default()
-                },
-            )?;
-
-            proxmox_notify::api::matcher::add_matcher(
-                &mut config,
-                &MatcherConfig {
-                    name: "default-matcher".to_string(),
-                    target: Some(vec!["default-target".to_string()]),
-                    ..Default::default()
-                },
-            )?;
+        // Instantiate empty config.
+        // Note: This will contain the default built-in targets/matchers.
+        let config = Config::new("", "")?;
+        if has_pve {
+            // Skip forwarding if we are co-installed with PVE AND
+            // we do not have our own notifications.cfg file yet
+            // --> We assume that PVE has a sane matcher configured that
+            // forwards the mail properly
+            // TODO: This can be removed once PBS has full notification integration
+
+            return Ok(());
         }
         config
     };
 
-    proxmox_notify::context::set_context(&PBS_CONTEXT);
     forward_common(mail, &config)?;
 
     Ok(())
-- 
2.39.2





             reply	other threads:[~2023-11-21 15:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-21 15:53 Lukas Wagner [this message]
2023-11-21 16:32 ` [pve-devel] applied: " Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231121155303.284443-1-l.wagner@proxmox.com \
    --to=l.wagner@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal