@pi-r/aws 0.6.3 → 0.6.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 +1 -1
- package/README.md +6 -3
- package/client/index.js +18 -20
- package/download/index.js +5 -8
- package/package.json +5 -5
- package/upload/index.js +7 -10
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright
|
|
1
|
+
Copyright 2024 An Pham
|
|
2
2
|
|
|
3
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
4
|
|
package/README.md
CHANGED
package/client/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
2
|
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
3
|
const aws = require("aws-sdk");
|
|
5
4
|
const types_1 = require("@e-mc/types");
|
|
@@ -18,15 +17,15 @@ async function setCannedAcl(S3, Bucket, ACL, service = 'aws', recursive) {
|
|
|
18
17
|
}
|
|
19
18
|
const callback = (err) => {
|
|
20
19
|
if (!err) {
|
|
21
|
-
this.formatMessage(64
|
|
20
|
+
this.formatMessage(64, service, ['Grant ' + ACL, Bucket], '', { ...recursive ? Cloud.LOG_CLOUD_DELAYED : Cloud.LOG_CLOUD_COMMAND });
|
|
22
21
|
}
|
|
23
22
|
else if (!recursive) {
|
|
24
23
|
if (err instanceof Error && err.code === 'OperationAborted') {
|
|
25
|
-
setTimeout(async () => setCannedAcl.call(this, S3, Bucket, ACL, service, true), 60000
|
|
26
|
-
this.formatMessage(64
|
|
24
|
+
setTimeout(async () => setCannedAcl.call(this, S3, Bucket, ACL, service, true), 60000);
|
|
25
|
+
this.formatMessage(64, service, [`Grant ${ACL} (delayed)`, Bucket], err, { ...Cloud.LOG_CLOUD_DELAYED });
|
|
27
26
|
}
|
|
28
27
|
else {
|
|
29
|
-
this.formatMessage(64
|
|
28
|
+
this.formatMessage(64, service, ['Unable to grant ' + ACL, Bucket], err, { ...Cloud.LOG_CLOUD_WARN });
|
|
30
29
|
}
|
|
31
30
|
}
|
|
32
31
|
};
|
|
@@ -188,7 +187,7 @@ async function createBucketV2(credential, Bucket, ACL, options, service = 'aws',
|
|
|
188
187
|
}
|
|
189
188
|
return S3.createBucket(input).promise()
|
|
190
189
|
.then(async () => {
|
|
191
|
-
this.formatMessage(64
|
|
190
|
+
this.formatMessage(64, service, ["Bucket created", Bucket], '', { ...Cloud.LOG_CLOUD_COMMAND });
|
|
192
191
|
if (ACL) {
|
|
193
192
|
await setCannedAcl.call(this, S3, Bucket, ACL, service);
|
|
194
193
|
}
|
|
@@ -203,7 +202,7 @@ async function createBucketV2(credential, Bucket, ACL, options, service = 'aws',
|
|
|
203
202
|
}
|
|
204
203
|
return true;
|
|
205
204
|
default:
|
|
206
|
-
this.formatFail(64
|
|
205
|
+
this.formatFail(64, service, ["Unable to create bucket", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL });
|
|
207
206
|
return false;
|
|
208
207
|
}
|
|
209
208
|
});
|
|
@@ -220,12 +219,12 @@ async function setBucketPolicy(credential, Bucket, options, service = 'aws', sdk
|
|
|
220
219
|
}
|
|
221
220
|
return ('PublicAccessBlockConfiguration' in options ? S3.putPublicAccessBlock(options) : 'Policy' in options && (0, types_1.isString)(options.Policy) && !ibm ? S3.putBucketPolicy(options) : S3.putBucketAcl(options)).promise()
|
|
222
221
|
.then(() => {
|
|
223
|
-
this.formatMessage(64
|
|
222
|
+
this.formatMessage(64, service, ["Bucket policy configured", Bucket], '', { ...Cloud.LOG_CLOUD_COMMAND });
|
|
224
223
|
return true;
|
|
225
224
|
})
|
|
226
225
|
.catch(err => {
|
|
227
226
|
if (!(0, exports.isNoSuchBucket)(err)) {
|
|
228
|
-
this.formatFail(64
|
|
227
|
+
this.formatFail(64, service, ["Unable to update bucket policy", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
|
|
229
228
|
}
|
|
230
229
|
return false;
|
|
231
230
|
});
|
|
@@ -243,12 +242,12 @@ async function setBucketWebsite(credential, Bucket, options, service = 'aws', sd
|
|
|
243
242
|
}
|
|
244
243
|
return S3.putBucketWebsite({ Bucket, WebsiteConfiguration }).promise()
|
|
245
244
|
.then(() => {
|
|
246
|
-
this.formatMessage(64
|
|
245
|
+
this.formatMessage(64, service, ["Bucket configured", Bucket], WebsiteConfiguration, { ...Cloud.LOG_CLOUD_COMMAND });
|
|
247
246
|
return true;
|
|
248
247
|
})
|
|
249
248
|
.catch(err => {
|
|
250
249
|
if (!(0, exports.isNoSuchBucket)(err)) {
|
|
251
|
-
this.formatFail(64
|
|
250
|
+
this.formatFail(64, service, ["Unable to configure bucket", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
|
|
252
251
|
}
|
|
253
252
|
return false;
|
|
254
253
|
});
|
|
@@ -272,17 +271,17 @@ async function deleteObjectsV2(credential, Bucket, recursive = true, service = '
|
|
|
272
271
|
const Deleted = data.Deleted;
|
|
273
272
|
if ((0, types_1.isArray)(Deleted)) {
|
|
274
273
|
const files = Deleted.length + ' files';
|
|
275
|
-
this.formatMessage(64
|
|
274
|
+
this.formatMessage(64, service, ["Bucket emptied" + ` (${recursive ? 'recursive' : files})`, Bucket], recursive ? files : '', { ...Cloud.LOG_CLOUD_COMMAND });
|
|
276
275
|
}
|
|
277
276
|
})
|
|
278
277
|
.catch(err => {
|
|
279
|
-
this.formatFail(64
|
|
278
|
+
this.formatFail(64, service, ["Unable to empty bucket", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
|
|
280
279
|
});
|
|
281
280
|
}
|
|
282
281
|
})
|
|
283
282
|
.catch(err => {
|
|
284
283
|
if (!(0, exports.isNoSuchBucket)(err)) {
|
|
285
|
-
this.formatFail(64
|
|
284
|
+
this.formatFail(64, service, ["Unable to list bucket", Bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
|
|
286
285
|
}
|
|
287
286
|
});
|
|
288
287
|
}
|
|
@@ -314,7 +313,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
314
313
|
let rows, queryString = '';
|
|
315
314
|
if (key && (id || (0, types_1.isPlainObject)(key))) {
|
|
316
315
|
if (!TableName) {
|
|
317
|
-
throw (0, util_1.formatError)(item, "Missing database table"
|
|
316
|
+
throw (0, util_1.formatError)(item, "Missing database table");
|
|
318
317
|
}
|
|
319
318
|
if (useCache) {
|
|
320
319
|
queryString = TableName + '_' + Module.asString(key, true) + (id !== undefined ? '_' + Module.asString(id, true) : '');
|
|
@@ -339,7 +338,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
339
338
|
query.TableName = TableName;
|
|
340
339
|
}
|
|
341
340
|
if (!TableName) {
|
|
342
|
-
throw (0, util_1.formatError)(item, "Missing database table"
|
|
341
|
+
throw (0, util_1.formatError)(item, "Missing database table");
|
|
343
342
|
}
|
|
344
343
|
if (limit > 0) {
|
|
345
344
|
query.Limit = limit;
|
|
@@ -360,9 +359,8 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
360
359
|
}
|
|
361
360
|
TableName || (TableName = Object.keys(params.RequestItems)[0]);
|
|
362
361
|
if (!TableName) {
|
|
363
|
-
throw (0, util_1.formatError)(item, "Missing database table"
|
|
362
|
+
throw (0, util_1.formatError)(item, "Missing database table");
|
|
364
363
|
}
|
|
365
|
-
// @ts-ignore
|
|
366
364
|
const Item = (_a = params.RequestItems)[TableName] || (_a[TableName] = {});
|
|
367
365
|
Item.Keys = query;
|
|
368
366
|
params = { RequestItems: { [TableName]: Item } };
|
|
@@ -393,7 +391,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
393
391
|
}
|
|
394
392
|
}
|
|
395
393
|
else {
|
|
396
|
-
throw (0, util_1.formatError)(item, "Missing database query"
|
|
394
|
+
throw (0, util_1.formatError)(item, "Missing database query");
|
|
397
395
|
}
|
|
398
396
|
result[i] = this.setQueryResult(service, credential, queryString, rows, cacheValue);
|
|
399
397
|
}
|
|
@@ -433,7 +431,7 @@ function writeMessageDefaultRetention(bucket, retention, service = 'aws') {
|
|
|
433
431
|
if (Mode) {
|
|
434
432
|
status.push(status.length ? `(${Mode})` : Mode);
|
|
435
433
|
}
|
|
436
|
-
this.formatMessage(64
|
|
434
|
+
this.formatMessage(64, service, ["Bucket configured" + ' (Retention Policy)', bucket], status.join(' '), { ...Cloud.LOG_CLOUD_COMMAND });
|
|
437
435
|
}
|
|
438
436
|
exports.writeMessageDefaultRetention = writeMessageDefaultRetention;
|
|
439
437
|
function parseAttributeValue(value) {
|
package/download/index.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
2
|
const types_1 = require("@e-mc/types");
|
|
4
3
|
const Module = require("@e-mc/module");
|
|
5
4
|
const Cloud = require("@e-mc/cloud");
|
|
6
|
-
const client_1 = require("
|
|
7
|
-
function download(credential, service = 'aws', sdk = 'aws-sdk/clients/s3') {
|
|
5
|
+
const client_1 = require("@pi-r/aws");
|
|
6
|
+
module.exports = function download(credential, service = 'aws', sdk = 'aws-sdk/clients/s3') {
|
|
8
7
|
const s3 = client_1.createStorageClient.call(this, credential, service, sdk);
|
|
9
8
|
return (data, callback) => {
|
|
10
9
|
const { bucket: Bucket, download: target } = data;
|
|
@@ -22,10 +21,10 @@ function download(credential, service = 'aws', sdk = 'aws-sdk/clients/s3') {
|
|
|
22
21
|
if (deleteObject) {
|
|
23
22
|
s3.deleteObject((0, types_1.isPlainObject)(deleteObject) ? Object.assign(deleteObject, params) : params, error => {
|
|
24
23
|
if (!error) {
|
|
25
|
-
this.formatMessage(64
|
|
24
|
+
this.formatMessage(64, service, "Delete success", location, { ...Cloud.LOG_CLOUD_DELETE });
|
|
26
25
|
}
|
|
27
26
|
else {
|
|
28
|
-
this.formatFail(64
|
|
27
|
+
this.formatFail(64, service, ["Delete failed", location], error, { ...Cloud.LOG_CLOUD_FAIL, fatal: !!target.active });
|
|
29
28
|
}
|
|
30
29
|
});
|
|
31
30
|
}
|
|
@@ -35,6 +34,4 @@ function download(credential, service = 'aws', sdk = 'aws-sdk/clients/s3') {
|
|
|
35
34
|
}
|
|
36
35
|
});
|
|
37
36
|
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
module.exports = download;
|
|
37
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/aws",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.6",
|
|
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.7",
|
|
25
|
+
"@e-mc/module": "^0.8.7",
|
|
26
|
+
"@e-mc/types": "^0.8.7",
|
|
27
|
+
"aws-sdk": "^2.1591.0"
|
|
28
28
|
}
|
|
29
29
|
}
|
package/upload/index.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
2
|
const path = require("path");
|
|
4
3
|
const util_1 = require("@e-mc/cloud/util");
|
|
5
4
|
const types_1 = require("@e-mc/types");
|
|
6
5
|
const Module = require("@e-mc/module");
|
|
7
6
|
const Cloud = require("@e-mc/cloud");
|
|
8
|
-
const client_1 = require("
|
|
7
|
+
const client_1 = require("@pi-r/aws");
|
|
9
8
|
const BUCKET_SESSION = new Set();
|
|
10
9
|
const BUCKET_RESPONSE = {};
|
|
11
|
-
function upload(credential, service = 'aws', sdk = 'aws-sdk/clients/s3') {
|
|
10
|
+
module.exports = function upload(credential, service = 'aws', sdk = 'aws-sdk/clients/s3') {
|
|
12
11
|
const s3 = client_1.createStorageClient.call(this, credential, service, sdk);
|
|
13
12
|
return async (data, callback) => {
|
|
14
13
|
var _a;
|
|
@@ -70,7 +69,7 @@ function upload(credential, service = 'aws', sdk = 'aws-sdk/clients/s3') {
|
|
|
70
69
|
});
|
|
71
70
|
} while (exists && ++i);
|
|
72
71
|
if (i > 0) {
|
|
73
|
-
this.formatMessage(64
|
|
72
|
+
this.formatMessage(64, service, ["File renamed", current], filename, { ...Cloud.LOG_CLOUD_WARN });
|
|
74
73
|
}
|
|
75
74
|
}
|
|
76
75
|
if (pathname) {
|
|
@@ -129,7 +128,7 @@ function upload(credential, service = 'aws', sdk = 'aws-sdk/clients/s3') {
|
|
|
129
128
|
return;
|
|
130
129
|
}
|
|
131
130
|
const url = endpoint ? Module.joinPath(endpoint, result.Key) : result.Location;
|
|
132
|
-
this.formatMessage(64
|
|
131
|
+
this.formatMessage(64, service, "Upload success", url, { ...Cloud.LOG_CLOUD_UPLOAD });
|
|
133
132
|
if (!first) {
|
|
134
133
|
return;
|
|
135
134
|
}
|
|
@@ -142,7 +141,7 @@ function upload(credential, service = 'aws', sdk = 'aws-sdk/clients/s3') {
|
|
|
142
141
|
}
|
|
143
142
|
s3.putObjectTagging({ Bucket, Key: result.Key, Tagging: { TagSet }, ExpectedBucketOwner: params.ExpectedBucketOwner, RequestPayer: params.RequestPayer }, error => {
|
|
144
143
|
if (!error) {
|
|
145
|
-
this.formatMessage(64
|
|
144
|
+
this.formatMessage(64, service, ["Tags created", Bucket], result.Key, { ...Cloud.LOG_CLOUD_COMMAND });
|
|
146
145
|
}
|
|
147
146
|
else {
|
|
148
147
|
addLog(error);
|
|
@@ -152,7 +151,7 @@ function upload(credential, service = 'aws', sdk = 'aws-sdk/clients/s3') {
|
|
|
152
151
|
else if (tags === false || length === 0) {
|
|
153
152
|
s3.deleteObjectTagging({ Bucket, Key: result.Key, ExpectedBucketOwner: params.ExpectedBucketOwner }, error => {
|
|
154
153
|
if (!error) {
|
|
155
|
-
this.formatMessage(64
|
|
154
|
+
this.formatMessage(64, service, ["Tags deleted", Bucket], result.Key, { ...Cloud.LOG_CLOUD_COMMAND });
|
|
156
155
|
}
|
|
157
156
|
else {
|
|
158
157
|
addLog(error);
|
|
@@ -165,6 +164,4 @@ function upload(credential, service = 'aws', sdk = 'aws-sdk/clients/s3') {
|
|
|
165
164
|
});
|
|
166
165
|
}
|
|
167
166
|
};
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
module.exports = upload;
|
|
167
|
+
};
|