@dotenvx/dotenvx 2.38.1 → 3.0.0-beta.1
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 +186 -3315
- 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 +139 -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 -2727
- 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
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
const macosKeychain = require('../../../helpers/macosKeychain')
|
|
2
|
-
const windowsCredentialManager = require('../../../helpers/windowsCredentialManager')
|
|
3
|
-
const linuxSecretService = require('../../../helpers/linuxSecretService')
|
|
4
|
-
|
|
5
|
-
function get (key) {
|
|
6
|
-
if (process.platform === 'win32') {
|
|
7
|
-
return windowsCredentialManager.get(key)
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
if (process.platform === 'linux') {
|
|
11
|
-
return linuxSecretService.get(key)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return macosKeychain.get(key)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function set (key, value, label = key) {
|
|
18
|
-
if (process.platform === 'win32') {
|
|
19
|
-
windowsCredentialManager.set(key, value, label)
|
|
20
|
-
return
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (process.platform === 'linux') {
|
|
24
|
-
linuxSecretService.set(key, value, label)
|
|
25
|
-
return
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
macosKeychain.set(key, value, label)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
index.delete = function (key) {
|
|
32
|
-
if (process.platform === 'win32') {
|
|
33
|
-
windowsCredentialManager.delete(key)
|
|
34
|
-
return
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (process.platform === 'linux') {
|
|
38
|
-
linuxSecretService.delete(key)
|
|
39
|
-
return
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
macosKeychain.delete(key)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function index (publicKeyHex) {
|
|
46
|
-
return require('@dotenvx/providers').native().getSync(publicKeyHex)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
index.async = function (publicKeyHex) {
|
|
50
|
-
return require('@dotenvx/providers').native().get(publicKeyHex)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
index.set = set
|
|
54
|
-
index.get = get
|
|
55
|
-
|
|
56
|
-
module.exports = index
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
const backend = require('./backend')
|
|
2
|
-
const storePrivateKey = require('./store')
|
|
3
|
-
|
|
4
|
-
const names = {
|
|
5
|
-
darwin: 'macOS Keychain',
|
|
6
|
-
win32: 'Windows Credential Manager',
|
|
7
|
-
linux: 'Linux Secret Service'
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function enabled (options = {}) {
|
|
11
|
-
return !!names[process.platform] && !process.env.CI && options.noNative !== true && options.native !== false && process.env.DOTENVX_NO_NATIVE !== 'true'
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
module.exports = {
|
|
15
|
-
id: 'native',
|
|
16
|
-
get name () { return `OS${names[process.platform] ? ` (${names[process.platform]})` : ''}` },
|
|
17
|
-
enabled,
|
|
18
|
-
available: () => true,
|
|
19
|
-
configured: () => true,
|
|
20
|
-
get: backend.async,
|
|
21
|
-
getSync: backend,
|
|
22
|
-
set: backend.set,
|
|
23
|
-
delete: backend.delete,
|
|
24
|
-
store (publicKey, privateKey, context) {
|
|
25
|
-
if (!storePrivateKey(publicKey, privateKey, context.keysFilepath)) return { fallback: 'file' }
|
|
26
|
-
return { nativePrivateKeyAdded: true }
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const nativeProvider = require('./backend')
|
|
2
|
-
const armoredKeyDisplay = require('../../../helpers/armoredKeyDisplay')
|
|
3
|
-
const { logger } = require('../../../../shared/logger')
|
|
4
|
-
|
|
5
|
-
function storeNativePrivateKey (publicKey, privateKey, keysFilepath) {
|
|
6
|
-
try {
|
|
7
|
-
nativeProvider.set(publicKey, privateKey, `dotenvx (${armoredKeyDisplay(publicKey)})`)
|
|
8
|
-
} catch (error) {
|
|
9
|
-
if (error.code !== 'NATIVE_UNAVAILABLE') throw error
|
|
10
|
-
logger.warn(`OS secret store unavailable; saving private key to ${keysFilepath}`)
|
|
11
|
-
return false
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// A successful write must be readable before committing the encrypted file.
|
|
15
|
-
// Read failures must never fall back to plaintext storage.
|
|
16
|
-
if (nativeProvider.get(publicKey) !== privateKey) {
|
|
17
|
-
const error = new Error('could not verify private key in OS secret store')
|
|
18
|
-
error.code = 'NATIVE_VERIFY_FAILED'
|
|
19
|
-
throw error
|
|
20
|
-
}
|
|
21
|
-
return true
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
module.exports = storeNativePrivateKey
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
const { execFile } = require('child_process')
|
|
2
|
-
const { onepassword } = require('@dotenvx/providers')
|
|
3
|
-
const Session = require('../../../db/session')
|
|
4
|
-
const armoredKeyDisplay = require('../../helpers/armoredKeyDisplay')
|
|
5
|
-
|
|
6
|
-
const PREFIX = 'DOTENVX_ONEPASSWORD_'
|
|
7
|
-
const ID = /^[a-z0-9]{26}$/i
|
|
8
|
-
const COMMAND_OPTIONS = { encoding: 'utf8', windowsHide: true, timeout: 120000, killSignal: 'SIGKILL', maxBuffer: 1024 * 1024 }
|
|
9
|
-
|
|
10
|
-
function failure (message) {
|
|
11
|
-
const error = new Error(message)
|
|
12
|
-
error.code = '1PASSWORD_FAILED'
|
|
13
|
-
return error
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function commandError (args, stderr) {
|
|
17
|
-
const step = args[0] === 'item'
|
|
18
|
-
? (args[1] === 'delete' ? 'delete the key item' : 'create the key item')
|
|
19
|
-
: {
|
|
20
|
-
whoami: 'check the signed-in account',
|
|
21
|
-
signin: 'sign in',
|
|
22
|
-
read: 'read the private key'
|
|
23
|
-
}[args[0]] || 'check availability'
|
|
24
|
-
if (/account is not signed in/i.test(String(stderr || ''))) {
|
|
25
|
-
const error = failure(`1Password could not ${step}: account is not signed in. Sign in with op signin or enable the desktop app CLI integration`)
|
|
26
|
-
error.reason = 'NOT_SIGNED_IN'
|
|
27
|
-
return error
|
|
28
|
-
}
|
|
29
|
-
return failure(`1Password could not ${step}; check sign-in and vault permissions`)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function run (args, input, timeout = COMMAND_OPTIONS.timeout) {
|
|
33
|
-
return new Promise((resolve, reject) => {
|
|
34
|
-
// On Unix, Node supplies a socket for stdin. op only detects piped JSON
|
|
35
|
-
// through a real pipe, so cat bridges the socket without writing a file.
|
|
36
|
-
const pipeInput = input !== undefined && process.platform !== 'win32'
|
|
37
|
-
const command = pipeInput ? '/bin/sh' : 'op'
|
|
38
|
-
const commandArgs = pipeInput ? ['-c', 'cat | op "$@"', 'dotenvx-op', ...args] : args
|
|
39
|
-
let timer
|
|
40
|
-
const child = execFile(command, commandArgs, {
|
|
41
|
-
...COMMAND_OPTIONS,
|
|
42
|
-
timeout: pipeInput ? 0 : timeout,
|
|
43
|
-
...(pipeInput ? { detached: true } : {})
|
|
44
|
-
}, (error, stdout, stderr) => {
|
|
45
|
-
clearTimeout(timer)
|
|
46
|
-
// Subprocess errors may include secrets from stdin or stdout.
|
|
47
|
-
if (error) reject(commandError(args, stderr))
|
|
48
|
-
else resolve(stdout)
|
|
49
|
-
})
|
|
50
|
-
if (pipeInput) {
|
|
51
|
-
timer = setTimeout(() => {
|
|
52
|
-
// Kill the whole pipeline, including op, if authentication times out.
|
|
53
|
-
try { process.kill(-child.pid, 'SIGKILL') } catch {}
|
|
54
|
-
}, timeout)
|
|
55
|
-
timer.unref()
|
|
56
|
-
}
|
|
57
|
-
if (child.stdin) {
|
|
58
|
-
child.stdin.on('error', () => {})
|
|
59
|
-
child.stdin.end(input)
|
|
60
|
-
}
|
|
61
|
-
})
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function parseResponse (value) {
|
|
65
|
-
try { return JSON.parse(value) } catch {
|
|
66
|
-
throw failure('1Password CLI returned an invalid response')
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
async function available () {
|
|
71
|
-
try {
|
|
72
|
-
const version = await run(['--version'], undefined, 2000)
|
|
73
|
-
// Availability means the CLI is installed. Account setup and authentication
|
|
74
|
-
// are checked by set() only after the user selects 1Password.
|
|
75
|
-
return /^2\./.test(version.trim())
|
|
76
|
-
} catch {
|
|
77
|
-
return false
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function configured () {
|
|
82
|
-
const store = new Session().openStore()
|
|
83
|
-
return !!store && Object.keys(store.store).some(key => key.startsWith(PREFIX))
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function location (publicKey) {
|
|
87
|
-
const store = new Session().openStore()
|
|
88
|
-
const value = store && store.get(`${PREFIX}${publicKey}`)
|
|
89
|
-
if (!value) return null
|
|
90
|
-
const [account, reference] = String(value).split('|')
|
|
91
|
-
if (!ID.test(account) || !/^op:\/\/[a-z0-9]{26}\/[a-z0-9]{26}\/(?:private_key|password)$/i.test(reference || '')) {
|
|
92
|
-
throw failure('invalid 1Password private-key reference in dotenvx settings')
|
|
93
|
-
}
|
|
94
|
-
return { account, reference }
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
async function get (publicKey) {
|
|
98
|
-
return onepassword().get(publicKey)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function getSync (publicKey) {
|
|
102
|
-
return onepassword().getSync(publicKey)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
async function set (publicKey, privateKey) {
|
|
106
|
-
let identity
|
|
107
|
-
try {
|
|
108
|
-
identity = parseResponse(await run(['whoami', '--format=json']))
|
|
109
|
-
} catch (error) {
|
|
110
|
-
if (error.reason !== 'NOT_SIGNED_IN' || process.env.OP_SERVICE_ACCOUNT_TOKEN) throw error
|
|
111
|
-
// whoami checks authentication but does not initiate the desktop app flow.
|
|
112
|
-
// Discard signin output; never print or evaluate a returned session token.
|
|
113
|
-
await run(['signin'])
|
|
114
|
-
identity = parseResponse(await run(['whoami', '--format=json']))
|
|
115
|
-
}
|
|
116
|
-
const account = identity.account_uuid
|
|
117
|
-
if (!ID.test(account || '')) throw failure('could not identify the signed-in 1Password account')
|
|
118
|
-
const item = parseResponse(await run(['item', 'create', '-', '--format=json', `--account=${account}`], JSON.stringify({
|
|
119
|
-
title: `dotenvx (${armoredKeyDisplay(publicKey)})`,
|
|
120
|
-
category: 'PASSWORD',
|
|
121
|
-
tags: ['dotenvx'],
|
|
122
|
-
fields: [
|
|
123
|
-
{ id: 'password', label: 'private_key', type: 'CONCEALED', purpose: 'PASSWORD', value: privateKey },
|
|
124
|
-
{ id: 'public_key', label: 'public_key', type: 'STRING', value: publicKey }
|
|
125
|
-
]
|
|
126
|
-
})))
|
|
127
|
-
if (!ID.test(item.id || '')) throw failure('1Password did not return a saved item ID')
|
|
128
|
-
const vault = item.vault && item.vault.id
|
|
129
|
-
if (!ID.test(vault || '')) throw failure('1Password did not return the saved item vault ID')
|
|
130
|
-
const reference = `op://${vault}/${item.id}/password`
|
|
131
|
-
const saved = await run(['read', reference, '--no-newline', `--account=${account}`])
|
|
132
|
-
if (saved.trim() !== privateKey) throw failure('could not verify private key in 1Password')
|
|
133
|
-
// Only a nonsecret locator is persisted locally, never the private key.
|
|
134
|
-
new Session().createStore().set(`${PREFIX}${publicKey}`, `${account}|${reference}`)
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
async function remove (publicKey) {
|
|
138
|
-
const loc = location(publicKey)
|
|
139
|
-
if (!loc) return
|
|
140
|
-
const [vault, item] = loc.reference.slice('op://'.length).split('/')
|
|
141
|
-
await run(['item', 'delete', item, `--vault=${vault}`, `--account=${loc.account}`])
|
|
142
|
-
new Session().openStore().delete(`${PREFIX}${publicKey}`)
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function enabled (options = {}) {
|
|
146
|
-
return options.no1Password !== true && process.env.DOTENVX_NO_1PASSWORD !== 'true'
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
module.exports = { id: 'onepassword', name: '1Password', enabled, store: set, available, configured, get, getSync, set, delete: remove }
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
const Session = require('../../../../db/session')
|
|
2
|
-
const store = require('./store')
|
|
3
|
-
|
|
4
|
-
module.exports = {
|
|
5
|
-
id: 'armored',
|
|
6
|
-
name: '⛨ Armor',
|
|
7
|
-
custody: 'managed',
|
|
8
|
-
enabled: (options = {}) => options.noArmor !== true && options.armor !== false && process.env.DOTENVX_NO_ARMOR !== 'true',
|
|
9
|
-
available: () => true,
|
|
10
|
-
async configured (options = {}) {
|
|
11
|
-
return !!options.token || !await new Session().noArmor()
|
|
12
|
-
},
|
|
13
|
-
store
|
|
14
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
const keypairMetadata = require('../../../helpers/keypairMetadata')
|
|
2
|
-
const Session = require('../../../../db/session')
|
|
3
|
-
const PostArmorUp = require('../../../api/postArmorUp')
|
|
4
|
-
const prompts = require('../../../helpers/prompts')
|
|
5
|
-
const teamChoicesFromMeta = require('../../../helpers/teamChoicesFromMeta')
|
|
6
|
-
const isTeamRequiredError = require('../../../helpers/isTeamRequiredError')
|
|
7
|
-
|
|
8
|
-
async function store (publicKey, privateKey, context = {}) {
|
|
9
|
-
const sesh = new Session()
|
|
10
|
-
const hostname = sesh.hostname()
|
|
11
|
-
const token = context.token || sesh.token()
|
|
12
|
-
const devicePublicKey = sesh.devicePublicKey()
|
|
13
|
-
|
|
14
|
-
const metadata = keypairMetadata.file(context.envFilepath)
|
|
15
|
-
|
|
16
|
-
try {
|
|
17
|
-
await new PostArmorUp(hostname, token, devicePublicKey, publicKey, privateKey, undefined, metadata).run()
|
|
18
|
-
} catch (error) {
|
|
19
|
-
if (!isTeamRequiredError(error)) {
|
|
20
|
-
throw error
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const choices = teamChoicesFromMeta(error.meta)
|
|
24
|
-
|
|
25
|
-
let team = choices[0].value
|
|
26
|
-
if (choices.length > 1) {
|
|
27
|
-
team = await prompts.select({
|
|
28
|
-
message: 'Select team',
|
|
29
|
-
prefix: '⛨',
|
|
30
|
-
choices: context.allowCustodyBack ? [...choices, { name: '← back', value: '__back' }] : choices,
|
|
31
|
-
...(context.allowCustodyBack ? { navigation: true, backValue: '__back' } : {})
|
|
32
|
-
}, {
|
|
33
|
-
input: process.stdin,
|
|
34
|
-
output: process.stderr
|
|
35
|
-
})
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (team === '__back') {
|
|
39
|
-
const error = new Error('Return to private key custody')
|
|
40
|
-
error.code = 'KEY_CUSTODY_BACK'
|
|
41
|
-
throw error
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
await new PostArmorUp(hostname, token, devicePublicKey, publicKey, privateKey, team, metadata).run()
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
module.exports = store
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
const fs = require('node:fs')
|
|
2
|
-
const path = require('node:path')
|
|
3
|
-
const { scan, derive } = require('@dotenvx/primitives')
|
|
4
|
-
const custodians = require('./index')
|
|
5
|
-
const keynames = require('../conventions/keynames')
|
|
6
|
-
const matchesStoredKey = require('../helpers/matchesStoredKey')
|
|
7
|
-
const removeEnvKey = require('../helpers/removeEnvKey')
|
|
8
|
-
const Errors = require('../helpers/errors')
|
|
9
|
-
|
|
10
|
-
function read (filename) {
|
|
11
|
-
try { return fs.readFileSync(filename, 'utf8') } catch (error) {
|
|
12
|
-
if (error.code === 'ENOENT') return undefined
|
|
13
|
-
throw error
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function value (src, name) {
|
|
18
|
-
return src === undefined ? undefined : scan(src).parsed[name]?.at(-1)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// Return the originating store with the key, so a move only removes that source.
|
|
22
|
-
// Never look up Armor itself: these operations upload a locally held private key.
|
|
23
|
-
module.exports = async function resolveLocalKey (envFile = '.env', { allowMissing = false } = {}) {
|
|
24
|
-
const src = read(envFile)
|
|
25
|
-
const { publicKeyName, privateKeyName } = keynames(envFile, src || '')
|
|
26
|
-
let publicKey = value(src, publicKeyName)
|
|
27
|
-
if (allowMissing && !publicKey) {
|
|
28
|
-
if (src === undefined) throw new Errors({ envFilepath: envFile }).missingEnvFile()
|
|
29
|
-
throw new Errors({ key: publicKeyName }).missingKey()
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async function result (stored, remove, reread) {
|
|
33
|
-
// A file-only push remains supported.
|
|
34
|
-
if (!publicKey) publicKey = derive(stored)
|
|
35
|
-
if (!matchesStoredKey(publicKey, stored)) throw new Error('private key does not match the .env public key')
|
|
36
|
-
const privateKey = stored
|
|
37
|
-
return {
|
|
38
|
-
publicKey,
|
|
39
|
-
privateKey,
|
|
40
|
-
privateKeyName,
|
|
41
|
-
async remove () {
|
|
42
|
-
if (await reread() !== stored) throw new Error('private key changed during upload; original storage was not modified')
|
|
43
|
-
await remove()
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const files = [...new Set([path.resolve(path.dirname(envFile), '.env.keys'), path.resolve('.env.keys')])]
|
|
49
|
-
for (const filename of files) {
|
|
50
|
-
const stored = value(read(filename), privateKeyName)
|
|
51
|
-
if (stored) return result(stored, () => removeEnvKey(privateKeyName, filename), () => value(read(filename), privateKeyName))
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (publicKey) {
|
|
55
|
-
for (const id of ['native', 'onepassword', 'bitwarden']) {
|
|
56
|
-
const custodian = custodians.get(id)
|
|
57
|
-
if (!custodian.enabled() || (custodian.configured && !custodian.configured())) continue
|
|
58
|
-
const stored = (await custodian.get(publicKey))?.[publicKey]
|
|
59
|
-
if (stored) return result(stored, () => custodian.delete(publicKey), async () => (await custodian.get(publicKey))?.[publicKey])
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Up can be repeated for a key already held by Armor; the server verifies it.
|
|
64
|
-
if (allowMissing) return { publicKey, privateKeyName, remove: async () => {} }
|
|
65
|
-
if (!publicKey && src === undefined) throw new Errors({ envFilepath: '.env.keys' }).missingEnvFile()
|
|
66
|
-
throw new Error(`private key ${privateKeyName} not found in .env.keys, OS secret storage, 1Password, or Bitwarden`)
|
|
67
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const Session = require('../../../db/session')
|
|
2
|
-
const { armor } = require('@dotenvx/providers')
|
|
3
|
-
const { version } = require('../../helpers/packageJson')
|
|
4
|
-
|
|
5
|
-
async function index (src, options = {}) {
|
|
6
|
-
const sesh = new Session()
|
|
7
|
-
|
|
8
|
-
const hostname = sesh.hostname()
|
|
9
|
-
const token = options.token || sesh.token()
|
|
10
|
-
const devicePublicKey = sesh.devicePublicKey()
|
|
11
|
-
|
|
12
|
-
return await armor({
|
|
13
|
-
hostname,
|
|
14
|
-
token,
|
|
15
|
-
devicePublicKey,
|
|
16
|
-
cliVersion: version,
|
|
17
|
-
onApprovalRequired: options.onStatus && (({ approvalUri, code }) => {
|
|
18
|
-
options.onStatus(`[${code}] open [${approvalUri}] to approve. Waiting for approval…`)
|
|
19
|
-
})
|
|
20
|
-
}).decrypt(src, { publicKey: options.publicKey, grantToken: options.grantToken })
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
module.exports = index
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
const Session = require('./../../db/session')
|
|
2
|
-
|
|
3
|
-
const armorDecryptor = require('./armor/index')
|
|
4
|
-
|
|
5
|
-
function syncArmorDecryptor (src, options) {
|
|
6
|
-
const { createSyncFn } = require('@dotenvx/tooling')
|
|
7
|
-
const runDecryptorSync = createSyncFn(require.resolve('./decryptor-worker.js'))
|
|
8
|
-
return runDecryptorSync(src, options)
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function armorDecryptorForOptions (options) {
|
|
12
|
-
return (src, decryptOptions) => armorDecryptor(src, {
|
|
13
|
-
...decryptOptions,
|
|
14
|
-
onStatus: options.onStatus,
|
|
15
|
-
token: options.token,
|
|
16
|
-
command: options.command
|
|
17
|
-
})
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function syncArmorDecryptorForOptions (options) {
|
|
21
|
-
return (src, decryptOptions) => syncArmorDecryptor(src, {
|
|
22
|
-
...decryptOptions,
|
|
23
|
-
onStatus: options.onStatus,
|
|
24
|
-
token: options.token,
|
|
25
|
-
command: options.command
|
|
26
|
-
})
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function useArmor (options, noArmor) {
|
|
30
|
-
return options.noArmor !== true && options.armor !== false && !noArmor
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
async function decryptors (options = {}) {
|
|
34
|
-
if (Object.prototype.hasOwnProperty.call(options, 'decryptor')) {
|
|
35
|
-
return options.decryptor
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (options.noArmor === true || options.armor === false) {
|
|
39
|
-
return null
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const sesh = new Session()
|
|
43
|
-
const noArmor = !options.token && await sesh.noArmor()
|
|
44
|
-
if (!useArmor(options, noArmor)) {
|
|
45
|
-
return null
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return armorDecryptorForOptions(options)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
decryptors.sync = function decryptorsSync (options = {}) {
|
|
52
|
-
if (Object.prototype.hasOwnProperty.call(options, 'decryptor')) {
|
|
53
|
-
return options.decryptor
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (options.noArmor === true || options.armor === false) {
|
|
57
|
-
return null
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const sesh = new Session()
|
|
61
|
-
const noArmor = !options.token && sesh.noArmorSync()
|
|
62
|
-
if (!useArmor(options, noArmor)) {
|
|
63
|
-
return null
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return syncArmorDecryptorForOptions(options)
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
module.exports = decryptors
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
const fs = require('node:fs')
|
|
2
|
-
const path = require('node:path')
|
|
3
|
-
|
|
4
|
-
const ignoredDirectories = new Set(['.git', 'node_modules', 'dist', 'build', '.next', 'vendor', '.venv', 'coverage', '__pycache__'])
|
|
5
|
-
|
|
6
|
-
// Discover selectable inputs without reading their values. Env files are often
|
|
7
|
-
// gitignored, so .gitignore must not hide them from this checklist.
|
|
8
|
-
module.exports = function discoverEnvFiles ({ directory = process.cwd() } = {}) {
|
|
9
|
-
const root = path.resolve(directory)
|
|
10
|
-
const files = []
|
|
11
|
-
function walk (current) {
|
|
12
|
-
const entries = fs.readdirSync(current, { withFileTypes: true })
|
|
13
|
-
// Stop at nested packages and initialized projects, including symlinked markers.
|
|
14
|
-
if (current !== root && entries.some(entry => ['Envfile', 'package.json'].includes(entry.name))) return
|
|
15
|
-
for (const entry of entries) {
|
|
16
|
-
const filename = path.join(current, entry.name)
|
|
17
|
-
if (entry.isDirectory()) {
|
|
18
|
-
if (!ignoredDirectories.has(entry.name) && !entry.name.startsWith('.env')) walk(filename)
|
|
19
|
-
continue
|
|
20
|
-
}
|
|
21
|
-
if (entry.name !== '.env' && !entry.name.startsWith('.env.')) continue
|
|
22
|
-
if (/^\.env\.(schema|x)$/.test(entry.name) || /^\.env\.(keys|vault)(\.|$)/.test(entry.name)) continue
|
|
23
|
-
if (!entry.isFile() && !(entry.isSymbolicLink() && fs.statSync(filename, { throwIfNoEntry: false })?.isFile())) continue
|
|
24
|
-
files.push(path.relative(root, filename).split(path.sep).join('/'))
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
walk(root)
|
|
28
|
-
return files.sort()
|
|
29
|
-
}
|