From: Nicolas Frey <n.frey@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH pve-access-control 2/2] api: token: add delete parameter for comment
Date: Wed, 8 Oct 2025 13:19:20 +0200 [thread overview]
Message-ID: <20251008111930.55867-3-n.frey@proxmox.com> (raw)
In-Reply-To: <20251008111930.55867-1-n.frey@proxmox.com>
Adds delete parameter to the endpoint, which was suggested by Fabian
Grünbichler in the bug report.
Suggested-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Signed-off-by: Nicolas Frey <n.frey@proxmox.com>
---
src/PVE/API2/User.pm | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/src/PVE/API2/User.pm b/src/PVE/API2/User.pm
index e7c895e..4742f17 100644
--- a/src/PVE/API2/User.pm
+++ b/src/PVE/API2/User.pm
@@ -848,6 +848,12 @@ __PACKAGE__->register_method({
expire => get_standard_option('token-expire'),
privsep => get_standard_option('token-privsep'),
comment => get_standard_option('token-comment'),
+ delete => {
+ type => 'string',
+ format => 'pve-configid-list',
+ description => "A list of settings you want to delete.",
+ optional => 1,
+ },
},
},
returns =>
@@ -861,6 +867,9 @@ __PACKAGE__->register_method({
my $usercfg = cfs_read_file("user.cfg");
my $token = PVE::AccessControl::check_token_exist($usercfg, $userid, $tokenid);
+ my $delete = extract_param($param, 'delete');
+ $delete = { map { $_ => 1 } PVE::Tools::split_list($delete) } if $delete;
+
PVE::AccessControl::lock_user_config(
sub {
$usercfg = cfs_read_file("user.cfg");
@@ -873,6 +882,18 @@ __PACKAGE__->register_method({
$token->{comment} = $param->{comment} if defined($param->{comment});
delete $token->{comment} if (!length $token->{comment});
+ my $deletable = {
+ comment => 1,
+ };
+
+ for my $k (keys $delete->%*) {
+ if (!$deletable->{$k}) {
+ raise_param_exc({ delete => "unknown option '$k'" });
+ }
+
+ delete $token->{$k};
+ }
+
$usercfg->{users}->{$userid}->{tokens}->{$tokenid} = $token;
cfs_write_file("user.cfg", $usercfg);
},
--
2.47.3
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
prev parent reply other threads:[~2025-10-08 11:20 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-08 11:19 [pve-devel] [PATCH pve-access-control 0/2] api: token: fix #6890: allow comment removal via delete parameter or empty string Nicolas Frey
2025-10-08 11:19 ` [pve-devel] [PATCH pve-access-control 1/2] api: token: fix #6890: add ability to remove comment with " Nicolas Frey
2025-10-08 11:19 ` Nicolas Frey [this message]
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=20251008111930.55867-3-n.frey@proxmox.com \
--to=n.frey@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