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] notify: switch to proxmox-base64
Date: Mon, 26 May 2025 11:52:20 +0200	[thread overview]
Message-ID: <20250526095220.132201-1-l.wagner@proxmox.com> (raw)

This also fixes any warnings that were shown during compilation because
we were using the deprecated `base64::encode/decode` functions.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
Intended for the trixie bootstrap work on the master branch.

Notes:
    Could probably also use the serde helpers from proxmox-base64 to
    deserialize the KeyAndBase64 val struct, but I'd rather do this
    separately.

 proxmox-notify/Cargo.toml               | 6 +++---
 proxmox-notify/src/api/webhook.rs       | 8 +++-----
 proxmox-notify/src/endpoints/webhook.rs | 8 ++++----
 3 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/proxmox-notify/Cargo.toml b/proxmox-notify/Cargo.toml
index 471eaf23..920224ef 100644
--- a/proxmox-notify/Cargo.toml
+++ b/proxmox-notify/Cargo.toml
@@ -13,7 +13,6 @@ rust-version.workspace = true
 
 [dependencies]
 anyhow.workspace = true
-base64 = { workspace = true, optional = true }
 const_format.workspace = true
 handlebars = { workspace = true }
 http = { workspace = true, optional = true }
@@ -26,6 +25,7 @@ regex.workspace = true
 serde = { workspace = true, features = ["derive"] }
 serde_json.workspace = true
 
+proxmox-base64 = { workspace = true, optional = true }
 proxmox-http = { workspace = true, features = ["client-sync"], optional = true }
 proxmox-http-error.workspace = true
 proxmox-human-byte.workspace = true
@@ -40,9 +40,9 @@ proxmox-uuid = { workspace = true, features = ["serde"] }
 [features]
 default = ["sendmail", "gotify", "smtp", "webhook"]
 mail-forwarder = ["dep:mail-parser", "dep:proxmox-sys", "proxmox-sendmail/mail-forwarder"]
-sendmail = ["dep:proxmox-sys", "dep:base64", "dep:proxmox-sendmail"]
+sendmail = ["dep:proxmox-sys", "dep:proxmox-sendmail"]
 gotify = ["dep:proxmox-http", "dep:http"]
 pve-context = ["dep:proxmox-sys"]
 pbs-context = ["dep:proxmox-sys"]
 smtp = ["dep:lettre"]
-webhook = ["dep:base64", "dep:http", "dep:percent-encoding", "dep:proxmox-http"]
+webhook = ["dep:http", "dep:percent-encoding", "dep:proxmox-base64", "dep:proxmox-http"]
diff --git a/proxmox-notify/src/api/webhook.rs b/proxmox-notify/src/api/webhook.rs
index 31c5c869..9d904d0b 100644
--- a/proxmox-notify/src/api/webhook.rs
+++ b/proxmox-notify/src/api/webhook.rs
@@ -294,8 +294,6 @@ mod tests {
     use super::*;
     use crate::{api::test_helpers::empty_config, endpoints::webhook::HttpMethod};
 
-    use base64::encode;
-
     pub fn add_default_webhook_endpoint(config: &mut Config) -> Result<(), HttpError> {
         add_endpoint(
             config,
@@ -308,7 +306,7 @@ mod tests {
                     "application/json",
                 )
                 .into()],
-                body: Some(encode("this is the body")),
+                body: Some(proxmox_base64::encode("this is the body")),
                 comment: Some("comment".into()),
                 disable: Some(false),
                 secret: vec![KeyAndBase64Val::new_with_plain_value("token", "secret").into()],
@@ -388,9 +386,9 @@ mod tests {
             .secret;
 
         assert_eq!(secrets[1].name, "token".to_string());
-        assert_eq!(secrets[1].value, Some(encode("secret")));
+        assert_eq!(secrets[1].value, Some(proxmox_base64::encode("secret")));
         assert_eq!(secrets[0].name, "token2".to_string());
-        assert_eq!(secrets[0].value, Some(encode("newsecret")));
+        assert_eq!(secrets[0].value, Some(proxmox_base64::encode("newsecret")));
 
         // Test property deletion
         update_endpoint(
diff --git a/proxmox-notify/src/endpoints/webhook.rs b/proxmox-notify/src/endpoints/webhook.rs
index a210b94c..0167efcf 100644
--- a/proxmox-notify/src/endpoints/webhook.rs
+++ b/proxmox-notify/src/endpoints/webhook.rs
@@ -200,7 +200,7 @@ pub struct KeyAndBase64Val {
 impl KeyAndBase64Val {
     #[cfg(test)]
     pub fn new_with_plain_value(name: &str, value: &str) -> Self {
-        let value = base64::encode(value);
+        let value = proxmox_base64::encode(value);
 
         Self {
             name: name.into(),
@@ -214,7 +214,7 @@ impl KeyAndBase64Val {
     /// text.
     pub fn decode_value(&self) -> Result<String, Error> {
         let value = self.value.as_deref().unwrap_or_default();
-        let bytes = base64::decode(value).map_err(|_| {
+        let bytes = proxmox_base64::decode(value).map_err(|_| {
             Error::Generic(format!(
                 "could not decode base64 value with key '{}'",
                 self.name
@@ -374,7 +374,7 @@ impl WebhookEndpoint {
 
     fn base64_decode(&self, s: &str) -> Result<String, Error> {
         // Also here, TODO: revisit Error variants for the *whole* crate.
-        let s = base64::decode(s)
+        let s = proxmox_base64::decode(s)
             .map_err(|err| Error::Generic(format!("could not decode base64 value: {err}")))?;
 
         String::from_utf8(s).map_err(|err| {
@@ -549,7 +549,7 @@ hello%20world
                 header: vec![
                     KeyAndBase64Val::new_with_plain_value("X-Severity", "{{ severity }}").into(),
                 ],
-                body: Some(base64::encode(body_template)),
+                body: Some(proxmox_base64::encode(body_template)),
                 ..Default::default()
             },
             private_config: WebhookPrivateConfig {
-- 
2.39.5



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


             reply	other threads:[~2025-05-26  9:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-26  9:52 Lukas Wagner [this message]
2025-05-26 14:01 ` [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=20250526095220.132201-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