@pi-r/gcp 0.3.4 → 0.3.6
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/LICENSE +6 -6
- package/README.md +4 -6
- package/client/index.js +117 -124
- package/download/index.js +1 -1
- package/package.json +29 -29
- package/types/index.d.ts +40 -0
- package/upload/index.js +1 -1
package/LICENSE
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
Copyright
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
-
|
|
5
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
-
|
|
1
|
+
Copyright 2023 An Pham
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
7
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
package/client/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getProjectId = exports.createBucketRequest = exports.setPredefinedAcl = exports.setPublicRead = exports.executeBatchQuery = exports.executeQuery = exports.deleteObjectsV2 = exports.deleteObjects = exports.setBucketWebsite = exports.setBucketPolicy = exports.createBucketV2 = exports.createBucket = exports.createDatabaseClient = exports.createStorageClient = exports.validateDatabase = exports.validateStorage = exports.isFirebaseApp = void 0;
|
|
4
4
|
const path = require("path");
|
|
5
|
-
const storage = require("@google-cloud/storage");
|
|
6
|
-
const firestore = require("@google-cloud/firestore");
|
|
7
5
|
const util_1 = require("@e-mc/cloud/util");
|
|
8
6
|
const types_1 = require("@e-mc/types");
|
|
9
7
|
const Module = require("@e-mc/module");
|
|
@@ -63,29 +61,23 @@ async function hasBucket(client) {
|
|
|
63
61
|
const [exists] = await client.exists().catch(err => isErrorConflict(err) ? [true] : [false]);
|
|
64
62
|
return exists;
|
|
65
63
|
}
|
|
66
|
-
function updatePredefinedAcl(acl, values, metadata
|
|
64
|
+
function updatePredefinedAcl(acl, values, metadata) {
|
|
65
|
+
const { generation, userProject } = metadata;
|
|
67
66
|
const items = [];
|
|
68
|
-
let projectNumber;
|
|
69
|
-
if ('projectNumber' in metadata || 'defaultObjectAcl' in metadata) {
|
|
70
|
-
let defaultObjectAcl;
|
|
71
|
-
({ projectNumber, defaultObjectAcl } = metadata);
|
|
72
|
-
if (projectNumber === undefined && (0, types_1.isArray)(defaultObjectAcl)) {
|
|
73
|
-
const target = defaultObjectAcl.find(item => { var _a; return (_a = item.projectTeam) === null || _a === void 0 ? void 0 : _a.projectNumber; });
|
|
74
|
-
if (target !== undefined) {
|
|
75
|
-
projectNumber = target.projectTeam.projectNumber;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
67
|
for (const target of acl.default ? [acl, acl.default] : [acl]) {
|
|
80
68
|
items.push(...values.map(async (value) => {
|
|
69
|
+
var _a;
|
|
70
|
+
if (generation !== undefined) {
|
|
71
|
+
(_a = value.generation) !== null && _a !== void 0 ? _a : (value.generation = +generation);
|
|
72
|
+
}
|
|
73
|
+
if (userProject) {
|
|
74
|
+
value.userProject || (value.userProject = userProject);
|
|
75
|
+
}
|
|
81
76
|
const entity = await target.get({ entity: value.entity }).catch(() => null);
|
|
82
77
|
if (entity) {
|
|
83
78
|
return (0, types_1.isString)(value.role) ? target.update(value) : target.delete(value);
|
|
84
79
|
}
|
|
85
80
|
if ((0, types_1.isString)(value.role)) {
|
|
86
|
-
if (projectNumber !== undefined) {
|
|
87
|
-
value.userProject || (value.userProject = projectNumber.toString());
|
|
88
|
-
}
|
|
89
81
|
return target.add(value);
|
|
90
82
|
}
|
|
91
83
|
}));
|
|
@@ -108,8 +100,8 @@ function setUniformBucketLevel(bucket, enabled) {
|
|
|
108
100
|
const getFirebasePackageName = (credential) => credential.apiKey && credential.authDomain ? 'firebase' : 'firebase-admin';
|
|
109
101
|
const hasKeyFile = (credential) => !!(credential.keyFile || credential.keyFilename || process.env.GOOGLE_APPLICATION_CREDENTIALS);
|
|
110
102
|
const isErrorConflict = (err) => (err instanceof Error) && err.code === 409;
|
|
111
|
-
function isFirebaseApp(credential,
|
|
112
|
-
return !!(credential.apiKey && credential.authDomain && (
|
|
103
|
+
function isFirebaseApp(credential, storage, admin) {
|
|
104
|
+
return !!(credential.apiKey && credential.authDomain && (storage || credential.databaseURL) || credential.product === 'firebase' && process.env.GOOGLE_APPLICATION_CREDENTIALS) && (!admin || !credential.admin);
|
|
113
105
|
}
|
|
114
106
|
exports.isFirebaseApp = isFirebaseApp;
|
|
115
107
|
function validateStorage(credential) {
|
|
@@ -121,60 +113,59 @@ function validateDatabase(credential, data) {
|
|
|
121
113
|
}
|
|
122
114
|
exports.validateDatabase = validateDatabase;
|
|
123
115
|
function createStorageClient(credential, bucket) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
116
|
+
let packageName = '';
|
|
117
|
+
try {
|
|
118
|
+
if (isFirebaseApp(credential, true)) {
|
|
127
119
|
if (bucket) {
|
|
128
120
|
credential.storageBucket = bucket;
|
|
129
121
|
}
|
|
130
122
|
packageName = getFirebasePackageName(credential);
|
|
131
123
|
return getApp(credential, false);
|
|
132
124
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
125
|
+
credential.projectId || (credential.projectId = getProjectId(credential));
|
|
126
|
+
const { Storage } = require(packageName = '@google-cloud/storage');
|
|
127
|
+
return new Storage(credential);
|
|
128
|
+
}
|
|
129
|
+
catch (err) {
|
|
130
|
+
this.checkPackage(err, packageName, { passThrough: true });
|
|
131
|
+
throw err;
|
|
137
132
|
}
|
|
138
|
-
credential.projectId || (credential.projectId = getProjectId(credential));
|
|
139
|
-
return new storage.Storage(credential);
|
|
140
133
|
}
|
|
141
134
|
exports.createStorageClient = createStorageClient;
|
|
142
135
|
function createDatabaseClient(credential, data) {
|
|
143
136
|
let packageName = '';
|
|
144
137
|
try {
|
|
145
|
-
|
|
146
|
-
if (data) {
|
|
147
|
-
({ product, name, table } = data);
|
|
148
|
-
}
|
|
138
|
+
const product = data === null || data === void 0 ? void 0 : data.product;
|
|
149
139
|
if (product === 'firebase' || isFirebaseApp(credential)) {
|
|
150
140
|
packageName = getFirebasePackageName(credential);
|
|
151
141
|
return getApp(credential, true);
|
|
152
142
|
}
|
|
153
143
|
credential.projectId || (credential.projectId = getProjectId(credential));
|
|
154
144
|
if (data) {
|
|
155
|
-
if (product === 'spanner' || !product && name && data.database) {
|
|
145
|
+
if (product === 'spanner' || !product && data.name && data.database) {
|
|
156
146
|
const { Spanner } = require(packageName = '@google-cloud/spanner');
|
|
157
147
|
return new Spanner(credential);
|
|
158
148
|
}
|
|
159
|
-
if (product === 'bigtable' || !product && name && table) {
|
|
149
|
+
if (product === 'bigtable' || !product && data.name && data.table) {
|
|
160
150
|
const { Bigtable } = require(packageName = '@google-cloud/bigtable');
|
|
161
151
|
return new Bigtable(credential);
|
|
162
152
|
}
|
|
163
|
-
if (product === 'bigquery' || !product && !table && typeof data.query === 'string') {
|
|
153
|
+
if (product === 'bigquery' || !product && !data.table && typeof data.query === 'string') {
|
|
164
154
|
const { BigQuery } = require(packageName = '@google-cloud/bigquery');
|
|
165
155
|
return new BigQuery(credential);
|
|
166
156
|
}
|
|
167
|
-
if (product === 'datastore' || !product && !table && (data.keys || data.query)) {
|
|
157
|
+
if (product === 'datastore' || !product && !data.table && (data.keys || data.query)) {
|
|
168
158
|
const { Datastore } = require(packageName = '@google-cloud/datastore');
|
|
169
159
|
return new Datastore(credential);
|
|
170
160
|
}
|
|
171
161
|
}
|
|
162
|
+
const { Firestore } = require(packageName = '@google-cloud/firestore');
|
|
163
|
+
return new Firestore(credential);
|
|
172
164
|
}
|
|
173
165
|
catch (err) {
|
|
174
166
|
this.checkPackage(err, packageName, { passThrough: true });
|
|
175
167
|
throw err;
|
|
176
168
|
}
|
|
177
|
-
return new firestore.Firestore(credential);
|
|
178
169
|
}
|
|
179
170
|
exports.createDatabaseClient = createDatabaseClient;
|
|
180
171
|
async function createBucket(credential, bucket, publicRead, service = 'gcp') {
|
|
@@ -185,14 +176,14 @@ async function createBucketV2(credential, bucket, acl, options, service = 'gcp')
|
|
|
185
176
|
if (isFirebaseApp(credential, true, true)) {
|
|
186
177
|
return false;
|
|
187
178
|
}
|
|
188
|
-
const
|
|
189
|
-
if (await hasBucket(
|
|
179
|
+
const storage = createStorageClient.call(this, credential, bucket);
|
|
180
|
+
if (await hasBucket(storage.bucket(bucket))) {
|
|
190
181
|
if (acl) {
|
|
191
182
|
await setBucketPolicy.call(this, credential, bucket, { acl }, service);
|
|
192
183
|
}
|
|
193
184
|
return true;
|
|
194
185
|
}
|
|
195
|
-
return
|
|
186
|
+
return storage.createBucket(bucket, options)
|
|
196
187
|
.then(async ([target]) => {
|
|
197
188
|
this.formatMessage(64, service, ["Bucket created", bucket], '', { ...Cloud.LOG_CLOUD_COMMAND });
|
|
198
189
|
if (acl) {
|
|
@@ -216,7 +207,7 @@ async function setBucketPolicy(credential, bucket, options, service = 'gcp') {
|
|
|
216
207
|
}
|
|
217
208
|
const client = createStorageClient.call(this, credential, bucket).bucket(bucket);
|
|
218
209
|
if (!await hasBucket(client)) {
|
|
219
|
-
this.formatFail(64, service, ["Bucket does not exist", bucket], (0,
|
|
210
|
+
this.formatFail(64, service, ["Bucket does not exist", bucket], (0, util_1.formatError)(service, "Bucket does not exist"), { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
|
|
220
211
|
return false;
|
|
221
212
|
}
|
|
222
213
|
const errors = [];
|
|
@@ -227,7 +218,7 @@ async function setBucketPolicy(credential, bucket, options, service = 'gcp') {
|
|
|
227
218
|
case 'private':
|
|
228
219
|
case 'projectPrivate':
|
|
229
220
|
await client.makePrivate(options).catch(err => !isErrorConflict(err) && errors.push(err));
|
|
230
|
-
await setPredefinedAcl.call(this, client.acl, acl, client, '', (_a = options.bucket) === null || _a === void 0 ? void 0 : _a.metadata)
|
|
221
|
+
await setPredefinedAcl.call(this, client.acl, acl, client, '', (_a = options.bucket) === null || _a === void 0 ? void 0 : _a.metadata);
|
|
231
222
|
break;
|
|
232
223
|
case 'authenticatedRead':
|
|
233
224
|
await client.makePublic(options).catch(err => !isErrorConflict(err) && errors.push(err));
|
|
@@ -254,7 +245,7 @@ async function setBucketPolicy(credential, bucket, options, service = 'gcp') {
|
|
|
254
245
|
}
|
|
255
246
|
}
|
|
256
247
|
if (options.acl && (options.acl = options.acl.filter(user => (0, types_1.isString)(user.entity))).length) {
|
|
257
|
-
errors.push(...await updatePredefinedAcl(client.acl, options.acl, options
|
|
248
|
+
errors.push(...await updatePredefinedAcl(client.acl, options.acl, options));
|
|
258
249
|
}
|
|
259
250
|
if (errors.length) {
|
|
260
251
|
this.formatFail(64, service, ["Unable to update bucket policy", bucket], errors[0], { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
|
|
@@ -269,12 +260,11 @@ function setBucketWebsite(credential, bucket, options, service = 'gcp') {
|
|
|
269
260
|
return Promise.resolve(false);
|
|
270
261
|
}
|
|
271
262
|
const website = {};
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
website.mainPageSuffix = indexPage;
|
|
263
|
+
if ((0, types_1.isString)(options.indexPage)) {
|
|
264
|
+
website.mainPageSuffix = options.indexPage;
|
|
275
265
|
}
|
|
276
|
-
if ((0, types_1.isString)(errorPage)) {
|
|
277
|
-
website.notFoundPage = errorPage;
|
|
266
|
+
if ((0, types_1.isString)(options.errorPage)) {
|
|
267
|
+
website.notFoundPage = options.errorPage;
|
|
278
268
|
}
|
|
279
269
|
return createStorageClient.call(this, credential, bucket).bucket(bucket).setMetadata({ website })
|
|
280
270
|
.then(() => {
|
|
@@ -292,7 +282,7 @@ function deleteObjects(credential, Bucket, service) {
|
|
|
292
282
|
}
|
|
293
283
|
exports.deleteObjects = deleteObjects;
|
|
294
284
|
async function deleteObjectsV2(credential, bucket, recursive = true, service = 'gcp') {
|
|
295
|
-
const
|
|
285
|
+
const storage = createStorageClient.call(this, credential, bucket);
|
|
296
286
|
const errors = [];
|
|
297
287
|
let promise;
|
|
298
288
|
if (isFirebaseApp(credential, true, true)) {
|
|
@@ -300,7 +290,7 @@ async function deleteObjectsV2(credential, bucket, recursive = true, service = '
|
|
|
300
290
|
const files = [];
|
|
301
291
|
await (async function recurse(prefix) {
|
|
302
292
|
try {
|
|
303
|
-
const { items, prefixes } = await listAll(ref(
|
|
293
|
+
const { items, prefixes } = await listAll(ref(storage, prefix));
|
|
304
294
|
if (items.length) {
|
|
305
295
|
files.push(...items.map(value => value.fullPath));
|
|
306
296
|
}
|
|
@@ -315,11 +305,11 @@ async function deleteObjectsV2(credential, bucket, recursive = true, service = '
|
|
|
315
305
|
}
|
|
316
306
|
})('');
|
|
317
307
|
if (files.length) {
|
|
318
|
-
promise = Promise.allSettled(files.map(value => deleteObject(ref(
|
|
308
|
+
promise = Promise.allSettled(files.map(value => deleteObject(ref(storage, value))));
|
|
319
309
|
}
|
|
320
310
|
}
|
|
321
311
|
else {
|
|
322
|
-
const client =
|
|
312
|
+
const client = storage.bucket(bucket);
|
|
323
313
|
if (await hasBucket(client)) {
|
|
324
314
|
if (recursive) {
|
|
325
315
|
return client.deleteFiles({ force: true }).then(() => this.formatMessage(64, service, "Bucket emptied" + ' (recursive)', bucket, { ...Cloud.LOG_CLOUD_COMMAND }));
|
|
@@ -385,7 +375,9 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
385
375
|
};
|
|
386
376
|
const closeClient = () => {
|
|
387
377
|
const fs = clients[3];
|
|
388
|
-
|
|
378
|
+
if (fs) {
|
|
379
|
+
fs.terminate();
|
|
380
|
+
}
|
|
389
381
|
};
|
|
390
382
|
const getFamily = (data, row, family) => {
|
|
391
383
|
const familyData = data[family];
|
|
@@ -528,30 +520,29 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
528
520
|
if ((0, types_1.isArray)(orderBy)) {
|
|
529
521
|
const sort = require('@firebase/database');
|
|
530
522
|
for (const items of orderBy) {
|
|
531
|
-
if (
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
break;
|
|
523
|
+
if ((0, types_1.isArray)(items)) {
|
|
524
|
+
const method = items[0];
|
|
525
|
+
switch (method) {
|
|
526
|
+
case 'orderByChild':
|
|
527
|
+
constraints.push(sort.orderByChild(items[1]));
|
|
528
|
+
break;
|
|
529
|
+
case 'orderByKey':
|
|
530
|
+
case 'orderByValue':
|
|
531
|
+
case 'orderByPriority':
|
|
532
|
+
constraints.push(sort[method]());
|
|
533
|
+
break;
|
|
534
|
+
case 'limitToFirst':
|
|
535
|
+
case 'limitToLast':
|
|
536
|
+
constraints.push(sort[method](limiter = +items[1]));
|
|
537
|
+
break;
|
|
538
|
+
case 'startAt':
|
|
539
|
+
case 'startAfter':
|
|
540
|
+
case 'endAt':
|
|
541
|
+
case 'endBefore':
|
|
542
|
+
case 'equalTo':
|
|
543
|
+
constraints.push(sort[method](items[1], items[2]));
|
|
544
|
+
break;
|
|
545
|
+
}
|
|
555
546
|
}
|
|
556
547
|
}
|
|
557
548
|
}
|
|
@@ -597,22 +588,21 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
597
588
|
else {
|
|
598
589
|
const task = db.createQuery(item.kind);
|
|
599
590
|
for (const args of query) {
|
|
600
|
-
if (
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
break;
|
|
591
|
+
if ((0, types_1.isArray)(args)) {
|
|
592
|
+
const method = args[0];
|
|
593
|
+
switch (method) {
|
|
594
|
+
case 'end':
|
|
595
|
+
case 'filter':
|
|
596
|
+
case 'groupBy':
|
|
597
|
+
case 'hasAncestor':
|
|
598
|
+
case 'limit':
|
|
599
|
+
case 'offset':
|
|
600
|
+
case 'order':
|
|
601
|
+
case 'select':
|
|
602
|
+
case 'start':
|
|
603
|
+
task[method].apply(task, args.slice(1));
|
|
604
|
+
break;
|
|
605
|
+
}
|
|
616
606
|
}
|
|
617
607
|
}
|
|
618
608
|
if (limit > 0) {
|
|
@@ -653,24 +643,23 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
653
643
|
}
|
|
654
644
|
let db = createClient(item, 3).collection(table);
|
|
655
645
|
for (const args of query) {
|
|
656
|
-
if (
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
break;
|
|
646
|
+
if ((0, types_1.isArray)(args)) {
|
|
647
|
+
const method = args[0];
|
|
648
|
+
switch (method) {
|
|
649
|
+
case 'endAt':
|
|
650
|
+
case 'endBefore':
|
|
651
|
+
case 'limit':
|
|
652
|
+
case 'limitToLast':
|
|
653
|
+
case 'offset':
|
|
654
|
+
case 'orderBy':
|
|
655
|
+
case 'select':
|
|
656
|
+
case 'startAfter':
|
|
657
|
+
case 'startAt':
|
|
658
|
+
case 'where':
|
|
659
|
+
case 'withConverter':
|
|
660
|
+
db = db[method].apply(db, args.slice(1));
|
|
661
|
+
break;
|
|
662
|
+
}
|
|
674
663
|
}
|
|
675
664
|
}
|
|
676
665
|
if ((0, types_1.isArray)(orderBy)) {
|
|
@@ -736,19 +725,25 @@ async function setPredefinedAcl(target, value, bucket, pathname = '', metadata =
|
|
|
736
725
|
items = [];
|
|
737
726
|
}
|
|
738
727
|
else {
|
|
739
|
-
|
|
728
|
+
if (bucket) {
|
|
729
|
+
const [users] = await bucket.acl.get().catch(() => [[]]);
|
|
730
|
+
acl = Array.isArray(users) ? users : [users];
|
|
731
|
+
}
|
|
732
|
+
else {
|
|
733
|
+
acl = [];
|
|
734
|
+
}
|
|
740
735
|
items = [{ entity: 'allUsers' }, { entity: 'allAuthenticatedUsers' }];
|
|
741
736
|
}
|
|
742
737
|
switch (value) {
|
|
743
738
|
case 'private': {
|
|
744
|
-
const owners = new Set(acl.filter(item => item.role === 'OWNER'
|
|
739
|
+
const owners = new Set(acl.filter(item => item.role === 'OWNER').map(item => item.entity));
|
|
745
740
|
if (owner) {
|
|
746
741
|
owners.add(owner);
|
|
747
742
|
}
|
|
748
743
|
if (owners.size) {
|
|
749
744
|
for (const user of acl) {
|
|
750
745
|
const entity = user.entity;
|
|
751
|
-
if (
|
|
746
|
+
if (!owners.has(entity)) {
|
|
752
747
|
items.push({ entity });
|
|
753
748
|
}
|
|
754
749
|
}
|
|
@@ -758,18 +753,19 @@ async function setPredefinedAcl(target, value, bucket, pathname = '', metadata =
|
|
|
758
753
|
case 'projectPrivate':
|
|
759
754
|
for (const user of acl) {
|
|
760
755
|
const entity = user.entity;
|
|
761
|
-
if (entity) {
|
|
762
|
-
|
|
763
|
-
|
|
756
|
+
if (entity.startsWith('project-')) {
|
|
757
|
+
items.push({ ...user, role: entity.startsWith('project-editors-') || entity.startsWith('project-owners-') ? 'OWNER' : 'READER' });
|
|
758
|
+
}
|
|
759
|
+
else {
|
|
760
|
+
items.push({ ...user, role: undefined });
|
|
764
761
|
}
|
|
765
762
|
}
|
|
766
763
|
break;
|
|
767
764
|
case 'bucketOwnerRead':
|
|
768
765
|
if (bucket && owner) {
|
|
769
766
|
for (const user of acl) {
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
items.push({ entity, role: 'READER' });
|
|
767
|
+
if (user.entity !== owner) {
|
|
768
|
+
items.push({ entity: user.entity, role: 'READER' });
|
|
773
769
|
}
|
|
774
770
|
}
|
|
775
771
|
}
|
|
@@ -798,12 +794,10 @@ function createBucketRequest(credential) {
|
|
|
798
794
|
for (const attr in credential) {
|
|
799
795
|
switch (attr) {
|
|
800
796
|
case 'archive':
|
|
801
|
-
case 'autoclass':
|
|
802
797
|
case 'coldline':
|
|
803
798
|
case 'cors':
|
|
804
799
|
case 'customPlacementConfig':
|
|
805
800
|
case 'dra':
|
|
806
|
-
case 'enableObjectRetention':
|
|
807
801
|
case 'location':
|
|
808
802
|
case 'multiRegional':
|
|
809
803
|
case 'nearline':
|
|
@@ -837,4 +831,3 @@ function getProjectId(credential) {
|
|
|
837
831
|
return '';
|
|
838
832
|
}
|
|
839
833
|
exports.getProjectId = getProjectId;
|
|
840
|
-
exports.CLOUD_UPLOAD_FROMDISK = true;
|
package/download/index.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
const path = require("path");
|
|
3
3
|
const fs = require("fs");
|
|
4
4
|
const https = require("https");
|
|
5
|
+
const client_1 = require("@pi-r/gcp");
|
|
5
6
|
const types_1 = require("@e-mc/types");
|
|
6
7
|
const Module = require("@e-mc/module");
|
|
7
8
|
const Cloud = require("@e-mc/cloud");
|
|
8
|
-
const client_1 = require("@pi-r/gcp");
|
|
9
9
|
function download(credential, service = 'gcp') {
|
|
10
10
|
const storage = client_1.createStorageClient.call(this, credential);
|
|
11
11
|
return (data, callback) => {
|
package/package.json
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@pi-r/gcp",
|
|
3
|
-
"version": "0.3.
|
|
4
|
-
"description": "Google (GCP) cloud functions for E-mc.",
|
|
5
|
-
"main": "client/index.js",
|
|
6
|
-
"publishConfig": {
|
|
7
|
-
"access": "public"
|
|
8
|
-
},
|
|
9
|
-
"repository": {
|
|
10
|
-
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/anpham6/pi-r.git",
|
|
12
|
-
"directory": "src/cloud/gcp"
|
|
13
|
-
},
|
|
14
|
-
"keywords": [
|
|
15
|
-
"squared",
|
|
16
|
-
"e-mc",
|
|
17
|
-
"squared-functions"
|
|
18
|
-
],
|
|
19
|
-
"author": "An Pham <anpham6@gmail.com>",
|
|
20
|
-
"license": "MIT",
|
|
21
|
-
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
22
|
-
"dependencies": {
|
|
23
|
-
"@e-mc/cloud": "^0.6.
|
|
24
|
-
"@e-mc/module": "^0.6.
|
|
25
|
-
"@e-mc/types": "^0.6.
|
|
26
|
-
"@google-cloud/firestore": "^6.8.0",
|
|
27
|
-
"@google-cloud/storage": "^7.
|
|
28
|
-
}
|
|
29
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@pi-r/gcp",
|
|
3
|
+
"version": "0.3.6",
|
|
4
|
+
"description": "Google (GCP) cloud functions for E-mc.",
|
|
5
|
+
"main": "client/index.js",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/anpham6/pi-r.git",
|
|
12
|
+
"directory": "src/cloud/gcp"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"squared",
|
|
16
|
+
"e-mc",
|
|
17
|
+
"squared-functions"
|
|
18
|
+
],
|
|
19
|
+
"author": "An Pham <anpham6@gmail.com>",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@e-mc/cloud": "^0.6.16",
|
|
24
|
+
"@e-mc/module": "^0.6.16",
|
|
25
|
+
"@e-mc/types": "^0.6.16",
|
|
26
|
+
"@google-cloud/firestore": "^6.8.0",
|
|
27
|
+
"@google-cloud/storage": "^7.12.0"
|
|
28
|
+
}
|
|
29
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { CloudDatabase, CloudStorage } from '@e-mc/types/lib/cloud';
|
|
2
|
+
|
|
3
|
+
import type { StorageOptions } from '@google-cloud/storage';
|
|
4
|
+
import type { PathType } from '@google-cloud/datastore';
|
|
5
|
+
import type { AggregateSpec } from '@google-cloud/firestore';
|
|
6
|
+
import type { entity } from '@google-cloud/datastore/build/src/entity';
|
|
7
|
+
import type { FirebaseOptions as IFirebaseOptions } from '@firebase/app';
|
|
8
|
+
import type { ServiceAccount } from 'firebase-admin/app';
|
|
9
|
+
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
import type { GoogleAuthOptions } from 'google-auth-library';
|
|
12
|
+
|
|
13
|
+
export type GCPStorage = CloudStorage<GCPStorageCredential, "gcp | gcloud">;
|
|
14
|
+
|
|
15
|
+
export interface GCPStorageCredential extends StorageOptions, IFirebaseOptions {}
|
|
16
|
+
|
|
17
|
+
export interface GCPDatabaseQuery<T = PlainObject> extends Omit<CloudDatabase<unknown, T, unknown, string | unknown[] | StandardMap, GCPDatabaseCredential>, "id"> {
|
|
18
|
+
source: "cloud";
|
|
19
|
+
service: "gcp" | "gcloud";
|
|
20
|
+
product?: "firestore" | "firebase" | "bigquery" | "bigtable" | "datastore" | "spanner";
|
|
21
|
+
database?: string;
|
|
22
|
+
id?: string | string[] | number;
|
|
23
|
+
updateType?: 0 | 1 | 2 | 3;
|
|
24
|
+
columns?: string[];
|
|
25
|
+
keys?: DatastoreKey | DatastoreKey[];
|
|
26
|
+
kind?: string | string[];
|
|
27
|
+
orderBy?: unknown[][];
|
|
28
|
+
aggregateSpec?: AggregateSpec;
|
|
29
|
+
flags?: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type GCPDatabaseCredential = GoogleAuthOptions;
|
|
33
|
+
|
|
34
|
+
export interface FirebaseOptions extends IFirebaseOptions {
|
|
35
|
+
product?: "firebase";
|
|
36
|
+
admin?: boolean | string | ServiceAccount;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type DatastoreKey = string | PathType[] | entity.KeyOptions;
|
|
40
|
+
export type BucketAcl = "authenticatedRead" | "private" | "projectPrivate" | "publicRead" | "publicReadWrite" | "bucketAccessUniform" | "bucketAccessACL";
|
package/upload/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const path = require("path");
|
|
3
3
|
const fs = require("fs");
|
|
4
|
+
const client_1 = require("@pi-r/gcp");
|
|
4
5
|
const util_1 = require("@e-mc/cloud/util");
|
|
5
6
|
const types_1 = require("@e-mc/types");
|
|
6
7
|
const Module = require("@e-mc/module");
|
|
7
8
|
const Cloud = require("@e-mc/cloud");
|
|
8
|
-
const client_1 = require("@pi-r/gcp");
|
|
9
9
|
const BUCKET_SESSION = new Set();
|
|
10
10
|
const BUCKET_RESPONSE = {};
|
|
11
11
|
const getBucketKey = (credential, bucket, acl = '') => Module.asString(credential, true) + bucket + '_' + acl;
|