getPromises()

This commit is contained in:
Cyrille 2019-05-09 22:16:52 +01:00
parent 0f5eebd9cc
commit 8e38a11e46
1 changed files with 13 additions and 8 deletions

View File

@ -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]