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

23 lines
967 B
JavaScript
Raw Normal View History

2019-05-09 20:20:14 +00:00
const AWS = require("aws-sdk");
const s3 = new AWS.S3({ apiVersion: "2006-03-01" });
2019-05-08 23:01:23 +00:00
const pathHelper = require("../pathHelper");
const fileNames = require("../fileNames");
2019-05-08 16:12:22 +00:00
2019-05-09 20:20:14 +00:00
module.exports.checkKeypair = (opts, options) => {
2019-05-08 23:01:23 +00:00
console.log("certificates.checkKeypair for", opts.subject);
2019-05-08 16:12:22 +00:00
2019-06-03 02:35:51 +00:00
let id = (opts.certificate && (opts.certificate.kid || opts.certificate.id)) || opts.subject;
2019-05-08 16:12:22 +00:00
2019-05-08 23:12:15 +00:00
let pemKeyPath = pathHelper.certificatesPath(options, id, fileNames.privkey.pem);
2019-05-09 21:18:09 +00:00
// let jwkKeyPath = pathHelper.certificatesPath(options, id, fileNames.privkey.jwk);
2019-05-08 16:12:22 +00:00
return s3.getObject({ Key: pemKeyPath, Bucket: options.bucketName }).promise().then((data) => {
2019-05-08 23:01:23 +00:00
console.log("Successfully retrieved certificate PEM keypair.");
2019-05-08 16:12:22 +00:00
return {
privateKeyPem: data.Body.toString()
2019-05-09 07:36:47 +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 retrieving your certificate PEM keypair:", err.message);
2019-05-08 16:12:22 +00:00
return null;
});
2019-05-08 23:12:15 +00:00
};