@geek-fun/serverlessinsight 0.5.5 → 0.5.7
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 +12 -10
- package/dist/package.json +2 -1
- package/dist/src/commands/deploy.js +74 -2
- package/dist/src/commands/index.js +17 -16
- package/dist/src/commands/show.js +302 -0
- package/dist/src/common/aliyunClient/apigwOperations.js +6 -22
- package/dist/src/common/aliyunClient/index.js +3 -2
- package/dist/src/common/aliyunClient/ossOperations.js +126 -1
- package/dist/src/common/constants.js +2 -3
- package/dist/src/common/context.js +4 -1
- package/dist/src/common/credentials.js +9 -3
- package/dist/src/common/domainUtils.js +121 -0
- package/dist/src/common/iacHelper.js +1 -8
- package/dist/src/common/stateBackend/cosStateBackend.js +16 -188
- package/dist/src/common/stateBackend/index.js +2 -0
- package/dist/src/common/stateBackend/lockUtils.js +55 -0
- package/dist/src/common/stateBackend/ossStateBackend.js +27 -199
- package/dist/src/common/stateBackend/remoteStateBackend.js +150 -0
- package/dist/src/common/tencentClient/cosOperations.js +366 -216
- package/dist/src/common/tencentClient/dnspodOperations.js +105 -0
- package/dist/src/common/tencentClient/index.js +5 -1
- package/dist/src/lang/en.js +30 -0
- package/dist/src/lang/zh-CN.js +28 -0
- package/dist/src/stack/aliyunStack/apigwResource.js +35 -0
- package/dist/src/stack/aliyunStack/ossResource.js +63 -19
- package/dist/src/stack/deploy.js +6 -33
- package/dist/src/stack/scfStack/cosResource.js +58 -8
- package/dist/src/types/domains/state.js +13 -0
- package/dist/src/validator/bucketSchema.js +1 -1
- package/dist/src/validator/templateRefSchema.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -1
- package/dist/src/commands/template.js +0 -28
|
@@ -1,29 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createCosOperations = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
// Set ACL if specified
|
|
21
|
-
if (config.ACL) {
|
|
4
|
+
const logger_1 = require("../logger");
|
|
5
|
+
const lang_1 = require("../../lang");
|
|
6
|
+
const domainUtils_1 = require("../domainUtils");
|
|
7
|
+
const createCosOperations = (cosClient, region, dnsOps) => {
|
|
8
|
+
const getCosEndpoint = (bucketName) => {
|
|
9
|
+
return `${bucketName}.cos.${region}.myqcloud.com`;
|
|
10
|
+
};
|
|
11
|
+
const bindCustomDomain = async (bucketName, domain) => {
|
|
12
|
+
const mainDomain = (0, domainUtils_1.extractMainDomain)(domain);
|
|
13
|
+
const hostRecord = (0, domainUtils_1.extractHostRecord)(domain, mainDomain);
|
|
14
|
+
const cosEndpoint = getCosEndpoint(bucketName);
|
|
15
|
+
let bucketDomainBound = false;
|
|
16
|
+
try {
|
|
22
17
|
await new Promise((resolve, reject) => {
|
|
23
|
-
cosClient.
|
|
24
|
-
Bucket:
|
|
25
|
-
Region:
|
|
26
|
-
|
|
18
|
+
cosClient.putBucketDomain({
|
|
19
|
+
Bucket: bucketName,
|
|
20
|
+
Region: region,
|
|
21
|
+
DomainRule: [
|
|
22
|
+
{
|
|
23
|
+
Status: 'ENABLED',
|
|
24
|
+
Name: domain,
|
|
25
|
+
Type: 'REST',
|
|
26
|
+
},
|
|
27
|
+
],
|
|
27
28
|
}, (err) => {
|
|
28
29
|
if (err) {
|
|
29
30
|
reject(err);
|
|
@@ -33,117 +34,176 @@ const createCosOperations = (cosClient) => ({
|
|
|
33
34
|
}
|
|
34
35
|
});
|
|
35
36
|
});
|
|
37
|
+
logger_1.logger.info(lang_1.lang.__('COS_BUCKET_DOMAIN_BOUND', { domain }));
|
|
38
|
+
bucketDomainBound = true;
|
|
36
39
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
catch (error) {
|
|
41
|
+
logger_1.logger.warn(lang_1.lang.__('COS_BUCKET_DOMAIN_BIND_FAILED', { error: String(error) }));
|
|
42
|
+
}
|
|
43
|
+
if (!dnsOps) {
|
|
44
|
+
logger_1.logger.warn(lang_1.lang.__('COS_DNS_MANUAL_CONFIG_REQUIRED', { domain, cname: cosEndpoint }));
|
|
45
|
+
return { domain, cname: cosEndpoint, bucketDomainBound };
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
const existingRecords = await dnsOps.describeDomainRecords(mainDomain, hostRecord);
|
|
49
|
+
const existingRecord = existingRecords.find((record) => record.rr === hostRecord && record.type === 'CNAME' && record.value === cosEndpoint);
|
|
50
|
+
if (existingRecord) {
|
|
51
|
+
logger_1.logger.info(lang_1.lang.__('COS_DNS_CNAME_EXISTS', { domain, cname: cosEndpoint }));
|
|
52
|
+
return {
|
|
53
|
+
domain,
|
|
54
|
+
cname: cosEndpoint,
|
|
55
|
+
dnsRecordId: existingRecord.recordId,
|
|
56
|
+
bucketDomainBound,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
const recordId = await dnsOps.addDomainRecord({
|
|
60
|
+
domainName: mainDomain,
|
|
61
|
+
rr: hostRecord,
|
|
62
|
+
type: 'CNAME',
|
|
63
|
+
value: cosEndpoint,
|
|
64
|
+
ttl: 600,
|
|
65
|
+
});
|
|
66
|
+
logger_1.logger.info(lang_1.lang.__('COS_DNS_CNAME_CREATED', { domain, cname: cosEndpoint }));
|
|
67
|
+
return { domain, cname: cosEndpoint, dnsRecordId: recordId, bucketDomainBound };
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
logger_1.logger.warn(lang_1.lang.__('COS_DNS_DOMAIN_NOT_MANAGED', { domain, cname: cosEndpoint }));
|
|
71
|
+
logger_1.logger.debug(`DNS error: ${error}`);
|
|
72
|
+
return { domain, cname: cosEndpoint, bucketDomainBound };
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const unbindCustomDomain = async (bucketName, domain, dnsRecordId) => {
|
|
76
|
+
try {
|
|
77
|
+
const existingRules = await new Promise((resolve, reject) => {
|
|
78
|
+
cosClient.getBucketDomain({
|
|
79
|
+
Bucket: bucketName,
|
|
80
|
+
Region: region,
|
|
81
|
+
}, (err, data) => {
|
|
46
82
|
if (err) {
|
|
47
|
-
|
|
83
|
+
if (err.statusCode === 404) {
|
|
84
|
+
resolve([]);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
reject(err);
|
|
88
|
+
}
|
|
48
89
|
}
|
|
49
90
|
else {
|
|
50
|
-
resolve();
|
|
91
|
+
resolve(data?.DomainRule ?? []);
|
|
51
92
|
}
|
|
52
93
|
});
|
|
53
94
|
});
|
|
95
|
+
const remainingRules = existingRules.filter((rule) => rule.Name !== domain);
|
|
96
|
+
if (remainingRules.length < existingRules.length) {
|
|
97
|
+
if (remainingRules.length > 0) {
|
|
98
|
+
await new Promise((resolve, reject) => {
|
|
99
|
+
cosClient.putBucketDomain({
|
|
100
|
+
Bucket: bucketName,
|
|
101
|
+
Region: region,
|
|
102
|
+
DomainRule: remainingRules.map((rule) => ({
|
|
103
|
+
Status: rule.Status,
|
|
104
|
+
Name: rule.Name,
|
|
105
|
+
Type: rule.Type,
|
|
106
|
+
})),
|
|
107
|
+
}, (err) => {
|
|
108
|
+
if (err) {
|
|
109
|
+
reject(err);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
resolve();
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
await new Promise((resolve, reject) => {
|
|
119
|
+
cosClient.deleteBucketDomain({
|
|
120
|
+
Bucket: bucketName,
|
|
121
|
+
Region: region,
|
|
122
|
+
}, (err) => {
|
|
123
|
+
if (err) {
|
|
124
|
+
reject(err);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
resolve();
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
logger_1.logger.info(lang_1.lang.__('COS_BUCKET_DOMAIN_UNBOUND', { domain }));
|
|
133
|
+
}
|
|
54
134
|
}
|
|
55
|
-
|
|
56
|
-
|
|
135
|
+
catch (error) {
|
|
136
|
+
logger_1.logger.warn(lang_1.lang.__('COS_BUCKET_DOMAIN_UNBIND_FAILED', { error: String(error) }));
|
|
137
|
+
}
|
|
138
|
+
if (!dnsOps || !dnsRecordId || dnsRecordId === 'existing') {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const mainDomain = (0, domainUtils_1.extractMainDomain)(domain);
|
|
57
142
|
try {
|
|
58
|
-
|
|
143
|
+
await dnsOps.deleteDomainRecord(mainDomain, dnsRecordId);
|
|
144
|
+
logger_1.logger.info(lang_1.lang.__('COS_DNS_CNAME_DELETED', { domain }));
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
logger_1.logger.warn(lang_1.lang.__('COS_DNS_CNAME_DELETE_FAILED', { domain, error: String(error) }));
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
return {
|
|
151
|
+
createBucket: async (config) => {
|
|
152
|
+
// Create bucket
|
|
59
153
|
await new Promise((resolve, reject) => {
|
|
60
|
-
cosClient.
|
|
61
|
-
Bucket:
|
|
62
|
-
Region:
|
|
63
|
-
}, (err
|
|
154
|
+
cosClient.putBucket({
|
|
155
|
+
Bucket: config.Bucket,
|
|
156
|
+
Region: config.Region,
|
|
157
|
+
}, (err) => {
|
|
64
158
|
if (err) {
|
|
65
159
|
reject(err);
|
|
66
160
|
}
|
|
67
161
|
else {
|
|
68
|
-
resolve(
|
|
162
|
+
resolve();
|
|
69
163
|
}
|
|
70
164
|
});
|
|
71
165
|
});
|
|
72
|
-
//
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}, (err, data) => {
|
|
166
|
+
// Set ACL if specified
|
|
167
|
+
if (config.ACL) {
|
|
168
|
+
await new Promise((resolve, reject) => {
|
|
169
|
+
cosClient.putBucketAcl({
|
|
170
|
+
Bucket: config.Bucket,
|
|
171
|
+
Region: config.Region,
|
|
172
|
+
ACL: config.ACL,
|
|
173
|
+
}, (err) => {
|
|
81
174
|
if (err) {
|
|
82
175
|
reject(err);
|
|
83
176
|
}
|
|
84
177
|
else {
|
|
85
|
-
resolve(
|
|
178
|
+
resolve();
|
|
86
179
|
}
|
|
87
180
|
});
|
|
88
181
|
});
|
|
89
|
-
acl = aclResult.ACL;
|
|
90
|
-
accessControlPolicy = {
|
|
91
|
-
owner: aclResult.Owner
|
|
92
|
-
? {
|
|
93
|
-
id: aclResult.Owner.ID,
|
|
94
|
-
displayName: undefined,
|
|
95
|
-
}
|
|
96
|
-
: undefined,
|
|
97
|
-
grants: aclResult.Grants?.map((g) => ({
|
|
98
|
-
grantee: g.Grantee
|
|
99
|
-
? {
|
|
100
|
-
type: 'ID' in g.Grantee ? 'CanonicalUser' : 'Group',
|
|
101
|
-
uri: 'URI' in g.Grantee ? g.Grantee.URI : undefined,
|
|
102
|
-
id: 'ID' in g.Grantee ? g.Grantee.ID : undefined,
|
|
103
|
-
displayName: undefined,
|
|
104
|
-
}
|
|
105
|
-
: undefined,
|
|
106
|
-
permission: g.Permission,
|
|
107
|
-
})),
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
catch {
|
|
111
|
-
// ACL might not be accessible due to insufficient permissions
|
|
112
182
|
}
|
|
113
|
-
//
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
cosClient.
|
|
118
|
-
Bucket:
|
|
119
|
-
Region:
|
|
120
|
-
|
|
183
|
+
// Set website configuration if specified
|
|
184
|
+
if (config.WebsiteConfiguration) {
|
|
185
|
+
const websiteConfig = config.WebsiteConfiguration;
|
|
186
|
+
await new Promise((resolve, reject) => {
|
|
187
|
+
cosClient.putBucketWebsite({
|
|
188
|
+
Bucket: config.Bucket,
|
|
189
|
+
Region: config.Region,
|
|
190
|
+
WebsiteConfiguration: websiteConfig,
|
|
191
|
+
}, (err) => {
|
|
121
192
|
if (err) {
|
|
122
193
|
reject(err);
|
|
123
194
|
}
|
|
124
195
|
else {
|
|
125
|
-
resolve(
|
|
196
|
+
resolve();
|
|
126
197
|
}
|
|
127
198
|
});
|
|
128
199
|
});
|
|
129
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
130
|
-
corsConfiguration = corsResult.CORSRules?.map((r) => ({
|
|
131
|
-
id: r.ID,
|
|
132
|
-
allowedOrigins: r.AllowedOrigin,
|
|
133
|
-
allowedMethods: r.AllowedMethod,
|
|
134
|
-
allowedHeaders: r.AllowedHeader,
|
|
135
|
-
exposeHeaders: r.ExposeHeader,
|
|
136
|
-
maxAgeSeconds: r.MaxAgeSeconds,
|
|
137
|
-
}));
|
|
138
|
-
}
|
|
139
|
-
catch {
|
|
140
|
-
// CORS might not be configured
|
|
141
200
|
}
|
|
142
|
-
|
|
143
|
-
|
|
201
|
+
},
|
|
202
|
+
getBucket: async (bucketName, region) => {
|
|
144
203
|
try {
|
|
145
|
-
|
|
146
|
-
|
|
204
|
+
// Check if bucket exists
|
|
205
|
+
await new Promise((resolve, reject) => {
|
|
206
|
+
cosClient.headBucket({
|
|
147
207
|
Bucket: bucketName,
|
|
148
208
|
Region: region,
|
|
149
209
|
}, (err, data) => {
|
|
@@ -155,133 +215,223 @@ const createCosOperations = (cosClient) => ({
|
|
|
155
215
|
}
|
|
156
216
|
});
|
|
157
217
|
});
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
218
|
+
// Get ACL
|
|
219
|
+
let acl;
|
|
220
|
+
let accessControlPolicy;
|
|
221
|
+
try {
|
|
222
|
+
const aclResult = await new Promise((resolve, reject) => {
|
|
223
|
+
cosClient.getBucketAcl({
|
|
224
|
+
Bucket: bucketName,
|
|
225
|
+
Region: region,
|
|
226
|
+
}, (err, data) => {
|
|
227
|
+
if (err) {
|
|
228
|
+
reject(err);
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
resolve(data);
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
acl = aclResult.ACL;
|
|
236
|
+
accessControlPolicy = {
|
|
237
|
+
owner: aclResult.Owner
|
|
238
|
+
? {
|
|
239
|
+
id: aclResult.Owner.ID,
|
|
240
|
+
displayName: undefined,
|
|
241
|
+
}
|
|
242
|
+
: undefined,
|
|
243
|
+
grants: aclResult.Grants?.map((g) => ({
|
|
244
|
+
grantee: g.Grantee
|
|
245
|
+
? {
|
|
246
|
+
type: 'ID' in g.Grantee ? 'CanonicalUser' : 'Group',
|
|
247
|
+
uri: 'URI' in g.Grantee ? g.Grantee.URI : undefined,
|
|
248
|
+
id: 'ID' in g.Grantee ? g.Grantee.ID : undefined,
|
|
249
|
+
displayName: undefined,
|
|
250
|
+
}
|
|
251
|
+
: undefined,
|
|
252
|
+
permission: g.Permission,
|
|
253
|
+
})),
|
|
163
254
|
};
|
|
164
255
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
256
|
+
catch {
|
|
257
|
+
// ACL might not be accessible due to insufficient permissions
|
|
258
|
+
}
|
|
259
|
+
// Get CORS configuration
|
|
260
|
+
let corsConfiguration;
|
|
261
|
+
try {
|
|
262
|
+
const corsResult = await new Promise((resolve, reject) => {
|
|
263
|
+
cosClient.getBucketCors({
|
|
264
|
+
Bucket: bucketName,
|
|
265
|
+
Region: region,
|
|
266
|
+
}, (err, data) => {
|
|
267
|
+
if (err) {
|
|
268
|
+
reject(err);
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
resolve(data);
|
|
272
|
+
}
|
|
273
|
+
});
|
|
183
274
|
});
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
275
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
276
|
+
corsConfiguration = corsResult.CORSRules?.map((r) => ({
|
|
277
|
+
id: r.ID,
|
|
278
|
+
allowedOrigins: r.AllowedOrigin,
|
|
279
|
+
allowedMethods: r.AllowedMethod,
|
|
280
|
+
allowedHeaders: r.AllowedHeader,
|
|
281
|
+
exposeHeaders: r.ExposeHeader,
|
|
282
|
+
maxAgeSeconds: r.MaxAgeSeconds,
|
|
283
|
+
}));
|
|
284
|
+
}
|
|
285
|
+
catch {
|
|
286
|
+
// CORS might not be configured
|
|
287
|
+
}
|
|
288
|
+
// Get website configuration
|
|
289
|
+
let websiteConfig;
|
|
290
|
+
try {
|
|
291
|
+
const websiteResult = await new Promise((resolve, reject) => {
|
|
292
|
+
cosClient.getBucketWebsite({
|
|
293
|
+
Bucket: bucketName,
|
|
294
|
+
Region: region,
|
|
295
|
+
}, (err, data) => {
|
|
296
|
+
if (err) {
|
|
297
|
+
reject(err);
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
resolve(data);
|
|
301
|
+
}
|
|
302
|
+
});
|
|
206
303
|
});
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
catch {
|
|
216
|
-
// Tagging might not be configured
|
|
217
|
-
}
|
|
218
|
-
return {
|
|
219
|
-
Name: bucketName,
|
|
220
|
-
Location: region,
|
|
221
|
-
ACL: acl,
|
|
222
|
-
WebsiteConfiguration: websiteConfig,
|
|
223
|
-
AccessControlPolicy: accessControlPolicy,
|
|
224
|
-
CorsConfiguration: corsConfiguration,
|
|
225
|
-
VersioningConfiguration: versioningConfig,
|
|
226
|
-
TaggingConfiguration: taggingConfig,
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
catch (error) {
|
|
230
|
-
if (error && typeof error === 'object' && 'statusCode' in error) {
|
|
231
|
-
const statusCode = error.statusCode;
|
|
232
|
-
if (statusCode === 404) {
|
|
233
|
-
return null;
|
|
304
|
+
if (websiteResult.WebsiteConfiguration?.IndexDocument ||
|
|
305
|
+
websiteResult.WebsiteConfiguration?.ErrorDocument) {
|
|
306
|
+
websiteConfig = {
|
|
307
|
+
IndexDocument: websiteResult.WebsiteConfiguration.IndexDocument,
|
|
308
|
+
ErrorDocument: websiteResult.WebsiteConfiguration.ErrorDocument,
|
|
309
|
+
};
|
|
310
|
+
}
|
|
234
311
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
}
|
|
238
|
-
},
|
|
239
|
-
updateBucketAcl: async (bucketName, region, acl) => {
|
|
240
|
-
await new Promise((resolve, reject) => {
|
|
241
|
-
cosClient.putBucketAcl({
|
|
242
|
-
Bucket: bucketName,
|
|
243
|
-
Region: region,
|
|
244
|
-
ACL: acl,
|
|
245
|
-
}, (err) => {
|
|
246
|
-
if (err) {
|
|
247
|
-
reject(err);
|
|
312
|
+
catch {
|
|
313
|
+
// Website configuration might not be set
|
|
248
314
|
}
|
|
249
|
-
|
|
250
|
-
|
|
315
|
+
// Get versioning configuration
|
|
316
|
+
let versioningConfig;
|
|
317
|
+
try {
|
|
318
|
+
const versioningResult = await new Promise((resolve, reject) => {
|
|
319
|
+
cosClient.getBucketVersioning({
|
|
320
|
+
Bucket: bucketName,
|
|
321
|
+
Region: region,
|
|
322
|
+
}, (err, data) => {
|
|
323
|
+
if (err) {
|
|
324
|
+
reject(err);
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
resolve(data);
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
});
|
|
331
|
+
versioningConfig = {
|
|
332
|
+
status: versioningResult.VersioningConfiguration?.Status,
|
|
333
|
+
};
|
|
251
334
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
},
|
|
255
|
-
updateBucketWebsite: async (bucketName, region, websiteConfig) => {
|
|
256
|
-
await new Promise((resolve, reject) => {
|
|
257
|
-
cosClient.putBucketWebsite({
|
|
258
|
-
Bucket: bucketName,
|
|
259
|
-
Region: region,
|
|
260
|
-
WebsiteConfiguration: websiteConfig,
|
|
261
|
-
}, (err) => {
|
|
262
|
-
if (err) {
|
|
263
|
-
reject(err);
|
|
335
|
+
catch {
|
|
336
|
+
// Versioning might not be accessible
|
|
264
337
|
}
|
|
265
|
-
|
|
266
|
-
|
|
338
|
+
// Get tagging configuration
|
|
339
|
+
let taggingConfig;
|
|
340
|
+
try {
|
|
341
|
+
const taggingResult = await new Promise((resolve, reject) => {
|
|
342
|
+
cosClient.getBucketTagging({
|
|
343
|
+
Bucket: bucketName,
|
|
344
|
+
Region: region,
|
|
345
|
+
}, (err, data) => {
|
|
346
|
+
if (err) {
|
|
347
|
+
reject(err);
|
|
348
|
+
}
|
|
349
|
+
else {
|
|
350
|
+
resolve(data);
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
});
|
|
354
|
+
taggingConfig = {
|
|
355
|
+
tags: taggingResult.Tags?.map((t) => ({
|
|
356
|
+
key: t.Key,
|
|
357
|
+
value: t.Value,
|
|
358
|
+
})),
|
|
359
|
+
};
|
|
267
360
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
},
|
|
271
|
-
deleteBucket: async (bucketName, region) => {
|
|
272
|
-
await new Promise((resolve, reject) => {
|
|
273
|
-
cosClient.deleteBucket({
|
|
274
|
-
Bucket: bucketName,
|
|
275
|
-
Region: region,
|
|
276
|
-
}, (err) => {
|
|
277
|
-
if (err) {
|
|
278
|
-
reject(err);
|
|
361
|
+
catch {
|
|
362
|
+
// Tagging might not be configured
|
|
279
363
|
}
|
|
280
|
-
|
|
281
|
-
|
|
364
|
+
return {
|
|
365
|
+
Name: bucketName,
|
|
366
|
+
Location: region,
|
|
367
|
+
ACL: acl,
|
|
368
|
+
WebsiteConfiguration: websiteConfig,
|
|
369
|
+
AccessControlPolicy: accessControlPolicy,
|
|
370
|
+
CorsConfiguration: corsConfiguration,
|
|
371
|
+
VersioningConfiguration: versioningConfig,
|
|
372
|
+
TaggingConfiguration: taggingConfig,
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
catch (error) {
|
|
376
|
+
if (error && typeof error === 'object' && 'statusCode' in error) {
|
|
377
|
+
const statusCode = error.statusCode;
|
|
378
|
+
if (statusCode === 404) {
|
|
379
|
+
return null;
|
|
380
|
+
}
|
|
282
381
|
}
|
|
382
|
+
throw error;
|
|
383
|
+
}
|
|
384
|
+
},
|
|
385
|
+
updateBucketAcl: async (bucketName, region, acl) => {
|
|
386
|
+
await new Promise((resolve, reject) => {
|
|
387
|
+
cosClient.putBucketAcl({
|
|
388
|
+
Bucket: bucketName,
|
|
389
|
+
Region: region,
|
|
390
|
+
ACL: acl,
|
|
391
|
+
}, (err) => {
|
|
392
|
+
if (err) {
|
|
393
|
+
reject(err);
|
|
394
|
+
}
|
|
395
|
+
else {
|
|
396
|
+
resolve();
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
});
|
|
400
|
+
},
|
|
401
|
+
updateBucketWebsite: async (bucketName, region, websiteConfig) => {
|
|
402
|
+
await new Promise((resolve, reject) => {
|
|
403
|
+
cosClient.putBucketWebsite({
|
|
404
|
+
Bucket: bucketName,
|
|
405
|
+
Region: region,
|
|
406
|
+
WebsiteConfiguration: websiteConfig,
|
|
407
|
+
}, (err) => {
|
|
408
|
+
if (err) {
|
|
409
|
+
reject(err);
|
|
410
|
+
}
|
|
411
|
+
else {
|
|
412
|
+
resolve();
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
});
|
|
416
|
+
},
|
|
417
|
+
deleteBucket: async (bucketName, region) => {
|
|
418
|
+
await new Promise((resolve, reject) => {
|
|
419
|
+
cosClient.deleteBucket({
|
|
420
|
+
Bucket: bucketName,
|
|
421
|
+
Region: region,
|
|
422
|
+
}, (err) => {
|
|
423
|
+
if (err) {
|
|
424
|
+
reject(err);
|
|
425
|
+
}
|
|
426
|
+
else {
|
|
427
|
+
resolve();
|
|
428
|
+
}
|
|
429
|
+
});
|
|
283
430
|
});
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
|
|
431
|
+
},
|
|
432
|
+
bindCustomDomain,
|
|
433
|
+
unbindCustomDomain,
|
|
434
|
+
getCosEndpoint,
|
|
435
|
+
};
|
|
436
|
+
};
|
|
287
437
|
exports.createCosOperations = createCosOperations;
|