[pmg-devel] [PATCH pmg-api 3/6] api: cluster: add update-fingerprints call

Stoiko Ivanov s.ivanov at proxmox.com
Mon Mar 15 23:01:32 CET 2021


Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
 src/PMG/API2/Cluster.pm | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/src/PMG/API2/Cluster.pm b/src/PMG/API2/Cluster.pm
index 7eab761..07aa8fa 100644
--- a/src/PMG/API2/Cluster.pm
+++ b/src/PMG/API2/Cluster.pm
@@ -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;
-- 
2.20.1





More information about the pmg-devel mailing list