@dooer/dooer-test-env 1.17.2 → 1.18.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/lib/command/customer.js +35 -0
- package/package.json +1 -1
package/lib/command/customer.js
CHANGED
|
@@ -2,6 +2,28 @@ const fs = require('fs')
|
|
|
2
2
|
const chalk = require('chalk')
|
|
3
3
|
const remote = require('../remote')
|
|
4
4
|
const serviceClient = require('../service-client')
|
|
5
|
+
|
|
6
|
+
// Run the documented shredder over the local database. Emails are already anonymized by the copy itself;
|
|
7
|
+
// this is the rest of the PII.
|
|
8
|
+
async function shredLocal() {
|
|
9
|
+
console.log(chalk.bold('\nshredding the local database…'))
|
|
10
|
+
const { shred } = require('../shred')
|
|
11
|
+
const { Client } = require('pg')
|
|
12
|
+
const client = new Client({ host: 'localhost', port: 55432, user: 'dooer', password: 'dooer', database: 'dooer' })
|
|
13
|
+
await client.connect()
|
|
14
|
+
try {
|
|
15
|
+
const result = await shred(client, { execute: true })
|
|
16
|
+
const failed = (result && result.failed) || []
|
|
17
|
+
if (failed.length) {
|
|
18
|
+
// Say so rather than letting a partial shred read as a clean one.
|
|
19
|
+
console.log(chalk.yellow(` ${failed.length} shred script(s) failed — local PII is NOT fully anonymized\n`))
|
|
20
|
+
} else {
|
|
21
|
+
console.log(chalk.green(` shredded ${((result && result.scripts) || []).length} script(s)\n`))
|
|
22
|
+
}
|
|
23
|
+
} finally {
|
|
24
|
+
await client.end().catch(() => {})
|
|
25
|
+
}
|
|
26
|
+
}
|
|
5
27
|
const { createAccount, SUBSCRIPTION_TYPES } = require('../account')
|
|
6
28
|
|
|
7
29
|
// `copy` now runs through service-dooer-test-env (export in the source, import in the target) instead of
|
|
@@ -65,6 +87,10 @@ const copyOptions = (y) =>
|
|
|
65
87
|
.option('skip-users', { type: 'boolean', describe: 'skip copying referenced users missing from the target' })
|
|
66
88
|
.option('confirm-production', { type: 'boolean', describe: 'REQUIRED to write to dooer-production' })
|
|
67
89
|
.option('reason', { type: 'string', describe: 'recorded in the audit trail at both ends' })
|
|
90
|
+
.option('shred', {
|
|
91
|
+
type: 'boolean',
|
|
92
|
+
describe: 'after a LOCAL copy, run the shredder over the local database (localhost only)',
|
|
93
|
+
})
|
|
68
94
|
.option('execute', { type: 'boolean', default: false, describe: 'actually write (default: dry-run)' })
|
|
69
95
|
|
|
70
96
|
module.exports = {
|
|
@@ -82,6 +108,12 @@ module.exports = {
|
|
|
82
108
|
const targetEnv = envFromFlags(argv.targetLocal, argv.targetNamespace, sourceEnv)
|
|
83
109
|
const { copyOrganization } = require('../copy')
|
|
84
110
|
|
|
111
|
+
// Shredding is whole-database and localhost-only by design (see command/shred.js), so it can
|
|
112
|
+
// only follow a copy INTO local, and only once — not per org in a batch.
|
|
113
|
+
if (argv.shred && targetEnv !== 'local') {
|
|
114
|
+
throw new Error('--shred only applies to a copy into the local env (the shredder is localhost-only)')
|
|
115
|
+
}
|
|
116
|
+
|
|
85
117
|
if (sources.length === 1) {
|
|
86
118
|
await copyOrganization({
|
|
87
119
|
organizationId: sources[0],
|
|
@@ -90,6 +122,7 @@ module.exports = {
|
|
|
90
122
|
reason: argv.reason,
|
|
91
123
|
dryRun: !argv.execute,
|
|
92
124
|
})
|
|
125
|
+
if (argv.shred && argv.execute) await shredLocal()
|
|
93
126
|
return
|
|
94
127
|
}
|
|
95
128
|
// Batch: each org is a full independent copy (the engine scans the source per org). One bad uuid
|
|
@@ -117,6 +150,8 @@ module.exports = {
|
|
|
117
150
|
)
|
|
118
151
|
)
|
|
119
152
|
failed.forEach((f) => console.log(chalk.red(` ${f.source}: ${f.error}`)))
|
|
153
|
+
// Once, after the whole batch — the shredder covers the entire database.
|
|
154
|
+
if (argv.shred && argv.execute && failed.length < sources.length) await shredLocal()
|
|
120
155
|
if (failed.length) process.exitCode = 1
|
|
121
156
|
},
|
|
122
157
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dooer/dooer-test-env",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.18.0",
|
|
4
4
|
"description": "Run the whole Dooer backend locally (staging DB minus customers), copy/purge customers between environments, and shred — one CLI.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": "Dooer/cli-dooer-test-env",
|