[pve-devel] [PATCH cluster 3/3] cluster: add helper to retrieve proxies
Maximiliano Sandoval
m.sandoval at proxmox.com
Tue Oct 21 12:03:27 CEST 2025
This will take into account the multiple layers of fallbacks and has
some rudimentary error handling.
Signed-off-by: Maximiliano Sandoval <m.sandoval at proxmox.com>
---
src/PVE/Cluster.pm | 58 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 58 insertions(+)
diff --git a/src/PVE/Cluster.pm b/src/PVE/Cluster.pm
index e829687..7e7f180 100644
--- a/src/PVE/Cluster.pm
+++ b/src/PVE/Cluster.pm
@@ -25,6 +25,7 @@ use PVE::Cluster::IPCConst;
use base 'Exporter';
our @EXPORT_OK = qw(
+ get_proxy
cfs_read_file
cfs_write_file
cfs_register_file
@@ -904,4 +905,61 @@ sub cfs_backup_database {
return $dbfile;
}
+=head3 get_proxy($scalar, $scalar, $scalar)
+
+Returns the proxy to be used for a given protocol and use-case.
+
+Parameters:
+
+=over
+
+=item C<$dccfg>
+
+The datacenter's configuration.
+
+=item C<$protocol>
+
+The protocol of the connection, can be one of C<http> or C<https>.
+
+=item C<$type>
+
+The use-case for the proxy. It can one of C<apt>, C<download>, or C<subscription>.
+
+=back
+
+=cut
+
+sub get_proxy {
+ my ($dccfg, $protocol, $type) = @_;
+
+ if ($protocol ne 'http' && $protocol ne 'https') {
+ die "Unsupported protocol $protocol when obtaining a proxy\n";
+ }
+
+ my $proxy;
+
+ # This could be simplified with some f-strings, but it is intentionally left
+ # out in a verbose form to accommodate for edge cases, like subscriptions
+ # which are exclusively handled with a HTTPS proxy.
+ if ($type eq 'subscription' && $protocol eq 'https') {
+ $proxy = $dccfg->{proxy}->{'https-subscription'};
+ } elsif ($type eq 'download' && $protocol eq 'http') {
+ $proxy = $dccfg->{proxy}->{'http-download'};
+ } elsif ($type eq 'download' && $protocol eq 'https') {
+ $proxy = $dccfg->{proxy}->{'https-download'};
+ } elsif ($type eq 'apt' && $protocol eq 'http') {
+ $proxy = $dccfg->{proxy}->{'http-apt'};
+ } elsif ($type eq 'apt' && $protocol eq 'https') {
+ $proxy = $dccfg->{proxy}->{'https-apt'};
+ } else {
+ die "Unsupported type $type for protocol $protocol when obtaining a proxy\n";
+ }
+
+ $proxy //= $dccfg->{proxy}->{global};
+ $proxy //= $dccfg->{http_proxy};
+ $proxy = undef if $proxy eq 'none';
+
+ return $proxy;
+}
+
1;
--
2.47.3
More information about the pve-devel
mailing list