You've already forked nginx-proxy-manager
							
							
				mirror of
				https://github.com/NginxProxyManager/nginx-proxy-manager.git
				synced 2025-10-30 18:05:34 +03:00 
			
		
		
		
	Convert backend to ESM
- About 5 years overdue - Remove eslint, use bomejs instead
This commit is contained in:
		| @@ -1,85 +1,87 @@ | ||||
| const dnsPlugins = require('../global/certbot-dns-plugins.json'); | ||||
| const utils      = require('./utils'); | ||||
| const error      = require('./error'); | ||||
| const logger     = require('../logger').certbot; | ||||
| const batchflow  = require('batchflow'); | ||||
| import batchflow from "batchflow"; | ||||
| import dnsPlugins from "../global/certbot-dns-plugins.json" with { type: "json" }; | ||||
| import { certbot as logger } from "../logger.js"; | ||||
| import errs from "./error.js"; | ||||
| import utils from "./utils.js"; | ||||
|  | ||||
| const CERTBOT_VERSION_REPLACEMENT = '$(certbot --version | grep -Eo \'[0-9](\\.[0-9]+)+\')'; | ||||
| const CERTBOT_VERSION_REPLACEMENT = "$(certbot --version | grep -Eo '[0-9](\\.[0-9]+)+')"; | ||||
|  | ||||
| const certbot = { | ||||
| /** | ||||
|  * @param {array} pluginKeys | ||||
|  */ | ||||
| const installPlugins = async (pluginKeys) => { | ||||
| 	let hasErrors = false; | ||||
|  | ||||
| 	/** | ||||
| 	 * @param {array} pluginKeys | ||||
| 	 */ | ||||
| 	installPlugins: async (pluginKeys) => { | ||||
| 		let hasErrors = false; | ||||
|  | ||||
| 		return new Promise((resolve, reject) => { | ||||
| 			if (pluginKeys.length === 0) { | ||||
| 				resolve(); | ||||
| 				return; | ||||
| 			} | ||||
|  | ||||
| 			batchflow(pluginKeys).sequential() | ||||
| 				.each((_i, pluginKey, next) => { | ||||
| 					certbot.installPlugin(pluginKey) | ||||
| 						.then(() => { | ||||
| 							next(); | ||||
| 						}) | ||||
| 						.catch((err) => { | ||||
| 							hasErrors = true; | ||||
| 							next(err); | ||||
| 						}); | ||||
| 				}) | ||||
| 				.error((err) => { | ||||
| 					logger.error(err.message); | ||||
| 				}) | ||||
| 				.end(() => { | ||||
| 					if (hasErrors) { | ||||
| 						reject(new error.CommandError('Some plugins failed to install. Please check the logs above', 1)); | ||||
| 					} else { | ||||
| 						resolve(); | ||||
| 					} | ||||
| 				}); | ||||
| 		}); | ||||
| 	}, | ||||
|  | ||||
| 	/** | ||||
| 	 * Installs a cerbot plugin given the key for the object from | ||||
| 	 * ../global/certbot-dns-plugins.json | ||||
| 	 * | ||||
| 	 * @param   {string}  pluginKey | ||||
| 	 * @returns {Object} | ||||
| 	 */ | ||||
| 	installPlugin: async (pluginKey) => { | ||||
| 		if (typeof dnsPlugins[pluginKey] === 'undefined') { | ||||
| 			// throw Error(`Certbot plugin ${pluginKey} not found`); | ||||
| 			throw new error.ItemNotFoundError(pluginKey); | ||||
| 	return new Promise((resolve, reject) => { | ||||
| 		if (pluginKeys.length === 0) { | ||||
| 			resolve(); | ||||
| 			return; | ||||
| 		} | ||||
|  | ||||
| 		const plugin = dnsPlugins[pluginKey]; | ||||
| 		logger.start(`Installing ${pluginKey}...`); | ||||
|  | ||||
| 		plugin.version      = plugin.version.replace(/{{certbot-version}}/g, CERTBOT_VERSION_REPLACEMENT); | ||||
| 		plugin.dependencies = plugin.dependencies.replace(/{{certbot-version}}/g, CERTBOT_VERSION_REPLACEMENT); | ||||
|  | ||||
| 		// SETUPTOOLS_USE_DISTUTILS is required for certbot plugins to install correctly | ||||
| 		// in new versions of Python | ||||
| 		let env = Object.assign({}, process.env, {SETUPTOOLS_USE_DISTUTILS: 'stdlib'}); | ||||
| 		if (typeof plugin.env === 'object') { | ||||
| 			env = Object.assign(env, plugin.env); | ||||
| 		} | ||||
|  | ||||
| 		const cmd = `. /opt/certbot/bin/activate && pip install --no-cache-dir ${plugin.dependencies} ${plugin.package_name}${plugin.version}  && deactivate`; | ||||
| 		return utils.exec(cmd, {env}) | ||||
| 			.then((result) => { | ||||
| 				logger.complete(`Installed ${pluginKey}`); | ||||
| 				return result; | ||||
| 		batchflow(pluginKeys) | ||||
| 			.sequential() | ||||
| 			.each((_i, pluginKey, next) => { | ||||
| 				certbot | ||||
| 					.installPlugin(pluginKey) | ||||
| 					.then(() => { | ||||
| 						next(); | ||||
| 					}) | ||||
| 					.catch((err) => { | ||||
| 						hasErrors = true; | ||||
| 						next(err); | ||||
| 					}); | ||||
| 			}) | ||||
| 			.catch((err) => { | ||||
| 				throw err; | ||||
| 			.error((err) => { | ||||
| 				logger.error(err.message); | ||||
| 			}) | ||||
| 			.end(() => { | ||||
| 				if (hasErrors) { | ||||
| 					reject( | ||||
| 						new errs.CommandError("Some plugins failed to install. Please check the logs above", 1), | ||||
| 					); | ||||
| 				} else { | ||||
| 					resolve(); | ||||
| 				} | ||||
| 			}); | ||||
| 	}, | ||||
| 	}); | ||||
| }; | ||||
|  | ||||
| module.exports = certbot; | ||||
| /** | ||||
|  * Installs a cerbot plugin given the key for the object from | ||||
|  * ../global/certbot-dns-plugins.json | ||||
|  * | ||||
|  * @param   {string}  pluginKey | ||||
|  * @returns {Object} | ||||
|  */ | ||||
| const installPlugin = async (pluginKey) => { | ||||
| 	if (typeof dnsPlugins[pluginKey] === "undefined") { | ||||
| 		// throw Error(`Certbot plugin ${pluginKey} not found`); | ||||
| 		throw new errs.ItemNotFoundError(pluginKey); | ||||
| 	} | ||||
|  | ||||
| 	const plugin = dnsPlugins[pluginKey]; | ||||
| 	logger.start(`Installing ${pluginKey}...`); | ||||
|  | ||||
| 	plugin.version = plugin.version.replace(/{{certbot-version}}/g, CERTBOT_VERSION_REPLACEMENT); | ||||
| 	plugin.dependencies = plugin.dependencies.replace(/{{certbot-version}}/g, CERTBOT_VERSION_REPLACEMENT); | ||||
|  | ||||
| 	// SETUPTOOLS_USE_DISTUTILS is required for certbot plugins to install correctly | ||||
| 	// in new versions of Python | ||||
| 	let env = Object.assign({}, process.env, { SETUPTOOLS_USE_DISTUTILS: "stdlib" }); | ||||
| 	if (typeof plugin.env === "object") { | ||||
| 		env = Object.assign(env, plugin.env); | ||||
| 	} | ||||
|  | ||||
| 	const cmd = `. /opt/certbot/bin/activate && pip install --no-cache-dir ${plugin.dependencies} ${plugin.package_name}${plugin.version}  && deactivate`; | ||||
| 	return utils | ||||
| 		.exec(cmd, { env }) | ||||
| 		.then((result) => { | ||||
| 			logger.complete(`Installed ${pluginKey}`); | ||||
| 			return result; | ||||
| 		}) | ||||
| 		.catch((err) => { | ||||
| 			throw err; | ||||
| 		}); | ||||
| }; | ||||
|  | ||||
| export { installPlugins, installPlugin }; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user