backend-manager 2.4.10 → 2.4.13
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/package.json
CHANGED
package/src/cli/cli.js
CHANGED
|
@@ -259,6 +259,8 @@ Main.prototype.setup = async function () {
|
|
|
259
259
|
throw new Error('Missing <engines.node> in package.json')
|
|
260
260
|
}
|
|
261
261
|
|
|
262
|
+
|
|
263
|
+
// Tests
|
|
262
264
|
await self.test('is a firebase project', async function () {
|
|
263
265
|
let exists = jetpack.exists(`${self.firebaseProjectPath}/firebase.json`);
|
|
264
266
|
return exists;
|
|
@@ -477,6 +479,15 @@ Main.prototype.setup = async function () {
|
|
|
477
479
|
return !localIndexes_exists || equal
|
|
478
480
|
}, NOFIX);
|
|
479
481
|
|
|
482
|
+
await self.test('add roles/datastore.importExportAdmin', async function () {
|
|
483
|
+
const result = await cmd_iamImportExport(self).catch(e => e);
|
|
484
|
+
return !(result instanceof Error);
|
|
485
|
+
}, NOFIX);
|
|
486
|
+
|
|
487
|
+
await self.test('set storage lifecycle policy', async function () {
|
|
488
|
+
const result = await cmd_setStorageLifecycle(self).catch(e => e);
|
|
489
|
+
return !(result instanceof Error);
|
|
490
|
+
}, NOFIX);
|
|
480
491
|
|
|
481
492
|
// Update actual files
|
|
482
493
|
await self.test('update firestore rules file', function () {
|
|
@@ -525,6 +536,12 @@ Main.prototype.setup = async function () {
|
|
|
525
536
|
return true;
|
|
526
537
|
}, NOFIX);
|
|
527
538
|
|
|
539
|
+
// await self.test('add roles/datastore.importExportAdmin', function () {
|
|
540
|
+
// const result = await cmd_iamImportExport(self);
|
|
541
|
+
// console.log('---result', result);
|
|
542
|
+
// return true;
|
|
543
|
+
// }, NOFIX);
|
|
544
|
+
|
|
528
545
|
// await self.test('has mocha package.json script', function () {
|
|
529
546
|
// let script = _.get(self.package, 'scripts.test', '')
|
|
530
547
|
// return script === MOCHA_PKG_SCRIPT;
|
|
@@ -1191,6 +1208,44 @@ async function cmd_configUnset(self) {
|
|
|
1191
1208
|
});
|
|
1192
1209
|
}
|
|
1193
1210
|
|
|
1211
|
+
async function cmd_iamImportExport(self) {
|
|
1212
|
+
return new Promise(function(resolve, reject) {
|
|
1213
|
+
const command = `
|
|
1214
|
+
gcloud projects add-iam-policy-binding {projectId} \
|
|
1215
|
+
--member serviceAccount:{projectId}@appspot.gserviceaccount.com \
|
|
1216
|
+
--role roles/datastore.importExportAdmin
|
|
1217
|
+
`
|
|
1218
|
+
.replace(/{projectId}/ig, self.projectName)
|
|
1219
|
+
|
|
1220
|
+
let cmd = exec(command, function (error, stdout, stderr) {
|
|
1221
|
+
if (error) {
|
|
1222
|
+
console.log(chalk.red(`Failed to run command`, error));
|
|
1223
|
+
reject(error);
|
|
1224
|
+
} else {
|
|
1225
|
+
// console.log(chalk.green(`Added permission`));
|
|
1226
|
+
resolve(stdout);
|
|
1227
|
+
}
|
|
1228
|
+
});
|
|
1229
|
+
});
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
async function cmd_setStorageLifecycle(self) {
|
|
1233
|
+
return new Promise(function(resolve, reject) {
|
|
1234
|
+
const command = `gsutil lifecycle set {config} gs://{bucket}`
|
|
1235
|
+
.replace(/{config}/ig, path.resolve(`${__dirname}/../../templates/storage-lifecycle-config.json`))
|
|
1236
|
+
.replace(/{bucket}/ig, `us.artifacts.${self.projectName}.appspot.com`)
|
|
1237
|
+
|
|
1238
|
+
let cmd = exec(command, function (error, stdout, stderr) {
|
|
1239
|
+
if (error) {
|
|
1240
|
+
console.log(chalk.red(`Failed to run command`, error));
|
|
1241
|
+
reject(error);
|
|
1242
|
+
} else {
|
|
1243
|
+
// console.log(chalk.green(`Added lifecycle`));
|
|
1244
|
+
resolve(stdout);
|
|
1245
|
+
}
|
|
1246
|
+
});
|
|
1247
|
+
});
|
|
1248
|
+
}
|
|
1194
1249
|
|
|
1195
1250
|
// HELPER
|
|
1196
1251
|
|
|
@@ -45,13 +45,16 @@ Module.prototype.main = function () {
|
|
|
45
45
|
// or set to a list of collection IDs to export,
|
|
46
46
|
collectionIds: []
|
|
47
47
|
})
|
|
48
|
-
.then(responses => {
|
|
48
|
+
.then(async (responses) => {
|
|
49
|
+
|
|
50
|
+
await self._setMetaStats();
|
|
51
|
+
|
|
49
52
|
const response = responses[0];
|
|
50
|
-
// assistant.log('Saved backup successfully', response['name'], {environment: 'development'})
|
|
51
53
|
assistant.log('Saved backup successfully:', response.metadata.outputUriPrefix, {environment: 'development'})
|
|
52
54
|
return resolve(response['name']);
|
|
53
55
|
})
|
|
54
|
-
.catch(e => {
|
|
56
|
+
.catch(async (e) => {
|
|
57
|
+
await self._setMetaStats(e);
|
|
55
58
|
return reject(assistant.errorManager(e, {code: 500, sentry: false, send: false, log: true}).error)
|
|
56
59
|
});
|
|
57
60
|
|
|
@@ -60,6 +63,40 @@ Module.prototype.main = function () {
|
|
|
60
63
|
|
|
61
64
|
};
|
|
62
65
|
|
|
66
|
+
Module.prototype._setMetaStats = function (error) {
|
|
67
|
+
const self = this;
|
|
68
|
+
const Manager = self.Manager;
|
|
69
|
+
const Api = self.Api;
|
|
70
|
+
const assistant = self.assistant;
|
|
71
|
+
const payload = self.payload;
|
|
72
|
+
|
|
73
|
+
return new Promise(async function(resolve, reject) {
|
|
74
|
+
error = error || false;
|
|
75
|
+
const isError = error instanceof Error;
|
|
76
|
+
|
|
77
|
+
await self.libraries.admin.firestore().doc('meta/stats')
|
|
78
|
+
.set({
|
|
79
|
+
backups: {
|
|
80
|
+
lastBackup: {
|
|
81
|
+
date: {
|
|
82
|
+
timestamp: assistant.meta.startTime.timestamp,
|
|
83
|
+
timestampUNIX: assistant.meta.startTime.timestampUNIX,
|
|
84
|
+
},
|
|
85
|
+
status: {
|
|
86
|
+
success: !isError,
|
|
87
|
+
error: error,
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}, {merge: true})
|
|
92
|
+
.catch(e => {
|
|
93
|
+
assistant.errorManager(e, {code: 500, sentry: false, send: false, log: true});
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
return resolve();
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
|
|
63
100
|
Module.prototype.createBucket = function (bucketName, resourceZone) {
|
|
64
101
|
const self = this;
|
|
65
102
|
const Manager = self.Manager;
|
|
@@ -30,7 +30,7 @@ Module.prototype.main = function() {
|
|
|
30
30
|
}
|
|
31
31
|
})
|
|
32
32
|
.then(response => {
|
|
33
|
-
assistant.log(`Successfully executed backup
|
|
33
|
+
assistant.log(`Successfully executed backup:`, response, {environment: 'production'})
|
|
34
34
|
return resolve(response);
|
|
35
35
|
})
|
|
36
36
|
.catch(e => {
|