@pi-r/aws 0.6.0 → 0.6.2
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/README.md +2 -0
- package/client/index.d.ts +4 -1
- package/client/index.js +111 -29
- package/package.json +5 -5
- package/types/index.d.ts +2 -2
- package/upload/index.js +43 -46
package/README.md
CHANGED
package/client/index.d.ts
CHANGED
|
@@ -6,13 +6,15 @@ import type { AWSDatabaseCredential, AWSDatabaseQuery, AWSStorageCredential, Buc
|
|
|
6
6
|
|
|
7
7
|
import type { ConfigurationOptions } from 'aws-sdk/lib/core';
|
|
8
8
|
import type { ServiceConfigurationOptions } from 'aws-sdk/lib/service';
|
|
9
|
-
import type { DocumentClient } from 'aws-sdk/clients/dynamodb';
|
|
9
|
+
import type { AttributeValue, DocumentClient } from 'aws-sdk/clients/dynamodb';
|
|
10
10
|
import type { DynamoDBClientConfig } from '@aws-sdk/client-dynamodb';
|
|
11
11
|
import type { CreateBucketRequest } from 'aws-sdk/clients/s3';
|
|
12
12
|
|
|
13
13
|
declare namespace AWS {
|
|
14
14
|
function isAccessDefined(credential: Pick<ConfigurationOptions, "accessKeyId" | "secretAccessKey" | "sessionToken">): boolean;
|
|
15
15
|
function isEnvDefined(): boolean;
|
|
16
|
+
function isSharedCredentialsDefined(): boolean;
|
|
17
|
+
function isProviderChainDefined(): boolean;
|
|
16
18
|
function isDatabaseDefined(credential: AWSDatabaseCredential, data: CloudDatabase): boolean;
|
|
17
19
|
function getPublicReadPolicy(bucket: string, authenticated?: boolean, write?: boolean): string;
|
|
18
20
|
function getBucketPublicReadPolicy(bucket: string): string;
|
|
@@ -32,6 +34,7 @@ declare namespace AWS {
|
|
|
32
34
|
function setDatabaseEndpoint(config: ServiceConfigurationOptions | DynamoDBClientConfig): void;
|
|
33
35
|
function checkBucketCannedACL(value: unknown): BucketCannedACL | undefined;
|
|
34
36
|
function writeMessageDefaultRetention(this: IModule, bucket: string, retention: s3.DefaultRetention, service?: string): void;
|
|
37
|
+
function parseAttributeValue(value: unknown): AttributeValue;
|
|
35
38
|
function getBucketKey(credential: unknown, Bucket: string, acl: string | undefined, service: string, sdk: string): string;
|
|
36
39
|
function isNoSuchBucket(err: unknown): boolean;
|
|
37
40
|
}
|
package/client/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isNoSuchBucket = exports.getBucketKey = exports.writeMessageDefaultRetention = exports.checkBucketCannedACL = exports.setDatabaseEndpoint = 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.getPrivatePolicy = exports.getBucketPublicReadPolicy = exports.getPublicReadPolicy = exports.isDatabaseDefined = exports.isEnvDefined = exports.isAccessDefined = void 0;
|
|
3
|
+
exports.isNoSuchBucket = exports.getBucketKey = exports.parseAttributeValue = exports.writeMessageDefaultRetention = exports.checkBucketCannedACL = exports.setDatabaseEndpoint = 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.getPrivatePolicy = exports.getBucketPublicReadPolicy = exports.getPublicReadPolicy = exports.isDatabaseDefined = exports.isProviderChainDefined = exports.isEnvDefined = exports.isSharedCredentialsDefined = exports.isAccessDefined = void 0;
|
|
4
4
|
const aws = require("aws-sdk");
|
|
5
5
|
const types_1 = require("@e-mc/types");
|
|
6
6
|
const util_1 = require("@e-mc/cloud/util");
|
|
@@ -62,12 +62,20 @@ function isAccessDefined(credential) {
|
|
|
62
62
|
return !!(credential.accessKeyId && credential.secretAccessKey || credential.sessionToken);
|
|
63
63
|
}
|
|
64
64
|
exports.isAccessDefined = isAccessDefined;
|
|
65
|
+
function isSharedCredentialsDefined() {
|
|
66
|
+
return !!process.env.AWS_SDK_LOAD_CONFIG;
|
|
67
|
+
}
|
|
68
|
+
exports.isSharedCredentialsDefined = isSharedCredentialsDefined;
|
|
65
69
|
function isEnvDefined() {
|
|
66
|
-
return !!(process.env.AWS_ACCESS_KEY_ID && process.env.AWS_SECRET_ACCESS_KEY
|
|
70
|
+
return !!(process.env.AWS_ACCESS_KEY_ID && process.env.AWS_SECRET_ACCESS_KEY);
|
|
67
71
|
}
|
|
68
72
|
exports.isEnvDefined = isEnvDefined;
|
|
73
|
+
function isProviderChainDefined() {
|
|
74
|
+
return isSharedCredentialsDefined() || !!(process.env.AWS_WEB_IDENTITY_TOKEN_FILE || process.env.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI || process.env.AWS_CONTAINER_CREDENTIALS_FULL_URI);
|
|
75
|
+
}
|
|
76
|
+
exports.isProviderChainDefined = isProviderChainDefined;
|
|
69
77
|
function isDatabaseDefined(credential, data) {
|
|
70
|
-
return !!(data.table && (credential.region || credential.endpoint || process.env.AWS_DEFAULT_REGION));
|
|
78
|
+
return !!(data.table && (credential.region || credential.endpoint || process.env.AWS_DEFAULT_REGION || process.env.AWS_REGION));
|
|
71
79
|
}
|
|
72
80
|
exports.isDatabaseDefined = isDatabaseDefined;
|
|
73
81
|
function getPublicReadPolicy(bucket, authenticated, write) {
|
|
@@ -114,7 +122,7 @@ function getPrivatePolicy(bucket) {
|
|
|
114
122
|
}
|
|
115
123
|
exports.getPrivatePolicy = getPrivatePolicy;
|
|
116
124
|
function validateStorage(credential) {
|
|
117
|
-
return !!(isAccessDefined(credential) || isEnvDefined() || credential.fromPath || credential.profile ||
|
|
125
|
+
return !!(isAccessDefined(credential) || isEnvDefined() || credential.fromPath || credential.profile || isProviderChainDefined());
|
|
118
126
|
}
|
|
119
127
|
exports.validateStorage = validateStorage;
|
|
120
128
|
function validateDatabase(credential, data) {
|
|
@@ -130,7 +138,7 @@ function createStorageClient(credential, service = 'aws', sdk = 'aws-sdk/clients
|
|
|
130
138
|
client.config.loadFromPath(fromPath);
|
|
131
139
|
return client;
|
|
132
140
|
}
|
|
133
|
-
if (profile ||
|
|
141
|
+
if (profile || isSharedCredentialsDefined() && !isAccessDefined(credential) && !isEnvDefined()) {
|
|
134
142
|
credential = new aws.SharedIniFileCredentials({ profile });
|
|
135
143
|
}
|
|
136
144
|
return new aws.S3(credential);
|
|
@@ -149,7 +157,7 @@ function createDatabaseClient(credential) {
|
|
|
149
157
|
if (fromPath) {
|
|
150
158
|
aws.config.loadFromPath(fromPath);
|
|
151
159
|
}
|
|
152
|
-
else if (profile ||
|
|
160
|
+
else if (profile || isSharedCredentialsDefined() && !isAccessDefined(credential) && !isEnvDefined()) {
|
|
153
161
|
options = new aws.SharedIniFileCredentials({ profile });
|
|
154
162
|
}
|
|
155
163
|
else {
|
|
@@ -284,39 +292,39 @@ async function executeQuery(credential, data, sessionKey) {
|
|
|
284
292
|
}
|
|
285
293
|
exports.executeQuery = executeQuery;
|
|
286
294
|
async function executeBatchQuery(credential, batch, sessionKey) {
|
|
295
|
+
var _a;
|
|
287
296
|
const length = batch.length;
|
|
288
297
|
const result = new Array(length);
|
|
289
298
|
const caching = length > 0 && this.hasCache(batch[0].service, sessionKey);
|
|
290
299
|
const cacheValue = { value: this.valueOfKey(credential, 'cache'), sessionKey };
|
|
291
300
|
let client;
|
|
292
|
-
const createClient = () =>
|
|
293
|
-
|
|
294
|
-
return client || (client = createDatabaseClient.call(this, length === 1 ? credential : { ...credential }));
|
|
295
|
-
};
|
|
301
|
+
const createClient = () => client || (client = createDatabaseClient.call(this, credential));
|
|
302
|
+
setDatabaseEndpoint(credential);
|
|
296
303
|
for (let i = 0; i < length; ++i) {
|
|
297
304
|
const item = batch[i];
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
throw (0, util_1.formatError)(item, "Missing database table" /* ERR_DB.TABLE */);
|
|
301
|
-
}
|
|
302
|
-
const renewCache = ignoreCache === 0;
|
|
305
|
+
let { service, table: TableName, id, query, partitionKey, key = partitionKey, limit = 0, update, ignoreCache } = item;
|
|
306
|
+
const useCache = caching && ignoreCache !== true;
|
|
303
307
|
const getCache = (value) => {
|
|
304
308
|
if (ignoreCache !== 1) {
|
|
305
|
-
cacheValue.renewCache =
|
|
309
|
+
cacheValue.renewCache = ignoreCache === 0;
|
|
306
310
|
return this.getQueryResult(service, credential, value, cacheValue);
|
|
307
311
|
}
|
|
308
312
|
};
|
|
309
|
-
|
|
313
|
+
cacheValue.exclusiveOf = Array.isArray(ignoreCache) ? ignoreCache : undefined;
|
|
314
|
+
let rows, queryString = '';
|
|
310
315
|
if (key && (id || (0, types_1.isPlainObject)(key))) {
|
|
311
|
-
if (
|
|
312
|
-
|
|
316
|
+
if (!TableName) {
|
|
317
|
+
throw (0, util_1.formatError)(item, "Missing database table" /* ERR_DB.TABLE */);
|
|
318
|
+
}
|
|
319
|
+
if (useCache) {
|
|
320
|
+
queryString = TableName + '_' + Module.asString(key, true) + (id !== undefined ? '_' + Module.asString(id, true) : '');
|
|
313
321
|
if (!update && (rows = getCache(queryString))) {
|
|
314
322
|
result[i] = rows;
|
|
315
323
|
continue;
|
|
316
324
|
}
|
|
317
325
|
}
|
|
318
|
-
const Key = (0, types_1.isPlainObject)(key) ? key : { [key]: id };
|
|
319
|
-
const command = { TableName
|
|
326
|
+
const Key = (0, types_1.isPlainObject)(key) ? key : { [key]: parseAttributeValue(id) };
|
|
327
|
+
const command = { TableName, Key };
|
|
320
328
|
client = createClient();
|
|
321
329
|
if (update) {
|
|
322
330
|
await client.update({ ...command, ...update }).promise();
|
|
@@ -327,19 +335,63 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
327
335
|
}
|
|
328
336
|
}
|
|
329
337
|
else if ((0, types_1.isPlainObject)(query)) {
|
|
330
|
-
if (
|
|
331
|
-
|
|
332
|
-
|
|
338
|
+
if (TableName) {
|
|
339
|
+
query.TableName = TableName;
|
|
340
|
+
}
|
|
341
|
+
if (!TableName) {
|
|
342
|
+
throw (0, util_1.formatError)(item, "Missing database table" /* ERR_DB.TABLE */);
|
|
333
343
|
}
|
|
334
|
-
query.TableName = table;
|
|
335
344
|
if (limit > 0) {
|
|
336
345
|
query.Limit = limit;
|
|
337
346
|
}
|
|
347
|
+
if (useCache && (rows = getCache(queryString = Module.asString(query, true)))) {
|
|
348
|
+
result[i] = rows;
|
|
349
|
+
continue;
|
|
350
|
+
}
|
|
338
351
|
const { Count, Items } = await createClient().query(query).promise();
|
|
339
352
|
if (Count && Items) {
|
|
340
353
|
rows = Items;
|
|
341
354
|
}
|
|
342
355
|
}
|
|
356
|
+
else if ((0, types_1.isArray)(query)) {
|
|
357
|
+
let params = (item.params || {});
|
|
358
|
+
if (!(0, types_1.isPlainObject)(params.RequestItems)) {
|
|
359
|
+
params.RequestItems = {};
|
|
360
|
+
}
|
|
361
|
+
TableName || (TableName = Object.keys(params.RequestItems)[0]);
|
|
362
|
+
if (!TableName) {
|
|
363
|
+
throw (0, util_1.formatError)(item, "Missing database table" /* ERR_DB.TABLE */);
|
|
364
|
+
}
|
|
365
|
+
// @ts-ignore
|
|
366
|
+
const Item = (_a = params.RequestItems)[TableName] || (_a[TableName] = {});
|
|
367
|
+
Item.Keys = query;
|
|
368
|
+
params = { RequestItems: { [TableName]: Item } };
|
|
369
|
+
if (useCache && (rows = getCache(queryString = Module.asString(params, true)))) {
|
|
370
|
+
result[i] = rows;
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
const { Responses } = await createClient().batchGet(params).promise();
|
|
374
|
+
if (Responses) {
|
|
375
|
+
rows = Responses[TableName];
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
else if (TableName) {
|
|
379
|
+
let params = item.params;
|
|
380
|
+
if ((0, types_1.isPlainObject)(params)) {
|
|
381
|
+
params.TableName = TableName;
|
|
382
|
+
}
|
|
383
|
+
else {
|
|
384
|
+
params = { TableName };
|
|
385
|
+
}
|
|
386
|
+
if (useCache && (rows = getCache(queryString = Module.asString(params, true)))) {
|
|
387
|
+
result[i] = rows;
|
|
388
|
+
continue;
|
|
389
|
+
}
|
|
390
|
+
const { Count, Items } = await createClient().scan(params).promise();
|
|
391
|
+
if (Count && Items) {
|
|
392
|
+
rows = Items;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
343
395
|
else {
|
|
344
396
|
throw (0, util_1.formatError)(item, "Missing database query" /* ERR_DB.QUERY */);
|
|
345
397
|
}
|
|
@@ -350,9 +402,9 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
350
402
|
exports.executeBatchQuery = executeBatchQuery;
|
|
351
403
|
function setDatabaseEndpoint(config) {
|
|
352
404
|
let region = config.region;
|
|
353
|
-
config.endpoint || (config.endpoint = `https://dynamodb.${(0, types_1.isString)(region) ? region : process.env.AWS_DEFAULT_REGION || 'us-east-1'}.amazonaws.com`);
|
|
354
|
-
if (!region
|
|
355
|
-
region = (
|
|
405
|
+
const endpoint = config.endpoint || (config.endpoint = `https://dynamodb.${(0, types_1.isString)(region) ? region : process.env.AWS_DEFAULT_REGION || process.env.AWS_REGION || 'us-east-1'}.amazonaws.com`);
|
|
406
|
+
if (!region) {
|
|
407
|
+
region = ((0, types_1.isString)(endpoint) && /\bdynamodb\.([^.]+)\./i.exec(endpoint)?.[1] || process.env.AWS_DEFAULT_REGION || process.env.AWS_REGION)?.toLowerCase();
|
|
356
408
|
if (region && region !== 'us-east-1') {
|
|
357
409
|
config.region = region;
|
|
358
410
|
}
|
|
@@ -381,9 +433,39 @@ function writeMessageDefaultRetention(bucket, retention, service = 'aws') {
|
|
|
381
433
|
if (Mode) {
|
|
382
434
|
status.push(status.length ? `(${Mode})` : Mode);
|
|
383
435
|
}
|
|
384
|
-
this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Bucket configured" /* VAL_CLOUD.CONFIGURE_BUCKET */ + ' (
|
|
436
|
+
this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Bucket configured" /* VAL_CLOUD.CONFIGURE_BUCKET */ + ' (Retention Policy)', bucket], status.join(' '), { ...Cloud.LOG_CLOUD_COMMAND });
|
|
385
437
|
}
|
|
386
438
|
exports.writeMessageDefaultRetention = writeMessageDefaultRetention;
|
|
439
|
+
function parseAttributeValue(value) {
|
|
440
|
+
switch (typeof value) {
|
|
441
|
+
case 'string':
|
|
442
|
+
return { S: value };
|
|
443
|
+
case 'number':
|
|
444
|
+
return { N: value.toString() };
|
|
445
|
+
case 'boolean':
|
|
446
|
+
return { BOOL: value };
|
|
447
|
+
case 'object':
|
|
448
|
+
if (value !== null) {
|
|
449
|
+
if ('S' in value || 'N' in value || 'BOOL' in value || 'B' in value || 'SS' in value || 'NS' in value || 'BS' in value || 'L' in value || 'M' in value || 'NULL' in value) {
|
|
450
|
+
return value;
|
|
451
|
+
}
|
|
452
|
+
if (Buffer.isBuffer(value)) {
|
|
453
|
+
return { B: value.toString('base64') };
|
|
454
|
+
}
|
|
455
|
+
if (Array.isArray(value)) {
|
|
456
|
+
return value.every(item => typeof item === 'string') ? { SS: value } : value.every(item => typeof item === 'number') ? { NS: value.map((item) => item.toString()) } : value.every(item => Buffer.isBuffer(item)) ? { BS: value.map((item) => item.toString('base64')) } : { L: value.map(item => parseAttributeValue(item)) };
|
|
457
|
+
}
|
|
458
|
+
const M = {};
|
|
459
|
+
for (const attr in value) {
|
|
460
|
+
M[attr] = parseAttributeValue(value[attr]);
|
|
461
|
+
}
|
|
462
|
+
return { M };
|
|
463
|
+
}
|
|
464
|
+
break;
|
|
465
|
+
}
|
|
466
|
+
return { NULL: true };
|
|
467
|
+
}
|
|
468
|
+
exports.parseAttributeValue = parseAttributeValue;
|
|
387
469
|
const getBucketKey = (credential, Bucket, acl, service, sdk) => Module.asString(credential, true) + Bucket + '_' + (acl || '') + service + sdk;
|
|
388
470
|
exports.getBucketKey = getBucketKey;
|
|
389
471
|
const isNoSuchBucket = (err) => err instanceof Error && err.code === 'NoSuchBucket';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/aws",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "AWS V2 cloud functions for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"types": "client/index.d.ts",
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@e-mc/cloud": "^0.8.
|
|
25
|
-
"@e-mc/module": "^0.8.
|
|
26
|
-
"@e-mc/types": "^0.8.
|
|
27
|
-
"aws-sdk": "^2.
|
|
24
|
+
"@e-mc/cloud": "^0.8.2",
|
|
25
|
+
"@e-mc/module": "^0.8.2",
|
|
26
|
+
"@e-mc/types": "^0.8.2",
|
|
27
|
+
"aws-sdk": "^2.1545.0"
|
|
28
28
|
}
|
|
29
29
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { CloudDatabase } from '@e-mc/types/lib/cloud';
|
|
|
3
3
|
|
|
4
4
|
import type { ConfigurationOptions } from 'aws-sdk/lib/core';
|
|
5
5
|
import type { ServiceConfigurationOptions } from 'aws-sdk/lib/service';
|
|
6
|
-
import type { Key, QueryInput, UpdateItemInput } from 'aws-sdk/clients/dynamodb';
|
|
6
|
+
import type { BatchGetItemInput, Key, QueryInput, ScanInput, UpdateItemInput } from 'aws-sdk/clients/dynamodb';
|
|
7
7
|
import type { PutBucketAclRequest, PutBucketPolicyRequest, PutPublicAccessBlockRequest } from 'aws-sdk/clients/s3';
|
|
8
8
|
|
|
9
9
|
export type BucketCannedACL = "authenticated-read" | "private" | "public-read" | "public-read-write";
|
|
@@ -15,7 +15,7 @@ export interface AWSStorageCredential extends ConfigurationOptions {
|
|
|
15
15
|
fromPath?: string;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
export interface AWSDatabaseQuery extends CloudDatabase<QueryInput, PlainObject, UpdateItemInput> {
|
|
18
|
+
export interface AWSDatabaseQuery extends CloudDatabase<QueryInput | Key[], PlainObject, UpdateItemInput, BatchGetItemInput | ScanInput> {
|
|
19
19
|
key?: string | Key;
|
|
20
20
|
partitionKey?: string | Key;
|
|
21
21
|
}
|
package/upload/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const path = require("path");
|
|
4
|
-
const fs = require("fs");
|
|
5
4
|
const util_1 = require("@e-mc/cloud/util");
|
|
6
5
|
const types_1 = require("@e-mc/types");
|
|
7
6
|
const Module = require("@e-mc/module");
|
|
@@ -37,7 +36,7 @@ function upload(credential, service = 'aws', sdk = 'aws-sdk/clients/s3') {
|
|
|
37
36
|
}
|
|
38
37
|
BUCKET_SESSION.add(service + Bucket);
|
|
39
38
|
}
|
|
40
|
-
if (service !== 'oci') {
|
|
39
|
+
if (service !== 'ibm' && service !== 'oci') {
|
|
41
40
|
const DefaultRetention = configBucket?.retentionPolicy;
|
|
42
41
|
if ((0, types_1.isPlainObject)(DefaultRetention)) {
|
|
43
42
|
s3.putObjectLockConfiguration({ Bucket, ObjectLockConfiguration: { ObjectLockEnabled: 'Enabled', Rule: { DefaultRetention } }, ExpectedBucketOwner: options?.ExpectedBucketOwner, RequestPayer: options?.RequestPayer }, err => {
|
|
@@ -81,15 +80,10 @@ function upload(credential, service = 'aws', sdk = 'aws-sdk/clients/s3') {
|
|
|
81
80
|
const Body = [data.buffer];
|
|
82
81
|
const ContentType = [contentType];
|
|
83
82
|
if (fileGroup) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
catch (err) {
|
|
90
|
-
addLog(err);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
83
|
+
const [key, body, type] = (0, util_1.createKeyAndBody)(filename, fileGroup, addLog);
|
|
84
|
+
Key.push(...key);
|
|
85
|
+
Body.push(...body);
|
|
86
|
+
ContentType.push(...type);
|
|
93
87
|
}
|
|
94
88
|
for (let i = 0; i < Key.length; ++i) {
|
|
95
89
|
const first = i === 0;
|
|
@@ -125,46 +119,49 @@ function upload(credential, service = 'aws', sdk = 'aws-sdk/clients/s3') {
|
|
|
125
119
|
}
|
|
126
120
|
}
|
|
127
121
|
s3.upload(params, (err, result) => {
|
|
128
|
-
if (
|
|
129
|
-
const url = endpoint ? Module.joinPath(endpoint, result.Key) : result.Location;
|
|
130
|
-
this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, "Upload success" /* VAL_CLOUD.UPLOAD_FILE */, url, { ...Cloud.LOG_CLOUD_UPLOAD });
|
|
122
|
+
if (err) {
|
|
131
123
|
if (first) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
TagSet.push({ Key: name, Value: tags[name] });
|
|
137
|
-
}
|
|
138
|
-
s3.putObjectTagging({ Bucket, Key: result.Key, Tagging: { TagSet }, ExpectedBucketOwner: params.ExpectedBucketOwner, RequestPayer: params.RequestPayer }, error => {
|
|
139
|
-
if (!error) {
|
|
140
|
-
this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Tags created" /* VAL_CLOUD.CREATE_TAG */, Bucket], result.Key, { ...Cloud.LOG_CLOUD_COMMAND });
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
addLog(error);
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
else if (tags === false) {
|
|
148
|
-
s3.deleteObjectTagging({ Bucket, Key: result.Key, ExpectedBucketOwner: params.ExpectedBucketOwner }, error => {
|
|
149
|
-
if (!error) {
|
|
150
|
-
this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Tags deleted" /* VAL_CLOUD.DELETE_TAG */, Bucket], result.Key, { ...Cloud.LOG_CLOUD_COMMAND });
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
addLog(error);
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
cleanup();
|
|
159
|
-
callback(null, url);
|
|
124
|
+
errorResponse(err);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
addLog(err);
|
|
160
128
|
}
|
|
129
|
+
return;
|
|
161
130
|
}
|
|
162
|
-
|
|
163
|
-
|
|
131
|
+
const url = endpoint ? Module.joinPath(endpoint, result.Key) : result.Location;
|
|
132
|
+
this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, "Upload success" /* VAL_CLOUD.UPLOAD_FILE */, url, { ...Cloud.LOG_CLOUD_UPLOAD });
|
|
133
|
+
if (!first) {
|
|
134
|
+
return;
|
|
164
135
|
}
|
|
165
|
-
|
|
166
|
-
|
|
136
|
+
if (service !== 'oci') {
|
|
137
|
+
let length = -1;
|
|
138
|
+
if ((0, types_1.isPlainObject)(tags) && (length = Object.keys(tags).length) > 0) {
|
|
139
|
+
const TagSet = [];
|
|
140
|
+
for (const name in tags) {
|
|
141
|
+
TagSet.push({ Key: name, Value: tags[name] });
|
|
142
|
+
}
|
|
143
|
+
s3.putObjectTagging({ Bucket, Key: result.Key, Tagging: { TagSet }, ExpectedBucketOwner: params.ExpectedBucketOwner, RequestPayer: params.RequestPayer }, error => {
|
|
144
|
+
if (!error) {
|
|
145
|
+
this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Tags created" /* VAL_CLOUD.CREATE_TAG */, Bucket], result.Key, { ...Cloud.LOG_CLOUD_COMMAND });
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
addLog(error);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
else if (tags === false || length === 0) {
|
|
153
|
+
s3.deleteObjectTagging({ Bucket, Key: result.Key, ExpectedBucketOwner: params.ExpectedBucketOwner }, error => {
|
|
154
|
+
if (!error) {
|
|
155
|
+
this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Tags deleted" /* VAL_CLOUD.DELETE_TAG */, Bucket], result.Key, { ...Cloud.LOG_CLOUD_COMMAND });
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
addLog(error);
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
167
162
|
}
|
|
163
|
+
cleanup();
|
|
164
|
+
callback(null, url);
|
|
168
165
|
});
|
|
169
166
|
}
|
|
170
167
|
};
|