prosodyctl: cert import: Reuse function from certmanager for locating certificates and keys
authorKim Alvefur <zash@zash.se>
Wed, 27 Sep 2017 15:21:20 +0200
changeset 8277 3798955049e3
parent 8276 ca881f4bc415
child 8278 13dad833e821
prosodyctl: cert import: Reuse function from certmanager for locating certificates and keys
core/certmanager.lua
prosodyctl
--- a/core/certmanager.lua	Wed Sep 27 05:27:22 2017 +0200
+++ b/core/certmanager.lua	Wed Sep 27 15:21:20 2017 +0200
@@ -231,4 +231,5 @@
 return {
 	create_context = create_context;
 	reload_ssl_config = reload_ssl_config;
+	find_cert = find_cert;
 };
--- a/prosodyctl	Wed Sep 27 05:27:22 2017 +0200
+++ b/prosodyctl	Wed Sep 27 15:21:20 2017 +0200
@@ -894,18 +894,14 @@
 		owner = config.get("*", "prosody_user") or "prosody";
 		group = config.get("*", "prosody_group") or owner;
 	end
+	local cm = require "core.certmanager";
 	local imported = {};
 	for _, host in ipairs(hostnames) do
 		for _, dir in ipairs(arg) do
-			if lfs.attributes(dir .. "/" .. host .. "/fullchain.pem")
-			and lfs.attributes(dir .. "/" .. host .. "/privkey.pem") then
-				copy(dir .. "/" .. host .. "/fullchain.pem", cert_basedir .. "/" .. host .. ".crt", nil, owner, group);
-				copy(dir .. "/" .. host .. "/privkey.pem", cert_basedir .. "/" .. host .. ".key", "0377", owner, group);
-				table.insert(imported, host);
-			elseif lfs.attributes(dir .. "/" .. host .. ".crt")
-			and lfs.attributes(dir .. "/" .. host .. ".key") then
-				copy(dir .. "/" .. host .. ".crt", cert_basedir .. "/" .. host .. ".crt", nil, owner, group);
-				copy(dir .. "/" .. host .. ".key", cert_basedir .. "/" .. host .. ".key", "0377", owner, group);
+			local paths = cm.find_cert(dir, host);
+			if paths then
+				copy(paths.certificate, cert_basedir .. "/" .. host .. ".crt", nil, owner, group);
+				copy(paths.key, cert_basedir .. "/" .. host .. ".key", "0377", owner, group);
 				table.insert(imported, host);
 			else
 				-- TODO Say where we looked