]> git.proxmox.com Git - pmg-api.git/commitdiff
api: cluster: add update-fingerprints call
authorStoiko Ivanov <s.ivanov@proxmox.com>
Mon, 15 Mar 2021 22:01:32 +0000 (23:01 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 16 Mar 2021 18:13:11 +0000 (19:13 +0100)
Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/PMG/API2/Cluster.pm

index 7eab761e008fa1b850ff35cfa3deca9230183f36..07aa8fa7b12386c36d67c0e11e0652d64fbd14fb 100644 (file)
@@ -111,6 +111,7 @@ __PACKAGE__->register_method({
            { name => 'status' },
            { name => 'create' },
            { name => 'join' },
+           { name => 'update-fingerprints' },
         ];
 
        return $result;
@@ -451,5 +452,44 @@ __PACKAGE__->register_method({
        return PMG::ClusterConfig::lock_config($code, "cluster join failed");
     }});
 
+__PACKAGE__->register_method({
+    name => 'update_fingerprints',
+    path => 'update-fingerprints',
+    method => 'POST',
+    description => "Update API certificate fingerprints (by fetching it via ssh).",
+    proxyto => 'master',
+    protected => 1,
+    parameters => {
+       additionalProperties => 0,
+    },
+    returns => { type => 'null' },
+    code => sub {
+       my ($param) = @_;
+
+       my $code = sub {
+           my $cinfo = PMG::ClusterConfig->new();
+
+           die "no cluster defined\n" if !scalar(keys %{$cinfo->{ids}});
+
+           my $localcid = $cinfo->{local}->{cid};
+
+           foreach my $cid (keys %{$cinfo->{ids}}) {
+               my $d = $cinfo->{ids}->{$cid};
+               my $fp;
+               if ($d->{cid} == $localcid) {
+                   $fp = PMG::Cluster::read_local_ssl_cert_fingerprint();
+               } else {
+                   $fp = PMG::Cluster::get_remote_cert_fingerprint($d);
+               }
+               $cinfo->{ids}->{$d->{cid}}->{fingerprint} = $fp;
+           }
+
+           $cinfo->write();
+
+           return;
+       };
+
+       PMG::ClusterConfig::lock_config($code, "update fingerprints failed");
+    }});
 
 1;