From: Thomas Lamprecht Date: Sun, 13 Nov 2022 10:50:40 +0000 (+0100) Subject: job registry: avoid injecting the section id unconditionally in configs X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=commitdiff_plain;h=ec9e46fae6581ea0e48ed7530a8c1a10eed9828c job registry: avoid injecting the section id unconditionally in configs this can result in a broken config due to it getting written out on write_config serialization, and if a plugin did not declare `id` as an option it understood (none do currently), it would then fail the next parse, far from ideal... As the section ID is available already anyway we should probably just drop this, but for now avoid rushed changes and just make it conforming to section config semantics and check if the option is actually understood by the respective section type we're working on. Signed-off-by: Thomas Lamprecht --- diff --git a/src/PVE/Job/Registry.pm b/src/PVE/Job/Registry.pm index 27110bb..32e0272 100644 --- a/src/PVE/Job/Registry.pm +++ b/src/PVE/Job/Registry.pm @@ -18,6 +18,8 @@ use base qw(PVE::SectionConfig); my $defaultData = { propertyList => { type => { description => "Section type." }, + # FIXME: remove below? this is the section ID, schema would only be checked if a plugin + # declares this as explicit option, which isn't really required as its available anyway.. id => { description => "The ID of the job.", type => 'string', @@ -60,10 +62,15 @@ sub parse_config { my $cfg = $class->SUPER::parse_config($filename, $raw, $allow_unknown); - foreach my $id (sort keys %{$cfg->{ids}}) { + for my $id (keys %{$cfg->{ids}}) { my $data = $cfg->{ids}->{$id}; + my $type = $data->{type}; - $data->{id} = $id; + # FIXME: below id injection is gross, guard to avoid breaking plugins that don't declare id + # as option; *iff* we want this it should be handled by section config directly. + if ($defaultData->{options}->{$type} && exists $defaultData->{options}->{$type}->{id}) { + $data->{id} = $id; + } $data->{enabled} //= 1; $data->{comment} = PVE::Tools::decode_text($data->{comment}) if defined($data->{comment});