aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorJonas Schäfer <jonas@wielicki.name>2021-12-21 21:20:21 +0100
committerJonas Schäfer <jonas@wielicki.name>2021-12-21 21:20:21 +0100
commit7c93370ad564fc9176b97cf981ed7e10e05d8890 (patch)
treeb63c715519099134c75900e0d7b1f9d7b04070d8 /util
parenta7f535e0cf44a188207ad49b88831f449812c8bf (diff)
downloadprosody-7c93370ad564fc9176b97cf981ed7e10e05d8890.tar.gz
prosody-7c93370ad564fc9176b97cf981ed7e10e05d8890.zip
prosodyctl cert: use the indexing functions for better UX
These provide (a) a way to deal with random assortments of certs and (b) avoid unnecessary error messages and warnings, according to #1669 anyway, which this fixes.
Diffstat (limited to 'util')
-rw-r--r--util/prosodyctl/cert.lua28
1 files changed, 15 insertions, 13 deletions
diff --git a/util/prosodyctl/cert.lua b/util/prosodyctl/cert.lua
index 2b96ac5c..d37bb82c 100644
--- a/util/prosodyctl/cert.lua
+++ b/util/prosodyctl/cert.lua
@@ -216,22 +216,24 @@ function cert_commands.import(arg)
group = configmanager.get("*", "prosody_group") or owner;
end
local cm = require "core.certmanager";
+ local files_by_name = {}
+ for _, dir in ipairs(arg) do
+ cm.index_certs(dir, files_by_name);
+ end
local imported = {};
for _, host in ipairs(hostnames) do
- for _, dir in ipairs(arg) do
- 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
- pctl.show_warning("No certificate for host "..host.." found :(");
- end
- -- TODO Additional checks
- -- Certificate names matches the hostname
- -- Private key matches public key in certificate
+ local paths = cm.find_cert_in_index(files_by_name, 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
+ pctl.show_warning("No certificate for host "..host.." found :(");
end
+ -- TODO Additional checks
+ -- Certificate names matches the hostname
+ -- Private key matches public key in certificate
end
if imported[1] then
pctl.show_message("Imported certificate and key for hosts %s", table.concat(imported, ", "));