@pi-r/aws-lib 0.7.3 → 0.8.0
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/index.js +29 -22
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,25 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
exports.
|
|
2
|
+
exports.isAccessDefined = isAccessDefined;
|
|
3
|
+
exports.isEnvDefined = isEnvDefined;
|
|
4
|
+
exports.isSharedCredentialsDefined = isSharedCredentialsDefined;
|
|
5
|
+
exports.isProviderChainDefined = isProviderChainDefined;
|
|
6
|
+
exports.isDatabaseDefined = isDatabaseDefined;
|
|
7
|
+
exports.getPublicReadPolicy = getPublicReadPolicy;
|
|
8
|
+
exports.getBucketPublicReadPolicy = getBucketPublicReadPolicy;
|
|
9
|
+
exports.getPrivatePolicy = getPrivatePolicy;
|
|
10
|
+
exports.setEndpoint = setEndpoint;
|
|
11
|
+
exports.setDatabaseEndpoint = setDatabaseEndpoint;
|
|
12
|
+
exports.checkBucketCannedACL = checkBucketCannedACL;
|
|
13
|
+
exports.formatDefaultRetention = formatDefaultRetention;
|
|
14
|
+
exports.getBucketKey = getBucketKey;
|
|
3
15
|
function isAccessDefined(credential) {
|
|
4
16
|
return !!(credential.accessKeyId && credential.secretAccessKey);
|
|
5
17
|
}
|
|
6
|
-
exports.isAccessDefined = isAccessDefined;
|
|
7
18
|
function isEnvDefined() {
|
|
8
19
|
return !!(process.env.AWS_ACCESS_KEY_ID && process.env.AWS_SECRET_ACCESS_KEY);
|
|
9
20
|
}
|
|
10
|
-
exports.isEnvDefined = isEnvDefined;
|
|
11
21
|
function isSharedCredentialsDefined() {
|
|
12
22
|
return !!process.env.AWS_SDK_LOAD_CONFIG;
|
|
13
23
|
}
|
|
14
|
-
exports.isSharedCredentialsDefined = isSharedCredentialsDefined;
|
|
15
24
|
function isProviderChainDefined() {
|
|
16
25
|
return isSharedCredentialsDefined() || !!(process.env.AWS_WEB_IDENTITY_TOKEN_FILE || process.env.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI || process.env.AWS_CONTAINER_CREDENTIALS_FULL_URI);
|
|
17
26
|
}
|
|
18
|
-
exports.isProviderChainDefined = isProviderChainDefined;
|
|
19
27
|
function isDatabaseDefined(credential, data) {
|
|
20
28
|
return !!(data.table && (credential.region || credential.endpoint || process.env.AWS_REGION));
|
|
21
29
|
}
|
|
22
|
-
exports.isDatabaseDefined = isDatabaseDefined;
|
|
23
30
|
function getPublicReadPolicy(bucket, authenticated, write) {
|
|
24
31
|
const Action = ["s3:GetObject", "s3:GetObjectVersion"];
|
|
25
32
|
if (write) {
|
|
@@ -27,42 +34,45 @@ function getPublicReadPolicy(bucket, authenticated, write) {
|
|
|
27
34
|
}
|
|
28
35
|
return JSON.stringify({
|
|
29
36
|
"Version": "2012-10-17",
|
|
30
|
-
"Statement": [
|
|
37
|
+
"Statement": [
|
|
38
|
+
{
|
|
31
39
|
"Sid": (authenticated ? "AuthenticatedRead" : "PublicRead") + (write ? "Write" : ""),
|
|
32
40
|
"Effect": "Allow",
|
|
33
41
|
"Principal": authenticated ? { "AWS": "*" } : "*",
|
|
34
42
|
"Action": Action,
|
|
35
43
|
"Resource": [`arn:aws:s3:::${bucket}/*`]
|
|
36
|
-
}
|
|
44
|
+
}
|
|
45
|
+
]
|
|
37
46
|
});
|
|
38
47
|
}
|
|
39
|
-
exports.getPublicReadPolicy = getPublicReadPolicy;
|
|
40
48
|
function getBucketPublicReadPolicy(bucket) {
|
|
41
49
|
return JSON.stringify({
|
|
42
50
|
"Version": "2012-10-17",
|
|
43
|
-
"Statement": [
|
|
51
|
+
"Statement": [
|
|
52
|
+
{
|
|
44
53
|
"Sid": "BucketPublicRead",
|
|
45
54
|
"Effect": "Allow",
|
|
46
55
|
"Principal": "*",
|
|
47
56
|
"Action": ["s3:ListBucket", "s3:ListBucketVersions", "s3:ListBucketMultipartUploads"],
|
|
48
57
|
"Resource": [`arn:aws:s3:::${bucket}`]
|
|
49
|
-
}
|
|
58
|
+
}
|
|
59
|
+
]
|
|
50
60
|
});
|
|
51
61
|
}
|
|
52
|
-
exports.getBucketPublicReadPolicy = getBucketPublicReadPolicy;
|
|
53
62
|
function getPrivatePolicy(bucket) {
|
|
54
63
|
return JSON.stringify({
|
|
55
64
|
"Version": "2012-10-17",
|
|
56
|
-
"Statement": [
|
|
65
|
+
"Statement": [
|
|
66
|
+
{
|
|
57
67
|
"Sid": "Private",
|
|
58
68
|
"Effect": "Deny",
|
|
59
69
|
"Principal": "*",
|
|
60
70
|
"Action": "*",
|
|
61
71
|
"Resource": [`arn:aws:s3:::${bucket}`, `arn:aws:s3:::${bucket}/*`]
|
|
62
|
-
}
|
|
72
|
+
}
|
|
73
|
+
]
|
|
63
74
|
});
|
|
64
75
|
}
|
|
65
|
-
exports.getPrivatePolicy = getPrivatePolicy;
|
|
66
76
|
function setEndpoint(config, instance, fallbackRegion) {
|
|
67
77
|
let { region, endpoint } = config;
|
|
68
78
|
if (!endpoint) {
|
|
@@ -79,11 +89,9 @@ function setEndpoint(config, instance, fallbackRegion) {
|
|
|
79
89
|
}
|
|
80
90
|
}
|
|
81
91
|
}
|
|
82
|
-
exports.setEndpoint = setEndpoint;
|
|
83
92
|
function setDatabaseEndpoint(config, fallbackRegion = "us-east-1") {
|
|
84
93
|
setEndpoint(config, 'dynamodb', fallbackRegion);
|
|
85
94
|
}
|
|
86
|
-
exports.setDatabaseEndpoint = setDatabaseEndpoint;
|
|
87
95
|
function checkBucketCannedACL(value) {
|
|
88
96
|
switch (value) {
|
|
89
97
|
case "private":
|
|
@@ -93,7 +101,6 @@ function checkBucketCannedACL(value) {
|
|
|
93
101
|
return value;
|
|
94
102
|
}
|
|
95
103
|
}
|
|
96
|
-
exports.checkBucketCannedACL = checkBucketCannedACL;
|
|
97
104
|
function formatDefaultRetention(retention) {
|
|
98
105
|
const { Years = 0, Days = 0, Mode } = retention;
|
|
99
106
|
const status = [];
|
|
@@ -104,10 +111,10 @@ function formatDefaultRetention(retention) {
|
|
|
104
111
|
status.push(Days.toString() + 'D');
|
|
105
112
|
}
|
|
106
113
|
if (Mode) {
|
|
107
|
-
status.push(status.length ? `(${Mode})` : Mode);
|
|
114
|
+
status.push(status.length > 0 ? `(${Mode})` : Mode);
|
|
108
115
|
}
|
|
109
116
|
return status.join(' ');
|
|
110
117
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
118
|
+
function getBucketKey(credential, bucket, acl, service, sdk) {
|
|
119
|
+
return JSON.stringify(credential) + bucket + '_' + (acl || '') + service + sdk;
|
|
120
|
+
}
|