From: Wolfgang Bumiller <w.bumiller@proxmox.com>
To: pmg-devel@lists.proxmox.com
Subject: [pmg-devel] [PATCH api 3/4] add PMG::NodeConfig::filter_domains_by_type helper
Date: Wed, 17 Mar 2021 11:02:15 +0100 [thread overview]
Message-ID: <20210317100216.8008-4-w.bumiller@proxmox.com> (raw)
In-Reply-To: <20210317100216.8008-1-w.bumiller@proxmox.com>
for reuse
The private $filter_domains is still there to do the
in-place modification it did before.
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
---
src/PMG/API2/Certificates.pm | 12 ++++--------
src/PMG/NodeConfig.pm | 19 +++++++++++++++++++
2 files changed, 23 insertions(+), 8 deletions(-)
diff --git a/src/PMG/API2/Certificates.pm b/src/PMG/API2/Certificates.pm
index 775d575..b50addd 100644
--- a/src/PMG/API2/Certificates.pm
+++ b/src/PMG/API2/Certificates.pm
@@ -468,17 +468,13 @@ my $order_certificate = sub {
my $filter_domains = sub {
my ($acme_config, $type) = @_;
- my $domains = $acme_config->{domains};
- foreach my $domain (sort keys %$domains) {
- my $entry = $domains->{$domain};
- if (!(grep { $_ eq $type } PVE::Tools::split_list($entry->{usage}))) {
- delete $domains->{$domain};
- }
- }
+ my $domains = PMG::NodeConfig::filter_domains_by_type($acme_config->{domains}, $type);
- if (!%$domains) {
+ if (!$domains) {
raise("No domains configured for type '$type'\n", 400);
}
+
+ $acme_config->{domains} = $domains;
};
__PACKAGE__->register_method ({
diff --git a/src/PMG/NodeConfig.pm b/src/PMG/NodeConfig.pm
index 84c2141..19d23c3 100644
--- a/src/PMG/NodeConfig.pm
+++ b/src/PMG/NodeConfig.pm
@@ -222,4 +222,23 @@ sub get_acme_conf {
return $res;
}
+# Helper to filter the domains hash. Returns `undef` if the list is empty.
+sub filter_domains_by_type : prototype($$) {
+ my ($domains, $type) = @_;
+
+ return undef if !$domains || !%$domains;
+
+ my $out = {};
+
+ foreach my $domain (keys %$domains) {
+ my $entry = $domains->{$domain};
+ if (grep { $_ eq $type } PVE::Tools::split_list($entry->{usage})) {
+ $out->{$domain} = $entry;
+ }
+ }
+
+ return undef if !%$out;
+ return $out;
+}
+
1;
--
2.20.1
next prev parent reply other threads:[~2021-03-17 10:02 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-17 10:02 [pmg-devel] [PATCH api 0/4] ACME updates Wolfgang Bumiller
2021-03-17 10:02 ` [pmg-devel] [PATCH api 1/4] add missing use statement Wolfgang Bumiller
2021-03-17 10:02 ` [pmg-devel] [PATCH api 2/4] support forced account deactivation Wolfgang Bumiller
2021-03-17 10:33 ` Thomas Lamprecht
2021-03-17 10:02 ` Wolfgang Bumiller [this message]
2021-03-17 10:02 ` [pmg-devel] [PATCH api 4/4] check acme cert expiration in pmg-daily Wolfgang Bumiller
2021-03-17 10:34 ` [pmg-devel] applied-series: [PATCH api 0/4] ACME updates Thomas Lamprecht
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=20210317100216.8008-4-w.bumiller@proxmox.com \
--to=w.bumiller@proxmox.com \
--cc=pmg-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