-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstoreKeyFile.js
More file actions
28 lines (26 loc) · 989 Bytes
/
storeKeyFile.js
File metadata and controls
28 lines (26 loc) · 989 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
* Stores an ejson keypair in the `ejson-keys` directory.
*/
const fs = require("fs");
const path = require("path");
/**
* Create an `ejson` key file in the local 'ejson-keys' directory from the
* process environment (expecting `EJSON_PUBLIC_KEY`, and `EJSON_PRIVATE_KEY`).
*/
function createKeyFile() {
if (!process.env.EJSON_PUBLIC_KEY || process.env.EJSON_PUBLIC_KEY.length < 0) {
console.error("Please specify a EJSON_PUBLIC_KEY environment variable");
process.exit(1);
}
if (!process.env.EJSON_PRIVATE_KEY || process.env.EJSON_PRIVATE_KEY.length < 0) {
console.error("Please specify a EJSON_PRIVATE_KEY environment variable");
process.exit(1);
}
const publicKey = process.env.EJSON_PUBLIC_KEY;
const privateKey = process.env.EJSON_PRIVATE_KEY;
const writeDir = path.resolve(".", "ejson-keys");
const dest = path.join(writeDir, publicKey);
fs.mkdirSync(writeDir, { recursive: true });
fs.writeFileSync(dest, privateKey);
}
createKeyFile();