Add oauth2-client-secret and oauth2-refresh-token to POST and PUT
endpoints for SMTP notifications and pass them along to the
proxmox-notify functions.

The non-private parameters oauth2-client-id and oauth2-tenant-id are
passed as part of the SmtpConfig struct.

Signed-off-by: Arthur Bied-Charreton <[email protected]>
---
 src/api2/config/notifications/smtp.rs | 36 ++++++++++++++++++++++++---
 1 file changed, 33 insertions(+), 3 deletions(-)

diff --git a/src/api2/config/notifications/smtp.rs 
b/src/api2/config/notifications/smtp.rs
index 8df2ab18c..4d88bd659 100644
--- a/src/api2/config/notifications/smtp.rs
+++ b/src/api2/config/notifications/smtp.rs
@@ -72,7 +72,15 @@ pub fn get_endpoint(name: String, rpcenv: &mut dyn 
RpcEnvironment) -> Result<Smt
             password: {
                 optional: true,
                 description: "SMTP authentication password"
-            }
+            },
+            "oauth2-client-secret": {
+                optional: true,
+                description: "Client secret for SMTP XOAUTH2"
+            },
+            "oauth2-refresh-token": {
+                optional: true,
+                description: "Refresh token for SMTP XOAUTH2"
+            },
         },
     },
     access: {
@@ -83,6 +91,8 @@ pub fn get_endpoint(name: String, rpcenv: &mut dyn 
RpcEnvironment) -> Result<Smt
 pub fn add_endpoint(
     endpoint: SmtpConfig,
     password: Option<String>,
+    oauth2_client_secret: Option<String>,
+    oauth2_refresh_token: Option<String>,
     _rpcenv: &mut dyn RpcEnvironment,
 ) -> Result<(), Error> {
     let _lock = pbs_config::notifications::lock_config()?;
@@ -90,9 +100,15 @@ pub fn add_endpoint(
     let private_endpoint_config = SmtpPrivateConfig {
         name: endpoint.name.clone(),
         password,
+        oauth2_client_secret,
     };
 
-    proxmox_notify::api::smtp::add_endpoint(&mut config, endpoint, 
private_endpoint_config)?;
+    proxmox_notify::api::smtp::add_endpoint(
+        &mut config,
+        endpoint,
+        private_endpoint_config,
+        oauth2_refresh_token,
+    )?;
 
     pbs_config::notifications::save_config(config)?;
     Ok(())
@@ -113,6 +129,14 @@ pub fn add_endpoint(
                 description: "SMTP authentication password",
                 optional: true,
             },
+            "oauth2-client-secret": {
+                optional: true,
+                description: "Client secret for SMTP XOAUTH2"
+            },
+            "oauth2-refresh-token": {
+                optional: true,
+                description: "Refresh token for SMTP XOAUTH2"
+            },
             delete: {
                 description: "List of properties to delete.",
                 type: Array,
@@ -136,6 +160,8 @@ pub fn update_endpoint(
     name: String,
     updater: SmtpConfigUpdater,
     password: Option<String>,
+    oauth2_client_secret: Option<String>,
+    oauth2_refresh_token: Option<String>,
     delete: Option<Vec<DeleteableSmtpProperty>>,
     digest: Option<String>,
     _rpcenv: &mut dyn RpcEnvironment,
@@ -148,7 +174,11 @@ pub fn update_endpoint(
         &mut config,
         &name,
         updater,
-        SmtpPrivateConfigUpdater { password },
+        SmtpPrivateConfigUpdater {
+            password,
+            oauth2_client_secret,
+        },
+        oauth2_refresh_token,
         delete.as_deref(),
         digest.as_deref(),
     )?;
-- 
2.47.3



Reply via email to