From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 108E7E7D2 for ; Wed, 19 Jul 2023 12:10:04 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id DB5635689 for ; Wed, 19 Jul 2023 12:10:03 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Wed, 19 Jul 2023 12:10:03 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 0579D40EE9 for ; Wed, 19 Jul 2023 12:10:03 +0200 (CEST) Date: Wed, 19 Jul 2023 12:10:02 +0200 From: Wolfgang Bumiller To: Lukas Wagner Cc: pve-devel@lists.proxmox.com Message-ID: References: <20230717150051.710464-1-l.wagner@proxmox.com> <20230717150051.710464-25-l.wagner@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230717150051.710464-25-l.wagner@proxmox.com> X-SPAM-LEVEL: Spam detection results: 0 AWL 0.118 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [notify.rs, lib.rs, genpackage.pl] Subject: Re: [pve-devel] [PATCH v3 proxmox-perl-rs 24/66] add PVE::RS::Notify module X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 19 Jul 2023 10:10:04 -0000 On Mon, Jul 17, 2023 at 05:00:09PM +0200, Lukas Wagner wrote: > Signed-off-by: Lukas Wagner > --- > pve-rs/Cargo.toml | 1 + > pve-rs/Makefile | 1 + > pve-rs/src/lib.rs | 1 + > pve-rs/src/notify.rs | 71 ++++++++++++++++++++++++++++++++++++++++++++ > 4 files changed, 74 insertions(+) > create mode 100644 pve-rs/src/notify.rs > > diff --git a/pve-rs/Cargo.toml b/pve-rs/Cargo.toml > index 3076a13..b28c118 100644 > --- a/pve-rs/Cargo.toml > +++ b/pve-rs/Cargo.toml > @@ -34,6 +34,7 @@ perlmod = { version = "0.13", features = [ "exporter" ] } > > proxmox-apt = "0.10" > proxmox-http = { version = "0.9", features = ["client-sync", "client-trait"] } > +proxmox-notify = "0.1" > proxmox-openid = "0.10" > proxmox-resource-scheduling = "0.3.0" > proxmox-subscription = "0.4" > diff --git a/pve-rs/Makefile b/pve-rs/Makefile > index de35c69..9d737c0 100644 > --- a/pve-rs/Makefile > +++ b/pve-rs/Makefile > @@ -27,6 +27,7 @@ PERLMOD_GENPACKAGE := /usr/lib/perlmod/genpackage.pl \ > > PERLMOD_PACKAGES := \ > PVE::RS::APT::Repositories \ > + PVE::RS::Notify \ > PVE::RS::OpenId \ > PVE::RS::ResourceScheduling::Static \ > PVE::RS::TFA > diff --git a/pve-rs/src/lib.rs b/pve-rs/src/lib.rs > index eb6ae02..0d63c28 100644 > --- a/pve-rs/src/lib.rs > +++ b/pve-rs/src/lib.rs > @@ -4,6 +4,7 @@ > pub mod common; > > pub mod apt; > +pub mod notify; > pub mod openid; > pub mod resource_scheduling; > pub mod tfa; > diff --git a/pve-rs/src/notify.rs b/pve-rs/src/notify.rs > new file mode 100644 > index 0000000..9677d8b > --- /dev/null > +++ b/pve-rs/src/notify.rs > @@ -0,0 +1,71 @@ > +#[perlmod::package(name = "PVE::RS::Notify")] > +mod export { > + use anyhow::{bail, Error}; > + use perlmod::Value; > + > + use std::sync::Mutex; > + > + use proxmox_notify::Config; > + > + pub struct NotificationConfig { > + config: Mutex, > + } > + > + perlmod::declare_magic!(Box : &NotificationConfig as "PVE::RS::Notify"); > + > + /// Support `dclone` so this can be put into the `ccache` of `PVE::Cluster`. > + #[export(name = "STORABLE_freeze", raw_return)] > + fn storable_freeze( > + #[try_from_ref] this: &NotificationConfig, > + cloning: bool, > + ) -> Result { > + if !cloning { > + bail!("freezing Notification config not supported!"); > + } > + > + let mut cloned = Box::new(NotificationConfig { > + config: Mutex::new(this.config.lock().unwrap().clone()), > + }); > + let value = Value::new_pointer::(&mut *cloned); > + let _perl = Box::leak(cloned); > + Ok(value) > + } > + > + /// Instead of `thaw` we implement `attach` for `dclone`. > + #[export(name = "STORABLE_attach", raw_return)] > + fn storable_attach( > + #[raw] class: Value, > + cloning: bool, > + #[raw] serialized: Value, > + ) -> Result { > + if !cloning { > + bail!("STORABLE_attach called with cloning=false"); > + } > + let data = unsafe { Box::from_raw(serialized.pv_raw::()?) }; > + Ok(perlmod::instantiate_magic!(&class, MAGIC => data)) > + } > + > + #[export(raw_return)] > + fn parse_config( > + #[raw] class: Value, > + raw_config: &str, > + raw_private_config: &str, I half-suspect that using &[u8] here - since that's what perl *actually* gives us if we just read the data out of files without setting the mode to 'utf8' or anything - might just fix the emoji issues. Alternatively, perl would have to actually declare an encoding ;-) > + ) -> Result { > + Ok(perlmod::instantiate_magic!(&class, MAGIC => Box::new( > + NotificationConfig { > + config: Mutex::new(Config::new(raw_config, raw_private_config)?) > + } > + ))) > + } > + > + #[export] > + fn write_config(#[try_from_ref] this: &NotificationConfig) -> Result<(String, String), Error> { > + Ok(this.config.lock().unwrap().write()?) > + } > + > + #[export] > + fn digest(#[try_from_ref] this: &NotificationConfig) -> String { > + let config = this.config.lock().unwrap(); > + hex::encode(config.digest()) > + } > +} > -- > 2.39.2