@geek-fun/serverlessinsight 0.9.2 → 0.9.4
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/.serverlessinsight/state-cdn-flow-app-cdn-flow-service.json.backup +1 -1
- package/.serverlessinsight/state-iam-test-app-iam-test-service.json.backup +2 -2
- package/.serverlessinsight/state-insight-poc-app-insight-poc-tencent.json.backup +4 -8
- package/.serverlessinsight/state-insight-poc-app-log-insight-poc-tencent-log.json.backup +3 -8
- package/.serverlessinsight/state-insight-poc-deploy-app-insight-poc-deploy.json.backup +4 -4
- package/.serverlessinsight/state-insight-poc-destroy-app-insight-poc-destroy.json.backup +1 -1
- package/.serverlessinsight/state-insight-poc-timer-app-insight-poc-timer.json.backup +28 -5
- package/.serverlessinsight/state-insight-volc-app-insight-volc.json.backup +2 -2
- package/.serverlessinsight/state-insight-volc-nested-app-insight-volc-nested.json.backup +3 -3
- package/.serverlessinsight/state-nested-drift-app-nested-drift-service.json.backup +20 -5
- package/.serverlessinsight/state-role-reconcile-test-app-role-reconcile-test-service.json.backup +3 -3
- package/AGENTS.md +10 -0
- package/CHANGELOG.md +62 -0
- package/README.md +256 -175
- package/README.zh-CN.md +249 -159
- package/dist/package.json +22 -19
- package/dist/src/commands/index.js +21 -52
- package/dist/src/commands/local.js +16 -3
- package/dist/src/commands/plan.js +35 -4
- package/dist/src/common/aliyunClient/apigwOperations.js +48 -9
- package/dist/src/common/aliyunClient/fc3Operations.js +7 -1
- package/dist/src/common/aliyunClient/ossOperations.js +214 -221
- package/dist/src/common/bucketPolicy.js +63 -0
- package/dist/src/common/domainUtils.js +4 -1
- package/dist/src/common/functionDefinition.js +25 -0
- package/dist/src/common/index.js +4 -0
- package/dist/src/common/jsonOutput.js +6 -1
- package/dist/src/common/nameBuilder.js +3 -1
- package/dist/src/common/planCapabilities.js +119 -0
- package/dist/src/common/planCompare.js +119 -66
- package/dist/src/common/planFormatter.js +22 -14
- package/dist/src/common/planRedaction.js +26 -0
- package/dist/src/common/refreshPlanner.js +66 -21
- package/dist/src/common/tencentClient/cosOperations.js +326 -322
- package/dist/src/common/tencentClient/scfOperations.js +9 -2
- package/dist/src/common/tencentClient/tdsqlcOperations.js +6 -11
- package/dist/src/common/triggerMapper.js +16 -1
- package/dist/src/common/volcengineClient/apigwOperations.js +82 -0
- package/dist/src/common/volcengineClient/iamOperations.js +27 -3
- package/dist/src/common/volcengineClient/tosOperations.js +62 -56
- package/dist/src/lang/en.js +33 -8
- package/dist/src/lang/index.js +28 -14
- package/dist/src/lang/zh-CN.js +33 -8
- package/dist/src/parser/eventParser.js +1 -0
- package/dist/src/parser/functionParser.js +1 -1
- package/dist/src/stack/aliyunStack/apigwDomainPlan.js +82 -0
- package/dist/src/stack/aliyunStack/apigwExecutor.js +4 -1
- package/dist/src/stack/aliyunStack/apigwPlanner.js +165 -25
- package/dist/src/stack/aliyunStack/apigwResource.js +172 -126
- package/dist/src/stack/aliyunStack/apigwTypes.js +3 -7
- package/dist/src/stack/aliyunStack/deployer.js +2 -0
- package/dist/src/stack/aliyunStack/esServerlessTypes.js +8 -4
- package/dist/src/stack/aliyunStack/fc3Executor.js +7 -3
- package/dist/src/stack/aliyunStack/fc3Planner.js +124 -155
- package/dist/src/stack/aliyunStack/fc3Resource.js +48 -52
- package/dist/src/stack/aliyunStack/fc3Types.js +30 -16
- package/dist/src/stack/aliyunStack/ossPlanner.js +15 -1
- package/dist/src/stack/aliyunStack/ossResource.js +113 -102
- package/dist/src/stack/aliyunStack/ossTypes.js +20 -20
- package/dist/src/stack/localStack/aliyunFc.js +1 -6
- package/dist/src/stack/localStack/event.js +31 -60
- package/dist/src/stack/localStack/function.js +24 -65
- package/dist/src/stack/localStack/functionRunner.js +10 -2
- package/dist/src/stack/localStack/httpAdapter.js +54 -0
- package/dist/src/stack/localStack/httpError.js +5 -0
- package/dist/src/stack/localStack/legacyLambda.js +26 -0
- package/dist/src/stack/localStack/localContext.js +29 -0
- package/dist/src/stack/localStack/localRoute.js +12 -0
- package/dist/src/stack/localStack/localRuntimes.js +22 -0
- package/dist/src/stack/localStack/localServer.js +8 -3
- package/dist/src/stack/localStack/requestBody.js +24 -0
- package/dist/src/stack/localStack/requestId.js +18 -0
- package/dist/src/stack/localStack/tencent.js +147 -0
- package/dist/src/stack/localStack/timer.js +23 -2
- package/dist/src/stack/localStack/volcengine.js +68 -0
- package/dist/src/stack/scfStack/cosPlanner.js +9 -14
- package/dist/src/stack/scfStack/cosResource.js +42 -50
- package/dist/src/stack/scfStack/cosTypes.js +19 -14
- package/dist/src/stack/scfStack/deployer.js +2 -0
- package/dist/src/stack/scfStack/scfExecutor.js +7 -3
- package/dist/src/stack/scfStack/scfHttpTrigger.js +106 -0
- package/dist/src/stack/scfStack/scfPlanner.js +67 -16
- package/dist/src/stack/scfStack/scfResource.js +170 -321
- package/dist/src/stack/scfStack/scfTypes.js +4 -3
- package/dist/src/stack/scfStack/tdsqlcPlanner.js +10 -13
- package/dist/src/stack/volcengineStack/apigwDomains.js +64 -0
- package/dist/src/stack/volcengineStack/apigwPlanner.js +71 -15
- package/dist/src/stack/volcengineStack/apigwResource.js +60 -24
- package/dist/src/stack/volcengineStack/apigwTypes.js +5 -1
- package/dist/src/stack/volcengineStack/deployer.js +6 -0
- package/dist/src/stack/volcengineStack/tosPlanner.js +8 -13
- package/dist/src/stack/volcengineStack/tosResource.js +22 -35
- package/dist/src/stack/volcengineStack/tosTypes.js +5 -8
- package/dist/src/stack/volcengineStack/vefaasPlanner.js +142 -49
- package/dist/src/stack/volcengineStack/vefaasResource.js +17 -12
- package/dist/src/stack/volcengineStack/vefaasTypes.js +6 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +22 -19
- package/release-notes.md +53 -0
- package/samples/README_TENCENT_COS.md +3 -3
- package/samples/README_TENCENT_SCF.md +3 -3
- package/samples/tencent-local/index.js +13 -0
- package/samples/tencent-local/serverlessinsight.yml +23 -0
- package/samples/volcengine-local/index.js +13 -0
- package/samples/volcengine-local/serverlessinsight.yml +28 -0
|
@@ -330,30 +330,13 @@ const createCosOperations = (cosClient, region, dnsOps) => {
|
|
|
330
330
|
}
|
|
331
331
|
},
|
|
332
332
|
getBucket: async (bucketName, region) => {
|
|
333
|
-
|
|
334
|
-
// Check if bucket exists. The HeadBucket response carries the bucket
|
|
335
|
-
// creation date in the x-cos-creation-date header — preserved so the
|
|
336
|
-
// state instance no longer reports creationDate: null.
|
|
337
|
-
const headBucketData = await new Promise((resolve, reject) => {
|
|
338
|
-
cosClient.headBucket({
|
|
339
|
-
Bucket: bucketName,
|
|
340
|
-
Region: region,
|
|
341
|
-
}, (err, data) => {
|
|
342
|
-
if (err) {
|
|
343
|
-
reject(err);
|
|
344
|
-
}
|
|
345
|
-
else {
|
|
346
|
-
resolve(data);
|
|
347
|
-
}
|
|
348
|
-
});
|
|
349
|
-
});
|
|
350
|
-
const creationDate = headBucketData.headers?.['x-cos-creation-date'];
|
|
351
|
-
// Get ACL
|
|
352
|
-
let acl;
|
|
353
|
-
let accessControlPolicy;
|
|
333
|
+
const headBucketData = await (async () => {
|
|
354
334
|
try {
|
|
355
|
-
|
|
356
|
-
|
|
335
|
+
// Check if bucket exists. The HeadBucket response carries the bucket
|
|
336
|
+
// creation date in the x-cos-creation-date header — preserved so the
|
|
337
|
+
// state instance no longer reports creationDate: null.
|
|
338
|
+
return await new Promise((resolve, reject) => {
|
|
339
|
+
cosClient.headBucket({
|
|
357
340
|
Bucket: bucketName,
|
|
358
341
|
Region: region,
|
|
359
342
|
}, (err, data) => {
|
|
@@ -365,322 +348,342 @@ const createCosOperations = (cosClient, region, dnsOps) => {
|
|
|
365
348
|
}
|
|
366
349
|
});
|
|
367
350
|
});
|
|
368
|
-
acl = aclResult.ACL;
|
|
369
|
-
accessControlPolicy = {
|
|
370
|
-
owner: aclResult.Owner
|
|
371
|
-
? {
|
|
372
|
-
id: aclResult.Owner.ID,
|
|
373
|
-
displayName: undefined,
|
|
374
|
-
}
|
|
375
|
-
: undefined,
|
|
376
|
-
grants: aclResult.Grants?.map((g) => ({
|
|
377
|
-
grantee: g.Grantee
|
|
378
|
-
? {
|
|
379
|
-
type: 'ID' in g.Grantee ? 'CanonicalUser' : 'Group',
|
|
380
|
-
uri: 'URI' in g.Grantee ? g.Grantee.URI : undefined,
|
|
381
|
-
id: 'ID' in g.Grantee ? g.Grantee.ID : undefined,
|
|
382
|
-
displayName: undefined,
|
|
383
|
-
}
|
|
384
|
-
: undefined,
|
|
385
|
-
permission: g.Permission,
|
|
386
|
-
})),
|
|
387
|
-
};
|
|
388
351
|
}
|
|
389
|
-
catch {
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
const corsResult = await new Promise((resolve, reject) => {
|
|
396
|
-
cosClient.getBucketCors({
|
|
397
|
-
Bucket: bucketName,
|
|
398
|
-
Region: region,
|
|
399
|
-
}, (err, data) => {
|
|
400
|
-
if (err) {
|
|
401
|
-
reject(err);
|
|
402
|
-
}
|
|
403
|
-
else {
|
|
404
|
-
resolve(data);
|
|
405
|
-
}
|
|
406
|
-
});
|
|
407
|
-
});
|
|
408
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
409
|
-
corsConfiguration = corsResult.CORSRules?.map((r) => ({
|
|
410
|
-
id: r.ID,
|
|
411
|
-
allowedOrigins: r.AllowedOrigin,
|
|
412
|
-
allowedMethods: r.AllowedMethod,
|
|
413
|
-
allowedHeaders: r.AllowedHeader,
|
|
414
|
-
exposeHeaders: r.ExposeHeader,
|
|
415
|
-
maxAgeSeconds: r.MaxAgeSeconds,
|
|
416
|
-
}));
|
|
417
|
-
}
|
|
418
|
-
catch {
|
|
419
|
-
// CORS might not be configured
|
|
420
|
-
}
|
|
421
|
-
// Get website configuration
|
|
422
|
-
let websiteConfig;
|
|
423
|
-
try {
|
|
424
|
-
const websiteResult = await new Promise((resolve, reject) => {
|
|
425
|
-
cosClient.getBucketWebsite({
|
|
426
|
-
Bucket: bucketName,
|
|
427
|
-
Region: region,
|
|
428
|
-
}, (err, data) => {
|
|
429
|
-
if (err) {
|
|
430
|
-
reject(err);
|
|
431
|
-
}
|
|
432
|
-
else {
|
|
433
|
-
resolve(data);
|
|
434
|
-
}
|
|
435
|
-
});
|
|
436
|
-
});
|
|
437
|
-
if (websiteResult.WebsiteConfiguration?.IndexDocument ||
|
|
438
|
-
websiteResult.WebsiteConfiguration?.ErrorDocument) {
|
|
439
|
-
websiteConfig = {
|
|
440
|
-
IndexDocument: websiteResult.WebsiteConfiguration.IndexDocument,
|
|
441
|
-
ErrorDocument: websiteResult.WebsiteConfiguration.ErrorDocument,
|
|
442
|
-
};
|
|
352
|
+
catch (error) {
|
|
353
|
+
if (error && typeof error === 'object' && 'statusCode' in error) {
|
|
354
|
+
const statusCode = error.statusCode;
|
|
355
|
+
if (statusCode === 404) {
|
|
356
|
+
return null;
|
|
357
|
+
}
|
|
443
358
|
}
|
|
359
|
+
throw error;
|
|
444
360
|
}
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
361
|
+
})();
|
|
362
|
+
if (headBucketData === null)
|
|
363
|
+
return null;
|
|
364
|
+
const creationDate = headBucketData.headers?.['x-cos-creation-date'];
|
|
365
|
+
// Get ACL
|
|
366
|
+
let acl;
|
|
367
|
+
let accessControlPolicy;
|
|
368
|
+
try {
|
|
369
|
+
const aclResult = await new Promise((resolve, reject) => {
|
|
370
|
+
cosClient.getBucketAcl({
|
|
371
|
+
Bucket: bucketName,
|
|
372
|
+
Region: region,
|
|
373
|
+
}, (err, data) => {
|
|
374
|
+
if (err) {
|
|
375
|
+
reject(err);
|
|
376
|
+
}
|
|
377
|
+
else {
|
|
378
|
+
resolve(data);
|
|
379
|
+
}
|
|
463
380
|
});
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
reject(err);
|
|
481
|
-
}
|
|
482
|
-
else {
|
|
483
|
-
resolve(data);
|
|
381
|
+
});
|
|
382
|
+
acl = aclResult.ACL;
|
|
383
|
+
accessControlPolicy = {
|
|
384
|
+
owner: aclResult.Owner
|
|
385
|
+
? {
|
|
386
|
+
id: aclResult.Owner.ID,
|
|
387
|
+
displayName: undefined,
|
|
388
|
+
}
|
|
389
|
+
: undefined,
|
|
390
|
+
grants: aclResult.Grants?.map((g) => ({
|
|
391
|
+
grantee: g.Grantee
|
|
392
|
+
? {
|
|
393
|
+
type: 'ID' in g.Grantee ? 'CanonicalUser' : 'Group',
|
|
394
|
+
uri: 'URI' in g.Grantee ? g.Grantee.URI : undefined,
|
|
395
|
+
id: 'ID' in g.Grantee ? g.Grantee.ID : undefined,
|
|
396
|
+
displayName: undefined,
|
|
484
397
|
}
|
|
485
|
-
|
|
398
|
+
: undefined,
|
|
399
|
+
permission: g.Permission,
|
|
400
|
+
})),
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
catch {
|
|
404
|
+
// ACL might not be accessible due to insufficient permissions
|
|
405
|
+
}
|
|
406
|
+
// Get CORS configuration
|
|
407
|
+
let corsConfiguration;
|
|
408
|
+
try {
|
|
409
|
+
const corsResult = await new Promise((resolve, reject) => {
|
|
410
|
+
cosClient.getBucketCors({
|
|
411
|
+
Bucket: bucketName,
|
|
412
|
+
Region: region,
|
|
413
|
+
}, (err, data) => {
|
|
414
|
+
if (err) {
|
|
415
|
+
reject(err);
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
resolve(data);
|
|
419
|
+
}
|
|
486
420
|
});
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
421
|
+
});
|
|
422
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
423
|
+
corsConfiguration = corsResult.CORSRules?.map((r) => ({
|
|
424
|
+
id: r.ID,
|
|
425
|
+
allowedOrigins: r.AllowedOrigin,
|
|
426
|
+
allowedMethods: r.AllowedMethod,
|
|
427
|
+
allowedHeaders: r.AllowedHeader,
|
|
428
|
+
exposeHeaders: r.ExposeHeader,
|
|
429
|
+
maxAgeSeconds: r.MaxAgeSeconds,
|
|
430
|
+
}));
|
|
431
|
+
}
|
|
432
|
+
catch {
|
|
433
|
+
// CORS might not be configured
|
|
434
|
+
}
|
|
435
|
+
// Get website configuration
|
|
436
|
+
let websiteConfig = null;
|
|
437
|
+
try {
|
|
438
|
+
const websiteResult = await new Promise((resolve, reject) => {
|
|
439
|
+
cosClient.getBucketWebsite({
|
|
440
|
+
Bucket: bucketName,
|
|
441
|
+
Region: region,
|
|
442
|
+
}, (err, data) => {
|
|
443
|
+
if (err) {
|
|
444
|
+
reject(err);
|
|
445
|
+
}
|
|
446
|
+
else {
|
|
447
|
+
resolve(data);
|
|
448
|
+
}
|
|
449
|
+
});
|
|
450
|
+
});
|
|
451
|
+
if (websiteResult.WebsiteConfiguration?.IndexDocument ||
|
|
452
|
+
websiteResult.WebsiteConfiguration?.ErrorDocument) {
|
|
453
|
+
websiteConfig = {
|
|
454
|
+
IndexDocument: websiteResult.WebsiteConfiguration.IndexDocument,
|
|
455
|
+
ErrorDocument: websiteResult.WebsiteConfiguration.ErrorDocument,
|
|
492
456
|
};
|
|
493
457
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
458
|
+
}
|
|
459
|
+
catch (error) {
|
|
460
|
+
const code = error?.code;
|
|
461
|
+
if (code !== 'NoSuchWebsiteConfiguration' && code !== 'NoSuchConfiguration')
|
|
462
|
+
throw error;
|
|
463
|
+
}
|
|
464
|
+
// Get versioning configuration
|
|
465
|
+
const versioningResult = await new Promise((resolve, reject) => {
|
|
466
|
+
cosClient.getBucketVersioning({
|
|
467
|
+
Bucket: bucketName,
|
|
468
|
+
Region: region,
|
|
469
|
+
}, (err, data) => {
|
|
470
|
+
if (err) {
|
|
471
|
+
reject(err);
|
|
504
472
|
}
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
473
|
+
else {
|
|
474
|
+
resolve(data);
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
});
|
|
478
|
+
const versioningConfig = {
|
|
479
|
+
status: versioningResult.VersioningConfiguration?.Status,
|
|
480
|
+
};
|
|
481
|
+
// Get tagging configuration
|
|
482
|
+
let taggingConfig;
|
|
483
|
+
try {
|
|
484
|
+
const taggingResult = await new Promise((resolve, reject) => {
|
|
485
|
+
cosClient.getBucketTagging({
|
|
486
|
+
Bucket: bucketName,
|
|
487
|
+
Region: region,
|
|
488
|
+
}, (err, data) => {
|
|
489
|
+
if (err) {
|
|
490
|
+
reject(err);
|
|
491
|
+
}
|
|
492
|
+
else {
|
|
493
|
+
resolve(data);
|
|
494
|
+
}
|
|
521
495
|
});
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
catch {
|
|
541
|
-
// Lifecycle might not be configured
|
|
496
|
+
});
|
|
497
|
+
taggingConfig = {
|
|
498
|
+
tags: taggingResult.Tags?.map((t) => ({
|
|
499
|
+
key: t.Key,
|
|
500
|
+
value: t.Value,
|
|
501
|
+
})),
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
catch (error) {
|
|
505
|
+
// A 404 or NoSuchTagSet means the bucket has no tagging config — not
|
|
506
|
+
// an error. Any other failure (auth, network) must surface loudly so
|
|
507
|
+
// it is not misread as "bucket not owned".
|
|
508
|
+
const err = error;
|
|
509
|
+
const isNoTags = err.statusCode === 404 ||
|
|
510
|
+
err.code === 'NoSuchTagSet' ||
|
|
511
|
+
String(err.message ?? '').includes('NoSuchTagSet');
|
|
512
|
+
if (!isNoTags) {
|
|
513
|
+
throw error;
|
|
542
514
|
}
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
}
|
|
515
|
+
}
|
|
516
|
+
// Get lifecycle configuration
|
|
517
|
+
let lifecycleConfiguration;
|
|
518
|
+
try {
|
|
519
|
+
const lifecycleResult = await new Promise((resolve, reject) => {
|
|
520
|
+
cosClient.getBucketLifecycle({
|
|
521
|
+
Bucket: bucketName,
|
|
522
|
+
Region: region,
|
|
523
|
+
}, (err, data) => {
|
|
524
|
+
if (err) {
|
|
525
|
+
reject(err);
|
|
526
|
+
}
|
|
527
|
+
else {
|
|
528
|
+
resolve(data);
|
|
529
|
+
}
|
|
558
530
|
});
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
},
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
531
|
+
});
|
|
532
|
+
lifecycleConfiguration = {
|
|
533
|
+
rules: lifecycleResult.Rules?.map((r) => ({
|
|
534
|
+
id: r.ID,
|
|
535
|
+
status: r.Status,
|
|
536
|
+
prefix: typeof r.Filter?.Prefix === 'string' ? r.Filter.Prefix : undefined,
|
|
537
|
+
expiration: {
|
|
538
|
+
days: r.Expiration?.Days,
|
|
539
|
+
date: r.Expiration?.Date,
|
|
540
|
+
expiredObjectDeleteMarker: r.Expiration?.ExpiredObjectDeleteMarker,
|
|
541
|
+
},
|
|
542
|
+
transition: {
|
|
543
|
+
days: r.Transition?.Days,
|
|
544
|
+
date: r.Transition?.Date,
|
|
545
|
+
storageClass: r.Transition?.StorageClass,
|
|
546
|
+
},
|
|
547
|
+
})),
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
catch {
|
|
551
|
+
// Lifecycle might not be configured
|
|
552
|
+
}
|
|
553
|
+
// Get logging configuration
|
|
554
|
+
let loggingConfiguration;
|
|
555
|
+
try {
|
|
556
|
+
const loggingResult = await new Promise((resolve, reject) => {
|
|
557
|
+
cosClient.getBucketLogging({
|
|
558
|
+
Bucket: bucketName,
|
|
559
|
+
Region: region,
|
|
560
|
+
}, (err, data) => {
|
|
561
|
+
if (err) {
|
|
562
|
+
reject(err);
|
|
563
|
+
}
|
|
564
|
+
else {
|
|
565
|
+
resolve(data);
|
|
566
|
+
}
|
|
582
567
|
});
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
}, (err, data) => {
|
|
607
|
-
if (err) {
|
|
608
|
-
reject(err);
|
|
609
|
-
}
|
|
610
|
-
else {
|
|
611
|
-
resolve(data);
|
|
612
|
-
}
|
|
613
|
-
});
|
|
568
|
+
});
|
|
569
|
+
loggingConfiguration = {
|
|
570
|
+
targetBucket: loggingResult.BucketLoggingStatus?.LoggingEnabled?.TargetBucket,
|
|
571
|
+
targetPrefix: loggingResult.BucketLoggingStatus?.LoggingEnabled?.TargetPrefix,
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
catch {
|
|
575
|
+
// Logging might not be configured
|
|
576
|
+
}
|
|
577
|
+
// Get replication configuration
|
|
578
|
+
let replicationConfiguration;
|
|
579
|
+
try {
|
|
580
|
+
const replicationResult = await new Promise((resolve, reject) => {
|
|
581
|
+
cosClient.getBucketReplication({
|
|
582
|
+
Bucket: bucketName,
|
|
583
|
+
Region: region,
|
|
584
|
+
}, (err, data) => {
|
|
585
|
+
if (err) {
|
|
586
|
+
reject(err);
|
|
587
|
+
}
|
|
588
|
+
else {
|
|
589
|
+
resolve(data);
|
|
590
|
+
}
|
|
614
591
|
});
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
//
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
}
|
|
592
|
+
});
|
|
593
|
+
replicationConfiguration = {
|
|
594
|
+
role: replicationResult.ReplicationConfiguration?.Role,
|
|
595
|
+
rules: replicationResult.ReplicationConfiguration?.Rules?.map((r) => ({
|
|
596
|
+
id: r.ID,
|
|
597
|
+
status: r.Status,
|
|
598
|
+
prefix: r.Prefix,
|
|
599
|
+
destination: {
|
|
600
|
+
bucket: r.Destination?.Bucket,
|
|
601
|
+
storageClass: r.Destination?.StorageClass,
|
|
602
|
+
},
|
|
603
|
+
})),
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
catch {
|
|
607
|
+
// Replication might not be configured
|
|
608
|
+
}
|
|
609
|
+
// Get server-side encryption configuration
|
|
610
|
+
let sseConfiguration = null;
|
|
611
|
+
try {
|
|
612
|
+
const encryptionResult = await new Promise((resolve, reject) => {
|
|
613
|
+
cosClient.getBucketEncryption({
|
|
614
|
+
Bucket: bucketName,
|
|
615
|
+
Region: region,
|
|
616
|
+
}, (err, data) => {
|
|
617
|
+
if (err) {
|
|
618
|
+
reject(err);
|
|
619
|
+
}
|
|
620
|
+
else {
|
|
621
|
+
resolve(data);
|
|
622
|
+
}
|
|
643
623
|
});
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
return {
|
|
658
|
-
Name: bucketName,
|
|
659
|
-
Location: region,
|
|
660
|
-
CreationDate: creationDate,
|
|
661
|
-
ACL: acl,
|
|
662
|
-
WebsiteConfiguration: websiteConfig,
|
|
663
|
-
AccessControlPolicy: accessControlPolicy,
|
|
664
|
-
CorsConfiguration: corsConfiguration,
|
|
665
|
-
VersioningConfiguration: versioningConfig,
|
|
666
|
-
TaggingConfiguration: taggingConfig,
|
|
667
|
-
Tags: taggingConfig?.tags?.map((t) => ({ Key: t.key ?? '', Value: t.value ?? '' })),
|
|
668
|
-
LifecycleConfiguration: lifecycleConfiguration,
|
|
669
|
-
LoggingConfiguration: loggingConfiguration,
|
|
670
|
-
ReplicationConfiguration: replicationConfiguration,
|
|
671
|
-
SseConfiguration: sseConfiguration,
|
|
672
|
-
Policy: policy,
|
|
624
|
+
});
|
|
625
|
+
const rule = encryptionResult.ServerSideEncryptionConfiguration?.Rule?.[0];
|
|
626
|
+
// SDK quirk: the type declares ApplySideEncryptionConfiguration, but the
|
|
627
|
+
// raw COS API returns ApplyServerSideEncryptionByDefault — read both.
|
|
628
|
+
const apply =
|
|
629
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
630
|
+
rule?.ApplyServerSideEncryptionByDefault ??
|
|
631
|
+
rule?.ApplySideEncryptionConfiguration;
|
|
632
|
+
sseConfiguration = {
|
|
633
|
+
sseAlgorithm: apply?.SSEAlgorithm,
|
|
634
|
+
sseKmsMasterKeyId: apply?.KMSMasterKeyID,
|
|
673
635
|
};
|
|
674
636
|
}
|
|
675
637
|
catch (error) {
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
638
|
+
const code = error?.code;
|
|
639
|
+
if (code !== 'ServerSideEncryptionConfigurationNotFoundError' &&
|
|
640
|
+
code !== 'NoSuchConfiguration')
|
|
641
|
+
throw error;
|
|
642
|
+
}
|
|
643
|
+
// Get bucket policy (cloud-effective, may differ from the definition)
|
|
644
|
+
let policy = null;
|
|
645
|
+
try {
|
|
646
|
+
const policyResult = await new Promise((resolve, reject) => {
|
|
647
|
+
cosClient.getBucketPolicy({
|
|
648
|
+
Bucket: bucketName,
|
|
649
|
+
Region: region,
|
|
650
|
+
}, (err, data) => {
|
|
651
|
+
if (err)
|
|
652
|
+
reject(err);
|
|
653
|
+
else
|
|
654
|
+
resolve(data);
|
|
655
|
+
});
|
|
656
|
+
});
|
|
657
|
+
if (policyResult.Policy) {
|
|
658
|
+
policy =
|
|
659
|
+
typeof policyResult.Policy === 'string'
|
|
660
|
+
? JSON.parse(policyResult.Policy)
|
|
661
|
+
: policyResult.Policy;
|
|
681
662
|
}
|
|
682
|
-
throw error;
|
|
683
663
|
}
|
|
664
|
+
catch (err) {
|
|
665
|
+
const e = err;
|
|
666
|
+
if (e?.code !== 'NoSuchBucketPolicy') {
|
|
667
|
+
throw err;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
return {
|
|
671
|
+
Name: bucketName,
|
|
672
|
+
Location: region,
|
|
673
|
+
CreationDate: creationDate,
|
|
674
|
+
ACL: acl,
|
|
675
|
+
WebsiteConfiguration: websiteConfig,
|
|
676
|
+
AccessControlPolicy: accessControlPolicy,
|
|
677
|
+
CorsConfiguration: corsConfiguration,
|
|
678
|
+
VersioningConfiguration: versioningConfig,
|
|
679
|
+
TaggingConfiguration: taggingConfig,
|
|
680
|
+
Tags: taggingConfig?.tags?.map((t) => ({ Key: t.key ?? '', Value: t.value ?? '' })),
|
|
681
|
+
LifecycleConfiguration: lifecycleConfiguration,
|
|
682
|
+
LoggingConfiguration: loggingConfiguration,
|
|
683
|
+
ReplicationConfiguration: replicationConfiguration,
|
|
684
|
+
SseConfiguration: sseConfiguration,
|
|
685
|
+
Policy: policy,
|
|
686
|
+
};
|
|
684
687
|
},
|
|
685
688
|
updateBucketAcl: async (bucketName, region, acl) => {
|
|
686
689
|
await new Promise((resolve, reject) => {
|
|
@@ -767,7 +770,7 @@ const createCosOperations = (cosClient, region, dnsOps) => {
|
|
|
767
770
|
}
|
|
768
771
|
catch (err) {
|
|
769
772
|
const e = err;
|
|
770
|
-
if (e
|
|
773
|
+
if (e?.code === 'NoSuchBucketPolicy') {
|
|
771
774
|
return null;
|
|
772
775
|
}
|
|
773
776
|
throw err;
|
|
@@ -795,8 +798,9 @@ const createCosOperations = (cosClient, region, dnsOps) => {
|
|
|
795
798
|
});
|
|
796
799
|
logger_1.logger.info(lang_1.lang.__('COS_BUCKET_POLICY_DELETED', { bucketName }));
|
|
797
800
|
}
|
|
798
|
-
catch {
|
|
799
|
-
|
|
801
|
+
catch (error) {
|
|
802
|
+
if (error?.code !== 'NoSuchBucketPolicy')
|
|
803
|
+
throw error;
|
|
800
804
|
}
|
|
801
805
|
},
|
|
802
806
|
};
|