From: Thomas Lamprecht Date: Tue, 9 Nov 2021 16:57:57 +0000 (+0100) Subject: dns: cope with plugin json index not being available X-Git-Url: https://git.proxmox.com/?p=proxmox-acme.git;a=commitdiff_plain;h=e2483043c62feb0a25a6bbebb891099e1afb7df4 dns: cope with plugin json index not being available not nice to die plainly on a using this module (which can come in indirectly/transitively), so lets better cope with that. Nice side-effect, if nothing uses it, it won't get loaded, so less IO and memory in that case. Signed-off-by: Thomas Lamprecht --- diff --git a/src/PVE/ACME/DNSChallenge.pm b/src/PVE/ACME/DNSChallenge.pm index 9b28970..7214d88 100644 --- a/src/PVE/ACME/DNSChallenge.pm +++ b/src/PVE/ACME/DNSChallenge.pm @@ -23,13 +23,19 @@ sub type { } my $DNS_API_CHALLENGE_SCHEMA_FN = '/usr/share/proxmox-acme/dns-challenge-schema.json'; -my $plugins = from_json(PVE::Tools::file_get_contents($DNS_API_CHALLENGE_SCHEMA_FN)); +my $plugin_cache; sub get_supported_plugins { - return $plugins; + if (!$plugin_cache) { + $plugin_cache = -e $DNS_API_CHALLENGE_SCHEMA_FN # we allow this to be optional as not all users require + ? from_json(PVE::Tools::file_get_contents($DNS_API_CHALLENGE_SCHEMA_FN)) + : {}; + } + return $plugin_cache; } sub properties { + my $plugins = get_supported_plugins(); return { api => { description => "API plugin name",