5
0
mirror of git://git.proxmox.com/git/pve-common.git synced 2025-01-18 14:03:34 +03:00

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 <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2022-11-13 11:50:40 +01:00
parent 2bbf0eae8c
commit ec9e46fae6

View 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};
# 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});