@geek-fun/serverlessinsight 0.5.8 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +372 -0
- package/README.md +2 -2
- package/README.zh-CN.md +11 -8
- package/dist/package.json +3 -1
- package/dist/src/commands/index.js +5 -4
- package/dist/src/common/aliyunClient/apigwOperations.js +96 -9
- package/dist/src/common/aliyunClient/casOperations.js +116 -0
- package/dist/src/common/aliyunClient/index.js +8 -0
- package/dist/src/common/aliyunClient/ossOperations.js +61 -4
- package/dist/src/common/aliyunClient/ramOperations.js +65 -20
- package/dist/src/common/certificateResolver.js +63 -0
- package/dist/src/common/iacHelper.js +9 -1
- package/dist/src/common/index.js +1 -0
- package/dist/src/common/tencentClient/index.js +18 -0
- package/dist/src/common/tencentClient/sslOperations.js +107 -0
- package/dist/src/lang/en.js +169 -0
- package/dist/src/lang/index.js +6 -0
- package/dist/src/lang/zh-CN.js +167 -0
- package/dist/src/parser/bucketParser.js +19 -1
- package/dist/src/parser/certificateParser.js +23 -0
- package/dist/src/parser/index.js +2 -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 +44 -17
- package/dist/src/stack/aliyunStack/apigwTypes.js +36 -5
- 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 +48 -5
- package/dist/src/stack/aliyunStack/tablestoreExecutor.js +21 -9
- package/dist/src/stack/localStack/event.js +1 -1
- package/dist/src/stack/scfStack/cosExecutor.js +9 -9
- package/dist/src/stack/scfStack/cosResource.js +45 -7
- 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/types/domains/certificate.js +2 -0
- package/dist/src/types/index.js +1 -0
- package/dist/src/validator/bucketSchema.js +27 -1
- package/dist/src/validator/certificateSchema.js +31 -0
- package/dist/src/validator/eventSchema.js +12 -0
- package/dist/src/validator/iacSchema.js +2 -0
- package/dist/src/validator/rootSchema.js +3 -0
- package/dist/src/validator/templateRefSchema.js +3 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -1
|
@@ -5,6 +5,8 @@ const aliyunClient_1 = require("../../common/aliyunClient");
|
|
|
5
5
|
const apigwTypes_1 = require("./apigwTypes");
|
|
6
6
|
const stateManager_1 = require("../../common/stateManager");
|
|
7
7
|
const hashUtils_1 = require("../../common/hashUtils");
|
|
8
|
+
const DNS_SUB_RESOURCE_SUFFIXES = ['.dns_verification', '.dns_txt_verification'];
|
|
9
|
+
const isDnsSubResource = (logicalId) => DNS_SUB_RESOURCE_SUFFIXES.some((suffix) => logicalId.endsWith(suffix));
|
|
8
10
|
const planEventDeletion = (logicalId, definition) => ({
|
|
9
11
|
logicalId,
|
|
10
12
|
action: 'delete',
|
|
@@ -19,7 +21,7 @@ const generateApigwPlan = async (context, state, events, serviceName) => {
|
|
|
19
21
|
if (!events || events.length === 0) {
|
|
20
22
|
const allStates = (0, stateManager_1.getAllResources)(state);
|
|
21
23
|
const items = Object.entries(allStates)
|
|
22
|
-
.filter(([logicalId]) => logicalId.startsWith('events.'))
|
|
24
|
+
.filter(([logicalId]) => logicalId.startsWith('events.') && !isDnsSubResource(logicalId))
|
|
23
25
|
.map(([logicalId, resourceState]) => planEventDeletion(logicalId, resourceState.definition));
|
|
24
26
|
return { items };
|
|
25
27
|
}
|
|
@@ -111,7 +113,18 @@ const generateApigwPlan = async (context, state, events, serviceName) => {
|
|
|
111
113
|
// Find resources in state that are no longer in config
|
|
112
114
|
const allStates = (0, stateManager_1.getAllResources)(state);
|
|
113
115
|
const deletionItems = Object.entries(allStates)
|
|
114
|
-
.filter(([logicalId]) =>
|
|
116
|
+
.filter(([logicalId]) => {
|
|
117
|
+
if (!logicalId.startsWith('events.')) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
if (desiredLogicalIds.has(logicalId)) {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
if (isDnsSubResource(logicalId)) {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
return true;
|
|
127
|
+
})
|
|
115
128
|
.map(([logicalId, resourceState]) => planEventDeletion(logicalId, resourceState.definition));
|
|
116
129
|
return { items: [...eventItems, ...deletionItems] };
|
|
117
130
|
};
|
|
@@ -56,6 +56,43 @@ const buildApigwDeploymentInstance = (groupId, apiId, stageName, stage) => {
|
|
|
56
56
|
stageName,
|
|
57
57
|
};
|
|
58
58
|
};
|
|
59
|
+
const resolveDomainCertificate = async (domain, context, client) => {
|
|
60
|
+
if (domain.certificate) {
|
|
61
|
+
if (!context.iac) {
|
|
62
|
+
throw new Error(lang_1.lang.__('CERT_REFERENCE_NOT_FOUND', { reference: String(domain.certificate) }));
|
|
63
|
+
}
|
|
64
|
+
const certDef = (0, common_1.getIacDefinition)(context.iac, domain.certificate);
|
|
65
|
+
if (!certDef || !(0, common_1.isCertificateDomain)(certDef)) {
|
|
66
|
+
throw new Error(lang_1.lang.__('CERT_REFERENCE_NOT_FOUND', { reference: String(domain.certificate) }));
|
|
67
|
+
}
|
|
68
|
+
const resolved = await (0, common_1.resolveCertificateDomain)(certDef, async (certId) => {
|
|
69
|
+
const detail = await client.cas.getCertificate(certId);
|
|
70
|
+
if (!detail)
|
|
71
|
+
return null;
|
|
72
|
+
return { cert: detail.cert, key: detail.key };
|
|
73
|
+
});
|
|
74
|
+
return {
|
|
75
|
+
certificateName: resolved.certificateName,
|
|
76
|
+
certificateBody: resolved.certificateBody,
|
|
77
|
+
certificatePrivateKey: resolved.certificatePrivateKey,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
certificateName: domain.certificate_name,
|
|
82
|
+
certificateBody: domain.certificate_body,
|
|
83
|
+
certificatePrivateKey: domain.certificate_private_key,
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
const buildDomainBindingConfig = async (domain, groupId, context, client) => {
|
|
87
|
+
const certConfig = await resolveDomainCertificate(domain, context, client);
|
|
88
|
+
const protocolConfig = (0, apigwTypes_1.inferProtocolConfig)(domain.protocol);
|
|
89
|
+
return {
|
|
90
|
+
groupId,
|
|
91
|
+
domainName: domain.domain_name,
|
|
92
|
+
isHttpRedirectToHttps: protocolConfig.isHttpRedirectToHttps,
|
|
93
|
+
...certConfig,
|
|
94
|
+
};
|
|
95
|
+
};
|
|
59
96
|
const createApigwResource = async (context, event, serviceName, roleArn, state) => {
|
|
60
97
|
const logicalId = `events.${event.key}`;
|
|
61
98
|
const client = (0, aliyunClient_1.createAliyunClient)(context);
|
|
@@ -147,13 +184,8 @@ const createApigwResource = async (context, event, serviceName, roleArn, state)
|
|
|
147
184
|
}
|
|
148
185
|
if (event.domain) {
|
|
149
186
|
try {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
domainName: event.domain.domain_name,
|
|
153
|
-
certificateName: event.domain.certificate_name,
|
|
154
|
-
certificateBody: event.domain.certificate_body,
|
|
155
|
-
certificatePrivateKey: event.domain.certificate_private_key,
|
|
156
|
-
}, state, logicalId);
|
|
187
|
+
const domainConfig = await buildDomainBindingConfig(event.domain, groupId, context, client);
|
|
188
|
+
state = await client.apigw.bindCustomDomain(domainConfig, state, logicalId);
|
|
157
189
|
}
|
|
158
190
|
catch (error) {
|
|
159
191
|
logger_1.logger.error(lang_1.lang.__('APIGW_DOMAIN_BINDING_FAILED', { error: String(error) }));
|
|
@@ -267,13 +299,8 @@ const updateApigwResource = async (context, event, serviceName, roleArn, state)
|
|
|
267
299
|
}
|
|
268
300
|
}
|
|
269
301
|
if (event.domain) {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
domainName: event.domain.domain_name,
|
|
273
|
-
certificateName: event.domain.certificate_name,
|
|
274
|
-
certificateBody: event.domain.certificate_body,
|
|
275
|
-
certificatePrivateKey: event.domain.certificate_private_key,
|
|
276
|
-
}, state, logicalId);
|
|
302
|
+
const domainConfig = await buildDomainBindingConfig(event.domain, groupId, context, client);
|
|
303
|
+
state = await client.apigw.bindCustomDomain(domainConfig, state, logicalId);
|
|
277
304
|
}
|
|
278
305
|
const groupDefinition = (0, apigwTypes_1.extractApigwGroupDefinition)(groupConfig);
|
|
279
306
|
const resourceState = {
|
|
@@ -360,13 +387,13 @@ const cleanupDnsRecords = async (context, eventLogicalId, state) => {
|
|
|
360
387
|
// Only delete if recordId is not 'existing' (which means we didn't create it)
|
|
361
388
|
if (recordId && recordId !== 'existing') {
|
|
362
389
|
try {
|
|
363
|
-
logger_1.logger.info(
|
|
390
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_DNS_RECORD', { recordId }));
|
|
364
391
|
await client.dns.deleteDomainRecord(recordId);
|
|
365
|
-
logger_1.logger.info(
|
|
392
|
+
logger_1.logger.info(lang_1.lang.__('DNS_RECORD_DELETED', { recordId }));
|
|
366
393
|
}
|
|
367
394
|
catch (error) {
|
|
368
395
|
// DNS record might already be deleted or not accessible
|
|
369
|
-
logger_1.logger.warn(
|
|
396
|
+
logger_1.logger.warn(lang_1.lang.__('FAILED_TO_DELETE_DNS_RECORD', { recordId, error: String(error) }));
|
|
370
397
|
}
|
|
371
398
|
}
|
|
372
399
|
state = (0, stateManager_1.removeResource)(state, dnsResourceId);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractApigwDeploymentDefinition = exports.extractApigwApiDefinition = exports.extractApigwGroupDefinition = exports.triggerToApigwApiConfig = exports.generateApiKey = exports.eventToApigwGroupConfig = void 0;
|
|
3
|
+
exports.inferProtocolConfig = exports.extractApigwDeploymentDefinition = exports.extractApigwApiDefinition = exports.extractApigwGroupDefinition = exports.triggerToApigwApiConfig = exports.generateApiKey = exports.eventToApigwGroupConfig = void 0;
|
|
4
4
|
const common_1 = require("../../common");
|
|
5
|
+
const lang_1 = require("../../lang");
|
|
5
6
|
/**
|
|
6
7
|
* Convert EventDomain to API Gateway group config
|
|
7
8
|
*/
|
|
@@ -34,18 +35,18 @@ const resolveFunctionReference = (backendRef) => {
|
|
|
34
35
|
// Get IAC from context
|
|
35
36
|
const context = (0, common_1.getContext)();
|
|
36
37
|
if (!context.iac) {
|
|
37
|
-
common_1.logger.warn(
|
|
38
|
+
common_1.logger.warn(lang_1.lang.__('CANNOT_RESOLVE_FUNCTION_REF', { backendRef }));
|
|
38
39
|
return backendRef;
|
|
39
40
|
}
|
|
40
41
|
// Use getIacDefinition to resolve function references
|
|
41
42
|
const functionDef = (0, common_1.getIacDefinition)(context.iac, backendRef);
|
|
42
|
-
if (!functionDef) {
|
|
43
|
+
if (!functionDef || !(0, common_1.isFunctionDomain)(functionDef)) {
|
|
43
44
|
// Not a function reference or function not found, return as is
|
|
44
|
-
common_1.logger.warn(
|
|
45
|
+
common_1.logger.warn(lang_1.lang.__('FUNCTION_REF_NOT_RESOLVED', { backendRef }));
|
|
45
46
|
return backendRef;
|
|
46
47
|
}
|
|
47
48
|
const functionName = functionDef.name;
|
|
48
|
-
common_1.logger.info(
|
|
49
|
+
common_1.logger.info(lang_1.lang.__('RESOLVED_FUNCTION_REF', { backendRef, functionName }));
|
|
49
50
|
return functionName;
|
|
50
51
|
};
|
|
51
52
|
/**
|
|
@@ -123,3 +124,33 @@ const extractApigwDeploymentDefinition = (config) => {
|
|
|
123
124
|
};
|
|
124
125
|
};
|
|
125
126
|
exports.extractApigwDeploymentDefinition = extractApigwDeploymentDefinition;
|
|
127
|
+
/**
|
|
128
|
+
* Infer protocol and HTTP→HTTPS redirect from event domain protocol value.
|
|
129
|
+
*
|
|
130
|
+
* | Value | requestProtocol | isHttpRedirectToHttps |
|
|
131
|
+
* |---------------------|-----------------|-----------------------|
|
|
132
|
+
* | "HTTP" | "HTTP" | undefined |
|
|
133
|
+
* | "HTTPS" | "HTTPS" | true |
|
|
134
|
+
* | ["HTTP", "HTTPS"] | "HTTP,HTTPS" | false |
|
|
135
|
+
* | undefined (default) | "HTTP" | undefined |
|
|
136
|
+
*/
|
|
137
|
+
const inferProtocolConfig = (protocol) => {
|
|
138
|
+
if (!protocol) {
|
|
139
|
+
return { requestProtocol: 'HTTP' };
|
|
140
|
+
}
|
|
141
|
+
if (Array.isArray(protocol)) {
|
|
142
|
+
return {
|
|
143
|
+
requestProtocol: protocol.join(','),
|
|
144
|
+
isHttpRedirectToHttps: false,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
if (protocol === 'HTTPS') {
|
|
148
|
+
common_1.logger.info(lang_1.lang.__('PROTOCOL_INFERRED_REDIRECT', { protocol: 'HTTPS', redirect: 'true' }));
|
|
149
|
+
return {
|
|
150
|
+
requestProtocol: 'HTTPS',
|
|
151
|
+
isHttpRedirectToHttps: true,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
return { requestProtocol: protocol };
|
|
155
|
+
};
|
|
156
|
+
exports.inferProtocolConfig = inferProtocolConfig;
|
|
@@ -8,23 +8,38 @@ const lang_1 = require("../../lang");
|
|
|
8
8
|
const getResourceTypeName = (resourceType) => resourceType === 'ALIYUN_ES_SERVERLESS' ? 'Elasticsearch Serverless' : 'RDS Serverless';
|
|
9
9
|
const executeCreateAction = async (context, database, resourceType, currentState) => {
|
|
10
10
|
const resourceTypeName = getResourceTypeName(resourceType);
|
|
11
|
-
common_1.logger.info(
|
|
11
|
+
common_1.logger.info(lang_1.lang.__('CREATING_RESOURCE', {
|
|
12
|
+
resourceType: `${resourceTypeName} database`,
|
|
13
|
+
name: database.name,
|
|
14
|
+
}));
|
|
12
15
|
const newState = await (0, databaseResource_1.createDatabaseResource)(context, database, currentState);
|
|
13
|
-
common_1.logger.info(
|
|
16
|
+
common_1.logger.info(lang_1.lang.__('RESOURCE_CREATED', {
|
|
17
|
+
resourceType: `${resourceTypeName} database`,
|
|
18
|
+
name: database.name,
|
|
19
|
+
}));
|
|
14
20
|
return newState;
|
|
15
21
|
};
|
|
16
22
|
const executeUpdateAction = async (context, database, instanceId, resourceType, currentState) => {
|
|
17
23
|
const resourceTypeName = getResourceTypeName(resourceType);
|
|
18
|
-
common_1.logger.info(
|
|
24
|
+
common_1.logger.info(lang_1.lang.__('UPDATING_RESOURCE', {
|
|
25
|
+
resourceType: `${resourceTypeName} database`,
|
|
26
|
+
name: database.name,
|
|
27
|
+
}));
|
|
19
28
|
const newState = await (0, databaseResource_1.updateDatabaseResource)(context, database, instanceId, resourceType, currentState);
|
|
20
|
-
common_1.logger.info(
|
|
29
|
+
common_1.logger.info(lang_1.lang.__('RESOURCE_UPDATED', {
|
|
30
|
+
resourceType: `${resourceTypeName} database`,
|
|
31
|
+
name: database.name,
|
|
32
|
+
}));
|
|
21
33
|
return newState;
|
|
22
34
|
};
|
|
23
35
|
const executeDeleteAction = async (context, instanceId, resourceType, logicalId, currentState) => {
|
|
24
36
|
const resourceTypeName = getResourceTypeName(resourceType);
|
|
25
|
-
common_1.logger.info(
|
|
37
|
+
common_1.logger.info(lang_1.lang.__('DELETING_RESOURCE', {
|
|
38
|
+
resourceType: `${resourceTypeName} database`,
|
|
39
|
+
name: instanceId,
|
|
40
|
+
}));
|
|
26
41
|
const newState = await (0, databaseResource_1.deleteDatabaseResource)(context, instanceId, resourceType, logicalId, currentState);
|
|
27
|
-
common_1.logger.info(
|
|
42
|
+
common_1.logger.info(lang_1.lang.__('RESOURCE_DELETED', { resourceType: `${resourceTypeName} database`, name: instanceId }));
|
|
28
43
|
return newState;
|
|
29
44
|
};
|
|
30
45
|
const executeSingleItem = async (context, item, databasesMap, currentState) => {
|
|
@@ -34,7 +49,7 @@ const executeSingleItem = async (context, item, databasesMap, currentState) => {
|
|
|
34
49
|
}
|
|
35
50
|
switch (item.action) {
|
|
36
51
|
case 'noop':
|
|
37
|
-
common_1.logger.info(
|
|
52
|
+
common_1.logger.info(lang_1.lang.__('NO_CHANGESForResource', { logicalId: item.logicalId }));
|
|
38
53
|
return null;
|
|
39
54
|
case 'create': {
|
|
40
55
|
const database = databasesMap.get(item.logicalId);
|
|
@@ -62,7 +77,7 @@ const executeSingleItem = async (context, item, databasesMap, currentState) => {
|
|
|
62
77
|
case 'delete': {
|
|
63
78
|
const state = (0, stateManager_1.getResource)(currentState, item.logicalId);
|
|
64
79
|
if (!state) {
|
|
65
|
-
common_1.logger.warn(
|
|
80
|
+
common_1.logger.warn(lang_1.lang.__('STATE_NOT_FOUND_SKIPPING', { logicalId: item.logicalId }));
|
|
66
81
|
return null;
|
|
67
82
|
}
|
|
68
83
|
const instanceId = state.metadata?.instanceId || state.instances?.[0]?.id;
|
|
@@ -73,7 +88,7 @@ const executeSingleItem = async (context, item, databasesMap, currentState) => {
|
|
|
73
88
|
return executeDeleteAction(context, instanceId, resourceType, item.logicalId, currentState);
|
|
74
89
|
}
|
|
75
90
|
default:
|
|
76
|
-
common_1.logger.warn(
|
|
91
|
+
common_1.logger.warn(lang_1.lang.__('UNKNOWN_ACTION_FOR_RESOURCE', { action: item.action, logicalId: item.logicalId }));
|
|
77
92
|
return null;
|
|
78
93
|
}
|
|
79
94
|
};
|
|
@@ -7,6 +7,7 @@ const esServerlessTypes_1 = require("./esServerlessTypes");
|
|
|
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 buildRdsInstanceFromProvider = (info, sid) => {
|
|
11
12
|
return {
|
|
12
13
|
sid,
|
|
@@ -233,7 +234,10 @@ const deleteDatabaseResource = async (context, instanceId, resourceType, logical
|
|
|
233
234
|
errorCode === 'NotFound' ||
|
|
234
235
|
errorMessage.includes('not found') ||
|
|
235
236
|
errorMessage.includes('NotFound')) {
|
|
236
|
-
logger_1.logger.warn(
|
|
237
|
+
logger_1.logger.warn(lang_1.lang.__('RESOURCE_NOT_FOUND_PROVIDER', {
|
|
238
|
+
resourceType: 'Database resource',
|
|
239
|
+
name: instanceId,
|
|
240
|
+
}));
|
|
237
241
|
}
|
|
238
242
|
else {
|
|
239
243
|
throw err;
|
|
@@ -34,7 +34,12 @@ const logDependencyGraph = (orderedItems, dotGraph) => {
|
|
|
34
34
|
common_1.logger.info(lang_1.lang.__('DEPENDENCY_GRAPH_GENERATED'));
|
|
35
35
|
common_1.logger.info(` ${lang_1.lang.__('EXECUTION_ORDER')}:`);
|
|
36
36
|
orderedItems.forEach((item, index) => {
|
|
37
|
-
common_1.logger.info(
|
|
37
|
+
common_1.logger.info(lang_1.lang.__('EXECUTION_ORDER_ITEM', {
|
|
38
|
+
index: String(index + 1),
|
|
39
|
+
logicalId: item.logicalId,
|
|
40
|
+
resourceType: item.resourceType,
|
|
41
|
+
action: item.action,
|
|
42
|
+
}));
|
|
38
43
|
});
|
|
39
44
|
common_1.logger.debug(`${lang_1.lang.__('DOT_GRAPH_OUTPUT')}:\n${dotGraph}`);
|
|
40
45
|
};
|
|
@@ -70,7 +75,11 @@ const deployAliyunStack = async (iac, backend) => {
|
|
|
70
75
|
// Plan execution below still follows the fixed per-resource ordering.
|
|
71
76
|
common_1.logger.info(`${lang_1.lang.__('PLAN_GENERATED')}: ${allItems.length} ${lang_1.lang.__('ACTIONS')}`);
|
|
72
77
|
allItems.forEach((item) => {
|
|
73
|
-
common_1.logger.info(
|
|
78
|
+
common_1.logger.info(lang_1.lang.__('EXECUTION_PLAN_ITEM', {
|
|
79
|
+
action: item.action.toUpperCase(),
|
|
80
|
+
logicalId: item.logicalId,
|
|
81
|
+
resourceType: item.resourceType,
|
|
82
|
+
}));
|
|
74
83
|
});
|
|
75
84
|
common_1.logger.info(lang_1.lang.__('EXECUTING_PLAN'));
|
|
76
85
|
// Execute plans per resource type in a fixed order.
|
|
@@ -59,7 +59,11 @@ const destroyAliyunStack = async (backend) => {
|
|
|
59
59
|
};
|
|
60
60
|
common_1.logger.info(`${lang_1.lang.__('PLAN_GENERATED')}: ${combinedPlan.items.length} ${lang_1.lang.__('ACTIONS')}`);
|
|
61
61
|
combinedPlan.items.forEach((item) => {
|
|
62
|
-
common_1.logger.info(
|
|
62
|
+
common_1.logger.info(lang_1.lang.__('EXECUTION_PLAN_ITEM', {
|
|
63
|
+
action: item.action.toUpperCase(),
|
|
64
|
+
logicalId: item.logicalId,
|
|
65
|
+
resourceType: item.resourceType,
|
|
66
|
+
}));
|
|
63
67
|
});
|
|
64
68
|
// Delete events before functions (events depend on functions)
|
|
65
69
|
const roleArn = (0, common_1.getRoleArnFromState)(state);
|
|
@@ -5,28 +5,29 @@ const types_1 = require("../../types");
|
|
|
5
5
|
const fc3Resource_1 = require("./fc3Resource");
|
|
6
6
|
const common_1 = require("../../common");
|
|
7
7
|
const stateManager_1 = require("../../common/stateManager");
|
|
8
|
+
const lang_1 = require("../../lang");
|
|
8
9
|
const executeCreateAction = async (context, fn, currentState) => {
|
|
9
|
-
common_1.logger.info(
|
|
10
|
+
common_1.logger.info(lang_1.lang.__('CREATING_RESOURCE', { resourceType: 'function', name: fn.name }));
|
|
10
11
|
const newState = await (0, fc3Resource_1.createResource)(context, fn, currentState);
|
|
11
|
-
common_1.logger.info(
|
|
12
|
+
common_1.logger.info(lang_1.lang.__('RESOURCE_CREATED', { resourceType: 'function', name: fn.name }));
|
|
12
13
|
return newState;
|
|
13
14
|
};
|
|
14
15
|
const executeUpdateAction = async (context, fn, currentState) => {
|
|
15
|
-
common_1.logger.info(
|
|
16
|
+
common_1.logger.info(lang_1.lang.__('UPDATING_RESOURCE', { resourceType: 'function', name: fn.name }));
|
|
16
17
|
const newState = await (0, fc3Resource_1.updateResource)(context, fn, currentState);
|
|
17
|
-
common_1.logger.info(
|
|
18
|
+
common_1.logger.info(lang_1.lang.__('RESOURCE_UPDATED', { resourceType: 'function', name: fn.name }));
|
|
18
19
|
return newState;
|
|
19
20
|
};
|
|
20
21
|
const executeDeleteAction = async (context, functionName, logicalId, currentState) => {
|
|
21
|
-
common_1.logger.info(
|
|
22
|
+
common_1.logger.info(lang_1.lang.__('DELETING_RESOURCE', { resourceType: 'function', name: functionName }));
|
|
22
23
|
const newState = await (0, fc3Resource_1.deleteResource)(context, functionName, logicalId, currentState);
|
|
23
|
-
common_1.logger.info(
|
|
24
|
+
common_1.logger.info(lang_1.lang.__('RESOURCE_DELETED', { resourceType: 'function', name: functionName }));
|
|
24
25
|
return newState;
|
|
25
26
|
};
|
|
26
27
|
const executeSingleItem = async (context, item, functionsMap, currentState) => {
|
|
27
28
|
switch (item.action) {
|
|
28
29
|
case 'noop':
|
|
29
|
-
common_1.logger.info(
|
|
30
|
+
common_1.logger.info(lang_1.lang.__('NO_CHANGESForResource', { logicalId: item.logicalId }));
|
|
30
31
|
return null;
|
|
31
32
|
case 'create': {
|
|
32
33
|
const fn = functionsMap.get(item.logicalId);
|
|
@@ -45,14 +46,14 @@ const executeSingleItem = async (context, item, functionsMap, currentState) => {
|
|
|
45
46
|
case 'delete': {
|
|
46
47
|
const state = (0, stateManager_1.getResource)(currentState, item.logicalId);
|
|
47
48
|
if (!state) {
|
|
48
|
-
common_1.logger.warn(
|
|
49
|
+
common_1.logger.warn(lang_1.lang.__('STATE_NOT_FOUND_SKIPPING', { logicalId: item.logicalId }));
|
|
49
50
|
return null;
|
|
50
51
|
}
|
|
51
52
|
const functionName = state.definition.functionName;
|
|
52
53
|
return executeDeleteAction(context, functionName, item.logicalId, currentState);
|
|
53
54
|
}
|
|
54
55
|
default:
|
|
55
|
-
common_1.logger.warn(
|
|
56
|
+
common_1.logger.warn(lang_1.lang.__('UNKNOWN_ACTION_FOR_RESOURCE', { action: item.action, logicalId: item.logicalId }));
|
|
56
57
|
return null;
|
|
57
58
|
}
|
|
58
59
|
};
|
|
@@ -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;
|