@dotenvx/dotenvx-ops 0.27.0 → 0.28.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/backup.js +53 -0
- package/src/cli/dotenvx-ops.js +8 -0
- package/src/lib/api/postBackup.js +65 -0
- package/src/lib/services/backup.js +68 -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.28.0...main)
|
|
6
|
+
|
|
7
|
+
## [0.28.0](https://github.com/dotenvx/dotenvx-ops/compare/v0.27.0...v0.28.0) (2025-12-22)
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
* Add `backup` command for backing up .env.keys files. Will serve as entry-level low priced product to serve many. ([#18](https://github.com/dotenvx/dotenvx-ops/pull/18))
|
|
6
12
|
|
|
7
13
|
## [0.27.0](https://github.com/dotenvx/dotenvx-ops/compare/v0.26.0...v0.27.0) (2025-12-14)
|
|
8
14
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// const fs = require('fs')
|
|
2
|
+
// const crypto = require('crypto')
|
|
3
|
+
|
|
4
|
+
const { logger } = require('@dotenvx/dotenvx')
|
|
5
|
+
|
|
6
|
+
const { createSpinner } = require('./../../lib/helpers/createSpinner')
|
|
7
|
+
|
|
8
|
+
const Backup = require('./../../lib/services/backup')
|
|
9
|
+
|
|
10
|
+
const spinner = createSpinner('backing up')
|
|
11
|
+
|
|
12
|
+
async function backup () {
|
|
13
|
+
// debug opts
|
|
14
|
+
const options = this.opts()
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
18
|
+
|
|
19
|
+
spinner.start()
|
|
20
|
+
|
|
21
|
+
const {
|
|
22
|
+
projectUsernameName,
|
|
23
|
+
files
|
|
24
|
+
} = await new Backup(options.hostname, options.force).run()
|
|
25
|
+
logger.debug(`files: ${JSON.stringify(files)}`)
|
|
26
|
+
|
|
27
|
+
// write output files
|
|
28
|
+
// for (const file of files) {
|
|
29
|
+
// // const { filepath, src, sha } = file
|
|
30
|
+
// }
|
|
31
|
+
|
|
32
|
+
spinner.stop()
|
|
33
|
+
|
|
34
|
+
logger.success(`✔ backed up [${projectUsernameName}]`)
|
|
35
|
+
} catch (error) {
|
|
36
|
+
spinner.stop()
|
|
37
|
+
if (error.message) {
|
|
38
|
+
logger.error(error.message)
|
|
39
|
+
} else {
|
|
40
|
+
logger.error(error)
|
|
41
|
+
}
|
|
42
|
+
if (error.help) {
|
|
43
|
+
logger.help(error.help)
|
|
44
|
+
}
|
|
45
|
+
if (error.stack) {
|
|
46
|
+
logger.debug(error.stack)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
process.exit(1)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
module.exports = backup
|
package/src/cli/dotenvx-ops.js
CHANGED
|
@@ -30,6 +30,14 @@ program
|
|
|
30
30
|
.version(packageJson.version)
|
|
31
31
|
.allowUnknownOption()
|
|
32
32
|
|
|
33
|
+
// dotenvx-ops backup
|
|
34
|
+
const backupAction = require('./actions/backup')
|
|
35
|
+
program
|
|
36
|
+
.command('backup')
|
|
37
|
+
.description('backup .env.keys file(s)')
|
|
38
|
+
.option('-h, --hostname <url>', 'set hostname', sesh.hostname())
|
|
39
|
+
.action(backupAction)
|
|
40
|
+
|
|
33
41
|
// dotenvx-ops observe base64String
|
|
34
42
|
const observeAction = require('./actions/observe')
|
|
35
43
|
program.command('observe')
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
const { http } = require('../../lib/helpers/http')
|
|
2
|
+
const buildApiError = require('../../lib/helpers/buildApiError')
|
|
3
|
+
const packageJson = require('../../lib/helpers/packageJson')
|
|
4
|
+
|
|
5
|
+
class PostBackup {
|
|
6
|
+
constructor (hostname, token, devicePublicKey, encoded, dotenvxProjectId, pwd = null, gitUrl = null, gitBranch = null, systemUuid = null, osPlatform = null, osArch = null) {
|
|
7
|
+
this.hostname = hostname || 'https://ops.dotenvx.com'
|
|
8
|
+
this.token = token
|
|
9
|
+
this.devicePublicKey = devicePublicKey
|
|
10
|
+
this.encoded = encoded
|
|
11
|
+
this.dotenvxProjectId = dotenvxProjectId
|
|
12
|
+
this.pwd = pwd
|
|
13
|
+
this.gitUrl = gitUrl
|
|
14
|
+
this.gitBranch = gitBranch
|
|
15
|
+
this.systemUuid = systemUuid
|
|
16
|
+
this.osPlatform = osPlatform
|
|
17
|
+
this.osArch = osArch
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async run () {
|
|
21
|
+
const token = this.token
|
|
22
|
+
const devicePublicKey = this.devicePublicKey
|
|
23
|
+
const url = `${this.hostname}/api/backup`
|
|
24
|
+
const encoded = this.encoded
|
|
25
|
+
const dotenvxProjectId = this.dotenvxProjectId
|
|
26
|
+
const backedupAt = new Date().toISOString()
|
|
27
|
+
const pwd = this.pwd
|
|
28
|
+
const gitUrl = this.gitUrl
|
|
29
|
+
const gitBranch = this.gitBranch
|
|
30
|
+
const systemUuid = this.systemUuid
|
|
31
|
+
const osPlatform = this.osPlatform
|
|
32
|
+
const osArch = this.osArch
|
|
33
|
+
|
|
34
|
+
const resp = await http(url, {
|
|
35
|
+
method: 'POST',
|
|
36
|
+
headers: {
|
|
37
|
+
Authorization: `Bearer ${token}`,
|
|
38
|
+
'Content-Type': 'application/json'
|
|
39
|
+
},
|
|
40
|
+
body: JSON.stringify({
|
|
41
|
+
device_public_key: devicePublicKey,
|
|
42
|
+
encoded,
|
|
43
|
+
dotenvx_project_id: dotenvxProjectId,
|
|
44
|
+
backedup_at: backedupAt,
|
|
45
|
+
pwd,
|
|
46
|
+
git_url: gitUrl,
|
|
47
|
+
git_branch: gitBranch,
|
|
48
|
+
system_uuid: systemUuid,
|
|
49
|
+
os_platform: osPlatform,
|
|
50
|
+
os_arch: osArch,
|
|
51
|
+
cli_version: packageJson.version
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
const json = await resp.body.json()
|
|
56
|
+
|
|
57
|
+
if (resp.statusCode >= 400) {
|
|
58
|
+
throw buildApiError(resp.statusCode, json)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return json
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
module.exports = PostBackup
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const path = require('path')
|
|
3
|
+
const si = require('systeminformation')
|
|
4
|
+
const dotenvx = require('@dotenvx/dotenvx')
|
|
5
|
+
|
|
6
|
+
const Session = require('./../../db/session')
|
|
7
|
+
|
|
8
|
+
const gitUrl = require('./../helpers/gitUrl')
|
|
9
|
+
const gitBranch = require('./../helpers/gitBranch')
|
|
10
|
+
const dotenvxProjectId = require('./../helpers/dotenvxProjectId')
|
|
11
|
+
|
|
12
|
+
// api calls
|
|
13
|
+
const PostBackup = require('./../api/postBackup')
|
|
14
|
+
|
|
15
|
+
class Backup {
|
|
16
|
+
constructor (hostname) {
|
|
17
|
+
this.hostname = hostname
|
|
18
|
+
this.cwd = process.cwd()
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async run () {
|
|
22
|
+
const sesh = new Session()
|
|
23
|
+
const token = sesh.token()
|
|
24
|
+
const devicePublicKey = sesh.devicePublicKey()
|
|
25
|
+
|
|
26
|
+
// required
|
|
27
|
+
const files = this._files()
|
|
28
|
+
const payload = { files }
|
|
29
|
+
const encoded = Buffer.from(JSON.stringify(payload)).toString('base64')
|
|
30
|
+
const _dotenvxProjectId = dotenvxProjectId(this.cwd)
|
|
31
|
+
|
|
32
|
+
// optional
|
|
33
|
+
const _pwd = this.cwd
|
|
34
|
+
const _gitUrl = gitUrl()
|
|
35
|
+
const _gitBranch = gitBranch()
|
|
36
|
+
|
|
37
|
+
const system = await si.system()
|
|
38
|
+
const _systemUuid = system.uuid
|
|
39
|
+
|
|
40
|
+
const osInfo = await si.osInfo()
|
|
41
|
+
const _osPlatform = osInfo.platform
|
|
42
|
+
const _osArch = osInfo.arch
|
|
43
|
+
|
|
44
|
+
const data = await new PostBackup(this.hostname, token, devicePublicKey, encoded, _dotenvxProjectId, _pwd, _gitUrl, _gitBranch, _systemUuid, _osPlatform, _osArch).run()
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
id: data.id,
|
|
48
|
+
dotenvxProjectId: data.dotenvx_project_id,
|
|
49
|
+
projectUsernameName: data.project_username_name,
|
|
50
|
+
files: data.files
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
_files () {
|
|
55
|
+
const out = []
|
|
56
|
+
const filepaths = dotenvx.ls(this.cwd, '.env.keys*')
|
|
57
|
+
|
|
58
|
+
for (const fp of filepaths) {
|
|
59
|
+
const abs = path.join(this.cwd, fp)
|
|
60
|
+
const src = fs.readFileSync(abs, 'utf8')
|
|
61
|
+
out.push({ filepath: fp, src })
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return out
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
module.exports = Backup
|