@dotenvx/dotenvx 2.29.0 → 2.31.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 +24 -1
- package/README.md +81 -749
- package/package.json +5 -5
- package/src/cli/actions/armor/down.js +1 -1
- package/src/cli/actions/armor/move.js +1 -1
- package/src/cli/actions/armor/open.js +1 -1
- package/src/cli/actions/armor/pull.js +1 -1
- package/src/cli/actions/armor/push.js +1 -1
- package/src/cli/actions/armor/up.js +1 -1
- package/src/cli/actions/{validate.js → check.js} +5 -5
- package/src/cli/actions/curl.js +2 -2
- package/src/cli/actions/decrypt.js +4 -10
- package/src/cli/actions/del.js +3 -5
- package/src/cli/actions/encrypt.js +4 -10
- package/src/cli/actions/ext/genexample.js +1 -1
- package/src/cli/actions/ext/prebuild.js +1 -1
- package/src/cli/actions/ext/scan.js +2 -3
- package/src/cli/actions/feedback.js +42 -0
- package/src/cli/actions/get.js +4 -7
- package/src/cli/actions/init.js +56 -2
- package/src/cli/actions/keychain/down.js +1 -1
- package/src/cli/actions/keychain/pull.js +1 -1
- package/src/cli/actions/keychain/push.js +1 -1
- package/src/cli/actions/keychain/up.js +1 -1
- package/src/cli/actions/keypair.js +3 -3
- package/src/cli/actions/lock/down.js +2 -3
- package/src/cli/actions/lock/up.js +2 -3
- package/src/cli/actions/login.js +2 -2
- package/src/cli/actions/logout.js +1 -1
- package/src/cli/actions/ls.js +1 -1
- package/src/cli/actions/protect.js +4 -1
- package/src/cli/actions/protectDocker.js +2 -2
- package/src/cli/actions/protectProcess.js +4 -1
- package/src/cli/actions/protectStdin.js +1 -0
- package/src/cli/actions/run.js +5 -6
- package/src/cli/actions/set.js +5 -9
- package/src/cli/actions/settings/device.js +2 -2
- package/src/cli/actions/settings/hostname.js +2 -2
- package/src/cli/actions/settings/off.js +1 -1
- package/src/cli/actions/settings/on.js +1 -1
- package/src/cli/actions/settings/path.js +2 -2
- package/src/cli/actions/settings/token.js +2 -2
- package/src/cli/actions/settings/username.js +2 -2
- package/src/cli/commandAction.js +16 -0
- package/src/cli/commands/armor.js +10 -9
- package/src/cli/commands/custody.js +6 -4
- package/src/cli/commands/ext.js +4 -3
- package/src/cli/commands/lock.js +3 -2
- package/src/cli/commands/native.js +5 -4
- package/src/cli/commands/primitives.js +46 -0
- package/src/cli/commands/settings.js +8 -7
- package/src/cli/dotenvx.js +45 -24
- package/src/lib/api/postFeedback.js +31 -0
- package/src/lib/envfile/discovery/discoverEnvFiles.js +29 -0
- package/src/lib/envfile/discovery/extractEnvKeys.js +173 -0
- package/src/lib/envfile/discovery/scanSource.js +79 -0
- package/src/lib/{helpers → envfile/parsing}/readEnvfile.js +3 -3
- package/src/lib/envfile/rendering/normalizeEnvfile.js +56 -0
- package/src/lib/envfile/rendering/renderEnvfile.js +26 -0
- package/src/lib/{helpers → envfile/validation}/validate.js +2 -2
- package/src/lib/{helpers → envfile/validation}/validateEnvfile.js +1 -1
- package/src/lib/events/backends/armor.js +31 -0
- package/src/lib/events/background.js +59 -0
- package/src/lib/events/catalog.js +14 -0
- package/src/lib/events/cli.js +40 -0
- package/src/lib/events/delivery.js +89 -0
- package/src/lib/events/index.js +73 -0
- package/src/lib/events/metadata.js +25 -0
- package/src/lib/events/sdk.js +44 -0
- package/src/lib/events/worker.js +29 -0
- package/src/lib/events/workerEnvironment.js +14 -0
- package/src/lib/helpers/checklist.js +9 -4
- package/src/lib/helpers/errors.js +1 -1
- package/src/lib/helpers/executeCommand.js +12 -1
- package/src/lib/helpers/hasPlaintextSecrets.js +2 -6
- package/src/lib/helpers/prompts.js +17 -0
- package/src/lib/main.d.ts +14 -0
- package/src/lib/main.js +15 -3
- package/src/lib/services/init.js +34 -12
- package/src/lib/services/validate.js +2 -2
- package/src/cli/actions/define.js +0 -17
- /package/src/lib/{grammars → envfile/parsing}/envfile.peggy +0 -0
- /package/src/lib/{helpers → envfile/parsing}/envfileParser.js +0 -0
- /package/src/lib/{helpers → envfile/parsing}/formatEnvfileSyntaxError.js +0 -0
- /package/src/lib/{helpers → envfile/validation}/encryptedSources.js +0 -0
package/src/cli/actions/set.js
CHANGED
|
@@ -25,8 +25,7 @@ async function set (key, value) {
|
|
|
25
25
|
if (value === undefined || value === null) {
|
|
26
26
|
if (!process.stdin.isTTY) {
|
|
27
27
|
catchAndLog(new Errors({ key }).missingValue())
|
|
28
|
-
|
|
29
|
-
return
|
|
28
|
+
return { exitCode: 1 }
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
try {
|
|
@@ -40,8 +39,7 @@ async function set (key, value) {
|
|
|
40
39
|
})
|
|
41
40
|
} catch (error) {
|
|
42
41
|
if (error.code === 'PROMPT_CANCELLED') {
|
|
43
|
-
|
|
44
|
-
return
|
|
42
|
+
return { exitCode: 130, error }
|
|
45
43
|
}
|
|
46
44
|
|
|
47
45
|
throw error
|
|
@@ -127,14 +125,12 @@ async function set (key, value) {
|
|
|
127
125
|
// // do nothing
|
|
128
126
|
// }
|
|
129
127
|
|
|
130
|
-
|
|
131
|
-
process.exit(1)
|
|
132
|
-
}
|
|
128
|
+
return { exitCode: errorCount > 0 ? 1 : 0, errorCount }
|
|
133
129
|
} catch (error) {
|
|
134
130
|
if (spinner) spinner.stop()
|
|
135
131
|
catchAndLog(error)
|
|
136
|
-
|
|
132
|
+
return { exitCode: 1, error }
|
|
137
133
|
}
|
|
138
134
|
}
|
|
139
135
|
|
|
140
|
-
module.exports = set
|
|
136
|
+
module.exports = require('../../lib/events/cli')('set', set)
|
|
@@ -13,10 +13,10 @@ function device () {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
logger.error('missing device. Try generating one with [dotenvx armor login].')
|
|
16
|
-
|
|
16
|
+
return { exitCode: 1 }
|
|
17
17
|
} catch (error) {
|
|
18
18
|
logger.error(error.message)
|
|
19
|
-
|
|
19
|
+
return { exitCode: 1, error }
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -10,10 +10,10 @@ function hostname () {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
logger.error('missing hostname. Try running [dotenvx armor login].')
|
|
13
|
-
|
|
13
|
+
return { exitCode: 1 }
|
|
14
14
|
} catch (error) {
|
|
15
15
|
logger.error(error.message)
|
|
16
|
-
|
|
16
|
+
return { exitCode: 1, error }
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|
|
@@ -10,10 +10,10 @@ function path () {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
logger.error('missing path. Try running [dotenvx armor login].')
|
|
13
|
-
|
|
13
|
+
return { exitCode: 1 }
|
|
14
14
|
} catch (error) {
|
|
15
15
|
logger.error(error.message)
|
|
16
|
-
|
|
16
|
+
return { exitCode: 1, error }
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|
|
@@ -13,10 +13,10 @@ function token () {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
logger.error('missing token. Try generating one with [dotenvx armor login].')
|
|
16
|
-
|
|
16
|
+
return { exitCode: 1 }
|
|
17
17
|
} catch (error) {
|
|
18
18
|
logger.error(error.message)
|
|
19
|
-
|
|
19
|
+
return { exitCode: 1, error }
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -10,10 +10,10 @@ function username () {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
logger.error('login required. Try running [dotenvx armor login].')
|
|
13
|
-
|
|
13
|
+
return { exitCode: 1 }
|
|
14
14
|
} catch (error) {
|
|
15
15
|
logger.error(error.message)
|
|
16
|
-
|
|
16
|
+
return { exitCode: 1, error }
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Command lifecycle only. Returning an outcome does not opt into event tracking.
|
|
2
|
+
module.exports = function commandAction (action) {
|
|
3
|
+
return async function (...args) {
|
|
4
|
+
const result = await action.apply(this, args)
|
|
5
|
+
if (Number.isInteger(result?.exitCode)) {
|
|
6
|
+
// Pipe writes are asynchronous. Flush both streams before forcing exit so
|
|
7
|
+
// successful output and failure diagnostics cannot be silently truncated.
|
|
8
|
+
await Promise.all([process.stdout, process.stderr].map(stream => {
|
|
9
|
+
if (!stream.writable || stream.destroyed) return Promise.resolve()
|
|
10
|
+
return new Promise(resolve => stream.write('', 'utf8', resolve))
|
|
11
|
+
}))
|
|
12
|
+
process.exit(result.exitCode)
|
|
13
|
+
}
|
|
14
|
+
return result
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const commandAction = require('../commandAction')
|
|
1
2
|
const executeDynamic = require('./../../lib/helpers/executeDynamic')
|
|
2
3
|
|
|
3
4
|
function configureArmorCommand (armor) {
|
|
@@ -25,7 +26,7 @@ function configureArmorCommand (armor) {
|
|
|
25
26
|
.option('--token <token>', 'set token')
|
|
26
27
|
.option('--team <team>', 'team to armor private key for')
|
|
27
28
|
.action(function (...args) {
|
|
28
|
-
return require('./../actions/armor/up').apply(this, args)
|
|
29
|
+
return commandAction(require('./../actions/armor/up')).apply(this, args)
|
|
29
30
|
})
|
|
30
31
|
|
|
31
32
|
// dotenvx armor down
|
|
@@ -36,7 +37,7 @@ function configureArmorCommand (armor) {
|
|
|
36
37
|
.option('--token <token>', 'set token')
|
|
37
38
|
.option('--team <team>', 'team to dearmor private key from')
|
|
38
39
|
.action(function (...args) {
|
|
39
|
-
return require('./../actions/armor/down').apply(this, args)
|
|
40
|
+
return commandAction(require('./../actions/armor/down')).apply(this, args)
|
|
40
41
|
})
|
|
41
42
|
|
|
42
43
|
// dotenvx armor push
|
|
@@ -47,7 +48,7 @@ function configureArmorCommand (armor) {
|
|
|
47
48
|
.option('--token <token>', 'set token')
|
|
48
49
|
.option('--team <team>', 'team to push armored private key for')
|
|
49
50
|
.action(function (...args) {
|
|
50
|
-
return require('./../actions/armor/push').apply(this, args)
|
|
51
|
+
return commandAction(require('./../actions/armor/push')).apply(this, args)
|
|
51
52
|
})
|
|
52
53
|
|
|
53
54
|
// dotenvx armor pull
|
|
@@ -58,7 +59,7 @@ function configureArmorCommand (armor) {
|
|
|
58
59
|
.option('--token <token>', 'set token')
|
|
59
60
|
.option('--team <team>', 'team to pull armored private key from')
|
|
60
61
|
.action(function (...args) {
|
|
61
|
-
return require('./../actions/armor/pull').apply(this, args)
|
|
62
|
+
return commandAction(require('./../actions/armor/pull')).apply(this, args)
|
|
62
63
|
})
|
|
63
64
|
|
|
64
65
|
// dotenvx armor open
|
|
@@ -67,7 +68,7 @@ function configureArmorCommand (armor) {
|
|
|
67
68
|
.description('open armored key (in browser)')
|
|
68
69
|
.option('-f, --env-file <path>', 'path to your env file')
|
|
69
70
|
.action(function (...args) {
|
|
70
|
-
return require('./../actions/armor/open').apply(this, args)
|
|
71
|
+
return commandAction(require('./../actions/armor/open')).apply(this, args)
|
|
71
72
|
})
|
|
72
73
|
|
|
73
74
|
// dotenvx armor move
|
|
@@ -77,7 +78,7 @@ function configureArmorCommand (armor) {
|
|
|
77
78
|
.option('-f, --env-file <path>', 'path to your env file')
|
|
78
79
|
.option('--token <token>', 'set token')
|
|
79
80
|
.action(function (...args) {
|
|
80
|
-
return require('./../actions/armor/move').apply(this, args)
|
|
81
|
+
return commandAction(require('./../actions/armor/move')).apply(this, args)
|
|
81
82
|
})
|
|
82
83
|
|
|
83
84
|
// dotenvx armor login
|
|
@@ -87,7 +88,7 @@ function configureArmorCommand (armor) {
|
|
|
87
88
|
.allowUnknownOption()
|
|
88
89
|
.option('--hostname <hostname>', 'set Armor ⛨ hostname')
|
|
89
90
|
.action(function (...args) {
|
|
90
|
-
return require('./../actions/login').apply(this, args)
|
|
91
|
+
return commandAction(require('./../actions/login')).apply(this, args)
|
|
91
92
|
})
|
|
92
93
|
|
|
93
94
|
// dotenvx armor logout
|
|
@@ -97,7 +98,7 @@ function configureArmorCommand (armor) {
|
|
|
97
98
|
.allowUnknownOption()
|
|
98
99
|
.option('--hostname <hostname>', 'set Armor ⛨ hostname')
|
|
99
100
|
.action(function (...args) {
|
|
100
|
-
return require('./../actions/logout').apply(this, args)
|
|
101
|
+
return commandAction(require('./../actions/logout')).apply(this, args)
|
|
101
102
|
})
|
|
102
103
|
|
|
103
104
|
// dotenvx armor status
|
|
@@ -105,7 +106,7 @@ function configureArmorCommand (armor) {
|
|
|
105
106
|
.command('status')
|
|
106
107
|
.description('print armor status')
|
|
107
108
|
.action(function (...args) {
|
|
108
|
-
return require('./../actions/armor/status').apply(this, args)
|
|
109
|
+
return commandAction(require('./../actions/armor/status')).apply(this, args)
|
|
109
110
|
})
|
|
110
111
|
|
|
111
112
|
// dotenvx armor settings
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const commandAction = require('../commandAction')
|
|
2
|
+
|
|
1
3
|
function configureCustodyCommand (command, name, custodianId) {
|
|
2
4
|
command.hook('preAction', async () => {
|
|
3
5
|
const Session = require('../../db/session')
|
|
@@ -15,7 +17,7 @@ function configureCustodyCommand (command, name, custodianId) {
|
|
|
15
17
|
.description(description)
|
|
16
18
|
.option('-f, --env-file <path>', 'path to your env file')
|
|
17
19
|
.option('-fk, --env-keys-file <path>', 'path to your .env.keys file', '.env.keys')
|
|
18
|
-
.action(async function () {
|
|
20
|
+
.action(commandAction(async function () {
|
|
19
21
|
const { logger } = require('../../shared/logger')
|
|
20
22
|
const createSpinner = require('../../lib/helpers/createSpinner')
|
|
21
23
|
const armoredKeyDisplay = require('../../lib/helpers/armoredKeyDisplay')
|
|
@@ -31,11 +33,11 @@ function configureCustodyCommand (command, name, custodianId) {
|
|
|
31
33
|
else logger.info(`○ no change (${display})`)
|
|
32
34
|
} catch (error) {
|
|
33
35
|
if (spinner) spinner.stop()
|
|
34
|
-
if (error.code === 'PROMPT_CANCELLED') return
|
|
36
|
+
if (error.code === 'PROMPT_CANCELLED') return { exitCode: 130, error }
|
|
35
37
|
logger.error(error.message)
|
|
36
|
-
|
|
38
|
+
return { exitCode: 1, error }
|
|
37
39
|
}
|
|
38
|
-
})
|
|
40
|
+
}))
|
|
39
41
|
}
|
|
40
42
|
return command
|
|
41
43
|
}
|
package/src/cli/commands/ext.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const commandAction = require('../commandAction')
|
|
1
2
|
const { Command } = require('@dotenvx/tooling')
|
|
2
3
|
|
|
3
4
|
const help = require('./../help')
|
|
@@ -26,7 +27,7 @@ ext.command('ls')
|
|
|
26
27
|
.option('-ef, --exclude-env-file <excludeFilenames...>', 'path(s) to exclude from your env file(s) (default: none)')
|
|
27
28
|
.option('--json', 'output a JSON array of absolute filepaths')
|
|
28
29
|
.action(function (...args) {
|
|
29
|
-
return require('./../actions/ls').apply(this, args)
|
|
30
|
+
return commandAction(require('./../actions/ls')).apply(this, args)
|
|
30
31
|
})
|
|
31
32
|
|
|
32
33
|
// dotenvx ext genexample
|
|
@@ -35,7 +36,7 @@ ext.command('genexample')
|
|
|
35
36
|
.argument('[directory]', 'directory to generate from', '.')
|
|
36
37
|
.option('-f, --env-file <paths...>', 'path(s) to your env file(s)', '.env')
|
|
37
38
|
.action(function (...args) {
|
|
38
|
-
return require('./../actions/ext/genexample').apply(this, args)
|
|
39
|
+
return commandAction(require('./../actions/ext/genexample')).apply(this, args)
|
|
39
40
|
})
|
|
40
41
|
|
|
41
42
|
// dotenvx ext gitignore
|
|
@@ -71,7 +72,7 @@ ext.command('precommit')
|
|
|
71
72
|
ext.command('scan')
|
|
72
73
|
.description('scan for leaked secrets')
|
|
73
74
|
.action(function (...args) {
|
|
74
|
-
return require('./../actions/ext/scan').apply(this, args)
|
|
75
|
+
return commandAction(require('./../actions/ext/scan')).apply(this, args)
|
|
75
76
|
})
|
|
76
77
|
|
|
77
78
|
// override helpInformation to hide dynamic commands
|
package/src/cli/commands/lock.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const commandAction = require('../commandAction')
|
|
1
2
|
function configureLockCommand (lock) {
|
|
2
3
|
lock.hook('preAction', async () => {
|
|
3
4
|
const Session = require('./../../db/session')
|
|
@@ -17,7 +18,7 @@ function configureLockCommand (lock) {
|
|
|
17
18
|
.option('-f, --env-file <path>', 'path to your env file')
|
|
18
19
|
.option('-fk, --env-keys-file <path>', 'path to your .env.keys file', '.env.keys')
|
|
19
20
|
.action(function (...args) {
|
|
20
|
-
return require('./../actions/lock/up').apply(this, args)
|
|
21
|
+
return commandAction(require('./../actions/lock/up')).apply(this, args)
|
|
21
22
|
})
|
|
22
23
|
|
|
23
24
|
lock
|
|
@@ -26,7 +27,7 @@ function configureLockCommand (lock) {
|
|
|
26
27
|
.option('-f, --env-file <path>', 'path to your env file')
|
|
27
28
|
.option('-fk, --env-keys-file <path>', 'path to your .env.keys file', '.env.keys')
|
|
28
29
|
.action(function (...args) {
|
|
29
|
-
return require('./../actions/lock/down').apply(this, args)
|
|
30
|
+
return commandAction(require('./../actions/lock/down')).apply(this, args)
|
|
30
31
|
})
|
|
31
32
|
|
|
32
33
|
return lock
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const commandAction = require('../commandAction')
|
|
1
2
|
function configureNativeCommand (native) {
|
|
2
3
|
native.hook('preAction', async () => {
|
|
3
4
|
const Session = require('./../../db/session')
|
|
@@ -17,7 +18,7 @@ function configureNativeCommand (native) {
|
|
|
17
18
|
.option('-f, --env-file <path>', 'path to your env file')
|
|
18
19
|
.option('-fk, --env-keys-file <path>', 'path to your .env.keys file', '.env.keys')
|
|
19
20
|
.action(function (...args) {
|
|
20
|
-
return require('./../actions/keychain/up').apply(this, args)
|
|
21
|
+
return commandAction(require('./../actions/keychain/up')).apply(this, args)
|
|
21
22
|
})
|
|
22
23
|
|
|
23
24
|
native
|
|
@@ -26,7 +27,7 @@ function configureNativeCommand (native) {
|
|
|
26
27
|
.option('-f, --env-file <path>', 'path to your env file')
|
|
27
28
|
.option('-fk, --env-keys-file <path>', 'path to your .env.keys file', '.env.keys')
|
|
28
29
|
.action(function (...args) {
|
|
29
|
-
return require('./../actions/keychain/down').apply(this, args)
|
|
30
|
+
return commandAction(require('./../actions/keychain/down')).apply(this, args)
|
|
30
31
|
})
|
|
31
32
|
|
|
32
33
|
native
|
|
@@ -35,7 +36,7 @@ function configureNativeCommand (native) {
|
|
|
35
36
|
.option('-f, --env-file <path>', 'path to your env file')
|
|
36
37
|
.option('-fk, --env-keys-file <path>', 'path to your .env.keys file', '.env.keys')
|
|
37
38
|
.action(function (...args) {
|
|
38
|
-
return require('./../actions/keychain/push').apply(this, args)
|
|
39
|
+
return commandAction(require('./../actions/keychain/push')).apply(this, args)
|
|
39
40
|
})
|
|
40
41
|
|
|
41
42
|
native
|
|
@@ -44,7 +45,7 @@ function configureNativeCommand (native) {
|
|
|
44
45
|
.option('-f, --env-file <path>', 'path to your env file')
|
|
45
46
|
.option('-fk, --env-keys-file <path>', 'path to your .env.keys file', '.env.keys')
|
|
46
47
|
.action(function (...args) {
|
|
47
|
-
return require('./../actions/keychain/pull').apply(this, args)
|
|
48
|
+
return commandAction(require('./../actions/keychain/pull')).apply(this, args)
|
|
48
49
|
})
|
|
49
50
|
|
|
50
51
|
return native
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const { derive, keypair } = require('@dotenvx/primitives')
|
|
2
|
+
const commandAction = require('../commandAction')
|
|
3
|
+
const catchAndLog = require('../../lib/helpers/catchAndLog')
|
|
4
|
+
|
|
5
|
+
function output (operation, required = false) {
|
|
6
|
+
return commandAction(async function (privateKey) {
|
|
7
|
+
try {
|
|
8
|
+
if (this.opts().stdin) {
|
|
9
|
+
if (privateKey !== undefined) throw new Error('Cannot combine a private key argument with --stdin')
|
|
10
|
+
process.stdin.setEncoding('utf8')
|
|
11
|
+
let input = ''
|
|
12
|
+
for await (const chunk of process.stdin) input += chunk
|
|
13
|
+
privateKey = input.trim()
|
|
14
|
+
if (!privateKey) throw new Error('Expected a private key on stdin')
|
|
15
|
+
}
|
|
16
|
+
if (required && privateKey === undefined) throw new Error('Provide a private key argument or use --stdin')
|
|
17
|
+
if (privateKey !== undefined && (privateKey.length !== 64 || !/^[a-f0-9]{64}$/i.test(privateKey))) throw new Error('Expected one 64-character hex private key')
|
|
18
|
+
const result = operation(privateKey)
|
|
19
|
+
console.log(typeof result === 'string' ? result : JSON.stringify(result))
|
|
20
|
+
return { exitCode: 0 }
|
|
21
|
+
} catch (error) {
|
|
22
|
+
catchAndLog(error)
|
|
23
|
+
return { exitCode: 1 }
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports = function primitives (command) {
|
|
29
|
+
command
|
|
30
|
+
.description('standalone primitives without env file reads or writes')
|
|
31
|
+
.action(function () { this.help() })
|
|
32
|
+
|
|
33
|
+
command.command('keypair')
|
|
34
|
+
.description('generate or restore a key pair and print JSON')
|
|
35
|
+
.argument('[privateKey]', 'hex-encoded private key to restore')
|
|
36
|
+
.option('--stdin', 'read the private key from stdin')
|
|
37
|
+
.allowExcessArguments(false)
|
|
38
|
+
.action(output(keypair))
|
|
39
|
+
|
|
40
|
+
command.command('derive')
|
|
41
|
+
.description('derive and print a public key from a private key')
|
|
42
|
+
.argument('[privateKey]', 'hex-encoded private key')
|
|
43
|
+
.option('--stdin', 'read the private key from stdin')
|
|
44
|
+
.allowExcessArguments(false)
|
|
45
|
+
.action(output(derive, true))
|
|
46
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const commandAction = require('../commandAction')
|
|
1
2
|
function configureSettingsCommand (settings) {
|
|
2
3
|
settings
|
|
3
4
|
.description('settings')
|
|
@@ -9,7 +10,7 @@ function configureSettingsCommand (settings) {
|
|
|
9
10
|
.command('username')
|
|
10
11
|
.description('print your username')
|
|
11
12
|
.action(function (...args) {
|
|
12
|
-
return require('./../actions/settings/username').apply(this, args)
|
|
13
|
+
return commandAction(require('./../actions/settings/username')).apply(this, args)
|
|
13
14
|
})
|
|
14
15
|
|
|
15
16
|
settings
|
|
@@ -17,7 +18,7 @@ function configureSettingsCommand (settings) {
|
|
|
17
18
|
.description('print your access token (--unmask)')
|
|
18
19
|
.option('--unmask', 'unmask access token')
|
|
19
20
|
.action(function (...args) {
|
|
20
|
-
return require('./../actions/settings/token').apply(this, args)
|
|
21
|
+
return commandAction(require('./../actions/settings/token')).apply(this, args)
|
|
21
22
|
})
|
|
22
23
|
|
|
23
24
|
settings
|
|
@@ -25,35 +26,35 @@ function configureSettingsCommand (settings) {
|
|
|
25
26
|
.description('print your device pubkey (--unmask)')
|
|
26
27
|
.option('--unmask', 'unmask device pubkey')
|
|
27
28
|
.action(function (...args) {
|
|
28
|
-
return require('./../actions/settings/device').apply(this, args)
|
|
29
|
+
return commandAction(require('./../actions/settings/device')).apply(this, args)
|
|
29
30
|
})
|
|
30
31
|
|
|
31
32
|
settings
|
|
32
33
|
.command('hostname')
|
|
33
34
|
.description('print hostname')
|
|
34
35
|
.action(function (...args) {
|
|
35
|
-
return require('./../actions/settings/hostname').apply(this, args)
|
|
36
|
+
return commandAction(require('./../actions/settings/hostname')).apply(this, args)
|
|
36
37
|
})
|
|
37
38
|
|
|
38
39
|
settings
|
|
39
40
|
.command('path')
|
|
40
41
|
.description('print path to settings file')
|
|
41
42
|
.action(function (...args) {
|
|
42
|
-
return require('./../actions/settings/path').apply(this, args)
|
|
43
|
+
return commandAction(require('./../actions/settings/path')).apply(this, args)
|
|
43
44
|
})
|
|
44
45
|
|
|
45
46
|
settings
|
|
46
47
|
.command('on')
|
|
47
48
|
.description('turn armor on')
|
|
48
49
|
.action(function (...args) {
|
|
49
|
-
return require('./../actions/settings/on').apply(this, args)
|
|
50
|
+
return commandAction(require('./../actions/settings/on')).apply(this, args)
|
|
50
51
|
})
|
|
51
52
|
|
|
52
53
|
settings
|
|
53
54
|
.command('off')
|
|
54
55
|
.description('turn armor off')
|
|
55
56
|
.action(function (...args) {
|
|
56
|
-
return require('./../actions/settings/off').apply(this, args)
|
|
57
|
+
return commandAction(require('./../actions/settings/off')).apply(this, args)
|
|
57
58
|
})
|
|
58
59
|
|
|
59
60
|
return settings
|
package/src/cli/dotenvx.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
/* c8 ignore start */
|
|
4
4
|
const { Command } = require('@dotenvx/tooling')
|
|
5
5
|
const program = new Command()
|
|
6
|
+
const commandAction = require('./commandAction')
|
|
6
7
|
|
|
7
8
|
const { setLogLevel } = require('../shared/logger')
|
|
8
9
|
const help = require('./help')
|
|
@@ -220,28 +221,20 @@ program.command('ls', { hidden: true })
|
|
|
220
221
|
.option('-ef, --exclude-env-file <excludeFilenames...>', 'path(s) to exclude from your env file(s) (default: none)')
|
|
221
222
|
.option('--json', 'output a JSON array of absolute filepaths')
|
|
222
223
|
.action(function (...args) {
|
|
223
|
-
return require('./actions/ls').apply(this, args)
|
|
224
|
+
return commandAction(require('./actions/ls')).apply(this, args)
|
|
224
225
|
})
|
|
225
226
|
|
|
226
227
|
// dotenvx init
|
|
227
228
|
program.command('init', { hidden: true })
|
|
228
|
-
.description('
|
|
229
|
+
.description('select .env files to create an Envfile')
|
|
229
230
|
.option('-f, --env-file <path>', 'file to read variable names from')
|
|
230
231
|
.action(function () {
|
|
231
|
-
return require('./actions/init').apply(this, arguments)
|
|
232
|
+
return commandAction(require('./actions/init')).apply(this, arguments)
|
|
232
233
|
})
|
|
233
234
|
|
|
234
|
-
// dotenvx
|
|
235
|
-
program.command('
|
|
236
|
-
.description('
|
|
237
|
-
.option('-f, --env-file <path>', 'file to read variable names from')
|
|
238
|
-
.action(function () {
|
|
239
|
-
return require('./actions/define').apply(this, arguments)
|
|
240
|
-
})
|
|
241
|
-
|
|
242
|
-
// dotenvx validate
|
|
243
|
-
program.command('validate', { hidden: true })
|
|
244
|
-
.description('validate .env file(s) against Envfile')
|
|
235
|
+
// dotenvx check
|
|
236
|
+
program.command('check', { hidden: true })
|
|
237
|
+
.description('check .env file(s) against Envfile')
|
|
245
238
|
.option('--strict', 'process.exit(1) on any errors, including missing env files', false)
|
|
246
239
|
.option('-e, --env <strings...>', 'environment variable(s) set as string (example: "HELLO=World")', collectEnvs('env'), [])
|
|
247
240
|
.option('-f, --env-file <path>', 'path(s) to your env file(s)', collectEnvs('envFile'), [])
|
|
@@ -256,7 +249,7 @@ program.command('validate', { hidden: true })
|
|
|
256
249
|
.option('--no-bitwarden', 'disable Bitwarden secret reference resolution')
|
|
257
250
|
.action(function (...args) {
|
|
258
251
|
this.envs = envs
|
|
259
|
-
return require('./actions/
|
|
252
|
+
return commandAction(require('./actions/check')).apply(this, args)
|
|
260
253
|
})
|
|
261
254
|
|
|
262
255
|
// dotenvx gitignore
|
|
@@ -274,7 +267,7 @@ program.command('genexample', { hidden: true })
|
|
|
274
267
|
.argument('[directory]', 'directory to generate from', '.')
|
|
275
268
|
.option('-f, --env-file <paths...>', 'path(s) to your env file(s)', '.env')
|
|
276
269
|
.action(function (...args) {
|
|
277
|
-
return require('./actions/ext/genexample').apply(this, args)
|
|
270
|
+
return commandAction(require('./actions/ext/genexample')).apply(this, args)
|
|
278
271
|
})
|
|
279
272
|
|
|
280
273
|
// dotenvx precommit
|
|
@@ -313,21 +306,43 @@ program.command('doctor', { hidden: true })
|
|
|
313
306
|
.description('scan for dotenv loaders')
|
|
314
307
|
.argument('[directory]', 'directory to scan', '.')
|
|
315
308
|
.action(function (...args) {
|
|
316
|
-
return require('./actions/doctor').apply(this, args)
|
|
309
|
+
return commandAction(require('./actions/doctor')).apply(this, args)
|
|
310
|
+
})
|
|
311
|
+
|
|
312
|
+
// dotenvx feedback
|
|
313
|
+
program.command('feedback', { hidden: true })
|
|
314
|
+
.description('send feedback to dotenvx')
|
|
315
|
+
.argument('[message]', 'feedback message')
|
|
316
|
+
.allowExcessArguments(false)
|
|
317
|
+
.option('--hostname <hostname>', 'set API hostname')
|
|
318
|
+
.action(function (...args) {
|
|
319
|
+
return commandAction(require('./actions/feedback')).apply(this, args)
|
|
317
320
|
})
|
|
318
321
|
|
|
319
|
-
//
|
|
322
|
+
// Build menu entries from the command definitions so new subcommands stay discoverable.
|
|
323
|
+
function hiddenSubcommands (name) {
|
|
324
|
+
const parent = program.commands.find(command => command.name() === name)
|
|
325
|
+
const formatter = parent.createHelp()
|
|
326
|
+
const entries = parent.commands.map(command => ({
|
|
327
|
+
term: `${name} ${formatter.subcommandTerm(command)}`,
|
|
328
|
+
description: command.description()
|
|
329
|
+
}))
|
|
330
|
+
const width = Math.max(...entries.map(entry => entry.term.length))
|
|
331
|
+
return entries.map(entry => ` ${entry.term.padEnd(width)} ${entry.description}`).join('\n')
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// dotenvx hidden (a menu of commands and subcommands)
|
|
320
335
|
program.command('hidden')
|
|
321
336
|
.allowExcessArguments(false)
|
|
322
337
|
.description('hidden features')
|
|
323
|
-
.addHelpText('after',
|
|
338
|
+
.addHelpText('after', () => `\nHidden Commands:\n update update dotenvx\n feedback [message] send feedback to dotenvx\n protect protect secrets and private keys from code commits\n ls [directory] print all .env files in a tree structure\n genexample [directory] generate .env.example\n lock ⊡ lock private keys with a local passphrase\n native ⌥ move private keys in/out of your OS secret store\n 1password □ move private keys in/out of 1Password\n bitwarden □ move private keys in/out of Bitwarden\n armor ⛨ move private keys in/out of Dotenvx Armor [www.dotenvx.com/armor]\n curl ⛨ call authenticated api Dotenvx Armor [www.dotenvx.com/armor]\n\nBeta Commands:\n init create an Envfile from .env files and source code\n check check .env file(s) against Envfile\n${hiddenSubcommands('primitives')}\n\nDeprecated Commands:\n gitignore deprecated. use [dotenvx protect]\n precommit [directory] deprecated. use [dotenvx protect]\n prebuild [directory] deprecated. use [dotenvx protect --docker]\n\nRun directly: dotenvx <command>`)
|
|
324
339
|
.action(function () { this.outputHelp() })
|
|
325
340
|
|
|
326
341
|
// dotenvx update
|
|
327
|
-
program.command('update')
|
|
342
|
+
program.command('update', { hidden: true })
|
|
328
343
|
.description('update dotenvx')
|
|
329
344
|
.action(function (...args) {
|
|
330
|
-
return require('./actions/update').apply(this, args)
|
|
345
|
+
return commandAction(require('./actions/update')).apply(this, args)
|
|
331
346
|
})
|
|
332
347
|
|
|
333
348
|
// dotenvx login (compatibility alias for dotenvx armor login)
|
|
@@ -336,7 +351,7 @@ program.command('login', { hidden: true })
|
|
|
336
351
|
.allowUnknownOption()
|
|
337
352
|
.option('--hostname <hostname>', 'set Armor ⛨ hostname')
|
|
338
353
|
.action(function (...args) {
|
|
339
|
-
return require('./actions/login').apply(this, args)
|
|
354
|
+
return commandAction(require('./actions/login')).apply(this, args)
|
|
340
355
|
})
|
|
341
356
|
|
|
342
357
|
// dotenvx logout (compatibility alias for dotenvx armor logout)
|
|
@@ -345,7 +360,7 @@ program.command('logout', { hidden: true })
|
|
|
345
360
|
.allowUnknownOption()
|
|
346
361
|
.option('--hostname <hostname>', 'set Armor ⛨ hostname')
|
|
347
362
|
.action(function (...args) {
|
|
348
|
-
return require('./actions/logout').apply(this, args)
|
|
363
|
+
return commandAction(require('./actions/logout')).apply(this, args)
|
|
349
364
|
})
|
|
350
365
|
|
|
351
366
|
// dotenvx curl
|
|
@@ -362,7 +377,7 @@ program.command('curl', { hidden: true })
|
|
|
362
377
|
return
|
|
363
378
|
}
|
|
364
379
|
|
|
365
|
-
return require('./actions/curl').apply(this, args)
|
|
380
|
+
return commandAction(require('./actions/curl')).apply(this, args)
|
|
366
381
|
})
|
|
367
382
|
|
|
368
383
|
// dotenvx help
|
|
@@ -393,6 +408,9 @@ require('./commands/lock')(program.command('lock', { hidden: true }))
|
|
|
393
408
|
// dotenvx armor
|
|
394
409
|
require('./commands/armor')(program.command('armor', { hidden: true }))
|
|
395
410
|
|
|
411
|
+
// dotenvx primitives
|
|
412
|
+
require('./commands/primitives')(program.command('primitives', { hidden: true }))
|
|
413
|
+
|
|
396
414
|
// dotenvx ext
|
|
397
415
|
program.addCommand(require('./commands/ext'))
|
|
398
416
|
|
|
@@ -415,6 +433,9 @@ program.helpInformation = function () {
|
|
|
415
433
|
}
|
|
416
434
|
/* c8 ignore stop */
|
|
417
435
|
|
|
436
|
+
program.command('_deliver-events', { hidden: true })
|
|
437
|
+
.action(() => require('../lib/events/worker')())
|
|
438
|
+
|
|
418
439
|
require('./commands/fileOptions')(program)
|
|
419
440
|
|
|
420
441
|
program.parse(process.argv)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const { http } = require('../helpers/http')
|
|
2
|
+
const buildApiError = require('../helpers/buildApiError')
|
|
3
|
+
|
|
4
|
+
class PostFeedback {
|
|
5
|
+
constructor (hostname, body) {
|
|
6
|
+
this.hostname = hostname
|
|
7
|
+
this.body = body
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async run () {
|
|
11
|
+
const url = `${this.hostname}/api/feedback`
|
|
12
|
+
|
|
13
|
+
const resp = await http(url, {
|
|
14
|
+
method: 'POST',
|
|
15
|
+
headers: {
|
|
16
|
+
'Content-Type': 'application/json'
|
|
17
|
+
},
|
|
18
|
+
body: JSON.stringify({ body: this.body })
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
const json = await resp.body.json()
|
|
22
|
+
|
|
23
|
+
if (resp.statusCode >= 400) {
|
|
24
|
+
throw buildApiError(resp.statusCode, json)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return json
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = PostFeedback
|