From 6f281fef42504d691b32f7f8159e5445a4746bd8 Mon Sep 17 00:00:00 2001 From: Jamie Curnow Date: Tue, 15 Nov 2022 07:48:57 +1000 Subject: [PATCH] Workaround for cloudflare plugin install (#2381) --- backend/internal/certificate.js | 7 ++++++- backend/setup.js | 20 ++++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/backend/internal/certificate.js b/backend/internal/certificate.js index 7c8fdde..c0b3c85 100644 --- a/backend/internal/certificate.js +++ b/backend/internal/certificate.js @@ -874,7 +874,12 @@ const internalCertificate = { // Escape single quotes and backslashes const escapedCredentials = certificate.meta.dns_provider_credentials.replaceAll('\'', '\\\'').replaceAll('\\', '\\\\'); const credentialsCmd = 'mkdir -p /etc/letsencrypt/credentials 2> /dev/null; echo \'' + escapedCredentials + '\' > \'' + credentialsLocation + '\' && chmod 600 \'' + credentialsLocation + '\''; - const prepareCmd = 'pip install ' + dns_plugin.package_name + (dns_plugin.version_requirement || '') + ' ' + dns_plugin.dependencies; + let prepareCmd = 'pip install ' + dns_plugin.package_name + (dns_plugin.version_requirement || '') + ' ' + dns_plugin.dependencies; + + // Special case for cloudflare + if (dns_plugin.package_name === 'certbot-dns-cloudflare') { + prepareCmd = 'pip install certbot-dns-cloudflare --index-url https://www.piwheels.org/simple --prefer-binary'; + } // Whether the plugin has a ---credentials argument const hasConfigArg = certificate.meta.dns_provider !== 'route53'; diff --git a/backend/setup.js b/backend/setup.js index 47fd1e7..225a2f8 100644 --- a/backend/setup.js +++ b/backend/setup.js @@ -171,16 +171,20 @@ const setupCertbotPlugins = () => { if (certificates && certificates.length) { let plugins = []; let promises = []; + let install_cloudflare_plugin = false; certificates.map(function (certificate) { if (certificate.meta && certificate.meta.dns_challenge === true) { const dns_plugin = dns_plugins[certificate.meta.dns_provider]; - const packages_to_install = `${dns_plugin.package_name}${dns_plugin.version_requirement || ''} ${dns_plugin.dependencies}`; - - if (plugins.indexOf(packages_to_install) === -1) plugins.push(packages_to_install); + if (dns_plugin.package_name === 'certbot-dns-cloudflare') { + install_cloudflare_plugin = true; + } else { + const packages_to_install = `${dns_plugin.package_name}${dns_plugin.version_requirement || ''} ${dns_plugin.dependencies}`; + if (plugins.indexOf(packages_to_install) === -1) plugins.push(packages_to_install); + } // Make sure credentials file exists - const credentials_loc = '/etc/letsencrypt/credentials/credentials-' + certificate.id; + const credentials_loc = '/etc/letsencrypt/credentials/credentials-' + certificate.id; // Escape single quotes and backslashes const escapedCredentials = certificate.meta.dns_provider_credentials.replaceAll('\'', '\\\'').replaceAll('\\', '\\\\'); const credentials_cmd = '[ -f \'' + credentials_loc + '\' ] || { mkdir -p /etc/letsencrypt/credentials 2> /dev/null; echo \'' + escapedCredentials + '\' > \'' + credentials_loc + '\' && chmod 600 \'' + credentials_loc + '\'; }'; @@ -193,10 +197,14 @@ const setupCertbotPlugins = () => { promises.push(utils.exec(install_cmd)); } + if (install_cloudflare_plugin) { + promises.push(utils.exec('pip install certbot-dns-cloudflare --index-url https://www.piwheels.org/simple --prefer-binary')); + } + if (promises.length) { return Promise.all(promises) - .then(() => { - logger.info('Added Certbot plugins ' + plugins.join(', ')); + .then(() => { + logger.info('Added Certbot plugins ' + plugins.join(', ')); }); } }