From: Maximiliano Sandoval <m.sandoval@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH cluster 3/3] cluster: add helper to retrieve proxies
Date: Tue, 21 Oct 2025 12:03:27 +0200 [thread overview]
Message-ID: <20251021100332.251697-4-m.sandoval@proxmox.com> (raw)
In-Reply-To: <20251021100332.251697-1-m.sandoval@proxmox.com>
This will take into account the multiple layers of fallbacks and has
some rudimentary error handling.
Signed-off-by: Maximiliano Sandoval <m.sandoval@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
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next prev parent reply other threads:[~2025-10-21 10:03 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-21 10:03 [pve-devel] [RFC cluster/manager/storage 0/7] datacenter config: add setting for HTTP{, S} proxies Maximiliano Sandoval
2025-10-21 10:03 ` [pve-devel] [PATCH cluster 1/3] " Maximiliano Sandoval
2025-10-21 10:03 ` [pve-devel] [PATCH cluster 2/3] datacenter config: deprecate http_proxy Maximiliano Sandoval
2025-10-21 10:03 ` Maximiliano Sandoval [this message]
2025-10-21 10:03 ` [pve-devel] [PATCH manager 1/3] api: subscription: use new proxy dc option Maximiliano Sandoval
2025-10-21 10:03 ` [pve-devel] [PATCH manager 2/3] api: apt: use new dc proxy option Maximiliano Sandoval
2025-10-21 10:03 ` [pve-devel] [PATCH manager 3/3] api: nodes: " Maximiliano Sandoval
2025-10-21 10:03 ` [pve-devel] [PATCH storage 1/1] api: storage: status: " Maximiliano Sandoval
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251021100332.251697-4-m.sandoval@proxmox.com \
--to=m.sandoval@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox