From 055c54b5a20164d59c7288cc6a24f7ea2b597978 Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Thu, 23 Apr 2020 08:47:17 +0200 Subject: [PATCH] domain sync: make options actually required we want the api options to be optional, but only as long as there are default values set in the realm config since they are all marked as optional (else they would be required in the api) this check did not work as intended instead, set the result to the value of: * the parameter * the set default in the config * the api default in this order if it is undef after this, raise a parameter exception Signed-off-by: Dominik Csapak --- PVE/API2/Domains.pm | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/PVE/API2/Domains.pm b/PVE/API2/Domains.pm index b3c3ac4..e139869 100644 --- a/PVE/API2/Domains.pm +++ b/PVE/API2/Domains.pm @@ -372,21 +372,18 @@ my $parse_sync_opts = sub { my $sync_opts_fmt = PVE::JSONSchema::get_format('realm-sync-options'); my $res = {}; + my $defaults = {}; if (defined(my $cfg_opts = $realmconfig->{'sync-defaults-options'})) { - $res = PVE::JSONSchema::parse_property_string($sync_opts_fmt, $cfg_opts); + $defaults = PVE::JSONSchema::parse_property_string($sync_opts_fmt, $cfg_opts); } for my $opt (sort keys %$sync_opts_fmt) { my $fmt = $sync_opts_fmt->{$opt}; - if (exists $param->{$opt}) { - $res->{$opt} = $param->{$opt}; - } elsif (!exists $res->{$opt}) { - raise_param_exc({ - "$opt" => 'Not passed as parameter and not defined in realm default sync options.' - }) if !$fmt->{optional}; - $res->{$opt} = $fmt->{default} if exists $fmt->{default}; - } + $res->{$opt} = $param->{$opt} // $defaults->{$opt} // $fmt->{default}; + raise_param_exc({ + "$opt" => 'Not passed as parameter and not defined in realm default sync options.' + }) if !defined($res->{$opt}); } return $res; }; -- 2.39.2