@dotenvx/dotenvx 1.75.0 → 2.0.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 +34 -1
- package/README.md +4 -114
- package/package.json +8 -7
- package/src/cli/actions/decrypt.js +35 -17
- package/src/cli/actions/doctor.js +2 -2
- package/src/cli/actions/encrypt.js +64 -85
- package/src/cli/actions/ext/genexample.js +2 -2
- package/src/cli/actions/get.js +16 -7
- package/src/cli/actions/keypair.js +55 -42
- package/src/cli/actions/login.js +4 -3
- package/src/cli/actions/normalizeArmorAliases.js +9 -0
- package/src/cli/actions/run.js +65 -22
- package/src/cli/actions/set.js +51 -37
- package/src/cli/dotenvx.js +6 -21
- package/src/lib/api/{postKeypair.js → postArmorKeyring.js} +4 -14
- package/src/lib/{helpers/envResolution → conventions}/environment.js +1 -1
- package/src/lib/conventions/filepaths.js +9 -0
- package/src/lib/conventions/keynames.js +38 -0
- package/src/lib/helpers/catchAndLog.js +4 -1
- package/src/lib/helpers/cryptography/index.js +1 -12
- package/src/lib/helpers/cryptography/mutateKeysSrc.js +5 -21
- package/src/lib/helpers/envResolution/index.js +1 -1
- package/src/lib/helpers/errors.js +13 -0
- package/src/lib/helpers/executeDynamic.js +1 -3
- package/src/lib/helpers/keypairMetadata.js +3 -3
- package/src/lib/helpers/readEnvKey.js +4 -3
- package/src/lib/main.d.ts +2 -39
- package/src/lib/main.js +82 -45
- package/src/lib/providers/armor/index.js +29 -0
- package/src/lib/providers/index.js +46 -0
- package/src/lib/providers/worker.js +6 -0
- package/src/lib/resolvers/envs.js +302 -0
- package/src/lib/resolvers/get.js +69 -0
- package/src/lib/resolvers/keypair.js +81 -0
- package/src/lib/resolvers/ls.js +41 -0
- package/src/lib/services/armorDown.js +2 -2
- package/src/lib/services/{armorKeypair.js → armorKeyring.js} +14 -51
- package/src/lib/services/armorMove.js +2 -2
- package/src/lib/services/armorPull.js +2 -2
- package/src/lib/services/armorPush.js +2 -2
- package/src/lib/services/armorUp.js +2 -2
- package/src/lib/services/genexample.js +19 -8
- package/src/lib/services/login.js +25 -0
- package/src/lib/services/prebuild.js +11 -5
- package/src/lib/services/precommit.js +11 -5
- package/src/lib/transforms/decrypt.js +83 -0
- package/src/lib/transforms/encrypt.js +179 -0
- package/src/lib/transforms/set.js +179 -0
- package/src/shared/logger.js +5 -0
- package/src/cli/actions/normalizeArmorOptions.js +0 -10
- package/src/cli/actions/rotate.js +0 -87
- package/src/lib/helpers/append.js +0 -61
- package/src/lib/helpers/cryptography/armorKeypair.js +0 -42
- package/src/lib/helpers/cryptography/armorKeypairSync.js +0 -55
- package/src/lib/helpers/cryptography/encryptValue.js +0 -7
- package/src/lib/helpers/cryptography/localKeypair.js +0 -14
- package/src/lib/helpers/cryptography/mutateKeysSrcSync.js +0 -38
- package/src/lib/helpers/cryptography/provision.js +0 -56
- package/src/lib/helpers/cryptography/provisionSync.js +0 -51
- package/src/lib/helpers/cryptography/provisionWithPrivateKey.js +0 -26
- package/src/lib/helpers/dotenvParse.js +0 -55
- package/src/lib/helpers/escapeDollarSigns.js +0 -5
- package/src/lib/helpers/escapeForRegex.js +0 -5
- package/src/lib/helpers/evalKeyValue.js +0 -23
- package/src/lib/helpers/isFullyEncrypted.js +0 -27
- package/src/lib/helpers/isIgnoringDotenvKeys.js +0 -19
- package/src/lib/helpers/keyResolution/index.js +0 -16
- package/src/lib/helpers/keyResolution/keyNamesForEnvFile.js +0 -24
- package/src/lib/helpers/keyResolution/keyValues.js +0 -99
- package/src/lib/helpers/keyResolution/keyValuesFromEnvSrc.js +0 -80
- package/src/lib/helpers/keyResolution/keyValuesSync.js +0 -103
- package/src/lib/helpers/keyResolution/readFileKey.js +0 -17
- package/src/lib/helpers/keyResolution/readFileKeySync.js +0 -15
- package/src/lib/helpers/keyResolution/readProcessKey.js +0 -7
- package/src/lib/helpers/localDisplayPath.js +0 -11
- package/src/lib/helpers/parse.js +0 -214
- package/src/lib/helpers/pluralize.js +0 -10
- package/src/lib/helpers/quotes.js +0 -36
- package/src/lib/helpers/replace.js +0 -82
- package/src/lib/helpers/resolveEscapeSequences.js +0 -5
- package/src/lib/services/decrypt.js +0 -157
- package/src/lib/services/encrypt.js +0 -214
- package/src/lib/services/get.js +0 -76
- package/src/lib/services/keypair.js +0 -60
- package/src/lib/services/loginPoll.js +0 -36
- package/src/lib/services/ls.js +0 -57
- package/src/lib/services/rotate.js +0 -198
- package/src/lib/services/run.js +0 -255
- package/src/lib/services/sets.js +0 -326
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
const fsx = require('./../helpers/fsx')
|
|
2
|
-
const path = require('path')
|
|
3
|
-
const picomatch = require('picomatch')
|
|
4
|
-
const { encrypted } = require('@dotenvx/primitives')
|
|
5
|
-
|
|
6
|
-
const TYPE_ENV_FILE = 'envFile'
|
|
7
|
-
|
|
8
|
-
const Errors = require('./../helpers/errors')
|
|
9
|
-
|
|
10
|
-
const {
|
|
11
|
-
determine
|
|
12
|
-
} = require('./../helpers/envResolution')
|
|
13
|
-
|
|
14
|
-
const {
|
|
15
|
-
keyNamesForEnvFile,
|
|
16
|
-
keyValues
|
|
17
|
-
} = require('./../helpers/keyResolution')
|
|
18
|
-
|
|
19
|
-
const {
|
|
20
|
-
decryptKeyValue
|
|
21
|
-
} = require('./../helpers/cryptography')
|
|
22
|
-
|
|
23
|
-
const replace = require('./../helpers/replace')
|
|
24
|
-
const dotenvParse = require('./../helpers/dotenvParse')
|
|
25
|
-
const detectEncoding = require('./../helpers/detectEncoding')
|
|
26
|
-
|
|
27
|
-
class Decrypt {
|
|
28
|
-
constructor (envs = [], key = [], excludeKey = [], envKeysFilepath = null, noArmor = false, options = {}) {
|
|
29
|
-
this.envs = determine(envs, process.env)
|
|
30
|
-
this.key = key
|
|
31
|
-
this.excludeKey = excludeKey
|
|
32
|
-
this.envKeysFilepath = envKeysFilepath
|
|
33
|
-
this.noArmor = noArmor
|
|
34
|
-
this.command = options.command
|
|
35
|
-
|
|
36
|
-
this.processedEnvs = []
|
|
37
|
-
this.changedFilepaths = new Set()
|
|
38
|
-
this.unchangedFilepaths = new Set()
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
async run () {
|
|
42
|
-
// example
|
|
43
|
-
// envs [
|
|
44
|
-
// { type: 'envFile', value: '.env' }
|
|
45
|
-
// ]
|
|
46
|
-
|
|
47
|
-
this.keys = this._keys()
|
|
48
|
-
const excludeKeys = this._excludeKeys()
|
|
49
|
-
|
|
50
|
-
this.exclude = picomatch(excludeKeys)
|
|
51
|
-
this.include = picomatch(this.keys, { ignore: excludeKeys })
|
|
52
|
-
|
|
53
|
-
for (const env of this.envs) {
|
|
54
|
-
if (env.type === TYPE_ENV_FILE) {
|
|
55
|
-
await this._decryptEnvFile(env.value)
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return {
|
|
60
|
-
processedEnvs: this.processedEnvs,
|
|
61
|
-
changedFilepaths: [...this.changedFilepaths],
|
|
62
|
-
unchangedFilepaths: [...this.unchangedFilepaths]
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async _decryptEnvFile (envFilepath) {
|
|
67
|
-
const row = {}
|
|
68
|
-
row.keys = []
|
|
69
|
-
row.type = TYPE_ENV_FILE
|
|
70
|
-
|
|
71
|
-
const filepath = path.resolve(envFilepath)
|
|
72
|
-
row.filepath = filepath
|
|
73
|
-
row.envFilepath = envFilepath
|
|
74
|
-
|
|
75
|
-
try {
|
|
76
|
-
const encoding = await detectEncoding(filepath)
|
|
77
|
-
let envSrc = await fsx.readFileX(filepath, { encoding })
|
|
78
|
-
const envParsed = dotenvParse(envSrc, false, false, true)
|
|
79
|
-
|
|
80
|
-
const { privateKeyName } = keyNamesForEnvFile(envFilepath)
|
|
81
|
-
const { privateKeyValue, privateKeySource } = await keyValues(envFilepath, {
|
|
82
|
-
keysFilepath: this.envKeysFilepath,
|
|
83
|
-
noArmor: this.noArmor,
|
|
84
|
-
command: this.command
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
row.privateKey = privateKeyValue
|
|
88
|
-
row.privateKeySource = privateKeySource
|
|
89
|
-
row.armoredPrivateKeyUsed = privateKeySource === 'armor'
|
|
90
|
-
row.privateKeyName = privateKeyName
|
|
91
|
-
row.changed = false // track possible changes
|
|
92
|
-
|
|
93
|
-
for (const [key, values] of Object.entries(envParsed)) {
|
|
94
|
-
// key excluded - don't decrypt it
|
|
95
|
-
if (this.exclude(key)) {
|
|
96
|
-
continue
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// key effectively excluded (by not being in the list of includes) - don't decrypt it
|
|
100
|
-
if (this.keys.length > 0 && !this.include(key)) {
|
|
101
|
-
continue
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const hasEncrypted = values.some(value => encrypted(value))
|
|
105
|
-
if (hasEncrypted) {
|
|
106
|
-
row.keys.push(key) // track key(s)
|
|
107
|
-
|
|
108
|
-
const decryptedValues = values.map(value => {
|
|
109
|
-
if (!encrypted(value)) {
|
|
110
|
-
return value
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return decryptKeyValue(key, value, privateKeyName, privateKeyValue)
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
// once newSrc is built write it out
|
|
117
|
-
envSrc = replace(envSrc, key, decryptedValues)
|
|
118
|
-
|
|
119
|
-
row.changed = true // track change
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
row.envSrc = envSrc
|
|
124
|
-
if (row.changed) {
|
|
125
|
-
this.changedFilepaths.add(envFilepath)
|
|
126
|
-
} else {
|
|
127
|
-
this.unchangedFilepaths.add(envFilepath)
|
|
128
|
-
}
|
|
129
|
-
} catch (e) {
|
|
130
|
-
if (e.code === 'ENOENT') {
|
|
131
|
-
row.error = new Errors({ envFilepath, filepath }).missingEnvFile()
|
|
132
|
-
} else {
|
|
133
|
-
row.error = e
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
this.processedEnvs.push(row)
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
_keys () {
|
|
141
|
-
if (!Array.isArray(this.key)) {
|
|
142
|
-
return [this.key]
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
return this.key
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
_excludeKeys () {
|
|
149
|
-
if (!Array.isArray(this.excludeKey)) {
|
|
150
|
-
return [this.excludeKey]
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
return this.excludeKey
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
module.exports = Decrypt
|
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
const fsx = require('./../helpers/fsx')
|
|
2
|
-
const path = require('path')
|
|
3
|
-
const picomatch = require('picomatch')
|
|
4
|
-
const { encrypted } = require('@dotenvx/primitives')
|
|
5
|
-
|
|
6
|
-
const TYPE_ENV_FILE = 'envFile'
|
|
7
|
-
|
|
8
|
-
const Errors = require('./../helpers/errors')
|
|
9
|
-
|
|
10
|
-
const {
|
|
11
|
-
determine
|
|
12
|
-
} = require('./../helpers/envResolution')
|
|
13
|
-
|
|
14
|
-
const {
|
|
15
|
-
keyNamesForEnvFile,
|
|
16
|
-
keyValues
|
|
17
|
-
} = require('./../helpers/keyResolution')
|
|
18
|
-
|
|
19
|
-
const {
|
|
20
|
-
encryptValue,
|
|
21
|
-
isPublicKey,
|
|
22
|
-
provision,
|
|
23
|
-
provisionWithPrivateKey
|
|
24
|
-
} = require('./../helpers/cryptography')
|
|
25
|
-
|
|
26
|
-
const replace = require('./../helpers/replace')
|
|
27
|
-
const dotenvParse = require('./../helpers/dotenvParse')
|
|
28
|
-
const detectEncoding = require('./../helpers/detectEncoding')
|
|
29
|
-
const SAMPLE_ENV_KIT = require('./../helpers/kits/sample')
|
|
30
|
-
|
|
31
|
-
class Encrypt {
|
|
32
|
-
constructor (envs = [], key = [], excludeKey = [], envKeysFilepath = null, noArmor = false, noCreate = false, token = undefined, options = {}) {
|
|
33
|
-
this.envs = determine(envs, process.env)
|
|
34
|
-
this.key = key
|
|
35
|
-
this.excludeKey = excludeKey
|
|
36
|
-
this.envKeysFilepath = envKeysFilepath
|
|
37
|
-
this.noArmor = noArmor
|
|
38
|
-
this.noCreate = noCreate
|
|
39
|
-
this.token = token
|
|
40
|
-
this.selectKeyStorage = options.selectKeyStorage
|
|
41
|
-
this.command = options.command
|
|
42
|
-
|
|
43
|
-
this.processedEnvs = []
|
|
44
|
-
this.changedFilepaths = new Set()
|
|
45
|
-
this.unchangedFilepaths = new Set()
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async run () {
|
|
49
|
-
// example
|
|
50
|
-
// envs [
|
|
51
|
-
// { type: 'envFile', value: '.env' }
|
|
52
|
-
// ]
|
|
53
|
-
|
|
54
|
-
this.keys = this._keys()
|
|
55
|
-
const excludeKeys = this._excludeKeys()
|
|
56
|
-
|
|
57
|
-
this.exclude = picomatch(excludeKeys)
|
|
58
|
-
this.include = picomatch(this.keys, { ignore: excludeKeys })
|
|
59
|
-
|
|
60
|
-
for (const env of this.envs) {
|
|
61
|
-
if (env.type === TYPE_ENV_FILE) {
|
|
62
|
-
await this._encryptEnvFile(env.value)
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return {
|
|
67
|
-
processedEnvs: this.processedEnvs,
|
|
68
|
-
changedFilepaths: [...this.changedFilepaths],
|
|
69
|
-
unchangedFilepaths: [...this.unchangedFilepaths]
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
async _encryptEnvFile (envFilepath) {
|
|
74
|
-
const row = {}
|
|
75
|
-
row.keys = []
|
|
76
|
-
row.type = TYPE_ENV_FILE
|
|
77
|
-
let fileCreated = false
|
|
78
|
-
|
|
79
|
-
const filepath = path.resolve(envFilepath)
|
|
80
|
-
row.filepath = filepath
|
|
81
|
-
row.envFilepath = envFilepath
|
|
82
|
-
|
|
83
|
-
try {
|
|
84
|
-
const fileExists = await fsx.exists(filepath)
|
|
85
|
-
let envSrc
|
|
86
|
-
if (!fileExists && !this.noCreate) {
|
|
87
|
-
envSrc = SAMPLE_ENV_KIT
|
|
88
|
-
fileCreated = true
|
|
89
|
-
row.kitCreated = 'sample'
|
|
90
|
-
row.changed = true
|
|
91
|
-
} else {
|
|
92
|
-
const encoding = await detectEncoding(filepath)
|
|
93
|
-
envSrc = await fsx.readFileX(filepath, { encoding })
|
|
94
|
-
}
|
|
95
|
-
if (envSrc.trim().length === 0) {
|
|
96
|
-
envSrc = SAMPLE_ENV_KIT
|
|
97
|
-
row.kitCreated = 'sample'
|
|
98
|
-
row.changed = true
|
|
99
|
-
}
|
|
100
|
-
const envParsed = dotenvParse(envSrc, false, false, true)
|
|
101
|
-
|
|
102
|
-
let publicKey
|
|
103
|
-
let privateKey
|
|
104
|
-
|
|
105
|
-
const { publicKeyName, privateKeyName } = keyNamesForEnvFile(envFilepath)
|
|
106
|
-
const { publicKeyValue, privateKeyValue } = await keyValues(envFilepath, {
|
|
107
|
-
keysFilepath: this.envKeysFilepath,
|
|
108
|
-
noArmor: this.noArmor,
|
|
109
|
-
command: this.command
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
// first pass - provision
|
|
113
|
-
if (!privateKeyValue && !publicKeyValue) {
|
|
114
|
-
const prov = await provision({
|
|
115
|
-
envSrc,
|
|
116
|
-
envFilepath,
|
|
117
|
-
keysFilepath: this.envKeysFilepath,
|
|
118
|
-
noArmor: this.noArmor,
|
|
119
|
-
token: this.token,
|
|
120
|
-
selectKeyStorage: this.selectKeyStorage,
|
|
121
|
-
command: this.command
|
|
122
|
-
})
|
|
123
|
-
envSrc = prov.envSrc
|
|
124
|
-
publicKey = prov.publicKey
|
|
125
|
-
privateKey = prov.privateKey
|
|
126
|
-
row.localPrivateKeyAdded = prov.localPrivateKeyAdded
|
|
127
|
-
row.remotePrivateKeyAdded = prov.remotePrivateKeyAdded
|
|
128
|
-
row.envKeysFilepath = prov.envKeysFilepath
|
|
129
|
-
} else if (privateKeyValue) {
|
|
130
|
-
const prov = provisionWithPrivateKey({ envSrc, envFilepath, keysFilepath: this.envKeysFilepath, privateKeyValue, publicKeyValue, publicKeyName })
|
|
131
|
-
publicKey = prov.publicKey
|
|
132
|
-
privateKey = prov.privateKey
|
|
133
|
-
envSrc = prov.envSrc
|
|
134
|
-
} else if (publicKeyValue) {
|
|
135
|
-
publicKey = publicKeyValue
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
row.publicKey = publicKey
|
|
139
|
-
row.privateKey = privateKey
|
|
140
|
-
row.privateKeyName = privateKeyName
|
|
141
|
-
|
|
142
|
-
// iterate over all non-encrypted values and encrypt them
|
|
143
|
-
for (const [key, values] of Object.entries(envParsed)) {
|
|
144
|
-
// key excluded - don't encrypt it
|
|
145
|
-
if (this.exclude(key)) {
|
|
146
|
-
continue
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// key effectively excluded (by not being in the list of includes) - don't encrypt it
|
|
150
|
-
if (this.keys.length > 0 && !this.include(key)) {
|
|
151
|
-
continue
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const fullyEncrypted = values.every(value => encrypted(value) || isPublicKey(key))
|
|
155
|
-
if (!fullyEncrypted) {
|
|
156
|
-
row.keys.push(key) // track key(s)
|
|
157
|
-
|
|
158
|
-
const encryptedValues = values.map(value => {
|
|
159
|
-
if (encrypted(value) || isPublicKey(key)) {
|
|
160
|
-
return value
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
try {
|
|
164
|
-
return encryptValue(value, publicKey)
|
|
165
|
-
} catch {
|
|
166
|
-
throw new Errors({ publicKeyName, publicKey }).invalidPublicKey()
|
|
167
|
-
}
|
|
168
|
-
})
|
|
169
|
-
|
|
170
|
-
// once newSrc is built write it out
|
|
171
|
-
envSrc = replace(envSrc, key, encryptedValues)
|
|
172
|
-
|
|
173
|
-
row.changed = true // track change
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
row.envSrc = envSrc
|
|
178
|
-
if (fileCreated) {
|
|
179
|
-
row.changed = true
|
|
180
|
-
}
|
|
181
|
-
if (row.changed) {
|
|
182
|
-
this.changedFilepaths.add(envFilepath)
|
|
183
|
-
} else {
|
|
184
|
-
this.unchangedFilepaths.add(envFilepath)
|
|
185
|
-
}
|
|
186
|
-
} catch (e) {
|
|
187
|
-
if (e.code === 'ENOENT') {
|
|
188
|
-
row.error = new Errors({ envFilepath, filepath }).missingEnvFile()
|
|
189
|
-
} else {
|
|
190
|
-
row.error = e
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
this.processedEnvs.push(row)
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
_keys () {
|
|
198
|
-
if (!Array.isArray(this.key)) {
|
|
199
|
-
return [this.key]
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
return this.key
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
_excludeKeys () {
|
|
206
|
-
if (!Array.isArray(this.excludeKey)) {
|
|
207
|
-
return [this.excludeKey]
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
return this.excludeKey
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
module.exports = Encrypt
|
package/src/lib/services/get.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
const Run = require('./run')
|
|
2
|
-
const Errors = require('./../helpers/errors')
|
|
3
|
-
const { determine } = require('./../helpers/envResolution')
|
|
4
|
-
|
|
5
|
-
class Get {
|
|
6
|
-
constructor (key, envs = [], overload = false, all = false, envKeysFilepath = null, noArmor = false, options = {}) {
|
|
7
|
-
this.key = key
|
|
8
|
-
this.envs = envs
|
|
9
|
-
this.overload = overload
|
|
10
|
-
this.all = all
|
|
11
|
-
this.envKeysFilepath = envKeysFilepath
|
|
12
|
-
this.noArmor = noArmor
|
|
13
|
-
this.command = options.command
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
runSync () {
|
|
17
|
-
const processEnv = { ...process.env }
|
|
18
|
-
const envs = determine(this.envs, processEnv)
|
|
19
|
-
const { processedEnvs } = new Run(envs, this.overload, processEnv, this.envKeysFilepath, this.noArmor, {
|
|
20
|
-
command: this.command
|
|
21
|
-
}).runSync()
|
|
22
|
-
return this._result(processedEnvs, processEnv)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async run () {
|
|
26
|
-
const processEnv = { ...process.env }
|
|
27
|
-
const envs = determine(this.envs, processEnv)
|
|
28
|
-
const { processedEnvs } = await new Run(envs, this.overload, processEnv, this.envKeysFilepath, this.noArmor, {
|
|
29
|
-
command: this.command
|
|
30
|
-
}).run()
|
|
31
|
-
return this._result(processedEnvs, processEnv)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
_result (processedEnvs, processEnv) {
|
|
35
|
-
const errors = []
|
|
36
|
-
for (const processedEnv of processedEnvs) {
|
|
37
|
-
for (const error of processedEnv.errors) {
|
|
38
|
-
errors.push(error)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (this.key) {
|
|
43
|
-
const parsed = {}
|
|
44
|
-
const value = processEnv[this.key]
|
|
45
|
-
parsed[this.key] = value
|
|
46
|
-
|
|
47
|
-
if (value === undefined) {
|
|
48
|
-
errors.push(new Errors({ key: this.key }).missingKey())
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return { parsed, errors }
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// if user wants to return ALL envs (even prior set on machine)
|
|
55
|
-
if (this.all) {
|
|
56
|
-
return { parsed: processEnv, errors }
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// typical scenario - return only envs that were identified in the .env file
|
|
60
|
-
// iterate over all processedEnvs.parsed and grab from processEnv
|
|
61
|
-
/** @type {Record<string, string>} */
|
|
62
|
-
const parsed = {}
|
|
63
|
-
for (const processedEnv of processedEnvs) {
|
|
64
|
-
// parsed means we saw the key in a file or --env flag. this effectively filters out any preset machine envs - while still respecting complex evaluating, expansion, and overload. in other words, the value might be the machine value because the key was displayed in a .env file
|
|
65
|
-
if (processedEnv.parsed) {
|
|
66
|
-
for (const key of Object.keys(processedEnv.parsed)) {
|
|
67
|
-
parsed[key] = processEnv[key]
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return { parsed, errors }
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
module.exports = Get
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
const keyNamesForEnvFile = require('./../helpers/keyResolution/keyNamesForEnvFile')
|
|
2
|
-
const keyValues = require('./../helpers/keyResolution/keyValues')
|
|
3
|
-
const keyValuesSync = require('./../helpers/keyResolution/keyValuesSync')
|
|
4
|
-
|
|
5
|
-
class Keypair {
|
|
6
|
-
constructor (envFile = '.env', envKeysFilepath = null, noArmor = false, options = {}) {
|
|
7
|
-
this.envFile = envFile
|
|
8
|
-
this.envKeysFilepath = envKeysFilepath
|
|
9
|
-
this.noArmor = noArmor
|
|
10
|
-
this.command = options.command
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
runSync () {
|
|
14
|
-
const out = {}
|
|
15
|
-
|
|
16
|
-
const filepaths = this._filepaths()
|
|
17
|
-
for (const filepath of filepaths) {
|
|
18
|
-
const { publicKeyName, privateKeyName } = keyNamesForEnvFile(filepath)
|
|
19
|
-
const { publicKeyValue, privateKeyValue } = keyValuesSync(filepath, {
|
|
20
|
-
keysFilepath: this.envKeysFilepath,
|
|
21
|
-
noArmor: this.noArmor,
|
|
22
|
-
command: this.command
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
out[publicKeyName] = publicKeyValue
|
|
26
|
-
out[privateKeyName] = privateKeyValue
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return out
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async run () {
|
|
33
|
-
const out = {}
|
|
34
|
-
|
|
35
|
-
const filepaths = this._filepaths()
|
|
36
|
-
for (const filepath of filepaths) {
|
|
37
|
-
const { publicKeyName, privateKeyName } = keyNamesForEnvFile(filepath)
|
|
38
|
-
const { publicKeyValue, privateKeyValue } = await keyValues(filepath, {
|
|
39
|
-
keysFilepath: this.envKeysFilepath,
|
|
40
|
-
noArmor: this.noArmor,
|
|
41
|
-
command: this.command
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
out[publicKeyName] = publicKeyValue
|
|
45
|
-
out[privateKeyName] = privateKeyValue
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return out
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
_filepaths () {
|
|
52
|
-
if (!Array.isArray(this.envFile)) {
|
|
53
|
-
return [this.envFile]
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return this.envFile
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
module.exports = Keypair
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
const Session = require('../../db/session')
|
|
2
|
-
const PostOauthToken = require('../api/postOauthToken')
|
|
3
|
-
|
|
4
|
-
class LoginPoll {
|
|
5
|
-
constructor (hostname, deviceCode, interval) {
|
|
6
|
-
this.hostname = hostname
|
|
7
|
-
this.deviceCode = deviceCode
|
|
8
|
-
this.interval = interval
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
async run () {
|
|
12
|
-
const sesh = new Session()
|
|
13
|
-
|
|
14
|
-
while (true) {
|
|
15
|
-
try {
|
|
16
|
-
const data = await new PostOauthToken(this.hostname, this.deviceCode).run()
|
|
17
|
-
|
|
18
|
-
if (data.access_token) {
|
|
19
|
-
sesh.login(this.hostname, data.id, data.username, data.access_token)
|
|
20
|
-
await sesh.notifyUpdate()
|
|
21
|
-
return data
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
await new Promise(resolve => setTimeout(resolve, this.interval * 1000))
|
|
25
|
-
} catch (error) {
|
|
26
|
-
if (error.code === 'authorization_pending') {
|
|
27
|
-
await new Promise(resolve => setTimeout(resolve, (this.interval + 1) * 1000))
|
|
28
|
-
} else {
|
|
29
|
-
throw error
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
module.exports = LoginPoll
|
package/src/lib/services/ls.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
const { fdir: Fdir } = require('fdir')
|
|
2
|
-
const path = require('path')
|
|
3
|
-
const picomatch = require('picomatch')
|
|
4
|
-
|
|
5
|
-
class Ls {
|
|
6
|
-
constructor (directory = './', envFile = ['.env*'], excludeEnvFile = []) {
|
|
7
|
-
this.ignore = ['node_modules/**', '.git/**']
|
|
8
|
-
|
|
9
|
-
this.cwd = path.resolve(directory)
|
|
10
|
-
this.envFile = envFile
|
|
11
|
-
this.excludeEnvFile = excludeEnvFile
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
run () {
|
|
15
|
-
return this._filepaths()
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
_filepaths () {
|
|
19
|
-
const exclude = picomatch(this._exclude())
|
|
20
|
-
const include = picomatch(this._patterns(), {
|
|
21
|
-
ignore: this._exclude()
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
return new Fdir()
|
|
25
|
-
.withRelativePaths()
|
|
26
|
-
.exclude((dir, path) => exclude(path))
|
|
27
|
-
.filter((path) => include(path))
|
|
28
|
-
.crawl(this.cwd)
|
|
29
|
-
.sync()
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
_patterns () {
|
|
33
|
-
if (!Array.isArray(this.envFile)) {
|
|
34
|
-
return [`**/${this.envFile}`]
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return this.envFile.map(part => `**/${part}`)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
_excludePatterns () {
|
|
41
|
-
if (!Array.isArray(this.excludeEnvFile)) {
|
|
42
|
-
return [`**/${this.excludeEnvFile}`]
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return this.excludeEnvFile.map(part => `**/${part}`)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
_exclude () {
|
|
49
|
-
if (this._excludePatterns().length > 0) {
|
|
50
|
-
return this.ignore.concat(this._excludePatterns())
|
|
51
|
-
} else {
|
|
52
|
-
return this.ignore
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
module.exports = Ls
|