@dotenvx/dotenvx-ops 0.32.0 → 0.33.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 +7 -1
- package/package.json +1 -1
- package/src/cli/actions/keypair.js +42 -0
- package/src/cli/dotenvx-ops.js +10 -0
- package/src/lib/api/postKeypair.js +39 -0
- package/src/lib/main.js +25 -0
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-ops/compare/v0.
|
|
5
|
+
[Unreleased](https://github.com/dotenvx/dotenvx-ops/compare/v0.33.0...main)
|
|
6
|
+
|
|
7
|
+
## [0.33.0](https://github.com/dotenvx/dotenvx-ops/compare/v0.32.0...v0.33.0) (2026-03-11)
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
* Add internal `keypair` command that calls remotely ([#27](https://github.com/dotenvx/dotenvx-ops/pull/27))
|
|
6
12
|
|
|
7
13
|
## [0.32.0](https://github.com/dotenvx/dotenvx-ops/compare/v0.31.2...v0.32.0) (2026-03-11)
|
|
8
14
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const { logger } = require('@dotenvx/dotenvx')
|
|
2
|
+
|
|
3
|
+
const main = require('./../../lib/main')
|
|
4
|
+
|
|
5
|
+
async function keypair () {
|
|
6
|
+
// debug opts
|
|
7
|
+
const options = this.opts()
|
|
8
|
+
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
9
|
+
|
|
10
|
+
const hostname = options.hostname
|
|
11
|
+
const token = options.token
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
const kp = await main.keypair({ hostname, token })
|
|
15
|
+
const output = {
|
|
16
|
+
public_key: kp.publicKey,
|
|
17
|
+
private_key: kp.privateKey
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let space = 0
|
|
21
|
+
if (options.prettyPrint) {
|
|
22
|
+
space = 2
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
console.log(JSON.stringify(output, null, space))
|
|
26
|
+
} catch (error) {
|
|
27
|
+
if (error.message) {
|
|
28
|
+
logger.error(error.message)
|
|
29
|
+
} else {
|
|
30
|
+
logger.error(error)
|
|
31
|
+
}
|
|
32
|
+
if (error.help) {
|
|
33
|
+
logger.help(error.help)
|
|
34
|
+
}
|
|
35
|
+
if (error.stack) {
|
|
36
|
+
logger.debug(error.stack)
|
|
37
|
+
}
|
|
38
|
+
process.exit(1)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
module.exports = keypair
|
package/src/cli/dotenvx-ops.js
CHANGED
|
@@ -117,6 +117,16 @@ program
|
|
|
117
117
|
.description('[INTERNAL] status')
|
|
118
118
|
.action(statusAction)
|
|
119
119
|
|
|
120
|
+
// dotenvx-ops keypair
|
|
121
|
+
const keypairAction = require('./actions/keypair')
|
|
122
|
+
program
|
|
123
|
+
.command('keypair')
|
|
124
|
+
.description('[INTERNAL] generate keypair')
|
|
125
|
+
.option('-h, --hostname <url>', 'set hostname', sesh.hostname())
|
|
126
|
+
.option('--token <token>', 'set token')
|
|
127
|
+
.option('--pp, --pretty-print', 'pretty print output')
|
|
128
|
+
.action(keypairAction)
|
|
129
|
+
|
|
120
130
|
program.addCommand(require('./commands/gateway'))
|
|
121
131
|
program.addCommand(require('./commands/settings'))
|
|
122
132
|
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const { http } = require('../../lib/helpers/http')
|
|
2
|
+
const buildApiError = require('../../lib/helpers/buildApiError')
|
|
3
|
+
const packageJson = require('../../lib/helpers/packageJson')
|
|
4
|
+
|
|
5
|
+
class PostKeypair {
|
|
6
|
+
constructor (hostname, token, devicePublicKey) {
|
|
7
|
+
this.hostname = hostname || 'https://ops.dotenvx.com'
|
|
8
|
+
this.token = token
|
|
9
|
+
this.devicePublicKey = devicePublicKey
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async run () {
|
|
13
|
+
const token = this.token
|
|
14
|
+
const devicePublicKey = this.devicePublicKey
|
|
15
|
+
const url = `${this.hostname}/api/keypair`
|
|
16
|
+
|
|
17
|
+
const resp = await http(url, {
|
|
18
|
+
method: 'POST',
|
|
19
|
+
headers: {
|
|
20
|
+
Authorization: `Bearer ${token}`,
|
|
21
|
+
'Content-Type': 'application/json'
|
|
22
|
+
},
|
|
23
|
+
body: JSON.stringify({
|
|
24
|
+
device_public_key: devicePublicKey,
|
|
25
|
+
cli_version: packageJson.version
|
|
26
|
+
})
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
const json = await resp.body.json()
|
|
30
|
+
|
|
31
|
+
if (resp.statusCode >= 400) {
|
|
32
|
+
throw buildApiError(resp.statusCode, json)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return json
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
module.exports = PostKeypair
|
package/src/lib/main.js
CHANGED
|
@@ -5,6 +5,7 @@ const Session = require('./../db/session')
|
|
|
5
5
|
const PostObserve = require('./api/postObserve')
|
|
6
6
|
const PostGet = require('./api/postGet')
|
|
7
7
|
const PostSet = require('./api/postSet')
|
|
8
|
+
const PostKeypair = require('./api/postKeypair')
|
|
8
9
|
|
|
9
10
|
const gitUrl = require('./helpers/gitUrl')
|
|
10
11
|
const gitBranch = require('./helpers/gitBranch')
|
|
@@ -76,6 +77,29 @@ const set = async function (uri, value, options = {}) {
|
|
|
76
77
|
return await new PostSet(hostname, token, devicePublicKey, uri, value).run()
|
|
77
78
|
}
|
|
78
79
|
|
|
80
|
+
const keypair = async function (options = {}) {
|
|
81
|
+
const sesh = new Session() // TODO: handle scenario where constructor fails
|
|
82
|
+
|
|
83
|
+
let hostname = process.env.DOTENVX_OPS_HOSTNAME || options.hostname
|
|
84
|
+
if (!hostname) {
|
|
85
|
+
hostname = sesh.hostname()
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
let token = process.env.DOTENVX_OPS_TOKEN || options.token
|
|
89
|
+
if (!token) {
|
|
90
|
+
token = sesh.token()
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const devicePublicKey = sesh.devicePublicKey()
|
|
94
|
+
|
|
95
|
+
const json = await new PostKeypair(hostname, token, devicePublicKey).run()
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
publicKey: json.public_key,
|
|
99
|
+
privateKey: json.private_key
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
79
103
|
const config = function (options = {}) {
|
|
80
104
|
return dotenvx.config(options)
|
|
81
105
|
}
|
|
@@ -84,6 +108,7 @@ module.exports = {
|
|
|
84
108
|
observe,
|
|
85
109
|
get,
|
|
86
110
|
set,
|
|
111
|
+
keypair,
|
|
87
112
|
// dotenv proxies
|
|
88
113
|
config
|
|
89
114
|
}
|