2
0
mirror of https://github.com/cderche/greenlock-storage-s3 synced 2025-02-22 14:18:05 +00:00

20 lines
906 B
JavaScript
Raw Normal View History

2019-05-09 21:20:14 +01:00
const AWS = require("aws-sdk");
const s3 = new AWS.S3({ apiVersion: "2006-03-01" });
2019-05-09 00:01:23 +01:00
const pathHelper = require("../pathHelper");
const fileNames = require("../fileNames");
2019-05-08 17:12:22 +01:00
2019-05-09 21:20:14 +01:00
module.exports.setKeypair = (opts, options) => {
2019-06-02 19:35:51 -07:00
let id = (opts.certificate && (opts.certificate.kid || opts.certificate.id)) || opts.subject;
2019-05-09 00:01:23 +01:00
console.log("certificates.setKeypair for", id);
2019-05-08 17:12:22 +01:00
2019-05-09 00:01:23 +01:00
let pemKeyPath = pathHelper.certificatesPath(options, id, fileNames.privkey.pem);
2019-05-09 21:20:14 +01:00
// let jwkKeyPath = pathHelper.certificatesPath(options, id, fileNames.privkey.jwk);
2019-05-08 17:12:22 +01:00
return s3.putObject({ Key: pemKeyPath, Body: opts.keypair.privateKeyPem, Bucket: options.bucketName }).promise().then((data) => {
2019-05-09 00:01:23 +01:00
console.log("Successfully set the PEM privateKey.");
2019-05-08 17:12:22 +01:00
return null;
}).catch((err) => {
2019-05-09 00:01:23 +01:00
console.error("There was an error setting your PEM privateKey:", err.message);
2019-05-08 17:12:22 +01:00
throw err;
});
2019-05-09 00:12:15 +01:00
};