cryptoenv
Advanced tools
Comparing version 0.1.4 to 0.1.5
{ | ||
"name": "cryptoenv", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "Manage encrypted env variables", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/secrez/cryptoenv#readme", |
@@ -106,2 +106,10 @@ # CryptoEnv | ||
## Enable/disable | ||
It can be annoying be forced to skip the decryption all the time you launch a compilation or a test. To toggle the configuration, i.e., disable or enable the encrypted variable, you can run | ||
```shell | ||
cryptoEnv -t | ||
``` | ||
## About security | ||
@@ -108,0 +116,0 @@ |
@@ -42,19 +42,17 @@ const path = require("path"); | ||
async toggle() { | ||
if (fs.existsSync(this.envPath)) { | ||
let env = fs.readFileSync(this.envPath, "utf8").split("\n"); | ||
let variables = {}; | ||
if (await fs.pathExists(this.envPath)) { | ||
let env = (await fs.readFile(this.envPath, "utf8")).split("\n"); | ||
let newEnv = []; | ||
for (let variable of env) { | ||
if (RegExp(`^#{0,1}${this.prefix}([^=]+)=`).test(variable)) { | ||
let key = variable.split(this.prefix)[1].split("=")[0]; | ||
let encVariable = variable.slice(variable.indexOf("=") + 1); | ||
for (let row of env) { | ||
if (RegExp(`^#{0,1}${this.prefix}([^=]+)=`).test(row)) { | ||
let encVariable = row.slice(row.indexOf("=") + 1); | ||
if (this.isBase64(encVariable)) { | ||
if (/^#/.test(variable)) { | ||
variable = variable.substring(1); | ||
if (/^#/.test(row)) { | ||
row = row.substring(1); | ||
} else { | ||
variable = "#" + variable; | ||
row = "#" + row; | ||
} | ||
} | ||
} | ||
newEnv.push(variable); | ||
newEnv.push(row); | ||
} | ||
@@ -65,2 +63,13 @@ await fs.writeFile(this.envPath, newEnv.join("\n") + "\n"); | ||
hasDisabled() { | ||
if (fs.existsSync(this.envPath)) { | ||
let env = fs.readFileSync(this.envPath, "utf8").split("\n"); | ||
for (let row of env) { | ||
if (RegExp(`^#${this.prefix}([^=]+)=`).test(row)) { | ||
return true; | ||
} | ||
} | ||
} | ||
} | ||
list(asIs) { | ||
@@ -70,6 +79,6 @@ if (fs.existsSync(this.envPath)) { | ||
let variables = {}; | ||
for (let variable of env) { | ||
if (RegExp(`^${this.prefix}([^=]+)=`).test(variable)) { | ||
let key = variable.split(this.prefix)[1].split("=")[0]; | ||
let encVariable = variable.slice(variable.indexOf("=") + 1); | ||
for (let row of env) { | ||
if (RegExp(`^${this.prefix}([^=]+)=`).test(row)) { | ||
let key = row.split(this.prefix)[1].split("=")[0]; | ||
let encVariable = row.slice(row.indexOf("=") + 1); | ||
if (this.isBase64(encVariable)) { | ||
@@ -182,3 +191,11 @@ variables[key] = encVariable; | ||
if (Object.keys(this.keys).length === 0) { | ||
console.info(chalk.grey(`CryptoEnv > no encrypted keys found`)); | ||
if (this.hasDisabled()) { | ||
console.info( | ||
chalk.grey( | ||
`CryptoEnv > some encrypted keys are disabled. Run "cryptoEnv -t" to enable them` | ||
) | ||
); | ||
} else { | ||
console.info(chalk.grey(`CryptoEnv > no encrypted keys found`)); | ||
} | ||
process.env.__decryptionAlreadyDone__ = "TRUE"; | ||
@@ -185,0 +202,0 @@ return; |
29046
437
156