backend-manager 2.4.9 → 2.4.12

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backend-manager",
3
- "version": "2.4.9",
3
+ "version": "2.4.12",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -67,4 +67,4 @@
67
67
  "src/",
68
68
  "templates/"
69
69
  ]
70
- }
70
+ }
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
 
@@ -21,10 +21,13 @@ Module.prototype.main = function () {
21
21
  if (!payload.user.roles.admin) {
22
22
  return reject(assistant.errorManager(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
23
23
  } else {
24
+ // https://googleapis.dev/nodejs/firestore/latest/v1.FirestoreAdminClient.html#exportDocuments
25
+ // https://firebase.google.com/docs/firestore/solutions/schedule-export#firebase-cli
26
+ // https://levelup.gitconnected.com/how-to-back-up-firestore-easily-and-automatically-eab6bf0d7e1f
24
27
  const client = new self.libraries.admin.firestore.v1.FirestoreAdminClient({
25
- credential: Manager.libraries.admin.credential.cert(
26
- require(Manager.project.serviceAccountPath)
27
- ),
28
+ // credential: Manager.libraries.admin.credential.cert(
29
+ // require(Manager.project.serviceAccountPath)
30
+ // ),
28
31
  });
29
32
  const projectId = Manager.project.projectId;
30
33
  const resourceZone = Manager.project.resourceZone;
@@ -52,7 +55,6 @@ Module.prototype.main = function () {
52
55
  return reject(assistant.errorManager(e, {code: 500, sentry: false, send: false, log: true}).error)
53
56
  });
54
57
 
55
-
56
58
  }
57
59
  });
58
60
 
@@ -30,7 +30,7 @@ Module.prototype.main = function() {
30
30
  }
31
31
  })
32
32
  .then(response => {
33
- assistant.log(`Successfully executed backup: ${response}`, {environment: 'production'})
33
+ assistant.log(`Successfully executed backup:`, response, {environment: 'production'})
34
34
  return resolve(response);
35
35
  })
36
36
  .catch(e => {
@@ -0,0 +1,9 @@
1
+ {
2
+ "rule":
3
+ [
4
+ {
5
+ "action": {"type": "Delete"},
6
+ "condition": {"age": 1}
7
+ }
8
+ ]
9
+ }