@dotenvx/dotenvx 2.38.2 → 3.0.0-beta.2
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/README.md +197 -3314
- package/bin/dotenvx.cjs +34 -0
- package/config.cjs +1 -0
- package/config.d.ts +1 -0
- package/config.mjs +2 -0
- package/index.cjs +141 -0
- package/index.d.ts +66 -0
- package/index.mjs +3 -0
- package/lib/cli.cjs +43 -0
- package/lib/native-package.cjs +21 -0
- package/lib/platforms.cjs +18 -0
- package/{src/lib/helpers/redactOutput.js → lib/redactOutput.cjs} +2 -48
- package/lib/redaction.cjs +64 -0
- package/lib/validateOptions.cjs +57 -0
- package/native.cjs +23 -0
- package/package.json +57 -65
- package/CHANGELOG.md +0 -2733
- package/src/cli/actions/armor/down.js +0 -38
- package/src/cli/actions/armor/invite.js +0 -21
- package/src/cli/actions/armor/move.js +0 -43
- package/src/cli/actions/armor/open.js +0 -28
- package/src/cli/actions/armor/pull.js +0 -38
- package/src/cli/actions/armor/push.js +0 -38
- package/src/cli/actions/armor/status.js +0 -7
- package/src/cli/actions/armor/up.js +0 -38
- package/src/cli/actions/check.js +0 -78
- package/src/cli/actions/curl.js +0 -71
- package/src/cli/actions/decrypt.js +0 -119
- package/src/cli/actions/del.js +0 -54
- package/src/cli/actions/doctor.js +0 -22
- package/src/cli/actions/encrypt.js +0 -104
- package/src/cli/actions/ext/genexample.js +0 -36
- package/src/cli/actions/ext/gitignore.js +0 -106
- package/src/cli/actions/ext/prebuild.js +0 -7
- package/src/cli/actions/ext/precommit.js +0 -38
- package/src/cli/actions/ext/scan.js +0 -33
- package/src/cli/actions/feedback.js +0 -42
- package/src/cli/actions/get.js +0 -128
- package/src/cli/actions/init.js +0 -67
- package/src/cli/actions/keychain/down.js +0 -30
- package/src/cli/actions/keychain/pull.js +0 -30
- package/src/cli/actions/keychain/push.js +0 -30
- package/src/cli/actions/keychain/up.js +0 -30
- package/src/cli/actions/keypair.js +0 -84
- package/src/cli/actions/login.js +0 -64
- package/src/cli/actions/logout.js +0 -37
- package/src/cli/actions/ls.js +0 -76
- package/src/cli/actions/policy.js +0 -14
- package/src/cli/actions/primitivesCheck.js +0 -32
- package/src/cli/actions/primitivesProfile.js +0 -15
- package/src/cli/actions/primitivesRedact.js +0 -19
- package/src/cli/actions/protect.js +0 -75
- package/src/cli/actions/protectDocker.js +0 -30
- package/src/cli/actions/protectProcess.js +0 -126
- package/src/cli/actions/protectStdin.js +0 -80
- package/src/cli/actions/run.js +0 -203
- package/src/cli/actions/set.js +0 -103
- package/src/cli/actions/settings/device.js +0 -23
- package/src/cli/actions/settings/hostname.js +0 -20
- package/src/cli/actions/settings/off.js +0 -14
- package/src/cli/actions/settings/on.js +0 -14
- package/src/cli/actions/settings/path.js +0 -20
- package/src/cli/actions/settings/token.js +0 -23
- package/src/cli/actions/settings/username.js +0 -20
- package/src/cli/actions/update.js +0 -15
- package/src/cli/commandAction.js +0 -16
- package/src/cli/commands/armor.js +0 -129
- package/src/cli/commands/custody.js +0 -45
- package/src/cli/commands/ext.js +0 -88
- package/src/cli/commands/fileOptions.js +0 -22
- package/src/cli/commands/native.js +0 -54
- package/src/cli/commands/primitives.js +0 -73
- package/src/cli/commands/settings.js +0 -63
- package/src/cli/dotenvx.js +0 -443
- package/src/cli/help.js +0 -179
- package/src/db/device.js +0 -67
- package/src/db/session.js +0 -330
- package/src/lib/api/getAccount.js +0 -32
- package/src/lib/api/getConnectionResources.js +0 -21
- package/src/lib/api/getTeamConnections.js +0 -27
- package/src/lib/api/getTeamServices.js +0 -23
- package/src/lib/api/getTeams.js +0 -28
- package/src/lib/api/postArmorDown.js +0 -48
- package/src/lib/api/postArmorMove.js +0 -48
- package/src/lib/api/postArmorPull.js +0 -48
- package/src/lib/api/postArmorPush.js +0 -48
- package/src/lib/api/postArmorUp.js +0 -53
- package/src/lib/api/postConnectionKeypair.js +0 -23
- package/src/lib/api/postFeedback.js +0 -31
- package/src/lib/api/postLogout.js +0 -34
- package/src/lib/api/postOauthDeviceCode.js +0 -38
- package/src/lib/api/postOauthToken.js +0 -35
- package/src/lib/api/postTeamInvitation.js +0 -28
- package/src/lib/api/teamConnectionSetup.js +0 -31
- package/src/lib/config.d.ts +0 -1
- package/src/lib/config.js +0 -1
- package/src/lib/conventions/environment.js +0 -27
- package/src/lib/conventions/filepaths.js +0 -9
- package/src/lib/conventions/keynames.js +0 -38
- package/src/lib/custodians/index.js +0 -75
- package/src/lib/custodians/local/bitwarden.js +0 -165
- package/src/lib/custodians/local/file.js +0 -18
- package/src/lib/custodians/local/native/backend.js +0 -56
- package/src/lib/custodians/local/native/index.js +0 -28
- package/src/lib/custodians/local/native/store.js +0 -24
- package/src/lib/custodians/local/onepassword.js +0 -149
- package/src/lib/custodians/managed/armor/index.js +0 -14
- package/src/lib/custodians/managed/armor/store.js +0 -48
- package/src/lib/custodians/resolveLocalKey.js +0 -67
- package/src/lib/decryptors/armor/index.js +0 -23
- package/src/lib/decryptors/decryptor-worker.js +0 -6
- package/src/lib/decryptors/index.js +0 -69
- package/src/lib/envfile/discovery/discoverEnvFiles.js +0 -29
- package/src/lib/envfile/discovery/extractEnvKeys.js +0 -173
- package/src/lib/envfile/discovery/scanSource.js +0 -79
- package/src/lib/envfile/parsing/formatEnvfileSyntaxError.js +0 -24
- package/src/lib/envfile/parsing/readEnvfile.js +0 -43
- package/src/lib/envfile/parsing/resolveEnvfilePath.js +0 -5
- package/src/lib/envfile/rendering/normalizeEnvfile.js +0 -53
- package/src/lib/envfile/rendering/previewEnvfile.js +0 -43
- package/src/lib/envfile/rendering/renderEnvfile.js +0 -30
- package/src/lib/envfile/validation/diagnosticLocation.js +0 -29
- package/src/lib/envfile/validation/protectEnvfile.js +0 -40
- package/src/lib/envfile/validation/validateEnvfile.js +0 -14
- package/src/lib/events/backends/armor.js +0 -31
- package/src/lib/events/background.js +0 -59
- package/src/lib/events/catalog.js +0 -14
- package/src/lib/events/cli.js +0 -40
- package/src/lib/events/delivery.js +0 -89
- package/src/lib/events/index.js +0 -73
- package/src/lib/events/metadata.js +0 -25
- package/src/lib/events/sdk.js +0 -44
- package/src/lib/events/worker.js +0 -29
- package/src/lib/events/workerEnvironment.js +0 -14
- package/src/lib/helpers/armoredKeyDisplay.js +0 -10
- package/src/lib/helpers/arrayToTree.js +0 -27
- package/src/lib/helpers/buildApiError.js +0 -19
- package/src/lib/helpers/buildCommandEnvs.js +0 -40
- package/src/lib/helpers/buildConfigEnvs.js +0 -13
- package/src/lib/helpers/buildEnvs.js +0 -24
- package/src/lib/helpers/buildOauthError.js +0 -14
- package/src/lib/helpers/canonicalEnvFilename.js +0 -13
- package/src/lib/helpers/catchAndLog.js +0 -16
- package/src/lib/helpers/checklist.js +0 -50
- package/src/lib/helpers/chomp.js +0 -5
- package/src/lib/helpers/colorDepth.js +0 -23
- package/src/lib/helpers/conventions.js +0 -28
- package/src/lib/helpers/createElapsedStatus.js +0 -17
- package/src/lib/helpers/createProtectSpinner.js +0 -13
- package/src/lib/helpers/createSpinner.js +0 -40
- package/src/lib/helpers/cryptography/decryptKeyValue.js +0 -50
- package/src/lib/helpers/cryptography/index.js +0 -7
- package/src/lib/helpers/cryptography/isDotenvPublicKey.js +0 -7
- package/src/lib/helpers/cryptography/isPlainKey.js +0 -7
- package/src/lib/helpers/cryptography/mutateKeysSrc.js +0 -22
- package/src/lib/helpers/cryptography/mutateSrc.js +0 -24
- package/src/lib/helpers/custodySelect.js +0 -25
- package/src/lib/helpers/decryptDeviceValue.js +0 -7
- package/src/lib/helpers/detectEncoding.js +0 -22
- package/src/lib/helpers/detectEncodingSync.js +0 -22
- package/src/lib/helpers/dotenvOptionPaths.js +0 -25
- package/src/lib/helpers/dotenvPrivateKeyNames.js +0 -7
- package/src/lib/helpers/enclavedHint.js +0 -11
- package/src/lib/helpers/encryptDeviceValue.js +0 -7
- package/src/lib/helpers/envResolution/determine.js +0 -49
- package/src/lib/helpers/envResolution/index.js +0 -8
- package/src/lib/helpers/errors.js +0 -374
- package/src/lib/helpers/escape.js +0 -6
- package/src/lib/helpers/execute.js +0 -12
- package/src/lib/helpers/executeCommand.js +0 -208
- package/src/lib/helpers/executeDynamic.js +0 -86
- package/src/lib/helpers/executeExtension.js +0 -39
- package/src/lib/helpers/filterKeys.js +0 -15
- package/src/lib/helpers/findEnvFiles.js +0 -25
- package/src/lib/helpers/formatCode.js +0 -11
- package/src/lib/helpers/fsx.js +0 -110
- package/src/lib/helpers/guessPrivateKeyFilename.js +0 -15
- package/src/lib/helpers/hasPlaintextSecrets.js +0 -7
- package/src/lib/helpers/http.js +0 -14
- package/src/lib/helpers/installPrecommitHook.js +0 -82
- package/src/lib/helpers/installProtectFilter.js +0 -57
- package/src/lib/helpers/installProtectIgnore.js +0 -27
- package/src/lib/helpers/isPublicKey.js +0 -3
- package/src/lib/helpers/isTeamRequiredError.js +0 -10
- package/src/lib/helpers/jsonToEnv.js +0 -7
- package/src/lib/helpers/keypairMetadata.js +0 -90
- package/src/lib/helpers/kits/sample.js +0 -5
- package/src/lib/helpers/linuxSecretService.js +0 -52
- package/src/lib/helpers/listenForOpenKey.js +0 -46
- package/src/lib/helpers/logProtectedFiles.js +0 -9
- package/src/lib/helpers/logSetSummary.js +0 -21
- package/src/lib/helpers/macosKeychain.js +0 -52
- package/src/lib/helpers/mask.js +0 -22
- package/src/lib/helpers/maskEnvSrc.js +0 -15
- package/src/lib/helpers/maskProcessedEnvs.js +0 -29
- package/src/lib/helpers/matchesStoredKey.js +0 -5
- package/src/lib/helpers/nativeStoreError.js +0 -10
- package/src/lib/helpers/normalizeDotenvConfigConvention.js +0 -13
- package/src/lib/helpers/normalizeDotenvConfigIgnore.js +0 -18
- package/src/lib/helpers/normalizeDotenvConfigPath.js +0 -14
- package/src/lib/helpers/normalizeDotenvConfigQuiet.js +0 -13
- package/src/lib/helpers/normalizeToken.js +0 -5
- package/src/lib/helpers/openUrl.js +0 -7
- package/src/lib/helpers/packageJson.js +0 -3
- package/src/lib/helpers/parseWithDecryptor.js +0 -115
- package/src/lib/helpers/plaintextKeys.js +0 -9
- package/src/lib/helpers/precommitEnvPatterns.js +0 -1
- package/src/lib/helpers/prependPublicKey.js +0 -17
- package/src/lib/helpers/preserveShebang.js +0 -16
- package/src/lib/helpers/prompts.js +0 -169
- package/src/lib/helpers/protectSettings.js +0 -64
- package/src/lib/helpers/ptyCommand.js +0 -27
- package/src/lib/helpers/readEnvKey.js +0 -32
- package/src/lib/helpers/redact.js +0 -9
- package/src/lib/helpers/redactProcessOutput.js +0 -58
- package/src/lib/helpers/redactedValues.js +0 -29
- package/src/lib/helpers/removeDynamicHelpSection.js +0 -21
- package/src/lib/helpers/removeEnvKey.js +0 -51
- package/src/lib/helpers/removeLegacyProtectFilter.js +0 -43
- package/src/lib/helpers/removeOptionsHelpParts.js +0 -59
- package/src/lib/helpers/resolveBitwardenPassword.js +0 -165
- package/src/lib/helpers/resolveDirectoryFilepath.js +0 -16
- package/src/lib/helpers/resolveEnvKeysFile.js +0 -11
- package/src/lib/helpers/resolveHome.js +0 -12
- package/src/lib/helpers/resolveOnePassword.js +0 -82
- package/src/lib/helpers/sanitizeCommandForMetadata.js +0 -64
- package/src/lib/helpers/selectConnection.js +0 -51
- package/src/lib/helpers/selectConnectionResource.js +0 -41
- package/src/lib/helpers/selectEnvfileEnvs.js +0 -29
- package/src/lib/helpers/selectKeyStorage.js +0 -140
- package/src/lib/helpers/statusReporter.js +0 -8
- package/src/lib/helpers/storeKeyStorage.js +0 -39
- package/src/lib/helpers/teamChoicesFromMeta.js +0 -8
- package/src/lib/helpers/truncate.js +0 -10
- package/src/lib/helpers/uninstallPrecommitHook.js +0 -67
- package/src/lib/helpers/upsertEnvKey.js +0 -62
- package/src/lib/helpers/windowsCredentialManager.js +0 -166
- package/src/lib/main.d.ts +0 -509
- package/src/lib/main.js +0 -468
- package/src/lib/providers/index.js +0 -86
- package/src/lib/providers/native/index.js +0 -2
- package/src/lib/resolvers/envs.js +0 -416
- package/src/lib/resolvers/get.js +0 -87
- package/src/lib/resolvers/keypair.js +0 -135
- package/src/lib/resolvers/ls.js +0 -69
- package/src/lib/services/armorDown.js +0 -73
- package/src/lib/services/armorInvite.js +0 -36
- package/src/lib/services/armorMove.js +0 -55
- package/src/lib/services/armorOpen.js +0 -26
- package/src/lib/services/armorPull.js +0 -73
- package/src/lib/services/armorPush.js +0 -66
- package/src/lib/services/armorUp.js +0 -71
- package/src/lib/services/custodyTransfer.js +0 -50
- package/src/lib/services/doctor.js +0 -93
- package/src/lib/services/genexample.js +0 -112
- package/src/lib/services/init.js +0 -83
- package/src/lib/services/keychainDown.js +0 -60
- package/src/lib/services/keychainPull.js +0 -46
- package/src/lib/services/keychainPush.js +0 -51
- package/src/lib/services/keychainUp.js +0 -72
- package/src/lib/services/login.js +0 -51
- package/src/lib/services/logout.js +0 -26
- package/src/lib/services/prebuild.js +0 -91
- package/src/lib/services/precommit.js +0 -144
- package/src/lib/services/validate.js +0 -57
- package/src/lib/transforms/decrypt.js +0 -98
- package/src/lib/transforms/del.js +0 -58
- package/src/lib/transforms/encrypt.js +0 -164
- package/src/lib/transforms/set.js +0 -144
- package/src/shared/colors.js +0 -67
- package/src/shared/logger.js +0 -148
package/src/lib/services/init.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
const fs = require('node:fs')
|
|
2
|
-
const fsx = require('../helpers/fsx')
|
|
3
|
-
const path = require('node:path')
|
|
4
|
-
const { scan, encrypted } = require('@dotenvx/primitives')
|
|
5
|
-
|
|
6
|
-
const normalizeEnvfile = require('../envfile/rendering/normalizeEnvfile')
|
|
7
|
-
const renderEnvfile = require('../envfile/rendering/renderEnvfile')
|
|
8
|
-
const isPublicKey = require('../helpers/isPublicKey')
|
|
9
|
-
|
|
10
|
-
function declaration (name) {
|
|
11
|
-
const item = { name }
|
|
12
|
-
if (/(^|_)port$/i.test(name)) item.type = 'port'
|
|
13
|
-
if (/(^|_)url$/i.test(name)) item.type = 'url'
|
|
14
|
-
if (isPublicKey(name)) item.redacted = false
|
|
15
|
-
return item
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
module.exports = function init ({ directory = process.cwd(), envFile, envFiles, sourceKeys = [], overwrite = false, stdout = false, onFile = () => {} } = {}) {
|
|
19
|
-
const target = path.resolve(directory, 'Envfile')
|
|
20
|
-
const existing = stdout ? undefined : fs.lstatSync(target, { throwIfNoEntry: false })
|
|
21
|
-
if (existing && !overwrite) return { created: false }
|
|
22
|
-
if (existing && !existing.isFile()) throw new Error(`Cannot replace Envfile: expected a regular file (${target})`)
|
|
23
|
-
const seen = new Set()
|
|
24
|
-
|
|
25
|
-
const sources = []
|
|
26
|
-
const names = new Set()
|
|
27
|
-
const files = []
|
|
28
|
-
const candidates = envFiles || (envFile ? [envFile] : ['.env.example', '.env'])
|
|
29
|
-
const relativeFilename = candidate => path.relative(path.resolve(directory), path.resolve(directory, candidate)).split(path.sep).join('/')
|
|
30
|
-
for (const candidate of candidates) {
|
|
31
|
-
const resolved = path.resolve(directory, candidate)
|
|
32
|
-
if (seen.has(resolved)) continue
|
|
33
|
-
seen.add(resolved)
|
|
34
|
-
let src
|
|
35
|
-
try {
|
|
36
|
-
src = fs.readFileSync(path.resolve(directory, candidate), 'utf8')
|
|
37
|
-
} catch (error) {
|
|
38
|
-
if (envFiles || envFile || error.code !== 'ENOENT') throw error
|
|
39
|
-
continue
|
|
40
|
-
}
|
|
41
|
-
onFile(candidate)
|
|
42
|
-
sources.push(candidate)
|
|
43
|
-
// scan preserves every assignment as an array, without decrypting or expanding.
|
|
44
|
-
const allEntries = Object.entries(scan(src).parsed)
|
|
45
|
-
const entries = allEntries.filter(([key]) => !key.startsWith('DOTENV_PUBLIC_KEY'))
|
|
46
|
-
for (const [key] of entries) {
|
|
47
|
-
if (!/^DOTENV_PRIVATE_KEY(?:_|$)/.test(key)) names.add(key)
|
|
48
|
-
}
|
|
49
|
-
const hasEncryptedValues = entries.some(([key, values]) => !/^DOTENV_PRIVATE_KEY(?:_|$)/.test(key) && values.some(value => encrypted(value)))
|
|
50
|
-
files.push({
|
|
51
|
-
filename: relativeFilename(candidate),
|
|
52
|
-
hasValues: entries.length > 0,
|
|
53
|
-
declarations: entries.filter(([key]) => !/^DOTENV_PRIVATE_KEY(?:_|$)/.test(key)).map(([key, values]) => ({
|
|
54
|
-
...declaration(key), encrypted: values.some(value => encrypted(value)) || (!hasEncryptedValues && !key.endsWith('_PLAIN'))
|
|
55
|
-
}))
|
|
56
|
-
})
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const inputCount = names.size
|
|
60
|
-
const codeDeclarations = sourceKeys.filter(key => !/^DOTENV_(?:PUBLIC|PRIVATE)_KEY(?:_|$)/.test(key)).map(declaration)
|
|
61
|
-
for (const item of codeDeclarations) names.add(item.name)
|
|
62
|
-
const addedFromSource = names.size - inputCount
|
|
63
|
-
const keys = [...names]
|
|
64
|
-
const invalid = keys.filter(key => !/^[A-Za-z_][A-Za-z0-9_]*$/.test(key))
|
|
65
|
-
if (invalid.length) throw new Error(`Unsupported Envfile variable names: ${invalid.join(', ')}`)
|
|
66
|
-
|
|
67
|
-
const document = normalizeEnvfile({ files, codeDeclarations })
|
|
68
|
-
const content = renderEnvfile(document)
|
|
69
|
-
if (stdout) return { created: false, content }
|
|
70
|
-
try {
|
|
71
|
-
if (overwrite) {
|
|
72
|
-
const stat = fs.lstatSync(target, { throwIfNoEntry: false })
|
|
73
|
-
if (stat && !stat.isFile()) throw new Error(`Cannot replace Envfile: expected a regular file (${target})`)
|
|
74
|
-
fsx.writeFileXSync(target, content, { followSymlinks: false })
|
|
75
|
-
} else {
|
|
76
|
-
fs.writeFileSync(target, content, { flag: 'wx' })
|
|
77
|
-
}
|
|
78
|
-
} catch (error) {
|
|
79
|
-
if (error.code === 'EEXIST') return { created: false }
|
|
80
|
-
throw error
|
|
81
|
-
}
|
|
82
|
-
return { created: true, replaced: Boolean(existing), source: sources.join(', '), count: keys.length, addedFromSource }
|
|
83
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
const keynames = require('../conventions/keynames')
|
|
2
|
-
const readEnvKey = require('../helpers/readEnvKey')
|
|
3
|
-
const upsertEnvKey = require('../helpers/upsertEnvKey')
|
|
4
|
-
const armoredKeyDisplay = require('../helpers/armoredKeyDisplay')
|
|
5
|
-
const nativeProvider = require('../providers/native')
|
|
6
|
-
|
|
7
|
-
class KeychainDown {
|
|
8
|
-
constructor (envFile = '.env', envKeysFile = '.env.keys') {
|
|
9
|
-
this.envFile = envFile
|
|
10
|
-
this.envKeysFile = envKeysFile
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
run () {
|
|
14
|
-
const envFile = this.envFile
|
|
15
|
-
const envKeysFile = this.envKeysFile
|
|
16
|
-
|
|
17
|
-
const {
|
|
18
|
-
publicKeyName,
|
|
19
|
-
privateKeyName
|
|
20
|
-
} = keynames(envFile)
|
|
21
|
-
|
|
22
|
-
const publicKey = readEnvKey(publicKeyName, envFile, { strict: true, ignore: ['MISSING_PRIVATE_KEY'] })
|
|
23
|
-
let privateKey
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
privateKey = nativeProvider.get(publicKey)
|
|
27
|
-
if (!privateKey) {
|
|
28
|
-
const secretStore = process.platform === 'win32'
|
|
29
|
-
? 'Windows Credential Manager'
|
|
30
|
-
: process.platform === 'linux' ? 'Linux Secret Service' : 'macOS Keychain'
|
|
31
|
-
throw new Error(`[NOT_FOUND] private key not found in ${secretStore} (${armoredKeyDisplay(publicKey)}). fix: [dotenvx native up]`)
|
|
32
|
-
}
|
|
33
|
-
} catch (error) {
|
|
34
|
-
privateKey = readEnvKey(privateKeyName, envKeysFile, { strict: false })
|
|
35
|
-
|
|
36
|
-
if (privateKey) {
|
|
37
|
-
return {
|
|
38
|
-
changed: false,
|
|
39
|
-
privateKeyName,
|
|
40
|
-
privateKeyValue: privateKey,
|
|
41
|
-
publicKeyValue: publicKey
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
throw error
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
upsertEnvKey(privateKeyName, privateKey, envKeysFile)
|
|
49
|
-
nativeProvider.delete(publicKey)
|
|
50
|
-
|
|
51
|
-
return {
|
|
52
|
-
changed: true,
|
|
53
|
-
privateKeyName,
|
|
54
|
-
privateKeyValue: privateKey,
|
|
55
|
-
publicKeyValue: publicKey
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
module.exports = KeychainDown
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
const keynames = require('../conventions/keynames')
|
|
2
|
-
const readEnvKey = require('../helpers/readEnvKey')
|
|
3
|
-
const upsertEnvKey = require('../helpers/upsertEnvKey')
|
|
4
|
-
const armoredKeyDisplay = require('../helpers/armoredKeyDisplay')
|
|
5
|
-
const nativeProvider = require('../providers/native')
|
|
6
|
-
|
|
7
|
-
class KeychainPull {
|
|
8
|
-
constructor (envFile = '.env', envKeysFile = '.env.keys') {
|
|
9
|
-
this.envFile = envFile
|
|
10
|
-
this.envKeysFile = envKeysFile
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
run () {
|
|
14
|
-
const envFile = this.envFile
|
|
15
|
-
const envKeysFile = this.envKeysFile
|
|
16
|
-
|
|
17
|
-
const {
|
|
18
|
-
publicKeyName,
|
|
19
|
-
privateKeyName
|
|
20
|
-
} = keynames(envFile)
|
|
21
|
-
|
|
22
|
-
const publicKey = readEnvKey(publicKeyName, envFile, { strict: true, ignore: ['MISSING_PRIVATE_KEY'] })
|
|
23
|
-
let privateKey
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
privateKey = nativeProvider.get(publicKey)
|
|
27
|
-
if (!privateKey) throw new Error('not found')
|
|
28
|
-
} catch {
|
|
29
|
-
const secretStore = process.platform === 'win32'
|
|
30
|
-
? 'Windows Credential Manager'
|
|
31
|
-
: process.platform === 'linux' ? 'Linux Secret Service' : 'macOS Keychain'
|
|
32
|
-
throw new Error(`[NOT_FOUND] private key not found in ${secretStore} (${armoredKeyDisplay(publicKey)}). fix: [dotenvx native up]`)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const result = upsertEnvKey(privateKeyName, privateKey, envKeysFile)
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
changed: result.changed,
|
|
39
|
-
privateKeyName,
|
|
40
|
-
privateKeyValue: privateKey,
|
|
41
|
-
publicKeyValue: publicKey
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
module.exports = KeychainPull
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
const keynames = require('../conventions/keynames')
|
|
2
|
-
const readEnvKey = require('../helpers/readEnvKey')
|
|
3
|
-
const armoredKeyDisplay = require('../helpers/armoredKeyDisplay')
|
|
4
|
-
const nativeProvider = require('../providers/native')
|
|
5
|
-
|
|
6
|
-
class KeychainPush {
|
|
7
|
-
constructor (envFile = '.env', envKeysFile = '.env.keys') {
|
|
8
|
-
this.envFile = envFile
|
|
9
|
-
this.envKeysFile = envKeysFile
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
run () {
|
|
13
|
-
const envFile = this.envFile
|
|
14
|
-
const envKeysFile = this.envKeysFile
|
|
15
|
-
|
|
16
|
-
const {
|
|
17
|
-
publicKeyName,
|
|
18
|
-
privateKeyName
|
|
19
|
-
} = keynames(envFile)
|
|
20
|
-
|
|
21
|
-
const publicKey = readEnvKey(publicKeyName, envFile, { strict: true, ignore: ['MISSING_PRIVATE_KEY'] })
|
|
22
|
-
const privateKey = readEnvKey(privateKeyName, envKeysFile, { strict: true })
|
|
23
|
-
const label = `dotenvx (${armoredKeyDisplay(publicKey)})`
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
const existingPrivateKey = nativeProvider.get(publicKey)
|
|
27
|
-
|
|
28
|
-
if (existingPrivateKey === privateKey) {
|
|
29
|
-
return {
|
|
30
|
-
changed: false,
|
|
31
|
-
label,
|
|
32
|
-
privateKeyName,
|
|
33
|
-
privateKeyValue: privateKey,
|
|
34
|
-
publicKeyValue: publicKey
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
} catch {}
|
|
38
|
-
|
|
39
|
-
nativeProvider.set(publicKey, privateKey, label)
|
|
40
|
-
|
|
41
|
-
return {
|
|
42
|
-
changed: true,
|
|
43
|
-
label,
|
|
44
|
-
privateKeyName,
|
|
45
|
-
privateKeyValue: privateKey,
|
|
46
|
-
publicKeyValue: publicKey
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
module.exports = KeychainPush
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
const keynames = require('../conventions/keynames')
|
|
2
|
-
const readEnvKey = require('../helpers/readEnvKey')
|
|
3
|
-
const removeEnvKey = require('../helpers/removeEnvKey')
|
|
4
|
-
const armoredKeyDisplay = require('../helpers/armoredKeyDisplay')
|
|
5
|
-
const nativeProvider = require('../providers/native')
|
|
6
|
-
|
|
7
|
-
class KeychainUp {
|
|
8
|
-
constructor (envFile = '.env', envKeysFile = '.env.keys') {
|
|
9
|
-
this.envFile = envFile
|
|
10
|
-
this.envKeysFile = envKeysFile
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
run () {
|
|
14
|
-
const envFile = this.envFile
|
|
15
|
-
const envKeysFile = this.envKeysFile
|
|
16
|
-
|
|
17
|
-
const {
|
|
18
|
-
publicKeyName,
|
|
19
|
-
privateKeyName
|
|
20
|
-
} = keynames(envFile)
|
|
21
|
-
|
|
22
|
-
const publicKey = readEnvKey(publicKeyName, envFile, { strict: true, ignore: ['MISSING_PRIVATE_KEY'] })
|
|
23
|
-
const label = `dotenvx (${armoredKeyDisplay(publicKey)})`
|
|
24
|
-
let existingPrivateKey
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
existingPrivateKey = nativeProvider.get(publicKey)
|
|
28
|
-
} catch {}
|
|
29
|
-
|
|
30
|
-
const privateKey = readEnvKey(privateKeyName, envKeysFile, { strict: !existingPrivateKey })
|
|
31
|
-
|
|
32
|
-
if (existingPrivateKey) {
|
|
33
|
-
if (!privateKey) {
|
|
34
|
-
return {
|
|
35
|
-
changed: false,
|
|
36
|
-
label,
|
|
37
|
-
privateKeyName,
|
|
38
|
-
privateKeyValue: existingPrivateKey,
|
|
39
|
-
publicKeyValue: publicKey
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (existingPrivateKey === privateKey) {
|
|
44
|
-
const result = removeEnvKey(privateKeyName, envKeysFile)
|
|
45
|
-
|
|
46
|
-
return {
|
|
47
|
-
changed: result.changed,
|
|
48
|
-
label,
|
|
49
|
-
privateKeyName,
|
|
50
|
-
privateKeyValue: privateKey,
|
|
51
|
-
publicKeyValue: publicKey
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
nativeProvider.set(publicKey, privateKey, label)
|
|
57
|
-
if (nativeProvider.get(publicKey) !== privateKey) {
|
|
58
|
-
throw new Error('could not verify private key in OS secret store; .env.keys unchanged')
|
|
59
|
-
}
|
|
60
|
-
removeEnvKey(privateKeyName, envKeysFile)
|
|
61
|
-
|
|
62
|
-
return {
|
|
63
|
-
changed: true,
|
|
64
|
-
label,
|
|
65
|
-
privateKeyName,
|
|
66
|
-
privateKeyValue: privateKey,
|
|
67
|
-
publicKeyValue: publicKey
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
module.exports = KeychainUp
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
const Session = require('../../db/session')
|
|
2
|
-
const PostOauthDeviceCode = require('../api/postOauthDeviceCode')
|
|
3
|
-
const PostOauthToken = require('../api/postOauthToken')
|
|
4
|
-
|
|
5
|
-
class Login {
|
|
6
|
-
constructor (hostname) {
|
|
7
|
-
this.hostname = hostname
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
async run () {
|
|
11
|
-
const sesh = new Session()
|
|
12
|
-
const devicePublicKey = sesh.devicePublicKey()
|
|
13
|
-
const systemInformation = await sesh.systemInformation()
|
|
14
|
-
|
|
15
|
-
const data = await new PostOauthDeviceCode(this.hostname, devicePublicKey, systemInformation).run()
|
|
16
|
-
|
|
17
|
-
return {
|
|
18
|
-
deviceCode: data.device_code,
|
|
19
|
-
userCode: data.user_code,
|
|
20
|
-
verificationUri: data.verification_uri,
|
|
21
|
-
verificationUriComplete: data.verification_uri_complete,
|
|
22
|
-
interval: data.interval
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
async poll (deviceCode, interval) {
|
|
27
|
-
const sesh = new Session()
|
|
28
|
-
|
|
29
|
-
while (true) {
|
|
30
|
-
try {
|
|
31
|
-
const data = await new PostOauthToken(this.hostname, deviceCode).run()
|
|
32
|
-
|
|
33
|
-
if (data.access_token) {
|
|
34
|
-
sesh.login(this.hostname, data.id, data.username, data.access_token)
|
|
35
|
-
await sesh.notifyUpdate()
|
|
36
|
-
return data
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
await new Promise(resolve => setTimeout(resolve, interval * 1000))
|
|
40
|
-
} catch (error) {
|
|
41
|
-
if (error.code === 'authorization_pending') {
|
|
42
|
-
await new Promise(resolve => setTimeout(resolve, (interval + 1) * 1000))
|
|
43
|
-
} else {
|
|
44
|
-
throw error
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
module.exports = Login
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
const Session = require('../../db/session')
|
|
2
|
-
const PostLogout = require('../api/postLogout')
|
|
3
|
-
|
|
4
|
-
class Logout {
|
|
5
|
-
constructor (hostname) {
|
|
6
|
-
this.hostname = hostname
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
async run () {
|
|
10
|
-
const sesh = new Session()
|
|
11
|
-
const token = sesh.token()
|
|
12
|
-
|
|
13
|
-
const data = await new PostLogout(this.hostname, token).run()
|
|
14
|
-
|
|
15
|
-
const id = data.id
|
|
16
|
-
const username = data.username
|
|
17
|
-
const accessToken = data.access_token
|
|
18
|
-
const settingsDevicesUrl = `${this.hostname}/settings/devices`
|
|
19
|
-
|
|
20
|
-
sesh.logout(this.hostname, id, accessToken)
|
|
21
|
-
|
|
22
|
-
return { username, accessToken, settingsDevicesUrl }
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
module.exports = Logout
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
/* istanbul ignore file */
|
|
2
|
-
const fsx = require('./../helpers/fsx')
|
|
3
|
-
const path = require('path')
|
|
4
|
-
const { ignore } = require('@dotenvx/tooling')
|
|
5
|
-
|
|
6
|
-
const ls = require('../resolvers/ls')
|
|
7
|
-
const Errors = require('../helpers/errors')
|
|
8
|
-
const hasPlaintextSecrets = require('../helpers/hasPlaintextSecrets')
|
|
9
|
-
|
|
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
|
-
|
|
12
|
-
class Prebuild {
|
|
13
|
-
constructor (directory = './') {
|
|
14
|
-
// args
|
|
15
|
-
this.directory = directory
|
|
16
|
-
|
|
17
|
-
this.excludeEnvFile = ['test/**', 'tests/**', 'spec/**', 'specs/**', 'pytest/**', 'test_suite/**']
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
run () {
|
|
21
|
-
let count = 0
|
|
22
|
-
const warnings = []
|
|
23
|
-
let dockerignore = MISSING_DOCKERIGNORE
|
|
24
|
-
|
|
25
|
-
// 1. check for .dockerignore file
|
|
26
|
-
if (!fsx.existsSync('.dockerignore')) {
|
|
27
|
-
const warning = new Errors({
|
|
28
|
-
message: '.dockerignore missing',
|
|
29
|
-
help: 'fix: [touch .dockerignore]'
|
|
30
|
-
}).custom()
|
|
31
|
-
warnings.push(warning)
|
|
32
|
-
} else {
|
|
33
|
-
dockerignore = fsx.readFileXSync('.dockerignore')
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// 2. check .env* files against .dockerignore file
|
|
37
|
-
const ig = ignore().add(dockerignore)
|
|
38
|
-
const dotenvFiles = this._filepaths()
|
|
39
|
-
dotenvFiles.forEach(_file => {
|
|
40
|
-
count += 1
|
|
41
|
-
|
|
42
|
-
const file = path.join(this.directory, _file) // to handle when directory argument passed
|
|
43
|
-
|
|
44
|
-
// check if that file is being ignored
|
|
45
|
-
if (ig.ignores(file)) {
|
|
46
|
-
if (file === '.env.example' || file === '.env.vault' || file === '.env.x') {
|
|
47
|
-
const warning = new Errors({
|
|
48
|
-
message: `${file} ignored (should not be)`,
|
|
49
|
-
help: `fix: [dotenvx gitignore --pattern !${file}]`
|
|
50
|
-
}).custom()
|
|
51
|
-
warnings.push(warning)
|
|
52
|
-
}
|
|
53
|
-
} else {
|
|
54
|
-
if (file !== '.env.example' && file !== '.env.vault' && file !== '.env.x') {
|
|
55
|
-
const src = fsx.readFileXSync(file)
|
|
56
|
-
const privateKeyFile = path.basename(file).startsWith('.env.keys')
|
|
57
|
-
|
|
58
|
-
if (privateKeyFile || hasPlaintextSecrets(src)) {
|
|
59
|
-
let errorMsg = `${file} not encrypted/dockerignored`
|
|
60
|
-
let errorHelp = `fix: [dotenvx encrypt -f ${file}] or [dotenvx gitignore --pattern ${file}]`
|
|
61
|
-
if (privateKeyFile) {
|
|
62
|
-
errorMsg = `${file} not dockerignored`
|
|
63
|
-
errorHelp = `fix: [dotenvx gitignore --pattern ${file}]`
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
throw new Errors({ message: errorMsg, help: errorHelp }).custom()
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
let successMessage = count === 0 ? '▣ no .env files' : `▣ encrypted/dockerignored (${count})`
|
|
73
|
-
if (warnings.length > 0) {
|
|
74
|
-
successMessage += ` with warnings (${warnings.length})`
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return {
|
|
78
|
-
successMessage,
|
|
79
|
-
warnings
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
_filepaths () {
|
|
84
|
-
return ls.sync({
|
|
85
|
-
directory: this.directory,
|
|
86
|
-
excludeEnvFile: this.excludeEnvFile
|
|
87
|
-
})
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
module.exports = Prebuild
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
/* istanbul ignore file */
|
|
2
|
-
const fsx = require('./../helpers/fsx')
|
|
3
|
-
const path = require('path')
|
|
4
|
-
const { ignore } = require('@dotenvx/tooling')
|
|
5
|
-
|
|
6
|
-
const ls = require('../resolvers/ls')
|
|
7
|
-
const { sealed } = require('@dotenvx/primitives')
|
|
8
|
-
|
|
9
|
-
const InstallPrecommitHook = require('./../helpers/installPrecommitHook')
|
|
10
|
-
const Errors = require('./../helpers/errors')
|
|
11
|
-
const childProcess = require('child_process')
|
|
12
|
-
const MISSING_GITIGNORE = '.env.keys' // by default only ignore .env.keys. all other .env* files COULD be included - as long as they are encrypted
|
|
13
|
-
|
|
14
|
-
class Precommit {
|
|
15
|
-
constructor (directory = './', options = {}) {
|
|
16
|
-
// args
|
|
17
|
-
this.directory = directory
|
|
18
|
-
// options
|
|
19
|
-
this.install = options.install
|
|
20
|
-
this.excludeEnvFile = ['test/**', 'tests/**', 'spec/**', 'specs/**', 'pytest/**', 'test_suite/**']
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
run () {
|
|
24
|
-
if (this.install) {
|
|
25
|
-
const {
|
|
26
|
-
successMessage
|
|
27
|
-
} = this._installPrecommitHook()
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
successMessage,
|
|
31
|
-
warnings: []
|
|
32
|
-
}
|
|
33
|
-
} else {
|
|
34
|
-
let count = 0
|
|
35
|
-
const warnings = []
|
|
36
|
-
let gitignore = MISSING_GITIGNORE
|
|
37
|
-
|
|
38
|
-
// 1. check for .gitignore file
|
|
39
|
-
if (!fsx.existsSync('.gitignore')) {
|
|
40
|
-
const warning = new Errors({
|
|
41
|
-
message: '.gitignore missing',
|
|
42
|
-
help: 'fix: [touch .gitignore]'
|
|
43
|
-
}).custom()
|
|
44
|
-
warnings.push(warning)
|
|
45
|
-
} else {
|
|
46
|
-
gitignore = fsx.readFileXSync('.gitignore')
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// 2. check .env* files against .gitignore file
|
|
50
|
-
const ig = ignore().add(gitignore)
|
|
51
|
-
|
|
52
|
-
const dotenvFiles = this._filepaths()
|
|
53
|
-
dotenvFiles.forEach(_file => {
|
|
54
|
-
count += 1
|
|
55
|
-
|
|
56
|
-
const file = path.join(this.directory, _file) // to handle when directory argument passed
|
|
57
|
-
const filename = path.basename(file) // exemptions match on filename, so they apply at any depth
|
|
58
|
-
|
|
59
|
-
// check if file is going to be committed
|
|
60
|
-
if (this._isFileToBeCommitted(file)) {
|
|
61
|
-
// check if that file is being ignored
|
|
62
|
-
if (ig.ignores(file)) {
|
|
63
|
-
if (filename === '.env.example' || filename === '.env.vault' || filename === '.env.x') {
|
|
64
|
-
const warning = new Errors({
|
|
65
|
-
message: `${file} ignored (should not be)`,
|
|
66
|
-
help: `fix: [dotenvx gitignore --pattern !${file}]`
|
|
67
|
-
}).custom()
|
|
68
|
-
warnings.push(warning)
|
|
69
|
-
}
|
|
70
|
-
} else {
|
|
71
|
-
if (filename !== '.env.example' && filename !== '.env.vault' && filename !== '.env.x') {
|
|
72
|
-
const src = fsx.readFileXSync(file)
|
|
73
|
-
const encrypted = sealed(src)
|
|
74
|
-
|
|
75
|
-
// if contents are encrypted don't raise an error
|
|
76
|
-
if (!encrypted) {
|
|
77
|
-
let errorMsg = `${file} not encrypted/gitignored`
|
|
78
|
-
let errorHelp = `fix: [dotenvx encrypt -f ${file}] or [dotenvx gitignore --pattern ${file}]`
|
|
79
|
-
if (file.includes('.env.keys')) {
|
|
80
|
-
errorMsg = `${file} not gitignored`
|
|
81
|
-
errorHelp = `fix: [dotenvx gitignore --pattern ${file}]`
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
throw new Errors({ message: errorMsg, help: errorHelp }).custom()
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
let successMessage = count === 0 ? '▣ no .env files' : `▣ encrypted/gitignored (${count})`
|
|
92
|
-
if (warnings.length > 0) {
|
|
93
|
-
successMessage += ` with warnings (${warnings.length})`
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return {
|
|
97
|
-
successMessage,
|
|
98
|
-
warnings
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
_filepaths () {
|
|
104
|
-
return ls.sync({
|
|
105
|
-
directory: this.directory,
|
|
106
|
-
envFile: require('../helpers/precommitEnvPatterns'),
|
|
107
|
-
excludeEnvFile: this.excludeEnvFile
|
|
108
|
-
})
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
_isInGitRepo () {
|
|
112
|
-
try {
|
|
113
|
-
childProcess.execSync('git rev-parse --is-inside-work-tree', { stdio: 'ignore' })
|
|
114
|
-
return true
|
|
115
|
-
} catch {
|
|
116
|
-
return false
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
_isFileToBeCommitted (filePath) {
|
|
121
|
-
try {
|
|
122
|
-
if (!this._isInGitRepo()) {
|
|
123
|
-
// consider file to be committed if there is an error (not a git repo)
|
|
124
|
-
return true
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// -z separates paths with NUL and prints them verbatim. without it git c-quotes
|
|
128
|
-
// any path holding non-ascii or special characters ("caf\303\251/.env"), which
|
|
129
|
-
// never matches filePath - the file would be skipped and its secrets committed.
|
|
130
|
-
const output = childProcess.execSync('git diff HEAD --name-only -z').toString()
|
|
131
|
-
const files = output.split('\0')
|
|
132
|
-
return files.includes(filePath)
|
|
133
|
-
} catch (error) {
|
|
134
|
-
// consider file to be committed if there is an error (not using git)
|
|
135
|
-
return true
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
_installPrecommitHook () {
|
|
140
|
-
return new InstallPrecommitHook().run()
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
module.exports = Precommit
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
const envsResolver = require('../resolvers/envs')
|
|
2
|
-
const Session = require('../../db/session')
|
|
3
|
-
const selectEnvfileEnvs = require('../helpers/selectEnvfileEnvs')
|
|
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
|
-
const Errors = require('../helpers/errors')
|
|
9
|
-
const path = require('node:path')
|
|
10
|
-
const resolveDirectoryFilepath = require('../helpers/resolveDirectoryFilepath')
|
|
11
|
-
|
|
12
|
-
// Load once and validate the final values; callers own presentation and execution.
|
|
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 => {
|
|
16
|
-
const resolved = resolveDirectoryFilepath(env.value, '.env')
|
|
17
|
-
// A directory with a convention selects optional layers rather than one file.
|
|
18
|
-
return options.convention && resolved !== env.value ? [] : [path.resolve(resolved)]
|
|
19
|
-
}))
|
|
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()
|
|
23
|
-
|
|
24
|
-
const session = new Session()
|
|
25
|
-
const noArmor = options.armor === false || (!(options.token || processEnv.DOTENVX_TOKEN) && (await session.noArmor()))
|
|
26
|
-
const { processedEnvs, readableFilepaths } = await envsResolver({
|
|
27
|
-
envs,
|
|
28
|
-
overload: options.overload,
|
|
29
|
-
processEnv,
|
|
30
|
-
envKeysFile: resolveEnvKeysFile(options.envKeysFile),
|
|
31
|
-
noArmor,
|
|
32
|
-
noNative: options.native === false || options.noNative === true,
|
|
33
|
-
no1Password: options['1password'] === false || options.no1Password === true,
|
|
34
|
-
noBitwarden: options.bitwarden === false || options.noBitwarden === true,
|
|
35
|
-
token: options.token,
|
|
36
|
-
command,
|
|
37
|
-
onStatus
|
|
38
|
-
})
|
|
39
|
-
|
|
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)
|
|
46
|
-
|
|
47
|
-
return {
|
|
48
|
-
processEnv,
|
|
49
|
-
processedEnvs,
|
|
50
|
-
readableFilepaths,
|
|
51
|
-
requiredFilepaths,
|
|
52
|
-
hasEnvfile: schema.exists,
|
|
53
|
-
schema,
|
|
54
|
-
checked: result.checked,
|
|
55
|
-
validationError: validateEnvfile.error(result.errors)
|
|
56
|
-
}
|
|
57
|
-
}
|