[pve-devel] [PATCH manager 1/3] api: acme: set http_proxy if configured in datacenter.cfg

Stoiko Ivanov s.ivanov at proxmox.com
Tue Nov 9 17:36:31 CET 2021


partially fixes #3536

If a http_proxy is set in the datacenter config, use it for
communicating with the (usually public) Acme provider.

Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
 PVE/API2/ACME.pm        | 13 +++++++++++++
 PVE/API2/ACMEAccount.pm | 17 +++++++++++++++++
 2 files changed, 30 insertions(+)

diff --git a/PVE/API2/ACME.pm b/PVE/API2/ACME.pm
index 393e6b01..6e6f44f6 100644
--- a/PVE/API2/ACME.pm
+++ b/PVE/API2/ACME.pm
@@ -6,6 +6,7 @@ use warnings;
 use PVE::ACME;
 use PVE::CertHelpers;
 use PVE::Certificate;
+use PVE::Cluster;
 use PVE::Exception qw(raise raise_param_exc);
 use PVE::JSONSchema qw(get_standard_option);
 use PVE::NodeConfig;
@@ -207,6 +208,10 @@ __PACKAGE__->register_method ({
 		if ! -e $account_file;
 
 	    my $acme = PVE::ACME->new($account_file);
+	    my $dccfg = PVE::Cluster::cfs_read_file('datacenter.cfg');
+	    if (my $http_proxy = $dccfg->{http_proxy}) {
+		$acme->set_proxy($http_proxy);
+	    }
 
 	    print "Loading ACME account details\n";
 	    $acme->load();
@@ -284,6 +289,10 @@ __PACKAGE__->register_method ({
 		if ! -e $account_file;
 
 	    my $acme = PVE::ACME->new($account_file);
+	    my $dccfg = PVE::Cluster::cfs_read_file('datacenter.cfg');
+	    if (my $http_proxy = $dccfg->{http_proxy}) {
+		$acme->set_proxy($http_proxy);
+	    }
 
 	    print "Loading ACME account details\n";
 	    $acme->load();
@@ -352,6 +361,10 @@ __PACKAGE__->register_method ({
 		if ! -e $account_file;
 
 	    my $acme = PVE::ACME->new($account_file);
+	    my $dccfg = PVE::Cluster::cfs_read_file('datacenter.cfg');
+	    if (my $http_proxy = $dccfg->{http_proxy}) {
+		$acme->set_proxy($http_proxy);
+	    }
 
 	    print "Loading ACME account details\n";
 	    $acme->load();
diff --git a/PVE/API2/ACMEAccount.pm b/PVE/API2/ACMEAccount.pm
index b790843a..218b84fe 100644
--- a/PVE/API2/ACMEAccount.pm
+++ b/PVE/API2/ACMEAccount.pm
@@ -5,6 +5,7 @@ use warnings;
 
 use PVE::ACME;
 use PVE::CertHelpers;
+use PVE::Cluster;
 use PVE::Exception qw(raise_param_exc);
 use PVE::JSONSchema qw(get_standard_option);
 use PVE::RPCEnvironment;
@@ -142,6 +143,10 @@ __PACKAGE__->register_method ({
 		    if -e $account_file;
 
 		my $acme = PVE::ACME->new($account_file, $directory);
+		my $dccfg = PVE::Cluster::cfs_read_file('datacenter.cfg');
+		if (my $http_proxy = $dccfg->{http_proxy}) {
+		    $acme->set_proxy($http_proxy);
+		}
 		print "Generating ACME account key..\n";
 		$acme->init(4096);
 		print "Registering ACME account..\n";
@@ -177,6 +182,10 @@ my $update_account = sub {
 		if ! -e $account_file;
 
 	    my $acme = PVE::ACME->new($account_file);
+	    my $dccfg = PVE::Cluster::cfs_read_file('datacenter.cfg');
+	    if (my $http_proxy = $dccfg->{http_proxy}) {
+		$acme->set_proxy($http_proxy);
+	    }
 	    $acme->load();
 	    $acme->update_account(%info);
 	    if ($info{status} && $info{status} eq 'deactivated') {
@@ -276,6 +285,10 @@ __PACKAGE__->register_method ({
 	    if ! -e $account_file;
 
 	my $acme = PVE::ACME->new($account_file);
+	my $dccfg = PVE::Cluster::cfs_read_file('datacenter.cfg');
+	if (my $http_proxy = $dccfg->{http_proxy}) {
+	    $acme->set_proxy($http_proxy);
+	}
 	$acme->load();
 
 	my $res = {};
@@ -334,6 +347,10 @@ __PACKAGE__->register_method ({
 	my $directory = extract_param($param, 'directory') // $acme_default_directory_url;
 
 	my $acme = PVE::ACME->new(undef, $directory);
+	my $dccfg = PVE::Cluster::cfs_read_file('datacenter.cfg');
+	if (my $http_proxy = $dccfg->{http_proxy}) {
+	    $acme->set_proxy($http_proxy);
+	}
 	my $meta = $acme->get_meta();
 
 	return $meta ? $meta->{termsOfService} : undef;
-- 
2.30.2






More information about the pve-devel mailing list