@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
|
@@ -5,7 +5,7 @@ const { ignore } = require('@dotenvx/tooling')
|
|
|
5
5
|
|
|
6
6
|
const ls = require('../resolvers/ls')
|
|
7
7
|
const Errors = require('../helpers/errors')
|
|
8
|
-
const
|
|
8
|
+
const hasPlaintextSecrets = require('../helpers/hasPlaintextSecrets')
|
|
9
9
|
|
|
10
10
|
const MISSING_DOCKERIGNORE = '.env.keys' // by default only ignore .env.keys. all other .env* files COULD be included - as long as they are encrypted
|
|
11
11
|
|
|
@@ -53,13 +53,12 @@ class Prebuild {
|
|
|
53
53
|
} else {
|
|
54
54
|
if (file !== '.env.example' && file !== '.env.vault' && file !== '.env.x') {
|
|
55
55
|
const src = fsx.readFileXSync(file)
|
|
56
|
-
const
|
|
56
|
+
const privateKeyFile = path.basename(file).startsWith('.env.keys')
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
if (!encrypted) {
|
|
58
|
+
if (privateKeyFile || hasPlaintextSecrets(src)) {
|
|
60
59
|
let errorMsg = `${file} not encrypted/dockerignored`
|
|
61
60
|
let errorHelp = `fix: [dotenvx encrypt -f ${file}] or [dotenvx gitignore --pattern ${file}]`
|
|
62
|
-
if (
|
|
61
|
+
if (privateKeyFile) {
|
|
63
62
|
errorMsg = `${file} not dockerignored`
|
|
64
63
|
errorHelp = `fix: [dotenvx gitignore --pattern ${file}]`
|
|
65
64
|
}
|
|
@@ -17,14 +17,10 @@ class Precommit {
|
|
|
17
17
|
this.directory = directory
|
|
18
18
|
// options
|
|
19
19
|
this.install = options.install
|
|
20
|
-
this.global = options.global
|
|
21
20
|
this.excludeEnvFile = ['test/**', 'tests/**', 'spec/**', 'specs/**', 'pytest/**', 'test_suite/**']
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
run () {
|
|
25
|
-
if (this.global && !this.install) {
|
|
26
|
-
throw new Error('--global requires --install')
|
|
27
|
-
}
|
|
28
24
|
if (this.install) {
|
|
29
25
|
const {
|
|
30
26
|
successMessage
|
|
@@ -107,6 +103,7 @@ class Precommit {
|
|
|
107
103
|
_filepaths () {
|
|
108
104
|
return ls.sync({
|
|
109
105
|
directory: this.directory,
|
|
106
|
+
envFile: require('../helpers/precommitEnvPatterns'),
|
|
110
107
|
excludeEnvFile: this.excludeEnvFile
|
|
111
108
|
})
|
|
112
109
|
}
|
|
@@ -140,14 +137,7 @@ class Precommit {
|
|
|
140
137
|
}
|
|
141
138
|
|
|
142
139
|
_installPrecommitHook () {
|
|
143
|
-
|
|
144
|
-
const attributesPath = require('../helpers/installPrecommitFilter')(true)
|
|
145
|
-
return { successMessage: `▣ dotenvx required clean filter installed globally [${attributesPath}]` }
|
|
146
|
-
}
|
|
147
|
-
const hookPath = require('../helpers/installPrecommitFilter')()
|
|
148
|
-
const result = new InstallPrecommitHook(hookPath).run()
|
|
149
|
-
result.successMessage += '\n▣ dotenvx required clean filter installed (blocks staging plaintext .env files)'
|
|
150
|
-
return result
|
|
140
|
+
return new InstallPrecommitHook().run()
|
|
151
141
|
}
|
|
152
142
|
}
|
|
153
143
|
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
const fs = require('fs')
|
|
2
|
-
const path = require('path')
|
|
3
|
-
const { sealed } = require('@dotenvx/primitives')
|
|
4
|
-
|
|
5
|
-
function precommitClean (filepath) {
|
|
6
|
-
try {
|
|
7
|
-
const content = fs.readFileSync(0)
|
|
8
|
-
const filename = path.posix.basename(filepath)
|
|
9
|
-
const exempt = ['.env.example', '.env.vault', '.env.x'].includes(filename)
|
|
10
|
-
if (filename.startsWith('.env.keys') || (!exempt && !sealed(content.toString('utf8')))) {
|
|
11
|
-
throw new Error(`refusing to stage ${JSON.stringify(filepath)}: encrypt this env file or add it to .gitignore`)
|
|
12
|
-
}
|
|
13
|
-
// stdout is Git's blob content: no logging, normalization, or extra newline.
|
|
14
|
-
process.stdout.write(content)
|
|
15
|
-
} catch (error) {
|
|
16
|
-
process.stderr.write(`dotenvx: ${error.message}\n`)
|
|
17
|
-
process.exitCode = 1
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
module.exports = precommitClean
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
const fs = require('fs')
|
|
2
|
-
const path = require('path')
|
|
3
|
-
const os = require('os')
|
|
4
|
-
const { execFileSync } = require('child_process')
|
|
5
|
-
|
|
6
|
-
const ATTRIBUTE = '.env* filter=dotenvx'
|
|
7
|
-
|
|
8
|
-
function quote (value) {
|
|
9
|
-
return "'" + value.replace(/'/g, "'\\''") + "'"
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function installPrecommitFilter (global = false) {
|
|
13
|
-
const git = (...args) => execFileSync('git', args, { encoding: 'utf8' }).trim()
|
|
14
|
-
let attributesPath
|
|
15
|
-
if (global) {
|
|
16
|
-
try {
|
|
17
|
-
attributesPath = git('config', '--global', '--includes', '--path', '--get', 'core.attributesFile')
|
|
18
|
-
} catch (error) {
|
|
19
|
-
if (error.status !== 1) throw error
|
|
20
|
-
}
|
|
21
|
-
if (!attributesPath) {
|
|
22
|
-
attributesPath = path.join(process.env.XDG_CONFIG_HOME || path.join(os.homedir(), '.config'), 'git/attributes')
|
|
23
|
-
git('config', '--global', 'core.attributesFile', attributesPath)
|
|
24
|
-
}
|
|
25
|
-
} else {
|
|
26
|
-
attributesPath = git('rev-parse', '--git-path', 'info/attributes')
|
|
27
|
-
}
|
|
28
|
-
const hookPath = global ? null : git('rev-parse', '--git-path', 'hooks/pre-commit')
|
|
29
|
-
const current = fs.existsSync(attributesPath) ? fs.readFileSync(attributesPath, 'utf8') : ''
|
|
30
|
-
// Use the installed executable, including standalone builds. Never download a
|
|
31
|
-
// replacement via npx while Git is handling secret input.
|
|
32
|
-
const executable = process.pkg
|
|
33
|
-
? quote(process.execPath)
|
|
34
|
-
: `${quote(process.execPath)} ${quote(path.resolve(__dirname, '../../cli/dotenvx.js'))}`
|
|
35
|
-
|
|
36
|
-
const scope = global ? '--global' : '--local'
|
|
37
|
-
// Git's filter_buffer_or_fd shell-quotes the filename with sq_quote_buf
|
|
38
|
-
// before substituting %f (convert.c). Keep the placeholder unquoted here.
|
|
39
|
-
git('config', scope, 'filter.dotenvx.clean', `${executable} precommit --clean %f`)
|
|
40
|
-
git('config', scope, 'filter.dotenvx.required', 'true')
|
|
41
|
-
fs.mkdirSync(path.dirname(attributesPath), { recursive: true })
|
|
42
|
-
if (!current.split(/\r?\n/).includes(ATTRIBUTE)) {
|
|
43
|
-
fs.appendFileSync(attributesPath, `${current && !current.endsWith('\n') ? '\n' : ''}${ATTRIBUTE}\n`)
|
|
44
|
-
}
|
|
45
|
-
if (global) return attributesPath
|
|
46
|
-
fs.mkdirSync(path.dirname(hookPath), { recursive: true })
|
|
47
|
-
return hookPath
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
module.exports = installPrecommitFilter
|