@dotenvx/dotenvx 2.36.0 → 2.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -1
- package/package.json +3 -3
- package/src/cli/actions/keypair.js +4 -0
- package/src/cli/actions/set.js +2 -34
- package/src/lib/api/getConnectionResources.js +21 -0
- package/src/lib/api/getTeamConnections.js +27 -0
- package/src/lib/api/getTeamServices.js +23 -0
- package/src/lib/api/postArmorUp.js +4 -2
- package/src/lib/api/postConnectionKeypair.js +23 -0
- package/src/lib/api/teamConnectionSetup.js +31 -0
- package/src/lib/custodians/managed/armor/store.js +5 -2
- package/src/lib/helpers/enclavedHint.js +11 -0
- package/src/lib/helpers/http.js +8 -1
- package/src/lib/helpers/keypairMetadata.js +13 -0
- package/src/lib/helpers/logSetSummary.js +21 -0
- package/src/lib/helpers/prompts.js +12 -3
- package/src/lib/helpers/selectConnection.js +51 -0
- package/src/lib/helpers/selectConnectionResource.js +41 -0
- package/src/lib/helpers/selectKeyStorage.js +68 -0
- package/src/lib/helpers/storeKeyStorage.js +22 -1
- package/src/lib/main.js +2 -24
- package/src/lib/providers/index.js +7 -1
- package/src/lib/resolvers/envs.js +3 -0
- package/src/lib/resolvers/get.js +5 -1
- package/src/lib/resolvers/keypair.js +25 -6
- package/src/lib/services/armorUp.js +6 -3
- package/src/lib/transforms/decrypt.js +2 -0
- package/src/lib/transforms/encrypt.js +4 -9
- package/src/lib/transforms/set.js +8 -10
- package/src/lib/helpers/isNetworkError.js +0 -21
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,20 @@
|
|
|
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.
|
|
5
|
+
[Unreleased](https://github.com/dotenvx/dotenvx/compare/v2.37.0...main)
|
|
6
|
+
|
|
7
|
+
## [2.37.0](https://github.com/dotenvx/dotenvx/compare/v2.36.0...v2.37.0) (2026-10-15)
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
* New: Dotenvx Armor Enclaved Keys - software enclaved on the remote provider like Vercel, GitHub Actions, and more. ([#1026](https://github.com/dotenvx/dotenvx/pull/1026))
|
|
12
|
+
|
|
13
|
+
```text
|
|
14
|
+
⛨ Choose key type …
|
|
15
|
+
⛨ Armored
|
|
16
|
+
❯ ◊ Enclaved
|
|
17
|
+
```
|
|
18
|
+
|
|
6
19
|
|
|
7
20
|
## [2.36.0](https://github.com/dotenvx/dotenvx/compare/v2.35.0...v2.36.0) (2026-10-14)
|
|
8
21
|
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.
|
|
2
|
+
"version": "2.37.0",
|
|
3
3
|
"name": "@dotenvx/dotenvx",
|
|
4
4
|
"description": "a secure dotenv–from the creator of `dotenv`",
|
|
5
5
|
"author": "@motdotla",
|
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
},
|
|
54
54
|
"funding": "https://dotenvx.com",
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@dotenvx/primitives": "^3.3.
|
|
57
|
-
"@dotenvx/providers": "^0.3.
|
|
56
|
+
"@dotenvx/primitives": "^3.3.1",
|
|
57
|
+
"@dotenvx/providers": "^0.3.8",
|
|
58
58
|
"@dotenvx/tooling": "^1.0.5",
|
|
59
59
|
"undici": "^6.28.1",
|
|
60
60
|
"write-file-atomic": "^5.0.1",
|
|
@@ -17,7 +17,9 @@ async function keypair (key) {
|
|
|
17
17
|
const prettyPrint = options.prettyPrint || options.pp
|
|
18
18
|
|
|
19
19
|
try {
|
|
20
|
+
const errors = []
|
|
20
21
|
const keypairs = await keypairResolver({
|
|
22
|
+
onError: error => errors.push(error),
|
|
21
23
|
includeProvider: key === 'provider' || (!key && !['shell', 'colon'].includes(options.format)),
|
|
22
24
|
envFile: options.envFile,
|
|
23
25
|
envKeysFile: options.envKeysFile,
|
|
@@ -37,6 +39,7 @@ async function keypair (key) {
|
|
|
37
39
|
const results = key ? keypairs[key] : keypairs
|
|
38
40
|
|
|
39
41
|
if (spinner) spinner.stop()
|
|
42
|
+
errors.forEach(catchAndLog)
|
|
40
43
|
if (typeof results === 'object' && results !== null) {
|
|
41
44
|
if (options.format === 'shell') {
|
|
42
45
|
let inline = ''
|
|
@@ -73,6 +76,7 @@ async function keypair (key) {
|
|
|
73
76
|
console.log(results)
|
|
74
77
|
}
|
|
75
78
|
}
|
|
79
|
+
return { exitCode: errors.length > 0 ? 1 : 0, errorCount: errors.length }
|
|
76
80
|
} catch (error) {
|
|
77
81
|
if (spinner) spinner.stop()
|
|
78
82
|
catchAndLog(error)
|
package/src/cli/actions/set.js
CHANGED
|
@@ -2,6 +2,7 @@ const fsx = require('./../../lib/helpers/fsx')
|
|
|
2
2
|
const { logger } = require('./../../shared/logger')
|
|
3
3
|
|
|
4
4
|
const setTransform = require('./../../lib/transforms/set')
|
|
5
|
+
const logSetSummary = require('../../lib/helpers/logSetSummary')
|
|
5
6
|
|
|
6
7
|
const catchAndLog = require('../../lib/helpers/catchAndLog')
|
|
7
8
|
const createSpinner = require('../../lib/helpers/createSpinner')
|
|
@@ -88,40 +89,7 @@ async function set (key, value) {
|
|
|
88
89
|
}
|
|
89
90
|
}
|
|
90
91
|
|
|
91
|
-
|
|
92
|
-
// const remoteKeyAddedEnv = processedEnvs.find((processedEnv) => processedEnv.remotePrivateKeyAdded)
|
|
93
|
-
// let keyAddedSuffix = ''
|
|
94
|
-
// if (remoteKeyAddedEnv) {
|
|
95
|
-
// keyAddedSuffix = ' · armored ⛨'
|
|
96
|
-
// }
|
|
97
|
-
|
|
98
|
-
if (changedFilepaths.length > 0) {
|
|
99
|
-
let msg = `◇ set ${key} (${changedFilepaths.join(',')})`
|
|
100
|
-
if (encrypt) {
|
|
101
|
-
msg = `◈ encrypted ${key} (${changedFilepaths.join(',')})`
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
logger.success(msg)
|
|
105
|
-
|
|
106
|
-
// if (encrypt) {
|
|
107
|
-
// logger.success(`◈ encrypted ${key} (${changedFilepaths.join(',')})${keyAddedSuffix}`)
|
|
108
|
-
// } else {
|
|
109
|
-
// logger.success(`◇ set ${key} (${changedFilepaths.join(',')})`)
|
|
110
|
-
// }
|
|
111
|
-
} else if (unchangedFilepaths.length > 0) {
|
|
112
|
-
logger.info(`○ no change (${unchangedFilepaths})`)
|
|
113
|
-
} else {
|
|
114
|
-
// do nothing - scenario when no .env files found
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// } else if (encrypt && localKeyAddedEnv) {
|
|
118
|
-
// const localKeyAddedEnvFilepath = localKeyAddedEnv.envFilepath || changedFilepaths[0] || '.env'
|
|
119
|
-
// logger.success(`◈ encrypted ${key} (${localKeyAddedEnvFilepath})${keyAddedSuffix}`)
|
|
120
|
-
// } else if (unchangedFilepaths.length > 0) {
|
|
121
|
-
// logger.info(`○ no change (${unchangedFilepaths})`)
|
|
122
|
-
// } else {
|
|
123
|
-
// // do nothing
|
|
124
|
-
// }
|
|
92
|
+
await logSetSummary(key, encrypt, { processedEnvs, changedFilepaths, unchangedFilepaths })
|
|
125
93
|
|
|
126
94
|
return { exitCode: errorCount > 0 ? 1 : 0, errorCount }
|
|
127
95
|
} catch (error) {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const { http } = require('../helpers/http')
|
|
2
|
+
const buildApiError = require('../helpers/buildApiError')
|
|
3
|
+
const normalizeToken = require('../helpers/normalizeToken')
|
|
4
|
+
|
|
5
|
+
class GetConnectionResources {
|
|
6
|
+
constructor (hostname, token, team, connectionId) {
|
|
7
|
+
this.url = `${hostname}/api/teams/${encodeURIComponent(team)}/connections/${encodeURIComponent(connectionId)}/resources`
|
|
8
|
+
this.token = token
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async run (query = '') {
|
|
12
|
+
const response = await http(`${this.url}?${new URLSearchParams({ q: query })}`, {
|
|
13
|
+
method: 'GET', headers: { Authorization: `Bearer ${normalizeToken(this.token)}` }
|
|
14
|
+
})
|
|
15
|
+
const json = await response.body.json()
|
|
16
|
+
if (response.statusCode >= 400) throw buildApiError(response.statusCode, json)
|
|
17
|
+
return json
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = GetConnectionResources
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const { http } = require('../helpers/http')
|
|
2
|
+
const buildApiError = require('../helpers/buildApiError')
|
|
3
|
+
const normalizeToken = require('../helpers/normalizeToken')
|
|
4
|
+
|
|
5
|
+
class GetTeamConnections {
|
|
6
|
+
constructor (hostname, token, team, service) {
|
|
7
|
+
Object.assign(this, { hostname, token, team, service })
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async run () {
|
|
11
|
+
const connections = []
|
|
12
|
+
let page = 1
|
|
13
|
+
while (page) {
|
|
14
|
+
const query = new URLSearchParams({ service: this.service, page })
|
|
15
|
+
const response = await http(`${this.hostname}/api/teams/${encodeURIComponent(this.team)}/connections?${query}`, {
|
|
16
|
+
method: 'GET', headers: { Authorization: `Bearer ${normalizeToken(this.token)}` }
|
|
17
|
+
})
|
|
18
|
+
const json = await response.body.json()
|
|
19
|
+
if (response.statusCode >= 400) throw buildApiError(response.statusCode, json)
|
|
20
|
+
connections.push(...json.connections)
|
|
21
|
+
page = json.meta && json.meta.next_page
|
|
22
|
+
}
|
|
23
|
+
return { connections }
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = GetTeamConnections
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const { http } = require('../helpers/http')
|
|
2
|
+
const buildApiError = require('../helpers/buildApiError')
|
|
3
|
+
const normalizeToken = require('../helpers/normalizeToken')
|
|
4
|
+
|
|
5
|
+
class GetTeamServices {
|
|
6
|
+
constructor (hostname, token, team) {
|
|
7
|
+
this.hostname = hostname
|
|
8
|
+
this.token = token
|
|
9
|
+
this.team = team
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async run () {
|
|
13
|
+
const resp = await http(`${this.hostname}/api/teams/${encodeURIComponent(this.team)}/services`, {
|
|
14
|
+
method: 'GET',
|
|
15
|
+
headers: { Authorization: `Bearer ${normalizeToken(this.token)}` }
|
|
16
|
+
})
|
|
17
|
+
const json = await resp.body.json()
|
|
18
|
+
if (resp.statusCode >= 400) throw buildApiError(resp.statusCode, json)
|
|
19
|
+
return json
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = GetTeamServices
|
|
@@ -4,13 +4,14 @@ const packageJson = require('../helpers/packageJson')
|
|
|
4
4
|
const normalizeToken = require('../helpers/normalizeToken')
|
|
5
5
|
|
|
6
6
|
class PostArmorUp {
|
|
7
|
-
constructor (hostname, token, devicePublicKey, publicKey, privateKey, team) {
|
|
7
|
+
constructor (hostname, token, devicePublicKey, publicKey, privateKey, team, metadata) {
|
|
8
8
|
this.hostname = hostname
|
|
9
9
|
this.token = token
|
|
10
10
|
this.devicePublicKey = devicePublicKey
|
|
11
11
|
this.publicKey = publicKey
|
|
12
12
|
this.privateKey = privateKey
|
|
13
13
|
this.team = team
|
|
14
|
+
this.metadata = metadata
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
async run () {
|
|
@@ -26,7 +27,8 @@ class PostArmorUp {
|
|
|
26
27
|
cli_version: packageJson.version,
|
|
27
28
|
public_key: publicKey,
|
|
28
29
|
private_key: privateKey,
|
|
29
|
-
team
|
|
30
|
+
team,
|
|
31
|
+
metadata: this.metadata
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
const resp = await http(url, {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const { http } = require('../helpers/http')
|
|
2
|
+
const buildApiError = require('../helpers/buildApiError')
|
|
3
|
+
const normalizeToken = require('../helpers/normalizeToken')
|
|
4
|
+
|
|
5
|
+
class PostConnectionKeypair {
|
|
6
|
+
constructor (hostname, token, selection, privateKeyName) {
|
|
7
|
+
Object.assign(this, { hostname, token, selection, privateKeyName })
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async run () {
|
|
11
|
+
const { team, connectionId, resourceId } = this.selection
|
|
12
|
+
const response = await http(`${this.hostname}/api/teams/${encodeURIComponent(team)}/connections/${encodeURIComponent(connectionId)}/keypairs`, {
|
|
13
|
+
method: 'POST',
|
|
14
|
+
headers: { Authorization: `Bearer ${normalizeToken(this.token)}`, 'Content-Type': 'application/json' },
|
|
15
|
+
body: JSON.stringify({ resource_id: resourceId, private_key_name: this.privateKeyName })
|
|
16
|
+
})
|
|
17
|
+
const json = await response.body.json()
|
|
18
|
+
if (response.statusCode >= 400) throw buildApiError(response.statusCode, json)
|
|
19
|
+
return json
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = PostConnectionKeypair
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const { http } = require('../helpers/http')
|
|
2
|
+
const buildApiError = require('../helpers/buildApiError')
|
|
3
|
+
const normalizeToken = require('../helpers/normalizeToken')
|
|
4
|
+
|
|
5
|
+
class TeamConnectionSetup {
|
|
6
|
+
constructor (hostname, token, team) {
|
|
7
|
+
this.url = `${hostname}/api/teams/${encodeURIComponent(team)}/connections/setup`
|
|
8
|
+
this.token = token
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async request (suffix, options) {
|
|
12
|
+
const response = await http(`${this.url}${suffix}`, {
|
|
13
|
+
...options,
|
|
14
|
+
headers: { Authorization: `Bearer ${normalizeToken(this.token)}`, 'Content-Type': 'application/json' },
|
|
15
|
+
signal: AbortSignal.timeout(30000)
|
|
16
|
+
})
|
|
17
|
+
const json = await response.body.json()
|
|
18
|
+
if (response.statusCode >= 400) throw buildApiError(response.statusCode, json)
|
|
19
|
+
return json
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
create (service) {
|
|
23
|
+
return this.request('', { method: 'POST', body: JSON.stringify({ service }) })
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
status (id) {
|
|
27
|
+
return this.request(`/${encodeURIComponent(id)}`, { method: 'GET' })
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = TeamConnectionSetup
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const keypairMetadata = require('../../../helpers/keypairMetadata')
|
|
1
2
|
const Session = require('../../../../db/session')
|
|
2
3
|
const PostArmorUp = require('../../../api/postArmorUp')
|
|
3
4
|
const prompts = require('../../../helpers/prompts')
|
|
@@ -10,8 +11,10 @@ async function store (publicKey, privateKey, context = {}) {
|
|
|
10
11
|
const token = context.token || sesh.token()
|
|
11
12
|
const devicePublicKey = sesh.devicePublicKey()
|
|
12
13
|
|
|
14
|
+
const metadata = keypairMetadata.file(context.envFilepath)
|
|
15
|
+
|
|
13
16
|
try {
|
|
14
|
-
await new PostArmorUp(hostname, token, devicePublicKey, publicKey, privateKey, undefined).run()
|
|
17
|
+
await new PostArmorUp(hostname, token, devicePublicKey, publicKey, privateKey, undefined, metadata).run()
|
|
15
18
|
} catch (error) {
|
|
16
19
|
if (!isTeamRequiredError(error)) {
|
|
17
20
|
throw error
|
|
@@ -38,7 +41,7 @@ async function store (publicKey, privateKey, context = {}) {
|
|
|
38
41
|
throw error
|
|
39
42
|
}
|
|
40
43
|
|
|
41
|
-
await new PostArmorUp(hostname, token, devicePublicKey, publicKey, privateKey, team).run()
|
|
44
|
+
await new PostArmorUp(hostname, token, devicePublicKey, publicKey, privateKey, team, metadata).run()
|
|
42
45
|
}
|
|
43
46
|
}
|
|
44
47
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const escape = require('./escape')
|
|
2
|
+
|
|
3
|
+
function enclavedHint (error, envFilepath) {
|
|
4
|
+
if (error?.code !== 'ENCLAVED' || !envFilepath) return error
|
|
5
|
+
const file = /^[a-zA-Z0-9_./-]+$/.test(envFilepath) ? envFilepath : escape(envFilepath)
|
|
6
|
+
error.help = `hint: [dotenvx armor open -f ${file}]`
|
|
7
|
+
error.messageWithHelp = `${error.message}. ${error.help}`
|
|
8
|
+
return error
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
module.exports = enclavedHint
|
package/src/lib/helpers/http.js
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
const { request } = require('@dotenvx/tooling')
|
|
2
|
+
const { isNetworkError } = require('@dotenvx/providers')
|
|
2
3
|
|
|
3
4
|
async function http (url, opts = {}) {
|
|
4
|
-
|
|
5
|
+
try {
|
|
6
|
+
return await request(url, opts)
|
|
7
|
+
} catch (error) {
|
|
8
|
+
if (!isNetworkError(error)) throw error
|
|
9
|
+
const code = error.code || error.cause?.code || 'NETWORK_ERROR'
|
|
10
|
+
throw Object.assign(new Error(`[${code}] unable to connect to ${new URL(url).origin}. Check your connection and that the server is running.`), { code, cause: error })
|
|
11
|
+
}
|
|
5
12
|
}
|
|
6
13
|
|
|
7
14
|
module.exports = { http }
|
|
@@ -74,4 +74,17 @@ function keypairMetadata (envFile = '.env', metadata = undefined) {
|
|
|
74
74
|
})
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
// Descriptive upload context must never prevent storing a key.
|
|
78
|
+
keypairMetadata.file = function (envFile = '.env') {
|
|
79
|
+
try {
|
|
80
|
+
return compact({
|
|
81
|
+
filepath: normalizeFilepath(envFile),
|
|
82
|
+
filename: canonicalEnvFilename(envFile),
|
|
83
|
+
project_name: projectName()
|
|
84
|
+
})
|
|
85
|
+
} catch (_) {
|
|
86
|
+
return {}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
77
90
|
module.exports = keypairMetadata
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const { publickeys, injectsummary } = require('@dotenvx/primitives')
|
|
2
|
+
const { logger } = require('../../shared/logger')
|
|
3
|
+
|
|
4
|
+
function logSetSummary (key, encrypt, result) {
|
|
5
|
+
const { processedEnvs, changedFilepaths, unchangedFilepaths } = result
|
|
6
|
+
const rows = new Map(processedEnvs.map(row => [row.envFilepath, {
|
|
7
|
+
filepath: `(${row.envFilepath})`,
|
|
8
|
+
publicKeys: publickeys(row.envSrc || ''),
|
|
9
|
+
keySources: row.keySources
|
|
10
|
+
}]))
|
|
11
|
+
const paths = changedFilepaths.length ? changedFilepaths : unchangedFilepaths
|
|
12
|
+
if (!paths.length) return
|
|
13
|
+
const summary = encrypt ? injectsummary.sources(paths.map(filepath => rows.get(filepath) || `(${filepath})`)) : { files: [`(${paths.join(',')})`], suffix: '' }
|
|
14
|
+
if (changedFilepaths.length) {
|
|
15
|
+
logger.success(`${encrypt ? '◈ encrypted' : '◇ set'} ${key} ${summary.files.join(',')}${summary.suffix}`)
|
|
16
|
+
} else {
|
|
17
|
+
logger.info(`○ no change ${summary.files.join(',')}${summary.suffix}`)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = logSetSummary
|
|
@@ -40,17 +40,18 @@ function clearLastLine (stream) {
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
async function select ({ message, choices, navigation, backValue, initial, prefix }, context) {
|
|
43
|
+
async function select ({ message, choices, navigation, backValue, initial, prefix, footer }, context) {
|
|
44
44
|
try {
|
|
45
45
|
if (navigation) {
|
|
46
46
|
const CustodySelect = require('./custodySelect')
|
|
47
|
-
return await new CustodySelect({ message, choices: choicesForSelect(choices), backValue, initial, ...(prefix ? { symbols: { prefix: { pending: prefix } } } : {}), ...enquirerOptions(context) }).run()
|
|
47
|
+
return await new CustodySelect({ message, choices: choicesForSelect(choices), backValue, initial, footer, ...(prefix ? { symbols: { prefix: { pending: prefix } } } : {}), ...enquirerOptions(context) }).run()
|
|
48
48
|
}
|
|
49
49
|
const answer = await enquirer.prompt({
|
|
50
50
|
type: 'select',
|
|
51
51
|
name: 'value',
|
|
52
52
|
...(prefix ? { symbols: { prefix: { pending: prefix } } } : {}),
|
|
53
53
|
message,
|
|
54
|
+
footer,
|
|
54
55
|
choices: choicesForSelect(choices),
|
|
55
56
|
...enquirerOptions(context)
|
|
56
57
|
})
|
|
@@ -85,11 +86,19 @@ async function multiselect ({ message, choices, initial = [], submitLabel }, con
|
|
|
85
86
|
}
|
|
86
87
|
}
|
|
87
88
|
|
|
88
|
-
async function input ({ message }, context) {
|
|
89
|
+
async function input ({ message, initial }, context) {
|
|
89
90
|
try {
|
|
90
91
|
const answer = await enquirer.prompt({
|
|
91
92
|
type: 'input',
|
|
92
93
|
name: 'value',
|
|
94
|
+
...(initial !== undefined
|
|
95
|
+
? {
|
|
96
|
+
onRun () {
|
|
97
|
+
this.input = String(initial)
|
|
98
|
+
this.cursor = this.input.length
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
: {}),
|
|
93
102
|
message,
|
|
94
103
|
...enquirerOptions(context)
|
|
95
104
|
})
|
|
@@ -0,0 +1,51 @@
|
|
|
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
|
|
@@ -0,0 +1,41 @@
|
|
|
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,6 +1,11 @@
|
|
|
1
1
|
const prompts = require('./prompts')
|
|
2
2
|
const custodians = require('../custodians')
|
|
3
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')
|
|
4
9
|
|
|
5
10
|
const nativeNames = { darwin: 'macOS Keychain', win32: 'Windows Credential Manager', linux: 'Linux Secret Service' }
|
|
6
11
|
|
|
@@ -63,6 +68,69 @@ async function selectKeyStorage (options = {}) {
|
|
|
63
68
|
if (!entries.some(choice => choice.value === storage)) throw new Error('Invalid private key storage selection')
|
|
64
69
|
}
|
|
65
70
|
if (setup.has(storage)) throw new Error(setup.get(storage))
|
|
71
|
+
if (storage === 'armored') {
|
|
72
|
+
while (true) {
|
|
73
|
+
const keyType = await prompts.select({
|
|
74
|
+
message: 'Choose key type',
|
|
75
|
+
prefix: '⛨',
|
|
76
|
+
choices: [
|
|
77
|
+
{ name: '⛨ Armored', value: 'armored' },
|
|
78
|
+
{ name: '◊ Enclaved', value: 'enclaved' },
|
|
79
|
+
{ name: '← back', value: '__back' }
|
|
80
|
+
],
|
|
81
|
+
initial: 'armored',
|
|
82
|
+
navigation: true,
|
|
83
|
+
backValue: '__back'
|
|
84
|
+
}, context)
|
|
85
|
+
if (keyType === '__back') {
|
|
86
|
+
initial = 'armored'
|
|
87
|
+
break
|
|
88
|
+
}
|
|
89
|
+
if (keyType === 'enclaved') {
|
|
90
|
+
const session = new Session()
|
|
91
|
+
const { teams } = await new GetTeams(session.hostname(), options.token || session.token()).run()
|
|
92
|
+
if (!teams.length) throw new Error('No teams available for enclave keys')
|
|
93
|
+
const choices = teams.map(team => ({ name: team.slug, value: team.slug }))
|
|
94
|
+
while (true) {
|
|
95
|
+
const team = await prompts.select({
|
|
96
|
+
message: 'Select team',
|
|
97
|
+
prefix: '◊',
|
|
98
|
+
choices: [...choices, { name: '← back', value: '__back' }],
|
|
99
|
+
navigation: true,
|
|
100
|
+
backValue: '__back'
|
|
101
|
+
}, context)
|
|
102
|
+
if (team === '__back') break
|
|
103
|
+
if (!choices.some(choice => choice.value === team)) throw new Error('Invalid team selection')
|
|
104
|
+
const { services } = await new GetTeamServices(session.hostname(), options.token || session.token(), team).run()
|
|
105
|
+
if (!services.length) throw new Error('No services available for this team')
|
|
106
|
+
const serviceChoices = services.map(service => ({ name: service.name, value: service.slug }))
|
|
107
|
+
while (true) {
|
|
108
|
+
const service = await prompts.select({
|
|
109
|
+
message: 'Select service',
|
|
110
|
+
prefix: '◊',
|
|
111
|
+
choices: [...serviceChoices, { name: '← back', value: '__back' }],
|
|
112
|
+
navigation: true,
|
|
113
|
+
backValue: '__back'
|
|
114
|
+
}, context)
|
|
115
|
+
if (service === '__back') break
|
|
116
|
+
if (!serviceChoices.some(choice => choice.value === service)) throw new Error('Invalid service selection')
|
|
117
|
+
const selectedService = services.find(item => item.slug === service)
|
|
118
|
+
while (true) {
|
|
119
|
+
const connection = await selectConnection(session.hostname(), options.token || session.token(), team, selectedService, context)
|
|
120
|
+
if (!connection) break
|
|
121
|
+
const resource = await selectConnectionResource(session.hostname(), options.token || session.token(), team, connection, context)
|
|
122
|
+
if (!resource) continue
|
|
123
|
+
return { id: 'enclaved', team, service, connectionId: connection.id, resourceId: resource.id }
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
continue
|
|
128
|
+
}
|
|
129
|
+
if (keyType !== 'armored') throw new Error('Invalid key type selection')
|
|
130
|
+
return storage
|
|
131
|
+
}
|
|
132
|
+
continue
|
|
133
|
+
}
|
|
66
134
|
return storage
|
|
67
135
|
}
|
|
68
136
|
} finally {
|
|
@@ -1,13 +1,34 @@
|
|
|
1
1
|
const selectKeyStorage = require('./selectKeyStorage')
|
|
2
|
+
const prompts = require('./prompts')
|
|
3
|
+
const createSpinner = require('./createSpinner')
|
|
2
4
|
const custodians = require('../custodians')
|
|
5
|
+
const { keypair, encrypt } = require('@dotenvx/primitives')
|
|
6
|
+
const Session = require('../../db/session')
|
|
7
|
+
const PostConnectionKeypair = require('../api/postConnectionKeypair')
|
|
3
8
|
|
|
4
9
|
async function storeKeyStorage (storage, publicKey, privateKey, options, context) {
|
|
5
10
|
context.allowCustodyBack = true
|
|
6
11
|
while (true) {
|
|
7
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())
|
|
8
29
|
try {
|
|
9
30
|
const stored = await custodians.store(storage, publicKey, privateKey, context)
|
|
10
|
-
return { storage, stored }
|
|
31
|
+
return { storage, stored, publicKey }
|
|
11
32
|
} catch (error) {
|
|
12
33
|
if (error.code !== 'KEY_CUSTODY_BACK') throw error
|
|
13
34
|
storage = undefined
|
package/src/lib/main.js
CHANGED
|
@@ -15,6 +15,7 @@ const Session = require('./../db/session')
|
|
|
15
15
|
|
|
16
16
|
// transforms
|
|
17
17
|
const setTransform = require('./transforms/set')
|
|
18
|
+
const logSetSummary = require('./helpers/logSetSummary')
|
|
18
19
|
|
|
19
20
|
// helpers
|
|
20
21
|
const buildEnvs = require('./helpers/buildEnvs')
|
|
@@ -321,30 +322,7 @@ const set = async function (key, value, options = {}, events) {
|
|
|
321
322
|
}
|
|
322
323
|
if (events) events.add({ error_count: processedEnvs.filter(env => env.error).length })
|
|
323
324
|
|
|
324
|
-
|
|
325
|
-
const localKeyAddedEnv = processedEnvs.find((processedEnv) => processedEnv.localPrivateKeyAdded)
|
|
326
|
-
const remoteKeyAddedEnv = processedEnvs.find((processedEnv) => processedEnv.remotePrivateKeyAdded)
|
|
327
|
-
|
|
328
|
-
if (remoteKeyAddedEnv) {
|
|
329
|
-
keyAddedSuffix = ' · armored ⛨'
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
if (changedFilepaths.length > 0) {
|
|
333
|
-
if (encrypt) {
|
|
334
|
-
logger.success(`◈ encrypted ${key} (${changedFilepaths.join(',')})${keyAddedSuffix}`)
|
|
335
|
-
} else {
|
|
336
|
-
logger.success(`◇ set ${key} (${changedFilepaths.join(',')})`)
|
|
337
|
-
}
|
|
338
|
-
} else if (encrypt && localKeyAddedEnv) {
|
|
339
|
-
const keyAddedEnvFilepath = localKeyAddedEnv.envFilepath || changedFilepaths[0] || '.env'
|
|
340
|
-
logger.success(`◈ encrypted ${key} (${keyAddedEnvFilepath})${keyAddedSuffix}`)
|
|
341
|
-
} else if (unchangedFilepaths.length > 0) {
|
|
342
|
-
logger.info(`○ no change (${unchangedFilepaths})`)
|
|
343
|
-
} else {
|
|
344
|
-
// do nothing
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
// intentionally quiet: success line communicates key creation
|
|
325
|
+
await logSetSummary(key, encrypt, { processedEnvs, changedFilepaths, unchangedFilepaths })
|
|
348
326
|
|
|
349
327
|
return {
|
|
350
328
|
processedEnvs,
|
|
@@ -38,7 +38,13 @@ function lookup (publicKey, options, sync) {
|
|
|
38
38
|
const keys = provider(providerOptions)
|
|
39
39
|
|
|
40
40
|
function found (ring) {
|
|
41
|
-
if (!ring[publicKey] && armorError)
|
|
41
|
+
if (!ring[publicKey] && armorError) {
|
|
42
|
+
// This response confirms custody even though the private key cannot be retrieved.
|
|
43
|
+
if (armorError.code === 'ENCLAVED' || (armorError.code === 'BAD_REQUEST' && ['[BAD_REQUEST] private key enclaved ◊', '[BAD_REQUEST] Private key is held exclusively in its remote enclave.'].includes(armorError.message))) {
|
|
44
|
+
if (options.onProvider) options.onProvider('armor', publicKey)
|
|
45
|
+
}
|
|
46
|
+
throw armorError
|
|
47
|
+
}
|
|
42
48
|
if (ring[publicKey] && options.onProvider) {
|
|
43
49
|
options.onProvider(source === 'native' ? nativeNames[process.platform] || source : source, publicKey)
|
|
44
50
|
}
|
|
@@ -6,6 +6,7 @@ const TYPE_ENV = 'env'
|
|
|
6
6
|
const TYPE_ENV_FILE = 'envFile'
|
|
7
7
|
|
|
8
8
|
const Errors = require('./../helpers/errors')
|
|
9
|
+
const enclavedHint = require('../helpers/enclavedHint')
|
|
9
10
|
const detectEncoding = require('./../helpers/detectEncoding')
|
|
10
11
|
const detectEncodingSync = require('./../helpers/detectEncodingSync')
|
|
11
12
|
const keynames = require('./../conventions/keynames')
|
|
@@ -242,6 +243,7 @@ async function injectEnvFile ({ env, overload, processEnv, envKeysFilepath, prov
|
|
|
242
243
|
}
|
|
243
244
|
}
|
|
244
245
|
|
|
246
|
+
for (const error of row.errors || []) enclavedHint(error, env.value)
|
|
245
247
|
return row
|
|
246
248
|
}
|
|
247
249
|
|
|
@@ -303,6 +305,7 @@ function injectEnvFileSync ({ env, overload, processEnv, envKeysFilepath, provid
|
|
|
303
305
|
}
|
|
304
306
|
}
|
|
305
307
|
|
|
308
|
+
for (const error of row.errors || []) enclavedHint(error, env.value)
|
|
306
309
|
return row
|
|
307
310
|
}
|
|
308
311
|
|
package/src/lib/resolvers/get.js
CHANGED
|
@@ -61,12 +61,16 @@ async function get (options = {}) {
|
|
|
61
61
|
const processEnv = { ...(options.processEnv || process.env) }
|
|
62
62
|
const { processedEnvs } = await envsResolver(buildOptions(options, processEnv))
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
const resolved = result({
|
|
65
65
|
key: options.key,
|
|
66
66
|
all: options.all,
|
|
67
67
|
processedEnvs,
|
|
68
68
|
processEnv
|
|
69
69
|
})
|
|
70
|
+
if (options.includeKeySources) {
|
|
71
|
+
resolved.keySources = Object.assign({}, ...processedEnvs.map(row => row.keySources))
|
|
72
|
+
}
|
|
73
|
+
return resolved
|
|
70
74
|
}
|
|
71
75
|
|
|
72
76
|
module.exports = get
|
|
@@ -6,6 +6,7 @@ const filepaths = require('./../conventions/filepaths')
|
|
|
6
6
|
|
|
7
7
|
const { keyring, keyringSync, publickeys } = require('@dotenvx/primitives')
|
|
8
8
|
const providers = require('./../providers')
|
|
9
|
+
const enclavedHint = require('../helpers/enclavedHint')
|
|
9
10
|
|
|
10
11
|
function buildOptions ({ publicKey, processEnv, fk }) {
|
|
11
12
|
const ring = {}
|
|
@@ -45,7 +46,8 @@ async function keypair (options = {}) {
|
|
|
45
46
|
})
|
|
46
47
|
|
|
47
48
|
let origin = 'environment'
|
|
48
|
-
|
|
49
|
+
let confirmedProvider = false
|
|
50
|
+
const provider = await providers({ ...options, onProvider: name => { origin = name; confirmedProvider = true } })
|
|
49
51
|
const keys = file({ fk: keyringOptions.fk })
|
|
50
52
|
keyringOptions.provider = async publicKey => {
|
|
51
53
|
const ring = await keys.get(publicKey)
|
|
@@ -58,10 +60,18 @@ async function keypair (options = {}) {
|
|
|
58
60
|
}
|
|
59
61
|
if (publicKey) keyringOptions.fk = []
|
|
60
62
|
|
|
61
|
-
|
|
63
|
+
let ring
|
|
64
|
+
try {
|
|
65
|
+
ring = await keyring(keyringOptions)
|
|
66
|
+
} catch (error) {
|
|
67
|
+
enclavedHint(error, filepath)
|
|
68
|
+
if (!options.onError) throw error
|
|
69
|
+
options.onError(error)
|
|
70
|
+
ring = {}
|
|
71
|
+
}
|
|
62
72
|
|
|
63
73
|
outputKeypair({ out, filepath, publicKey, ring })
|
|
64
|
-
origins[filepath] = publicKey && ring[publicKey] ? origin : null
|
|
74
|
+
origins[filepath] = publicKey && (ring[publicKey] || confirmedProvider) ? origin : null
|
|
65
75
|
}
|
|
66
76
|
|
|
67
77
|
if (options.includeProvider) {
|
|
@@ -86,7 +96,8 @@ function keypairSync (options = {}) {
|
|
|
86
96
|
fk: options.envKeysFilepath || options.envKeysFile || path.resolve(path.dirname(filepath), '.env.keys')
|
|
87
97
|
})
|
|
88
98
|
let origin = 'environment'
|
|
89
|
-
|
|
99
|
+
let confirmedProvider = false
|
|
100
|
+
const provider = providers.sync({ ...options, onProvider: name => { origin = name; confirmedProvider = true } })
|
|
90
101
|
const keys = file({ fk: keyringOptions.fk })
|
|
91
102
|
keyringOptions.provider = publicKey => {
|
|
92
103
|
const ring = keys.getSync(publicKey)
|
|
@@ -99,10 +110,18 @@ function keypairSync (options = {}) {
|
|
|
99
110
|
}
|
|
100
111
|
if (publicKey) keyringOptions.fk = []
|
|
101
112
|
|
|
102
|
-
|
|
113
|
+
let ring
|
|
114
|
+
try {
|
|
115
|
+
ring = keyringSync(keyringOptions)
|
|
116
|
+
} catch (error) {
|
|
117
|
+
enclavedHint(error, filepath)
|
|
118
|
+
if (!options.onError) throw error
|
|
119
|
+
options.onError(error)
|
|
120
|
+
ring = {}
|
|
121
|
+
}
|
|
103
122
|
|
|
104
123
|
outputKeypair({ out, filepath, publicKey, ring })
|
|
105
|
-
origins[filepath] = publicKey && ring[publicKey] ? origin : null
|
|
124
|
+
origins[filepath] = publicKey && (ring[publicKey] || confirmedProvider) ? origin : null
|
|
106
125
|
}
|
|
107
126
|
|
|
108
127
|
if (options.includeProvider) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const keypairMetadata = require('../helpers/keypairMetadata')
|
|
1
2
|
const prompts = require('../helpers/prompts')
|
|
2
3
|
const resolveLocalKey = require('../custodians/resolveLocalKey')
|
|
3
4
|
const PostArmorUp = require('../api/postArmorUp')
|
|
@@ -23,13 +24,15 @@ class ArmorUp {
|
|
|
23
24
|
const source = await resolveLocalKey(envFile, { allowMissing: true })
|
|
24
25
|
const { publicKey, privateKey, privateKeyName } = source
|
|
25
26
|
|
|
27
|
+
const metadata = keypairMetadata.file(envFile)
|
|
28
|
+
|
|
26
29
|
let json
|
|
27
30
|
|
|
28
31
|
if (team) {
|
|
29
|
-
json = await new PostArmorUp(hostname, token, devicePublicKey, publicKey, privateKey, team).run()
|
|
32
|
+
json = await new PostArmorUp(hostname, token, devicePublicKey, publicKey, privateKey, team, metadata).run()
|
|
30
33
|
} else {
|
|
31
34
|
try {
|
|
32
|
-
json = await new PostArmorUp(hostname, token, devicePublicKey, publicKey, privateKey, undefined).run()
|
|
35
|
+
json = await new PostArmorUp(hostname, token, devicePublicKey, publicKey, privateKey, undefined, metadata).run()
|
|
33
36
|
} catch (error) {
|
|
34
37
|
if (!isTeamRequiredError(error)) {
|
|
35
38
|
throw error
|
|
@@ -49,7 +52,7 @@ class ArmorUp {
|
|
|
49
52
|
})
|
|
50
53
|
}
|
|
51
54
|
|
|
52
|
-
json = await new PostArmorUp(hostname, token, devicePublicKey, publicKey, privateKey, team).run()
|
|
55
|
+
json = await new PostArmorUp(hostname, token, devicePublicKey, publicKey, privateKey, team, metadata).run()
|
|
53
56
|
}
|
|
54
57
|
}
|
|
55
58
|
|
|
@@ -5,6 +5,7 @@ const { upsert } = require('@dotenvx/primitives')
|
|
|
5
5
|
const TYPE_ENV_FILE = 'envFile'
|
|
6
6
|
|
|
7
7
|
const Errors = require('./../helpers/errors')
|
|
8
|
+
const enclavedHint = require('../helpers/enclavedHint')
|
|
8
9
|
const { determine } = require('./../helpers/envResolution')
|
|
9
10
|
const detectEncoding = require('./../helpers/detectEncoding')
|
|
10
11
|
const providers = require('./../providers')
|
|
@@ -83,6 +84,7 @@ async function decrypt (options = {}) {
|
|
|
83
84
|
}
|
|
84
85
|
}
|
|
85
86
|
|
|
87
|
+
enclavedHint(row.error, envFilepath)
|
|
86
88
|
processedEnvs.push(row)
|
|
87
89
|
}
|
|
88
90
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const fsx = require('./../helpers/fsx')
|
|
2
2
|
const path = require('path')
|
|
3
|
-
const { encrypted, encrypt, scan, upsert, publickeys
|
|
3
|
+
const { encrypted, encrypt, scan, upsert, publickeys } = require('@dotenvx/primitives')
|
|
4
4
|
|
|
5
5
|
const TYPE_ENV_FILE = 'envFile'
|
|
6
6
|
const SAMPLE_ENV_KIT = require('../helpers/kits/sample')
|
|
@@ -105,18 +105,13 @@ async function encryptTransform (options = {}) {
|
|
|
105
105
|
let publicKey = publickeys(row.envSrc)[0]
|
|
106
106
|
|
|
107
107
|
if (!publicKey) {
|
|
108
|
-
// upsert public key to .env file
|
|
109
|
-
const kp = keypair() // local
|
|
110
|
-
publicKey = kp.publicKey
|
|
111
|
-
const privateKey = kp.privateKey
|
|
112
108
|
const { publicKeyName, privateKeyName } = keynames(envFilepath)
|
|
113
|
-
const { envSrc } = mutateSrc({ envSrc: row.envSrc, envFilepath, keysFilepath: fk, publicKeyName, publicKeyValue: publicKey })
|
|
114
|
-
row.envSrc = envSrc
|
|
115
|
-
|
|
116
109
|
const comment = path.basename(envFilepath)
|
|
117
110
|
|
|
118
|
-
const result = await storeKeyStorage(storage,
|
|
111
|
+
const result = await storeKeyStorage(storage, undefined, undefined, options, Object.assign(custodyContext, { envFilepath: filepath, keysSrc, privateKeyName, comment, keysFilepath: fk }))
|
|
119
112
|
storage = result.storage
|
|
113
|
+
publicKey = result.publicKey
|
|
114
|
+
row.envSrc = mutateSrc({ envSrc: row.envSrc, envFilepath, keysFilepath: fk, publicKeyName, publicKeyValue: publicKey }).envSrc
|
|
120
115
|
row.keySources = { [publicKey]: Object.prototype.hasOwnProperty.call(result.stored, 'keysSrc') ? 'file' : (typeof storage === 'string' ? storage : storage.id) }
|
|
121
116
|
const stored = result.stored
|
|
122
117
|
if (Object.prototype.hasOwnProperty.call(stored, 'keysSrc')) keysSrc = stored.keysSrc
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const fsx = require('./../helpers/fsx')
|
|
2
2
|
const path = require('path')
|
|
3
|
-
const { encrypt, upsert, publickeys
|
|
3
|
+
const { encrypt, upsert, publickeys } = require('@dotenvx/primitives')
|
|
4
4
|
|
|
5
5
|
const TYPE_ENV_FILE = 'envFile'
|
|
6
6
|
|
|
@@ -74,18 +74,14 @@ async function setTransform (options = {}) {
|
|
|
74
74
|
|
|
75
75
|
// only create if missing public key and encryption needed
|
|
76
76
|
if (!publicKey && !noEncrypt) {
|
|
77
|
-
// upsert public key to .env file
|
|
78
|
-
const kp = keypair() // local
|
|
79
|
-
publicKey = kp.publicKey
|
|
80
|
-
const privateKey = kp.privateKey
|
|
81
77
|
const { publicKeyName, privateKeyName } = keynames(envFilepath)
|
|
82
|
-
const { envSrc } = mutateSrc({ envSrc: row.envSrc, envFilepath, keysFilepath: fk, publicKeyName, publicKeyValue: publicKey })
|
|
83
|
-
row.envSrc = envSrc
|
|
84
|
-
|
|
85
78
|
const comment = path.basename(envFilepath)
|
|
86
79
|
|
|
87
|
-
const result = await storeKeyStorage(storage,
|
|
80
|
+
const result = await storeKeyStorage(storage, undefined, undefined, options, Object.assign(custodyContext, { envFilepath: filepath, keysSrc, privateKeyName, comment, keysFilepath: fk }))
|
|
88
81
|
storage = result.storage
|
|
82
|
+
publicKey = result.publicKey
|
|
83
|
+
row.envSrc = mutateSrc({ envSrc: row.envSrc, envFilepath, keysFilepath: fk, publicKeyName, publicKeyValue: publicKey }).envSrc
|
|
84
|
+
row.keySources = { [publicKey]: Object.prototype.hasOwnProperty.call(result.stored, 'keysSrc') ? 'file' : (typeof storage === 'string' ? storage : storage.id) }
|
|
89
85
|
const stored = result.stored
|
|
90
86
|
if (Object.prototype.hasOwnProperty.call(stored, 'keysSrc')) keysSrc = stored.keysSrc
|
|
91
87
|
if (stored.nativePrivateKeyAdded) row.nativePrivateKeyAdded = true
|
|
@@ -99,7 +95,8 @@ async function setTransform (options = {}) {
|
|
|
99
95
|
}
|
|
100
96
|
} else {
|
|
101
97
|
// expensive additional loop
|
|
102
|
-
const { parsed } = await getResolver({
|
|
98
|
+
const { parsed, keySources } = await getResolver({
|
|
99
|
+
includeKeySources: true,
|
|
103
100
|
key,
|
|
104
101
|
envs: [env],
|
|
105
102
|
all: true,
|
|
@@ -110,6 +107,7 @@ async function setTransform (options = {}) {
|
|
|
110
107
|
noBitwarden: options.noBitwarden
|
|
111
108
|
})
|
|
112
109
|
|
|
110
|
+
row.keySources = row.keySources || keySources
|
|
113
111
|
const before = parsed[key]
|
|
114
112
|
if (value !== before) {
|
|
115
113
|
const encryptedValue = encrypt(publicKey, value)
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
const NETWORK_ERROR_CODES = new Set([
|
|
2
|
-
'ECONNRESET',
|
|
3
|
-
'ECONNREFUSED',
|
|
4
|
-
'ENOTFOUND',
|
|
5
|
-
'ENETDOWN',
|
|
6
|
-
'ENETUNREACH',
|
|
7
|
-
'EHOSTDOWN',
|
|
8
|
-
'EHOSTUNREACH',
|
|
9
|
-
'EPIPE',
|
|
10
|
-
'ETIMEDOUT',
|
|
11
|
-
'UND_ERR_CONNECT_TIMEOUT',
|
|
12
|
-
'UND_ERR_HEADERS_TIMEOUT',
|
|
13
|
-
'UND_ERR_BODY_TIMEOUT',
|
|
14
|
-
'UND_ERR_SOCKET'
|
|
15
|
-
])
|
|
16
|
-
|
|
17
|
-
function isNetworkError (error) {
|
|
18
|
-
return NETWORK_ERROR_CODES.has(error && error.code) || NETWORK_ERROR_CODES.has(error && error.cause && error.cause.code)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
module.exports = isNetworkError
|