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 <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2020-04-23 08:47:17 +02:00 committed by Thomas Lamprecht
parent 782b702dbb
commit 055c54b5a2

View File

@ -372,21 +372,18 @@ my $parse_sync_opts = sub {
my $sync_opts_fmt = PVE::JSONSchema::get_format('realm-sync-options'); my $sync_opts_fmt = PVE::JSONSchema::get_format('realm-sync-options');
my $res = {}; my $res = {};
my $defaults = {};
if (defined(my $cfg_opts = $realmconfig->{'sync-defaults-options'})) { 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) { for my $opt (sort keys %$sync_opts_fmt) {
my $fmt = $sync_opts_fmt->{$opt}; my $fmt = $sync_opts_fmt->{$opt};
if (exists $param->{$opt}) { $res->{$opt} = $param->{$opt} // $defaults->{$opt} // $fmt->{default};
$res->{$opt} = $param->{$opt};
} elsif (!exists $res->{$opt}) {
raise_param_exc({ raise_param_exc({
"$opt" => 'Not passed as parameter and not defined in realm default sync options.' "$opt" => 'Not passed as parameter and not defined in realm default sync options.'
}) if !$fmt->{optional}; }) if !defined($res->{$opt});
$res->{$opt} = $fmt->{default} if exists $fmt->{default};
}
} }
return $res; return $res;
}; };