@geek-fun/serverlessinsight 0.5.7 → 0.5.10
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/AGENTS.md +372 -0
- package/README.md +2 -2
- package/README.zh-CN.md +11 -8
- package/dist/package.json +1 -1
- package/dist/src/commands/index.js +5 -4
- package/dist/src/common/aliyunClient/apigwOperations.js +96 -9
- package/dist/src/common/aliyunClient/ossOperations.js +68 -0
- package/dist/src/common/aliyunClient/ramOperations.js +65 -20
- package/dist/src/common/tencentClient/cosOperations.js +123 -0
- package/dist/src/lang/en.js +137 -0
- package/dist/src/lang/index.js +6 -0
- package/dist/src/lang/zh-CN.js +136 -0
- package/dist/src/stack/aliyunStack/apigwExecutor.js +15 -9
- package/dist/src/stack/aliyunStack/apigwPlanner.js +15 -2
- package/dist/src/stack/aliyunStack/apigwResource.js +3 -3
- package/dist/src/stack/aliyunStack/apigwTypes.js +4 -3
- package/dist/src/stack/aliyunStack/databaseExecutor.js +24 -9
- package/dist/src/stack/aliyunStack/databaseResource.js +5 -1
- package/dist/src/stack/aliyunStack/deployer.js +11 -2
- package/dist/src/stack/aliyunStack/destroyer.js +5 -1
- package/dist/src/stack/aliyunStack/fc3Executor.js +10 -9
- package/dist/src/stack/aliyunStack/fc3Resource.js +36 -27
- package/dist/src/stack/aliyunStack/ossExecutor.js +9 -9
- package/dist/src/stack/aliyunStack/ossResource.js +19 -3
- package/dist/src/stack/aliyunStack/tablestoreExecutor.js +21 -9
- package/dist/src/stack/scfStack/cosExecutor.js +9 -9
- package/dist/src/stack/scfStack/cosResource.js +20 -3
- package/dist/src/stack/scfStack/deployer.js +5 -1
- package/dist/src/stack/scfStack/destroyer.js +5 -1
- package/dist/src/stack/scfStack/esServerlessExecutor.js +21 -9
- package/dist/src/stack/scfStack/esServerlessResource.js +2 -1
- package/dist/src/stack/scfStack/scfExecutor.js +9 -9
- package/dist/src/stack/scfStack/scfResource.js +2 -1
- package/dist/src/stack/scfStack/tdsqlcExecutor.js +9 -9
- package/dist/src/stack/scfStack/tdsqlcResource.js +5 -1
- package/dist/src/validator/bucketSchema.js +4 -0
- package/package.json +1 -1
|
@@ -12,12 +12,17 @@ const constants_1 = require("../../common/constants");
|
|
|
12
12
|
const types_1 = require("../../types");
|
|
13
13
|
const fc3Types_1 = require("./fc3Types");
|
|
14
14
|
const logger_1 = require("../../common/logger");
|
|
15
|
+
const lang_1 = require("../../lang");
|
|
15
16
|
const RECOVERY_GET_FUNCTION_DELAY_MS = 1500;
|
|
16
17
|
const delay = async (ms) => {
|
|
17
18
|
await new Promise((resolve) => {
|
|
18
19
|
setTimeout(resolve, ms);
|
|
19
20
|
});
|
|
20
21
|
};
|
|
22
|
+
const getTrustedServicesForFunction = (context, fnKey) => {
|
|
23
|
+
const fnHasApiGateway = context.iac?.events?.some((event) => event.triggers?.some((trigger) => String(trigger.backend) === `\${functions.${fnKey}}`));
|
|
24
|
+
return fnHasApiGateway ? ['fc.aliyuncs.com', 'apigateway.aliyuncs.com'] : ['fc.aliyuncs.com'];
|
|
25
|
+
};
|
|
21
26
|
const isRecoverableCreateError = (error) => {
|
|
22
27
|
const code = error && typeof error === 'object' && 'code' in error && typeof error.code === 'string'
|
|
23
28
|
? error.code.toLowerCase()
|
|
@@ -43,13 +48,13 @@ const ensureOssCodeUpload = async (client, codePath, region, functionName) => {
|
|
|
43
48
|
logger_1.logger.info(`Code package ${node_path_1.default.basename(codePath)} is ${(fileSize / (1024 * 1024)).toFixed(1)}MB, uploading to OSS bucket ${bucketName}`);
|
|
44
49
|
const existingBucket = await client.oss.getBucket(bucketName);
|
|
45
50
|
if (!existingBucket) {
|
|
46
|
-
logger_1.logger.info(
|
|
51
|
+
logger_1.logger.info(lang_1.lang.__('CREATING_BOOTSTRAP_BUCKET', { bucketName }));
|
|
47
52
|
await client.oss.createBucket({ bucketName });
|
|
48
53
|
}
|
|
49
54
|
const codeHash = (0, common_1.computeFileHash)(codePath);
|
|
50
55
|
const ossObjectName = `fc3-code/${functionName}/${codeHash}.zip`;
|
|
51
56
|
await client.oss.putFile(bucketName, ossObjectName, codePath);
|
|
52
|
-
logger_1.logger.info(
|
|
57
|
+
logger_1.logger.info(lang_1.lang.__('UPLOADED_CODE_TO_OSS', { bucketName, objectName: ossObjectName }));
|
|
53
58
|
return { ossBucketName: bucketName, ossObjectName };
|
|
54
59
|
};
|
|
55
60
|
const buildFc3InstanceFromProvider = (info, sid) => {
|
|
@@ -146,17 +151,17 @@ const createDependentResources = async (context, fn, serviceName, existingInstan
|
|
|
146
151
|
else {
|
|
147
152
|
const projectName = `${serviceName}-${context.stage}-sls`;
|
|
148
153
|
const logstoreName = `${serviceName}-${context.stage}-sls-logstore`;
|
|
149
|
-
logger_1.logger.info(
|
|
154
|
+
logger_1.logger.info(lang_1.lang.__('CREATING_SLS_PROJECT', { projectName }));
|
|
150
155
|
const project = await client.sls.createProject(projectName);
|
|
151
156
|
instances.push({ type: 'ALIYUN_SLS_PROJECT', id: projectName, attributes: { ...project } });
|
|
152
|
-
logger_1.logger.info(
|
|
157
|
+
logger_1.logger.info(lang_1.lang.__('CREATING_SLS_LOGSTORE', { logstoreName }));
|
|
153
158
|
const logstore = await client.sls.createLogstore(projectName, logstoreName);
|
|
154
159
|
instances.push({
|
|
155
160
|
type: 'ALIYUN_SLS_LOGSTORE',
|
|
156
161
|
id: `${projectName}/${logstoreName}`,
|
|
157
162
|
attributes: { ...logstore },
|
|
158
163
|
});
|
|
159
|
-
logger_1.logger.info(
|
|
164
|
+
logger_1.logger.info(lang_1.lang.__('CREATING_SLS_INDEX', { logstoreName }));
|
|
160
165
|
const index = await client.sls.createIndex(projectName, logstoreName);
|
|
161
166
|
instances.push({
|
|
162
167
|
type: 'ALIYUN_SLS_INDEX',
|
|
@@ -170,18 +175,16 @@ const createDependentResources = async (context, fn, serviceName, existingInstan
|
|
|
170
175
|
}
|
|
171
176
|
}
|
|
172
177
|
const roleName = `${serviceName}-${context.stage}-fc-role`;
|
|
178
|
+
const trustedServices = getTrustedServicesForFunction(context, fn.key);
|
|
173
179
|
if (hasRamRole) {
|
|
174
180
|
const ramRoleInstance = existingInstances.find((i) => i.type === 'ALIYUN_RAM_ROLE');
|
|
175
181
|
if (ramRoleInstance) {
|
|
176
182
|
instances.push(ramRoleInstance);
|
|
183
|
+
await client.ram.updateRoleTrustPolicy(roleName, trustedServices);
|
|
177
184
|
}
|
|
178
185
|
}
|
|
179
186
|
else {
|
|
180
|
-
|
|
181
|
-
const trustedServices = fnHasApiGateway
|
|
182
|
-
? ['fc.aliyuncs.com', 'apigateway.aliyuncs.com']
|
|
183
|
-
: ['fc.aliyuncs.com'];
|
|
184
|
-
logger_1.logger.info(`Creating RAM role: ${roleName}`);
|
|
187
|
+
logger_1.logger.info(lang_1.lang.__('CREATING_RAM_ROLE', { roleName }));
|
|
185
188
|
const ramRole = await client.ram.createRole(roleName, trustedServices);
|
|
186
189
|
instances.push({
|
|
187
190
|
type: 'ALIYUN_RAM_ROLE',
|
|
@@ -206,7 +209,7 @@ const createDependentResources = async (context, fn, serviceName, existingInstan
|
|
|
206
209
|
}
|
|
207
210
|
else {
|
|
208
211
|
const sgName = fn.network.security_group.name;
|
|
209
|
-
logger_1.logger.info(
|
|
212
|
+
logger_1.logger.info(lang_1.lang.__('CREATING_SECURITY_GROUP', { sgName }));
|
|
210
213
|
const sg = await client.ecs.createSecurityGroup(sgName, fn.network.vpc_id, fn.network.security_group.ingress, fn.network.security_group.egress);
|
|
211
214
|
instances.push({
|
|
212
215
|
type: 'ALIYUN_ECS_SECURITY_GROUP',
|
|
@@ -242,23 +245,23 @@ const createDependentResources = async (context, fn, serviceName, existingInstan
|
|
|
242
245
|
for (const nasItem of fn.storage.nas) {
|
|
243
246
|
const mountPath = nasItem.mount_path.replace(/\//g, '-').replace(/^-/, '');
|
|
244
247
|
const accessGroupName = `${fn.name}-${context.stage}-nas-access-${mountPath}`;
|
|
245
|
-
logger_1.logger.info(
|
|
248
|
+
logger_1.logger.info(lang_1.lang.__('CREATING_NAS_ACCESS_GROUP', { accessGroupName }));
|
|
246
249
|
const accessGroup = await client.nas.createAccessGroup(accessGroupName);
|
|
247
250
|
instances.push({
|
|
248
251
|
type: 'ALIYUN_NAS_ACCESS_GROUP',
|
|
249
252
|
id: accessGroupName,
|
|
250
253
|
attributes: { ...accessGroup },
|
|
251
254
|
});
|
|
252
|
-
logger_1.logger.info(
|
|
255
|
+
logger_1.logger.info(lang_1.lang.__('CREATING_NAS_ACCESS_RULE', { accessGroupName }));
|
|
253
256
|
await client.nas.createAccessRule(accessGroupName, '10.0.0.0/8');
|
|
254
|
-
logger_1.logger.info(
|
|
257
|
+
logger_1.logger.info(lang_1.lang.__('CREATING_NAS_FILE_SYSTEM', { name: fn.name }));
|
|
255
258
|
const fileSystem = await client.nas.createFileSystem(nasItem.storage_class, fn.name);
|
|
256
259
|
instances.push({
|
|
257
260
|
type: 'ALIYUN_NAS_FILE_SYSTEM',
|
|
258
261
|
id: fileSystem.fileSystemId,
|
|
259
262
|
attributes: { ...fileSystem },
|
|
260
263
|
});
|
|
261
|
-
logger_1.logger.info(
|
|
264
|
+
logger_1.logger.info(lang_1.lang.__('CREATING_NAS_MOUNT_TARGET', { fileSystemId: fileSystem.fileSystemId }));
|
|
262
265
|
const mountTarget = await client.nas.createMountTarget(fileSystem.fileSystemId, accessGroupName, fn.network.vpc_id, fn.network.subnet_ids[0]);
|
|
263
266
|
instances.push({
|
|
264
267
|
type: 'ALIYUN_NAS_MOUNT_TARGET',
|
|
@@ -291,48 +294,52 @@ const deleteDependentResources = async (context, instances) => {
|
|
|
291
294
|
switch (instance.type) {
|
|
292
295
|
case 'ALIYUN_NAS_MOUNT_TARGET': {
|
|
293
296
|
const [fileSystemId, mountTargetDomain] = instance.id.split('/');
|
|
294
|
-
logger_1.logger.info(
|
|
297
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_NAS_MOUNT_TARGET', { id: instance.id }));
|
|
295
298
|
await client.nas.deleteMountTarget(fileSystemId, mountTargetDomain);
|
|
296
299
|
break;
|
|
297
300
|
}
|
|
298
301
|
case 'ALIYUN_NAS_FILE_SYSTEM':
|
|
299
|
-
logger_1.logger.info(
|
|
302
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_NAS_FILE_SYSTEM', { id: instance.id }));
|
|
300
303
|
await client.nas.deleteFileSystem(instance.id);
|
|
301
304
|
break;
|
|
302
305
|
case 'ALIYUN_NAS_ACCESS_GROUP':
|
|
303
|
-
logger_1.logger.info(
|
|
306
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_NAS_ACCESS_GROUP', { id: instance.id }));
|
|
304
307
|
await client.nas.deleteAccessGroup(instance.id);
|
|
305
308
|
break;
|
|
306
309
|
case 'ALIYUN_ECS_SECURITY_GROUP':
|
|
307
|
-
logger_1.logger.info(
|
|
310
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_SECURITY_GROUP', { id: instance.id }));
|
|
308
311
|
await client.ecs.deleteSecurityGroup(instance.id);
|
|
309
312
|
break;
|
|
310
313
|
case 'ALIYUN_RAM_ROLE':
|
|
311
|
-
logger_1.logger.info(
|
|
314
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_RAM_ROLE', { id: instance.id }));
|
|
312
315
|
await client.ram.deleteRole(instance.id);
|
|
313
316
|
break;
|
|
314
317
|
case 'ALIYUN_SLS_INDEX': {
|
|
315
318
|
const [projectName, logstoreName] = instance.id.split('/');
|
|
316
|
-
logger_1.logger.info(
|
|
319
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_SLS_INDEX', { id: instance.id }));
|
|
317
320
|
await client.sls.deleteIndex(projectName, logstoreName);
|
|
318
321
|
break;
|
|
319
322
|
}
|
|
320
323
|
case 'ALIYUN_SLS_LOGSTORE': {
|
|
321
324
|
const [projectName, logstoreName] = instance.id.split('/');
|
|
322
|
-
logger_1.logger.info(
|
|
325
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_SLS_LOGSTORE', { id: instance.id }));
|
|
323
326
|
await client.sls.deleteLogstore(projectName, logstoreName);
|
|
324
327
|
break;
|
|
325
328
|
}
|
|
326
329
|
case 'ALIYUN_SLS_PROJECT':
|
|
327
|
-
logger_1.logger.info(
|
|
330
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_SLS_PROJECT', { id: instance.id }));
|
|
328
331
|
await client.sls.deleteProject(instance.id);
|
|
329
332
|
break;
|
|
330
333
|
default:
|
|
331
|
-
logger_1.logger.warn(
|
|
334
|
+
logger_1.logger.warn(lang_1.lang.__('UNKNOWN_RESOURCE_TYPE', { type: instance.type }));
|
|
332
335
|
}
|
|
333
336
|
}
|
|
334
337
|
catch (err) {
|
|
335
|
-
logger_1.logger.error(
|
|
338
|
+
logger_1.logger.error(lang_1.lang.__('FAILED_TO_DELETE_RESOURCE', {
|
|
339
|
+
type: instance.type,
|
|
340
|
+
id: instance.id,
|
|
341
|
+
error: String(err),
|
|
342
|
+
}));
|
|
336
343
|
}
|
|
337
344
|
}
|
|
338
345
|
};
|
|
@@ -469,6 +476,7 @@ const updateResource = async (context, fn, state) => {
|
|
|
469
476
|
const hasRamRole = existingInstances.some((i) => i.type === 'ALIYUN_RAM_ROLE');
|
|
470
477
|
const hasSecurityGroup = existingInstances.some((i) => i.type === 'ALIYUN_ECS_SECURITY_GROUP');
|
|
471
478
|
const hasNasResources = existingInstances.some((i) => i.type === 'ALIYUN_NAS_FILE_SYSTEM');
|
|
479
|
+
const client = (0, aliyunClient_1.createAliyunClient)(context);
|
|
472
480
|
const newDependentInstances = [];
|
|
473
481
|
let logConfig;
|
|
474
482
|
let role;
|
|
@@ -499,6 +507,8 @@ const updateResource = async (context, fn, state) => {
|
|
|
499
507
|
roleName: ramRoleInstance.id,
|
|
500
508
|
arn: ramRoleInstance.roleArn ?? `acs:ram::${context.accountId}:role/${ramRoleInstance.id}`,
|
|
501
509
|
};
|
|
510
|
+
const trustedServices = getTrustedServicesForFunction(context, fn.key);
|
|
511
|
+
await client.ram.updateRoleTrustPolicy(ramRoleInstance.id, trustedServices);
|
|
502
512
|
}
|
|
503
513
|
}
|
|
504
514
|
if (fn.network && !hasSecurityGroup) {
|
|
@@ -567,7 +577,6 @@ const updateResource = async (context, fn, state) => {
|
|
|
567
577
|
};
|
|
568
578
|
}
|
|
569
579
|
const codePath = fn.code.path;
|
|
570
|
-
const client = (0, aliyunClient_1.createAliyunClient)(context);
|
|
571
580
|
await client.fc3.updateFunctionConfiguration(config);
|
|
572
581
|
const ossCode = await ensureOssCodeUpload(client, codePath, context.region, fn.name);
|
|
573
582
|
await client.fc3.updateFunctionCode(fn.name, codePath, ossCode);
|
|
@@ -620,7 +629,7 @@ const deleteResource = async (context, functionName, logicalId, state) => {
|
|
|
620
629
|
catch (err) {
|
|
621
630
|
const errorCode = err?.code;
|
|
622
631
|
if (errorCode === 'FunctionNotFound') {
|
|
623
|
-
logger_1.logger.warn(
|
|
632
|
+
logger_1.logger.warn(lang_1.lang.__('RESOURCE_NOT_FOUND_PROVIDER', { resourceType: 'Function', name: functionName }));
|
|
624
633
|
}
|
|
625
634
|
else {
|
|
626
635
|
throw err;
|
|
@@ -6,27 +6,27 @@ const common_1 = require("../../common");
|
|
|
6
6
|
const stateManager_1 = require("../../common/stateManager");
|
|
7
7
|
const lang_1 = require("../../lang");
|
|
8
8
|
const executeCreateAction = async (context, bucket, currentState) => {
|
|
9
|
-
common_1.logger.info(
|
|
9
|
+
common_1.logger.info(lang_1.lang.__('CREATING_RESOURCE', { resourceType: 'bucket', name: bucket.name }));
|
|
10
10
|
const newState = await (0, ossResource_1.createBucketResource)(context, bucket, currentState);
|
|
11
|
-
common_1.logger.info(
|
|
11
|
+
common_1.logger.info(lang_1.lang.__('RESOURCE_CREATED', { resourceType: 'bucket', name: bucket.name }));
|
|
12
12
|
return newState;
|
|
13
13
|
};
|
|
14
14
|
const executeUpdateAction = async (context, bucket, currentState) => {
|
|
15
|
-
common_1.logger.info(
|
|
15
|
+
common_1.logger.info(lang_1.lang.__('UPDATING_RESOURCE', { resourceType: 'bucket', name: bucket.name }));
|
|
16
16
|
const newState = await (0, ossResource_1.updateBucketResource)(context, bucket, currentState);
|
|
17
|
-
common_1.logger.info(
|
|
17
|
+
common_1.logger.info(lang_1.lang.__('RESOURCE_UPDATED', { resourceType: 'bucket', name: bucket.name }));
|
|
18
18
|
return newState;
|
|
19
19
|
};
|
|
20
20
|
const executeDeleteAction = async (context, bucketName, logicalId, currentState) => {
|
|
21
|
-
common_1.logger.info(
|
|
21
|
+
common_1.logger.info(lang_1.lang.__('DELETING_RESOURCE', { resourceType: 'bucket', name: bucketName }));
|
|
22
22
|
const newState = await (0, ossResource_1.deleteBucketResource)(context, bucketName, logicalId, currentState);
|
|
23
|
-
common_1.logger.info(
|
|
23
|
+
common_1.logger.info(lang_1.lang.__('RESOURCE_DELETED', { resourceType: 'bucket', name: bucketName }));
|
|
24
24
|
return newState;
|
|
25
25
|
};
|
|
26
26
|
const executeSingleItem = async (context, item, bucketsMap, currentState) => {
|
|
27
27
|
switch (item.action) {
|
|
28
28
|
case 'noop':
|
|
29
|
-
common_1.logger.info(
|
|
29
|
+
common_1.logger.info(lang_1.lang.__('NO_CHANGESForResource', { logicalId: item.logicalId }));
|
|
30
30
|
return null;
|
|
31
31
|
case 'create': {
|
|
32
32
|
const bucket = bucketsMap.get(item.logicalId);
|
|
@@ -45,14 +45,14 @@ const executeSingleItem = async (context, item, bucketsMap, currentState) => {
|
|
|
45
45
|
case 'delete': {
|
|
46
46
|
const state = (0, stateManager_1.getResource)(currentState, item.logicalId);
|
|
47
47
|
if (!state) {
|
|
48
|
-
common_1.logger.warn(
|
|
48
|
+
common_1.logger.warn(lang_1.lang.__('STATE_NOT_FOUND_SKIPPING', { logicalId: item.logicalId }));
|
|
49
49
|
return null;
|
|
50
50
|
}
|
|
51
51
|
const bucketName = state.definition.bucketName;
|
|
52
52
|
return executeDeleteAction(context, bucketName, item.logicalId, currentState);
|
|
53
53
|
}
|
|
54
54
|
default:
|
|
55
|
-
common_1.logger.warn(
|
|
55
|
+
common_1.logger.warn(lang_1.lang.__('UNKNOWN_ACTION_FOR_RESOURCE', { action: item.action, logicalId: item.logicalId }));
|
|
56
56
|
return null;
|
|
57
57
|
}
|
|
58
58
|
};
|
|
@@ -125,7 +125,10 @@ const createBucketResource = async (context, bucket, state) => {
|
|
|
125
125
|
state = (0, common_1.setResource)(state, logicalId, partialResourceState);
|
|
126
126
|
let cnameInfo;
|
|
127
127
|
if (bucket.website?.domain) {
|
|
128
|
-
logger_1.logger.info(
|
|
128
|
+
logger_1.logger.info(lang_1.lang.__('BINDING_CUSTOM_DOMAIN_TO_BUCKET', {
|
|
129
|
+
domain: bucket.website.domain,
|
|
130
|
+
bucketName: config.bucketName,
|
|
131
|
+
}));
|
|
129
132
|
cnameInfo = await client.oss.bindCustomDomain(config.bucketName, bucket.website.domain);
|
|
130
133
|
if (cnameInfo) {
|
|
131
134
|
const instanceId = cnameInfo.dnsRecordId ?? bucket.website.domain;
|
|
@@ -138,6 +141,11 @@ const createBucketResource = async (context, bucket, state) => {
|
|
|
138
141
|
...(cnameInfo.dnsRecordId ? { dnsRecordId: cnameInfo.dnsRecordId } : {}),
|
|
139
142
|
};
|
|
140
143
|
instances.push(dnsInstance);
|
|
144
|
+
// Refresh bucket info to capture auto-added CORS rule
|
|
145
|
+
bucketInfo = await client.oss.getBucket(config.bucketName);
|
|
146
|
+
if (bucketInfo) {
|
|
147
|
+
instances[0] = buildOssInstanceFromProvider(bucketInfo, sid);
|
|
148
|
+
}
|
|
141
149
|
}
|
|
142
150
|
}
|
|
143
151
|
// Upload static files if code path is specified
|
|
@@ -199,7 +207,10 @@ const updateBucketResource = async (context, bucket, state) => {
|
|
|
199
207
|
if (domainChanged && existingDnsInstance) {
|
|
200
208
|
await client.oss.unbindCustomDomain(config.bucketName, existingDnsInstance.domain, existingDnsInstance.dnsRecordId);
|
|
201
209
|
}
|
|
202
|
-
logger_1.logger.info(
|
|
210
|
+
logger_1.logger.info(lang_1.lang.__('BINDING_CUSTOM_DOMAIN_TO_BUCKET', {
|
|
211
|
+
domain: bucket.website.domain,
|
|
212
|
+
bucketName: config.bucketName,
|
|
213
|
+
}));
|
|
203
214
|
const cnameInfo = await client.oss.bindCustomDomain(config.bucketName, bucket.website.domain);
|
|
204
215
|
if (cnameInfo) {
|
|
205
216
|
const instanceId = cnameInfo.dnsRecordId ?? bucket.website.domain;
|
|
@@ -212,6 +223,11 @@ const updateBucketResource = async (context, bucket, state) => {
|
|
|
212
223
|
...(cnameInfo.dnsRecordId ? { dnsRecordId: cnameInfo.dnsRecordId } : {}),
|
|
213
224
|
};
|
|
214
225
|
instances.push(dnsInstance);
|
|
226
|
+
// Refresh bucket info to capture auto-added CORS rule
|
|
227
|
+
const refreshedInfo = await client.oss.getBucket(config.bucketName);
|
|
228
|
+
if (refreshedInfo) {
|
|
229
|
+
instances[0] = buildOssInstanceFromProvider(refreshedInfo, sid);
|
|
230
|
+
}
|
|
215
231
|
}
|
|
216
232
|
}
|
|
217
233
|
else if (existingDnsInstance) {
|
|
@@ -240,7 +256,7 @@ const deleteBucketResource = async (context, bucketName, logicalId, state) => {
|
|
|
240
256
|
catch (err) {
|
|
241
257
|
const errorCode = err?.code;
|
|
242
258
|
if (errorCode === 'NoSuchBucket') {
|
|
243
|
-
logger_1.logger.warn(
|
|
259
|
+
logger_1.logger.warn(lang_1.lang.__('RESOURCE_NOT_FOUND_PROVIDER', { resourceType: 'Bucket', name: bucketName }));
|
|
244
260
|
}
|
|
245
261
|
else {
|
|
246
262
|
throw err;
|
|
@@ -6,27 +6,39 @@ const common_1 = require("../../common");
|
|
|
6
6
|
const stateManager_1 = require("../../common/stateManager");
|
|
7
7
|
const lang_1 = require("../../lang");
|
|
8
8
|
const executeCreateAction = async (context, table, currentState) => {
|
|
9
|
-
common_1.logger.info(
|
|
9
|
+
common_1.logger.info(lang_1.lang.__('CREATING_RESOURCE', {
|
|
10
|
+
resourceType: 'table',
|
|
11
|
+
name: `${table.collection}/${table.name}`,
|
|
12
|
+
}));
|
|
10
13
|
const newState = await (0, tablestoreResource_1.createTableResource)(context, table, currentState);
|
|
11
|
-
common_1.logger.info(
|
|
14
|
+
common_1.logger.info(lang_1.lang.__('RESOURCE_CREATED', {
|
|
15
|
+
resourceType: 'table',
|
|
16
|
+
name: `${table.collection}/${table.name}`,
|
|
17
|
+
}));
|
|
12
18
|
return newState;
|
|
13
19
|
};
|
|
14
20
|
const executeUpdateAction = async (context, table, currentState) => {
|
|
15
|
-
common_1.logger.info(
|
|
21
|
+
common_1.logger.info(lang_1.lang.__('UPDATING_RESOURCE', {
|
|
22
|
+
resourceType: 'table',
|
|
23
|
+
name: `${table.collection}/${table.name}`,
|
|
24
|
+
}));
|
|
16
25
|
const newState = await (0, tablestoreResource_1.updateTableResource)(context, table, currentState);
|
|
17
|
-
common_1.logger.info(
|
|
26
|
+
common_1.logger.info(lang_1.lang.__('RESOURCE_UPDATED', {
|
|
27
|
+
resourceType: 'table',
|
|
28
|
+
name: `${table.collection}/${table.name}`,
|
|
29
|
+
}));
|
|
18
30
|
return newState;
|
|
19
31
|
};
|
|
20
32
|
const executeDeleteAction = async (context, instanceName, tableName, logicalId, currentState) => {
|
|
21
|
-
common_1.logger.info(
|
|
33
|
+
common_1.logger.info(lang_1.lang.__('DELETING_RESOURCE', { resourceType: 'table', name: `${instanceName}/${tableName}` }));
|
|
22
34
|
const newState = await (0, tablestoreResource_1.deleteTableResource)(context, instanceName, tableName, logicalId, currentState);
|
|
23
|
-
common_1.logger.info(
|
|
35
|
+
common_1.logger.info(lang_1.lang.__('RESOURCE_DELETED', { resourceType: 'table', name: `${instanceName}/${tableName}` }));
|
|
24
36
|
return newState;
|
|
25
37
|
};
|
|
26
38
|
const executeSingleItem = async (context, item, tablesMap, currentState) => {
|
|
27
39
|
switch (item.action) {
|
|
28
40
|
case 'noop':
|
|
29
|
-
common_1.logger.info(
|
|
41
|
+
common_1.logger.info(lang_1.lang.__('NO_CHANGESForResource', { logicalId: item.logicalId }));
|
|
30
42
|
return null;
|
|
31
43
|
case 'create': {
|
|
32
44
|
const table = tablesMap.get(item.logicalId);
|
|
@@ -45,7 +57,7 @@ const executeSingleItem = async (context, item, tablesMap, currentState) => {
|
|
|
45
57
|
case 'delete': {
|
|
46
58
|
const state = (0, stateManager_1.getResource)(currentState, item.logicalId);
|
|
47
59
|
if (!state) {
|
|
48
|
-
common_1.logger.warn(
|
|
60
|
+
common_1.logger.warn(lang_1.lang.__('STATE_NOT_FOUND_SKIPPING', { logicalId: item.logicalId }));
|
|
49
61
|
return null;
|
|
50
62
|
}
|
|
51
63
|
const instanceName = state.definition.instanceName;
|
|
@@ -53,7 +65,7 @@ const executeSingleItem = async (context, item, tablesMap, currentState) => {
|
|
|
53
65
|
return executeDeleteAction(context, instanceName, tableName, item.logicalId, currentState);
|
|
54
66
|
}
|
|
55
67
|
default:
|
|
56
|
-
common_1.logger.warn(
|
|
68
|
+
common_1.logger.warn(lang_1.lang.__('UNKNOWN_ACTION_FOR_RESOURCE', { action: item.action, logicalId: item.logicalId }));
|
|
57
69
|
return null;
|
|
58
70
|
}
|
|
59
71
|
};
|
|
@@ -6,27 +6,27 @@ const common_1 = require("../../common");
|
|
|
6
6
|
const stateManager_1 = require("../../common/stateManager");
|
|
7
7
|
const lang_1 = require("../../lang");
|
|
8
8
|
const executeCreateAction = async (context, bucket, currentState) => {
|
|
9
|
-
common_1.logger.info(
|
|
9
|
+
common_1.logger.info(lang_1.lang.__('CREATING_RESOURCE', { resourceType: 'bucket', name: bucket.name }));
|
|
10
10
|
const newState = await (0, cosResource_1.createBucketResource)(context, bucket, currentState);
|
|
11
|
-
common_1.logger.info(
|
|
11
|
+
common_1.logger.info(lang_1.lang.__('RESOURCE_CREATED', { resourceType: 'bucket', name: bucket.name }));
|
|
12
12
|
return newState;
|
|
13
13
|
};
|
|
14
14
|
const executeUpdateAction = async (context, bucket, currentState) => {
|
|
15
|
-
common_1.logger.info(
|
|
15
|
+
common_1.logger.info(lang_1.lang.__('UPDATING_RESOURCE', { resourceType: 'bucket', name: bucket.name }));
|
|
16
16
|
const newState = await (0, cosResource_1.updateBucketResource)(context, bucket, currentState);
|
|
17
|
-
common_1.logger.info(
|
|
17
|
+
common_1.logger.info(lang_1.lang.__('RESOURCE_UPDATED', { resourceType: 'bucket', name: bucket.name }));
|
|
18
18
|
return newState;
|
|
19
19
|
};
|
|
20
20
|
const executeDeleteAction = async (context, bucketName, region, logicalId, currentState) => {
|
|
21
|
-
common_1.logger.info(
|
|
21
|
+
common_1.logger.info(lang_1.lang.__('DELETING_RESOURCE', { resourceType: 'bucket', name: bucketName }));
|
|
22
22
|
const newState = await (0, cosResource_1.deleteBucketResource)(context, bucketName, region, logicalId, currentState);
|
|
23
|
-
common_1.logger.info(
|
|
23
|
+
common_1.logger.info(lang_1.lang.__('RESOURCE_DELETED', { resourceType: 'bucket', name: bucketName }));
|
|
24
24
|
return newState;
|
|
25
25
|
};
|
|
26
26
|
const executeSingleItem = async (context, item, bucketsMap, currentState) => {
|
|
27
27
|
switch (item.action) {
|
|
28
28
|
case 'noop':
|
|
29
|
-
common_1.logger.info(
|
|
29
|
+
common_1.logger.info(lang_1.lang.__('NO_CHANGESForResource', { logicalId: item.logicalId }));
|
|
30
30
|
return null;
|
|
31
31
|
case 'create': {
|
|
32
32
|
const bucket = bucketsMap.get(item.logicalId);
|
|
@@ -45,14 +45,14 @@ const executeSingleItem = async (context, item, bucketsMap, currentState) => {
|
|
|
45
45
|
case 'delete': {
|
|
46
46
|
const state = (0, stateManager_1.getResource)(currentState, item.logicalId);
|
|
47
47
|
if (!state) {
|
|
48
|
-
common_1.logger.warn(
|
|
48
|
+
common_1.logger.warn(lang_1.lang.__('STATE_NOT_FOUND_SKIPPING', { logicalId: item.logicalId }));
|
|
49
49
|
return null;
|
|
50
50
|
}
|
|
51
51
|
const bucketName = state.definition.bucket;
|
|
52
52
|
return executeDeleteAction(context, bucketName, state.region, item.logicalId, currentState);
|
|
53
53
|
}
|
|
54
54
|
default:
|
|
55
|
-
common_1.logger.warn(
|
|
55
|
+
common_1.logger.warn(lang_1.lang.__('UNKNOWN_ACTION_FOR_RESOURCE', { action: item.action, logicalId: item.logicalId }));
|
|
56
56
|
return null;
|
|
57
57
|
}
|
|
58
58
|
};
|
|
@@ -7,6 +7,7 @@ const cosTypes_1 = require("./cosTypes");
|
|
|
7
7
|
const stateManager_1 = require("../../common/stateManager");
|
|
8
8
|
const common_1 = require("../../common");
|
|
9
9
|
const logger_1 = require("../../common/logger");
|
|
10
|
+
const lang_1 = require("../../lang");
|
|
10
11
|
const buildCosInstanceFromProvider = (info, sid) => {
|
|
11
12
|
return {
|
|
12
13
|
sid,
|
|
@@ -81,7 +82,10 @@ const createBucketResource = async (context, bucket, state) => {
|
|
|
81
82
|
];
|
|
82
83
|
let cnameInfo;
|
|
83
84
|
if (bucket.website?.domain) {
|
|
84
|
-
logger_1.logger.info(
|
|
85
|
+
logger_1.logger.info(lang_1.lang.__('BINDING_CUSTOM_DOMAIN_TO_BUCKET', {
|
|
86
|
+
domain: bucket.website.domain,
|
|
87
|
+
bucketName: bucket.name,
|
|
88
|
+
}));
|
|
85
89
|
cnameInfo = await client.cos.bindCustomDomain(bucket.name, bucket.website.domain);
|
|
86
90
|
if (cnameInfo) {
|
|
87
91
|
const instanceId = cnameInfo.dnsRecordId ?? bucket.website.domain;
|
|
@@ -94,6 +98,11 @@ const createBucketResource = async (context, bucket, state) => {
|
|
|
94
98
|
...(cnameInfo.dnsRecordId ? { dnsRecordId: cnameInfo.dnsRecordId } : {}),
|
|
95
99
|
};
|
|
96
100
|
instances.push(dnsInstance);
|
|
101
|
+
// Refresh bucket info to capture auto-added CORS rule
|
|
102
|
+
const refreshedInfo = await client.cos.getBucket(bucket.name, context.region);
|
|
103
|
+
if (refreshedInfo) {
|
|
104
|
+
instances[0] = buildCosInstanceFromProvider(refreshedInfo, sid);
|
|
105
|
+
}
|
|
97
106
|
}
|
|
98
107
|
}
|
|
99
108
|
const resourceState = {
|
|
@@ -137,7 +146,10 @@ const updateBucketResource = async (context, bucket, state) => {
|
|
|
137
146
|
if (domainChanged && existingDnsInstance) {
|
|
138
147
|
await client.cos.unbindCustomDomain(bucket.name, existingDnsInstance.domain, existingDnsInstance.dnsRecordId);
|
|
139
148
|
}
|
|
140
|
-
logger_1.logger.info(
|
|
149
|
+
logger_1.logger.info(lang_1.lang.__('BINDING_CUSTOM_DOMAIN_TO_BUCKET', {
|
|
150
|
+
domain: bucket.website.domain,
|
|
151
|
+
bucketName: bucket.name,
|
|
152
|
+
}));
|
|
141
153
|
const cnameInfo = await client.cos.bindCustomDomain(bucket.name, bucket.website.domain);
|
|
142
154
|
if (cnameInfo) {
|
|
143
155
|
const instanceId = cnameInfo.dnsRecordId ?? bucket.website.domain;
|
|
@@ -150,6 +162,11 @@ const updateBucketResource = async (context, bucket, state) => {
|
|
|
150
162
|
...(cnameInfo.dnsRecordId ? { dnsRecordId: cnameInfo.dnsRecordId } : {}),
|
|
151
163
|
};
|
|
152
164
|
instances.push(dnsInstance);
|
|
165
|
+
// Refresh bucket info to capture auto-added CORS rule
|
|
166
|
+
const refreshedInfo = await client.cos.getBucket(bucket.name, context.region);
|
|
167
|
+
if (refreshedInfo) {
|
|
168
|
+
instances[0] = buildCosInstanceFromProvider(refreshedInfo, sid);
|
|
169
|
+
}
|
|
153
170
|
}
|
|
154
171
|
}
|
|
155
172
|
else if (existingDnsInstance) {
|
|
@@ -179,7 +196,7 @@ const deleteBucketResource = async (context, bucketName, region, logicalId, stat
|
|
|
179
196
|
const errorCode = err?.code;
|
|
180
197
|
const statusCode = err?.statusCode;
|
|
181
198
|
if (errorCode === 'NoSuchBucket' || statusCode === 404) {
|
|
182
|
-
logger_1.logger.warn(
|
|
199
|
+
logger_1.logger.warn(lang_1.lang.__('RESOURCE_NOT_FOUND_PROVIDER', { resourceType: 'Bucket', name: bucketName }));
|
|
183
200
|
}
|
|
184
201
|
else {
|
|
185
202
|
throw err;
|
|
@@ -43,7 +43,11 @@ const deployTencentStack = async (iac, backend) => {
|
|
|
43
43
|
};
|
|
44
44
|
common_1.logger.info(`${lang_1.lang.__('PLAN_GENERATED')}: ${combinedPlan.items.length} ${lang_1.lang.__('ACTIONS')}`);
|
|
45
45
|
combinedPlan.items.forEach((item) => {
|
|
46
|
-
common_1.logger.info(
|
|
46
|
+
common_1.logger.info(lang_1.lang.__('EXECUTION_PLAN_ITEM', {
|
|
47
|
+
action: item.action.toUpperCase(),
|
|
48
|
+
logicalId: item.logicalId,
|
|
49
|
+
resourceType: item.resourceType,
|
|
50
|
+
}));
|
|
47
51
|
});
|
|
48
52
|
common_1.logger.info(lang_1.lang.__('EXECUTING_PLAN'));
|
|
49
53
|
const functionResult = await (0, scfExecutor_1.executeFunctionPlan)(context, functionPlan, iac.functions, state, onStateChange);
|
|
@@ -42,7 +42,11 @@ const destroyTencentStack = async (backend) => {
|
|
|
42
42
|
};
|
|
43
43
|
common_1.logger.info(`${lang_1.lang.__('PLAN_GENERATED')}: ${combinedPlan.items.length} ${lang_1.lang.__('ACTIONS')}`);
|
|
44
44
|
combinedPlan.items.forEach((item) => {
|
|
45
|
-
common_1.logger.info(
|
|
45
|
+
common_1.logger.info(lang_1.lang.__('EXECUTION_PLAN_ITEM', {
|
|
46
|
+
action: item.action.toUpperCase(),
|
|
47
|
+
logicalId: item.logicalId,
|
|
48
|
+
resourceType: item.resourceType,
|
|
49
|
+
}));
|
|
46
50
|
});
|
|
47
51
|
const functionResult = await (0, scfExecutor_1.executeFunctionPlan)(context, functionPlan, undefined, state, onStateChange);
|
|
48
52
|
state = functionResult.state;
|
|
@@ -6,21 +6,33 @@ const common_1 = require("../../common");
|
|
|
6
6
|
const stateManager_1 = require("../../common/stateManager");
|
|
7
7
|
const lang_1 = require("../../lang");
|
|
8
8
|
const executeCreateAction = async (context, database, currentState) => {
|
|
9
|
-
common_1.logger.info(
|
|
9
|
+
common_1.logger.info(lang_1.lang.__('CREATING_RESOURCE', {
|
|
10
|
+
resourceType: 'Tencent ES serverless space',
|
|
11
|
+
name: database.name,
|
|
12
|
+
}));
|
|
10
13
|
const newState = await (0, esServerlessResource_1.createEsResource)(context, database, currentState);
|
|
11
|
-
common_1.logger.info(
|
|
14
|
+
common_1.logger.info(lang_1.lang.__('RESOURCE_CREATED', {
|
|
15
|
+
resourceType: 'Tencent ES serverless space',
|
|
16
|
+
name: database.name,
|
|
17
|
+
}));
|
|
12
18
|
return newState;
|
|
13
19
|
};
|
|
14
20
|
const executeUpdateAction = async (context, database, spaceId, currentState) => {
|
|
15
|
-
common_1.logger.info(
|
|
21
|
+
common_1.logger.info(lang_1.lang.__('UPDATING_RESOURCE', {
|
|
22
|
+
resourceType: 'Tencent ES serverless space',
|
|
23
|
+
name: database.name,
|
|
24
|
+
}));
|
|
16
25
|
const newState = await (0, esServerlessResource_1.updateEsResource)(context, database, spaceId, currentState);
|
|
17
|
-
common_1.logger.info(
|
|
26
|
+
common_1.logger.info(lang_1.lang.__('RESOURCE_UPDATED', {
|
|
27
|
+
resourceType: 'Tencent ES serverless space',
|
|
28
|
+
name: database.name,
|
|
29
|
+
}));
|
|
18
30
|
return newState;
|
|
19
31
|
};
|
|
20
32
|
const executeDeleteAction = async (context, spaceId, logicalId, currentState) => {
|
|
21
|
-
common_1.logger.info(
|
|
33
|
+
common_1.logger.info(lang_1.lang.__('DELETING_RESOURCE', { resourceType: 'Tencent ES serverless space', name: spaceId }));
|
|
22
34
|
const newState = await (0, esServerlessResource_1.deleteEsResource)(context, spaceId, logicalId, currentState);
|
|
23
|
-
common_1.logger.info(
|
|
35
|
+
common_1.logger.info(lang_1.lang.__('RESOURCE_DELETED', { resourceType: 'Tencent ES serverless space', name: spaceId }));
|
|
24
36
|
return newState;
|
|
25
37
|
};
|
|
26
38
|
const executeSingleItem = async (context, item, databasesMap, currentState) => {
|
|
@@ -29,7 +41,7 @@ const executeSingleItem = async (context, item, databasesMap, currentState) => {
|
|
|
29
41
|
}
|
|
30
42
|
switch (item.action) {
|
|
31
43
|
case 'noop':
|
|
32
|
-
common_1.logger.info(
|
|
44
|
+
common_1.logger.info(lang_1.lang.__('NO_CHANGESForResource', { logicalId: item.logicalId }));
|
|
33
45
|
return null;
|
|
34
46
|
case 'create': {
|
|
35
47
|
const database = databasesMap.get(item.logicalId);
|
|
@@ -56,7 +68,7 @@ const executeSingleItem = async (context, item, databasesMap, currentState) => {
|
|
|
56
68
|
case 'delete': {
|
|
57
69
|
const state = (0, stateManager_1.getResource)(currentState, item.logicalId);
|
|
58
70
|
if (!state) {
|
|
59
|
-
common_1.logger.warn(
|
|
71
|
+
common_1.logger.warn(lang_1.lang.__('STATE_NOT_FOUND_SKIPPING', { logicalId: item.logicalId }));
|
|
60
72
|
return null;
|
|
61
73
|
}
|
|
62
74
|
const spaceId = state.metadata?.spaceId || state.instances?.[0]?.id;
|
|
@@ -66,7 +78,7 @@ const executeSingleItem = async (context, item, databasesMap, currentState) => {
|
|
|
66
78
|
return executeDeleteAction(context, spaceId, item.logicalId, currentState);
|
|
67
79
|
}
|
|
68
80
|
default:
|
|
69
|
-
common_1.logger.warn(
|
|
81
|
+
common_1.logger.warn(lang_1.lang.__('UNKNOWN_ACTION_FOR_RESOURCE', { action: item.action, logicalId: item.logicalId }));
|
|
70
82
|
return null;
|
|
71
83
|
}
|
|
72
84
|
};
|
|
@@ -6,6 +6,7 @@ const esServerlessTypes_1 = require("./esServerlessTypes");
|
|
|
6
6
|
const stateManager_1 = require("../../common/stateManager");
|
|
7
7
|
const common_1 = require("../../common");
|
|
8
8
|
const logger_1 = require("../../common/logger");
|
|
9
|
+
const lang_1 = require("../../lang");
|
|
9
10
|
const buildEsSpaceFromProvider = (info, sid) => {
|
|
10
11
|
return {
|
|
11
12
|
sid,
|
|
@@ -96,7 +97,7 @@ const deleteEsResource = async (context, spaceId, logicalId, state) => {
|
|
|
96
97
|
catch (err) {
|
|
97
98
|
const errorCode = err?.code;
|
|
98
99
|
if (errorCode === 'ResourceNotFound' || errorCode === 'InvalidParameterValue') {
|
|
99
|
-
logger_1.logger.warn(
|
|
100
|
+
logger_1.logger.warn(lang_1.lang.__('RESOURCE_NOT_FOUND_PROVIDER', { resourceType: 'ES space', name: spaceId }));
|
|
100
101
|
}
|
|
101
102
|
else {
|
|
102
103
|
throw err;
|