X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=blobdiff_plain;f=src%2FPVE%2FSectionConfig.pm;h=71d296e6574f7a11d47a67083a45c5188c1b4887;hp=d4d2ed57e43437db4a73b231862f25452d07d2fc;hb=771d18f5c7be2055f0c9012f7f921f6d5f6337db;hpb=516dfb55e1d1e542cafe72c09798f658db950fd2 diff --git a/src/PVE/SectionConfig.pm b/src/PVE/SectionConfig.pm index d4d2ed5..71d296e 100644 --- a/src/PVE/SectionConfig.pm +++ b/src/PVE/SectionConfig.pm @@ -52,11 +52,51 @@ sub createSchema { my $pdata = $class->private(); my $propertyList = $pdata->{propertyList}; + my $plugins = $pdata->{plugins}; + + my $props = {}; + + my $copy_property = sub { + my ($src) = @_; + + my $res = {}; + foreach my $k (keys %$src) { + $res->{$k} = $src->{$k}; + } + + return $res; + }; + + foreach my $p (keys %$propertyList) { + if (!$propertyList->{$p}->{optional}) { + $props->{$p} = $propertyList->{$p}; + next; + } + + my $required = 1; + + my $copts = $class->options(); + $required = 0 if defined($copts->{$p}) && $copts->{$p}->{optional}; + + foreach my $t (keys %$plugins) { + my $opts = $pdata->{options}->{$t} || {}; + $required = 0 if !defined($opts->{$p}) || $opts->{$p}->{optional}; + } + + if ($required) { + # make a copy, because we modify the optional property + my $res = &$copy_property($propertyList->{$p}); + $res->{optional} = 0; + $props->{$p} = $res; + } else { + $props->{$p} = $propertyList->{$p}; + } + } return { type => "object", additionalProperties => 0, - properties => $propertyList, + properties => $props, }; } @@ -78,6 +118,9 @@ sub updateSchema { my $modifyable = 0; + my $copts = $class->options(); + $modifyable = 1 if defined($copts->{$p}) && !$copts->{$p}->{fixed}; + foreach my $t (keys %$plugins) { my $opts = $pdata->{options}->{$t} || {}; next if !defined($opts->{$p});