[pve-devel] [PATCH/RFC v2 manager 3/3] vzdump: notes-template: replace unknown variable with error string

Thomas Lamprecht t.lamprecht at proxmox.com
Wed May 4 08:23:47 CEST 2022


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();




More information about the pve-devel mailing list