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

18 lines
798 B
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.setKeypair = (opts, options, s3) => {
2019-05-08 23:01:23 +00:00
let id = opts.certificate.kid || opts.certificate.id || opts.subject;
console.log("certificates.setKeypair for", id);
2019-05-08 16:12:22 +00:00
2019-05-08 23:01:23 +00:00
let pemKeyPath = pathHelper.certificatesPath(options, id, fileNames.privkey.pem);
let jwkKeyPath = pathHelper.certificatesPath(options, id, fileNames.privkey.jwk);
2019-05-08 16:12:22 +00:00
return s3.putObject({ Key: pemKeyPath, Body: opts.keypair.privateKeyPem, Bucket: options.bucketName }).promise().then((data) => {
2019-05-08 23:01:23 +00:00
console.log("Successfully set the PEM privateKey.");
2019-05-08 16:12:22 +00:00
return null;
}).catch((err) => {
2019-05-08 23:01:23 +00:00
console.error("There was an error setting your PEM privateKey:", err.message);
2019-05-08 16:12:22 +00:00
throw err;
});
2019-05-08 23:12:15 +00:00
};