backend-manager 2.5.49 → 2.5.51
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 +1 -1
- package/src/manager/functions/core/actions/api/admin/backup.js +43 -38
- package/src/manager/functions/core/actions/api/admin/sync-users.js +1 -1
- package/src/manager/functions/core/cron/daily.js +12 -11
- package/src/manager/index.js +1 -1
- package/templates/backend-manager-config.json +0 -1
package/package.json
CHANGED
|
@@ -18,52 +18,57 @@ Module.prototype.main = function () {
|
|
|
18
18
|
|
|
19
19
|
payload.data.payload.deletionRegex = payload.data.payload.deletionRegex ? powertools.regexify(payload.data.payload.deletionRegex) : payload.data.payload.deletionRegex;
|
|
20
20
|
|
|
21
|
-
if (!payload.user.roles.admin) {
|
|
21
|
+
if (!payload.user.roles.admin && assistant.meta.environment === 'production') {
|
|
22
22
|
return reject(assistant.errorManager(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
|
|
23
|
-
}
|
|
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
|
|
27
|
-
const client = new self.libraries.admin.firestore.v1.FirestoreAdminClient({
|
|
28
|
-
// credential: Manager.libraries.admin.credential.cert(
|
|
29
|
-
// require(Manager.project.serviceAccountPath)
|
|
30
|
-
// ),
|
|
31
|
-
});
|
|
32
|
-
const projectId = Manager.project.projectId;
|
|
33
|
-
const resourceZone = Manager.project.resourceZone;
|
|
34
|
-
const databaseName = client.databasePath(projectId, '(default)');
|
|
35
|
-
const bucketName = `bm-backup-firestore-${projectId}`;
|
|
36
|
-
const bucketAddress = `gs://${bucketName}`;
|
|
37
|
-
|
|
38
|
-
await self.createBucket(bucketName, resourceZone);
|
|
39
|
-
// await self.deleteOldFiles(bucketName, resourceZone);
|
|
40
|
-
|
|
41
|
-
client.exportDocuments({
|
|
42
|
-
name: databaseName,
|
|
43
|
-
outputUriPrefix: bucketAddress,
|
|
44
|
-
// Leave collectionIds empty to export all collections
|
|
45
|
-
// or set to a list of collection IDs to export,
|
|
46
|
-
collectionIds: []
|
|
47
|
-
})
|
|
48
|
-
.then(async (responses) => {
|
|
23
|
+
}
|
|
49
24
|
|
|
50
|
-
|
|
25
|
+
// https://googleapis.dev/nodejs/firestore/latest/v1.FirestoreAdminClient.html#exportDocuments
|
|
26
|
+
// https://firebase.google.com/docs/firestore/solutions/schedule-export#firebase-cli
|
|
27
|
+
// https://levelup.gitconnected.com/how-to-back-up-firestore-easily-and-automatically-eab6bf0d7e1f
|
|
28
|
+
const client = new self.libraries.admin.firestore.v1.FirestoreAdminClient({
|
|
29
|
+
// credential: Manager.libraries.admin.credential.cert(
|
|
30
|
+
// require(Manager.project.serviceAccountPath)
|
|
31
|
+
// ),
|
|
32
|
+
});
|
|
33
|
+
const projectId = Manager.project.projectId;
|
|
34
|
+
const resourceZone = Manager.project.resourceZone;
|
|
35
|
+
const databaseName = client.databasePath(projectId, '(default)');
|
|
36
|
+
const bucketName = `bm-backup-firestore-${projectId}`;
|
|
37
|
+
const bucketAddress = `gs://${bucketName}`;
|
|
38
|
+
|
|
39
|
+
await self.createBucket(bucketName, resourceZone);
|
|
40
|
+
// await self.deleteOldFiles(bucketName, resourceZone);
|
|
41
|
+
|
|
42
|
+
client.exportDocuments({
|
|
43
|
+
name: databaseName,
|
|
44
|
+
outputUriPrefix: bucketAddress,
|
|
45
|
+
// Leave collectionIds empty to export all collections
|
|
46
|
+
// or set to a list of collection IDs to export,
|
|
47
|
+
collectionIds: []
|
|
48
|
+
})
|
|
49
|
+
.then(async (responses) => {
|
|
51
50
|
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
const response = responses[0];
|
|
52
|
+
const meta = {
|
|
53
|
+
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
assistant.log('Saved backup successfully:', response.metadata.outputUriPrefix, meta, {environment: 'development'})
|
|
57
|
+
|
|
58
|
+
await self._setMetaStats(null, meta);
|
|
59
|
+
|
|
60
|
+
return resolve(response['name']);
|
|
61
|
+
})
|
|
62
|
+
.catch(async (e) => {
|
|
63
|
+
await self._setMetaStats(e);
|
|
64
|
+
return reject(assistant.errorManager(e, {code: 500, sentry: false, send: false, log: true}).error)
|
|
65
|
+
});
|
|
54
66
|
|
|
55
|
-
return resolve(response['name']);
|
|
56
|
-
})
|
|
57
|
-
.catch(async (e) => {
|
|
58
|
-
await self._setMetaStats(e);
|
|
59
|
-
return reject(assistant.errorManager(e, {code: 500, sentry: false, send: false, log: true}).error)
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
67
|
});
|
|
63
68
|
|
|
64
69
|
};
|
|
65
70
|
|
|
66
|
-
Module.prototype._setMetaStats = function (error) {
|
|
71
|
+
Module.prototype._setMetaStats = function (error, meta) {
|
|
67
72
|
const self = this;
|
|
68
73
|
const Manager = self.Manager;
|
|
69
74
|
const Api = self.Api;
|
|
@@ -38,17 +38,18 @@ Module.prototype.main = function() {
|
|
|
38
38
|
}),
|
|
39
39
|
|
|
40
40
|
// Sync Firestore users to the database
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
})
|
|
41
|
+
// TODO: This is not working becaues the pageToken is not relative any more when its saved...
|
|
42
|
+
// fetch(`${Manager.project.functionsUrl}/bm_api`, {
|
|
43
|
+
// method: 'post',
|
|
44
|
+
// response: 'json',
|
|
45
|
+
// body: {
|
|
46
|
+
// backendManagerKey: Manager.config.backend_manager.key,
|
|
47
|
+
// command: 'admin:sync-users',
|
|
48
|
+
// }
|
|
49
|
+
// })
|
|
50
|
+
// .then(response => {
|
|
51
|
+
// assistant.log(`Successfully executed sync-users:`, response, {environment: 'production'})
|
|
52
|
+
// }),
|
|
52
53
|
|
|
53
54
|
// More daily processes
|
|
54
55
|
// ...
|
package/src/manager/index.js
CHANGED
|
@@ -177,7 +177,7 @@ Manager.prototype.init = function (exporter, options) {
|
|
|
177
177
|
const serviceAccount = require(self.project.serviceAccountPath);
|
|
178
178
|
self.libraries.initializedAdmin = self.libraries.admin.initializeApp({
|
|
179
179
|
credential: self.libraries.admin.credential.cert(serviceAccount),
|
|
180
|
-
databaseURL: self.project.databaseURL
|
|
180
|
+
databaseURL: self.project.databaseURL || `https://${self.project.projectId}.firebaseio.com`,
|
|
181
181
|
}, options.uniqueAppName);
|
|
182
182
|
|
|
183
183
|
// const loadedProjectId = get(self.libraries.initializedAdmin, 'options_.credential.projectId', null);
|