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.set = (opts, options, s3) => {
|
2019-05-08 23:01:23 +00:00
|
|
|
console.log("certificates.set for ", opts.subject);
|
2019-05-08 16:12:22 +00:00
|
|
|
|
|
|
|
var pems = {
|
|
|
|
cert: opts.pems.cert
|
|
|
|
, chain: opts.pems.chain
|
|
|
|
, privkey: opts.pems.privkey
|
|
|
|
}
|
|
|
|
|
|
|
|
var certPath = pathHelper.certificatesPath(options, opts.subject, fileNames.cert);
|
|
|
|
var chainPath = pathHelper.certificatesPath(options, opts.subject, fileNames.chain);
|
|
|
|
var fullchainPath = pathHelper.certificatesPath(options, opts.subject, fileNames.fullchain);
|
|
|
|
var bundlePath = pathHelper.certificatesPath(options, opts.subject, fileNames.bundle);
|
|
|
|
|
2019-05-08 23:01:23 +00:00
|
|
|
var fullchainPem = [pems.cert, pems.chain].join("\n"); // for Apache, Nginx, etc
|
|
|
|
var bundlePem = [pems.privkey, pems.cert, pems.chain].join("\n"); // for HAProxy
|
2019-05-08 16:12:22 +00:00
|
|
|
|
|
|
|
return Promise.all([
|
|
|
|
s3.putObject({ Key: certPath, Body: pems.cert, Bucket: options.bucketName }).promise().then((data) => {
|
2019-05-08 23:01:23 +00:00
|
|
|
console.log("Successfully set", certPath);
|
2019-05-08 16:12:22 +00:00
|
|
|
}).catch((err) => {
|
2019-05-08 23:01:23 +00:00
|
|
|
console.error("There was an error setting cert.pem:", err.message);
|
2019-05-08 16:12:22 +00:00
|
|
|
throw err;
|
|
|
|
}),
|
|
|
|
s3.putObject({ Key: chainPath, Body: pems.chain, Bucket: options.bucketName }).promise().then((data) => {
|
2019-05-08 23:01:23 +00:00
|
|
|
console.log("Successfully set", chainPath);
|
2019-05-08 16:12:22 +00:00
|
|
|
}).catch((err) => {
|
2019-05-08 23:01:23 +00:00
|
|
|
console.error("There was an error setting chain.pem:", err.message);
|
2019-05-08 16:12:22 +00:00
|
|
|
throw err;
|
|
|
|
}),
|
|
|
|
s3.putObject({ Key: fullchainPath, Body: fullchainPem, Bucket: options.bucketName }).promise().then((data) => {
|
2019-05-08 23:01:23 +00:00
|
|
|
console.log("Successfully set", fullchainPath);
|
2019-05-08 16:12:22 +00:00
|
|
|
}).catch((err) => {
|
2019-05-08 23:01:23 +00:00
|
|
|
console.error("There was an error setting fullchain.pem:", err.message);
|
2019-05-08 16:12:22 +00:00
|
|
|
throw err;
|
|
|
|
}),
|
|
|
|
s3.putObject({ Key: bundlePath, Body: bundlePem, Bucket: options.bucketName }).promise().then((data) => {
|
2019-05-08 23:01:23 +00:00
|
|
|
console.log("Successfully set", bundlePath);
|
2019-05-08 16:12:22 +00:00
|
|
|
}).catch((err) => {
|
2019-05-08 23:01:23 +00:00
|
|
|
console.error("There was an error setting bundle.pem:", err.message);
|
2019-05-08 16:12:22 +00:00
|
|
|
throw err;
|
|
|
|
})
|
|
|
|
]).then((values) => {
|
|
|
|
return null;
|
|
|
|
}).catch((err) => {
|
2019-05-08 23:01:23 +00:00
|
|
|
console.error("There was an error setting the certificates:", err.message);
|
2019-05-08 16:12:22 +00:00
|
|
|
throw err;
|
|
|
|
});
|
2019-05-09 07:36:47 +00:00
|
|
|
};
|