reviewable-enterprise-tools 1.3.8 → 1.4.1
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/extract_data.js +1 -1
- package/lib/loadFirebase.js +5 -5
- package/package.json +3 -3
- package/write.js +51 -0
package/extract_data.js
CHANGED
|
@@ -55,7 +55,7 @@ for (const property of ['repos', 'output']) {
|
|
|
55
55
|
let uploadedFilesUrlRegex;
|
|
56
56
|
if (uploadedFilesUrl) {
|
|
57
57
|
uploadedFilesUrlRegex =
|
|
58
|
-
new RegExp(`(${_.escapeRegExp(uploadedFilesUrl)})((?:[^)]|\\(\\d+\\))*)`, 'g');
|
|
58
|
+
new RegExp(`(${_.escapeRegExp(uploadedFilesUrl)})((?:[^())]|\\(\\d+\\))*)`, 'g');
|
|
59
59
|
} else {
|
|
60
60
|
console.warn(
|
|
61
61
|
'WARNING: no REVIEWABLE_UPLOADS_PROVIDER or REVIEWABLE_UPLOADED_FILES_URL specified, ' +
|
package/lib/loadFirebase.js
CHANGED
|
@@ -5,7 +5,7 @@ import * as path from 'path';
|
|
|
5
5
|
import {fileURLToPath} from 'url';
|
|
6
6
|
import admin from 'firebase-admin';
|
|
7
7
|
import nodefireModule from 'nodefire';
|
|
8
|
-
import {
|
|
8
|
+
import {wrapDatabaseWithEncryption} from 'firecrypt';
|
|
9
9
|
|
|
10
10
|
const NodeFire = nodefireModule.default;
|
|
11
11
|
|
|
@@ -21,8 +21,6 @@ if (!process.env.REVIEWABLE_FIREBASE_URL) {
|
|
|
21
21
|
process.exit(1);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
if (process.env.REVIEWABLE_ENCRYPTION_AES_KEY) patchFirebase();
|
|
25
|
-
|
|
26
24
|
const firebaseConfig = {
|
|
27
25
|
databaseURL: process.env.REVIEWABLE_FIREBASE_URL,
|
|
28
26
|
databaseAuthVariableOverride: {uid: 'server'},
|
|
@@ -70,7 +68,9 @@ a key JSON file with the required values.`
|
|
|
70
68
|
|
|
71
69
|
admin.initializeApp(firebaseConfig);
|
|
72
70
|
|
|
71
|
+
let database = admin.database();
|
|
73
72
|
if (process.env.REVIEWABLE_ENCRYPTION_AES_KEY) {
|
|
73
|
+
const firecrypt = database = wrapDatabaseWithEncryption(database);
|
|
74
74
|
const options = {
|
|
75
75
|
algorithm: 'aes-siv', key: process.env.REVIEWABLE_ENCRYPTION_AES_KEY,
|
|
76
76
|
cacheSize: FIRECRYPT_CACHE_SIZE
|
|
@@ -78,9 +78,9 @@ if (process.env.REVIEWABLE_ENCRYPTION_AES_KEY) {
|
|
|
78
78
|
const dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
79
79
|
const specification = JSON.parse(fs.readFileSync(
|
|
80
80
|
path.join(dirname, '..', 'rules_firecrypt.json'), 'utf8'));
|
|
81
|
-
|
|
81
|
+
firecrypt.configureEncryption(options, specification);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
global.db = new NodeFire(
|
|
84
|
+
global.db = new NodeFire(database.ref());
|
|
85
85
|
|
|
86
86
|
export default admin;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reviewable-enterprise-tools",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Admin tools for Reviewable Enterprise",
|
|
6
6
|
"bin": {
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"command-line-usage": "^6.1.0",
|
|
41
41
|
"download": "^8.0.0",
|
|
42
42
|
"event-stream": "^4.0.1",
|
|
43
|
-
"firebase-admin": "
|
|
44
|
-
"firecrypt": "^
|
|
43
|
+
"firebase-admin": "11.x",
|
|
44
|
+
"firecrypt": "^3.0.0",
|
|
45
45
|
"hubkit": "^3.0.0",
|
|
46
46
|
"lodash": "^4.17.20",
|
|
47
47
|
"ms": "^2.1.2",
|
package/write.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import commandLineArgs from 'command-line-args';
|
|
4
|
+
import getUsage from 'command-line-usage';
|
|
5
|
+
import fs from 'fs';
|
|
6
|
+
|
|
7
|
+
const commandLineOptions = [
|
|
8
|
+
{name: 'path', alias: 'p', type: String,
|
|
9
|
+
description: 'The path in Firebase to which to write data. You can omit the leading slash.'},
|
|
10
|
+
{name: 'file', alias: 'f', type: String,
|
|
11
|
+
description: 'The JSON file containing the data'},
|
|
12
|
+
{name: 'help', alias: 'h', type: Boolean,
|
|
13
|
+
description: 'Display these usage instructions.'}
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
const usageSpec = [
|
|
17
|
+
{header: 'Data readout tool',
|
|
18
|
+
content:
|
|
19
|
+
'Writes stdin stream to a given path in Firebase, encrypting if necessary. ' +
|
|
20
|
+
'REVIEWABLE_FIREBASE_URL, REVIEWABLE_FIREBASE_CREDENTIALS_FILE, and ' +
|
|
21
|
+
'REVIEWABLE_ENCRYPTION_AES_KEY must be set.'
|
|
22
|
+
},
|
|
23
|
+
{header: 'Options', optionList: commandLineOptions}
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
const args = commandLineArgs(commandLineOptions);
|
|
27
|
+
if (args.help) {
|
|
28
|
+
console.log(getUsage(usageSpec));
|
|
29
|
+
process.exit(0);
|
|
30
|
+
}
|
|
31
|
+
for (const property of ['path', 'file']) {
|
|
32
|
+
if (!(property in args)) {
|
|
33
|
+
console.log('Missing required option: ' + property + '.');
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function write() {
|
|
39
|
+
await import('./lib/loadFirebase.js');
|
|
40
|
+
args.path = args.path.replace(/^\//, '');
|
|
41
|
+
const value = JSON.parse(fs.readFileSync(args.file));
|
|
42
|
+
await db.child(args.path).set(value);
|
|
43
|
+
console.log('Done');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
write().then(() => {
|
|
47
|
+
process.exit(0);
|
|
48
|
+
}, e => {
|
|
49
|
+
console.log(e);
|
|
50
|
+
process.exit(1);
|
|
51
|
+
});
|