@dotenvx/dotenvx-ops 0.23.7 → 0.24.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 +13 -1
- package/package.json +1 -1
- package/src/cli/actions/set.js +32 -0
- package/src/cli/dotenvx-ops.js +11 -0
- package/src/lib/api/postSet.js +40 -0
- package/src/lib/main.js +18 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,19 @@
|
|
|
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.30.0...main)
|
|
6
|
+
|
|
7
|
+
## [0.30.0](https://github.com/dotenvx/dotenvx-ops/compare/v0.23.8...v0.30.0) (2025-12-10)
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
* Add `set` ([#15](https://github.com/dotenvx/dotenvx-ops/pull/15))
|
|
12
|
+
|
|
13
|
+
## [0.23.8](https://github.com/dotenvx/dotenvx-ops/compare/v0.23.7...v0.23.8) (2025-12-10)
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
|
|
17
|
+
* Change publishing `rot_`
|
|
6
18
|
|
|
7
19
|
## [0.23.7](https://github.com/dotenvx/dotenvx-ops/compare/v0.23.6...v0.23.7) (2025-12-10)
|
|
8
20
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const { logger } = require('@dotenvx/dotenvx')
|
|
2
|
+
|
|
3
|
+
const main = require('./../../lib/main')
|
|
4
|
+
|
|
5
|
+
async function set (uri, value) {
|
|
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
|
+
await main.set(uri, value, { hostname, token })
|
|
15
|
+
logger.success(`✔ set [${uri}]`)
|
|
16
|
+
} catch (error) {
|
|
17
|
+
if (error.message) {
|
|
18
|
+
logger.error(error.message)
|
|
19
|
+
} else {
|
|
20
|
+
logger.error(error)
|
|
21
|
+
}
|
|
22
|
+
if (error.help) {
|
|
23
|
+
logger.help(error.help)
|
|
24
|
+
}
|
|
25
|
+
if (error.stack) {
|
|
26
|
+
logger.debug(error.stack)
|
|
27
|
+
}
|
|
28
|
+
process.exit(1)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = set
|
package/src/cli/dotenvx-ops.js
CHANGED
|
@@ -63,6 +63,17 @@ program
|
|
|
63
63
|
.option('--token <token>', 'set token')
|
|
64
64
|
.action(getAction)
|
|
65
65
|
|
|
66
|
+
// dotenvx-ops set
|
|
67
|
+
const setAction = require('./actions/set')
|
|
68
|
+
program
|
|
69
|
+
.command('set')
|
|
70
|
+
.description('set secret')
|
|
71
|
+
.argument('URI', 'URI')
|
|
72
|
+
.argument('value', 'value')
|
|
73
|
+
.option('--hostname <url>', 'set hostname', sesh.hostname())
|
|
74
|
+
.option('--token <token>', 'set token')
|
|
75
|
+
.action(setAction)
|
|
76
|
+
|
|
66
77
|
// dotenvx-ops rotate
|
|
67
78
|
program.addCommand(require('./commands/rotate'))
|
|
68
79
|
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const { http } = require('../../lib/helpers/http')
|
|
2
|
+
const buildApiError = require('../../lib/helpers/buildApiError')
|
|
3
|
+
|
|
4
|
+
class PostSet {
|
|
5
|
+
constructor (hostname, token, uri, value) {
|
|
6
|
+
this.hostname = hostname || 'https://ops.dotenvx.com'
|
|
7
|
+
this.token = token
|
|
8
|
+
this.uri = uri
|
|
9
|
+
this.value = value
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async run () {
|
|
13
|
+
const token = this.token
|
|
14
|
+
const uri = this.uri
|
|
15
|
+
const value = this.value
|
|
16
|
+
const url = `${this.hostname}/api/set`
|
|
17
|
+
|
|
18
|
+
const resp = await http(url, {
|
|
19
|
+
method: 'POST',
|
|
20
|
+
headers: {
|
|
21
|
+
Authorization: `Bearer ${token}`,
|
|
22
|
+
'Content-Type': 'application/json'
|
|
23
|
+
},
|
|
24
|
+
body: JSON.stringify({
|
|
25
|
+
uri,
|
|
26
|
+
value
|
|
27
|
+
})
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
if (resp.statusCode >= 400) {
|
|
31
|
+
const json = await resp.body.json()
|
|
32
|
+
throw buildApiError(resp.statusCode, json)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const text = await resp.body.text()
|
|
36
|
+
return text
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
module.exports = PostSet
|
package/src/lib/main.js
CHANGED
|
@@ -4,6 +4,7 @@ const dotenvx = require('@dotenvx/dotenvx')
|
|
|
4
4
|
const Session = require('./../db/session')
|
|
5
5
|
const PostObserve = require('./api/postObserve')
|
|
6
6
|
const PostGet = require('./api/postGet')
|
|
7
|
+
const PostSet = require('./api/postSet')
|
|
7
8
|
|
|
8
9
|
const gitUrl = require('./helpers/gitUrl')
|
|
9
10
|
const gitBranch = require('./helpers/gitBranch')
|
|
@@ -57,6 +58,22 @@ const get = async function (uri, options = {}) {
|
|
|
57
58
|
return value
|
|
58
59
|
}
|
|
59
60
|
|
|
61
|
+
const set = async function (uri, value, options = {}) {
|
|
62
|
+
const sesh = new Session() // TODO: handle scenario where constructor fails
|
|
63
|
+
|
|
64
|
+
let hostname = process.env.DOTENVX_OPS_HOSTNAME || process.env.DOTENVX_RADAR_HOSTNAME || options.hostname
|
|
65
|
+
if (!hostname) {
|
|
66
|
+
hostname = sesh.hostname()
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
let token = process.env.DOTENVX_OPS_TOKEN || process.env.DOTENVX_RADAR_TOKEN || options.token
|
|
70
|
+
if (!token) {
|
|
71
|
+
token = sesh.token()
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return await new PostSet(hostname, token, uri, value).run()
|
|
75
|
+
}
|
|
76
|
+
|
|
60
77
|
const config = function (options = {}) {
|
|
61
78
|
return dotenvx.config(options)
|
|
62
79
|
}
|
|
@@ -64,6 +81,7 @@ const config = function (options = {}) {
|
|
|
64
81
|
module.exports = {
|
|
65
82
|
observe,
|
|
66
83
|
get,
|
|
84
|
+
set,
|
|
67
85
|
// dotenv proxies
|
|
68
86
|
config
|
|
69
87
|
}
|