@dotenvx/dotenvx 2.28.2 → 2.30.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 +20 -1
- package/README.md +47 -12
- package/package.json +3 -3
- 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/curl.js +2 -2
- package/src/cli/actions/decrypt.js +4 -10
- package/src/cli/actions/define.js +1 -1
- 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/gitignore.js +1 -0
- package/src/cli/actions/ext/prebuild.js +5 -28
- package/src/cli/actions/ext/precommit.js +8 -3
- package/src/cli/actions/ext/scan.js +2 -3
- package/src/cli/actions/get.js +4 -7
- 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 +75 -0
- package/src/cli/actions/protectDocker.js +30 -0
- package/src/cli/actions/protectProcess.js +126 -0
- package/src/cli/actions/protectStdin.js +64 -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/actions/validate.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 +7 -7
- package/src/cli/commands/lock.js +3 -2
- package/src/cli/commands/native.js +5 -4
- package/src/cli/commands/settings.js +8 -7
- package/src/cli/dotenvx.js +31 -17
- package/src/cli/help.js +4 -3
- 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 +50 -0
- package/src/lib/helpers/createProtectSpinner.js +13 -0
- package/src/lib/helpers/executeCommand.js +12 -1
- package/src/lib/helpers/hasPlaintextSecrets.js +7 -0
- package/src/lib/helpers/installPrecommitHook.js +1 -0
- package/src/lib/helpers/installProtectFilter.js +56 -0
- package/src/lib/helpers/installProtectIgnore.js +27 -0
- package/src/lib/helpers/logProtectedFiles.js +9 -0
- package/src/lib/helpers/precommitEnvPatterns.js +1 -0
- package/src/lib/helpers/prompts.js +24 -0
- package/src/lib/helpers/protectSettings.js +63 -0
- package/src/lib/helpers/removeLegacyProtectFilter.js +42 -0
- package/src/lib/helpers/uninstallPrecommitHook.js +66 -0
- package/src/lib/main.d.ts +14 -0
- package/src/lib/main.js +11 -3
- package/src/lib/services/prebuild.js +4 -5
- package/src/lib/services/precommit.js +2 -12
- package/src/cli/actions/ext/precommitClean.js +0 -21
- package/src/lib/helpers/installPrecommitFilter.js +0 -50
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const installProtectFilter = require('../../lib/helpers/installProtectFilter')
|
|
2
|
+
const installProtectIgnore = require('../../lib/helpers/installProtectIgnore')
|
|
3
|
+
const prompts = require('../../lib/helpers/prompts')
|
|
4
|
+
const { logger } = require('../../shared/logger')
|
|
5
|
+
const catchAndLog = require('../../lib/helpers/catchAndLog')
|
|
6
|
+
const settings = require('../../lib/helpers/protectSettings')
|
|
7
|
+
const createSpinner = require('../../lib/helpers/createSpinner')
|
|
8
|
+
|
|
9
|
+
async function protect (directory) {
|
|
10
|
+
if (this.opts().docker) return require('./protectDocker').call(this, directory)
|
|
11
|
+
const filterOptions = typeof this.optsWithGlobals === 'function' ? this.optsWithGlobals() : this.opts()
|
|
12
|
+
if (this.opts().gitProcess) return require('./protectProcess')(filterOptions)
|
|
13
|
+
if (this.opts().gitFile !== undefined) {
|
|
14
|
+
return require('./protectStdin')(this.opts().gitFile, filterOptions)
|
|
15
|
+
}
|
|
16
|
+
let spinner
|
|
17
|
+
try {
|
|
18
|
+
let filter = true
|
|
19
|
+
let ignore = false
|
|
20
|
+
let current
|
|
21
|
+
const interactive = !process.env.CI && process.stdin.isTTY && process.stderr.isTTY
|
|
22
|
+
if (interactive) {
|
|
23
|
+
current = settings.state()
|
|
24
|
+
const protections = await prompts.multiselect({
|
|
25
|
+
message: 'Set protections',
|
|
26
|
+
submitLabel: selected => {
|
|
27
|
+
if (current.configured && ['filter', 'ignore'].every(key => selected.includes(key) === current[key])) return 'Done'
|
|
28
|
+
if (!selected.length) return 'Remove protections'
|
|
29
|
+
return current.configured ? 'Apply changes' : 'Install protections'
|
|
30
|
+
},
|
|
31
|
+
choices: [
|
|
32
|
+
{ name: 'Protect plaintext secrets from code commits (.env*)', value: 'filter' },
|
|
33
|
+
{ name: 'Protect private keys from code commits (.env.keys*)', value: 'ignore' }
|
|
34
|
+
],
|
|
35
|
+
initial: ['filter', 'ignore']
|
|
36
|
+
})
|
|
37
|
+
filter = protections.includes('filter')
|
|
38
|
+
ignore = protections.includes('ignore')
|
|
39
|
+
}
|
|
40
|
+
const options = this.opts()
|
|
41
|
+
const spinnerOptions = typeof this.optsWithGlobals === 'function' ? this.optsWithGlobals() : options
|
|
42
|
+
spinner = await createSpinner({ ...spinnerOptions, ...options, text: filter || ignore ? 'protecting' : 'unprotecting' })
|
|
43
|
+
if (interactive) {
|
|
44
|
+
// Check ownership-sensitive removal before changing the filter.
|
|
45
|
+
if (!ignore && current.ignore) settings.removeIgnore()
|
|
46
|
+
if (!filter && current.filter) settings.removeFilter()
|
|
47
|
+
}
|
|
48
|
+
const protectedFiles = []
|
|
49
|
+
let hookWarning
|
|
50
|
+
if (filter) {
|
|
51
|
+
installProtectFilter()
|
|
52
|
+
require('../../lib/helpers/removeLegacyProtectFilter')()
|
|
53
|
+
const { warning } = require('../../lib/helpers/uninstallPrecommitHook')()
|
|
54
|
+
hookWarning = warning
|
|
55
|
+
protectedFiles.push('.env*')
|
|
56
|
+
}
|
|
57
|
+
if (ignore) {
|
|
58
|
+
if (!current || !current.ignore) installProtectIgnore()
|
|
59
|
+
protectedFiles.push('.env.keys*')
|
|
60
|
+
}
|
|
61
|
+
if (interactive) settings.markConfigured()
|
|
62
|
+
if (spinner) spinner.stop()
|
|
63
|
+
if (hookWarning) logger.warn(hookWarning)
|
|
64
|
+
const status = protectedFiles.length === 2 ? 'full' : 'partial'
|
|
65
|
+
if (protectedFiles.length) logger.success(`⛉ protection: ${status} (${protectedFiles.join(', ')})`)
|
|
66
|
+
else logger.success('⛉ protection: none')
|
|
67
|
+
} catch (error) {
|
|
68
|
+
if (spinner) spinner.stop()
|
|
69
|
+
catchAndLog(error)
|
|
70
|
+
process.exitCode = 1
|
|
71
|
+
return { error }
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
module.exports = require('../../lib/events/cli')('protect', protect)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const { logger } = require('../../shared/logger')
|
|
2
|
+
|
|
3
|
+
const Prebuild = require('../../lib/services/prebuild')
|
|
4
|
+
const catchAndLog = require('../../lib/helpers/catchAndLog')
|
|
5
|
+
|
|
6
|
+
async function protectDocker (directory) {
|
|
7
|
+
// debug args
|
|
8
|
+
logger.debug(`directory: ${directory}`)
|
|
9
|
+
|
|
10
|
+
const options = this.opts()
|
|
11
|
+
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
const {
|
|
15
|
+
successMessage,
|
|
16
|
+
warnings
|
|
17
|
+
} = new Prebuild(directory, options).run()
|
|
18
|
+
|
|
19
|
+
for (const warning of warnings) {
|
|
20
|
+
logger.warn(warning.messageWithHelp || warning.message)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
logger.success(successMessage)
|
|
24
|
+
} catch (error) {
|
|
25
|
+
catchAndLog(error)
|
|
26
|
+
return { exitCode: 1, error }
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
module.exports = protectDocker
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
const { once } = require('events')
|
|
2
|
+
const { check, exempt } = require('./protectStdin')
|
|
3
|
+
const { logger } = require('../../shared/logger')
|
|
4
|
+
const createProtectSpinner = require('../../lib/helpers/createProtectSpinner')
|
|
5
|
+
const logProtectedFiles = require('../../lib/helpers/logProtectedFiles')
|
|
6
|
+
|
|
7
|
+
// Git's v2 filter protocol frames every message and blob with pkt-line lengths.
|
|
8
|
+
async function * packets (input) {
|
|
9
|
+
let buffer = Buffer.alloc(0)
|
|
10
|
+
for await (const chunk of input) {
|
|
11
|
+
buffer = Buffer.concat([buffer, chunk])
|
|
12
|
+
while (buffer.length >= 4) {
|
|
13
|
+
const header = buffer.subarray(0, 4).toString('ascii')
|
|
14
|
+
if (!/^[0-9a-fA-F]{4}$/.test(header)) throw new Error('Invalid Git filter packet')
|
|
15
|
+
const length = parseInt(header, 16)
|
|
16
|
+
if (length !== 0 && (length < 4 || length > 65520)) throw new Error('Invalid Git filter packet length')
|
|
17
|
+
if (buffer.length < (length || 4)) break
|
|
18
|
+
const packet = length ? buffer.subarray(4, length) : null
|
|
19
|
+
buffer = buffer.subarray(length || 4)
|
|
20
|
+
yield packet
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (buffer.length) throw new Error('Incomplete Git filter packet')
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
module.exports = async function protectProcess (options = {}) {
|
|
27
|
+
let spinner
|
|
28
|
+
let started = false
|
|
29
|
+
let failed = false
|
|
30
|
+
let errorCount = 0
|
|
31
|
+
let activeRequest = false
|
|
32
|
+
let reported = false
|
|
33
|
+
const checkedFiles = new Set()
|
|
34
|
+
const stop = () => { if (spinner) spinner.stop() }
|
|
35
|
+
const finish = () => {
|
|
36
|
+
stop()
|
|
37
|
+
if (spinner && !failed && !activeRequest && !reported) {
|
|
38
|
+
reported = true
|
|
39
|
+
logProtectedFiles(checkedFiles)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// Git may terminate an idle filter with SIGTERM instead of closing stdin.
|
|
43
|
+
const onExit = code => { if (code === 0 || code === 143) finish() }
|
|
44
|
+
process.once('exit', onExit)
|
|
45
|
+
const reader = packets(process.stdin)
|
|
46
|
+
const write = async data => {
|
|
47
|
+
if (!process.stdout.write(data)) await once(process.stdout, 'drain')
|
|
48
|
+
}
|
|
49
|
+
const packet = async data => {
|
|
50
|
+
if (data === null) return write('0000')
|
|
51
|
+
const bytes = Buffer.isBuffer(data) ? data : Buffer.from(data)
|
|
52
|
+
await write(Buffer.from((bytes.length + 4).toString(16).padStart(4, '0')))
|
|
53
|
+
await write(bytes)
|
|
54
|
+
}
|
|
55
|
+
const list = async (allowEOF = false) => {
|
|
56
|
+
const result = []
|
|
57
|
+
while (true) {
|
|
58
|
+
const item = await reader.next()
|
|
59
|
+
if (item.done) {
|
|
60
|
+
if (allowEOF && !result.length) return null
|
|
61
|
+
throw new Error('Incomplete Git filter request')
|
|
62
|
+
}
|
|
63
|
+
if (item.value === null) return result
|
|
64
|
+
result.push(item.value)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const lines = entries => entries.map(entry => entry.toString('utf8').replace(/\n$/, ''))
|
|
68
|
+
try {
|
|
69
|
+
const hello = lines(await list())
|
|
70
|
+
if (hello[0] !== 'git-filter-client' || !hello.includes('version=2')) throw new Error('Unsupported Git filter handshake')
|
|
71
|
+
await packet('git-filter-server\n')
|
|
72
|
+
await packet('version=2\n')
|
|
73
|
+
await packet(null)
|
|
74
|
+
const capabilities = lines(await list())
|
|
75
|
+
if (!capabilities.includes('capability=clean')) throw new Error('Git filter requires clean capability')
|
|
76
|
+
await packet('capability=clean\n')
|
|
77
|
+
const smudge = capabilities.includes('capability=smudge')
|
|
78
|
+
if (smudge) await packet('capability=smudge\n')
|
|
79
|
+
await packet(null)
|
|
80
|
+
while (true) {
|
|
81
|
+
const headers = await list(true)
|
|
82
|
+
if (headers === null) return { errorCount }
|
|
83
|
+
activeRequest = true
|
|
84
|
+
const fields = new Map(lines(headers).map(line => {
|
|
85
|
+
const index = line.indexOf('=')
|
|
86
|
+
return [line.slice(0, index), line.slice(index + 1)]
|
|
87
|
+
}))
|
|
88
|
+
const command = fields.get('command')
|
|
89
|
+
if ((command !== 'clean' && !(smudge && command === 'smudge')) || !fields.has('pathname')) throw new Error('Invalid Git filter request')
|
|
90
|
+
if (command === 'clean' && !started) {
|
|
91
|
+
started = true
|
|
92
|
+
spinner = await createProtectSpinner(options)
|
|
93
|
+
}
|
|
94
|
+
const content = Buffer.concat(await list())
|
|
95
|
+
// Checkout must remain a byte-for-byte passthrough, even for existing plaintext history.
|
|
96
|
+
if (command === 'clean' && !check(fields.get('pathname'), content, stop)) {
|
|
97
|
+
failed = true
|
|
98
|
+
errorCount++
|
|
99
|
+
await packet('status=error\n')
|
|
100
|
+
await packet(null)
|
|
101
|
+
activeRequest = false
|
|
102
|
+
continue
|
|
103
|
+
}
|
|
104
|
+
await packet('status=success\n')
|
|
105
|
+
await packet(null)
|
|
106
|
+
for (let offset = 0; offset < content.length; offset += 65516) {
|
|
107
|
+
await packet(content.subarray(offset, offset + 65516))
|
|
108
|
+
}
|
|
109
|
+
await packet(null)
|
|
110
|
+
await packet(null)
|
|
111
|
+
if (command === 'clean' && !exempt(fields.get('pathname'))) checkedFiles.add(fields.get('pathname'))
|
|
112
|
+
activeRequest = false
|
|
113
|
+
}
|
|
114
|
+
} catch {
|
|
115
|
+
failed = true
|
|
116
|
+
stop()
|
|
117
|
+
// Never include malformed protocol data: it may contain secret contents.
|
|
118
|
+
logger.error('Git protection filter protocol failed')
|
|
119
|
+
process.exitCode = 1
|
|
120
|
+
process.stdin.destroy()
|
|
121
|
+
return { error: { code: 'GIT_FILTER_PROTOCOL_FAILED' } }
|
|
122
|
+
} finally {
|
|
123
|
+
finish()
|
|
124
|
+
process.removeListener('exit', onExit)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const path = require('path')
|
|
3
|
+
const hasPlaintextSecrets = require('../../lib/helpers/hasPlaintextSecrets')
|
|
4
|
+
const { logger } = require('../../shared/logger')
|
|
5
|
+
const createProtectSpinner = require('../../lib/helpers/createProtectSpinner')
|
|
6
|
+
const logProtectedFiles = require('../../lib/helpers/logProtectedFiles')
|
|
7
|
+
|
|
8
|
+
function exempt (filepath) {
|
|
9
|
+
return ['.env.example', '.env.vault', '.env.x'].includes(path.posix.basename(filepath))
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function fixMessage (filepath, privateKeyFile) {
|
|
13
|
+
if (Array.from(filepath).some(char => char.charCodeAt(0) < 32 || char.charCodeAt(0) === 127)) {
|
|
14
|
+
return privateKeyFile ? 'fix: add this private-key file to .gitignore' : 'fix: encrypt this env file or add it to .gitignore'
|
|
15
|
+
}
|
|
16
|
+
const argument = /^[a-zA-Z0-9_./-]+$/.test(filepath) ? filepath : "'" + filepath.replace(/'/g, "'\\''") + "'"
|
|
17
|
+
return privateKeyFile
|
|
18
|
+
? `fix: run [dotenvx gitignore --pattern ${argument}]`
|
|
19
|
+
: `fix: run [dotenvx encrypt -f ${argument}]`
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function check (filepath, content, beforeError = () => {}) {
|
|
23
|
+
const filename = path.posix.basename(filepath)
|
|
24
|
+
const privateKeyFile = filename.startsWith('.env.keys')
|
|
25
|
+
if (privateKeyFile || (!exempt(filepath) && hasPlaintextSecrets(content.toString('utf8')))) {
|
|
26
|
+
const code = privateKeyFile ? 'PRIVATE_KEY_FILE' : 'PLAINTEXT_ENV'
|
|
27
|
+
const fix = fixMessage(filepath, privateKeyFile)
|
|
28
|
+
const message = privateKeyFile
|
|
29
|
+
? `refusing to stage ${JSON.stringify(filepath)}`
|
|
30
|
+
: `${JSON.stringify(filepath)} contains plaintext secrets`
|
|
31
|
+
beforeError()
|
|
32
|
+
logger.error(`[${code}] ${message}. ${fix}`)
|
|
33
|
+
return false
|
|
34
|
+
}
|
|
35
|
+
return true
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function protectStdin (filepath, options = {}) {
|
|
39
|
+
let spinner
|
|
40
|
+
const stop = () => { if (spinner) spinner.stop() }
|
|
41
|
+
try {
|
|
42
|
+
spinner = await createProtectSpinner(options)
|
|
43
|
+
const content = fs.readFileSync(0)
|
|
44
|
+
if (!check(filepath, content, stop)) {
|
|
45
|
+
process.exitCode = 1
|
|
46
|
+
return
|
|
47
|
+
}
|
|
48
|
+
// stdout is Git's blob content: no logging, normalization, or extra newline.
|
|
49
|
+
process.stdout.write(content)
|
|
50
|
+
stop()
|
|
51
|
+
if (spinner && !exempt(filepath)) logProtectedFiles([filepath])
|
|
52
|
+
} catch (error) {
|
|
53
|
+
stop()
|
|
54
|
+
logger.error(error.message)
|
|
55
|
+
process.exitCode = 1
|
|
56
|
+
return { error }
|
|
57
|
+
} finally {
|
|
58
|
+
stop()
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
module.exports = protectStdin
|
|
63
|
+
module.exports.check = check
|
|
64
|
+
module.exports.exempt = exempt
|
package/src/cli/actions/run.js
CHANGED
|
@@ -95,7 +95,7 @@ async function run () {
|
|
|
95
95
|
logger.error(`ambiguous command due to missing '--' separator. try [dotenvx run -f ${realExample} -- yourcommand]`)
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
|
|
98
|
+
return { exitCode: 1 }
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
try {
|
|
@@ -214,18 +214,17 @@ async function run () {
|
|
|
214
214
|
if (closeProxy) await closeProxy()
|
|
215
215
|
if (spinner) spinner.stop()
|
|
216
216
|
if (error.code === 'PROMPT_CANCELLED') {
|
|
217
|
-
|
|
218
|
-
return
|
|
217
|
+
return { exitCode: 130, error }
|
|
219
218
|
}
|
|
220
219
|
catchAndLog(error)
|
|
221
|
-
|
|
220
|
+
return { exitCode: 1, error }
|
|
222
221
|
}
|
|
223
222
|
|
|
224
223
|
try {
|
|
225
|
-
await executeCommand(commandArgs, commandEnv, sensitiveValues, closeProxy)
|
|
224
|
+
return await executeCommand(commandArgs, commandEnv, sensitiveValues, closeProxy)
|
|
226
225
|
} finally {
|
|
227
226
|
if (closeProxy) await closeProxy()
|
|
228
227
|
}
|
|
229
228
|
}
|
|
230
229
|
|
|
231
|
-
module.exports = run
|
|
230
|
+
module.exports = require('../../lib/events/cli')('run', run)
|
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
|
|
|
@@ -61,14 +61,14 @@ async function validate () {
|
|
|
61
61
|
if (spinner) spinner.stop()
|
|
62
62
|
|
|
63
63
|
if (errorCount > 0) {
|
|
64
|
-
|
|
64
|
+
return { exitCode: 1 }
|
|
65
65
|
} else {
|
|
66
66
|
logger.success(`▣ valid ${sourceSummary}`)
|
|
67
67
|
}
|
|
68
68
|
} catch (error) {
|
|
69
69
|
if (spinner) spinner.stop()
|
|
70
70
|
catchAndLog(error)
|
|
71
|
-
|
|
71
|
+
return { exitCode: 1, error }
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
|
|
@@ -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
|
|
@@ -49,7 +50,7 @@ ext.command('gitignore')
|
|
|
49
50
|
|
|
50
51
|
// dotenvx ext prebuild
|
|
51
52
|
ext.command('prebuild')
|
|
52
|
-
.description('
|
|
53
|
+
.description('deprecated. use [dotenvx protect --docker]')
|
|
53
54
|
.addHelpText('after', help.prebuild)
|
|
54
55
|
.argument('[directory]', 'directory to prevent including .env files from', '.')
|
|
55
56
|
.action(function (...args) {
|
|
@@ -61,9 +62,8 @@ ext.command('precommit')
|
|
|
61
62
|
.description('prevent committing .env files to code')
|
|
62
63
|
.addHelpText('after', help.precommit)
|
|
63
64
|
.argument('[directory]', 'directory to prevent committing .env files from', '.')
|
|
64
|
-
.option('-i, --install', 'install a pre-commit hook
|
|
65
|
-
.option('--
|
|
66
|
-
.addOption(ext.createOption('--clean <path>', 'validate Git filter input from stdin').hideHelp())
|
|
65
|
+
.option('-i, --install', 'install a pre-commit hook')
|
|
66
|
+
.option('--uninstall', 'remove the dotenvx pre-commit hook')
|
|
67
67
|
.action(function (...args) {
|
|
68
68
|
return require('./../actions/ext/precommit').apply(this, args)
|
|
69
69
|
})
|
|
@@ -72,7 +72,7 @@ ext.command('precommit')
|
|
|
72
72
|
ext.command('scan')
|
|
73
73
|
.description('scan for leaked secrets')
|
|
74
74
|
.action(function (...args) {
|
|
75
|
-
return require('./../actions/ext/scan').apply(this, args)
|
|
75
|
+
return commandAction(require('./../actions/ext/scan')).apply(this, args)
|
|
76
76
|
})
|
|
77
77
|
|
|
78
78
|
// override helpInformation to hide dynamic commands
|