public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH proxmox] notify: switch to proxmox-base64
@ 2025-05-26  9:52 Lukas Wagner
  2025-05-26 14:01 ` [pve-devel] applied: " Thomas Lamprecht
  0 siblings, 1 reply; 2+ messages in thread
From: Lukas Wagner @ 2025-05-26  9:52 UTC (permalink / raw)
  To: pve-devel

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [pve-devel] applied: [PATCH proxmox] notify: switch to proxmox-base64
  2025-05-26  9:52 [pve-devel] [PATCH proxmox] notify: switch to proxmox-base64 Lukas Wagner
@ 2025-05-26 14:01 ` Thomas Lamprecht
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Lamprecht @ 2025-05-26 14:01 UTC (permalink / raw)
  To: pve-devel, Lukas Wagner

On Mon, 26 May 2025 11:52:20 +0200, Lukas Wagner wrote:
> This also fixes any warnings that were shown during compilation because
> we were using the deprecated `base64::encode/decode` functions.
> 
> 

Applied, thanks!

[1/1] notify: switch to proxmox-base64
      commit: 6fdd2353d37f9ee83640f05d0a40a2b87d9ad8e9


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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-05-26 14:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-26  9:52 [pve-devel] [PATCH proxmox] notify: switch to proxmox-base64 Lukas Wagner
2025-05-26 14:01 ` [pve-devel] applied: " Thomas Lamprecht

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