@dotenvx/dotenvx 2.32.4 → 2.34.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 +22 -1
- package/README.md +24 -26
- package/package.json +5 -13
- package/src/cli/actions/check.js +6 -11
- package/src/cli/actions/encrypt.js +2 -2
- package/src/cli/actions/get.js +4 -5
- package/src/cli/actions/init.js +4 -4
- package/src/cli/actions/keypair.js +1 -0
- package/src/cli/actions/policy.js +14 -0
- package/src/cli/actions/primitivesCheck.js +32 -0
- package/src/cli/actions/primitivesProfile.js +15 -0
- package/src/cli/actions/primitivesRedact.js +19 -0
- package/src/cli/actions/protectStdin.js +2 -2
- package/src/cli/actions/run.js +8 -46
- package/src/cli/actions/set.js +1 -1
- package/src/cli/commands/primitives.js +28 -1
- package/src/cli/dotenvx.js +6 -6
- package/src/db/session.js +1 -1
- package/src/lib/custodians/index.js +12 -10
- package/src/lib/custodians/local/bitwarden.js +5 -15
- package/src/lib/custodians/local/native/backend.js +4 -10
- package/src/lib/custodians/local/native/index.js +1 -1
- package/src/lib/custodians/local/onepassword.js +7 -29
- package/src/lib/custodians/managed/armor/index.js +0 -10
- package/src/lib/custodians/resolveLocalKey.js +3 -4
- package/src/lib/decryptors/armor/index.js +6 -7
- package/src/lib/{envspec → envfile}/discovery/discoverEnvFiles.js +1 -1
- package/src/lib/{envspec → envfile}/discovery/scanSource.js +1 -1
- package/src/lib/{envspec/parsing/formatEnvspecSyntaxError.js → envfile/parsing/formatEnvfileSyntaxError.js} +1 -1
- package/src/lib/envfile/parsing/readEnvfile.js +43 -0
- package/src/lib/envfile/parsing/resolveEnvfilePath.js +5 -0
- package/src/lib/{envspec/rendering/normalizeEnvspec.js → envfile/rendering/normalizeEnvfile.js} +1 -1
- package/src/lib/{envspec/rendering/previewEnvspec.js → envfile/rendering/previewEnvfile.js} +7 -15
- package/src/lib/{envspec/rendering/renderEnvspec.js → envfile/rendering/renderEnvfile.js} +3 -3
- package/src/lib/{envspec/validation/protectEnvspec.js → envfile/validation/protectEnvfile.js} +7 -7
- package/src/lib/envfile/validation/validateEnvfile.js +14 -0
- package/src/lib/helpers/errors.js +3 -25
- package/src/lib/helpers/executeCommand.js +1 -2
- package/src/lib/helpers/matchesStoredKey.js +1 -12
- package/src/lib/helpers/parseWithDecryptor.js +27 -12
- package/src/lib/helpers/redactOutput.js +30 -32
- package/src/lib/helpers/redactProcessOutput.js +58 -0
- package/src/lib/helpers/redactedValues.js +2 -2
- package/src/lib/helpers/selectEnvfileEnvs.js +29 -0
- package/src/lib/helpers/selectKeyStorage.js +1 -1
- package/src/lib/helpers/storeKeyStorage.js +0 -1
- package/src/lib/main.d.ts +12 -6
- package/src/lib/main.js +16 -29
- package/src/lib/providers/index.js +53 -53
- package/src/lib/resolvers/envs.js +7 -26
- package/src/lib/resolvers/get.js +2 -3
- package/src/lib/resolvers/keypair.js +39 -4
- package/src/lib/services/init.js +4 -4
- package/src/lib/services/validate.js +20 -32
- package/src/lib/transforms/encrypt.js +5 -5
- package/src/lib/transforms/set.js +5 -3
- package/src/cli/actions/lock/down.js +0 -54
- package/src/cli/actions/lock/up.js +0 -62
- package/src/cli/commands/lock.js +0 -36
- package/src/lib/api/postArmorDecrypt.js +0 -49
- package/src/lib/api/postArmorKeyring.js +0 -50
- package/src/lib/custodians/lock.js +0 -80
- package/src/lib/custodians/managed/armor/get.js +0 -44
- package/src/lib/envspec/parsing/envspec.peggy +0 -105
- package/src/lib/envspec/parsing/envspecParser.js +0 -2851
- package/src/lib/envspec/parsing/readEnvspec.js +0 -144
- package/src/lib/envspec/parsing/resolveEnvspecPath.js +0 -11
- package/src/lib/envspec/validation/encryptedSources.js +0 -15
- package/src/lib/envspec/validation/validate.js +0 -109
- package/src/lib/envspec/validation/validateEnvspec.js +0 -57
- package/src/lib/helpers/isValidEmail.js +0 -11
- package/src/lib/helpers/isValidUrl.js +0 -9
- package/src/lib/helpers/lockedValue.js +0 -24
- package/src/lib/helpers/resolveLockPassword.js +0 -5
- package/src/lib/helpers/unlockedValue.js +0 -26
- package/src/lib/helpers/withLockedKeys.js +0 -41
- package/src/lib/providers/provider-worker.js +0 -6
- package/src/lib/proxy/configureProxy.js +0 -55
- package/src/lib/proxy/eligibleHeaders.js +0 -16
- package/src/lib/proxy/prepareProxy.js +0 -24
- package/src/lib/proxy/proxyCertificates.js +0 -44
- package/src/lib/proxy/proxyForward.js +0 -65
- package/src/lib/proxy/proxyPreload.js +0 -21
- package/src/lib/proxy/proxyPreloadSource.js +0 -3
- package/src/lib/proxy/proxyServer.js +0 -175
- package/src/lib/services/armorKeyring.js +0 -119
- package/src/lib/services/lockDown.js +0 -157
- package/src/lib/services/lockUp.js +0 -150
- /package/src/lib/{envspec → envfile}/discovery/extractEnvKeys.js +0 -0
- /package/src/lib/{envspec → envfile}/validation/diagnosticLocation.js +0 -0
|
@@ -54,13 +54,10 @@ function inject (processEnv, parsed) {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
function buildParseOptions ({
|
|
57
|
+
function buildParseOptions ({ processEnv, overload, envKeysFilepath, provider, decryptor }) {
|
|
58
58
|
const options = {
|
|
59
|
-
lockPassword,
|
|
60
59
|
processEnv,
|
|
61
60
|
overload,
|
|
62
|
-
proxyCredentials,
|
|
63
|
-
proxyRules,
|
|
64
61
|
fk: envKeysFilepath
|
|
65
62
|
}
|
|
66
63
|
|
|
@@ -77,7 +74,7 @@ function buildParseOptions ({ lockPassword, processEnv, overload, envKeysFilepat
|
|
|
77
74
|
return options
|
|
78
75
|
}
|
|
79
76
|
|
|
80
|
-
async function injectEnv ({ env,
|
|
77
|
+
async function injectEnv ({ env, overload, processEnv, envKeysFilepath, provider, decryptor, no1Password, noBitwarden, onStatus }) {
|
|
81
78
|
const row = {}
|
|
82
79
|
row.type = TYPE_ENV
|
|
83
80
|
row.string = env.value
|
|
@@ -91,12 +88,9 @@ async function injectEnv ({ env, lockPassword, overload, processEnv, envKeysFile
|
|
|
91
88
|
const parseOptions = buildParseOptions({
|
|
92
89
|
processEnv: parseProcessEnv,
|
|
93
90
|
overload,
|
|
94
|
-
lockPassword,
|
|
95
91
|
envKeysFilepath,
|
|
96
92
|
provider,
|
|
97
|
-
decryptor
|
|
98
|
-
proxyCredentials,
|
|
99
|
-
proxyRules
|
|
93
|
+
decryptor
|
|
100
94
|
})
|
|
101
95
|
|
|
102
96
|
const {
|
|
@@ -133,7 +127,7 @@ async function injectEnv ({ env, lockPassword, overload, processEnv, envKeysFile
|
|
|
133
127
|
return row
|
|
134
128
|
}
|
|
135
129
|
|
|
136
|
-
function injectEnvSync ({ env,
|
|
130
|
+
function injectEnvSync ({ env, overload, processEnv, envKeysFilepath, provider, decryptor, no1Password, noBitwarden }) {
|
|
137
131
|
const row = {}
|
|
138
132
|
row.type = TYPE_ENV
|
|
139
133
|
row.string = env.value
|
|
@@ -147,7 +141,6 @@ function injectEnvSync ({ env, lockPassword, overload, processEnv, envKeysFilepa
|
|
|
147
141
|
const parseOptions = buildParseOptions({
|
|
148
142
|
processEnv: parseProcessEnv,
|
|
149
143
|
overload,
|
|
150
|
-
lockPassword,
|
|
151
144
|
envKeysFilepath,
|
|
152
145
|
provider,
|
|
153
146
|
decryptor
|
|
@@ -186,7 +179,7 @@ function injectEnvSync ({ env, lockPassword, overload, processEnv, envKeysFilepa
|
|
|
186
179
|
return row
|
|
187
180
|
}
|
|
188
181
|
|
|
189
|
-
async function injectEnvFile ({ env,
|
|
182
|
+
async function injectEnvFile ({ env, overload, processEnv, envKeysFilepath, provider, decryptor, readableFilepaths, no1Password, noBitwarden, onStatus }) {
|
|
190
183
|
const row = {}
|
|
191
184
|
row.type = TYPE_ENV_FILE
|
|
192
185
|
row.filepath = env.value
|
|
@@ -202,12 +195,9 @@ async function injectEnvFile ({ env, lockPassword, overload, processEnv, envKeys
|
|
|
202
195
|
const parseOptions = buildParseOptions({
|
|
203
196
|
processEnv,
|
|
204
197
|
overload,
|
|
205
|
-
lockPassword,
|
|
206
198
|
envKeysFilepath: fk,
|
|
207
199
|
provider,
|
|
208
|
-
decryptor
|
|
209
|
-
proxyCredentials,
|
|
210
|
-
proxyRules
|
|
200
|
+
decryptor
|
|
211
201
|
})
|
|
212
202
|
|
|
213
203
|
const {
|
|
@@ -249,7 +239,7 @@ async function injectEnvFile ({ env, lockPassword, overload, processEnv, envKeys
|
|
|
249
239
|
return row
|
|
250
240
|
}
|
|
251
241
|
|
|
252
|
-
function injectEnvFileSync ({ env,
|
|
242
|
+
function injectEnvFileSync ({ env, overload, processEnv, envKeysFilepath, provider, decryptor, readableFilepaths, no1Password, noBitwarden }) {
|
|
253
243
|
const row = {}
|
|
254
244
|
row.type = TYPE_ENV_FILE
|
|
255
245
|
row.filepath = env.value
|
|
@@ -265,7 +255,6 @@ function injectEnvFileSync ({ env, lockPassword, overload, processEnv, envKeysFi
|
|
|
265
255
|
const parseOptions = buildParseOptions({
|
|
266
256
|
processEnv,
|
|
267
257
|
overload,
|
|
268
|
-
lockPassword,
|
|
269
258
|
envKeysFilepath: fk,
|
|
270
259
|
provider,
|
|
271
260
|
decryptor
|
|
@@ -323,7 +312,6 @@ async function envs (options = {}) {
|
|
|
323
312
|
processedEnvs.push(await injectEnvFile({
|
|
324
313
|
env,
|
|
325
314
|
overload: options.overload,
|
|
326
|
-
lockPassword: options.lockPassword,
|
|
327
315
|
processEnv,
|
|
328
316
|
envKeysFilepath,
|
|
329
317
|
provider,
|
|
@@ -331,23 +319,18 @@ async function envs (options = {}) {
|
|
|
331
319
|
readableFilepaths,
|
|
332
320
|
no1Password,
|
|
333
321
|
noBitwarden,
|
|
334
|
-
proxyCredentials: options.proxyCredentials,
|
|
335
|
-
proxyRules: options.proxyRules,
|
|
336
322
|
onStatus: options.onStatus
|
|
337
323
|
}))
|
|
338
324
|
} else if (env.type === TYPE_ENV) {
|
|
339
325
|
processedEnvs.push(await injectEnv({
|
|
340
326
|
env,
|
|
341
327
|
overload: options.overload,
|
|
342
|
-
lockPassword: options.lockPassword,
|
|
343
328
|
processEnv,
|
|
344
329
|
envKeysFilepath,
|
|
345
330
|
provider,
|
|
346
331
|
decryptor,
|
|
347
332
|
no1Password,
|
|
348
333
|
noBitwarden,
|
|
349
|
-
proxyCredentials: options.proxyCredentials,
|
|
350
|
-
proxyRules: options.proxyRules,
|
|
351
334
|
onStatus: options.onStatus
|
|
352
335
|
}))
|
|
353
336
|
}
|
|
@@ -374,7 +357,6 @@ function envsSync (options = {}) {
|
|
|
374
357
|
processedEnvs.push(injectEnvFileSync({
|
|
375
358
|
env,
|
|
376
359
|
overload: options.overload,
|
|
377
|
-
lockPassword: options.lockPassword,
|
|
378
360
|
processEnv,
|
|
379
361
|
envKeysFilepath,
|
|
380
362
|
provider,
|
|
@@ -387,7 +369,6 @@ function envsSync (options = {}) {
|
|
|
387
369
|
processedEnvs.push(injectEnvSync({
|
|
388
370
|
env,
|
|
389
371
|
overload: options.overload,
|
|
390
|
-
lockPassword: options.lockPassword,
|
|
391
372
|
processEnv,
|
|
392
373
|
envKeysFilepath,
|
|
393
374
|
provider,
|
package/src/lib/resolvers/get.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const envsResolver = require('./envs')
|
|
2
2
|
const Errors = require('./../helpers/errors')
|
|
3
|
-
const
|
|
3
|
+
const selectEnvfileEnvs = require('../helpers/selectEnvfileEnvs')
|
|
4
4
|
|
|
5
5
|
function collectErrors (processedEnvs) {
|
|
6
6
|
const errors = []
|
|
@@ -45,7 +45,7 @@ function result ({ key, all, processedEnvs, processEnv }) {
|
|
|
45
45
|
|
|
46
46
|
function buildOptions (options, processEnv) {
|
|
47
47
|
return {
|
|
48
|
-
envs:
|
|
48
|
+
envs: selectEnvfileEnvs(options.envs, options, processEnv),
|
|
49
49
|
overload: options.overload,
|
|
50
50
|
processEnv,
|
|
51
51
|
envKeysFilepath: options.envKeysFilepath || options.envKeysFile || null,
|
|
@@ -53,7 +53,6 @@ function buildOptions (options, processEnv) {
|
|
|
53
53
|
noNative: options.noNative,
|
|
54
54
|
no1Password: options.no1Password,
|
|
55
55
|
noBitwarden: options.noBitwarden,
|
|
56
|
-
lockPassword: options.lockPassword,
|
|
57
56
|
onStatus: options.onStatus
|
|
58
57
|
}
|
|
59
58
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const { file } = require('@dotenvx/providers')
|
|
1
2
|
const fsx = require('./../helpers/fsx')
|
|
2
3
|
const path = require('path')
|
|
3
4
|
const keynames = require('./../conventions/keynames')
|
|
@@ -30,6 +31,7 @@ function outputKeypair ({ out, filepath, publicKey, ring }) {
|
|
|
30
31
|
|
|
31
32
|
async function keypair (options = {}) {
|
|
32
33
|
const out = {}
|
|
34
|
+
const origins = {}
|
|
33
35
|
const processEnv = options.processEnv || process.env
|
|
34
36
|
|
|
35
37
|
for (const filepath of filepaths(options.envFile)) {
|
|
@@ -42,19 +44,36 @@ async function keypair (options = {}) {
|
|
|
42
44
|
fk: options.envKeysFilepath || options.envKeysFile || path.resolve(path.dirname(filepath), '.env.keys')
|
|
43
45
|
})
|
|
44
46
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
let origin = 'environment'
|
|
48
|
+
const provider = await providers({ ...options, onProvider: name => { origin = name } })
|
|
49
|
+
const keys = file({ fk: keyringOptions.fk })
|
|
50
|
+
keyringOptions.provider = async publicKey => {
|
|
51
|
+
const ring = await keys.get(publicKey)
|
|
52
|
+
if (ring[publicKey]) {
|
|
53
|
+
origin = '.env.keys'
|
|
54
|
+
return ring
|
|
55
|
+
}
|
|
56
|
+
origin = 'custom'
|
|
57
|
+
return provider ? provider(publicKey) : {}
|
|
58
|
+
}
|
|
59
|
+
if (publicKey) keyringOptions.fk = []
|
|
47
60
|
|
|
48
61
|
const ring = await keyring(keyringOptions)
|
|
49
62
|
|
|
50
63
|
outputKeypair({ out, filepath, publicKey, ring })
|
|
64
|
+
origins[filepath] = publicKey && ring[publicKey] ? origin : null
|
|
51
65
|
}
|
|
52
66
|
|
|
67
|
+
if (options.includeProvider) {
|
|
68
|
+
const names = Object.keys(origins)
|
|
69
|
+
out.provider = names.length === 1 ? origins[names[0]] : origins
|
|
70
|
+
}
|
|
53
71
|
return out
|
|
54
72
|
}
|
|
55
73
|
|
|
56
74
|
function keypairSync (options = {}) {
|
|
57
75
|
const out = {}
|
|
76
|
+
const origins = {}
|
|
58
77
|
const processEnv = options.processEnv || process.env
|
|
59
78
|
|
|
60
79
|
for (const filepath of filepaths(options.envFile)) {
|
|
@@ -66,14 +85,30 @@ function keypairSync (options = {}) {
|
|
|
66
85
|
processEnv,
|
|
67
86
|
fk: options.envKeysFilepath || options.envKeysFile || path.resolve(path.dirname(filepath), '.env.keys')
|
|
68
87
|
})
|
|
69
|
-
|
|
70
|
-
|
|
88
|
+
let origin = 'environment'
|
|
89
|
+
const provider = providers.sync({ ...options, onProvider: name => { origin = name } })
|
|
90
|
+
const keys = file({ fk: keyringOptions.fk })
|
|
91
|
+
keyringOptions.provider = publicKey => {
|
|
92
|
+
const ring = keys.getSync(publicKey)
|
|
93
|
+
if (ring[publicKey]) {
|
|
94
|
+
origin = '.env.keys'
|
|
95
|
+
return ring
|
|
96
|
+
}
|
|
97
|
+
origin = 'custom'
|
|
98
|
+
return provider ? provider(publicKey) : {}
|
|
99
|
+
}
|
|
100
|
+
if (publicKey) keyringOptions.fk = []
|
|
71
101
|
|
|
72
102
|
const ring = keyringSync(keyringOptions)
|
|
73
103
|
|
|
74
104
|
outputKeypair({ out, filepath, publicKey, ring })
|
|
105
|
+
origins[filepath] = publicKey && ring[publicKey] ? origin : null
|
|
75
106
|
}
|
|
76
107
|
|
|
108
|
+
if (options.includeProvider) {
|
|
109
|
+
const names = Object.keys(origins)
|
|
110
|
+
out.provider = names.length === 1 ? origins[names[0]] : origins
|
|
111
|
+
}
|
|
77
112
|
return out
|
|
78
113
|
}
|
|
79
114
|
|
package/src/lib/services/init.js
CHANGED
|
@@ -2,8 +2,8 @@ const fs = require('node:fs')
|
|
|
2
2
|
const path = require('node:path')
|
|
3
3
|
const { scan, encrypted } = require('@dotenvx/primitives')
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const normalizeEnvfile = require('../envfile/rendering/normalizeEnvfile')
|
|
6
|
+
const renderEnvfile = require('../envfile/rendering/renderEnvfile')
|
|
7
7
|
const isPublicKey = require('../helpers/isPublicKey')
|
|
8
8
|
|
|
9
9
|
function declaration (name) {
|
|
@@ -63,8 +63,8 @@ module.exports = function init ({ directory = process.cwd(), envFile, envFiles,
|
|
|
63
63
|
const invalid = keys.filter(key => !/^[A-Za-z_][A-Za-z0-9_]*$/.test(key))
|
|
64
64
|
if (invalid.length) throw new Error(`Unsupported Envfile variable names: ${invalid.join(', ')}`)
|
|
65
65
|
|
|
66
|
-
const document =
|
|
67
|
-
const content =
|
|
66
|
+
const document = normalizeEnvfile({ files, codeDeclarations })
|
|
67
|
+
const content = renderEnvfile(document)
|
|
68
68
|
if (stdout) return { created: false, content }
|
|
69
69
|
try {
|
|
70
70
|
fs.writeFileSync(target, content, { flag: overwrite ? fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_TRUNC | fs.constants.O_NOFOLLOW : 'wx' })
|
|
@@ -1,37 +1,30 @@
|
|
|
1
1
|
const envsResolver = require('../resolvers/envs')
|
|
2
2
|
const Session = require('../../db/session')
|
|
3
|
-
const
|
|
4
|
-
const resolveEnvKeysFile = require('../helpers/resolveEnvKeysFile')
|
|
5
|
-
const readEnvspec = require('../envspec/parsing/readEnvspec')
|
|
6
|
-
const validateEnvspec = require('../envspec/validation/validateEnvspec')
|
|
3
|
+
const selectEnvfileEnvs = require('../helpers/selectEnvfileEnvs')
|
|
7
4
|
const normalizeDotenvConfigPath = require('../helpers/normalizeDotenvConfigPath')
|
|
5
|
+
const resolveEnvKeysFile = require('../helpers/resolveEnvKeysFile')
|
|
6
|
+
const readEnvfile = require('../envfile/parsing/readEnvfile')
|
|
7
|
+
const validateEnvfile = require('../envfile/validation/validateEnvfile')
|
|
8
8
|
const Errors = require('../helpers/errors')
|
|
9
|
-
const { determine } = require('../helpers/envResolution')
|
|
10
9
|
const path = require('node:path')
|
|
11
10
|
const resolveDirectoryFilepath = require('../helpers/resolveDirectoryFilepath')
|
|
12
11
|
|
|
13
12
|
// Load once and validate the final values; callers own presentation and execution.
|
|
14
|
-
module.exports = async function validate ({ envs = [], options = {}, processEnv = { ...process.env },
|
|
15
|
-
|
|
16
|
-
const requiredFilepaths = new Set(
|
|
13
|
+
module.exports = async function validate ({ envs = [], options = {}, processEnv = { ...process.env }, requireEnvfile = true, command, onStatus } = {}) {
|
|
14
|
+
const explicitEnvs = options.profile ? envs : normalizeDotenvConfigPath(envs, processEnv)
|
|
15
|
+
const requiredFilepaths = new Set(explicitEnvs.filter(env => env.type === 'envFile').flatMap(env => {
|
|
17
16
|
const resolved = resolveDirectoryFilepath(env.value, '.env')
|
|
18
17
|
// A directory with a convention selects optional layers rather than one file.
|
|
19
18
|
return options.convention && resolved !== env.value ? [] : [path.resolve(resolved)]
|
|
20
19
|
}))
|
|
21
|
-
envs =
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (requireEnvspec && !schema.exists) throw new Errors().envspecRequired()
|
|
20
|
+
envs = selectEnvfileEnvs(envs, options, processEnv)
|
|
21
|
+
const schema = readEnvfile(undefined, envs.filter(env => env.type === 'envFile').map(env => env.value))
|
|
22
|
+
if (requireEnvfile && !schema.exists) throw new Errors().envfileRequired()
|
|
25
23
|
|
|
26
24
|
const session = new Session()
|
|
27
|
-
const
|
|
28
|
-
const noArmor = options.armor === false || (!proxyToken && (await session.noArmor()))
|
|
29
|
-
if (schema.proxyRules.size > 0 && noArmor) throw new Error('Envfile proxy requires Armor. Enable Armor and authenticate before running.')
|
|
30
|
-
const proxyCredentials = noArmor ? undefined : []
|
|
25
|
+
const noArmor = options.armor === false || (!(options.token || processEnv.DOTENVX_TOKEN) && (await session.noArmor()))
|
|
31
26
|
const { processedEnvs, readableFilepaths } = await envsResolver({
|
|
32
27
|
envs,
|
|
33
|
-
proxyRules: schema.proxyRules,
|
|
34
|
-
proxyCredentials,
|
|
35
28
|
overload: options.overload,
|
|
36
29
|
processEnv,
|
|
37
30
|
envKeysFile: resolveEnvKeysFile(options.envKeysFile),
|
|
@@ -39,31 +32,26 @@ module.exports = async function validate ({ envs = [], options = {}, processEnv
|
|
|
39
32
|
noNative: options.native === false || options.noNative === true,
|
|
40
33
|
no1Password: options['1password'] === false || options.no1Password === true,
|
|
41
34
|
noBitwarden: options.bitwarden === false || options.noBitwarden === true,
|
|
42
|
-
lockPassword: options.lockPassword,
|
|
43
35
|
token: options.token,
|
|
44
36
|
command,
|
|
45
37
|
onStatus
|
|
46
38
|
})
|
|
47
39
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
40
|
+
const keys = new Set([
|
|
41
|
+
...Object.keys(schema.keys),
|
|
42
|
+
...processedEnvs.flatMap(row => Object.keys(row.parsed || {}))
|
|
43
|
+
])
|
|
44
|
+
const finalEnv = Object.fromEntries([...keys].filter(key => Object.hasOwn(processEnv, key)).map(key => [key, processEnv[key]]))
|
|
45
|
+
const result = validateEnvfile(schema, finalEnv)
|
|
55
46
|
|
|
56
47
|
return {
|
|
57
48
|
processEnv,
|
|
58
49
|
processedEnvs,
|
|
59
50
|
readableFilepaths,
|
|
60
51
|
requiredFilepaths,
|
|
61
|
-
|
|
52
|
+
hasEnvfile: schema.exists,
|
|
62
53
|
schema,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
session,
|
|
66
|
-
proxyError,
|
|
67
|
-
validationError: validateEnvspec(schema, processEnv, processedEnvs, onKey)
|
|
54
|
+
checked: result.checked,
|
|
55
|
+
validationError: validateEnvfile.error(result.errors)
|
|
68
56
|
}
|
|
69
57
|
}
|
|
@@ -6,13 +6,13 @@ const TYPE_ENV_FILE = 'envFile'
|
|
|
6
6
|
const SAMPLE_ENV_KIT = require('../helpers/kits/sample')
|
|
7
7
|
|
|
8
8
|
const Errors = require('../helpers/errors')
|
|
9
|
-
const
|
|
9
|
+
const selectEnvfileEnvs = require('../helpers/selectEnvfileEnvs')
|
|
10
10
|
const detectEncoding = require('./../helpers/detectEncoding')
|
|
11
11
|
const { isDotenvPublicKey, isPlainKey, mutateSrc } = require('../helpers/cryptography')
|
|
12
12
|
const keynames = require('../conventions/keynames')
|
|
13
13
|
|
|
14
14
|
const storeKeyStorage = require('../helpers/storeKeyStorage')
|
|
15
|
-
const
|
|
15
|
+
const readEnvfile = require('../envfile/parsing/readEnvfile')
|
|
16
16
|
|
|
17
17
|
async function encryptTransform (options = {}) {
|
|
18
18
|
const envs = options.envs || []
|
|
@@ -42,7 +42,7 @@ async function encryptTransform (options = {}) {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
for (const env of
|
|
45
|
+
for (const env of selectEnvfileEnvs(envs, options)) {
|
|
46
46
|
if (env.type !== TYPE_ENV_FILE) {
|
|
47
47
|
continue
|
|
48
48
|
}
|
|
@@ -52,7 +52,7 @@ async function encryptTransform (options = {}) {
|
|
|
52
52
|
const row = { keys: [], type: TYPE_ENV_FILE, filepath, envFilepath, changed: false }
|
|
53
53
|
|
|
54
54
|
try {
|
|
55
|
-
const schema =
|
|
55
|
+
const schema = readEnvfile(undefined, [filepath])
|
|
56
56
|
const fileExists = await fsx.exists(filepath)
|
|
57
57
|
if (!fileExists && !noCreate) {
|
|
58
58
|
row.envSrc = SAMPLE_ENV_KIT
|
|
@@ -70,7 +70,7 @@ async function encryptTransform (options = {}) {
|
|
|
70
70
|
const { parsed } = scan(row.envSrc, { ik, ek })
|
|
71
71
|
const selected = Object.entries(parsed).filter(([key]) => {
|
|
72
72
|
if (isDotenvPublicKey(key)) return false
|
|
73
|
-
return schema.exists ? (schema.
|
|
73
|
+
return schema.exists ? (schema.keys[key]?.fs.encrypted ?? true) : !isPlainKey(key)
|
|
74
74
|
})
|
|
75
75
|
if (schema.exists && !selected.some(([, values]) => values.some(value => !encrypted(value)))) {
|
|
76
76
|
// A missing file still needs writing even when its initial values are
|
|
@@ -5,7 +5,8 @@ const { encrypt, upsert, publickeys, keypair } = require('@dotenvx/primitives')
|
|
|
5
5
|
const TYPE_ENV_FILE = 'envFile'
|
|
6
6
|
|
|
7
7
|
const getResolver = require('./../resolvers/get')
|
|
8
|
-
const
|
|
8
|
+
const selectEnvfileEnvs = require('../helpers/selectEnvfileEnvs')
|
|
9
|
+
const readEnvfile = require('../envfile/parsing/readEnvfile')
|
|
9
10
|
const detectEncoding = require('./../helpers/detectEncoding')
|
|
10
11
|
const { isPlainKey, mutateSrc } = require('../helpers/cryptography')
|
|
11
12
|
const keynames = require('../conventions/keynames')
|
|
@@ -23,7 +24,6 @@ async function setTransform (options = {}) {
|
|
|
23
24
|
const custodyContext = { token: options.token }
|
|
24
25
|
const noNative = options.noNative
|
|
25
26
|
const noCreate = options.noCreate
|
|
26
|
-
const noEncrypt = !options.encrypt || isPlainKey(key)
|
|
27
27
|
|
|
28
28
|
const processedEnvs = []
|
|
29
29
|
const changedFilepaths = []
|
|
@@ -44,7 +44,7 @@ async function setTransform (options = {}) {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
for (const env of
|
|
47
|
+
for (const env of selectEnvfileEnvs(envs, options)) {
|
|
48
48
|
if (env.type !== TYPE_ENV_FILE) {
|
|
49
49
|
continue
|
|
50
50
|
}
|
|
@@ -54,6 +54,8 @@ async function setTransform (options = {}) {
|
|
|
54
54
|
const row = { key, value, type: TYPE_ENV_FILE, filepath, envFilepath, changed: false }
|
|
55
55
|
|
|
56
56
|
try {
|
|
57
|
+
const schema = readEnvfile(undefined, [filepath])
|
|
58
|
+
const noEncrypt = !options.encrypt || (schema.exists ? schema.keys[key]?.fs.encrypted === false : isPlainKey(key))
|
|
57
59
|
const fileExists = await fsx.exists(filepath)
|
|
58
60
|
if (!fileExists && !noCreate) {
|
|
59
61
|
row.envSrc = ''
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
const unlockedValue = require('../../../lib/helpers/unlockedValue')
|
|
2
|
-
|
|
3
|
-
const { logger } = require('../../../shared/logger')
|
|
4
|
-
const LockDown = require('./../../../lib/services/lockDown')
|
|
5
|
-
const armoredKeyDisplay = require('../../../lib/helpers/armoredKeyDisplay')
|
|
6
|
-
const prompts = require('../../../lib/helpers/prompts')
|
|
7
|
-
const resolveLockPassword = require('../../../lib/helpers/resolveLockPassword')
|
|
8
|
-
|
|
9
|
-
async function down () {
|
|
10
|
-
const options = this.opts()
|
|
11
|
-
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
12
|
-
|
|
13
|
-
try {
|
|
14
|
-
const lockDown = new LockDown(options.envFile, options.envKeysFile)
|
|
15
|
-
const plan = lockDown.plan()
|
|
16
|
-
let results = plan.alreadyUnlocked
|
|
17
|
-
|
|
18
|
-
if (plan.locked.length > 0) {
|
|
19
|
-
const preset = resolveLockPassword(options)
|
|
20
|
-
const passphrase = preset !== undefined
|
|
21
|
-
? preset
|
|
22
|
-
: await prompts.password({
|
|
23
|
-
message: 'passphrase',
|
|
24
|
-
prefix: '⊡',
|
|
25
|
-
separator: '='
|
|
26
|
-
}, {
|
|
27
|
-
input: process.stdin,
|
|
28
|
-
output: process.stderr
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
results = lockDown.run(lockedPrivateKey => unlockedValue(lockedPrivateKey, passphrase)).results
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
for (const result of results) {
|
|
35
|
-
const keyDisplay = armoredKeyDisplay(result.publicKeyValue) || result.privateKeyName
|
|
36
|
-
|
|
37
|
-
if (result.changed) {
|
|
38
|
-
logger.success(`⊡ unlocked (${keyDisplay})`)
|
|
39
|
-
} else {
|
|
40
|
-
logger.info(`○ no change (${keyDisplay})`)
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
} catch (error) {
|
|
44
|
-
if (error.code === 'PROMPT_CANCELLED') {
|
|
45
|
-
return { exitCode: 130, error }
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
logger.error(error.message)
|
|
49
|
-
return { exitCode: 1, error }
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
module.exports = down
|
|
54
|
-
module.exports.unlockedValue = unlockedValue
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
const lockedValue = require('../../../lib/helpers/lockedValue')
|
|
2
|
-
|
|
3
|
-
const { logger } = require('../../../shared/logger')
|
|
4
|
-
const LockUp = require('./../../../lib/services/lockUp')
|
|
5
|
-
const armoredKeyDisplay = require('../../../lib/helpers/armoredKeyDisplay')
|
|
6
|
-
const prompts = require('../../../lib/helpers/prompts')
|
|
7
|
-
const resolveLockPassword = require('../../../lib/helpers/resolveLockPassword')
|
|
8
|
-
|
|
9
|
-
async function up () {
|
|
10
|
-
const options = this.opts()
|
|
11
|
-
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
12
|
-
|
|
13
|
-
try {
|
|
14
|
-
const lockUp = new LockUp(options.envFile, options.envKeysFile)
|
|
15
|
-
|
|
16
|
-
const plan = lockUp.plan()
|
|
17
|
-
let results = plan.alreadyLocked.map(lockedPrivateKey => ({
|
|
18
|
-
changed: false,
|
|
19
|
-
privateKeyName: lockedPrivateKey.privateKeyName,
|
|
20
|
-
privateKeyValue: undefined,
|
|
21
|
-
lockedPrivateKeyValue: lockedPrivateKey.lockedPrivateKeyValue,
|
|
22
|
-
publicKeyValue: lockedPrivateKey.publicKeyValue,
|
|
23
|
-
alreadyLocked: true
|
|
24
|
-
}))
|
|
25
|
-
|
|
26
|
-
if (plan.matches.length > 0) {
|
|
27
|
-
const preset = resolveLockPassword(options)
|
|
28
|
-
const passphrase = preset !== undefined
|
|
29
|
-
? preset
|
|
30
|
-
: await prompts.password({
|
|
31
|
-
message: 'passphrase',
|
|
32
|
-
prefix: '⊡',
|
|
33
|
-
separator: '='
|
|
34
|
-
}, {
|
|
35
|
-
input: process.stdin,
|
|
36
|
-
output: process.stderr
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
results = lockUp.run((privateKey, publicKey) => lockedValue(privateKey, passphrase, publicKey)).results
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
for (const result of results) {
|
|
43
|
-
const keyDisplay = armoredKeyDisplay(result.publicKeyValue) || result.privateKeyName
|
|
44
|
-
|
|
45
|
-
if (result.changed) {
|
|
46
|
-
logger.success(`⊡ locked (${keyDisplay})`)
|
|
47
|
-
} else {
|
|
48
|
-
logger.info(`○ no change (${keyDisplay})`)
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
} catch (error) {
|
|
52
|
-
if (error.code === 'PROMPT_CANCELLED') {
|
|
53
|
-
return { exitCode: 130, error }
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
logger.error(error.message)
|
|
57
|
-
return { exitCode: 1, error }
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
module.exports = up
|
|
62
|
-
module.exports.lockedValue = lockedValue
|
package/src/cli/commands/lock.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
const commandAction = require('../commandAction')
|
|
2
|
-
function configureLockCommand (lock) {
|
|
3
|
-
lock.hook('preAction', async () => {
|
|
4
|
-
const Session = require('./../../db/session')
|
|
5
|
-
const sesh = new Session()
|
|
6
|
-
await sesh.notifyUpdate()
|
|
7
|
-
})
|
|
8
|
-
|
|
9
|
-
lock
|
|
10
|
-
.description('lock private keys with a local passphrase')
|
|
11
|
-
.action(function () {
|
|
12
|
-
this.help()
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
lock
|
|
16
|
-
.command('up')
|
|
17
|
-
.description('lock key in .env.keys')
|
|
18
|
-
.option('-f, --env-file <path>', 'path to your env file')
|
|
19
|
-
.option('-fk, --env-keys-file <path>', 'path to your .env.keys file', '.env.keys')
|
|
20
|
-
.action(function (...args) {
|
|
21
|
-
return commandAction(require('./../actions/lock/up')).apply(this, args)
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
lock
|
|
25
|
-
.command('down')
|
|
26
|
-
.description('unlock key in .env.keys')
|
|
27
|
-
.option('-f, --env-file <path>', 'path to your env file')
|
|
28
|
-
.option('-fk, --env-keys-file <path>', 'path to your .env.keys file', '.env.keys')
|
|
29
|
-
.action(function (...args) {
|
|
30
|
-
return commandAction(require('./../actions/lock/down')).apply(this, args)
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
return lock
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
module.exports = configureLockCommand
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
const { http } = require('../helpers/http')
|
|
2
|
-
const buildApiError = require('../helpers/buildApiError')
|
|
3
|
-
const packageJson = require('../helpers/packageJson')
|
|
4
|
-
const normalizeToken = require('../helpers/normalizeToken')
|
|
5
|
-
|
|
6
|
-
class PostArmorDecrypt {
|
|
7
|
-
constructor (hostname, token, devicePublicKey, publicKey, src, grantToken) {
|
|
8
|
-
this.hostname = hostname || 'https://armor.dotenvx.com'
|
|
9
|
-
this.token = token
|
|
10
|
-
this.devicePublicKey = devicePublicKey
|
|
11
|
-
this.publicKey = publicKey
|
|
12
|
-
this.src = src
|
|
13
|
-
this.grantToken = grantToken
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async run () {
|
|
17
|
-
const token = normalizeToken(this.token)
|
|
18
|
-
const url = `${this.hostname}/api/armor/decrypt`
|
|
19
|
-
const body = {
|
|
20
|
-
device_public_key: this.devicePublicKey,
|
|
21
|
-
cli_version: packageJson.version,
|
|
22
|
-
public_key: this.publicKey,
|
|
23
|
-
src: this.src
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (this.grantToken) {
|
|
27
|
-
body.grant_token = this.grantToken
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const resp = await http(url, {
|
|
31
|
-
method: 'POST',
|
|
32
|
-
headers: {
|
|
33
|
-
Authorization: `Bearer ${token}`,
|
|
34
|
-
'Content-Type': 'application/json'
|
|
35
|
-
},
|
|
36
|
-
body: JSON.stringify(body)
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
const json = await resp.body.json()
|
|
40
|
-
|
|
41
|
-
if (resp.statusCode >= 400) {
|
|
42
|
-
throw buildApiError(resp.statusCode, json)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return json
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
module.exports = PostArmorDecrypt
|