@dotenvx/dotenvx 1.2.0 → 1.3.0
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 +7 -1
- package/README.md +12 -0
- package/package.json +1 -1
- package/src/cli/actions/encrypt.js +1 -1
- package/src/cli/dotenvx.js +1 -0
- package/src/lib/main.d.ts +3 -1
- package/src/lib/main.js +2 -2
- package/src/lib/services/encrypt.js +20 -8
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,13 @@
|
|
|
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.3.0...main)
|
|
6
|
+
|
|
7
|
+
## 1.3.0
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
* encrypt specified keys with `--key` option - `dotenvx encrypt -k HELLO` ([#281](https://github.com/dotenvx/dotenvx/pull/281))
|
|
6
12
|
|
|
7
13
|
## 1.2.0
|
|
8
14
|
|
package/README.md
CHANGED
|
@@ -1114,6 +1114,18 @@ More examples
|
|
|
1114
1114
|
ℹ run [DOTENV_PRIVATE_KEY_PRODUCTION='bff..bc4' dotenvx run -- yourcommand] to test decryption locally
|
|
1115
1115
|
```
|
|
1116
1116
|
|
|
1117
|
+
</details>
|
|
1118
|
+
* <details><summary>`encrypt -k`</summary><br>
|
|
1119
|
+
|
|
1120
|
+
Specify the key(s) to encrypt by passing `--key`.
|
|
1121
|
+
|
|
1122
|
+
```sh
|
|
1123
|
+
$ echo "HELLO=World\nHELLO2=Universe" > .env
|
|
1124
|
+
|
|
1125
|
+
$ dotenvx encrypt -k HELLO2
|
|
1126
|
+
✔ encrypted (.env)
|
|
1127
|
+
```
|
|
1128
|
+
|
|
1117
1129
|
</details>
|
|
1118
1130
|
* <details><summary>`help`</summary><br>
|
|
1119
1131
|
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@ async function encrypt () {
|
|
|
16
16
|
processedEnvFiles,
|
|
17
17
|
changedFilepaths,
|
|
18
18
|
unchangedFilepaths
|
|
19
|
-
} = main.encrypt(options.envFile)
|
|
19
|
+
} = main.encrypt(options.envFile, options.key)
|
|
20
20
|
|
|
21
21
|
for (const processedEnvFile of processedEnvFiles) {
|
|
22
22
|
logger.verbose(`encrypting ${processedEnvFile.envFilepath} (${processedEnvFile.filepath})`)
|
package/src/cli/dotenvx.js
CHANGED
|
@@ -94,6 +94,7 @@ const encryptAction = require('./actions/encrypt')
|
|
|
94
94
|
program.command('encrypt')
|
|
95
95
|
.description('convert .env file(s) to encrypted .env file(s)')
|
|
96
96
|
.option('-f, --env-file <paths...>', 'path(s) to your env file(s)')
|
|
97
|
+
.option('-k, --key <keys...>', 'keys(s) to encrypt (default: all keys in file)')
|
|
97
98
|
.action(encryptAction)
|
|
98
99
|
|
|
99
100
|
// dotenvx pro
|
package/src/lib/main.d.ts
CHANGED
|
@@ -144,8 +144,9 @@ export type EncryptOutput = {
|
|
|
144
144
|
*
|
|
145
145
|
* @see https://dotenvx.com/docs
|
|
146
146
|
* @param envFile - path to the .env file
|
|
147
|
+
* @param key - keys(s) to encrypt (default: all keys in .env file)
|
|
147
148
|
*/
|
|
148
|
-
export function encrypt(envFile: string): EncryptOutput;
|
|
149
|
+
export function encrypt(envFile: string, key: string): EncryptOutput;
|
|
149
150
|
|
|
150
151
|
export type VaultEncryptOutput = {
|
|
151
152
|
dotenvKeys: Record<string, string>;
|
|
@@ -157,6 +158,7 @@ export type VaultEncryptOutput = {
|
|
|
157
158
|
existingVaults: string[];
|
|
158
159
|
addedDotenvFilenames: string[];
|
|
159
160
|
envFile: string | string[];
|
|
161
|
+
key: string | string[];
|
|
160
162
|
};
|
|
161
163
|
|
|
162
164
|
/**
|
package/src/lib/main.js
CHANGED
|
@@ -194,8 +194,8 @@ const set = function (key, value, envFile, encrypt) {
|
|
|
194
194
|
}
|
|
195
195
|
|
|
196
196
|
/** @type {import('./main').encrypt} */
|
|
197
|
-
const encrypt = function (envFile) {
|
|
198
|
-
return new Encrypt(envFile).run()
|
|
197
|
+
const encrypt = function (envFile, key) {
|
|
198
|
+
return new Encrypt(envFile, key).run()
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
/** @type {import('./main').status} */
|
|
@@ -11,8 +11,9 @@ const replace = require('./../helpers/replace')
|
|
|
11
11
|
const ENCODING = 'utf8'
|
|
12
12
|
|
|
13
13
|
class Encrypt {
|
|
14
|
-
constructor (envFile = '.env') {
|
|
14
|
+
constructor (envFile = '.env', key = []) {
|
|
15
15
|
this.envFile = envFile
|
|
16
|
+
this.key = key
|
|
16
17
|
this.processedEnvFiles = []
|
|
17
18
|
this.changedFilepaths = new Set()
|
|
18
19
|
this.unchangedFilepaths = new Set()
|
|
@@ -20,6 +21,7 @@ class Encrypt {
|
|
|
20
21
|
|
|
21
22
|
run () {
|
|
22
23
|
const envFilepaths = this._envFilepaths()
|
|
24
|
+
const keys = this._keys()
|
|
23
25
|
for (const envFilepath of envFilepaths) {
|
|
24
26
|
const filepath = path.resolve(envFilepath)
|
|
25
27
|
|
|
@@ -52,15 +54,17 @@ class Encrypt {
|
|
|
52
54
|
// iterate over all non-encrypted values and encrypt them
|
|
53
55
|
const parsed = dotenv.parse(src)
|
|
54
56
|
for (const [key, value] of Object.entries(parsed)) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
if (keys.length < 1 || keys.includes(key)) { // optionally control which key to encrypt
|
|
58
|
+
const encrypted = isEncrypted(key, value)
|
|
59
|
+
if (!encrypted) {
|
|
60
|
+
row.keys.push(key) // track key(s)
|
|
58
61
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
+
const encryptedValue = encryptValue(value, publicKey)
|
|
63
|
+
// once newSrc is built write it out
|
|
64
|
+
src = replace(src, key, encryptedValue)
|
|
62
65
|
|
|
63
|
-
|
|
66
|
+
row.changed = true // track change
|
|
67
|
+
}
|
|
64
68
|
}
|
|
65
69
|
}
|
|
66
70
|
|
|
@@ -99,6 +103,14 @@ class Encrypt {
|
|
|
99
103
|
|
|
100
104
|
return this.envFile
|
|
101
105
|
}
|
|
106
|
+
|
|
107
|
+
_keys () {
|
|
108
|
+
if (!Array.isArray(this.key)) {
|
|
109
|
+
return [this.key]
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return this.key
|
|
113
|
+
}
|
|
102
114
|
}
|
|
103
115
|
|
|
104
116
|
module.exports = Encrypt
|