@dotenvx/dotenvx 1.5.0 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -1
- package/README.md +88 -2
- package/package.json +9 -9
- package/src/cli/actions/decrypt.js +71 -0
- package/src/cli/actions/encrypt.js +54 -42
- package/src/cli/actions/ext/genexample.js +4 -12
- package/src/cli/actions/ext/gitignore.js +5 -0
- package/src/cli/actions/ext/prebuild.js +1 -0
- package/src/cli/actions/ext/scan.js +9 -6
- package/src/cli/actions/ext/settings.js +5 -4
- package/src/cli/actions/ext/vault/decrypt.js +6 -13
- package/src/cli/actions/ext/vault/encrypt.js +5 -12
- package/src/cli/actions/ext/vault/migrate.js +22 -39
- package/src/cli/actions/get.js +6 -5
- package/src/cli/actions/run.js +3 -110
- package/src/cli/actions/set.js +2 -2
- package/src/cli/commands/ext.js +2 -32
- package/src/cli/dotenvx.js +12 -14
- package/src/lib/helpers/execute.js +9 -0
- package/src/lib/helpers/executeCommand.js +117 -0
- package/src/lib/helpers/executeExtension.js +38 -0
- package/src/lib/helpers/findOrCreatePublicKey.js +14 -8
- package/src/lib/helpers/guessEnvironment.js +4 -1
- package/src/lib/helpers/isEncrypted.js +1 -2
- package/src/lib/helpers/isFullyEncrypted.js +2 -1
- package/src/lib/helpers/isIgnoringDotenvKeys.js +1 -1
- package/src/lib/helpers/isPublicKey.js +7 -0
- package/src/lib/helpers/keyPair.js +8 -2
- package/src/lib/helpers/smartDotenvPrivateKey.js +64 -6
- package/src/lib/main.js +16 -9
- package/src/lib/services/decrypt.js +79 -98
- package/src/lib/services/encrypt.js +12 -7
- package/src/lib/services/sets.js +9 -2
- package/src/lib/services/status.js +2 -2
- package/src/lib/services/vaultDecrypt.js +126 -0
- package/src/shared/logger.js +0 -3
- package/src/cli/commands/vault.js +0 -57
- package/src/lib/helpers/clipboardy/fallbacks/linux/xsel +0 -0
- package/src/lib/helpers/clipboardy/fallbacks/windows/clipboard_i686.exe +0 -0
- package/src/lib/helpers/clipboardy/fallbacks/windows/clipboard_x86_64.exe +0 -0
- package/src/lib/helpers/clipboardy/linux.js +0 -57
- package/src/lib/helpers/clipboardy/macos.js +0 -14
- package/src/lib/helpers/clipboardy/termux.js +0 -41
- package/src/lib/helpers/clipboardy/windows.js +0 -16
- package/src/lib/helpers/clipboardy.js +0 -51
- package/src/lib/helpers/extractUsernameName.js +0 -10
- package/src/lib/helpers/forgivingDirectory.js +0 -11
- package/src/lib/helpers/gitRoot.js +0 -14
- package/src/lib/helpers/gitUrl.js +0 -13
- package/src/lib/helpers/isGitRepo.js +0 -13
- package/src/lib/helpers/isGithub.js +0 -5
- package/src/lib/helpers/resolvePath.js +0 -8
- package/src/shared/confirm.js +0 -12
- package/src/shared/createSpinner.js +0 -97
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,30 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
-
## [Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.
|
|
5
|
+
## [Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.6.1...main)
|
|
6
|
+
|
|
7
|
+
## 1.6.1
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
* added support for `.env1` (`.env*`) file format. (private key expands to `DOTENV_PRIVATE_KEY_DEVELOPMENT1`) ([#312](https://github.com/dotenvx/dotenvx/pull/312))
|
|
12
|
+
|
|
13
|
+
## 1.6.0
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
* add `dotenvx decrypt` command. works inversely to `dotenvx encrypt`. same flags. ([#294](https://github.com/dotenvx/dotenvx/pull/294))
|
|
18
|
+
* add `--stdout` option to `dotenvx decrypt`. example: `dotenvx decrypt -f .env.production > somefile.txt` ([#298](https://github.com/dotenvx/dotenvx/pull/298))
|
|
19
|
+
* add `--stdout` option to `dotenvx encrypt`. example: `dotenvx encrypt -f .env.production > somefile.txt` ([#298](https://github.com/dotenvx/dotenvx/pull/298))
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
|
|
23
|
+
* smarter private key finder. if you rename your file to `secrets.txt` it can still decrypt from `DOTENV_PRIVATE_KEY` by seeking out the invert of the `DOTENV_PUBLIC_KEY` inside `secrets.txt` ([#302](https://github.com/dotenvx/dotenvx/pull/302))
|
|
24
|
+
|
|
25
|
+
### Removed
|
|
26
|
+
|
|
27
|
+
* remove `dotenvx convert` - still at `dotenvx encrypt`
|
|
28
|
+
* remove `dotenvx vault` - still at `dotenvx ext vault`
|
|
6
29
|
|
|
7
30
|
## 1.5.0
|
|
8
31
|
|
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
### Quickstart [](https://www.npmjs.com/package/@dotenvx/dotenvx) [](https://github.com/dotenvx/dotenvx/tree/main/tests) [](https://www.npmjs.com/package/@dotenvx/dotenvx) [](https://github.com/dotenvx/dotenvx/tree/main/tests) [](https://www.npmjs.com/package/@dotenvx/dotenvx)
|
|
13
13
|
|
|
14
14
|
Install and use it in code just like `dotenv`.
|
|
15
15
|
|
|
@@ -660,6 +660,16 @@ More examples
|
|
|
660
660
|
Note the `DOTENV_PRIVATE_KEY_CI` (and any `DOTENV_PRIVATE_KEY*`) can take multiple private keys by simply comma separating them.
|
|
661
661
|
|
|
662
662
|
</details>
|
|
663
|
+
* <details><summary>`--stdout`</summary><br>
|
|
664
|
+
|
|
665
|
+
```sh
|
|
666
|
+
$ echo "HELLO=World" > .env
|
|
667
|
+
$ dotenvx encrypt --stdout
|
|
668
|
+
$ dotenvx encrypt --stdout > .env.encrypted
|
|
669
|
+
```
|
|
670
|
+
|
|
671
|
+
</details>
|
|
672
|
+
|
|
663
673
|
* <details><summary>other curves</summary><br>
|
|
664
674
|
|
|
665
675
|
> `secp256k1` is a well-known and battle tested curve, in use with Bitcoin and other cryptocurrencies, but we are open to adding support for more curves.
|
|
@@ -1139,6 +1149,81 @@ More examples
|
|
|
1139
1149
|
```
|
|
1140
1150
|
|
|
1141
1151
|
</details>
|
|
1152
|
+
* <details><summary>`encrypt --stdout`</summary><br>
|
|
1153
|
+
|
|
1154
|
+
Encrypt the contents of a `.env` file and send to stdout.
|
|
1155
|
+
|
|
1156
|
+
```sh
|
|
1157
|
+
$ echo "HELLO=World" > .env
|
|
1158
|
+
$ dotenvx encrypt --stdout
|
|
1159
|
+
#/-------------------[DOTENV_PUBLIC_KEY]--------------------/
|
|
1160
|
+
#/ public-key encryption for .env files /
|
|
1161
|
+
#/ [how it works](https://dotenvx.com/encryption) /
|
|
1162
|
+
#/----------------------------------------------------------/
|
|
1163
|
+
DOTENV_PUBLIC_KEY="034af93e93708b994c10f236c96ef88e47291066946cce2e8d98c9e02c741ced45"
|
|
1164
|
+
# .env
|
|
1165
|
+
HELLO="encrypted:BDqDBibm4wsYqMpCjTQ6BsDHmMadg9K3dAt+Z9HPMfLEIRVz50hmLXPXRuDBXaJi/LwWYEVUNiq0HISrslzQPaoyS8Lotg3gFWJTsNCdOWnqpjF2xNUX2RQiP05kAbEXM6MWVjDr"
|
|
1166
|
+
```
|
|
1167
|
+
|
|
1168
|
+
or send to a file:
|
|
1169
|
+
|
|
1170
|
+
```sh
|
|
1171
|
+
$ echo "HELLO=World" > .env
|
|
1172
|
+
$ dotenvx encrypt --stdout > somefile.txt
|
|
1173
|
+
```
|
|
1174
|
+
|
|
1175
|
+
</details>
|
|
1176
|
+
* <details><summary>`decrypt`</summary><br>
|
|
1177
|
+
|
|
1178
|
+
Decrypt the contents of an encrypted `.env` file to an unencrypted `.env` file.
|
|
1179
|
+
|
|
1180
|
+
```sh
|
|
1181
|
+
$ echo "HELLO=World" > .env
|
|
1182
|
+
$ dotenvx encrypt
|
|
1183
|
+
✔ encrypted (.env)
|
|
1184
|
+
$ dotenvx decrypt
|
|
1185
|
+
✔ decrypted (.env)
|
|
1186
|
+
```
|
|
1187
|
+
|
|
1188
|
+
</details>
|
|
1189
|
+
* <details><summary>`decrypt -f`</summary><br>
|
|
1190
|
+
|
|
1191
|
+
Decrypt the contents of a specified encrypted `.env` file to an unencrypted `.env` file.
|
|
1192
|
+
|
|
1193
|
+
```sh
|
|
1194
|
+
$ echo "HELLO=World" > .env
|
|
1195
|
+
$ echo "HELLO=Production" > .env.production
|
|
1196
|
+
|
|
1197
|
+
$ dotenvx encrypt -f .env.production
|
|
1198
|
+
✔ encrypted (.env.production)
|
|
1199
|
+
$ dotenvx decrypt -f .env.production
|
|
1200
|
+
✔ decrypted (.env.production)
|
|
1201
|
+
```
|
|
1202
|
+
|
|
1203
|
+
</details>
|
|
1204
|
+
* <details><summary>`decrypt --stdout`</summary><br>
|
|
1205
|
+
|
|
1206
|
+
Decrypt the contents of an encrypted `.env` file and send to stdout.
|
|
1207
|
+
|
|
1208
|
+
```sh
|
|
1209
|
+
$ dotenvx decrypt --stdout
|
|
1210
|
+
#/-------------------[DOTENV_PUBLIC_KEY]--------------------/
|
|
1211
|
+
#/ public-key encryption for .env files /
|
|
1212
|
+
#/ [how it works](https://dotenvx.com/encryption) /
|
|
1213
|
+
#/----------------------------------------------------------/
|
|
1214
|
+
DOTENV_PUBLIC_KEY="034af93e93708b994c10f236c96ef88e47291066946cce2e8d98c9e02c741ced45"
|
|
1215
|
+
# .env
|
|
1216
|
+
HELLO="World"
|
|
1217
|
+
```
|
|
1218
|
+
|
|
1219
|
+
or send to a file:
|
|
1220
|
+
|
|
1221
|
+
```sh
|
|
1222
|
+
$ dotenvx decrypt --stdout > somefile.txt
|
|
1223
|
+
```
|
|
1224
|
+
|
|
1225
|
+
</details>
|
|
1226
|
+
|
|
1142
1227
|
* <details><summary>`help`</summary><br>
|
|
1143
1228
|
|
|
1144
1229
|
Output help for `dotenvx`.
|
|
@@ -1162,8 +1247,9 @@ More examples
|
|
|
1162
1247
|
get [options] [key] return a single environment variable
|
|
1163
1248
|
set [options] <KEY> <value> set a single environment variable
|
|
1164
1249
|
encrypt [options] convert .env file(s) to encrypted .env file(s)
|
|
1250
|
+
decrypt [options] convert encrypted .env file(s) to plain .env file(s)
|
|
1165
1251
|
pro 🏆 pro
|
|
1166
|
-
ext
|
|
1252
|
+
ext [command] [args...] 🔌 extensions
|
|
1167
1253
|
help [command] display help for command
|
|
1168
1254
|
```
|
|
1169
1255
|
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
2
|
+
"version": "1.6.1",
|
|
3
3
|
"name": "@dotenvx/dotenvx",
|
|
4
4
|
"description": "a better dotenv–from the creator of `dotenv`",
|
|
5
5
|
"author": "@motdotla",
|
|
@@ -8,7 +8,10 @@
|
|
|
8
8
|
"env"
|
|
9
9
|
],
|
|
10
10
|
"homepage": "https://github.com/dotenvx/dotenvx",
|
|
11
|
-
"repository":
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/dotenvx/dotenvx.git"
|
|
14
|
+
},
|
|
12
15
|
"license": "BSD-3-Clause",
|
|
13
16
|
"files": [
|
|
14
17
|
"src/**/*",
|
|
@@ -23,7 +26,9 @@
|
|
|
23
26
|
"scripts": {
|
|
24
27
|
"standard": "standard",
|
|
25
28
|
"standard:fix": "standard --fix",
|
|
26
|
-
"test": "tap run --
|
|
29
|
+
"test": "tap run --allow-empty-coverage --disable-coverage --timeout=60000",
|
|
30
|
+
"test-coverage": "tap run --show-full-coverage --timeout=60000",
|
|
31
|
+
"test-single": "tap run --coverage-report=none tests/cli/actions/decrypt.test.js",
|
|
27
32
|
"testshell": "bash shellspec",
|
|
28
33
|
"prerelease": "npm test && npm run testshell",
|
|
29
34
|
"release": "standard-version",
|
|
@@ -31,8 +36,6 @@
|
|
|
31
36
|
},
|
|
32
37
|
"funding": "https://dotenvx.com",
|
|
33
38
|
"dependencies": {
|
|
34
|
-
"@clack/core": "^0.3.4",
|
|
35
|
-
"arch": "^2.1.1",
|
|
36
39
|
"chalk": "^4.1.2",
|
|
37
40
|
"commander": "^11.1.0",
|
|
38
41
|
"conf": "^10.2.0",
|
|
@@ -42,11 +45,8 @@
|
|
|
42
45
|
"execa": "^5.1.1",
|
|
43
46
|
"fdir": "^6.1.1",
|
|
44
47
|
"ignore": "^5.3.0",
|
|
45
|
-
"is-wsl": "^2.1.1",
|
|
46
48
|
"object-treeify": "1.1.33",
|
|
47
|
-
"open": "^8.4.2",
|
|
48
49
|
"picomatch": "^3.0.1",
|
|
49
|
-
"undici": "^5.28.3",
|
|
50
50
|
"which": "^4.0.0",
|
|
51
51
|
"winston": "^3.11.0",
|
|
52
52
|
"xxhashjs": "^0.2.2"
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"sinon": "^14.0.1",
|
|
60
60
|
"standard": "^17.1.0",
|
|
61
61
|
"standard-version": "^9.5.0",
|
|
62
|
-
"tap": "^
|
|
62
|
+
"tap": "^19.2.0"
|
|
63
63
|
},
|
|
64
64
|
"publishConfig": {
|
|
65
65
|
"access": "public",
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const { logger } = require('./../../shared/logger')
|
|
3
|
+
|
|
4
|
+
const main = require('./../../lib/main')
|
|
5
|
+
|
|
6
|
+
const ENCODING = 'utf8'
|
|
7
|
+
|
|
8
|
+
function decrypt () {
|
|
9
|
+
const options = this.opts()
|
|
10
|
+
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
11
|
+
|
|
12
|
+
// stdout - should not have a try so that exit codes can surface to stdout
|
|
13
|
+
if (options.stdout) {
|
|
14
|
+
const {
|
|
15
|
+
processedEnvFiles
|
|
16
|
+
} = main.decrypt(options.envFile, options.key)
|
|
17
|
+
|
|
18
|
+
for (const processedEnvFile of processedEnvFiles) {
|
|
19
|
+
process.stdout.write(processedEnvFile.envSrc)
|
|
20
|
+
}
|
|
21
|
+
process.exit(0) // exit early
|
|
22
|
+
} else {
|
|
23
|
+
try {
|
|
24
|
+
const {
|
|
25
|
+
processedEnvFiles,
|
|
26
|
+
changedFilepaths,
|
|
27
|
+
unchangedFilepaths
|
|
28
|
+
} = main.decrypt(options.envFile, options.key)
|
|
29
|
+
|
|
30
|
+
for (const processedEnvFile of processedEnvFiles) {
|
|
31
|
+
logger.verbose(`decrypting ${processedEnvFile.envFilepath} (${processedEnvFile.filepath})`)
|
|
32
|
+
if (processedEnvFile.error) {
|
|
33
|
+
if (processedEnvFile.error.code === 'MISSING_ENV_FILE') {
|
|
34
|
+
logger.warn(processedEnvFile.error.message)
|
|
35
|
+
logger.help(`? add one with [echo "HELLO=World" > ${processedEnvFile.envFilepath}] and re-run [dotenvx decrypt]`)
|
|
36
|
+
} else {
|
|
37
|
+
logger.warn(processedEnvFile.error.message)
|
|
38
|
+
}
|
|
39
|
+
} else if (processedEnvFile.changed) {
|
|
40
|
+
fs.writeFileSync(processedEnvFile.filepath, processedEnvFile.envSrc, ENCODING)
|
|
41
|
+
|
|
42
|
+
logger.verbose(`decrypted ${processedEnvFile.envFilepath} (${processedEnvFile.filepath})`)
|
|
43
|
+
} else {
|
|
44
|
+
logger.verbose(`no changes ${processedEnvFile.envFilepath} (${processedEnvFile.filepath})`)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (changedFilepaths.length > 0) {
|
|
49
|
+
logger.success(`✔ decrypted (${changedFilepaths.join(',')})`)
|
|
50
|
+
} else if (unchangedFilepaths.length > 0) {
|
|
51
|
+
logger.info(`no changes (${unchangedFilepaths})`)
|
|
52
|
+
} else {
|
|
53
|
+
// do nothing - scenario when no .env files found
|
|
54
|
+
}
|
|
55
|
+
} catch (error) {
|
|
56
|
+
logger.error(error.message)
|
|
57
|
+
if (error.help) {
|
|
58
|
+
logger.help(error.help)
|
|
59
|
+
}
|
|
60
|
+
if (error.debug) {
|
|
61
|
+
logger.debug(error.debug)
|
|
62
|
+
}
|
|
63
|
+
if (error.code) {
|
|
64
|
+
logger.debug(`ERROR_CODE: ${error.code}`)
|
|
65
|
+
}
|
|
66
|
+
process.exit(1)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
module.exports = decrypt
|
|
@@ -7,66 +7,78 @@ const isIgnoringDotenvKeys = require('../../lib/helpers/isIgnoringDotenvKeys')
|
|
|
7
7
|
|
|
8
8
|
const ENCODING = 'utf8'
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
function encrypt () {
|
|
11
11
|
const options = this.opts()
|
|
12
12
|
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
13
13
|
|
|
14
|
-
try
|
|
14
|
+
// stdout - should not have a try so that exit codes can surface to stdout
|
|
15
|
+
if (options.stdout) {
|
|
15
16
|
const {
|
|
16
|
-
processedEnvFiles
|
|
17
|
-
changedFilepaths,
|
|
18
|
-
unchangedFilepaths
|
|
17
|
+
processedEnvFiles
|
|
19
18
|
} = main.encrypt(options.envFile, options.key)
|
|
20
19
|
|
|
21
20
|
for (const processedEnvFile of processedEnvFiles) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
process.stdout.write(processedEnvFile.envSrc)
|
|
22
|
+
}
|
|
23
|
+
process.exit(0) // exit early
|
|
24
|
+
} else {
|
|
25
|
+
try {
|
|
26
|
+
const {
|
|
27
|
+
processedEnvFiles,
|
|
28
|
+
changedFilepaths,
|
|
29
|
+
unchangedFilepaths
|
|
30
|
+
} = main.encrypt(options.envFile, options.key)
|
|
31
|
+
|
|
32
|
+
for (const processedEnvFile of processedEnvFiles) {
|
|
33
|
+
logger.verbose(`encrypting ${processedEnvFile.envFilepath} (${processedEnvFile.filepath})`)
|
|
34
|
+
if (processedEnvFile.error) {
|
|
35
|
+
if (processedEnvFile.error.code === 'MISSING_ENV_FILE') {
|
|
36
|
+
logger.warn(processedEnvFile.error.message)
|
|
37
|
+
logger.help(`? add one with [echo "HELLO=World" > ${processedEnvFile.envFilepath}] and re-run [dotenvx encrypt]`)
|
|
38
|
+
} else {
|
|
39
|
+
logger.warn(processedEnvFile.error.message)
|
|
40
|
+
}
|
|
41
|
+
} else if (processedEnvFile.changed) {
|
|
42
|
+
fs.writeFileSync(processedEnvFile.filepath, processedEnvFile.envSrc, ENCODING)
|
|
43
|
+
|
|
44
|
+
logger.verbose(`encrypted ${processedEnvFile.envFilepath} (${processedEnvFile.filepath})`)
|
|
27
45
|
} else {
|
|
28
|
-
logger.
|
|
46
|
+
logger.verbose(`no changes ${processedEnvFile.envFilepath} (${processedEnvFile.filepath})`)
|
|
29
47
|
}
|
|
30
|
-
}
|
|
31
|
-
fs.writeFileSync(processedEnvFile.filepath, processedEnvFile.envSrc, ENCODING)
|
|
48
|
+
}
|
|
32
49
|
|
|
33
|
-
|
|
50
|
+
if (changedFilepaths.length > 0) {
|
|
51
|
+
logger.success(`✔ encrypted (${changedFilepaths.join(',')})`)
|
|
52
|
+
} else if (unchangedFilepaths.length > 0) {
|
|
53
|
+
logger.info(`no changes (${unchangedFilepaths})`)
|
|
34
54
|
} else {
|
|
35
|
-
|
|
55
|
+
// do nothing - scenario when no .env files found
|
|
36
56
|
}
|
|
37
|
-
}
|
|
38
57
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
logger.info(`no changes (${unchangedFilepaths})`)
|
|
43
|
-
} else {
|
|
44
|
-
// do nothing - scenario when no .env files found
|
|
45
|
-
}
|
|
58
|
+
for (const processedEnvFile of processedEnvFiles) {
|
|
59
|
+
if (processedEnvFile.privateKeyAdded) {
|
|
60
|
+
logger.success(`✔ key added to .env.keys (${processedEnvFile.privateKeyName})`)
|
|
46
61
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
62
|
+
if (!isIgnoringDotenvKeys()) {
|
|
63
|
+
logger.help2('ℹ add .env.keys to .gitignore: [echo ".env.keys" >> .gitignore]')
|
|
64
|
+
}
|
|
50
65
|
|
|
51
|
-
|
|
52
|
-
logger.help2('ℹ add .env.keys to .gitignore: [echo ".env.keys" >> .gitignore]')
|
|
66
|
+
logger.help2(`ℹ run [${processedEnvFile.privateKeyName}='${processedEnvFile.privateKey}' dotenvx run -- yourcommand] to test decryption locally`)
|
|
53
67
|
}
|
|
54
|
-
|
|
55
|
-
logger.help2(`ℹ run [${processedEnvFile.privateKeyName}='${processedEnvFile.privateKey}' dotenvx run -- yourcommand] to test decryption locally`)
|
|
56
68
|
}
|
|
69
|
+
} catch (error) {
|
|
70
|
+
logger.error(error.message)
|
|
71
|
+
if (error.help) {
|
|
72
|
+
logger.help(error.help)
|
|
73
|
+
}
|
|
74
|
+
if (error.debug) {
|
|
75
|
+
logger.debug(error.debug)
|
|
76
|
+
}
|
|
77
|
+
if (error.code) {
|
|
78
|
+
logger.debug(`ERROR_CODE: ${error.code}`)
|
|
79
|
+
}
|
|
80
|
+
process.exit(1)
|
|
57
81
|
}
|
|
58
|
-
} catch (error) {
|
|
59
|
-
logger.error(error.message)
|
|
60
|
-
if (error.help) {
|
|
61
|
-
logger.help(error.help)
|
|
62
|
-
}
|
|
63
|
-
if (error.debug) {
|
|
64
|
-
logger.debug(error.debug)
|
|
65
|
-
}
|
|
66
|
-
if (error.code) {
|
|
67
|
-
logger.debug(`ERROR_CODE: ${error.code}`)
|
|
68
|
-
}
|
|
69
|
-
process.exit(1)
|
|
70
82
|
}
|
|
71
83
|
}
|
|
72
84
|
|
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
const fs = require('fs')
|
|
2
2
|
const main = require('./../../../lib/main')
|
|
3
3
|
const { logger } = require('./../../../shared/logger')
|
|
4
|
-
const { createSpinner } = require('./../../../shared/createSpinner')
|
|
5
|
-
|
|
6
|
-
const sleep = require('./../../../lib/helpers/sleep')
|
|
7
|
-
|
|
8
|
-
const spinner = createSpinner('generating')
|
|
9
4
|
|
|
10
5
|
const ENCODING = 'utf8'
|
|
11
6
|
|
|
12
|
-
|
|
13
|
-
spinner.start()
|
|
14
|
-
await sleep(500) // better dx
|
|
15
|
-
|
|
7
|
+
function genexample (directory) {
|
|
16
8
|
logger.debug(`directory: ${directory}`)
|
|
17
9
|
|
|
18
10
|
const options = this.opts()
|
|
@@ -34,12 +26,12 @@ async function genexample (directory) {
|
|
|
34
26
|
fs.writeFileSync(exampleFilepath, envExampleFile, ENCODING)
|
|
35
27
|
|
|
36
28
|
if (addedKeys.length > 0) {
|
|
37
|
-
|
|
29
|
+
logger.success(`updated .env.example (${addedKeys.length})`)
|
|
38
30
|
} else {
|
|
39
|
-
|
|
31
|
+
logger.blank('no changes (.env.example)')
|
|
40
32
|
}
|
|
41
33
|
} catch (error) {
|
|
42
|
-
|
|
34
|
+
logger.error(error.message)
|
|
43
35
|
if (error.help) {
|
|
44
36
|
logger.help(error.help)
|
|
45
37
|
}
|
|
@@ -1,25 +1,28 @@
|
|
|
1
|
-
const
|
|
1
|
+
const childProcess = require('child_process')
|
|
2
2
|
|
|
3
3
|
const { logger } = require('./../../../shared/logger')
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
function scan () {
|
|
6
6
|
const options = this.opts()
|
|
7
7
|
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
8
8
|
|
|
9
9
|
try {
|
|
10
|
-
|
|
10
|
+
// redirect stderr to stdout to capture and ignore it
|
|
11
|
+
childProcess.execSync('gitleaks version', { stdio: ['ignore', 'pipe', 'ignore'] })
|
|
11
12
|
} catch (error) {
|
|
12
|
-
logger.error('gitleaks command not found')
|
|
13
|
+
logger.error('gitleaks: command not found')
|
|
13
14
|
logger.help('? install gitleaks: [brew install gitleaks]')
|
|
14
15
|
logger.help2('? other install options: [https://github.com/gitleaks/gitleaks]')
|
|
15
16
|
process.exit(1)
|
|
17
|
+
return
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
try {
|
|
19
|
-
const
|
|
20
|
-
logger.blank(
|
|
21
|
+
const output = childProcess.execSync('gitleaks detect -v 2>&1', { stdio: 'pipe' }).toString() // gitleaks sends output as stderr for strange reason
|
|
22
|
+
logger.blank(output)
|
|
21
23
|
} catch (error) {
|
|
22
24
|
logger.error(error.message)
|
|
25
|
+
|
|
23
26
|
process.exit(1)
|
|
24
27
|
}
|
|
25
28
|
}
|
|
@@ -11,13 +11,14 @@ function settings (key = null) {
|
|
|
11
11
|
const value = main.settings(key)
|
|
12
12
|
|
|
13
13
|
if (typeof value === 'object' && value !== null) {
|
|
14
|
+
let space = 0
|
|
14
15
|
if (options.prettyPrint) {
|
|
15
|
-
|
|
16
|
-
} else {
|
|
17
|
-
logger.blank(value)
|
|
16
|
+
space = 2
|
|
18
17
|
}
|
|
18
|
+
|
|
19
|
+
process.stdout.write(JSON.stringify(value, null, space))
|
|
19
20
|
} else {
|
|
20
|
-
|
|
21
|
+
process.stdout.write(value)
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
24
|
|
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
const fs = require('fs')
|
|
2
2
|
|
|
3
3
|
const { logger } = require('./../../../../shared/logger')
|
|
4
|
-
const { createSpinner } = require('./../../../../shared/createSpinner')
|
|
5
|
-
const sleep = require('./../../../../lib/helpers/sleep')
|
|
6
4
|
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
const spinner = createSpinner('decrypting')
|
|
10
|
-
|
|
11
|
-
async function decrypt (directory) {
|
|
12
|
-
spinner.start()
|
|
13
|
-
await sleep(500) // better dx
|
|
5
|
+
const VaultDecrypt = require('./../../../../lib/services/vaultDecrypt')
|
|
14
6
|
|
|
7
|
+
function decrypt (directory) {
|
|
15
8
|
logger.debug(`directory: ${directory}`)
|
|
16
9
|
|
|
17
10
|
const options = this.opts()
|
|
@@ -22,7 +15,7 @@ async function decrypt (directory) {
|
|
|
22
15
|
processedEnvs,
|
|
23
16
|
changedFilenames,
|
|
24
17
|
unchangedFilenames
|
|
25
|
-
} = new
|
|
18
|
+
} = new VaultDecrypt(directory, options.environment).run()
|
|
26
19
|
|
|
27
20
|
for (const env of processedEnvs) {
|
|
28
21
|
if (env.warning) {
|
|
@@ -49,12 +42,12 @@ async function decrypt (directory) {
|
|
|
49
42
|
}
|
|
50
43
|
|
|
51
44
|
if (changedMsg.length > 0) {
|
|
52
|
-
|
|
45
|
+
logger.success(`${changedMsg} ${unchangedMsg}`)
|
|
53
46
|
} else {
|
|
54
|
-
|
|
47
|
+
logger.blank(`${unchangedMsg}`)
|
|
55
48
|
}
|
|
56
49
|
} catch (error) {
|
|
57
|
-
|
|
50
|
+
logger.error(error.message)
|
|
58
51
|
if (error.help) {
|
|
59
52
|
logger.help(error.help)
|
|
60
53
|
}
|
|
@@ -3,16 +3,9 @@ const path = require('path')
|
|
|
3
3
|
|
|
4
4
|
const main = require('./../../../../lib/main')
|
|
5
5
|
const { logger } = require('./../../../../shared/logger')
|
|
6
|
-
const { createSpinner } = require('./../../../../shared/createSpinner')
|
|
7
|
-
const sleep = require('./../../../../lib/helpers/sleep')
|
|
8
6
|
const pluralize = require('./../../../../lib/helpers/pluralize')
|
|
9
7
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
async function encrypt (directory) {
|
|
13
|
-
spinner.start()
|
|
14
|
-
await sleep(500) // better dx
|
|
15
|
-
|
|
8
|
+
function encrypt (directory) {
|
|
16
9
|
logger.debug(`directory: ${directory}`)
|
|
17
10
|
|
|
18
11
|
const options = this.opts()
|
|
@@ -50,14 +43,14 @@ async function encrypt (directory) {
|
|
|
50
43
|
fs.writeFileSync(path.resolve(directory, '.env.vault'), dotenvVaultFile)
|
|
51
44
|
|
|
52
45
|
if (addedDotenvFilenames.length > 0) {
|
|
53
|
-
|
|
46
|
+
logger.success(`encrypted to .env.vault (${addedDotenvFilenames})`)
|
|
54
47
|
logger.help2('ℹ commit .env.vault to code: [git commit -am ".env.vault"]')
|
|
55
48
|
} else {
|
|
56
|
-
|
|
49
|
+
logger.blank(`no changes (${envFile})`)
|
|
57
50
|
}
|
|
58
51
|
|
|
59
52
|
if (addedKeys.length > 0) {
|
|
60
|
-
|
|
53
|
+
logger.success(`${pluralize('key', addedKeys.length)} added to .env.keys (${addedKeys})`)
|
|
61
54
|
}
|
|
62
55
|
|
|
63
56
|
if (addedVaults.length > 0) {
|
|
@@ -68,7 +61,7 @@ async function encrypt (directory) {
|
|
|
68
61
|
logger.help2(`ℹ run [DOTENV_KEY='${tryKey}' dotenvx run -- yourcommand] to test decryption locally`)
|
|
69
62
|
}
|
|
70
63
|
} catch (error) {
|
|
71
|
-
|
|
64
|
+
logger.error(error.message)
|
|
72
65
|
if (error.help) {
|
|
73
66
|
logger.help(error.help)
|
|
74
67
|
}
|