From caf56d2e4ee937e8b4a9675c02ab7c44f25be317 Mon Sep 17 00:00:00 2001 From: Cyrille Date: Thu, 9 May 2019 21:36:29 +0100 Subject: [PATCH] Refactor lib/certificates/set.js --- lib/certificates/set.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/certificates/set.js b/lib/certificates/set.js index f94eb0f..4805c11 100644 --- a/lib/certificates/set.js +++ b/lib/certificates/set.js @@ -3,10 +3,8 @@ const s3 = new AWS.S3({ apiVersion: "2006-03-01" }); const pathHelper = require("../pathHelper"); const fileNames = require("../fileNames"); -module.exports.set = (opts, options) => { - console.log("certificates.set for ", opts.subject); - - let objects = [ +setObjects = (opts, options) => { + return [ { Key: pathHelper.certificatesPath(options, opts.subject, fileNames.cert) , Body: opts.pems.cert @@ -23,9 +21,11 @@ module.exports.set = (opts, options) => { Key: pathHelper.certificatesPath(options, opts.subject, fileNames.bundle) , Body: [opts.pems.privkey, opts.pems.cert, opts.pems.chain].join("\n") // for HAProxy } - ] + ]; +}; - var promises = []; +setPromises = (objects, options) => { + let promises = []; for (let i = 0; i < objects.length; i++) { const obj = objects[i]; @@ -38,6 +38,15 @@ module.exports.set = (opts, options) => { promises.push(promise); } + return promises; +}; + +module.exports.set = (opts, options) => { + console.log("certificates.set for ", opts.subject); + + const objects = setObjects(opts, options); + const promises = setPromises(objects, options); + return Promise.all(promises).then((values) => { return null; }).catch((err) => {