@geek-fun/serverlessinsight 0.8.1 → 0.8.3
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 +14 -0
- package/.serverlessinsight/state-iam-test-app-iam-test-service.json.backup +14 -0
- package/.serverlessinsight/state-insight-poc-deploy-app-insight-poc-deploy.json.backup +348 -0
- package/.serverlessinsight/state-insight-poc-destroy-app-insight-poc-destroy.json.backup +14 -0
- package/.serverlessinsight/state-insight-volc-app-insight-volc.json.backup +114 -0
- package/.serverlessinsight/state-insight-volc-destroy-app-insight-volc-destroy.json.backup +1 -0
- package/README.md +26 -18
- package/README.zh-CN.md +19 -6
- package/dist/package.json +3 -1
- package/dist/src/commands/deploy.js +87 -4
- package/dist/src/commands/destroy.js +61 -10
- package/dist/src/commands/forceUnlock.js +8 -0
- package/dist/src/commands/index.js +34 -2
- package/dist/src/commands/login.js +195 -0
- package/dist/src/commands/logout.js +17 -0
- package/dist/src/commands/show.js +15 -7
- package/dist/src/commands/whoami.js +20 -0
- package/dist/src/common/aliyunClient/apigwOperations.js +332 -32
- package/dist/src/common/aliyunClient/esOperations.js +43 -29
- package/dist/src/common/aliyunClient/fc3Operations.js +481 -207
- package/dist/src/common/aliyunClient/ossOperations.js +165 -13
- package/dist/src/common/aliyunClient/rdsOperations.js +143 -39
- package/dist/src/common/aliyunClient/slsOperations.js +56 -26
- package/dist/src/common/aliyunClient/tablestoreOperations.js +25 -22
- package/dist/src/common/apiClient.js +102 -0
- package/dist/src/common/constants.js +9 -4
- package/dist/src/common/credentialStore.js +94 -0
- package/dist/src/common/credentials.js +2 -0
- package/dist/src/common/eventQueue.js +208 -0
- package/dist/src/common/hashUtils.js +87 -11
- package/dist/src/common/imsClient.js +1 -0
- package/dist/src/common/index.js +3 -0
- package/dist/src/common/lockManager.js +61 -54
- package/dist/src/common/logger.js +2 -0
- package/dist/src/common/polling.js +54 -0
- package/dist/src/common/reportResourceEvent.js +8 -0
- package/dist/src/common/runtimeMapper.js +11 -12
- package/dist/src/common/stateBackend/index.js +10 -1
- package/dist/src/common/stateBackend/localStateBackend.js +4 -1
- package/dist/src/common/stateBackend/remoteStateBackend.js +6 -3
- package/dist/src/common/stateBackend/saasStateBackend.js +266 -0
- package/dist/src/common/stateManager.js +135 -13
- package/dist/src/common/tencentClient/cosOperations.js +180 -3
- package/dist/src/common/tencentClient/esOperations.js +110 -46
- package/dist/src/common/tencentClient/index.js +22 -1
- package/dist/src/common/tencentClient/scfOperations.js +255 -133
- package/dist/src/common/tencentClient/tdsqlcClusterMapper.js +81 -0
- package/dist/src/common/tencentClient/tdsqlcOperations.js +93 -99
- package/dist/src/common/triggerMapper.js +36 -0
- package/dist/src/common/volcengineClient/apigwOperations.js +539 -159
- package/dist/src/common/volcengineClient/iamOperations.js +58 -48
- package/dist/src/common/volcengineClient/index.js +46 -21
- package/dist/src/common/volcengineClient/stsOperations.js +32 -0
- package/dist/src/common/volcengineClient/tlsOperations.js +229 -178
- package/dist/src/common/volcengineClient/tosOperations.js +78 -19
- package/dist/src/common/volcengineClient/vefaasOperations.js +272 -54
- package/dist/src/lang/en.js +84 -0
- package/dist/src/lang/zh-CN.js +84 -0
- package/dist/src/parser/eventParser.js +2 -0
- package/dist/src/parser/functionParser.js +96 -65
- package/dist/src/parser/index.js +7 -4
- package/dist/src/stack/aliyunStack/apigwExecutor.js +39 -1
- package/dist/src/stack/aliyunStack/apigwPlanner.js +14 -10
- package/dist/src/stack/aliyunStack/apigwResource.js +230 -125
- package/dist/src/stack/aliyunStack/apigwTypes.js +16 -3
- package/dist/src/stack/aliyunStack/databaseExecutor.js +39 -1
- package/dist/src/stack/aliyunStack/databasePlanner.js +13 -1
- package/dist/src/stack/aliyunStack/databaseResource.js +135 -40
- package/dist/src/stack/aliyunStack/deployer.js +2 -2
- package/dist/src/stack/aliyunStack/destroyer.js +2 -2
- package/dist/src/stack/aliyunStack/fc3Executor.js +25 -2
- package/dist/src/stack/aliyunStack/fc3Planner.js +11 -1
- package/dist/src/stack/aliyunStack/fc3Resource.js +327 -64
- package/dist/src/stack/aliyunStack/ossExecutor.js +39 -1
- package/dist/src/stack/aliyunStack/ossPlanner.js +15 -1
- package/dist/src/stack/aliyunStack/ossResource.js +267 -219
- package/dist/src/stack/aliyunStack/tablestoreExecutor.js +39 -1
- package/dist/src/stack/aliyunStack/tablestorePlanner.js +13 -1
- package/dist/src/stack/aliyunStack/tablestoreResource.js +54 -20
- package/dist/src/stack/alreadyExists.js +26 -0
- package/dist/src/stack/ownershipTag.js +40 -0
- package/dist/src/stack/rfsStack/index.js +3 -1
- package/dist/src/stack/scfStack/cosExecutor.js +39 -1
- package/dist/src/stack/scfStack/cosPlanner.js +11 -1
- package/dist/src/stack/scfStack/cosResource.js +167 -64
- package/dist/src/stack/scfStack/deployer.js +2 -2
- package/dist/src/stack/scfStack/destroyer.js +2 -2
- package/dist/src/stack/scfStack/esServerlessExecutor.js +39 -1
- package/dist/src/stack/scfStack/esServerlessPlanner.js +11 -1
- package/dist/src/stack/scfStack/esServerlessResource.js +88 -23
- package/dist/src/stack/scfStack/scfExecutor.js +39 -1
- package/dist/src/stack/scfStack/scfPlanner.js +12 -2
- package/dist/src/stack/scfStack/scfResource.js +484 -14
- package/dist/src/stack/scfStack/tdsqlcExecutor.js +39 -1
- package/dist/src/stack/scfStack/tdsqlcPlanner.js +12 -1
- package/dist/src/stack/scfStack/tdsqlcResource.js +95 -16
- package/dist/src/stack/scfStack/tdsqlcTypes.js +5 -1
- package/dist/src/stack/volcengineStack/apigwExecutor.js +39 -1
- package/dist/src/stack/volcengineStack/apigwPlanner.js +25 -53
- package/dist/src/stack/volcengineStack/apigwResource.js +418 -222
- package/dist/src/stack/volcengineStack/apigwTypes.js +76 -66
- package/dist/src/stack/volcengineStack/deployer.js +49 -14
- package/dist/src/stack/volcengineStack/destroyer.js +1 -1
- package/dist/src/stack/volcengineStack/index.js +1 -2
- package/dist/src/stack/volcengineStack/tosExecutor.js +25 -2
- package/dist/src/stack/volcengineStack/tosPlanner.js +11 -1
- package/dist/src/stack/volcengineStack/tosResource.js +82 -27
- package/dist/src/stack/volcengineStack/tosTypes.js +12 -0
- package/dist/src/stack/volcengineStack/vefaasExecutor.js +25 -2
- package/dist/src/stack/volcengineStack/vefaasPlanner.js +71 -2
- package/dist/src/stack/volcengineStack/vefaasResource.js +148 -98
- package/dist/src/stack/volcengineStack/vefaasTypes.js +1 -3
- package/dist/src/types/domains/backend.js +1 -0
- package/dist/src/types/domains/state.js +29 -1
- package/dist/src/validator/eventSchema.js +10 -0
- package/dist/src/validator/functionSchema.js +37 -12
- package/dist/src/validator/iacSchema.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -1
|
@@ -13,6 +13,8 @@ const types_1 = require("../../types");
|
|
|
13
13
|
const fc3Types_1 = require("./fc3Types");
|
|
14
14
|
const logger_1 = require("../../common/logger");
|
|
15
15
|
const lang_1 = require("../../lang");
|
|
16
|
+
const ownershipTag_1 = require("../ownershipTag");
|
|
17
|
+
const alreadyExists_1 = require("../alreadyExists");
|
|
16
18
|
const RECOVERY_GET_FUNCTION_DELAY_MS = 1500;
|
|
17
19
|
const delay = async (ms) => {
|
|
18
20
|
await new Promise((resolve) => {
|
|
@@ -51,7 +53,7 @@ const ensureOssCodeUpload = async (client, codePath, region, functionName) => {
|
|
|
51
53
|
logger_1.logger.info(lang_1.lang.__('CREATING_BOOTSTRAP_BUCKET', { bucketName }));
|
|
52
54
|
await client.oss.createBucket({ bucketName });
|
|
53
55
|
}
|
|
54
|
-
const codeHash = (0, common_1.
|
|
56
|
+
const codeHash = await (0, common_1.computeZipContentHash)(codePath);
|
|
55
57
|
const ossObjectName = `fc3-code/${functionName}/${codeHash}.zip`;
|
|
56
58
|
await client.oss.putFile(bucketName, ossObjectName, codePath);
|
|
57
59
|
logger_1.logger.info(lang_1.lang.__('UPLOADED_CODE_TO_OSS', { bucketName, objectName: ossObjectName }));
|
|
@@ -63,6 +65,7 @@ const buildFc3InstanceFromProvider = (info, sid) => {
|
|
|
63
65
|
sid,
|
|
64
66
|
id: info.functionName ?? '',
|
|
65
67
|
functionName: info.functionName ?? null,
|
|
68
|
+
functionArn: info.functionArn ?? null,
|
|
66
69
|
functionId: info.functionId ?? null,
|
|
67
70
|
runtime: info.runtime ?? null,
|
|
68
71
|
handler: info.handler ?? null,
|
|
@@ -126,6 +129,19 @@ const buildFc3InstanceFromProvider = (info, sid) => {
|
|
|
126
129
|
lastUpdateStatus: info.lastUpdateStatus ?? null,
|
|
127
130
|
lastUpdateStatusReason: info.lastUpdateStatusReason ?? null,
|
|
128
131
|
lastUpdateStatusReasonCode: info.lastUpdateStatusReasonCode ?? null,
|
|
132
|
+
tags: info.tags?.map((tag) => ({
|
|
133
|
+
key: tag.Key ?? null,
|
|
134
|
+
value: tag.Value ?? null,
|
|
135
|
+
})),
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
const buildHttpTriggerConfig = (trigger) => {
|
|
139
|
+
const authType = (0, common_1.mapAuthType)(common_1.ProviderEnum.ALIYUN, trigger.auth_type);
|
|
140
|
+
const { disableURLInternet } = (0, common_1.mapAliyunAccess)(trigger.access);
|
|
141
|
+
return {
|
|
142
|
+
authType,
|
|
143
|
+
methods: ['GET', 'POST', 'PUT', 'DELETE', 'HEAD', 'PATCH'],
|
|
144
|
+
...(disableURLInternet !== undefined ? { disableURLInternet } : {}),
|
|
129
145
|
};
|
|
130
146
|
};
|
|
131
147
|
const createDependentResources = async (context, fn, serviceName, existingInstances = []) => {
|
|
@@ -309,61 +325,61 @@ const createDependentResources = async (context, fn, serviceName, existingInstan
|
|
|
309
325
|
const deleteDependentResources = async (context, instances) => {
|
|
310
326
|
const client = (0, aliyunClient_1.createAliyunClient)(context);
|
|
311
327
|
for (const instance of [...instances].reverse()) {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
break;
|
|
319
|
-
}
|
|
320
|
-
case 'ALIYUN_NAS_FILE_SYSTEM':
|
|
321
|
-
logger_1.logger.info(lang_1.lang.__('DELETING_NAS_FILE_SYSTEM', { id: instance.id }));
|
|
322
|
-
await client.nas.deleteFileSystem(instance.id);
|
|
323
|
-
break;
|
|
324
|
-
case 'ALIYUN_NAS_ACCESS_GROUP':
|
|
325
|
-
logger_1.logger.info(lang_1.lang.__('DELETING_NAS_ACCESS_GROUP', { id: instance.id }));
|
|
326
|
-
await client.nas.deleteAccessGroup(instance.id);
|
|
327
|
-
break;
|
|
328
|
-
case 'ALIYUN_ECS_SECURITY_GROUP':
|
|
329
|
-
logger_1.logger.info(lang_1.lang.__('DELETING_SECURITY_GROUP', { id: instance.id }));
|
|
330
|
-
await client.ecs.deleteSecurityGroup(instance.id);
|
|
331
|
-
break;
|
|
332
|
-
case 'ALIYUN_RAM_ROLE': {
|
|
333
|
-
const ramInstance = instance;
|
|
334
|
-
if (ramInstance.external)
|
|
335
|
-
break; // Skip external roles
|
|
336
|
-
const managedPolicies = ramInstance.managedPolicies;
|
|
337
|
-
logger_1.logger.info(lang_1.lang.__('DELETING_RAM_ROLE', { id: instance.id }));
|
|
338
|
-
await client.ram.deleteRole(instance.id, managedPolicies);
|
|
339
|
-
break;
|
|
340
|
-
}
|
|
341
|
-
case 'ALIYUN_SLS_INDEX': {
|
|
342
|
-
const [projectName, logstoreName] = instance.id.split('/');
|
|
343
|
-
logger_1.logger.info(lang_1.lang.__('DELETING_SLS_INDEX', { id: instance.id }));
|
|
344
|
-
await client.sls.deleteIndex(projectName, logstoreName);
|
|
345
|
-
break;
|
|
346
|
-
}
|
|
347
|
-
case 'ALIYUN_SLS_LOGSTORE': {
|
|
348
|
-
const [projectName, logstoreName] = instance.id.split('/');
|
|
349
|
-
logger_1.logger.info(lang_1.lang.__('DELETING_SLS_LOGSTORE', { id: instance.id }));
|
|
350
|
-
await client.sls.deleteLogstore(projectName, logstoreName);
|
|
351
|
-
break;
|
|
352
|
-
}
|
|
353
|
-
case 'ALIYUN_SLS_PROJECT':
|
|
354
|
-
logger_1.logger.info(lang_1.lang.__('DELETING_SLS_PROJECT', { id: instance.id }));
|
|
355
|
-
await client.sls.deleteProject(instance.id);
|
|
356
|
-
break;
|
|
357
|
-
default:
|
|
358
|
-
logger_1.logger.warn(lang_1.lang.__('UNKNOWN_RESOURCE_TYPE', { type: instance.type }));
|
|
328
|
+
switch (instance.type) {
|
|
329
|
+
case 'ALIYUN_NAS_MOUNT_TARGET': {
|
|
330
|
+
const [fileSystemId, mountTargetDomain] = instance.id.split('/');
|
|
331
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_NAS_MOUNT_TARGET', { id: instance.id }));
|
|
332
|
+
await client.nas.deleteMountTarget(fileSystemId, mountTargetDomain);
|
|
333
|
+
break;
|
|
359
334
|
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
335
|
+
case 'ALIYUN_NAS_FILE_SYSTEM':
|
|
336
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_NAS_FILE_SYSTEM', { id: instance.id }));
|
|
337
|
+
await client.nas.deleteFileSystem(instance.id);
|
|
338
|
+
break;
|
|
339
|
+
case 'ALIYUN_NAS_ACCESS_GROUP':
|
|
340
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_NAS_ACCESS_GROUP', { id: instance.id }));
|
|
341
|
+
await client.nas.deleteAccessGroup(instance.id);
|
|
342
|
+
break;
|
|
343
|
+
case 'ALIYUN_ECS_SECURITY_GROUP':
|
|
344
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_SECURITY_GROUP', { id: instance.id }));
|
|
345
|
+
await client.ecs.deleteSecurityGroup(instance.id);
|
|
346
|
+
break;
|
|
347
|
+
case 'ALIYUN_RAM_ROLE': {
|
|
348
|
+
const ramInstance = instance;
|
|
349
|
+
if (ramInstance.external)
|
|
350
|
+
break; // Skip external roles
|
|
351
|
+
const managedPolicies = ramInstance.managedPolicies;
|
|
352
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_RAM_ROLE', { id: instance.id }));
|
|
353
|
+
await client.ram.deleteRole(instance.id, managedPolicies);
|
|
354
|
+
break;
|
|
355
|
+
}
|
|
356
|
+
case 'ALIYUN_SLS_INDEX': {
|
|
357
|
+
const [projectName, logstoreName] = instance.id.split('/');
|
|
358
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_SLS_INDEX', { id: instance.id }));
|
|
359
|
+
await client.sls.deleteIndex(projectName, logstoreName);
|
|
360
|
+
break;
|
|
361
|
+
}
|
|
362
|
+
case 'ALIYUN_SLS_LOGSTORE': {
|
|
363
|
+
const [projectName, logstoreName] = instance.id.split('/');
|
|
364
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_SLS_LOGSTORE', { id: instance.id }));
|
|
365
|
+
await client.sls.deleteLogstore(projectName, logstoreName);
|
|
366
|
+
break;
|
|
367
|
+
}
|
|
368
|
+
case 'ALIYUN_SLS_PROJECT':
|
|
369
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_SLS_PROJECT', { id: instance.id }));
|
|
370
|
+
await client.sls.deleteProject(instance.id);
|
|
371
|
+
break;
|
|
372
|
+
case 'ALIYUN_FC3_HTTP_TRIGGER':
|
|
373
|
+
// HTTP trigger deletion requires functionName which is not available here.
|
|
374
|
+
// It is handled directly in deleteResource before calling this function.
|
|
375
|
+
logger_1.logger.warn(`HTTP trigger '${instance.id}' should be deleted before reaching dependent resource cleanup`);
|
|
376
|
+
break;
|
|
377
|
+
case 'ALIYUN_FC3_CUSTOM_DOMAIN':
|
|
378
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_CUSTOM_DOMAIN', { domainName: instance.id }));
|
|
379
|
+
await client.fc3.deleteCustomDomain(instance.id);
|
|
380
|
+
break;
|
|
381
|
+
default:
|
|
382
|
+
logger_1.logger.warn(lang_1.lang.__('UNKNOWN_RESOURCE_TYPE', { type: instance.type }));
|
|
367
383
|
}
|
|
368
384
|
}
|
|
369
385
|
};
|
|
@@ -375,6 +391,10 @@ const createResource = async (context, fn, state) => {
|
|
|
375
391
|
const existingDependentInstances = (existingResourceState?.instances ?? []).filter((i) => i.type !== 'ALIYUN_FC3_FUNCTION');
|
|
376
392
|
const dependentResources = await createDependentResources(context, fn, serviceName, existingDependentInstances);
|
|
377
393
|
let config = (0, fc3Types_1.functionToFc3Config)(fn);
|
|
394
|
+
config = {
|
|
395
|
+
...config,
|
|
396
|
+
tags: [{ key: ownershipTag_1.OWNERSHIP_TAG_KEY, value: (0, ownershipTag_1.buildOwnershipTagValue)(context, logicalId) }],
|
|
397
|
+
};
|
|
378
398
|
if (dependentResources.logConfig) {
|
|
379
399
|
config = {
|
|
380
400
|
...config,
|
|
@@ -416,7 +436,7 @@ const createResource = async (context, fn, state) => {
|
|
|
416
436
|
};
|
|
417
437
|
}
|
|
418
438
|
const codePath = fn.code.path;
|
|
419
|
-
const codeHash = (0, common_1.
|
|
439
|
+
const codeHash = await (0, common_1.computeZipContentHash)(codePath);
|
|
420
440
|
const baseDefinition = (0, fc3Types_1.extractFc3Definition)(config, codeHash);
|
|
421
441
|
const definition = fn.iam ? { ...baseDefinition, iam: fn.iam } : baseDefinition;
|
|
422
442
|
const dependentInstances = dependentResources.instances.map((dep) => ({
|
|
@@ -454,12 +474,18 @@ const createResource = async (context, fn, state) => {
|
|
|
454
474
|
logger_1.logger.warn(`Create function returned recoverable error for ${fn.name}, reconciling with provider state: ${String(error)}`);
|
|
455
475
|
const functionAfterError = await client.fc3.getFunction(fn.name);
|
|
456
476
|
if (functionAfterError) {
|
|
477
|
+
if (functionAfterError.state === 'Failed') {
|
|
478
|
+
throw new types_1.PartialResourceError(stateAfterDependents, new Error(`FC3 function ${fn.name} is in Failed state after create (reason: ${functionAfterError.stateReason ?? 'unknown'})`));
|
|
479
|
+
}
|
|
457
480
|
logger_1.logger.info(`Function ${fn.name} found after create error reconciliation, continuing deployment flow`);
|
|
458
481
|
}
|
|
459
482
|
else {
|
|
460
483
|
await delay(RECOVERY_GET_FUNCTION_DELAY_MS);
|
|
461
484
|
const functionAfterDelay = await client.fc3.getFunction(fn.name);
|
|
462
485
|
if (functionAfterDelay) {
|
|
486
|
+
if (functionAfterDelay.state === 'Failed') {
|
|
487
|
+
throw new types_1.PartialResourceError(stateAfterDependents, new Error(`FC3 function ${fn.name} is in Failed state after create (reason: ${functionAfterDelay.stateReason ?? 'unknown'})`));
|
|
488
|
+
}
|
|
463
489
|
logger_1.logger.info(`Function ${fn.name} found after delayed reconciliation, continuing deployment flow`);
|
|
464
490
|
}
|
|
465
491
|
else {
|
|
@@ -467,21 +493,87 @@ const createResource = async (context, fn, state) => {
|
|
|
467
493
|
}
|
|
468
494
|
}
|
|
469
495
|
}
|
|
496
|
+
else if ((0, alreadyExists_1.isResourceAlreadyExistsError)(error, ['FunctionAlreadyExists'])) {
|
|
497
|
+
// Idempotent adoption: the function already exists in the provider.
|
|
498
|
+
// Adopt it ONLY if it carries our ownership tag (proves a previous run
|
|
499
|
+
// of THIS stack created it — e.g. state was reset). An untagged
|
|
500
|
+
// same-named function may belong to another project, so it must fail
|
|
501
|
+
// loudly rather than silently taking it over (destroy would then remove
|
|
502
|
+
// a resource that was never ours).
|
|
503
|
+
const probe = await client.fc3.getFunction(fn.name);
|
|
504
|
+
if (probe && (0, ownershipTag_1.isOwnedByStack)(context, logicalId, probe.tags)) {
|
|
505
|
+
logger_1.logger.info(`Function ${fn.name} exists and carries ownership tag (${ownershipTag_1.OWNERSHIP_TAG_KEY}), adopting idempotently`);
|
|
506
|
+
}
|
|
507
|
+
else {
|
|
508
|
+
throw new types_1.PartialResourceError(stateAfterDependents, new Error(`Function ${fn.name} already exists in provider but is not owned by this stack (missing ${ownershipTag_1.OWNERSHIP_TAG_KEY} tag). Refusing to adopt — resolve manually.`));
|
|
509
|
+
}
|
|
510
|
+
}
|
|
470
511
|
else {
|
|
471
512
|
throw new types_1.PartialResourceError(stateAfterDependents, error instanceof Error ? error : new Error(String(error)));
|
|
472
513
|
}
|
|
473
514
|
}
|
|
474
|
-
|
|
515
|
+
let functionInfo;
|
|
516
|
+
try {
|
|
517
|
+
functionInfo = await client.fc3.getFunction(fn.name);
|
|
518
|
+
}
|
|
519
|
+
catch (error) {
|
|
520
|
+
throw new types_1.PartialResourceError(stateAfterDependents, error instanceof Error ? error : new Error(String(error)));
|
|
521
|
+
}
|
|
475
522
|
if (!functionInfo) {
|
|
476
|
-
throw new Error(`Failed to refresh state for function: ${fn.name}`);
|
|
523
|
+
throw new types_1.PartialResourceError(stateAfterDependents, new Error(`Failed to refresh state for function: ${fn.name}`));
|
|
524
|
+
}
|
|
525
|
+
if (functionInfo.state === 'Failed') {
|
|
526
|
+
throw new types_1.PartialResourceError(stateAfterDependents, new Error(`FC3 function ${fn.name} is in Failed state (reason: ${functionInfo.stateReason ?? 'unknown'})`));
|
|
477
527
|
}
|
|
478
528
|
const sid = (0, common_1.buildSid)('aliyun', 'fc3', context.stage, fn.name);
|
|
479
529
|
const fcInstance = buildFc3InstanceFromProvider(functionInfo, sid);
|
|
530
|
+
const lifecycleInstances = [];
|
|
531
|
+
try {
|
|
532
|
+
if (fn.triggers?.http) {
|
|
533
|
+
const triggerConfig = buildHttpTriggerConfig(fn.triggers.http);
|
|
534
|
+
logger_1.logger.info(lang_1.lang.__('CREATING_HTTP_TRIGGER', { triggerName: 'http-trigger', functionName: fn.name }));
|
|
535
|
+
await client.fc3.createTrigger(fn.name, 'http-trigger', 'http', triggerConfig);
|
|
536
|
+
logger_1.logger.info(lang_1.lang.__('HTTP_TRIGGER_CREATED', { triggerName: 'http-trigger', functionName: fn.name }));
|
|
537
|
+
lifecycleInstances.push({
|
|
538
|
+
type: 'ALIYUN_FC3_HTTP_TRIGGER',
|
|
539
|
+
id: 'http-trigger',
|
|
540
|
+
sid: (0, common_1.buildSid)('aliyun', 'fc3-http-trigger', context.stage, fn.name),
|
|
541
|
+
attributes: { ...triggerConfig },
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
if (fn.domain) {
|
|
545
|
+
logger_1.logger.info(lang_1.lang.__('CREATING_CUSTOM_DOMAIN', { domainName: fn.domain.domain_name }));
|
|
546
|
+
let certConfig;
|
|
547
|
+
if (fn.domain.certificate_id) {
|
|
548
|
+
const certId = fn.domain.certificate_id;
|
|
549
|
+
const detail = await client.cas.getCertificate(certId);
|
|
550
|
+
if (!detail || !detail.cert || !detail.key) {
|
|
551
|
+
throw new Error(lang_1.lang.__('CERT_REFERENCE_NOT_FOUND', { reference: certId }));
|
|
552
|
+
}
|
|
553
|
+
certConfig = {
|
|
554
|
+
certName: `${context.service}-${context.stage}-fc3-domain`,
|
|
555
|
+
certificate: detail.cert,
|
|
556
|
+
privateKey: detail.key,
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
await client.fc3.createCustomDomain(fn.domain.domain_name, fn.domain.protocol, fn.name, certConfig);
|
|
560
|
+
logger_1.logger.info(lang_1.lang.__('CUSTOM_DOMAIN_CREATED', { domainName: fn.domain.domain_name }));
|
|
561
|
+
lifecycleInstances.push({
|
|
562
|
+
type: 'ALIYUN_FC3_CUSTOM_DOMAIN',
|
|
563
|
+
id: fn.domain.domain_name,
|
|
564
|
+
sid: (0, common_1.buildSid)('aliyun', 'fc3-custom-domain', context.stage, fn.domain.domain_name),
|
|
565
|
+
attributes: { protocol: fn.domain.protocol, certificate_id: fn.domain.certificate_id },
|
|
566
|
+
});
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
catch (error) {
|
|
570
|
+
throw new types_1.PartialResourceError(stateAfterDependents, error instanceof Error ? error : new Error(String(error)));
|
|
571
|
+
}
|
|
480
572
|
const resourceState = {
|
|
481
573
|
mode: 'managed',
|
|
482
574
|
region: context.region,
|
|
483
575
|
definition,
|
|
484
|
-
instances: [fcInstance, ...dependentInstances],
|
|
576
|
+
instances: [fcInstance, ...lifecycleInstances, ...dependentInstances],
|
|
485
577
|
lastUpdated: new Date().toISOString(),
|
|
486
578
|
status: 'ready',
|
|
487
579
|
};
|
|
@@ -635,7 +727,7 @@ const updateResource = async (context, fn, state) => {
|
|
|
635
727
|
}
|
|
636
728
|
const codePath = fn.code.path;
|
|
637
729
|
const currentCodeHash = existingState?.definition?.codeHash;
|
|
638
|
-
const desiredCodeHash = (0, common_1.
|
|
730
|
+
const desiredCodeHash = await (0, common_1.computeZipContentHash)(codePath);
|
|
639
731
|
const codeChanged = currentCodeHash !== desiredCodeHash;
|
|
640
732
|
const existingConfig = existingState?.definition;
|
|
641
733
|
const desiredDefinition = (0, fc3Types_1.extractFc3Definition)(config, desiredCodeHash);
|
|
@@ -652,17 +744,142 @@ const updateResource = async (context, fn, state) => {
|
|
|
652
744
|
if (!configChanged && !codeChanged) {
|
|
653
745
|
logger_1.logger.warn(lang_1.lang.__('UPDATING_RESOURCE_WITH_NO_CHANGES', { resourceType: 'function', name: fn.name }));
|
|
654
746
|
}
|
|
747
|
+
const existingHttpTrigger = existingInstances.find((i) => i.type === 'ALIYUN_FC3_HTTP_TRIGGER');
|
|
748
|
+
const desiredHttpTrigger = fn.triggers?.http;
|
|
749
|
+
if (desiredHttpTrigger && !existingHttpTrigger) {
|
|
750
|
+
const triggerConfig = buildHttpTriggerConfig(desiredHttpTrigger);
|
|
751
|
+
logger_1.logger.info(lang_1.lang.__('CREATING_HTTP_TRIGGER', { triggerName: 'http-trigger', functionName: fn.name }));
|
|
752
|
+
await client.fc3.createTrigger(fn.name, 'http-trigger', 'http', triggerConfig);
|
|
753
|
+
logger_1.logger.info(lang_1.lang.__('HTTP_TRIGGER_CREATED', { triggerName: 'http-trigger', functionName: fn.name }));
|
|
754
|
+
}
|
|
755
|
+
else if (!desiredHttpTrigger && existingHttpTrigger) {
|
|
756
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_HTTP_TRIGGER', { triggerName: 'http-trigger', functionName: fn.name }));
|
|
757
|
+
try {
|
|
758
|
+
await client.fc3.deleteTrigger(fn.name, 'http-trigger');
|
|
759
|
+
logger_1.logger.info(lang_1.lang.__('HTTP_TRIGGER_DELETED', { triggerName: 'http-trigger' }));
|
|
760
|
+
}
|
|
761
|
+
catch (err) {
|
|
762
|
+
const errorCode = err?.code;
|
|
763
|
+
if (errorCode !== 'TriggerNotFound')
|
|
764
|
+
throw err;
|
|
765
|
+
logger_1.logger.warn(lang_1.lang.__('HTTP_TRIGGER_NOT_FOUND', { triggerName: 'http-trigger' }));
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
else if (desiredHttpTrigger && existingHttpTrigger) {
|
|
769
|
+
const desiredTriggerConfig = buildHttpTriggerConfig(desiredHttpTrigger);
|
|
770
|
+
const existingAttrs = existingHttpTrigger.attributes ?? {};
|
|
771
|
+
if (!(0, common_1.attributesEqual)(desiredTriggerConfig, existingAttrs)) {
|
|
772
|
+
logger_1.logger.info(lang_1.lang.__('UPDATING_HTTP_TRIGGER', { functionName: fn.name }));
|
|
773
|
+
try {
|
|
774
|
+
await client.fc3.deleteTrigger(fn.name, 'http-trigger');
|
|
775
|
+
}
|
|
776
|
+
catch (err) {
|
|
777
|
+
const errorCode = err?.code;
|
|
778
|
+
if (errorCode !== 'TriggerNotFound')
|
|
779
|
+
throw err;
|
|
780
|
+
}
|
|
781
|
+
await client.fc3.createTrigger(fn.name, 'http-trigger', 'http', desiredTriggerConfig);
|
|
782
|
+
logger_1.logger.info(lang_1.lang.__('HTTP_TRIGGER_CREATED', { triggerName: 'http-trigger', functionName: fn.name }));
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
const existingCustomDomain = existingInstances.find((i) => i.type === 'ALIYUN_FC3_CUSTOM_DOMAIN');
|
|
786
|
+
const desiredDomain = fn.domain;
|
|
787
|
+
if (desiredDomain && !existingCustomDomain) {
|
|
788
|
+
logger_1.logger.info(lang_1.lang.__('CREATING_CUSTOM_DOMAIN', { domainName: desiredDomain.domain_name }));
|
|
789
|
+
let certConfig;
|
|
790
|
+
if (desiredDomain.certificate_id) {
|
|
791
|
+
const certId = desiredDomain.certificate_id;
|
|
792
|
+
const detail = await client.cas.getCertificate(certId);
|
|
793
|
+
if (!detail || !detail.cert || !detail.key) {
|
|
794
|
+
throw new Error(lang_1.lang.__('CERT_REFERENCE_NOT_FOUND', { reference: certId }));
|
|
795
|
+
}
|
|
796
|
+
certConfig = {
|
|
797
|
+
certName: `${context.service}-${context.stage}-fc3-domain`,
|
|
798
|
+
certificate: detail.cert,
|
|
799
|
+
privateKey: detail.key,
|
|
800
|
+
};
|
|
801
|
+
}
|
|
802
|
+
await client.fc3.createCustomDomain(desiredDomain.domain_name, desiredDomain.protocol, fn.name, certConfig);
|
|
803
|
+
logger_1.logger.info(lang_1.lang.__('CUSTOM_DOMAIN_CREATED', { domainName: desiredDomain.domain_name }));
|
|
804
|
+
}
|
|
805
|
+
else if (!desiredDomain && existingCustomDomain) {
|
|
806
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_CUSTOM_DOMAIN', { domainName: existingCustomDomain.id }));
|
|
807
|
+
try {
|
|
808
|
+
await client.fc3.deleteCustomDomain(existingCustomDomain.id);
|
|
809
|
+
logger_1.logger.info(lang_1.lang.__('CUSTOM_DOMAIN_DELETED', { domainName: existingCustomDomain.id }));
|
|
810
|
+
}
|
|
811
|
+
catch (err) {
|
|
812
|
+
const errorCode = err?.code;
|
|
813
|
+
if (errorCode !== 'CustomDomainNotFound')
|
|
814
|
+
throw err;
|
|
815
|
+
logger_1.logger.warn(lang_1.lang.__('RESOURCE_NOT_FOUND_PROVIDER', {
|
|
816
|
+
resourceType: 'Custom Domain',
|
|
817
|
+
name: existingCustomDomain.id,
|
|
818
|
+
}));
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
else if (desiredDomain && existingCustomDomain) {
|
|
822
|
+
const existingProtocol = existingCustomDomain.attributes?.protocol;
|
|
823
|
+
const domainChanged = desiredDomain.domain_name !== existingCustomDomain.id ||
|
|
824
|
+
desiredDomain.protocol !== existingProtocol;
|
|
825
|
+
if (domainChanged) {
|
|
826
|
+
logger_1.logger.info(lang_1.lang.__('UPDATING_CUSTOM_DOMAIN', { domainName: desiredDomain.domain_name }));
|
|
827
|
+
let certConfig;
|
|
828
|
+
if (desiredDomain.certificate_id) {
|
|
829
|
+
const certId = desiredDomain.certificate_id;
|
|
830
|
+
const detail = await client.cas.getCertificate(certId);
|
|
831
|
+
if (!detail || !detail.cert || !detail.key) {
|
|
832
|
+
throw new Error(lang_1.lang.__('CERT_REFERENCE_NOT_FOUND', { reference: certId }));
|
|
833
|
+
}
|
|
834
|
+
certConfig = {
|
|
835
|
+
certName: `${context.service}-${context.stage}-fc3-domain`,
|
|
836
|
+
certificate: detail.cert,
|
|
837
|
+
privateKey: detail.key,
|
|
838
|
+
};
|
|
839
|
+
}
|
|
840
|
+
try {
|
|
841
|
+
await client.fc3.deleteCustomDomain(existingCustomDomain.id);
|
|
842
|
+
}
|
|
843
|
+
catch (err) {
|
|
844
|
+
const errorCode = err?.code;
|
|
845
|
+
if (errorCode !== 'CustomDomainNotFound')
|
|
846
|
+
throw err;
|
|
847
|
+
}
|
|
848
|
+
await client.fc3.createCustomDomain(desiredDomain.domain_name, desiredDomain.protocol, fn.name, certConfig);
|
|
849
|
+
logger_1.logger.info(lang_1.lang.__('CUSTOM_DOMAIN_CREATED', { domainName: desiredDomain.domain_name }));
|
|
850
|
+
}
|
|
851
|
+
}
|
|
655
852
|
const functionInfo = await client.fc3.getFunction(fn.name);
|
|
656
853
|
if (!functionInfo) {
|
|
657
854
|
throw new Error(`Failed to refresh state for function: ${fn.name}`);
|
|
658
855
|
}
|
|
659
|
-
const codeHash = (0, common_1.
|
|
856
|
+
const codeHash = await (0, common_1.computeZipContentHash)(codePath);
|
|
660
857
|
const baseDefinition = (0, fc3Types_1.extractFc3Definition)(config, codeHash);
|
|
661
858
|
const definition = fn.iam ? { ...baseDefinition, iam: fn.iam } : baseDefinition;
|
|
662
859
|
const sid = (0, common_1.buildSid)('aliyun', 'fc3', context.stage, fn.name);
|
|
663
860
|
const fcInstance = buildFc3InstanceFromProvider(functionInfo, sid);
|
|
861
|
+
const lifecycleInstances = [];
|
|
862
|
+
if (fn.triggers?.http) {
|
|
863
|
+
const triggerConfig = buildHttpTriggerConfig(fn.triggers.http);
|
|
864
|
+
lifecycleInstances.push({
|
|
865
|
+
type: 'ALIYUN_FC3_HTTP_TRIGGER',
|
|
866
|
+
id: 'http-trigger',
|
|
867
|
+
sid: (0, common_1.buildSid)('aliyun', 'fc3-http-trigger', context.stage, fn.name),
|
|
868
|
+
attributes: { ...triggerConfig },
|
|
869
|
+
});
|
|
870
|
+
}
|
|
871
|
+
if (fn.domain) {
|
|
872
|
+
lifecycleInstances.push({
|
|
873
|
+
type: 'ALIYUN_FC3_CUSTOM_DOMAIN',
|
|
874
|
+
id: fn.domain.domain_name,
|
|
875
|
+
sid: (0, common_1.buildSid)('aliyun', 'fc3-custom-domain', context.stage, fn.domain.domain_name),
|
|
876
|
+
attributes: { protocol: fn.domain.protocol },
|
|
877
|
+
});
|
|
878
|
+
}
|
|
664
879
|
const existingDependentInstances = existingInstances
|
|
665
880
|
.filter((i) => i.type !== 'ALIYUN_FC3_FUNCTION')
|
|
881
|
+
.filter((i) => i.type !== 'ALIYUN_FC3_HTTP_TRIGGER')
|
|
882
|
+
.filter((i) => i.type !== 'ALIYUN_FC3_CUSTOM_DOMAIN')
|
|
666
883
|
.filter((i) => !(typeof fn.iam?.role === 'string' && i.type === 'ALIYUN_RAM_ROLE'))
|
|
667
884
|
.map((i) => {
|
|
668
885
|
const { sid: existingSid, id: existingId, ...rest } = i;
|
|
@@ -686,7 +903,12 @@ const updateResource = async (context, fn, state) => {
|
|
|
686
903
|
mode: 'managed',
|
|
687
904
|
region: context.region,
|
|
688
905
|
definition,
|
|
689
|
-
instances: [
|
|
906
|
+
instances: [
|
|
907
|
+
fcInstance,
|
|
908
|
+
...lifecycleInstances,
|
|
909
|
+
...existingDependentInstances,
|
|
910
|
+
...newDependentInstancesMapped,
|
|
911
|
+
],
|
|
690
912
|
lastUpdated: new Date().toISOString(),
|
|
691
913
|
};
|
|
692
914
|
return (0, common_1.setResource)(state, logicalId, resourceState);
|
|
@@ -695,8 +917,46 @@ exports.updateResource = updateResource;
|
|
|
695
917
|
const deleteResource = async (context, functionName, logicalId, state) => {
|
|
696
918
|
const existingState = (0, common_1.getResource)(state, logicalId);
|
|
697
919
|
const existingInstances = (existingState?.instances ?? []);
|
|
698
|
-
const hasFcFunction = existingInstances.some((i) => i.type === 'ALIYUN_FC3_FUNCTION');
|
|
699
920
|
const client = (0, aliyunClient_1.createAliyunClient)(context);
|
|
921
|
+
// Delete HTTP trigger and custom domain before function (they depend on it)
|
|
922
|
+
const httpTriggerInstance = existingInstances.find((i) => i.type === 'ALIYUN_FC3_HTTP_TRIGGER');
|
|
923
|
+
if (httpTriggerInstance) {
|
|
924
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_HTTP_TRIGGER', { triggerName: httpTriggerInstance.id, functionName }));
|
|
925
|
+
try {
|
|
926
|
+
await client.fc3.deleteTrigger(functionName, httpTriggerInstance.id);
|
|
927
|
+
logger_1.logger.info(lang_1.lang.__('HTTP_TRIGGER_DELETED', { triggerName: httpTriggerInstance.id }));
|
|
928
|
+
}
|
|
929
|
+
catch (err) {
|
|
930
|
+
const errorCode = err?.code;
|
|
931
|
+
if (errorCode === 'TriggerNotFound') {
|
|
932
|
+
logger_1.logger.warn(lang_1.lang.__('HTTP_TRIGGER_NOT_FOUND', { triggerName: httpTriggerInstance.id }));
|
|
933
|
+
}
|
|
934
|
+
else {
|
|
935
|
+
throw err;
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
const customDomainInstance = existingInstances.find((i) => i.type === 'ALIYUN_FC3_CUSTOM_DOMAIN');
|
|
940
|
+
if (customDomainInstance) {
|
|
941
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_CUSTOM_DOMAIN', { domainName: customDomainInstance.id }));
|
|
942
|
+
try {
|
|
943
|
+
await client.fc3.deleteCustomDomain(customDomainInstance.id);
|
|
944
|
+
logger_1.logger.info(lang_1.lang.__('CUSTOM_DOMAIN_DELETED', { domainName: customDomainInstance.id }));
|
|
945
|
+
}
|
|
946
|
+
catch (err) {
|
|
947
|
+
const errorCode = err?.code;
|
|
948
|
+
if (errorCode === 'CustomDomainNotFound') {
|
|
949
|
+
logger_1.logger.warn(lang_1.lang.__('RESOURCE_NOT_FOUND_PROVIDER', {
|
|
950
|
+
resourceType: 'Custom Domain',
|
|
951
|
+
name: customDomainInstance.id,
|
|
952
|
+
}));
|
|
953
|
+
}
|
|
954
|
+
else {
|
|
955
|
+
throw err;
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
const hasFcFunction = existingInstances.some((i) => i.type === 'ALIYUN_FC3_FUNCTION');
|
|
700
960
|
if (hasFcFunction) {
|
|
701
961
|
try {
|
|
702
962
|
await client.fc3.deleteFunction(functionName);
|
|
@@ -711,7 +971,10 @@ const deleteResource = async (context, functionName, logicalId, state) => {
|
|
|
711
971
|
}
|
|
712
972
|
}
|
|
713
973
|
}
|
|
714
|
-
const dependentInstances = existingInstances.filter((i) => i.type !== 'ALIYUN_FC3_FUNCTION' &&
|
|
974
|
+
const dependentInstances = existingInstances.filter((i) => i.type !== 'ALIYUN_FC3_FUNCTION' &&
|
|
975
|
+
i.type !== 'ALIYUN_FC3_HTTP_TRIGGER' &&
|
|
976
|
+
i.type !== 'ALIYUN_FC3_CUSTOM_DOMAIN' &&
|
|
977
|
+
!i.type.includes('undefined'));
|
|
715
978
|
if (dependentInstances.length > 0) {
|
|
716
979
|
await deleteDependentResources(context, dependentInstances);
|
|
717
980
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.executeBucketPlan = void 0;
|
|
4
|
+
const types_1 = require("../../types");
|
|
4
5
|
const ossResource_1 = require("./ossResource");
|
|
5
6
|
const common_1 = require("../../common");
|
|
7
|
+
const reportResourceEvent_1 = require("../../common/reportResourceEvent");
|
|
6
8
|
const stateManager_1 = require("../../common/stateManager");
|
|
7
9
|
const lang_1 = require("../../lang");
|
|
8
10
|
const executeCreateAction = async (context, bucket, currentState) => {
|
|
@@ -61,13 +63,26 @@ const executeBucketPlan = async (context, plan, buckets, initialState, onStateCh
|
|
|
61
63
|
const successfulItems = [];
|
|
62
64
|
let currentState = initialState;
|
|
63
65
|
for (const item of plan.items) {
|
|
66
|
+
(0, reportResourceEvent_1.reportResourceEvent)(context, {
|
|
67
|
+
type: 'resource_pre',
|
|
68
|
+
logicalId: item.logicalId,
|
|
69
|
+
resourceType: item.resourceType,
|
|
70
|
+
action: item.action,
|
|
71
|
+
...(item.drifted ? { message: 'resource drifted' } : {}),
|
|
72
|
+
});
|
|
73
|
+
const __siStartedAt = Date.now();
|
|
64
74
|
try {
|
|
65
75
|
const newState = await executeSingleItem(context, item, bucketsMap, currentState);
|
|
66
76
|
if (newState !== null) {
|
|
67
77
|
currentState = newState;
|
|
68
78
|
successfulItems.push(item);
|
|
79
|
+
(0, reportResourceEvent_1.reportResourceEvent)(context, {
|
|
80
|
+
type: 'resource_complete',
|
|
81
|
+
logicalId: item.logicalId,
|
|
82
|
+
durationMs: Date.now() - __siStartedAt,
|
|
83
|
+
});
|
|
69
84
|
if (onStateChange) {
|
|
70
|
-
onStateChange(currentState);
|
|
85
|
+
await onStateChange(currentState);
|
|
71
86
|
common_1.logger.debug(lang_1.lang.__('STATE_PERSISTED_AFTER_OPERATION', {
|
|
72
87
|
action: item.action,
|
|
73
88
|
resourceId: item.logicalId,
|
|
@@ -76,6 +91,29 @@ const executeBucketPlan = async (context, plan, buckets, initialState, onStateCh
|
|
|
76
91
|
}
|
|
77
92
|
}
|
|
78
93
|
catch (error) {
|
|
94
|
+
(0, reportResourceEvent_1.reportResourceEvent)(context, {
|
|
95
|
+
type: 'resource_failed',
|
|
96
|
+
logicalId: item.logicalId,
|
|
97
|
+
severity: 'error',
|
|
98
|
+
durationMs: Date.now() - __siStartedAt,
|
|
99
|
+
error: {
|
|
100
|
+
message: error instanceof Error ? error.message : String(error),
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
if (error instanceof types_1.PartialResourceError) {
|
|
104
|
+
const updatedState = error.updatedState;
|
|
105
|
+
if (onStateChange) {
|
|
106
|
+
await onStateChange(updatedState);
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
state: updatedState,
|
|
110
|
+
partialFailure: {
|
|
111
|
+
failedItem: item,
|
|
112
|
+
error: error.cause,
|
|
113
|
+
successfulItems,
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
79
117
|
return {
|
|
80
118
|
state: currentState,
|
|
81
119
|
partialFailure: {
|
|
@@ -9,12 +9,16 @@ const aliyunClient_1 = require("../../common/aliyunClient");
|
|
|
9
9
|
const ossTypes_1 = require("./ossTypes");
|
|
10
10
|
const stateManager_1 = require("../../common/stateManager");
|
|
11
11
|
const hashUtils_1 = require("../../common/hashUtils");
|
|
12
|
+
const ownershipTag_1 = require("../ownershipTag");
|
|
12
13
|
const planBucketDeletion = (logicalId, definition) => ({
|
|
13
14
|
logicalId,
|
|
14
15
|
action: 'delete',
|
|
15
16
|
resourceType: 'ALIYUN_OSS_BUCKET',
|
|
16
17
|
changes: { before: normalizeDefinitionForDisplay(definition) },
|
|
17
18
|
});
|
|
19
|
+
// getBucket returns tags as { key, value } (BucketTag); the ownership helper
|
|
20
|
+
// expects { Key, Value }. Convert before verification.
|
|
21
|
+
const toOwnershipTags = (tags) => tags?.map((tag) => ({ Key: tag.key, Value: tag.value }));
|
|
18
22
|
const normalizeDefinitionForDisplay = (definition) => {
|
|
19
23
|
const { domainBound: _domainBound, ...rest } = definition;
|
|
20
24
|
return rest;
|
|
@@ -43,7 +47,17 @@ const generateBucketPlan = async (context, state, buckets) => {
|
|
|
43
47
|
}
|
|
44
48
|
})();
|
|
45
49
|
const desiredDefinition = (0, ossTypes_1.extractOssBucketDefinition)(config, websiteCodeHash);
|
|
46
|
-
if (!currentState) {
|
|
50
|
+
if (!currentState || currentState.status === 'tainted') {
|
|
51
|
+
// No usable local state: probe the provider before planning create.
|
|
52
|
+
// If a same-named bucket already exists WITHOUT our ownership tag it
|
|
53
|
+
// may belong to another project — fail fast in the plan instead of
|
|
54
|
+
// letting the executor discover it mid-deploy.
|
|
55
|
+
const client = (0, aliyunClient_1.createAliyunClient)(context);
|
|
56
|
+
const remoteBucket = await client.oss.getBucket(bucket.name);
|
|
57
|
+
if (remoteBucket &&
|
|
58
|
+
!(0, ownershipTag_1.isOwnedByStack)(context, logicalId, toOwnershipTags(remoteBucket.tags))) {
|
|
59
|
+
throw new Error(`Bucket ${bucket.name} already exists in provider but is not owned by this stack (missing ${ownershipTag_1.OWNERSHIP_TAG_KEY} tag). Refusing to create — resolve manually.`);
|
|
60
|
+
}
|
|
47
61
|
return {
|
|
48
62
|
logicalId,
|
|
49
63
|
action: 'create',
|