@dotenvx/dotenvx 2.31.0 → 2.31.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/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
-
[Unreleased](https://github.com/dotenvx/dotenvx/compare/v2.31.
|
|
5
|
+
[Unreleased](https://github.com/dotenvx/dotenvx/compare/v2.31.1...main)
|
|
6
|
+
|
|
7
|
+
## [2.31.1](https://github.com/dotenvx/dotenvx/compare/v2.31.0...v2.31.1) (2026-09-27)
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
* `armor up` should read for os secret store, 1password, and bitwarden ([#992](https://github.com/dotenvx/dotenvx/pull/992))
|
|
6
12
|
|
|
7
13
|
## [2.31.0](https://github.com/dotenvx/dotenvx/compare/v2.30.0...v2.31.0) (2026-09-27)
|
|
8
14
|
|
package/package.json
CHANGED
|
@@ -43,7 +43,7 @@ function configureArmorCommand (armor) {
|
|
|
43
43
|
// dotenvx armor push
|
|
44
44
|
armor
|
|
45
45
|
.command('push')
|
|
46
|
-
.description('push armored key
|
|
46
|
+
.description('push armored key')
|
|
47
47
|
.option('-f, --env-file <path>', 'path to your env file')
|
|
48
48
|
.option('--token <token>', 'set token')
|
|
49
49
|
.option('--team <team>', 'team to push armored private key for')
|
|
@@ -0,0 +1,68 @@
|
|
|
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 protection = require('./lock')
|
|
6
|
+
const keynames = require('../conventions/keynames')
|
|
7
|
+
const matchesStoredKey = require('../helpers/matchesStoredKey')
|
|
8
|
+
const removeEnvKey = require('../helpers/removeEnvKey')
|
|
9
|
+
const Errors = require('../helpers/errors')
|
|
10
|
+
|
|
11
|
+
function read (filename) {
|
|
12
|
+
try { return fs.readFileSync(filename, 'utf8') } catch (error) {
|
|
13
|
+
if (error.code === 'ENOENT') return undefined
|
|
14
|
+
throw error
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function value (src, name) {
|
|
19
|
+
return src === undefined ? undefined : scan(src).parsed[name]?.at(-1)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Return the originating store with the key, so a move only removes that source.
|
|
23
|
+
// Never look up Armor itself: these operations upload a locally held private key.
|
|
24
|
+
module.exports = async function resolveLocalKey (envFile = '.env', { allowMissing = false } = {}) {
|
|
25
|
+
const src = read(envFile)
|
|
26
|
+
const { publicKeyName, privateKeyName } = keynames(envFile, src || '')
|
|
27
|
+
let publicKey = value(src, publicKeyName)
|
|
28
|
+
if (allowMissing && !publicKey) {
|
|
29
|
+
if (src === undefined) throw new Errors({ envFilepath: envFile }).missingEnvFile()
|
|
30
|
+
throw new Errors({ key: publicKeyName }).missingKey()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function result (stored, remove, reread) {
|
|
34
|
+
// A file-only push remains supported, including password-locked keys.
|
|
35
|
+
if (!publicKey) publicKey = stored.startsWith('locked:') ? stored.split(':')[1] : derive(stored)
|
|
36
|
+
if (!matchesStoredKey(publicKey, stored)) throw new Error('private key does not match the .env public key')
|
|
37
|
+
const privateKey = (await protection.unlock(publicKey, { [publicKey]: stored }))[publicKey]
|
|
38
|
+
return {
|
|
39
|
+
publicKey,
|
|
40
|
+
privateKey,
|
|
41
|
+
privateKeyName,
|
|
42
|
+
async remove () {
|
|
43
|
+
if (await reread() !== stored) throw new Error('private key changed during upload; original storage was not modified')
|
|
44
|
+
await remove()
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const files = [...new Set([path.resolve(path.dirname(envFile), '.env.keys'), path.resolve('.env.keys')])]
|
|
50
|
+
for (const filename of files) {
|
|
51
|
+
const stored = value(read(filename), privateKeyName)
|
|
52
|
+
if (stored) return result(stored, () => removeEnvKey(privateKeyName, filename), () => value(read(filename), privateKeyName))
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (publicKey) {
|
|
56
|
+
for (const id of ['native', 'onepassword', 'bitwarden']) {
|
|
57
|
+
const custodian = custodians.get(id)
|
|
58
|
+
if (!custodian.enabled() || (custodian.configured && !custodian.configured())) continue
|
|
59
|
+
const stored = (await custodian.get(publicKey))?.[publicKey]
|
|
60
|
+
if (stored) return result(stored, () => custodian.delete(publicKey), async () => (await custodian.get(publicKey))?.[publicKey])
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Up can be repeated for a key already held by Armor; the server verifies it.
|
|
65
|
+
if (allowMissing) return { publicKey, privateKeyName, remove: async () => {} }
|
|
66
|
+
if (!publicKey && src === undefined) throw new Errors({ envFilepath: '.env.keys' }).missingEnvFile()
|
|
67
|
+
throw new Error(`private key ${privateKeyName} not found in .env.keys, OS secret storage, 1Password, or Bitwarden`)
|
|
68
|
+
}
|
|
@@ -1,19 +1,9 @@
|
|
|
1
|
-
const { derive } = require('@dotenvx/primitives')
|
|
2
1
|
const prompts = require('../helpers/prompts')
|
|
2
|
+
const resolveLocalKey = require('../custodians/resolveLocalKey')
|
|
3
3
|
const PostArmorPush = require('../api/postArmorPush')
|
|
4
|
-
const keynames = require('../conventions/keynames')
|
|
5
|
-
const readEnvKey = require('../helpers/readEnvKey')
|
|
6
4
|
const teamChoicesFromMeta = require('../helpers/teamChoicesFromMeta')
|
|
7
5
|
const isTeamRequiredError = require('../helpers/isTeamRequiredError')
|
|
8
6
|
|
|
9
|
-
function publicKeyFromPrivateKey (privateKey) {
|
|
10
|
-
try {
|
|
11
|
-
return derive(privateKey)
|
|
12
|
-
} catch {
|
|
13
|
-
return ''
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
7
|
class ArmorPush {
|
|
18
8
|
constructor (hostname, token, devicePublicKey, envFile = '.env', team = undefined) {
|
|
19
9
|
this.hostname = hostname
|
|
@@ -30,10 +20,8 @@ class ArmorPush {
|
|
|
30
20
|
const envFile = this.envFile
|
|
31
21
|
const team = this.team
|
|
32
22
|
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
const privateKey = readEnvKey(privateKeyName, '.env.keys', { strict: true })
|
|
36
|
-
const publicKey = publicKeyFromPrivateKey(privateKey)
|
|
23
|
+
const source = await resolveLocalKey(envFile)
|
|
24
|
+
const { publicKey, privateKey, privateKeyName } = source
|
|
37
25
|
|
|
38
26
|
let json
|
|
39
27
|
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
const prompts = require('../helpers/prompts')
|
|
2
|
+
const resolveLocalKey = require('../custodians/resolveLocalKey')
|
|
2
3
|
const PostArmorUp = require('../api/postArmorUp')
|
|
3
|
-
const keynames = require('../conventions/keynames')
|
|
4
|
-
const removeEnvKey = require('../helpers/removeEnvKey')
|
|
5
|
-
const readEnvKey = require('../helpers/readEnvKey')
|
|
6
4
|
const teamChoicesFromMeta = require('../helpers/teamChoicesFromMeta')
|
|
7
5
|
const isTeamRequiredError = require('../helpers/isTeamRequiredError')
|
|
8
6
|
|
|
@@ -22,13 +20,8 @@ class ArmorUp {
|
|
|
22
20
|
const envFile = this.envFile
|
|
23
21
|
const team = this.team
|
|
24
22
|
|
|
25
|
-
const {
|
|
26
|
-
|
|
27
|
-
privateKeyName
|
|
28
|
-
} = keynames(envFile)
|
|
29
|
-
|
|
30
|
-
const publicKey = readEnvKey(publicKeyName, envFile, { strict: true, ignore: ['MISSING_PRIVATE_KEY'] })
|
|
31
|
-
const privateKey = readEnvKey(privateKeyName, '.env.keys', { strict: true, ignore: ['MISSING_KEY'] })
|
|
23
|
+
const source = await resolveLocalKey(envFile, { allowMissing: true })
|
|
24
|
+
const { publicKey, privateKey, privateKeyName } = source
|
|
32
25
|
|
|
33
26
|
let json
|
|
34
27
|
|
|
@@ -59,11 +52,11 @@ class ArmorUp {
|
|
|
59
52
|
}
|
|
60
53
|
}
|
|
61
54
|
|
|
62
|
-
|
|
55
|
+
await source.remove()
|
|
63
56
|
|
|
64
57
|
return {
|
|
65
58
|
...json,
|
|
66
|
-
changed: json.changed,
|
|
59
|
+
changed: Boolean(json.changed || privateKey),
|
|
67
60
|
privateKeyName,
|
|
68
61
|
privateKeyValue: json.private_key,
|
|
69
62
|
publicKeyValue: publicKey
|