From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 8613B1FF1DE for ; Wed, 03 Jun 2026 20:05:37 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id EAA9F15D8C; Wed, 3 Jun 2026 20:05:33 +0200 (CEST) From: Stoiko Ivanov To: pmg-devel@lists.proxmox.com Subject: [PATCH pmg-api 08/15] api: pbs remote create/update: return parts of the configuration Date: Wed, 3 Jun 2026 20:03:10 +0200 Message-ID: <20260603180445.98770-9-s.ivanov@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260603180445.98770-1-s.ivanov@proxmox.com> References: <20260603180445.98770-1-s.ivanov@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1780509859749 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.087 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: E4RZWOI7D7SAHSUZER72A2LGVWCXLAWC X-Message-ID-Hash: E4RZWOI7D7SAHSUZER72A2LGVWCXLAWC X-MailFrom: s.ivanov@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Mail Gateway development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: This follows pve-storage commit: cd69ced ("api: storage create/update: return parts of the configuration") returning the encryption-key upon creation, to offer it for download/copying to the user in the GUI. Signed-off-by: Stoiko Ivanov --- src/PMG/API2/PBS/Remote.pm | 75 ++++++++++++++++++++++++++++++++++---- 1 file changed, 67 insertions(+), 8 deletions(-) diff --git a/src/PMG/API2/PBS/Remote.pm b/src/PMG/API2/PBS/Remote.pm index 881ab127..b5b9c3ad 100644 --- a/src/PMG/API2/PBS/Remote.pm +++ b/src/PMG/API2/PBS/Remote.pm @@ -67,16 +67,39 @@ __PACKAGE__->register_method({ proxyto => 'master', protected => 1, parameters => PMG::PBSConfig->createSchema(1), - returns => { type => 'null' }, + returns => { + type => 'object', + properties => { + remote => { + description => "The ID of the created PBS remote.", + type => 'string', + }, + config => { + description => "Partial, possibly server generated, configuration properties.", + type => 'object', + optional => 1, + additionalProperties => 1, + properties => { + 'encryption-key' => { + description => "The, possibly auto-generated, encryption-key.", + optional => 1, + type => 'string', + }, + }, + }, + }, + }, code => sub { my ($param) = @_; + my $remote; + my $encryption_key; my $code = sub { my $conf = PMG::PBSConfig->new(); $conf->{ids} //= {}; my $ids = $conf->{ids}; - my $remote = extract_param($param, 'remote'); + $remote = extract_param($param, 'remote'); die "PBS remote '$remote' already exists\n" if $ids->{$remote}; my $remotecfg = PMG::PBSConfig->check_config($remote, $param, 1); @@ -86,7 +109,7 @@ __PACKAGE__->register_method({ my $pbs = PVE::PBSClient->new($remotecfg, $remote, $conf->{secret_dir}); $pbs->set_password($password) if defined($password); - my $encryption_key = extract_param($remotecfg, 'encryption-key'); + $encryption_key = extract_param($remotecfg, 'encryption-key'); if (defined($encryption_key)) { my $decoded_key; @@ -111,8 +134,14 @@ __PACKAGE__->register_method({ }; PMG::PBSConfig::lock_config($code, "add PBS remote failed"); + my $res = { + remote => $remote, + config => { + 'encryption-key' => $encryption_key, + }, + }; - return undef; + return $res; }, }); @@ -162,10 +191,33 @@ __PACKAGE__->register_method({ protected => 1, proxyto => 'master', parameters => PMG::PBSConfig->updateSchema(), - returns => { type => 'null' }, + returns => { + type => 'object', + properties => { + remote => { + description => "The ID of the created PBS remote.", + type => 'string', + }, + config => { + description => "Partial, possibly server generated, configuration properties.", + type => 'object', + optional => 1, + additionalProperties => 1, + properties => { + 'encryption-key' => { + description => "The, possibly auto-generated, encryption-key.", + optional => 1, + type => 'string', + }, + }, + }, + }, + }, code => sub { my ($param) = @_; + my $remote; + my $encryption_key; my $code = sub { my $conf = PMG::PBSConfig->new(); @@ -174,7 +226,7 @@ __PACKAGE__->register_method({ my $digest = extract_param($param, 'digest'); PVE::SectionConfig::assert_if_modified($conf, $digest); - my $remote = extract_param($param, 'remote'); + $remote = extract_param($param, 'remote'); die "PBS remote '$remote' does not exist\n" if !$ids->{$remote}; @@ -197,7 +249,7 @@ __PACKAGE__->register_method({ } if (exists($param->{'encryption-key'})) { - if (defined(my $encryption_key = extract_param($param, 'encryption-key'))) { + if (defined($encryption_key = extract_param($param, 'encryption-key'))) { my $decoded_key; if ($encryption_key eq 'autogen') { $encryption_key = $pbs->autogen_encryption_key(); @@ -227,7 +279,14 @@ __PACKAGE__->register_method({ PMG::PBSConfig::lock_config($code, "update PBS remote failed"); - return undef; + my $res = { + remote => $remote, + config => { + 'encryption-key' => $encryption_key, + }, + }; + + return $res; }, }); -- 2.47.3