Refactored certificates/checks

This commit is contained in:
Cyrille 2019-05-09 21:01:39 +01:00
parent 526713d99d
commit b484efb75e
1 changed files with 16 additions and 22 deletions

View File

@ -5,33 +5,27 @@ module.exports.check = (opts, options, s3) => {
var id = opts.certificate && opts.certificate.id || opts.subject;
console.log("certificates.check for", opts.subject);
var privkeyPath = pathHelper.certificatesPath(options, id, fileNames.privkey.pem);
var certPath = pathHelper.certificatesPath(options, id, fileNames.cert);
var chainPath = pathHelper.certificatesPath(options, id, fileNames.chain);
let paths = [
pathHelper.certificatesPath(options, id, fileNames.privkey.pem)
, pathHelper.certificatesPath(options, id, fileNames.cert)
, pathHelper.certificatesPath(options, id, fileNames.chain)
]
return Promise.all([
s3.getObject({ Key: privkeyPath, Bucket: options.bucketName }).promise().then((data) => {
console.log("Successfully retrieved certificate privkey.pem");
var promises = [];
for (let i = 0; i < paths.length; i++) {
const key = paths[i];
const promise = s3.getObject({ Key: key, Bucket: options.bucketName }).promise().then((data) => {
console.log("Successfully retrieved certificate", key);
return data.Body.toString();
}).catch((err) => {
console.error("There was an error retrieving your certificate privkey.pem:", err.message);
throw err;
}),
s3.getObject({ Key: certPath, Bucket: options.bucketName }).promise().then((data) => {
console.log("Successfully retrieved certificate cert.pem");
return data.Body.toString();
}).catch((err) => {
console.error("There was an error retrieving your certificate cert.pem:", err.message);
throw err;
}),
s3.getObject({ Key: chainPath, Bucket: options.bucketName }).promise().then((data) => {
console.log("Successfully retrieved certificate chain.pem");
return data.Body.toString();
}).catch((err) => {
console.error("There was an error retrieving your certificate chain.pem:", err.message);
console.error("There was an error retrieving your certificate", key);
throw err;
})
]).then((values) => {
promises.push(promise);
}
return Promise.all(promises).then((values) => {
return {
privkey: values[0]
, cert: values[1]