public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
	Fabian Ebner <f.ebner@proxmox.com>
Subject: Re: [pve-devel] [PATCH/RFC v2 manager 3/3] vzdump: notes-template: replace unknown variable with error string
Date: Wed, 4 May 2022 08:23:47 +0200	[thread overview]
Message-ID: <06c00d65-ce59-876b-65a2-62af59b7bdd9@proxmox.com> (raw)
In-Reply-To: <20220503111800.64511-3-f.ebner@proxmox.com>

Am 5/3/22 um 13:18 schrieb Fabian Ebner:
> rather than not setting the notes at all. They still can contain
> useful information, and it likely is surprising to users to lose all
> of the note when an unkown variable (or simply mistyped) is provided.
> 

This feels like approaching the problem from the wrong end to me, why not check on add?

For jobs that's relatively simple and for manual VZDump runs we could explicitly do the
check to, e.g. something like (for jobs only & untested):


----8<----
diff --git a/PVE/API2/Backup.pm b/PVE/API2/Backup.pm
index 5d36789a..35482bc7 100644
--- a/PVE/API2/Backup.pm
+++ b/PVE/API2/Backup.pm
@@ -206,6 +206,18 @@ __PACKAGE__->register_method({
 
        $param->{enabled} = 1 if !defined($param->{enabled});
 
+       if (my $tmpl = $param->{'notes-template'}) {
+           my $problematic = [];
+           while($tmpl =~ /\{\{([^\s{}]+)\}\}/g) {
+               my $var = $1;
+               push @$problematic, "'$var' at char " . ((pos $tmpl) - length($var))
+                   if $var !~ /^(cluster|guestname|node|vmid)$/;
+           }
+           if (scalar(@$problematic)) {
+               raise_param_exc({ 'notes-template' => "found unknown variables: " . join(', ', @$problematic) });
+           }
+       }
+
        # autogenerate id for api compatibility FIXME remove with 8.0
        my $id = extract_param($param, 'id') // UUID::uuid();




  reply	other threads:[~2022-05-04  6:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-03 11:17 [pve-devel] [PATCH v2 manager 1/3] vzdump: notes-template: avoid escaping meta-characters upon replace Fabian Ebner
2022-05-03 11:17 ` [pve-devel] [PATCH v2 manager 2/3] vzdump: notes-template: improve check for unknown variable Fabian Ebner
2022-05-04  6:21   ` [pve-devel] applied: " Thomas Lamprecht
2022-05-03 11:18 ` [pve-devel] [PATCH/RFC v2 manager 3/3] vzdump: notes-template: replace unknown variable with error string Fabian Ebner
2022-05-04  6:23   ` Thomas Lamprecht [this message]
2022-05-04  6:20 ` [pve-devel] applied: [PATCH v2 manager 1/3] vzdump: notes-template: avoid escaping meta-characters upon replace 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=06c00d65-ce59-876b-65a2-62af59b7bdd9@proxmox.com \
    --to=t.lamprecht@proxmox.com \
    --cc=f.ebner@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