]> git.proxmox.com Git - pve-common.git/commitdiff
job registry: avoid injecting the section id unconditionally in configs
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Sun, 13 Nov 2022 10:50:40 +0000 (11:50 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Sun, 13 Nov 2022 10:50:42 +0000 (11:50 +0100)
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 <t.lamprecht@proxmox.com>
src/PVE/Job/Registry.pm

index 27110bb9c74095fc05b345f0cc78a5910b709f3f..32e02728d629dca67bc479a0c25d3ea3aae2858e 100644 (file)
@@ -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});