@geek-fun/serverlessinsight 0.8.2 → 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.serverlessinsight/state-cdn-flow-app-cdn-flow-service.json.backup +14 -0
- package/.serverlessinsight/state-iam-test-app-iam-test-service.json.backup +14 -0
- package/.serverlessinsight/state-insight-poc-deploy-app-insight-poc-deploy.json.backup +348 -0
- package/.serverlessinsight/state-insight-poc-destroy-app-insight-poc-destroy.json.backup +14 -0
- package/.serverlessinsight/state-insight-volc-app-insight-volc.json.backup +114 -0
- package/.serverlessinsight/state-insight-volc-destroy-app-insight-volc-destroy.json.backup +1 -0
- package/README.md +26 -18
- package/README.zh-CN.md +19 -6
- package/dist/package.json +3 -1
- package/dist/src/commands/deploy.js +87 -4
- package/dist/src/commands/destroy.js +61 -10
- package/dist/src/commands/forceUnlock.js +8 -0
- package/dist/src/commands/index.js +34 -2
- package/dist/src/commands/login.js +195 -0
- package/dist/src/commands/logout.js +17 -0
- package/dist/src/commands/show.js +15 -7
- package/dist/src/commands/whoami.js +20 -0
- package/dist/src/common/aliyunClient/apigwOperations.js +327 -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 +56 -26
- package/dist/src/common/aliyunClient/tablestoreOperations.js +25 -22
- package/dist/src/common/apiClient.js +102 -0
- package/dist/src/common/constants.js +9 -4
- package/dist/src/common/credentialStore.js +94 -0
- package/dist/src/common/credentials.js +2 -0
- package/dist/src/common/eventQueue.js +208 -0
- package/dist/src/common/hashUtils.js +87 -11
- package/dist/src/common/imsClient.js +1 -0
- package/dist/src/common/index.js +3 -0
- package/dist/src/common/lockManager.js +61 -54
- package/dist/src/common/logger.js +2 -0
- package/dist/src/common/polling.js +54 -0
- package/dist/src/common/reportResourceEvent.js +8 -0
- package/dist/src/common/runtimeMapper.js +11 -12
- package/dist/src/common/stateBackend/index.js +10 -1
- package/dist/src/common/stateBackend/localStateBackend.js +4 -1
- package/dist/src/common/stateBackend/remoteStateBackend.js +6 -3
- package/dist/src/common/stateBackend/saasStateBackend.js +266 -0
- package/dist/src/common/stateManager.js +135 -13
- package/dist/src/common/tencentClient/cosOperations.js +180 -3
- package/dist/src/common/tencentClient/esOperations.js +110 -46
- package/dist/src/common/tencentClient/index.js +22 -1
- package/dist/src/common/tencentClient/scfOperations.js +255 -133
- package/dist/src/common/tencentClient/tdsqlcClusterMapper.js +81 -0
- package/dist/src/common/tencentClient/tdsqlcOperations.js +93 -99
- package/dist/src/common/triggerMapper.js +36 -0
- package/dist/src/common/volcengineClient/apigwOperations.js +539 -159
- package/dist/src/common/volcengineClient/iamOperations.js +58 -48
- package/dist/src/common/volcengineClient/index.js +46 -21
- package/dist/src/common/volcengineClient/stsOperations.js +32 -0
- package/dist/src/common/volcengineClient/tlsOperations.js +229 -178
- package/dist/src/common/volcengineClient/tosOperations.js +78 -19
- package/dist/src/common/volcengineClient/vefaasOperations.js +272 -54
- package/dist/src/lang/en.js +84 -0
- package/dist/src/lang/zh-CN.js +84 -0
- package/dist/src/parser/eventParser.js +2 -0
- package/dist/src/parser/functionParser.js +96 -65
- package/dist/src/parser/index.js +7 -4
- package/dist/src/stack/aliyunStack/apigwExecutor.js +39 -1
- package/dist/src/stack/aliyunStack/apigwPlanner.js +14 -10
- package/dist/src/stack/aliyunStack/apigwResource.js +216 -124
- package/dist/src/stack/aliyunStack/apigwTypes.js +16 -3
- package/dist/src/stack/aliyunStack/databaseExecutor.js +39 -1
- package/dist/src/stack/aliyunStack/databasePlanner.js +13 -1
- package/dist/src/stack/aliyunStack/databaseResource.js +135 -40
- package/dist/src/stack/aliyunStack/deployer.js +2 -2
- package/dist/src/stack/aliyunStack/destroyer.js +2 -2
- package/dist/src/stack/aliyunStack/fc3Executor.js +25 -2
- package/dist/src/stack/aliyunStack/fc3Planner.js +11 -1
- package/dist/src/stack/aliyunStack/fc3Resource.js +327 -64
- package/dist/src/stack/aliyunStack/ossExecutor.js +39 -1
- package/dist/src/stack/aliyunStack/ossPlanner.js +15 -1
- package/dist/src/stack/aliyunStack/ossResource.js +267 -219
- package/dist/src/stack/aliyunStack/tablestoreExecutor.js +39 -1
- package/dist/src/stack/aliyunStack/tablestorePlanner.js +13 -1
- package/dist/src/stack/aliyunStack/tablestoreResource.js +54 -20
- package/dist/src/stack/alreadyExists.js +26 -0
- package/dist/src/stack/ownershipTag.js +40 -0
- package/dist/src/stack/rfsStack/index.js +3 -1
- package/dist/src/stack/scfStack/cosExecutor.js +39 -1
- package/dist/src/stack/scfStack/cosPlanner.js +11 -1
- package/dist/src/stack/scfStack/cosResource.js +167 -64
- package/dist/src/stack/scfStack/deployer.js +2 -2
- package/dist/src/stack/scfStack/destroyer.js +2 -2
- package/dist/src/stack/scfStack/esServerlessExecutor.js +39 -1
- package/dist/src/stack/scfStack/esServerlessPlanner.js +11 -1
- package/dist/src/stack/scfStack/esServerlessResource.js +88 -23
- package/dist/src/stack/scfStack/scfExecutor.js +39 -1
- package/dist/src/stack/scfStack/scfPlanner.js +12 -2
- package/dist/src/stack/scfStack/scfResource.js +484 -14
- package/dist/src/stack/scfStack/tdsqlcExecutor.js +39 -1
- package/dist/src/stack/scfStack/tdsqlcPlanner.js +12 -1
- package/dist/src/stack/scfStack/tdsqlcResource.js +95 -16
- package/dist/src/stack/scfStack/tdsqlcTypes.js +5 -1
- package/dist/src/stack/volcengineStack/apigwExecutor.js +39 -1
- package/dist/src/stack/volcengineStack/apigwPlanner.js +25 -53
- package/dist/src/stack/volcengineStack/apigwResource.js +418 -222
- package/dist/src/stack/volcengineStack/apigwTypes.js +76 -66
- package/dist/src/stack/volcengineStack/deployer.js +49 -14
- package/dist/src/stack/volcengineStack/destroyer.js +1 -1
- package/dist/src/stack/volcengineStack/index.js +1 -2
- package/dist/src/stack/volcengineStack/tosExecutor.js +25 -2
- package/dist/src/stack/volcengineStack/tosPlanner.js +11 -1
- package/dist/src/stack/volcengineStack/tosResource.js +82 -27
- package/dist/src/stack/volcengineStack/tosTypes.js +12 -0
- package/dist/src/stack/volcengineStack/vefaasExecutor.js +25 -2
- package/dist/src/stack/volcengineStack/vefaasPlanner.js +71 -2
- package/dist/src/stack/volcengineStack/vefaasResource.js +148 -98
- package/dist/src/stack/volcengineStack/vefaasTypes.js +1 -3
- package/dist/src/types/domains/backend.js +1 -0
- package/dist/src/types/domains/state.js +29 -1
- package/dist/src/validator/eventSchema.js +10 -0
- package/dist/src/validator/functionSchema.js +37 -12
- package/dist/src/validator/iacSchema.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.deleteDatabaseResource = exports.updateDatabaseResource = exports.readDatabaseResource = exports.createDatabaseResource = void 0;
|
|
4
|
+
const types_1 = require("../../types");
|
|
4
5
|
const aliyunClient_1 = require("../../common/aliyunClient");
|
|
5
6
|
const rdsTypes_1 = require("./rdsTypes");
|
|
6
7
|
const esServerlessTypes_1 = require("./esServerlessTypes");
|
|
@@ -8,6 +9,17 @@ const stateManager_1 = require("../../common/stateManager");
|
|
|
8
9
|
const common_1 = require("../../common");
|
|
9
10
|
const logger_1 = require("../../common/logger");
|
|
10
11
|
const lang_1 = require("../../lang");
|
|
12
|
+
const ownershipTag_1 = require("../ownershipTag");
|
|
13
|
+
const alreadyExists_1 = require("../alreadyExists");
|
|
14
|
+
// Normalize provider tag shape ({key,value}) to the ownership-check shape ({Key,Value}).
|
|
15
|
+
const toOwnershipTagShape = (tags) => tags?.map((t) => ({ Key: t.key, Value: t.value }));
|
|
16
|
+
// RDS CreateDBInstance reports a name collision as InvalidDBInstanceName.Duplicate
|
|
17
|
+
// ("Specified DB instance name already exists in the Aliyun RDS"). ES Serverless
|
|
18
|
+
// does not publish its CreateApp collision code in the SDK — DuplicateResource is
|
|
19
|
+
// Aliyun's common "resource already exists" code, and the generic matcher in
|
|
20
|
+
// alreadyExists.ts additionally catches '已存在'/'already exist' messages.
|
|
21
|
+
const RDS_ALREADY_EXISTS_CODES = ['InvalidDBInstanceName.Duplicate'];
|
|
22
|
+
const ES_ALREADY_EXISTS_CODES = ['DuplicateResource'];
|
|
11
23
|
const buildRdsInstanceFromProvider = (info, sid) => {
|
|
12
24
|
return {
|
|
13
25
|
sid,
|
|
@@ -39,6 +51,36 @@ const buildRdsInstanceFromProvider = (info, sid) => {
|
|
|
39
51
|
regionId: info.regionId ?? null,
|
|
40
52
|
securityIPList: info.securityIPList ?? null,
|
|
41
53
|
multiAZ: info.multiAZ ?? null,
|
|
54
|
+
tags: info.tags
|
|
55
|
+
? info.tags.map((t) => ({
|
|
56
|
+
key: t.key ?? null,
|
|
57
|
+
value: t.value ?? null,
|
|
58
|
+
}))
|
|
59
|
+
: [],
|
|
60
|
+
dbInstanceCpu: info.dbInstanceCpu ?? null,
|
|
61
|
+
dbInstanceMemory: info.dbInstanceMemory ?? null,
|
|
62
|
+
payType: info.payType ?? null,
|
|
63
|
+
expireTime: info.expireTime ?? null,
|
|
64
|
+
maintainTime: info.maintainTime ?? null,
|
|
65
|
+
maxConnections: info.maxConnections ?? null,
|
|
66
|
+
maxIOPS: info.maxIOPS ?? null,
|
|
67
|
+
resourceGroupId: info.resourceGroupId ?? null,
|
|
68
|
+
deletionProtection: info.deletionProtection ?? null,
|
|
69
|
+
lockMode: info.lockMode ?? null,
|
|
70
|
+
lockReason: info.lockReason ?? null,
|
|
71
|
+
connectionMode: info.connectionMode ?? null,
|
|
72
|
+
dbInstanceDiskUsed: info.dbInstanceDiskUsed ?? null,
|
|
73
|
+
dbInstanceType: info.dbInstanceType ?? null,
|
|
74
|
+
instanceNetworkType: info.instanceNetworkType ?? null,
|
|
75
|
+
timeZone: info.timeZone ?? null,
|
|
76
|
+
currentKernelVersion: info.currentKernelVersion ?? null,
|
|
77
|
+
latestKernelVersion: info.latestKernelVersion ?? null,
|
|
78
|
+
masterZone: info.masterZone ?? null,
|
|
79
|
+
masterInstanceId: info.masterInstanceId ?? null,
|
|
80
|
+
slaveZones: info.slaveZones?.map((z) => ({ zoneId: z.zoneId ?? null })) ?? [],
|
|
81
|
+
readOnlyDBInstanceIds: info.readOnlyDBInstanceIds ?? [],
|
|
82
|
+
burstingEnabled: info.burstingEnabled ?? null,
|
|
83
|
+
computeBurstEnabled: info.computeBurstEnabled ?? null,
|
|
42
84
|
};
|
|
43
85
|
};
|
|
44
86
|
const buildEsInstanceFromProvider = (info, sid) => {
|
|
@@ -98,60 +140,113 @@ const buildEsInstanceFromProvider = (info, sid) => {
|
|
|
98
140
|
};
|
|
99
141
|
const createDatabaseResource = async (context, database, state) => {
|
|
100
142
|
const client = (0, aliyunClient_1.createAliyunClient)(context);
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
let resourceType;
|
|
105
|
-
if (database.type === "ELASTICSEARCH_SERVERLESS" /* DatabaseEnum.ELASTICSEARCH_SERVERLESS */) {
|
|
106
|
-
// Create Elasticsearch Serverless app
|
|
107
|
-
const config = (0, esServerlessTypes_1.databaseToEsConfig)(database);
|
|
108
|
-
instanceId = await client.es.createApp(config);
|
|
109
|
-
// Refresh state from provider to get all attributes
|
|
110
|
-
const appInfo = await client.es.getApp(instanceId);
|
|
111
|
-
if (!appInfo) {
|
|
112
|
-
throw new Error(`Failed to refresh state for ES app: ${instanceId}`);
|
|
113
|
-
}
|
|
114
|
-
definition = (0, esServerlessTypes_1.extractEsDefinition)(config);
|
|
115
|
-
const sid = (0, common_1.buildSid)('aliyun', 'es', context.stage, instanceId);
|
|
116
|
-
instance = buildEsInstanceFromProvider(appInfo, sid);
|
|
117
|
-
resourceType = 'ALIYUN_ES_SERVERLESS';
|
|
118
|
-
}
|
|
119
|
-
else if ([
|
|
143
|
+
const logicalId = `databases.${database.key}`;
|
|
144
|
+
const isEs = database.type === "ELASTICSEARCH_SERVERLESS" /* DatabaseEnum.ELASTICSEARCH_SERVERLESS */;
|
|
145
|
+
const isRds = [
|
|
120
146
|
"RDS_MYSQL_SERVERLESS" /* DatabaseEnum.RDS_MYSQL_SERVERLESS */,
|
|
121
147
|
"RDS_PGSQL_SERVERLESS" /* DatabaseEnum.RDS_PGSQL_SERVERLESS */,
|
|
122
148
|
"RDS_MSSQL_SERVERLESS" /* DatabaseEnum.RDS_MSSQL_SERVERLESS */,
|
|
123
|
-
].includes(database.type)
|
|
124
|
-
|
|
125
|
-
const config = (0, rdsTypes_1.databaseToRdsConfig)(database);
|
|
126
|
-
instanceId = await client.rds.createInstance(config);
|
|
127
|
-
// Refresh state from provider to get all attributes
|
|
128
|
-
const rdsInfo = await client.rds.getInstance(instanceId);
|
|
129
|
-
if (!rdsInfo) {
|
|
130
|
-
throw new Error(`Failed to refresh state for RDS instance: ${instanceId}`);
|
|
131
|
-
}
|
|
132
|
-
definition = (0, rdsTypes_1.extractRdsDefinition)(config);
|
|
133
|
-
const sid = (0, common_1.buildSid)('aliyun', 'rds', context.stage, instanceId);
|
|
134
|
-
instance = buildRdsInstanceFromProvider(rdsInfo, sid);
|
|
135
|
-
resourceType = 'ALIYUN_RDS_SERVERLESS';
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
149
|
+
].includes(database.type);
|
|
150
|
+
if (!isEs && !isRds) {
|
|
138
151
|
throw new Error(`Unsupported database type: ${database.type}`);
|
|
139
152
|
}
|
|
140
|
-
const
|
|
153
|
+
const resourceType = isEs ? 'ALIYUN_ES_SERVERLESS' : 'ALIYUN_RDS_SERVERLESS';
|
|
154
|
+
const definition = isEs
|
|
155
|
+
? (0, esServerlessTypes_1.extractEsDefinition)((0, esServerlessTypes_1.databaseToEsConfig)(database))
|
|
156
|
+
: (0, rdsTypes_1.extractRdsDefinition)((0, rdsTypes_1.databaseToRdsConfig)(database));
|
|
157
|
+
const taintedResourceState = {
|
|
141
158
|
mode: 'managed',
|
|
142
159
|
region: context.region,
|
|
143
160
|
definition,
|
|
144
|
-
|
|
145
|
-
instances: [instance],
|
|
161
|
+
instances: [],
|
|
146
162
|
lastUpdated: new Date().toISOString(),
|
|
147
163
|
metadata: {
|
|
148
164
|
databaseName: database.name,
|
|
149
|
-
instanceId,
|
|
150
165
|
resourceType,
|
|
151
166
|
},
|
|
167
|
+
status: 'tainted',
|
|
152
168
|
};
|
|
153
|
-
const
|
|
154
|
-
|
|
169
|
+
const stateAfterDependents = (0, stateManager_1.setResource)(state, logicalId, taintedResourceState);
|
|
170
|
+
try {
|
|
171
|
+
let instanceId;
|
|
172
|
+
let instance;
|
|
173
|
+
if (isEs) {
|
|
174
|
+
const config = (0, esServerlessTypes_1.databaseToEsConfig)(database);
|
|
175
|
+
config.tags = [{ key: ownershipTag_1.OWNERSHIP_TAG_KEY, value: (0, ownershipTag_1.buildOwnershipTagValue)(context, logicalId) }];
|
|
176
|
+
try {
|
|
177
|
+
instanceId = await client.es.createApp(config);
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
if ((0, alreadyExists_1.isResourceAlreadyExistsError)(error, ES_ALREADY_EXISTS_CODES)) {
|
|
181
|
+
const probe = await client.es.getApp(config.appName);
|
|
182
|
+
if (probe && (0, ownershipTag_1.isOwnedByStack)(context, logicalId, toOwnershipTagShape(probe.tags))) {
|
|
183
|
+
instanceId = probe.appId ?? config.appName;
|
|
184
|
+
logger_1.logger.info(`ES app ${config.appName} exists and carries ownership tag (${ownershipTag_1.OWNERSHIP_TAG_KEY}), adopting idempotently`);
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
throw new Error(`ES app ${config.appName} already exists in provider but is not owned by this stack (missing ${ownershipTag_1.OWNERSHIP_TAG_KEY} tag). Refusing to adopt — resolve manually.`, { cause: error });
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
throw error;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
// Refresh state from provider to get all attributes
|
|
195
|
+
const appInfo = await client.es.getApp(instanceId);
|
|
196
|
+
if (!appInfo) {
|
|
197
|
+
throw new Error(`Failed to refresh state for ES app: ${instanceId}`);
|
|
198
|
+
}
|
|
199
|
+
const sid = (0, common_1.buildSid)('aliyun', 'es', context.stage, instanceId);
|
|
200
|
+
instance = buildEsInstanceFromProvider(appInfo, sid);
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
const config = (0, rdsTypes_1.databaseToRdsConfig)(database);
|
|
204
|
+
config.tags = [{ key: ownershipTag_1.OWNERSHIP_TAG_KEY, value: (0, ownershipTag_1.buildOwnershipTagValue)(context, logicalId) }];
|
|
205
|
+
try {
|
|
206
|
+
instanceId = await client.rds.createInstance(config);
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
if ((0, alreadyExists_1.isResourceAlreadyExistsError)(error, RDS_ALREADY_EXISTS_CODES)) {
|
|
210
|
+
const probe = await client.rds.getInstanceByName(config.dbInstanceDescription);
|
|
211
|
+
if (probe?.dbInstanceId &&
|
|
212
|
+
(0, ownershipTag_1.isOwnedByStack)(context, logicalId, toOwnershipTagShape(probe.tags))) {
|
|
213
|
+
instanceId = probe.dbInstanceId;
|
|
214
|
+
logger_1.logger.info(`RDS instance ${config.dbInstanceDescription} exists and carries ownership tag (${ownershipTag_1.OWNERSHIP_TAG_KEY}), adopting idempotently`);
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
throw new Error(`RDS instance ${config.dbInstanceDescription} already exists in provider but is not owned by this stack (missing ${ownershipTag_1.OWNERSHIP_TAG_KEY} tag). Refusing to adopt — resolve manually.`, { cause: error });
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
throw error;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
// Refresh state from provider to get all attributes
|
|
225
|
+
const rdsInfo = await client.rds.getInstance(instanceId);
|
|
226
|
+
if (!rdsInfo) {
|
|
227
|
+
throw new Error(`Failed to refresh state for RDS instance: ${instanceId}`);
|
|
228
|
+
}
|
|
229
|
+
const sid = (0, common_1.buildSid)('aliyun', 'rds', context.stage, instanceId);
|
|
230
|
+
instance = buildRdsInstanceFromProvider(rdsInfo, sid);
|
|
231
|
+
}
|
|
232
|
+
const resourceState = {
|
|
233
|
+
mode: 'managed',
|
|
234
|
+
region: context.region,
|
|
235
|
+
definition,
|
|
236
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
237
|
+
instances: [instance],
|
|
238
|
+
lastUpdated: new Date().toISOString(),
|
|
239
|
+
metadata: {
|
|
240
|
+
databaseName: database.name,
|
|
241
|
+
instanceId,
|
|
242
|
+
resourceType,
|
|
243
|
+
},
|
|
244
|
+
};
|
|
245
|
+
return (0, stateManager_1.setResource)(stateAfterDependents, logicalId, resourceState);
|
|
246
|
+
}
|
|
247
|
+
catch (error) {
|
|
248
|
+
throw new types_1.PartialResourceError(stateAfterDependents, error instanceof Error ? error : new Error(String(error)));
|
|
249
|
+
}
|
|
155
250
|
};
|
|
156
251
|
exports.createDatabaseResource = createDatabaseResource;
|
|
157
252
|
const readDatabaseResource = async (context, instanceId, resourceType) => {
|
|
@@ -13,8 +13,8 @@ const tablestorePlanner_1 = require("./tablestorePlanner");
|
|
|
13
13
|
const tablestoreExecutor_1 = require("./tablestoreExecutor");
|
|
14
14
|
const apigwPlanner_1 = require("./apigwPlanner");
|
|
15
15
|
const apigwExecutor_1 = require("./apigwExecutor");
|
|
16
|
-
const createSaveStateFn = (backend, iac, stage) => (state) => {
|
|
17
|
-
backend.saveState(state, iac.app, iac.service, stage);
|
|
16
|
+
const createSaveStateFn = (backend, iac, stage) => async (state) => {
|
|
17
|
+
await backend.saveState(state, iac.app, iac.service, stage);
|
|
18
18
|
};
|
|
19
19
|
const handlePartialFailure = (failure) => {
|
|
20
20
|
const error = failure.error;
|
|
@@ -13,8 +13,8 @@ const tablestorePlanner_1 = require("./tablestorePlanner");
|
|
|
13
13
|
const tablestoreExecutor_1 = require("./tablestoreExecutor");
|
|
14
14
|
const apigwPlanner_1 = require("./apigwPlanner");
|
|
15
15
|
const apigwExecutor_1 = require("./apigwExecutor");
|
|
16
|
-
const createSaveStateFn = (backend, app, service, stage) => (state) => {
|
|
17
|
-
backend.saveState(state, app, service, stage);
|
|
16
|
+
const createSaveStateFn = (backend, app, service, stage) => async (state) => {
|
|
17
|
+
await backend.saveState(state, app, service, stage);
|
|
18
18
|
};
|
|
19
19
|
const handlePartialFailure = (failure) => {
|
|
20
20
|
const error = failure.error;
|
|
@@ -4,6 +4,7 @@ exports.executeFunctionPlan = void 0;
|
|
|
4
4
|
const types_1 = require("../../types");
|
|
5
5
|
const fc3Resource_1 = require("./fc3Resource");
|
|
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, fn, currentState) => {
|
|
@@ -62,21 +63,43 @@ const executeFunctionPlan = async (context, plan, functions, initialState, onSta
|
|
|
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, functionsMap, 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
|
}
|
|
73
87
|
}
|
|
74
88
|
}
|
|
75
89
|
catch (error) {
|
|
90
|
+
(0, reportResourceEvent_1.reportResourceEvent)(context, {
|
|
91
|
+
type: 'resource_failed',
|
|
92
|
+
logicalId: item.logicalId,
|
|
93
|
+
severity: 'error',
|
|
94
|
+
durationMs: Date.now() - __siStartedAt,
|
|
95
|
+
error: {
|
|
96
|
+
message: error instanceof Error ? error.message : String(error),
|
|
97
|
+
},
|
|
98
|
+
});
|
|
76
99
|
if (error instanceof types_1.PartialResourceError) {
|
|
77
100
|
const updatedState = error.updatedState;
|
|
78
101
|
if (onStateChange) {
|
|
79
|
-
onStateChange(updatedState);
|
|
102
|
+
await onStateChange(updatedState);
|
|
80
103
|
}
|
|
81
104
|
return {
|
|
82
105
|
state: updatedState,
|
|
@@ -5,6 +5,7 @@ const common_1 = require("../../common");
|
|
|
5
5
|
const aliyunClient_1 = require("../../common/aliyunClient");
|
|
6
6
|
const fc3Types_1 = require("./fc3Types");
|
|
7
7
|
const lang_1 = require("../../lang");
|
|
8
|
+
const ownershipTag_1 = require("../ownershipTag");
|
|
8
9
|
/**
|
|
9
10
|
* Provider-managed logConfig fields that are set by the system after creation.
|
|
10
11
|
* These should not be compared when detecting changes.
|
|
@@ -77,10 +78,19 @@ const generateFunctionPlan = async (context, state, functions) => {
|
|
|
77
78
|
const rawConfig = (0, fc3Types_1.functionToFc3Config)(fn);
|
|
78
79
|
const config = await resolveVpcConfigSecurityGroup(context, rawConfig);
|
|
79
80
|
const codePath = fn.code.path;
|
|
80
|
-
const desiredCodeHash = (0, common_1.
|
|
81
|
+
const desiredCodeHash = await (0, common_1.computeZipContentHash)(codePath);
|
|
81
82
|
const baseDefinition = (0, fc3Types_1.extractFc3Definition)(config, desiredCodeHash);
|
|
82
83
|
const desiredDefinition = fn.iam ? { ...baseDefinition, iam: fn.iam } : baseDefinition;
|
|
83
84
|
if (!currentState || currentState.status === 'tainted') {
|
|
85
|
+
// No usable local state: probe the provider before planning create.
|
|
86
|
+
// If a same-named function already exists WITHOUT our ownership tag it
|
|
87
|
+
// may belong to another project — fail fast in the plan instead of
|
|
88
|
+
// letting the executor discover it mid-deploy.
|
|
89
|
+
const client = (0, aliyunClient_1.createAliyunClient)(context);
|
|
90
|
+
const remoteFunction = await client.fc3.getFunction(fn.name);
|
|
91
|
+
if (remoteFunction && !(0, ownershipTag_1.isOwnedByStack)(context, logicalId, remoteFunction.tags)) {
|
|
92
|
+
throw new Error(`Function ${fn.name} already exists in provider but is not owned by this stack (missing ${ownershipTag_1.OWNERSHIP_TAG_KEY} tag). Refusing to create — resolve manually.`);
|
|
93
|
+
}
|
|
84
94
|
return {
|
|
85
95
|
logicalId,
|
|
86
96
|
action: 'create',
|