global-functions: split $CertificateAvailable to $CertificateDownload

This allows to force download even if certificate is available. We need
this for a clean update path with Let's Encrypt.
This commit is contained in:
Christian Hesse 2020-01-03 10:07:55 +01:00
parent afb9839073
commit cb1e520965

View file

@ -17,6 +17,7 @@
# global functions
:global UrlEncode;
:global CharacterReplace;
:global CertificateDownload;
:global CertificateAvailable;
:global SendEMail;
:global SendTelegram;
@ -79,8 +80,8 @@
:return ($Return . $String);
}
# check and import required certificates
:set CertificateAvailable do={
# download and import certificate
:set CertificateDownload do={
:local CommonName [ :tostr $1 ];
:global ScriptUpdatesBaseUrl;
@ -89,9 +90,8 @@
:global UrlEncode;
:global WaitForFile;
:if ([ / certificate print count-only where common-name=$CommonName ] = 0) do={
:log info ("Certificate with CommonName " . $CommonName . \
" not available, downloading and importing.");
:log info ("Downloading and importing certificate with " . \
"CommonName " . $CommonName . ".");
:do {
:local LocalFileName ($CommonName . ".pem");
:local UrlFileName ([ $UrlEncode $CommonName ] . ".pem");
@ -105,6 +105,17 @@
} on-error={
:log warning "Failed imprting certificate!";
}
}
# check and download required certificate
:set CertificateAvailable do={
:local CommonName [ :tostr $1 ];
:global CertificateDownload;
:if ([ / certificate print count-only where common-name=$CommonName ] = 0) do={
:log info ("Certificate with CommonName " . $CommonName . " not available.");
$CertificateDownload $CommonName;
}
}