public inbox for pmg-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Stoiko Ivanov <s.ivanov@proxmox.com>
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	[thread overview]
Message-ID: <20260603180445.98770-9-s.ivanov@proxmox.com> (raw)
In-Reply-To: <20260603180445.98770-1-s.ivanov@proxmox.com>

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 <s.ivanov@proxmox.com>
---
 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





  parent reply	other threads:[~2026-06-03 18:05 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-03 18:03 [PATCH pve-common/pmg-api/pmg-docs/pmg-gui 00/15] fix #3226: add support for encrypted backups Stoiko Ivanov
2026-06-03 18:03 ` [PATCH pve-common 01/15] pbs-client: autogen key: rename old one if existing Stoiko Ivanov
2026-06-03 18:03 ` [PATCH pve-common 02/15] pbs-client: add support for master public key Stoiko Ivanov
2026-06-03 18:03 ` [PATCH pmg-api 03/15] api: pbs remote: fix delete_password invocation Stoiko Ivanov
2026-06-03 18:03 ` [PATCH pmg-api 04/15] fix #3226: pbs backup: remote: add encryption key support Stoiko Ivanov
2026-06-03 18:03 ` [PATCH pmg-api 05/15] pbs: job: add encrypted state to snapshot listing Stoiko Ivanov
2026-06-03 18:03 ` [PATCH pmg-api 06/15] pbs: job: add verification " Stoiko Ivanov
2026-06-03 18:03 ` [PATCH pmg-api 07/15] pmgbackup: add encypted and verification state to output Stoiko Ivanov
2026-06-03 18:03 ` Stoiko Ivanov [this message]
2026-06-03 18:03 ` [PATCH pmg-api 09/15] api: pmgbackup: add master-pubkey properties Stoiko Ivanov
2026-06-03 18:03 ` [PATCH pmg-gui 10/15] pbs: snapshotview: add missing gettext invocations Stoiko Ivanov
2026-06-03 18:03 ` [PATCH pmg-gui 11/15] utils: copy pbs helpers from pve-manager Stoiko Ivanov
2026-06-03 18:03 ` [PATCH pmg-gui 12/15] fix #3326: ui: pbs remote: add encryption tab to edit window Stoiko Ivanov
2026-06-03 18:03 ` [PATCH pmg-gui 13/15] ui: pbs remote: allow to downloading/print new encryption key Stoiko Ivanov
2026-06-03 18:03 ` [PATCH pmg-gui 14/15] ui: pbs snapshotview: add encryption and verification state Stoiko Ivanov
2026-06-03 18:03 ` [PATCH pmg-docs 15/15] pmgbackup: minimally document support for encrypted backups Stoiko Ivanov

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=20260603180445.98770-9-s.ivanov@proxmox.com \
    --to=s.ivanov@proxmox.com \
    --cc=pmg-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