@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,51 +0,0 @@
|
|
|
1
|
-
const { setTimeout: delay } = require('node:timers/promises')
|
|
2
|
-
const GetTeamConnections = require('../api/getTeamConnections')
|
|
3
|
-
const TeamConnectionSetup = require('../api/teamConnectionSetup')
|
|
4
|
-
const prompts = require('./prompts')
|
|
5
|
-
const openUrl = require('./openUrl')
|
|
6
|
-
|
|
7
|
-
async function selectConnection (hostname, token, team, service, context) {
|
|
8
|
-
const { connections } = await new GetTeamConnections(hostname, token, team, service.slug).run()
|
|
9
|
-
const selected = await prompts.select({
|
|
10
|
-
message: 'Select connection',
|
|
11
|
-
prefix: '◊',
|
|
12
|
-
choices: [
|
|
13
|
-
...connections.map(connection => ({ name: connection.name, value: String(connection.id) })),
|
|
14
|
-
{ name: `+ Connect to ${service.name}`, value: '__connect' },
|
|
15
|
-
{ name: '← back', value: '__back' }
|
|
16
|
-
],
|
|
17
|
-
navigation: true,
|
|
18
|
-
backValue: '__back'
|
|
19
|
-
}, context)
|
|
20
|
-
if (selected === '__back') return
|
|
21
|
-
if (selected !== '__connect') {
|
|
22
|
-
const connection = connections.find(connection => String(connection.id) === selected)
|
|
23
|
-
if (!connection) throw new Error('Invalid connection selection')
|
|
24
|
-
return connection
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const api = new TeamConnectionSetup(hostname, token, team)
|
|
28
|
-
const setup = await api.create(service.slug)
|
|
29
|
-
const url = new URL(setup.setup_url, hostname)
|
|
30
|
-
if (!['http:', 'https:'].includes(url.protocol)) throw new Error('Invalid connection setup URL')
|
|
31
|
-
context.output.write(`◇ waiting for ${service.name} connection…\n${url.href}\n`)
|
|
32
|
-
try {
|
|
33
|
-
await openUrl(url.href)
|
|
34
|
-
} catch {
|
|
35
|
-
context.output.write(`Open the URL above to connect ${service.name}.\n`)
|
|
36
|
-
}
|
|
37
|
-
const deadline = Math.min(Date.parse(setup.expires_at), Date.now() + 10 * 60 * 1000)
|
|
38
|
-
while (Date.now() < deadline) {
|
|
39
|
-
const result = await api.status(setup.id)
|
|
40
|
-
if (result.status === 'connected') {
|
|
41
|
-
if (!result.connection || result.connection.service !== service.slug) throw new Error('Invalid connection response')
|
|
42
|
-
return result.connection
|
|
43
|
-
}
|
|
44
|
-
if (result.status === 'expired') break
|
|
45
|
-
if (result.status !== 'pending') throw new Error(`${service.name} connection setup failed`)
|
|
46
|
-
await delay(Math.min(5000, Math.max(1000, (setup.interval || 2) * 1000)))
|
|
47
|
-
}
|
|
48
|
-
throw new Error(`${service.name} connection setup expired. Select Connect to ${service.name} to try again.`)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
module.exports = selectConnection
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
const GetConnectionResources = require('../api/getConnectionResources')
|
|
2
|
-
const prompts = require('./prompts')
|
|
3
|
-
|
|
4
|
-
async function selectConnectionResource (hostname, token, team, connection, context) {
|
|
5
|
-
const api = new GetConnectionResources(hostname, token, team, connection.id)
|
|
6
|
-
let query = ''
|
|
7
|
-
while (true) {
|
|
8
|
-
const { resources, meta } = await api.run(query)
|
|
9
|
-
const footer = !resources.length
|
|
10
|
-
? (query ? `No resources found for "${query}".` : 'No resources available for this connection.')
|
|
11
|
-
: (meta?.has_more ? 'Showing 5 resources. Search to narrow the results.' : undefined)
|
|
12
|
-
const shown = resources.slice(0, 5)
|
|
13
|
-
const selected = await prompts.select({
|
|
14
|
-
message: 'Select resource',
|
|
15
|
-
footer,
|
|
16
|
-
prefix: '◊',
|
|
17
|
-
choices: [
|
|
18
|
-
...shown.map(resource => {
|
|
19
|
-
const contextName = connection.name || resource.organization
|
|
20
|
-
const name = resource.name || String(resource.id)
|
|
21
|
-
const label = contextName ? `${contextName}${name.startsWith('/') ? ' ' : ' / '}${name}` : name
|
|
22
|
-
return { name: label, value: String(resource.id) }
|
|
23
|
-
}),
|
|
24
|
-
{ name: query ? 'Search again…' : 'Search…', value: '__search' },
|
|
25
|
-
{ name: '← back', value: '__back' }
|
|
26
|
-
],
|
|
27
|
-
navigation: true,
|
|
28
|
-
backValue: '__back'
|
|
29
|
-
}, context)
|
|
30
|
-
if (selected === '__back') return
|
|
31
|
-
if (selected === '__search') {
|
|
32
|
-
query = (await prompts.input({ message: 'Search resources (blank to reset)' }, context)).trim()
|
|
33
|
-
continue
|
|
34
|
-
}
|
|
35
|
-
const resource = shown.find(resource => String(resource.id) === selected)
|
|
36
|
-
if (!resource) throw new Error('Invalid resource selection')
|
|
37
|
-
return resource
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
module.exports = selectConnectionResource
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
const { profile } = require('@dotenvx/primitives')
|
|
2
|
-
const readEnvfile = require('../envfile/parsing/readEnvfile')
|
|
3
|
-
const normalizeDotenvConfigPath = require('./normalizeDotenvConfigPath')
|
|
4
|
-
const buildCommandEnvs = require('./buildCommandEnvs')
|
|
5
|
-
const determine = require('./envResolution/determine')
|
|
6
|
-
|
|
7
|
-
module.exports = function selectEnvfileEnvs (envs = [], options = {}, processEnv = process.env) {
|
|
8
|
-
const resolve = values => options.resolveDirectories === false ? values : buildCommandEnvs(values, options.convention)
|
|
9
|
-
const document = readEnvfile.source()
|
|
10
|
-
if (!document.exists) {
|
|
11
|
-
if (options.profile !== undefined) throw new Error('Profile selection requires an Envfile')
|
|
12
|
-
return determine(resolve(normalizeDotenvConfigPath(envs, processEnv)), processEnv)
|
|
13
|
-
}
|
|
14
|
-
// Keep explicit CLI file/inline-env ordering; profiles only supply file selection.
|
|
15
|
-
const explicit = resolve(envs)
|
|
16
|
-
const files = explicit.filter(env => env.type === 'envFile')
|
|
17
|
-
let selected
|
|
18
|
-
try {
|
|
19
|
-
selected = profile(document.source, {
|
|
20
|
-
f: files.length ? files.map(env => env.value).join(',') : undefined,
|
|
21
|
-
profile: options.profile,
|
|
22
|
-
processEnv
|
|
23
|
-
})
|
|
24
|
-
} catch (error) {
|
|
25
|
-
throw readEnvfile.formatError(error, document)
|
|
26
|
-
}
|
|
27
|
-
if (files.length) return explicit
|
|
28
|
-
return resolve((selected ? selected.split(',').map(value => ({ type: 'envFile', value })) : []).concat(explicit))
|
|
29
|
-
}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
const prompts = require('./prompts')
|
|
2
|
-
const custodians = require('../custodians')
|
|
3
|
-
const createSpinner = require('./createSpinner')
|
|
4
|
-
const Session = require('../../db/session')
|
|
5
|
-
const GetTeams = require('../api/getTeams')
|
|
6
|
-
const GetTeamServices = require('../api/getTeamServices')
|
|
7
|
-
const selectConnection = require('./selectConnection')
|
|
8
|
-
const selectConnectionResource = require('./selectConnectionResource')
|
|
9
|
-
|
|
10
|
-
const nativeNames = { darwin: 'macOS Keychain', win32: 'Windows Credential Manager', linux: 'Linux Secret Service' }
|
|
11
|
-
|
|
12
|
-
async function selectKeyStorage (options = {}) {
|
|
13
|
-
if (process.env.CI || options.noCreate || !process.stdin.isTTY || !process.stderr.isTTY) return 'file'
|
|
14
|
-
|
|
15
|
-
const groups = new Map()
|
|
16
|
-
const setup = new Map()
|
|
17
|
-
const definitions = [
|
|
18
|
-
['local', ['file', 'native']],
|
|
19
|
-
['passwords', ['onepassword', 'bitwarden']],
|
|
20
|
-
['armored', ['armored']]
|
|
21
|
-
]
|
|
22
|
-
for (const [group, ids] of definitions) {
|
|
23
|
-
const entries = []
|
|
24
|
-
for (const id of ids) {
|
|
25
|
-
const custodian = custodians.get(id)
|
|
26
|
-
if (!custodian.enabled(options)) continue
|
|
27
|
-
let name = id === 'native' ? nativeNames[process.platform] : id === 'file' ? `File ${options.fk || '.env.keys'}` : id === 'armored' ? '⛨ Dotenvx Armor' : custodian.name
|
|
28
|
-
if (!await custodian.available()) {
|
|
29
|
-
const command = id === 'onepassword' ? 'op' : 'bw'
|
|
30
|
-
name += ' (install CLI)'
|
|
31
|
-
setup.set(id, `Install the ${custodian.name} CLI (${command}), then retry this command.`)
|
|
32
|
-
} else if (id === 'armored' && !await custodian.configured(options)) {
|
|
33
|
-
name += ' (sign in)'
|
|
34
|
-
setup.set(id, 'Sign in with [dotenvx login], then retry this command.')
|
|
35
|
-
}
|
|
36
|
-
entries.push({ name, value: id })
|
|
37
|
-
}
|
|
38
|
-
if (entries.length) groups.set(group, entries)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
createSpinner.pause()
|
|
42
|
-
try {
|
|
43
|
-
const context = { input: process.stdin, output: process.stderr }
|
|
44
|
-
const choices = [
|
|
45
|
-
{ name: '⛉ Local', value: 'local' },
|
|
46
|
-
...(groups.get('armored') || []),
|
|
47
|
-
...(groups.has('passwords') ? [{ name: '⛊ Password Managers', value: 'passwords' }] : [])
|
|
48
|
-
]
|
|
49
|
-
let initial = 'local'
|
|
50
|
-
while (true) {
|
|
51
|
-
const category = await prompts.select({ message: 'Choose private key custody', choices, navigation: true, initial }, context)
|
|
52
|
-
if (!choices.some(choice => choice.value === category)) throw new Error('Invalid private key storage selection')
|
|
53
|
-
let storage = category
|
|
54
|
-
if (category !== 'armored') {
|
|
55
|
-
const entries = groups.get(category)
|
|
56
|
-
storage = await prompts.select({
|
|
57
|
-
message: category === 'local' ? 'Choose local custody' : 'Choose password manager',
|
|
58
|
-
prefix: category === 'local' ? '⛉' : '⛊',
|
|
59
|
-
choices: [...entries, { name: '← back', value: '__back' }],
|
|
60
|
-
navigation: true,
|
|
61
|
-
backValue: '__back'
|
|
62
|
-
}, context)
|
|
63
|
-
if (storage === '__back') {
|
|
64
|
-
initial = category
|
|
65
|
-
continue
|
|
66
|
-
}
|
|
67
|
-
if (!entries.some(choice => choice.value === storage)) throw new Error('Invalid private key storage selection')
|
|
68
|
-
}
|
|
69
|
-
if (setup.has(storage)) throw new Error(setup.get(storage))
|
|
70
|
-
if (storage === 'armored') {
|
|
71
|
-
while (true) {
|
|
72
|
-
const keyType = await prompts.select({
|
|
73
|
-
message: 'Choose key type',
|
|
74
|
-
prefix: '⛨',
|
|
75
|
-
choices: [
|
|
76
|
-
{ name: '⛨ Armored', value: 'armored' },
|
|
77
|
-
{ name: '◊ Enclaved', value: 'enclaved' },
|
|
78
|
-
{ name: '← back', value: '__back' }
|
|
79
|
-
],
|
|
80
|
-
initial: 'armored',
|
|
81
|
-
navigation: true,
|
|
82
|
-
backValue: '__back'
|
|
83
|
-
}, context)
|
|
84
|
-
if (keyType === '__back') {
|
|
85
|
-
initial = 'armored'
|
|
86
|
-
break
|
|
87
|
-
}
|
|
88
|
-
if (keyType === 'enclaved') {
|
|
89
|
-
const session = new Session()
|
|
90
|
-
const { teams } = await new GetTeams(session.hostname(), options.token || session.token()).run()
|
|
91
|
-
if (!teams.length) throw new Error('No teams available for enclave keys')
|
|
92
|
-
const choices = teams.map(team => ({ name: team.slug, value: team.slug }))
|
|
93
|
-
while (true) {
|
|
94
|
-
const team = await prompts.select({
|
|
95
|
-
message: 'Select team',
|
|
96
|
-
prefix: '◊',
|
|
97
|
-
choices: [...choices, { name: '← back', value: '__back' }],
|
|
98
|
-
navigation: true,
|
|
99
|
-
backValue: '__back'
|
|
100
|
-
}, context)
|
|
101
|
-
if (team === '__back') break
|
|
102
|
-
if (!choices.some(choice => choice.value === team)) throw new Error('Invalid team selection')
|
|
103
|
-
const { services } = await new GetTeamServices(session.hostname(), options.token || session.token(), team).run()
|
|
104
|
-
if (!services.length) throw new Error('No services available for this team')
|
|
105
|
-
const serviceChoices = services.map(service => ({ name: service.name, value: service.slug }))
|
|
106
|
-
while (true) {
|
|
107
|
-
const service = await prompts.select({
|
|
108
|
-
message: 'Select service',
|
|
109
|
-
prefix: '◊',
|
|
110
|
-
choices: [...serviceChoices, { name: '← back', value: '__back' }],
|
|
111
|
-
navigation: true,
|
|
112
|
-
backValue: '__back'
|
|
113
|
-
}, context)
|
|
114
|
-
if (service === '__back') break
|
|
115
|
-
if (!serviceChoices.some(choice => choice.value === service)) throw new Error('Invalid service selection')
|
|
116
|
-
const selectedService = services.find(item => item.slug === service)
|
|
117
|
-
while (true) {
|
|
118
|
-
const connection = await selectConnection(session.hostname(), options.token || session.token(), team, selectedService, context)
|
|
119
|
-
if (!connection) break
|
|
120
|
-
const resource = await selectConnectionResource(session.hostname(), options.token || session.token(), team, connection, context)
|
|
121
|
-
if (!resource) continue
|
|
122
|
-
return { id: 'enclaved', team, service, connectionId: connection.id, resourceId: resource.id }
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
continue
|
|
127
|
-
}
|
|
128
|
-
if (keyType !== 'armored') throw new Error('Invalid key type selection')
|
|
129
|
-
return storage
|
|
130
|
-
}
|
|
131
|
-
continue
|
|
132
|
-
}
|
|
133
|
-
return storage
|
|
134
|
-
}
|
|
135
|
-
} finally {
|
|
136
|
-
createSpinner.resume()
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
module.exports = selectKeyStorage
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
const selectKeyStorage = require('./selectKeyStorage')
|
|
2
|
-
const prompts = require('./prompts')
|
|
3
|
-
const createSpinner = require('./createSpinner')
|
|
4
|
-
const custodians = require('../custodians')
|
|
5
|
-
const { keypair, encrypt } = require('@dotenvx/primitives')
|
|
6
|
-
const Session = require('../../db/session')
|
|
7
|
-
const PostConnectionKeypair = require('../api/postConnectionKeypair')
|
|
8
|
-
|
|
9
|
-
async function storeKeyStorage (storage, publicKey, privateKey, options, context) {
|
|
10
|
-
context.allowCustodyBack = true
|
|
11
|
-
while (true) {
|
|
12
|
-
storage = storage || await selectKeyStorage(options)
|
|
13
|
-
if (storage.id === 'enclaved') {
|
|
14
|
-
let privateKeyName
|
|
15
|
-
createSpinner.pause()
|
|
16
|
-
try {
|
|
17
|
-
privateKeyName = await prompts.input({ message: 'Private key name', initial: context.privateKeyName }, context)
|
|
18
|
-
} finally {
|
|
19
|
-
createSpinner.resume()
|
|
20
|
-
}
|
|
21
|
-
const session = new Session()
|
|
22
|
-
const result = await new PostConnectionKeypair(session.hostname(), options.token || session.token(), storage, privateKeyName).run()
|
|
23
|
-
const remotePublicKey = result.keypair?.public_key
|
|
24
|
-
if (typeof remotePublicKey !== 'string' || !/^(?:0[23][0-9a-f]{64}|04[0-9a-f]{128})$/i.test(remotePublicKey)) throw new Error('Invalid public key returned by Armor')
|
|
25
|
-
encrypt(remotePublicKey, '')
|
|
26
|
-
return { storage, stored: {}, publicKey: remotePublicKey }
|
|
27
|
-
}
|
|
28
|
-
if (!publicKey) ({ publicKey, privateKey } = keypair())
|
|
29
|
-
try {
|
|
30
|
-
const stored = await custodians.store(storage, publicKey, privateKey, context)
|
|
31
|
-
return { storage, stored, publicKey }
|
|
32
|
-
} catch (error) {
|
|
33
|
-
if (error.code !== 'KEY_CUSTODY_BACK') throw error
|
|
34
|
-
storage = undefined
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
module.exports = storeKeyStorage
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
const fs = require('fs')
|
|
2
|
-
const fsx = require('./fsx')
|
|
3
|
-
const path = require('path')
|
|
4
|
-
const { execFileSync } = require('child_process')
|
|
5
|
-
const { HOOK_SCRIPT } = require('./installPrecommitHook')
|
|
6
|
-
|
|
7
|
-
const LEGACY_SCRIPT = `#!/bin/sh
|
|
8
|
-
|
|
9
|
-
if command -v dotenvx 2>&1 >/dev/null
|
|
10
|
-
then
|
|
11
|
-
dotenvx ext precommit
|
|
12
|
-
elif npx dotenvx -V >/dev/null 2>&1
|
|
13
|
-
then
|
|
14
|
-
npx dotenvx ext precommit
|
|
15
|
-
else
|
|
16
|
-
echo "[dotenvx][precommit] 'dotenvx' command not found"
|
|
17
|
-
echo "[dotenvx][precommit] ? install it with [curl -fsS https://dotenvx.sh | sh]"
|
|
18
|
-
echo "[dotenvx][precommit] ? other install options [https://dotenvx.com/docs/install]"
|
|
19
|
-
exit 1
|
|
20
|
-
fi
|
|
21
|
-
`
|
|
22
|
-
|
|
23
|
-
function within (directory, file) {
|
|
24
|
-
const relative = path.relative(directory, file)
|
|
25
|
-
return relative !== '..' && !relative.startsWith('..' + path.sep) && !path.isAbsolute(relative)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function uninstallPrecommitHook (directory = process.cwd()) {
|
|
29
|
-
const git = (...args) => execFileSync('git', args, { cwd: directory, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim()
|
|
30
|
-
let root
|
|
31
|
-
try {
|
|
32
|
-
root = git('rev-parse', '--show-toplevel')
|
|
33
|
-
} catch (error) {
|
|
34
|
-
if (error.status === 128) return { removed: false }
|
|
35
|
-
throw error
|
|
36
|
-
}
|
|
37
|
-
const hookPath = path.resolve(directory, git('rev-parse', '--git-path', 'hooks/pre-commit'))
|
|
38
|
-
const commonDir = path.resolve(directory, git('rev-parse', '--git-common-dir'))
|
|
39
|
-
const manual = () => ({ removed: false, warning: `pre-commit hook left unchanged; remove its dotenvx precommit entry manually [${hookPath}]` })
|
|
40
|
-
let stat
|
|
41
|
-
try {
|
|
42
|
-
stat = fs.lstatSync(hookPath)
|
|
43
|
-
} catch (error) {
|
|
44
|
-
if (error.code === 'ENOENT') return { removed: false }
|
|
45
|
-
throw error
|
|
46
|
-
}
|
|
47
|
-
// Never modify symlinked hooks or shared hooks outside this repository.
|
|
48
|
-
if (!stat.isFile() || (!within(root, fs.realpathSync(hookPath)) && !within(commonDir, fs.realpathSync(hookPath)))) return manual()
|
|
49
|
-
const source = fs.readFileSync(hookPath, 'utf8')
|
|
50
|
-
const templates = [HOOK_SCRIPT, LEGACY_SCRIPT, HOOK_SCRIPT.replaceAll('dotenvx precommit', 'dotenvx ext precommit'), LEGACY_SCRIPT.replaceAll('dotenvx ext precommit', 'dotenvx precommit')]
|
|
51
|
-
let next = source
|
|
52
|
-
for (const template of templates) {
|
|
53
|
-
for (const block of [template, template.replaceAll('\n', '\r\n')]) {
|
|
54
|
-
// Match whole, known installer blocks; do not guess at shell structure.
|
|
55
|
-
const escaped = block.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
56
|
-
next = next.replace(new RegExp('(^|\\n)' + escaped, 'g'), '$1')
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
if (next === source) {
|
|
60
|
-
return /dotenvx\s+(?:ext\s+)?precommit/.test(source) ? manual() : { removed: false }
|
|
61
|
-
}
|
|
62
|
-
if (next.trim() === '') fs.unlinkSync(hookPath)
|
|
63
|
-
else fsx.writeFileXSync(hookPath, next, 'utf8')
|
|
64
|
-
return { removed: true, warning: /dotenvx\s+(?:ext\s+)?precommit/.test(next) ? manual().warning : undefined }
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
module.exports = uninstallPrecommitHook
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
const fs = require('fs')
|
|
2
|
-
const path = require('path')
|
|
3
|
-
const fsx = require('./fsx')
|
|
4
|
-
|
|
5
|
-
function escapeForRegex (value) {
|
|
6
|
-
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function upsertEnvKey (key, value, keysFilepath = '.env.keys') {
|
|
10
|
-
const resolvedKeysFilepath = path.resolve(keysFilepath)
|
|
11
|
-
const keyValueLine = `${key}=${value}`
|
|
12
|
-
const created = !fs.existsSync(resolvedKeysFilepath)
|
|
13
|
-
|
|
14
|
-
let src = ''
|
|
15
|
-
if (!created) {
|
|
16
|
-
src = fs.readFileSync(resolvedKeysFilepath, 'utf8')
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const eol = src.includes('\r\n') ? '\r\n' : '\n'
|
|
20
|
-
const keyPattern = new RegExp(`^\\s*(?:export\\s+)?${escapeForRegex(key)}\\s*=`)
|
|
21
|
-
const lines = src.length > 0 ? src.split(/\r?\n/) : []
|
|
22
|
-
|
|
23
|
-
while (lines.length > 0 && lines[lines.length - 1] === '') {
|
|
24
|
-
lines.pop()
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
let replaced = false
|
|
28
|
-
const nextLines = []
|
|
29
|
-
|
|
30
|
-
for (const line of lines) {
|
|
31
|
-
if (keyPattern.test(line)) {
|
|
32
|
-
if (!replaced) {
|
|
33
|
-
nextLines.push(keyValueLine)
|
|
34
|
-
replaced = true
|
|
35
|
-
}
|
|
36
|
-
continue
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
nextLines.push(line)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (!replaced) {
|
|
43
|
-
nextLines.push(keyValueLine)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const nextSrc = `${nextLines.join(eol)}${eol}`
|
|
47
|
-
const changed = created || nextSrc !== src
|
|
48
|
-
|
|
49
|
-
if (changed) {
|
|
50
|
-
fsx.writeKeyFileSync(resolvedKeysFilepath, nextSrc)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return {
|
|
54
|
-
changed,
|
|
55
|
-
key,
|
|
56
|
-
value,
|
|
57
|
-
created,
|
|
58
|
-
filepath: keysFilepath
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
module.exports = upsertEnvKey
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
const { execFileSync } = require('child_process')
|
|
2
|
-
const nativeStoreError = require('./nativeStoreError')
|
|
3
|
-
|
|
4
|
-
const POWERSHELL_BIN = 'powershell.exe'
|
|
5
|
-
const SERVICE = 'dotenvx'
|
|
6
|
-
|
|
7
|
-
const script = `
|
|
8
|
-
$ErrorActionPreference = 'Stop'
|
|
9
|
-
|
|
10
|
-
Add-Type -TypeDefinition @'
|
|
11
|
-
using System;
|
|
12
|
-
using System.ComponentModel;
|
|
13
|
-
using System.Runtime.InteropServices;
|
|
14
|
-
using System.Text;
|
|
15
|
-
|
|
16
|
-
public static class DotenvxCredentialManager
|
|
17
|
-
{
|
|
18
|
-
private const uint CRED_TYPE_GENERIC = 1;
|
|
19
|
-
private const uint CRED_PERSIST_LOCAL_MACHINE = 2;
|
|
20
|
-
private const int ERROR_NOT_FOUND = 1168;
|
|
21
|
-
|
|
22
|
-
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
|
23
|
-
private struct Credential
|
|
24
|
-
{
|
|
25
|
-
public uint Flags;
|
|
26
|
-
public uint Type;
|
|
27
|
-
public string TargetName;
|
|
28
|
-
public string Comment;
|
|
29
|
-
public long LastWritten;
|
|
30
|
-
public uint CredentialBlobSize;
|
|
31
|
-
public IntPtr CredentialBlob;
|
|
32
|
-
public uint Persist;
|
|
33
|
-
public uint AttributeCount;
|
|
34
|
-
public IntPtr Attributes;
|
|
35
|
-
public string TargetAlias;
|
|
36
|
-
public string UserName;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
[DllImport("Advapi32.dll", EntryPoint = "CredWriteW", CharSet = CharSet.Unicode, SetLastError = true)]
|
|
40
|
-
private static extern bool CredWrite(ref Credential credential, uint flags);
|
|
41
|
-
|
|
42
|
-
[DllImport("Advapi32.dll", EntryPoint = "CredReadW", CharSet = CharSet.Unicode, SetLastError = true)]
|
|
43
|
-
private static extern bool CredRead(string target, uint type, uint flags, out IntPtr credentialPtr);
|
|
44
|
-
|
|
45
|
-
[DllImport("Advapi32.dll", EntryPoint = "CredDeleteW", CharSet = CharSet.Unicode, SetLastError = true)]
|
|
46
|
-
private static extern bool CredDelete(string target, uint type, uint flags);
|
|
47
|
-
|
|
48
|
-
[DllImport("Advapi32.dll", SetLastError = true)]
|
|
49
|
-
private static extern void CredFree(IntPtr credentialPtr);
|
|
50
|
-
|
|
51
|
-
public static string Read(string target)
|
|
52
|
-
{
|
|
53
|
-
IntPtr credentialPtr;
|
|
54
|
-
if (!CredRead(target, CRED_TYPE_GENERIC, 0, out credentialPtr))
|
|
55
|
-
{
|
|
56
|
-
int error = Marshal.GetLastWin32Error();
|
|
57
|
-
if (error == ERROR_NOT_FOUND) return null;
|
|
58
|
-
throw new Win32Exception(error);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
try
|
|
62
|
-
{
|
|
63
|
-
Credential credential = (Credential)Marshal.PtrToStructure(credentialPtr, typeof(Credential));
|
|
64
|
-
if (credential.CredentialBlob == IntPtr.Zero || credential.CredentialBlobSize == 0) return null;
|
|
65
|
-
return Marshal.PtrToStringUni(credential.CredentialBlob, (int)credential.CredentialBlobSize / 2);
|
|
66
|
-
}
|
|
67
|
-
finally
|
|
68
|
-
{
|
|
69
|
-
CredFree(credentialPtr);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
public static void Write(string target, string username, string secret)
|
|
74
|
-
{
|
|
75
|
-
IntPtr secretPtr = Marshal.StringToCoTaskMemUni(secret);
|
|
76
|
-
try
|
|
77
|
-
{
|
|
78
|
-
Credential credential = new Credential();
|
|
79
|
-
credential.Type = CRED_TYPE_GENERIC;
|
|
80
|
-
credential.TargetName = target;
|
|
81
|
-
credential.CredentialBlobSize = (uint)Encoding.Unicode.GetByteCount(secret);
|
|
82
|
-
credential.CredentialBlob = secretPtr;
|
|
83
|
-
credential.Persist = CRED_PERSIST_LOCAL_MACHINE;
|
|
84
|
-
credential.UserName = username;
|
|
85
|
-
|
|
86
|
-
if (!CredWrite(ref credential, 0))
|
|
87
|
-
{
|
|
88
|
-
throw new Win32Exception(Marshal.GetLastWin32Error());
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
finally
|
|
92
|
-
{
|
|
93
|
-
Marshal.ZeroFreeCoTaskMemUnicode(secretPtr);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
public static void Delete(string target)
|
|
98
|
-
{
|
|
99
|
-
if (!CredDelete(target, CRED_TYPE_GENERIC, 0))
|
|
100
|
-
{
|
|
101
|
-
throw new Win32Exception(Marshal.GetLastWin32Error());
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
'@
|
|
106
|
-
|
|
107
|
-
$payload = [Console]::In.ReadToEnd() | ConvertFrom-Json
|
|
108
|
-
|
|
109
|
-
if ($payload.action -eq 'read') {
|
|
110
|
-
$secret = [DotenvxCredentialManager]::Read([string]$payload.target)
|
|
111
|
-
if ($null -ne $secret) {
|
|
112
|
-
[Console]::Out.Write($secret)
|
|
113
|
-
}
|
|
114
|
-
} elseif ($payload.action -eq 'write') {
|
|
115
|
-
[DotenvxCredentialManager]::Write([string]$payload.target, [string]$payload.username, [string]$payload.secret)
|
|
116
|
-
} elseif ($payload.action -eq 'delete') {
|
|
117
|
-
[DotenvxCredentialManager]::Delete([string]$payload.target)
|
|
118
|
-
} else {
|
|
119
|
-
throw "unsupported credential action"
|
|
120
|
-
}
|
|
121
|
-
`
|
|
122
|
-
|
|
123
|
-
const encodedScript = Buffer.from(script, 'utf16le').toString('base64')
|
|
124
|
-
|
|
125
|
-
function target (publicKey) {
|
|
126
|
-
return `${SERVICE}:${publicKey}`
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
function run (payload) {
|
|
130
|
-
return execFileSync(POWERSHELL_BIN, ['-NoProfile', '-NonInteractive', '-EncodedCommand', encodedScript], {
|
|
131
|
-
input: JSON.stringify(payload),
|
|
132
|
-
timeout: 10000,
|
|
133
|
-
killSignal: 'SIGKILL',
|
|
134
|
-
encoding: 'utf8',
|
|
135
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
136
|
-
windowsHide: true
|
|
137
|
-
})
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function get (publicKey) {
|
|
141
|
-
try {
|
|
142
|
-
return run({ action: 'read', target: target(publicKey) }).trim() || null
|
|
143
|
-
} catch (error) {
|
|
144
|
-
throw nativeStoreError('failed to read private key from Windows Credential Manager', error)
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function set (publicKey, privateKey) {
|
|
149
|
-
try {
|
|
150
|
-
run({ action: 'write', target: target(publicKey), username: publicKey, secret: privateKey })
|
|
151
|
-
} catch (error) {
|
|
152
|
-
throw nativeStoreError('failed to save private key to Windows Credential Manager', error)
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
module.exports = {
|
|
157
|
-
get,
|
|
158
|
-
set,
|
|
159
|
-
delete (publicKey) {
|
|
160
|
-
try {
|
|
161
|
-
run({ action: 'delete', target: target(publicKey) })
|
|
162
|
-
} catch (error) {
|
|
163
|
-
throw nativeStoreError('failed to delete private key from Windows Credential Manager', error)
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|