From 8e38a11e467aa059cd3cfe64575a1488dc14eae2 Mon Sep 17 00:00:00 2001 From: Cyrille Date: Thu, 9 May 2019 22:16:52 +0100 Subject: [PATCH] getPromises() --- lib/certificates/check.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/certificates/check.js b/lib/certificates/check.js index 559a336..d8b795a 100644 --- a/lib/certificates/check.js +++ b/lib/certificates/check.js @@ -3,7 +3,7 @@ const s3 = new AWS.S3({ apiVersion: "2006-03-01" }); const pathHelper = require("../pathHelper"); const fileNames = require("../fileNames"); -const setPaths = (opts, options, id) => { +const getPaths = (opts, options, id) => { return [ pathHelper.certificatesPath(options, id, fileNames.privkey.pem) , pathHelper.certificatesPath(options, id, fileNames.cert) @@ -11,13 +11,8 @@ const setPaths = (opts, options, id) => { ] }; -module.exports.check = (opts, options) => { - const id = opts.certificate && opts.certificate.id || opts.subject; - console.log("certificates.check for", opts.subject); - - const paths = setPaths(opts, options, id); - - var promises = []; +const getPromises = (options, paths) => { + let promises = []; for (let i = 0; i < paths.length; i++) { const key = paths[i]; @@ -31,6 +26,16 @@ module.exports.check = (opts, options) => { promises.push(promise); } + return promises; +} + +module.exports.check = (opts, options) => { + const id = opts.certificate && opts.certificate.id || opts.subject; + console.log("certificates.check for", opts.subject); + + const paths = getPaths(opts, options, id); + const promises = getPromises(options, paths); + return Promise.all(promises).then((values) => { return { privkey: values[0]