-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
51 lines (42 loc) · 1.04 KB
/
index.js
File metadata and controls
51 lines (42 loc) · 1.04 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const dotenv = require('dotenv');
const fs = require('fs');
const { encryptEnv, decryptEnv } = require('./src/lib/utils');
function decrypt({ key, algo = 'aes-256-ctr', enc = '.env.enc', addToProcess = true, realOutput = false, outputDecryptFile = false }) {
const output = decryptEnv({ key, enc, algo });
const envs = dotenv.parse(output);
if (outputDecryptFile) {
fs.writeFileSync('.env', output);
}
const needToAdd = {};
const keys = Object.keys(envs);
keys.forEach((key) => {
let value = envs[key];
if (!isNaN(value)) {
value = Number(value);
}
envs[key] = value;
if (process.env[key]) return;
needToAdd[key] = value;
});
if (addToProcess) {
process.env = {
...process.env,
...needToAdd
};
}
if (realOutput) {
return output;
}
return envs;
}
function encrypt({ key, algo = 'aes-256-ctr', env = '.env', output = false }) {
const result = encryptEnv({ key, env, algo });
if (output) {
return result;
}
return '';
}
module.exports = {
encrypt,
decrypt
};