[pmg-devel] [PATCH pmg-api 1/2] api: acme: set http_proxy if configured in pmg.conf
Stoiko Ivanov
s.ivanov at proxmox.com
Tue Nov 9 17:20:08 CET 2021
If a http_proxy is set in pmg.conf, use it for communicating with the
(usually public) Acme provider.
Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
src/PMG/API2/ACME.pm | 21 +++++++++++++++++++++
src/PMG/API2/Certificates.pm | 13 +++++++++++++
2 files changed, 34 insertions(+)
diff --git a/src/PMG/API2/ACME.pm b/src/PMG/API2/ACME.pm
index 42c9f4e..bb12177 100644
--- a/src/PMG/API2/ACME.pm
+++ b/src/PMG/API2/ACME.pm
@@ -14,6 +14,7 @@ use PVE::ACME::Challenge;
use PMG::RESTEnvironment;
use PMG::RS::Acme;
use PMG::CertHelpers;
+use PMG::Config;
use PMG::API2::ACMEPlugin;
@@ -159,6 +160,11 @@ __PACKAGE__->register_method ({
print "Registering new ACME account..\n";
my $acme = PMG::RS::Acme->new($directory);
+ my $pmg_cfg = PMG::Config->new();
+ if (my $http_proxy = $pmg_cfg->get('admin', 'http_proxy')) {
+ $acme->set_proxy($http_proxy);
+ }
+
eval {
$acme->new_account($account_file, defined($param->{tos_url}), $contact, undef);
};
@@ -192,6 +198,11 @@ my $update_account = sub {
if ! -e $account_file;
my $acme = PMG::RS::Acme->load($account_file);
+ my $pmg_cfg = PMG::Config->new();
+ if (my $http_proxy = $pmg_cfg->get('admin', 'http_proxy')) {
+ $acme->set_proxy($http_proxy);
+ }
+
eval {
$acme->update_account(\%info);
};
@@ -297,6 +308,11 @@ __PACKAGE__->register_method ({
if ! -e $account_file;
my $acme = PMG::RS::Acme->load($account_file);
+ my $pmg_cfg = PMG::Config->new();
+ if (my $http_proxy = $pmg_cfg->get('admin', 'http_proxy')) {
+ $acme->set_proxy($http_proxy);
+ }
+
my $data = $acme->account();
return {
@@ -365,6 +381,11 @@ __PACKAGE__->register_method ({
my $directory = extract_param($param, 'directory') // $acme_default_directory_url;
my $acme = PMG::RS::Acme->new($directory);
+ my $pmg_cfg = PMG::Config->new();
+ if (my $http_proxy = $pmg_cfg->get('admin', 'http_proxy')) {
+ $acme->set_proxy($http_proxy);
+ }
+
my $meta = $acme->get_meta();
return $meta ? $meta->{termsOfService} : undef;
diff --git a/src/PMG/API2/Certificates.pm b/src/PMG/API2/Certificates.pm
index b52f010..6627328 100644
--- a/src/PMG/API2/Certificates.pm
+++ b/src/PMG/API2/Certificates.pm
@@ -9,6 +9,7 @@ use PVE::JSONSchema qw(get_standard_option);
use PVE::Tools qw(extract_param file_get_contents file_set_contents);
use PMG::CertHelpers;
+use PMG::Config;
use PMG::NodeConfig;
use PMG::RS::Acme;
use PMG::RS::CSR;
@@ -535,6 +536,10 @@ __PACKAGE__->register_method ({
print "Loading ACME account details\n";
my $acme = PMG::RS::Acme->load($account_file);
+ my $pmg_cfg = PMG::Config->new();
+ if (my $http_proxy = $pmg_cfg->get('admin', 'http_proxy')) {
+ $acme->set_proxy($http_proxy);
+ }
my ($cert, $key) = $order_certificate->($acme, $acme_config);
my $certificate = "$key\n$cert";
@@ -609,6 +614,10 @@ __PACKAGE__->register_method ({
print "Loading ACME account details\n";
my $acme = PMG::RS::Acme->load($account_file);
+ my $pmg_cfg = PMG::Config->new();
+ if (my $http_proxy = $pmg_cfg->get('admin', 'http_proxy')) {
+ $acme->set_proxy($http_proxy);
+ }
my ($cert, $key) = $order_certificate->($acme, $acme_config);
my $certificate = "$key\n$cert";
@@ -676,6 +685,10 @@ __PACKAGE__->register_method ({
print "Loading ACME account details\n";
my $acme = PMG::RS::Acme->load($account_file);
+ my $pmg_cfg = PMG::Config->new();
+ if (my $http_proxy = $pmg_cfg->get('admin', 'http_proxy')) {
+ $acme->set_proxy($http_proxy);
+ }
print "Revoking old certificate\n";
eval { $acme->revoke_certificate($cert, undef) };
--
2.30.2
More information about the pmg-devel
mailing list