gl-store-s3.js/lib/certificates/check.js

44 lines
1.9 KiB
JavaScript
Raw Normal View History

2019-05-08 23:01:23 +00:00
const pathHelper = require("../pathHelper");
const fileNames = require("../fileNames");
2019-05-08 16:12:22 +00:00
module.exports.check = (opts, options, s3) => {
var id = opts.certificate && opts.certificate.id || opts.subject;
2019-05-08 23:01:23 +00:00
console.log("certificates.check for", opts.subject);
2019-05-08 16:12:22 +00:00
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);
return Promise.all([
s3.getObject({ Key: privkeyPath, Bucket: options.bucketName }).promise().then((data) => {
2019-05-08 23:01:23 +00:00
console.log("Successfully retrieved certificate privkey.pem");
2019-05-08 16:12:22 +00:00
return data.Body.toString();
}).catch((err) => {
2019-05-08 23:01:23 +00:00
console.error("There was an error retrieving your certificate privkey.pem:", err.message);
2019-05-08 16:12:22 +00:00
throw err;
}),
s3.getObject({ Key: certPath, Bucket: options.bucketName }).promise().then((data) => {
2019-05-08 23:01:23 +00:00
console.log("Successfully retrieved certificate cert.pem");
2019-05-08 16:12:22 +00:00
return data.Body.toString();
}).catch((err) => {
2019-05-08 23:01:23 +00:00
console.error("There was an error retrieving your certificate cert.pem:", err.message);
2019-05-08 16:12:22 +00:00
throw err;
}),
s3.getObject({ Key: chainPath, Bucket: options.bucketName }).promise().then((data) => {
2019-05-08 23:01:23 +00:00
console.log("Successfully retrieved certificate chain.pem");
2019-05-08 16:12:22 +00:00
return data.Body.toString();
}).catch((err) => {
2019-05-08 23:01:23 +00:00
console.error("There was an error retrieving your certificate chain.pem:", err.message);
2019-05-08 16:12:22 +00:00
throw err;
})
]).then((values) => {
return {
privkey: values[0]
, cert: values[1]
, chain: values[2]
2019-05-08 23:12:15 +00:00
};
2019-05-08 16:12:22 +00:00
}).catch((err) => {
2019-05-08 23:01:23 +00:00
console.error("There was an error checking the ceritifcates:", err.message);
2019-05-08 16:12:22 +00:00
return null;
});
2019-05-08 23:01:23 +00:00
};