@geek-fun/serverlessinsight 0.8.2 → 0.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.serverlessinsight/state-cdn-flow-app-cdn-flow-service.json.backup +15 -0
- package/.serverlessinsight/state-iam-test-app-iam-test-service.json.backup +33 -0
- package/.serverlessinsight/state-insight-poc-deploy-app-insight-poc-deploy.json.backup +359 -0
- package/.serverlessinsight/state-insight-poc-destroy-app-insight-poc-destroy.json.backup +15 -0
- package/.serverlessinsight/state-insight-volc-app-insight-volc.json.backup +154 -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 +5 -2
- 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 +363 -30
- 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 +90 -28
- package/dist/src/common/aliyunClient/tablestoreOperations.js +25 -22
- package/dist/src/common/apiClient.js +102 -0
- package/dist/src/common/constants.js +13 -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 +10 -4
- package/dist/src/common/stateBackend/saasStateBackend.js +266 -0
- package/dist/src/common/stateManager.js +186 -14
- package/dist/src/common/tencentClient/clsOperations.js +137 -0
- 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 +43 -2
- package/dist/src/common/tencentClient/scfOperations.js +266 -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 +91 -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 +305 -171
- package/dist/src/common/volcengineClient/tosOperations.js +78 -19
- package/dist/src/common/volcengineClient/vefaasOperations.js +272 -54
- package/dist/src/lang/en.js +107 -1
- package/dist/src/lang/zh-CN.js +107 -1
- 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 +16 -10
- package/dist/src/stack/aliyunStack/apigwResource.js +334 -125
- package/dist/src/stack/aliyunStack/apigwTypes.js +35 -4
- 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 +27 -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 +416 -94
- 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/sharedLogProject.js +137 -0
- 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 +58 -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 +15 -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 +21 -3
- package/dist/src/stack/scfStack/scfResource.js +686 -24
- package/dist/src/stack/scfStack/scfTypes.js +6 -0
- package/dist/src/stack/scfStack/sharedLogset.js +126 -0
- 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 +434 -222
- package/dist/src/stack/volcengineStack/apigwTypes.js +85 -66
- package/dist/src/stack/volcengineStack/deployer.js +49 -14
- package/dist/src/stack/volcengineStack/destroyer.js +13 -1
- package/dist/src/stack/volcengineStack/index.js +1 -2
- package/dist/src/stack/volcengineStack/sharedLogProject.js +190 -0
- 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 +78 -2
- package/dist/src/stack/volcengineStack/vefaasResource.js +194 -144
- 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 +32 -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 +5 -2
|
@@ -1,32 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractEventDomainDefinition = exports.
|
|
3
|
+
exports.resolveFunctionReference = exports.buildEventResourceDefinition = exports.extractEventDomainDefinition = exports.triggerToApigwRouteConfig = exports.triggerToApigwUpstreamConfig = exports.eventToApigwServiceConfig = exports.eventToApigwGatewayConfig = exports.resolveFunctionKey = exports.buildRouteName = exports.buildUpstreamName = exports.buildServiceName = exports.buildGatewayName = void 0;
|
|
4
4
|
const common_1 = require("../../common");
|
|
5
5
|
const lang_1 = require("../../lang");
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Gateway instance name — reused for find-by-name adoption across deploys.
|
|
8
8
|
*/
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
const buildGatewayName = (serviceName, stage) => `${serviceName}-${stage}-apigw`.replace(/_/g, '-');
|
|
10
|
+
exports.buildGatewayName = buildGatewayName;
|
|
11
|
+
const buildServiceName = (event, stage) => `${event.name}-${stage}-service`.replace(/_/g, '-');
|
|
12
|
+
exports.buildServiceName = buildServiceName;
|
|
13
|
+
const buildUpstreamName = (event, backendRef, stage) => {
|
|
14
|
+
const fnKey = (0, exports.resolveFunctionKey)(backendRef);
|
|
15
|
+
return `${event.name}-${stage}-upstream-${fnKey.replace(/_/g, '-')}`;
|
|
15
16
|
};
|
|
16
|
-
exports.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
*/
|
|
21
|
-
const generateApiKey = (method, path) => {
|
|
22
|
-
const sanitizedPath = path
|
|
23
|
-
.replace(/\//g, '__')
|
|
17
|
+
exports.buildUpstreamName = buildUpstreamName;
|
|
18
|
+
const buildRouteName = (event, method, path) => {
|
|
19
|
+
const sanitized = path
|
|
20
|
+
.replace(/\//g, '_')
|
|
24
21
|
.replace(/[^a-zA-Z0-9_]/g, '_')
|
|
25
|
-
.replace(/^
|
|
26
|
-
|
|
27
|
-
return `${method}_${sanitizedPath}`;
|
|
22
|
+
.replace(/^_+|_+$/g, '');
|
|
23
|
+
return `${event.name}-${method}_${sanitized}`.replace(/_/g, '-').slice(0, 63);
|
|
28
24
|
};
|
|
29
|
-
exports.
|
|
25
|
+
exports.buildRouteName = buildRouteName;
|
|
30
26
|
/**
|
|
31
27
|
* Resolves a function reference like ${functions.xxx} to the actual function name
|
|
32
28
|
*/
|
|
@@ -41,66 +37,89 @@ const resolveFunctionReference = (backendRef) => {
|
|
|
41
37
|
common_1.logger.warn(lang_1.lang.__('FUNCTION_REF_NOT_RESOLVED', { backendRef }));
|
|
42
38
|
return backendRef;
|
|
43
39
|
}
|
|
44
|
-
|
|
45
|
-
common_1.logger.info(lang_1.lang.__('RESOLVED_FUNCTION_REF', { backendRef, functionName }));
|
|
46
|
-
return functionName;
|
|
40
|
+
return functionDef.name;
|
|
47
41
|
};
|
|
42
|
+
exports.resolveFunctionReference = resolveFunctionReference;
|
|
48
43
|
/**
|
|
49
|
-
*
|
|
44
|
+
* Extracts the function key (e.g. 'api_function') from a ${functions.xxx} backend ref.
|
|
50
45
|
*/
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
46
|
+
const resolveFunctionKey = (backendRef) => {
|
|
47
|
+
const match = /^\$\{functions\.([\w.]+)}$/.exec(String(backendRef ?? ''));
|
|
48
|
+
return match?.[1] ?? backendRef;
|
|
49
|
+
};
|
|
50
|
+
exports.resolveFunctionKey = resolveFunctionKey;
|
|
51
|
+
const eventToApigwGatewayConfig = (event, serviceName, stage, ownershipValue) => {
|
|
52
|
+
return {
|
|
53
|
+
gatewayName: (0, exports.buildGatewayName)(serviceName, stage),
|
|
54
|
+
type: 'serverless',
|
|
55
|
+
...(event.network && {
|
|
56
|
+
network: { vpcId: event.network.vpc_id, subnetIds: event.network.subnet_ids },
|
|
57
|
+
}),
|
|
58
|
+
logConfig: event.log ? { enable: true, projectId: '', topicId: '' } : undefined,
|
|
59
|
+
Tags: [{ Key: 'si-owned-by', Value: ownershipValue }],
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
exports.eventToApigwGatewayConfig = eventToApigwGatewayConfig;
|
|
63
|
+
const eventToApigwServiceConfig = (event, serviceName, stage, gatewayId) => {
|
|
57
64
|
return {
|
|
58
65
|
gatewayId,
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
backendFunctionName: resolvedFunctionName,
|
|
63
|
-
backendType: 'veFaaS',
|
|
64
|
-
requestTimeout: 60,
|
|
66
|
+
serviceName: (0, exports.buildServiceName)(event, stage),
|
|
67
|
+
protocol: ['HTTP'],
|
|
68
|
+
description: `API Gateway for ${serviceName}`,
|
|
65
69
|
};
|
|
66
70
|
};
|
|
67
|
-
exports.
|
|
68
|
-
|
|
69
|
-
* Extract definition from API Gateway group config for state comparison
|
|
70
|
-
*/
|
|
71
|
-
const extractApigwGroupDefinition = (config) => {
|
|
71
|
+
exports.eventToApigwServiceConfig = eventToApigwServiceConfig;
|
|
72
|
+
const triggerToApigwUpstreamConfig = (event, trigger, serviceName, stage, gatewayId, functionId) => {
|
|
72
73
|
return {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
gatewayId,
|
|
75
|
+
upstreamName: (0, exports.buildUpstreamName)(event, String(trigger.backend), stage),
|
|
76
|
+
sourceType: 'VeFaas',
|
|
77
|
+
functionId,
|
|
78
|
+
protocol: 'HTTP',
|
|
76
79
|
};
|
|
77
80
|
};
|
|
78
|
-
exports.
|
|
79
|
-
|
|
80
|
-
* Extract definition from API Gateway API config for state comparison
|
|
81
|
-
*/
|
|
82
|
-
const extractApigwApiDefinition = (config) => {
|
|
81
|
+
exports.triggerToApigwUpstreamConfig = triggerToApigwUpstreamConfig;
|
|
82
|
+
const triggerToApigwRouteConfig = (event, trigger, serviceId, upstreamId) => {
|
|
83
83
|
return {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
method:
|
|
87
|
-
path:
|
|
88
|
-
|
|
89
|
-
backendType: config.backendType,
|
|
84
|
+
serviceId,
|
|
85
|
+
routeName: (0, exports.buildRouteName)(event, String(trigger.method), String(trigger.path)),
|
|
86
|
+
method: trigger.method,
|
|
87
|
+
path: String(trigger.path),
|
|
88
|
+
upstreamId,
|
|
90
89
|
};
|
|
91
90
|
};
|
|
92
|
-
exports.
|
|
93
|
-
const extractEventDomainDefinition = (
|
|
94
|
-
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
91
|
+
exports.triggerToApigwRouteConfig = triggerToApigwRouteConfig;
|
|
92
|
+
const extractEventDomainDefinition = (event) => {
|
|
93
|
+
const context = (0, common_1.getContext)();
|
|
97
94
|
return {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
95
|
+
gatewayName: event.name,
|
|
96
|
+
...(event.network && {
|
|
97
|
+
network: { vpcId: event.network.vpc_id, subnetIds: event.network.subnet_ids },
|
|
98
|
+
}),
|
|
99
|
+
logEnabled: event.log === true || event.log === 'true',
|
|
100
|
+
...(event.log && context
|
|
101
|
+
? {
|
|
102
|
+
logConfig: {
|
|
103
|
+
project: `${context.app}-${context.stage}-tls`,
|
|
104
|
+
topic: `${context.service}-${context.stage}-apigw-logs`,
|
|
105
|
+
},
|
|
106
|
+
}
|
|
107
|
+
: {}),
|
|
108
|
+
triggers: event.triggers.map((t) => ({
|
|
109
|
+
method: String(t.method),
|
|
110
|
+
path: String(t.path),
|
|
111
|
+
backend: String(t.backend),
|
|
112
|
+
})),
|
|
113
|
+
domain: event.domain
|
|
114
|
+
? {
|
|
115
|
+
domainName: event.domain.domain_name,
|
|
116
|
+
certificateId: event.domain.certificate_id,
|
|
117
|
+
}
|
|
118
|
+
: undefined,
|
|
104
119
|
};
|
|
105
120
|
};
|
|
106
121
|
exports.extractEventDomainDefinition = extractEventDomainDefinition;
|
|
122
|
+
const buildEventResourceDefinition = (event) => {
|
|
123
|
+
return (0, exports.extractEventDomainDefinition)(event);
|
|
124
|
+
};
|
|
125
|
+
exports.buildEventResourceDefinition = buildEventResourceDefinition;
|
|
@@ -9,13 +9,36 @@ const tosPlanner_1 = require("./tosPlanner");
|
|
|
9
9
|
const tosExecutor_1 = require("./tosExecutor");
|
|
10
10
|
const apigwPlanner_1 = require("./apigwPlanner");
|
|
11
11
|
const apigwExecutor_1 = require("./apigwExecutor");
|
|
12
|
+
// Volcengine error responses can echo large request payloads (e.g. the base64
|
|
13
|
+
// function code) in Error.Message — cap what reaches the user.
|
|
14
|
+
const truncateMessage = (message, max = 2000) => {
|
|
15
|
+
if (!message)
|
|
16
|
+
return '';
|
|
17
|
+
return message.length > max
|
|
18
|
+
? `${message.slice(0, max)}… (truncated ${message.length} chars)`
|
|
19
|
+
: message;
|
|
20
|
+
};
|
|
21
|
+
// Enrich cloud API errors with the action name + RequestId so users can open a
|
|
22
|
+
// support ticket / debug against the console. The message itself is truncated
|
|
23
|
+
// to avoid dumping base64 payloads, but the actionable bits are always shown.
|
|
24
|
+
const formatApiError = (error) => {
|
|
25
|
+
const err = error;
|
|
26
|
+
const parts = [truncateMessage(error.message)];
|
|
27
|
+
if (err.action && !err.message.includes(err.action)) {
|
|
28
|
+
parts.unshift(`Action: ${err.action}`);
|
|
29
|
+
}
|
|
30
|
+
if (err.requestId) {
|
|
31
|
+
parts.push(`RequestId: ${err.requestId}`);
|
|
32
|
+
}
|
|
33
|
+
return parts.join(' | ');
|
|
34
|
+
};
|
|
12
35
|
const deployVolcengineStack = async (iac, backend) => {
|
|
13
36
|
const context = (0, common_1.getContext)();
|
|
14
37
|
common_1.logger.info(lang_1.lang.__('DEPLOYING_STACK'));
|
|
15
38
|
let state = await backend.loadState('volcengine', iac.app, iac.service, context.stage);
|
|
16
|
-
const onStateChange = (newState) => {
|
|
39
|
+
const onStateChange = async (newState) => {
|
|
17
40
|
state = newState;
|
|
18
|
-
backend.saveState(state, iac.app, iac.service, context.stage);
|
|
41
|
+
await backend.saveState(state, iac.app, iac.service, context.stage);
|
|
19
42
|
};
|
|
20
43
|
common_1.logger.info(lang_1.lang.__('GENERATING_PLAN'));
|
|
21
44
|
const functionPlan = await (0, vefaasPlanner_1.generateFunctionPlan)(context, state, iac.functions);
|
|
@@ -25,10 +48,14 @@ const deployVolcengineStack = async (iac, backend) => {
|
|
|
25
48
|
if (bucketResult.partialFailure) {
|
|
26
49
|
const error = bucketResult.partialFailure.error;
|
|
27
50
|
error.isPartialFailure = true;
|
|
28
|
-
common_1.logger.error(lang_1.lang.__('
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
51
|
+
common_1.logger.error(`${lang_1.lang.__('FAILED_TO_EXECUTE_ACTION', {
|
|
52
|
+
action: bucketResult.partialFailure.failedItem.action,
|
|
53
|
+
logicalId: bucketResult.partialFailure.failedItem.logicalId,
|
|
54
|
+
error: formatApiError(error),
|
|
55
|
+
})}\n\n${lang_1.lang.__('PARTIAL_DEPLOYMENT_FAILURE', {
|
|
56
|
+
successCount: String(bucketResult.partialFailure.successfulItems.length),
|
|
57
|
+
failedResource: bucketResult.partialFailure.failedItem.logicalId,
|
|
58
|
+
})}`);
|
|
32
59
|
throw error;
|
|
33
60
|
}
|
|
34
61
|
state = bucketResult.state;
|
|
@@ -36,10 +63,14 @@ const deployVolcengineStack = async (iac, backend) => {
|
|
|
36
63
|
if (functionResult.partialFailure) {
|
|
37
64
|
const error = functionResult.partialFailure.error;
|
|
38
65
|
error.isPartialFailure = true;
|
|
39
|
-
common_1.logger.error(lang_1.lang.__('
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
66
|
+
common_1.logger.error(`${lang_1.lang.__('FAILED_TO_EXECUTE_ACTION', {
|
|
67
|
+
action: functionResult.partialFailure.failedItem.action,
|
|
68
|
+
logicalId: functionResult.partialFailure.failedItem.logicalId,
|
|
69
|
+
error: formatApiError(error),
|
|
70
|
+
})}\n\n${lang_1.lang.__('PARTIAL_DEPLOYMENT_FAILURE', {
|
|
71
|
+
successCount: String(functionResult.partialFailure.successfulItems.length),
|
|
72
|
+
failedResource: functionResult.partialFailure.failedItem.logicalId,
|
|
73
|
+
})}`);
|
|
43
74
|
throw error;
|
|
44
75
|
}
|
|
45
76
|
state = functionResult.state;
|
|
@@ -47,10 +78,14 @@ const deployVolcengineStack = async (iac, backend) => {
|
|
|
47
78
|
if (apigwResult.partialFailure) {
|
|
48
79
|
const error = apigwResult.partialFailure.error;
|
|
49
80
|
error.isPartialFailure = true;
|
|
50
|
-
common_1.logger.error(lang_1.lang.__('
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
81
|
+
common_1.logger.error(`${lang_1.lang.__('FAILED_TO_EXECUTE_ACTION', {
|
|
82
|
+
action: apigwResult.partialFailure.failedItem.action,
|
|
83
|
+
logicalId: apigwResult.partialFailure.failedItem.logicalId,
|
|
84
|
+
error: formatApiError(error),
|
|
85
|
+
})}\n\n${lang_1.lang.__('PARTIAL_DEPLOYMENT_FAILURE', {
|
|
86
|
+
successCount: String(apigwResult.partialFailure.successfulItems.length),
|
|
87
|
+
failedResource: apigwResult.partialFailure.failedItem.logicalId,
|
|
88
|
+
})}`);
|
|
54
89
|
throw error;
|
|
55
90
|
}
|
|
56
91
|
await backend.saveState(apigwResult.state, iac.app, iac.service, context.stage);
|
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.destroyVolcengineStack = void 0;
|
|
4
4
|
const common_1 = require("../../common");
|
|
5
|
+
const volcengineClient_1 = require("../../common/volcengineClient");
|
|
5
6
|
const stateManager_1 = require("../../common/stateManager");
|
|
6
7
|
const lang_1 = require("../../lang");
|
|
7
8
|
const tosResource_1 = require("./tosResource");
|
|
8
9
|
const vefaasResource_1 = require("./vefaasResource");
|
|
9
10
|
const apigwResource_1 = require("./apigwResource");
|
|
11
|
+
const sharedLogProject_1 = require("./sharedLogProject");
|
|
10
12
|
const destroyVolcengineStack = async (backend) => {
|
|
11
13
|
const context = (0, common_1.getContext)();
|
|
12
14
|
const providerName = common_1.ProviderEnum.VOLCENGINE;
|
|
@@ -17,7 +19,7 @@ const destroyVolcengineStack = async (backend) => {
|
|
|
17
19
|
let state = await backend.loadState(providerName, context.app, context.service, context.stage);
|
|
18
20
|
const allResources = (0, stateManager_1.getAllResources)(state);
|
|
19
21
|
const eventEntries = Object.entries(allResources).filter(([logicalId, resourceState]) => logicalId.startsWith('events.') &&
|
|
20
|
-
resourceState.instances?.some((i) => i.type === '
|
|
22
|
+
resourceState.instances?.some((i) => typeof i.type === 'string' && i.type.startsWith('VOLCENGINE_APIGW_')));
|
|
21
23
|
for (const [logicalId] of eventEntries) {
|
|
22
24
|
try {
|
|
23
25
|
common_1.logger.info(lang_1.lang.__('DELETING_RESOURCE', { resourceType: 'API Gateway', name: logicalId }));
|
|
@@ -67,6 +69,16 @@ const destroyVolcengineStack = async (backend) => {
|
|
|
67
69
|
}
|
|
68
70
|
}
|
|
69
71
|
}
|
|
72
|
+
// Release the shared TLS project once no topics reference it anymore. The
|
|
73
|
+
// per-resource teardowns above deleted their own topics, so a project with
|
|
74
|
+
// zero remaining topics is safe to delete.
|
|
75
|
+
const sharedProject = (0, stateManager_1.getSharedResource)(state, context.stage, 'logs.project');
|
|
76
|
+
if (sharedProject) {
|
|
77
|
+
const releaseResult = await (0, sharedLogProject_1.releaseSharedLogProjectIfUnused)(context, (0, volcengineClient_1.createVolcengineClient)(context), sharedProject);
|
|
78
|
+
if (releaseResult === 'deleted') {
|
|
79
|
+
state = (0, stateManager_1.removeSharedResource)(state, context.stage, 'logs.project');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
70
82
|
await backend.saveState(state, context.app, context.service, context.stage);
|
|
71
83
|
};
|
|
72
84
|
exports.destroyVolcengineStack = destroyVolcengineStack;
|
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.deleteApigwResource = exports.updateApigwResource = exports.
|
|
17
|
+
exports.deleteApigwResource = exports.updateApigwResource = exports.createApigwResource = exports.deleteTosResource = exports.updateTosResource = exports.readTosResource = exports.createTosResource = exports.deleteVefaasResource = exports.updateVefaasResource = exports.readVefaasResource = exports.createVefaasResource = void 0;
|
|
18
18
|
__exportStar(require("./planner"), exports);
|
|
19
19
|
__exportStar(require("./deployer"), exports);
|
|
20
20
|
__exportStar(require("./destroyer"), exports);
|
|
@@ -37,7 +37,6 @@ __exportStar(require("./tosExecutor"), exports);
|
|
|
37
37
|
__exportStar(require("./apigwTypes"), exports);
|
|
38
38
|
var apigwResource_1 = require("./apigwResource");
|
|
39
39
|
Object.defineProperty(exports, "createApigwResource", { enumerable: true, get: function () { return apigwResource_1.createApigwResource; } });
|
|
40
|
-
Object.defineProperty(exports, "readApigwResource", { enumerable: true, get: function () { return apigwResource_1.readApigwResource; } });
|
|
41
40
|
Object.defineProperty(exports, "updateApigwResource", { enumerable: true, get: function () { return apigwResource_1.updateApigwResource; } });
|
|
42
41
|
Object.defineProperty(exports, "deleteApigwResource", { enumerable: true, get: function () { return apigwResource_1.deleteApigwResource; } });
|
|
43
42
|
__exportStar(require("./apigwPlanner"), exports);
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deleteTlsLogResources = exports.ensureOwnedTopic = exports.releaseSharedLogProjectIfUnused = exports.buildSharedProjectResourceState = exports.ensureSharedLogProject = exports.buildSharedProjectName = exports.SHARED_LOG_PROJECT_KEY = void 0;
|
|
4
|
+
const common_1 = require("../../common");
|
|
5
|
+
const logger_1 = require("../../common/logger");
|
|
6
|
+
const lang_1 = require("../../lang");
|
|
7
|
+
const ownershipTag_1 = require("../ownershipTag");
|
|
8
|
+
/**
|
|
9
|
+
* Issue #214: one shared TLS project per app×stage, tracked in the stage-level
|
|
10
|
+
* `shared` slot under the provider-neutral key 'logs.project'. Per-resource
|
|
11
|
+
* topics stay nested under their owning resource (function/event) so each
|
|
12
|
+
* owner tears down only its own topic; the shared project is released by the
|
|
13
|
+
* destroyer once the provider reports zero remaining topics.
|
|
14
|
+
*/
|
|
15
|
+
exports.SHARED_LOG_PROJECT_KEY = 'logs.project';
|
|
16
|
+
const buildSharedProjectName = (app, stage) => `${app}-${stage}-tls`;
|
|
17
|
+
exports.buildSharedProjectName = buildSharedProjectName;
|
|
18
|
+
const resolveSharedProjectName = (shared) => {
|
|
19
|
+
const instanceId = shared.instances?.[0]?.id;
|
|
20
|
+
return instanceId ?? shared.definition?.projectName;
|
|
21
|
+
};
|
|
22
|
+
const ensureSharedLogProject = async (context, client, state) => {
|
|
23
|
+
const shared = state
|
|
24
|
+
? (0, common_1.getSharedResource)(state, context.stage, exports.SHARED_LOG_PROJECT_KEY)
|
|
25
|
+
: undefined;
|
|
26
|
+
if (shared) {
|
|
27
|
+
const projectName = resolveSharedProjectName(shared);
|
|
28
|
+
if (projectName) {
|
|
29
|
+
const existing = await client.tls.getProject(projectName);
|
|
30
|
+
if (existing?.projectId) {
|
|
31
|
+
const tags = await client.tls.getProjectTags(projectName);
|
|
32
|
+
if ((0, ownershipTag_1.isOwnedByApp)(context.app, exports.SHARED_LOG_PROJECT_KEY, tags)) {
|
|
33
|
+
return { projectName, projectId: existing.projectId };
|
|
34
|
+
}
|
|
35
|
+
throw new Error(lang_1.lang.__('TLS_SHARED_PROJECT_NOT_OWNED', { projectName }));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const projectName = (0, exports.buildSharedProjectName)(context.app, context.stage);
|
|
40
|
+
logger_1.logger.info(lang_1.lang.__('CREATING_TLS_PROJECT', { projectName }));
|
|
41
|
+
const project = await client.tls.createProject({
|
|
42
|
+
projectName,
|
|
43
|
+
description: `Shared TLS logs for ${context.app}`,
|
|
44
|
+
region: context.region,
|
|
45
|
+
});
|
|
46
|
+
await client.tls.waitForProject(projectName);
|
|
47
|
+
if (project.projectId) {
|
|
48
|
+
if (project.created === true) {
|
|
49
|
+
await client.tls.addTags({
|
|
50
|
+
resourceType: 'project',
|
|
51
|
+
resourcesList: [project.projectId],
|
|
52
|
+
tags: [
|
|
53
|
+
{
|
|
54
|
+
key: ownershipTag_1.OWNERSHIP_TAG_KEY,
|
|
55
|
+
value: (0, ownershipTag_1.buildSharedOwnershipTagValue)(context.app, exports.SHARED_LOG_PROJECT_KEY),
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
// A same-named project already existed (create race). Re-read and verify
|
|
62
|
+
// ownership before adopting — an untagged or foreign project must not be
|
|
63
|
+
// silently taken over.
|
|
64
|
+
const tags = await client.tls.getProjectTags(projectName);
|
|
65
|
+
if (!(0, ownershipTag_1.isOwnedByApp)(context.app, exports.SHARED_LOG_PROJECT_KEY, tags)) {
|
|
66
|
+
throw new Error(lang_1.lang.__('TLS_SHARED_PROJECT_NOT_OWNED', { projectName }));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return { projectName, projectId: project.projectId ?? '' };
|
|
71
|
+
};
|
|
72
|
+
exports.ensureSharedLogProject = ensureSharedLogProject;
|
|
73
|
+
const buildSharedProjectResourceState = (context, result) => ({
|
|
74
|
+
mode: 'managed',
|
|
75
|
+
region: context.region,
|
|
76
|
+
definition: {
|
|
77
|
+
projectName: result.projectName,
|
|
78
|
+
region: context.region,
|
|
79
|
+
stage: context.stage,
|
|
80
|
+
},
|
|
81
|
+
instances: [
|
|
82
|
+
{
|
|
83
|
+
sid: (0, common_1.buildSid)('volcengine', 'tls', context.stage, result.projectName),
|
|
84
|
+
type: 'VOLCENGINE_TLS_PROJECT',
|
|
85
|
+
id: result.projectName,
|
|
86
|
+
projectId: result.projectId,
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
lastUpdated: new Date().toISOString(),
|
|
90
|
+
});
|
|
91
|
+
exports.buildSharedProjectResourceState = buildSharedProjectResourceState;
|
|
92
|
+
const releaseSharedLogProjectIfUnused = async (context, client, shared) => {
|
|
93
|
+
if (!shared) {
|
|
94
|
+
return 'absent';
|
|
95
|
+
}
|
|
96
|
+
const projectName = resolveSharedProjectName(shared);
|
|
97
|
+
if (!projectName) {
|
|
98
|
+
return 'absent';
|
|
99
|
+
}
|
|
100
|
+
const project = await client.tls.getProject(projectName);
|
|
101
|
+
if (!project?.projectId) {
|
|
102
|
+
return 'absent';
|
|
103
|
+
}
|
|
104
|
+
// Never delete a project that is not provably this app's — the ownership tag
|
|
105
|
+
// proves the shared container belongs to us before teardown.
|
|
106
|
+
const tags = await client.tls.getProjectTags(projectName);
|
|
107
|
+
if (!(0, ownershipTag_1.isOwnedByApp)(context.app, exports.SHARED_LOG_PROJECT_KEY, tags)) {
|
|
108
|
+
logger_1.logger.warn(lang_1.lang.__('TLS_SHARED_PROJECT_NOT_OWNED', { projectName }));
|
|
109
|
+
return 'retained';
|
|
110
|
+
}
|
|
111
|
+
const topics = await client.tls.listTopics(projectName);
|
|
112
|
+
if (topics.length > 0) {
|
|
113
|
+
logger_1.logger.info(lang_1.lang.__('SHARED_TLS_PROJECT_IN_USE', {
|
|
114
|
+
projectName,
|
|
115
|
+
count: String(topics.length),
|
|
116
|
+
}));
|
|
117
|
+
return 'retained';
|
|
118
|
+
}
|
|
119
|
+
await client.tls.deleteProject(projectName);
|
|
120
|
+
logger_1.logger.info(lang_1.lang.__('SHARED_TLS_PROJECT_DELETED', { projectName }));
|
|
121
|
+
return 'deleted';
|
|
122
|
+
};
|
|
123
|
+
exports.releaseSharedLogProjectIfUnused = releaseSharedLogProjectIfUnused;
|
|
124
|
+
/**
|
|
125
|
+
* Adopt-or-create a topic inside a (shared) project. Reuses a same-named topic
|
|
126
|
+
* only when its ownership tag belongs to this app's stack; a foreign or
|
|
127
|
+
* untagged topic is refused rather than silently taken over.
|
|
128
|
+
*/
|
|
129
|
+
const ensureOwnedTopic = async (context, client, params) => {
|
|
130
|
+
const { projectName, topicName, logicalId } = params;
|
|
131
|
+
const existing = await client.tls.getTopic(projectName, topicName);
|
|
132
|
+
if (existing) {
|
|
133
|
+
// Service-scoped topics are shared across a service's functions/events, so
|
|
134
|
+
// ownership is verified at the owning-stack level, not per logical id.
|
|
135
|
+
const tag = (existing.tags ?? []).find((t) => t.Key === ownershipTag_1.OWNERSHIP_TAG_KEY);
|
|
136
|
+
const parsed = (0, ownershipTag_1.parseOwnershipTagValue)(tag?.Value);
|
|
137
|
+
if (parsed?.stack === `${context.app}-${context.service}`) {
|
|
138
|
+
return { topicName: existing.topicName ?? topicName, topicId: existing.topicId ?? '' };
|
|
139
|
+
}
|
|
140
|
+
throw new Error(lang_1.lang.__('TLS_TOPIC_FOREIGN_OWNED', { topicName }));
|
|
141
|
+
}
|
|
142
|
+
logger_1.logger.info(lang_1.lang.__('CREATING_TLS_TOPIC', { topicName }));
|
|
143
|
+
const topic = await client.tls.createTopic({ projectName, topicName, ttl: 30 });
|
|
144
|
+
if (topic.topicId) {
|
|
145
|
+
await client.tls.addTags({
|
|
146
|
+
resourceType: 'topic',
|
|
147
|
+
resourcesList: [topic.topicId],
|
|
148
|
+
tags: [{ key: ownershipTag_1.OWNERSHIP_TAG_KEY, value: (0, ownershipTag_1.buildOwnershipTagValue)(context, logicalId) }],
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
logger_1.logger.info(lang_1.lang.__('CREATING_TLS_INDEX', { topicName }));
|
|
152
|
+
await client.tls.createIndex({
|
|
153
|
+
projectName,
|
|
154
|
+
topicName,
|
|
155
|
+
fullTextIndex: {
|
|
156
|
+
delimiter: ' ,.?;!\n\t',
|
|
157
|
+
caseSensitive: false,
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
logger_1.logger.info(lang_1.lang.__('WAITING_FOR_TLS_RESOURCES', { projectName, topicName }));
|
|
161
|
+
await client.tls.waitForProject(projectName);
|
|
162
|
+
await client.tls.waitForTopic(projectName, topicName);
|
|
163
|
+
return { topicName, topicId: topic.topicId ?? '' };
|
|
164
|
+
};
|
|
165
|
+
exports.ensureOwnedTopic = ensureOwnedTopic;
|
|
166
|
+
/**
|
|
167
|
+
* Delete per-resource TLS children (index then topic) and any legacy
|
|
168
|
+
* per-resource own-project. The stage-shared project is never deleted here.
|
|
169
|
+
*/
|
|
170
|
+
const deleteTlsLogResources = async (context, client, instances) => {
|
|
171
|
+
const children = instances.filter((i) => i.type === 'VOLCENGINE_TLS_TOPIC' || i.type === 'VOLCENGINE_TLS_INDEX');
|
|
172
|
+
for (const instance of [...children].reverse()) {
|
|
173
|
+
const [projectName, topicName] = instance.id.split('/');
|
|
174
|
+
if (instance.type === 'VOLCENGINE_TLS_INDEX') {
|
|
175
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_TLS_INDEX', { id: instance.id }));
|
|
176
|
+
await client.tls.deleteIndex(projectName, topicName);
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_TLS_TOPIC', { id: instance.id }));
|
|
180
|
+
await client.tls.deleteTopic(projectName, topicName);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
const sharedProjectName = (0, exports.buildSharedProjectName)(context.app, context.stage);
|
|
184
|
+
const legacyProject = instances.find((i) => i.type === 'VOLCENGINE_TLS_PROJECT' && i.id !== sharedProjectName);
|
|
185
|
+
if (legacyProject) {
|
|
186
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_TLS_PROJECT', { id: legacyProject.id }));
|
|
187
|
+
await client.tls.deleteProject(legacyProject.id);
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
exports.deleteTlsLogResources = deleteTlsLogResources;
|
|
@@ -4,6 +4,7 @@ exports.executeBucketPlan = void 0;
|
|
|
4
4
|
const types_1 = require("../../types");
|
|
5
5
|
const tosResource_1 = require("./tosResource");
|
|
6
6
|
const common_1 = require("../../common");
|
|
7
|
+
const reportResourceEvent_1 = require("../../common/reportResourceEvent");
|
|
7
8
|
const stateManager_1 = require("../../common/stateManager");
|
|
8
9
|
const lang_1 = require("../../lang");
|
|
9
10
|
const executeCreateAction = async (context, bucket, currentState) => {
|
|
@@ -62,13 +63,26 @@ const executeBucketPlan = async (context, plan, buckets, initialState, onStateCh
|
|
|
62
63
|
const successfulItems = [];
|
|
63
64
|
let currentState = initialState;
|
|
64
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();
|
|
65
74
|
try {
|
|
66
75
|
const newState = await executeSingleItem(context, item, bucketsMap, currentState);
|
|
67
76
|
if (newState !== null) {
|
|
68
77
|
currentState = newState;
|
|
69
78
|
successfulItems.push(item);
|
|
79
|
+
(0, reportResourceEvent_1.reportResourceEvent)(context, {
|
|
80
|
+
type: 'resource_complete',
|
|
81
|
+
logicalId: item.logicalId,
|
|
82
|
+
durationMs: Date.now() - __siStartedAt,
|
|
83
|
+
});
|
|
70
84
|
if (onStateChange) {
|
|
71
|
-
onStateChange(currentState);
|
|
85
|
+
await onStateChange(currentState);
|
|
72
86
|
common_1.logger.debug(lang_1.lang.__('STATE_PERSISTED_AFTER_OPERATION', {
|
|
73
87
|
action: item.action,
|
|
74
88
|
resourceId: item.logicalId,
|
|
@@ -77,10 +91,19 @@ const executeBucketPlan = async (context, plan, buckets, initialState, onStateCh
|
|
|
77
91
|
}
|
|
78
92
|
}
|
|
79
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
|
+
});
|
|
80
103
|
if (error instanceof types_1.PartialResourceError) {
|
|
81
104
|
const updatedState = error.updatedState;
|
|
82
105
|
if (onStateChange) {
|
|
83
|
-
onStateChange(updatedState);
|
|
106
|
+
await onStateChange(updatedState);
|
|
84
107
|
}
|
|
85
108
|
return {
|
|
86
109
|
state: updatedState,
|
|
@@ -9,6 +9,7 @@ const volcengineClient_1 = require("../../common/volcengineClient");
|
|
|
9
9
|
const tosTypes_1 = require("./tosTypes");
|
|
10
10
|
const stateManager_1 = require("../../common/stateManager");
|
|
11
11
|
const common_1 = require("../../common");
|
|
12
|
+
const ownershipTag_1 = require("../ownershipTag");
|
|
12
13
|
const planBucketDeletion = (logicalId, definition) => ({
|
|
13
14
|
logicalId,
|
|
14
15
|
action: 'delete',
|
|
@@ -39,7 +40,16 @@ const generateBucketPlan = async (context, state, buckets) => {
|
|
|
39
40
|
}
|
|
40
41
|
})();
|
|
41
42
|
const desiredDefinition = (0, tosTypes_1.extractTosBucketDefinition)(config, websiteCodeHash);
|
|
42
|
-
if (!currentState) {
|
|
43
|
+
if (!currentState || currentState.status === 'tainted') {
|
|
44
|
+
// No usable local state: probe the provider before planning create.
|
|
45
|
+
// If a same-named bucket already exists WITHOUT our ownership tag it
|
|
46
|
+
// may belong to another project — fail fast in the plan instead of
|
|
47
|
+
// letting the executor discover it mid-deploy.
|
|
48
|
+
const client = (0, volcengineClient_1.createVolcengineClient)(context);
|
|
49
|
+
const remoteBucket = await client.tos.getBucket(bucket.name);
|
|
50
|
+
if (remoteBucket && !(0, ownershipTag_1.isOwnedByStack)(context, logicalId, remoteBucket.Tags)) {
|
|
51
|
+
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.`);
|
|
52
|
+
}
|
|
43
53
|
return {
|
|
44
54
|
logicalId,
|
|
45
55
|
action: 'create',
|