]> git.proxmox.com Git - pve-storage.git/commitdiff
api: content: pass encrypted status for PBS backups
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 24 Nov 2020 22:17:57 +0000 (23:17 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 24 Nov 2020 22:18:05 +0000 (23:18 +0100)
Prefer the fingerprint, fallback to checking the files crypt-mode.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/API2/Storage/Content.pm
PVE/Storage/PBSPlugin.pm

index eac6343e86159ef884ba45ae0e57839174ddbf46..349231df9fc71d1b6e4eafb1259dfdb5fee4e124 100644 (file)
@@ -92,6 +92,12 @@ __PACKAGE__->register_method ({
                    type => 'string',
                    optional => 1,
                },
+               encrypted => {
+                   description => "If whole backup is encrypted, value is the fingerprint or '1' "
+                       ." if encrypted. Only useful for the Proxmox Backup Server storage type.",
+                   type => 'string',
+                   optional => 1,
+               },
                verification => {
                    description => "Last backup verification result, only useful for PBS storages.",
                    type => 'object',
index 1f576d322fed56e8b6dd4d43c626ab824f00a4f4..d1db4a9f34396e91894b22243c88e97a786753f1 100644 (file)
@@ -528,6 +528,24 @@ sub list_images {
     return $res;
 }
 
+my sub snapshot_files_encrypted {
+    my ($files) = @_;
+    return 0 if !$files;
+
+    my $any;
+    my $all = 1;
+    for my $file (@$files) {
+       my $fn = $file->{filename};
+       next if $fn eq 'client.log.blob' || $fn eq 'index.json.blob';
+
+       my $crypt = $file->{'crypt-mode'};
+
+       $all = 0 if !$crypt || $crypt ne 'encrypt';
+       $any ||= $crypt eq 'encrypt';
+    }
+    return $any && $all;
+}
+
 sub list_volumes {
     my ($class, $storeid, $scfg, $vmid, $content_types) = @_;
 
@@ -560,6 +578,11 @@ sub list_volumes {
 
        $info->{verification} = $item->{verification} if defined($item->{verification});
        $info->{notes} = $item->{comment} if defined($item->{comment});
+       if (defined($item->{fingerprint})) {
+           $info->{encrypted} = $item->{fingerprint};
+       } elsif (snapshot_files_encrypted($item->{files})) {
+           $info->{encrypted} = '1';
+       }
 
        push @$res, $info;
     }