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

24 lines
894 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-05-09 00:01:23 +01:00
console.log("accounts.setKeypair for", opts.account);
2019-05-08 17:12:22 +01:00
2019-05-09 00:01:23 +01:00
let id = opts.account.id || opts.email || "single-user";
2019-05-09 00:12:15 +01:00
let key = pathHelper.accountsPath(options, id);
2019-05-08 17:12:22 +01:00
var body = JSON.stringify({
privateKeyPem: opts.keypair.privateKeyPem // string PEM
, privateKeyJwk: opts.keypair.privateKeyJwk // object JWK
});
return s3.putObject({ Key: key, Body: body, Bucket: options.bucketName }).promise().then((data) => {
2019-05-09 00:01:23 +01:00
console.log("Successfully created account keypair.");
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 creating account keypair:", err.message);
2019-05-08 17:12:22 +01:00
return null;
});
2019-05-09 08:36:47 +01:00
};