public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
	Dominik Csapak <d.csapak@proxmox.com>
Subject: Re: [pve-devel] [PATCH common v3 1/1] SectionConfig: add helper to delete keys from a section config entry
Date: Wed, 8 Mar 2023 07:53:33 +0100	[thread overview]
Message-ID: <2eb7c57d-e5eb-75f0-337f-26c359762c95@proxmox.com> (raw)
In-Reply-To: <20230117114659.2397499-2-d.csapak@proxmox.com>

Am 17/01/2023 um 12:46 schrieb Dominik Csapak:
> this is a pattern we have very often, so we can implement that here and
> reuse it
> 
> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---
>  src/PVE/SectionConfig.pm | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/src/PVE/SectionConfig.pm b/src/PVE/SectionConfig.pm
> index 0a9f1cd..e354655 100644
> --- a/src/PVE/SectionConfig.pm
> +++ b/src/PVE/SectionConfig.pm
> @@ -543,4 +543,19 @@ sub assert_if_modified {
>      PVE::Tools::assert_if_modified($cfg->{digest}, $digest);
>  }
>  
> +sub delete_from_config {
> +    my ($config, $option_schema, $new_options, $to_delete) = @_;
> +
> +    for my $k ($to_delete->@*) {
> +	my $d = $option_schema->{$k} || die "no such option '$k'\n";
> +	die "unable to delete required option '$k'\n" if !$d->{optional};

Should we use the (here already imported but not used) raise_param_exc ?

As that would then also make the magic "mark-field-as-invalid" work if
used in API calls?

FWIW, we could use a cummulative approach, e.g. something like like:

my $errors = {};

for ... {
   eval {
       die "unable to delete fixed option\n" if $d->{fixed};
       ...
   };
   if (my $err = $@) {
       $errors->{$k} = $err;
   } else {
       delete ...
   }
}

raise_param_exc($errors) if scalar($errors->%*);


eval + die could be replaced by $err string in the loop for accumulating even
more errors, not sure how relevant in practice though.


Anyhow, method signature wouldn't change, so we could always do this as
followup too.

> +	die "unable to delete fixed option '$k'\n" if $d->{fixed};
> +	die "cannot set and delete property '$k' at the same time!\n"
> +	    if defined($new_options->{$k});
> +	delete $config->{$k};
> +    }
> +
> +    return $config;
> +}
> +
>  1;





  reply	other threads:[~2023-03-08  6:53 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-17 11:46 [pve-devel] [PATCH common/access-control/wt/manager v3] add realm sync jobs Dominik Csapak
2023-01-17 11:46 ` [pve-devel] [PATCH common v3 1/1] SectionConfig: add helper to delete keys from a section config entry Dominik Csapak
2023-03-08  6:53   ` Thomas Lamprecht [this message]
2023-03-11 17:23     ` [pve-devel] applied: " Thomas Lamprecht
2023-01-17 11:46 ` [pve-devel] [PATCH access-control v3 1/2] realm sync: refactor scope/remove-vanished into a standard option Dominik Csapak
2023-03-08 11:43   ` [pve-devel] applied: " Thomas Lamprecht
2023-01-17 11:46 ` [pve-devel] [PATCH access-control v3 2/2] add realm-sync plugin for jobs and CRUD api for realm-sync-jobs Dominik Csapak
2023-06-07  8:38   ` [pve-devel] applied: " Thomas Lamprecht
2023-01-17 11:46 ` [pve-devel] [PATCH widget-toolkit v3 1/1] RealmComboBox: add custom store filters for callers Dominik Csapak
2023-03-14 14:26   ` [pve-devel] applied: " Thomas Lamprecht
2023-01-17 11:46 ` [pve-devel] [PATCH manager v3 1/4] Jobs: include existing types in state file regex for deletion Dominik Csapak
2023-01-17 11:46 ` [pve-devel] [PATCH manager v3 2/4] Jobs: add RealmSync Plugin and register it Dominik Csapak
2023-01-17 11:46 ` [pve-devel] [PATCH manager v3 3/4] api: add realm-sync crud api to /cluster/jobs Dominik Csapak
2023-01-17 11:46 ` [pve-devel] [PATCH manager v3 4/4] ui: add Realm Sync panel Dominik Csapak
2023-03-07  8:06 ` [pve-devel] [PATCH common/access-control/wt/manager v3] add realm sync jobs Dominik Csapak
2023-05-03  7:35 ` Dominik Csapak
2023-06-07  9:59 ` Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2eb7c57d-e5eb-75f0-337f-26c359762c95@proxmox.com \
    --to=t.lamprecht@proxmox.com \
    --cc=d.csapak@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal