From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pbs-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9])
	by lore.proxmox.com (Postfix) with ESMTPS id CFFDD1FF173
	for <inbox@lore.proxmox.com>; Mon, 24 Mar 2025 11:39:40 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 41CEC186D2;
	Mon, 24 Mar 2025 11:39:37 +0100 (CET)
Message-ID: <f68639d1-e2d0-42ce-98cb-91d09fc11326@proxmox.com>
Date: Mon, 24 Mar 2025 11:39:03 +0100
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
To: pbs-devel@lists.proxmox.com
References: <20250321122521.198725-1-l.wagner@proxmox.com>
 <20250321122521.198725-5-l.wagner@proxmox.com>
Content-Language: de-AT, en-US
From: Lukas Wagner <l.wagner@proxmox.com>
In-Reply-To: <20250321122521.198725-5-l.wagner@proxmox.com>
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.009 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
 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [mod.rs]
Subject: Re: [pbs-devel] [PATCH proxmox-backup 04/10] notifications: add
 type for APT notification template data
X-BeenThere: pbs-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Backup Server development discussion
 <pbs-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pbs-devel/>
List-Post: <mailto:pbs-devel@lists.proxmox.com>
List-Help: <mailto:pbs-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox Backup Server development discussion
 <pbs-devel@lists.proxmox.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pbs-devel-bounces@lists.proxmox.com
Sender: "pbs-devel" <pbs-devel-bounces@lists.proxmox.com>



On  2025-03-21 13:25, Lukas Wagner wrote:
> This commit adds a separate type for the data passed to this type of
> notification template. Also we make sure that we do not expose any
> non-primitive types to the template renderer, any data
> needed in the template is mapped into the new dedicated
> template data type.
> This ensures that any changes in types defined in other places
> do not leak into the template rendering process by accident.
> 
> This commit also tries to unify the style and naming of template
> variables.
> 
> Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
> ---
>  src/server/notifications/mod.rs               | 23 ++++++-----
>  src/server/notifications/template_data.rs     | 41 ++++++++++++++++++-
>  .../default/package-updates-body.txt.hbs      |  8 ++--
>  .../default/package-updates-subject.txt.hbs   |  2 +-
>  4 files changed, 57 insertions(+), 17 deletions(-)
> 
> diff --git a/src/server/notifications/mod.rs b/src/server/notifications/mod.rs
> index 864c6e9f..480db365 100644
> --- a/src/server/notifications/mod.rs
> +++ b/src/server/notifications/mod.rs
> @@ -23,7 +23,10 @@ const SPOOL_DIR: &str = concatcp!(pbs_buildcfg::PROXMOX_BACKUP_STATE_DIR, "/noti
>  
>  mod template_data;
>  
> -use template_data::{AcmeErrTemplateData, CommonData, GcErrTemplateData, GcOkTemplateData};
> +use template_data::{
> +    AcmeErrTemplateData, CommonData, GcErrTemplateData, GcOkTemplateData,
> +    PackageUpdatesTemplateData,
> +};
>  
>  /// Initialize the notification system by setting context in proxmox_notify
>  pub fn init() -> Result<(), Error> {
> @@ -464,23 +467,21 @@ fn get_server_url() -> (String, usize) {
>  }
>  
>  pub fn send_updates_available(updates: &[&APTUpdateInfo]) -> Result<(), Error> {
> -    let (fqdn, port) = get_server_url();
>      let hostname = proxmox_sys::nodename().to_string();
>  
> -    let data = json!({
> -        "fqdn": fqdn,
> -        "hostname": &hostname,
> -        "port": port,
> -        "updates": updates,
> -    });
> -
>      let metadata = HashMap::from([
>          ("hostname".into(), hostname),
>          ("type".into(), "package-updates".into()),
>      ]);
>  
> -    let notification =
> -        Notification::from_template(Severity::Info, "package-updates", data, metadata);
> +    let template_data = PackageUpdatesTemplateData::new(updates);
> +
> +    let notification = Notification::from_template(
> +        Severity::Info,
> +        "package-updates",
> +        serde_json::to_value(template_data)?,
> +        metadata,
> +    );
>  
>      send_notification(notification)?;
>      Ok(())
> diff --git a/src/server/notifications/template_data.rs b/src/server/notifications/template_data.rs
> index c3e31367..98b39c10 100644
> --- a/src/server/notifications/template_data.rs
> +++ b/src/server/notifications/template_data.rs
> @@ -1,4 +1,4 @@
> -use pbs_api_types::GarbageCollectionStatus;
> +use pbs_api_types::{APTUpdateInfo, GarbageCollectionStatus};
>  use serde::Serialize;
>  
>  // NOTE: For some of these types, the `XyzOkTemplateData` and `XyzErrTemplateData`
> @@ -141,3 +141,42 @@ pub struct AcmeErrTemplateData {
>      /// The error that occured when trying to request the certificate.
>      pub error: String,
>  }
> +
> +#[derive(Serialize)]
> +#[serde(rename_all = "kebab-case")]
> +/// A single package which can be upgraded.
> +pub struct UpgradablePackage {
> +    /// The name of the package.
> +    name: String,
> +    /// The new version which can be installed.
> +    version: String,
> +    /// The currently installed version.
> +    old_version: String,
> +}

I'll do a

name -> package_name
old_version -> installed_version
version -> available_version

in a v2 so that this the same as in the PVE template which I am auditing right now.

I'll send it once I am sure that there are no other changes I want to make
in order to make it more consistent with PVE's templates.

-- 
- Lukas



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