@geek-fun/serverlessinsight 0.5.2 → 0.5.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/dist/package.json +1 -1
- package/dist/src/common/aliyunClient/apigwOperations.js +3 -2
- package/dist/src/common/index.js +1 -0
- package/dist/src/common/sidUtils.js +24 -0
- package/dist/src/common/stateBackend/index.js +4 -4
- package/dist/src/common/stateManager.js +2 -2
- package/dist/src/parser/index.js +7 -8
- package/dist/src/stack/aliyunStack/apigwResource.js +13 -12
- package/dist/src/stack/aliyunStack/databaseResource.js +37 -21
- package/dist/src/stack/aliyunStack/fc3Executor.js +15 -5
- package/dist/src/stack/aliyunStack/fc3Planner.js +1 -1
- package/dist/src/stack/aliyunStack/fc3Resource.js +175 -129
- package/dist/src/stack/aliyunStack/ossResource.js +19 -8
- package/dist/src/stack/aliyunStack/tablestoreResource.js +19 -7
- package/dist/src/stack/scfStack/cosResource.js +21 -7
- package/dist/src/stack/scfStack/esServerlessResource.js +20 -7
- package/dist/src/stack/scfStack/scfResource.js +20 -7
- package/dist/src/stack/scfStack/tdsqlcResource.js +24 -7
- package/dist/src/types/domains/state.js +11 -2
- package/dist/src/validator/rootSchema.js +16 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -3,13 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.deleteResource = exports.updateResource = exports.readResource = exports.createResource = void 0;
|
|
4
4
|
const aliyunClient_1 = require("../../common/aliyunClient");
|
|
5
5
|
const common_1 = require("../../common");
|
|
6
|
+
const types_1 = require("../../types");
|
|
6
7
|
const fc3Types_1 = require("./fc3Types");
|
|
7
8
|
const logger_1 = require("../../common/logger");
|
|
8
|
-
const
|
|
9
|
-
const buildFc3InstanceFromProvider = (info, arn) => {
|
|
9
|
+
const buildFc3InstanceFromProvider = (info, sid) => {
|
|
10
10
|
return {
|
|
11
11
|
type: 'ALIYUN_FC3_FUNCTION',
|
|
12
|
-
|
|
12
|
+
sid,
|
|
13
13
|
id: info.functionName ?? '',
|
|
14
14
|
functionName: info.functionName ?? null,
|
|
15
15
|
functionId: info.functionId ?? null,
|
|
@@ -77,104 +77,153 @@ const buildFc3InstanceFromProvider = (info, arn) => {
|
|
|
77
77
|
lastUpdateStatusReasonCode: info.lastUpdateStatusReasonCode ?? null,
|
|
78
78
|
};
|
|
79
79
|
};
|
|
80
|
-
|
|
81
|
-
const createDependentResources = async (context, fn, serviceName) => {
|
|
80
|
+
const createDependentResources = async (context, fn, serviceName, existingInstances = []) => {
|
|
82
81
|
const client = (0, aliyunClient_1.createAliyunClient)(context);
|
|
83
82
|
const instances = [];
|
|
84
83
|
let logConfig;
|
|
85
84
|
let securityGroup;
|
|
86
85
|
let nasConfig;
|
|
87
|
-
|
|
86
|
+
const hasSlsProject = existingInstances.some((i) => i.type === 'ALIYUN_SLS_PROJECT');
|
|
87
|
+
const hasRamRole = existingInstances.some((i) => i.type === 'ALIYUN_RAM_ROLE');
|
|
88
|
+
const hasSecurityGroup = existingInstances.some((i) => i.type === 'ALIYUN_ECS_SECURITY_GROUP');
|
|
89
|
+
const hasNasResources = existingInstances.some((i) => i.type === 'ALIYUN_NAS_FILE_SYSTEM');
|
|
88
90
|
if (fn.log) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
attributes: { ...
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
91
|
+
if (hasSlsProject) {
|
|
92
|
+
const slsProjectInstance = existingInstances.find((i) => i.type === 'ALIYUN_SLS_PROJECT');
|
|
93
|
+
const slsLogstoreInstance = existingInstances.find((i) => i.type === 'ALIYUN_SLS_LOGSTORE');
|
|
94
|
+
if (slsProjectInstance && slsLogstoreInstance) {
|
|
95
|
+
const [projectName, logstoreName] = slsLogstoreInstance.id.split('/');
|
|
96
|
+
logConfig = { project: projectName, logstore: logstoreName };
|
|
97
|
+
instances.push(...existingInstances.filter((i) => i.type.startsWith('ALIYUN_SLS_')));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
const projectName = `${serviceName}-sls`;
|
|
102
|
+
const logstoreName = `${serviceName}-sls-logstore`;
|
|
103
|
+
logger_1.logger.info(`Creating SLS project: ${projectName}`);
|
|
104
|
+
const project = await client.sls.createProject(projectName);
|
|
105
|
+
instances.push({ type: 'ALIYUN_SLS_PROJECT', id: projectName, attributes: { ...project } });
|
|
106
|
+
logger_1.logger.info(`Creating SLS logstore: ${logstoreName}`);
|
|
107
|
+
const logstore = await client.sls.createLogstore(projectName, logstoreName);
|
|
108
|
+
instances.push({
|
|
109
|
+
type: 'ALIYUN_SLS_LOGSTORE',
|
|
110
|
+
id: `${projectName}/${logstoreName}`,
|
|
111
|
+
attributes: { ...logstore },
|
|
112
|
+
});
|
|
113
|
+
logger_1.logger.info(`Creating SLS index for: ${logstoreName}`);
|
|
114
|
+
const index = await client.sls.createIndex(projectName, logstoreName);
|
|
115
|
+
instances.push({
|
|
116
|
+
type: 'ALIYUN_SLS_INDEX',
|
|
117
|
+
id: `${projectName}/${logstoreName}/index`,
|
|
118
|
+
attributes: { ...index },
|
|
119
|
+
});
|
|
120
|
+
logger_1.logger.info(`Waiting for SLS project and logstore to be ready: ${projectName}/${logstoreName}`);
|
|
121
|
+
await client.sls.waitForProject(projectName);
|
|
122
|
+
await client.sls.waitForLogstore(projectName, logstoreName);
|
|
123
|
+
logConfig = { project: projectName, logstore: logstoreName };
|
|
124
|
+
}
|
|
116
125
|
}
|
|
117
|
-
// Create RAM role
|
|
118
126
|
const roleName = `${serviceName}-fc-role`;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
// Create security group if network is configured
|
|
129
|
-
if (fn.network) {
|
|
130
|
-
const sgName = fn.network.security_group.name;
|
|
131
|
-
logger_1.logger.info(`Creating security group: ${sgName}`);
|
|
132
|
-
const sg = await client.ecs.createSecurityGroup(sgName, fn.network.vpc_id, fn.network.security_group.ingress, fn.network.security_group.egress);
|
|
127
|
+
if (hasRamRole) {
|
|
128
|
+
const ramRoleInstance = existingInstances.find((i) => i.type === 'ALIYUN_RAM_ROLE');
|
|
129
|
+
if (ramRoleInstance) {
|
|
130
|
+
instances.push(ramRoleInstance);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
logger_1.logger.info(`Creating RAM role: ${roleName}`);
|
|
135
|
+
const ramRole = await client.ram.createRole(roleName);
|
|
133
136
|
instances.push({
|
|
134
|
-
type: '
|
|
135
|
-
id:
|
|
136
|
-
|
|
137
|
+
type: 'ALIYUN_RAM_ROLE',
|
|
138
|
+
id: roleName,
|
|
139
|
+
roleArn: ramRole.arn,
|
|
140
|
+
attributes: { ...ramRole },
|
|
137
141
|
});
|
|
138
|
-
securityGroup = { securityGroupId: sg.securityGroupId };
|
|
139
142
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
logger_1.logger.info(`Creating
|
|
156
|
-
const
|
|
157
|
-
instances.push({
|
|
158
|
-
type: 'ALIYUN_NAS_FILE_SYSTEM',
|
|
159
|
-
id: fileSystem.fileSystemId,
|
|
160
|
-
attributes: { ...fileSystem },
|
|
161
|
-
});
|
|
162
|
-
logger_1.logger.info(`Creating NAS mount target for: ${fileSystem.fileSystemId}`);
|
|
163
|
-
const mountTarget = await client.nas.createMountTarget(fileSystem.fileSystemId, accessGroupName, fn.network.vpc_id, fn.network.subnet_ids[0]);
|
|
143
|
+
const ramRoleInstance = instances.find((i) => i.type === 'ALIYUN_RAM_ROLE');
|
|
144
|
+
const role = {
|
|
145
|
+
roleName,
|
|
146
|
+
arn: ramRoleInstance?.roleArn ?? `acs:ram::${context.accountId}:role/${roleName}`,
|
|
147
|
+
};
|
|
148
|
+
if (fn.network) {
|
|
149
|
+
if (hasSecurityGroup) {
|
|
150
|
+
const sgInstance = existingInstances.find((i) => i.type === 'ALIYUN_ECS_SECURITY_GROUP');
|
|
151
|
+
if (sgInstance) {
|
|
152
|
+
instances.push(sgInstance);
|
|
153
|
+
securityGroup = { securityGroupId: sgInstance.id };
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
const sgName = fn.network.security_group.name;
|
|
158
|
+
logger_1.logger.info(`Creating security group: ${sgName}`);
|
|
159
|
+
const sg = await client.ecs.createSecurityGroup(sgName, fn.network.vpc_id, fn.network.security_group.ingress, fn.network.security_group.egress);
|
|
164
160
|
instances.push({
|
|
165
|
-
type: '
|
|
166
|
-
id:
|
|
167
|
-
attributes: { ...
|
|
168
|
-
});
|
|
169
|
-
mountPoints.push({
|
|
170
|
-
serverAddr: `${mountTarget.mountTargetDomain}:/`,
|
|
171
|
-
mountDir: nasItem.mount_path,
|
|
172
|
-
fileSystemId: fileSystem.fileSystemId,
|
|
173
|
-
mountTargetDomain: mountTarget.mountTargetDomain,
|
|
174
|
-
accessGroupName,
|
|
161
|
+
type: 'ALIYUN_ECS_SECURITY_GROUP',
|
|
162
|
+
id: sg.securityGroupId,
|
|
163
|
+
attributes: { ...sg },
|
|
175
164
|
});
|
|
165
|
+
securityGroup = { securityGroupId: sg.securityGroupId };
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (fn.storage?.nas && fn.storage.nas.length > 0 && fn.network) {
|
|
169
|
+
if (hasNasResources) {
|
|
170
|
+
const nasInstances = existingInstances.filter((i) => i.type.startsWith('ALIYUN_NAS_'));
|
|
171
|
+
instances.push(...nasInstances);
|
|
172
|
+
const mountTargetInstances = nasInstances.filter((i) => i.type === 'ALIYUN_NAS_MOUNT_TARGET');
|
|
173
|
+
const nasStorageItems = fn.storage.nas;
|
|
174
|
+
if (mountTargetInstances.length > 0) {
|
|
175
|
+
nasConfig = {
|
|
176
|
+
mountPoints: mountTargetInstances.map((mt, idx) => {
|
|
177
|
+
const [fileSystemId, mountTargetDomain] = mt.id.split('/');
|
|
178
|
+
return {
|
|
179
|
+
serverAddr: `${mountTargetDomain}:/`,
|
|
180
|
+
mountDir: nasStorageItems[idx]?.mount_path ?? '/mnt/nas',
|
|
181
|
+
fileSystemId,
|
|
182
|
+
mountTargetDomain,
|
|
183
|
+
accessGroupName: mt.attributes?.accessGroupName ?? '',
|
|
184
|
+
};
|
|
185
|
+
}),
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
const mountPoints = [];
|
|
191
|
+
for (const nasItem of fn.storage.nas) {
|
|
192
|
+
const mountPath = nasItem.mount_path.replace(/\//g, '-').replace(/^-/, '');
|
|
193
|
+
const accessGroupName = `${fn.name}-nas-access-${mountPath}`;
|
|
194
|
+
logger_1.logger.info(`Creating NAS access group: ${accessGroupName}`);
|
|
195
|
+
const accessGroup = await client.nas.createAccessGroup(accessGroupName);
|
|
196
|
+
instances.push({
|
|
197
|
+
type: 'ALIYUN_NAS_ACCESS_GROUP',
|
|
198
|
+
id: accessGroupName,
|
|
199
|
+
attributes: { ...accessGroup },
|
|
200
|
+
});
|
|
201
|
+
logger_1.logger.info(`Creating NAS access rule for: ${accessGroupName}`);
|
|
202
|
+
await client.nas.createAccessRule(accessGroupName, '10.0.0.0/8');
|
|
203
|
+
logger_1.logger.info(`Creating NAS file system for: ${fn.name}`);
|
|
204
|
+
const fileSystem = await client.nas.createFileSystem(nasItem.storage_class, fn.name);
|
|
205
|
+
instances.push({
|
|
206
|
+
type: 'ALIYUN_NAS_FILE_SYSTEM',
|
|
207
|
+
id: fileSystem.fileSystemId,
|
|
208
|
+
attributes: { ...fileSystem },
|
|
209
|
+
});
|
|
210
|
+
logger_1.logger.info(`Creating NAS mount target for: ${fileSystem.fileSystemId}`);
|
|
211
|
+
const mountTarget = await client.nas.createMountTarget(fileSystem.fileSystemId, accessGroupName, fn.network.vpc_id, fn.network.subnet_ids[0]);
|
|
212
|
+
instances.push({
|
|
213
|
+
type: 'ALIYUN_NAS_MOUNT_TARGET',
|
|
214
|
+
id: `${fileSystem.fileSystemId}/${mountTarget.mountTargetDomain}`,
|
|
215
|
+
attributes: { ...mountTarget, accessGroupName },
|
|
216
|
+
});
|
|
217
|
+
mountPoints.push({
|
|
218
|
+
serverAddr: `${mountTarget.mountTargetDomain}:/`,
|
|
219
|
+
mountDir: nasItem.mount_path,
|
|
220
|
+
fileSystemId: fileSystem.fileSystemId,
|
|
221
|
+
mountTargetDomain: mountTarget.mountTargetDomain,
|
|
222
|
+
accessGroupName,
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
nasConfig = { mountPoints };
|
|
176
226
|
}
|
|
177
|
-
nasConfig = { mountPoints };
|
|
178
227
|
}
|
|
179
228
|
return {
|
|
180
229
|
logConfig,
|
|
@@ -184,10 +233,8 @@ const createDependentResources = async (context, fn, serviceName) => {
|
|
|
184
233
|
instances,
|
|
185
234
|
};
|
|
186
235
|
};
|
|
187
|
-
// Helper function to delete dependent resources directly using the client
|
|
188
236
|
const deleteDependentResources = async (context, instances) => {
|
|
189
237
|
const client = (0, aliyunClient_1.createAliyunClient)(context);
|
|
190
|
-
// Delete in reverse order of creation
|
|
191
238
|
for (const instance of [...instances].reverse()) {
|
|
192
239
|
try {
|
|
193
240
|
switch (instance.type) {
|
|
@@ -241,11 +288,11 @@ const deleteDependentResources = async (context, instances) => {
|
|
|
241
288
|
const createResource = async (context, fn, state) => {
|
|
242
289
|
const ctx = (0, common_1.getContext)();
|
|
243
290
|
const serviceName = `${ctx.app}-${ctx.service}`;
|
|
244
|
-
|
|
245
|
-
const
|
|
246
|
-
|
|
291
|
+
const logicalId = `functions.${fn.key}`;
|
|
292
|
+
const existingResourceState = (0, common_1.getResource)(state, logicalId);
|
|
293
|
+
const existingDependentInstances = (existingResourceState?.instances ?? []).filter((i) => i.type !== 'ALIYUN_FC3_FUNCTION');
|
|
294
|
+
const dependentResources = await createDependentResources(context, fn, serviceName, existingDependentInstances);
|
|
247
295
|
let config = (0, fc3Types_1.functionToFc3Config)(fn);
|
|
248
|
-
// Update config with dependent resources
|
|
249
296
|
if (dependentResources.logConfig) {
|
|
250
297
|
config = {
|
|
251
298
|
...config,
|
|
@@ -288,52 +335,45 @@ const createResource = async (context, fn, state) => {
|
|
|
288
335
|
const codePath = fn.code.path;
|
|
289
336
|
const codeHash = (0, common_1.computeFileHash)(codePath);
|
|
290
337
|
const definition = (0, fc3Types_1.extractFc3Definition)(config, codeHash);
|
|
291
|
-
const logicalId = `functions.${fn.key}`;
|
|
292
|
-
// Save state with dependent resources BEFORE attempting function creation
|
|
293
338
|
const dependentInstances = dependentResources.instances.map((dep) => ({
|
|
294
|
-
|
|
295
|
-
|
|
339
|
+
sid: dep.sid ??
|
|
340
|
+
(0, common_1.buildSid)('aliyun', dep.type.replace('ALIYUN_', '').toLowerCase(), context.stage, dep.id),
|
|
296
341
|
id: dep.id,
|
|
297
342
|
type: dep.type,
|
|
343
|
+
...(dep.roleArn ? { roleArn: dep.roleArn } : {}),
|
|
298
344
|
...dep.attributes,
|
|
299
345
|
}));
|
|
300
|
-
|
|
301
|
-
const partialResourceState = {
|
|
346
|
+
const taintedResourceState = {
|
|
302
347
|
mode: 'managed',
|
|
303
348
|
region: context.region,
|
|
304
349
|
definition,
|
|
305
350
|
instances: dependentInstances,
|
|
306
351
|
lastUpdated: new Date().toISOString(),
|
|
352
|
+
status: 'tainted',
|
|
307
353
|
};
|
|
308
|
-
|
|
309
|
-
// Now attempt to create the function
|
|
354
|
+
const stateAfterDependents = (0, common_1.setResource)(state, logicalId, taintedResourceState);
|
|
310
355
|
const client = (0, aliyunClient_1.createAliyunClient)(context);
|
|
311
356
|
try {
|
|
312
357
|
await client.fc3.createFunction(config, codePath);
|
|
313
358
|
}
|
|
314
359
|
catch (error) {
|
|
315
|
-
|
|
316
|
-
logger_1.logger.info(lang_1.lang.__('FC3_DEPENDENT_RESOURCES_TRACKED'));
|
|
317
|
-
logger_1.logger.info(lang_1.lang.__('FC3_CAN_RETRY_DEPLOYMENT'));
|
|
318
|
-
return state;
|
|
360
|
+
throw new types_1.PartialResourceError(stateAfterDependents, error instanceof Error ? error : new Error(String(error)));
|
|
319
361
|
}
|
|
320
|
-
// Refresh state from provider to get all attributes
|
|
321
362
|
const functionInfo = await client.fc3.getFunction(fn.name);
|
|
322
363
|
if (!functionInfo) {
|
|
323
364
|
throw new Error(`Failed to refresh state for function: ${fn.name}`);
|
|
324
365
|
}
|
|
325
|
-
const
|
|
326
|
-
|
|
327
|
-
// Build instances array with FC function as first item, followed by dependent resources
|
|
328
|
-
const fcInstance = buildFc3InstanceFromProvider(functionInfo, arn);
|
|
366
|
+
const sid = (0, common_1.buildSid)('aliyun', 'fc3', context.stage, fn.name);
|
|
367
|
+
const fcInstance = buildFc3InstanceFromProvider(functionInfo, sid);
|
|
329
368
|
const resourceState = {
|
|
330
369
|
mode: 'managed',
|
|
331
370
|
region: context.region,
|
|
332
371
|
definition,
|
|
333
372
|
instances: [fcInstance, ...dependentInstances],
|
|
334
373
|
lastUpdated: new Date().toISOString(),
|
|
374
|
+
status: 'ready',
|
|
335
375
|
};
|
|
336
|
-
return (0, common_1.setResource)(
|
|
376
|
+
return (0, common_1.setResource)(stateAfterDependents, logicalId, resourceState);
|
|
337
377
|
};
|
|
338
378
|
exports.createResource = createResource;
|
|
339
379
|
const readResource = async (context, functionName) => {
|
|
@@ -345,10 +385,8 @@ const updateResource = async (context, fn, state) => {
|
|
|
345
385
|
const ctx = (0, common_1.getContext)();
|
|
346
386
|
const serviceName = `${ctx.app}-${ctx.service}`;
|
|
347
387
|
const logicalId = `functions.${fn.key}`;
|
|
348
|
-
// Get existing resource state to check if dependent resources exist
|
|
349
388
|
const existingState = (0, common_1.getResource)(state, logicalId);
|
|
350
389
|
const existingInstances = (existingState?.instances ?? []);
|
|
351
|
-
// Check if we need to create new dependent resources
|
|
352
390
|
const hasSlsResources = existingInstances.some((i) => i.type === 'ALIYUN_SLS_PROJECT');
|
|
353
391
|
const hasRamRole = existingInstances.some((i) => i.type === 'ALIYUN_RAM_ROLE');
|
|
354
392
|
const hasSecurityGroup = existingInstances.some((i) => i.type === 'ALIYUN_ECS_SECURITY_GROUP');
|
|
@@ -358,7 +396,6 @@ const updateResource = async (context, fn, state) => {
|
|
|
358
396
|
let role;
|
|
359
397
|
let securityGroup;
|
|
360
398
|
let nasConfig;
|
|
361
|
-
// Create new dependent resources if they don't exist
|
|
362
399
|
if (fn.log && !hasSlsResources) {
|
|
363
400
|
const deps = await createDependentResources(context, { ...fn, network: undefined, storage: { ...fn.storage, nas: undefined } }, serviceName);
|
|
364
401
|
logConfig = deps.logConfig;
|
|
@@ -382,7 +419,7 @@ const updateResource = async (context, fn, state) => {
|
|
|
382
419
|
if (ramRoleInstance) {
|
|
383
420
|
role = {
|
|
384
421
|
roleName: ramRoleInstance.id,
|
|
385
|
-
arn: ramRoleInstance.
|
|
422
|
+
arn: ramRoleInstance.roleArn ?? `acs:ram::${context.accountId}:role/${ramRoleInstance.id}`,
|
|
386
423
|
};
|
|
387
424
|
}
|
|
388
425
|
}
|
|
@@ -414,7 +451,6 @@ const updateResource = async (context, fn, state) => {
|
|
|
414
451
|
};
|
|
415
452
|
}
|
|
416
453
|
}
|
|
417
|
-
// Build FC3 config with dependent resources
|
|
418
454
|
let config = (0, fc3Types_1.functionToFc3Config)(fn);
|
|
419
455
|
if (logConfig) {
|
|
420
456
|
config = {
|
|
@@ -462,26 +498,25 @@ const updateResource = async (context, fn, state) => {
|
|
|
462
498
|
}
|
|
463
499
|
const codeHash = (0, common_1.computeFileHash)(codePath);
|
|
464
500
|
const definition = (0, fc3Types_1.extractFc3Definition)(config, codeHash);
|
|
465
|
-
const
|
|
466
|
-
|
|
467
|
-
// Build instances array: FC function + existing dependent resources + new dependent resources
|
|
468
|
-
const fcInstance = buildFc3InstanceFromProvider(functionInfo, arn);
|
|
501
|
+
const sid = (0, common_1.buildSid)('aliyun', 'fc3', context.stage, fn.name);
|
|
502
|
+
const fcInstance = buildFc3InstanceFromProvider(functionInfo, sid);
|
|
469
503
|
const existingDependentInstances = existingInstances
|
|
470
504
|
.filter((i) => i.type !== 'ALIYUN_FC3_FUNCTION')
|
|
471
505
|
.map((i) => {
|
|
472
|
-
const {
|
|
506
|
+
const { sid: existingSid, id: existingId, ...rest } = i;
|
|
473
507
|
return {
|
|
474
|
-
|
|
475
|
-
|
|
508
|
+
sid: existingSid ??
|
|
509
|
+
(0, common_1.buildSid)('aliyun', i.type?.toString().replace('ALIYUN_', '').toLowerCase() ?? '', context.stage, existingId?.toString() ?? ''),
|
|
476
510
|
id: existingId?.toString() ?? '',
|
|
477
511
|
...rest,
|
|
478
512
|
};
|
|
479
513
|
});
|
|
480
514
|
const newDependentInstancesMapped = newDependentInstances.map((dep) => ({
|
|
481
|
-
|
|
482
|
-
|
|
515
|
+
sid: dep.sid ??
|
|
516
|
+
(0, common_1.buildSid)('aliyun', dep.type.replace('ALIYUN_', '').toLowerCase(), context.stage, dep.id),
|
|
483
517
|
id: dep.id,
|
|
484
518
|
type: dep.type,
|
|
519
|
+
...(dep.roleArn ? { roleArn: dep.roleArn } : {}),
|
|
485
520
|
...dep.attributes,
|
|
486
521
|
}));
|
|
487
522
|
const resourceState = {
|
|
@@ -495,13 +530,24 @@ const updateResource = async (context, fn, state) => {
|
|
|
495
530
|
};
|
|
496
531
|
exports.updateResource = updateResource;
|
|
497
532
|
const deleteResource = async (context, functionName, logicalId, state) => {
|
|
498
|
-
// Get existing resource state to find dependent resources
|
|
499
533
|
const existingState = (0, common_1.getResource)(state, logicalId);
|
|
500
534
|
const existingInstances = (existingState?.instances ?? []);
|
|
501
|
-
|
|
535
|
+
const hasFcFunction = existingInstances.some((i) => i.type === 'ALIYUN_FC3_FUNCTION');
|
|
502
536
|
const client = (0, aliyunClient_1.createAliyunClient)(context);
|
|
503
|
-
|
|
504
|
-
|
|
537
|
+
if (hasFcFunction) {
|
|
538
|
+
try {
|
|
539
|
+
await client.fc3.deleteFunction(functionName);
|
|
540
|
+
}
|
|
541
|
+
catch (err) {
|
|
542
|
+
const errorCode = err?.code;
|
|
543
|
+
if (errorCode === 'FunctionNotFound') {
|
|
544
|
+
logger_1.logger.warn(`Function ${functionName} not found in provider, skipping deletion`);
|
|
545
|
+
}
|
|
546
|
+
else {
|
|
547
|
+
throw err;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
}
|
|
505
551
|
const dependentInstances = existingInstances.filter((i) => i.type !== 'ALIYUN_FC3_FUNCTION' && !i.type.includes('undefined'));
|
|
506
552
|
if (dependentInstances.length > 0) {
|
|
507
553
|
await deleteDependentResources(context, dependentInstances);
|
|
@@ -10,10 +10,10 @@ const ossTypes_1 = require("./ossTypes");
|
|
|
10
10
|
const logger_1 = require("../../common/logger");
|
|
11
11
|
const lang_1 = require("../../lang");
|
|
12
12
|
const node_path_1 = __importDefault(require("node:path"));
|
|
13
|
-
const buildOssInstanceFromProvider = (info,
|
|
13
|
+
const buildOssInstanceFromProvider = (info, sid) => {
|
|
14
14
|
return {
|
|
15
15
|
type: 'ALIYUN_OSS_BUCKET',
|
|
16
|
-
|
|
16
|
+
sid,
|
|
17
17
|
id: info.name,
|
|
18
18
|
bucketName: info.name,
|
|
19
19
|
location: info.location ?? null,
|
|
@@ -111,14 +111,14 @@ const createBucketResource = async (context, bucket, state) => {
|
|
|
111
111
|
throw new Error(`Failed to refresh state for bucket: ${config.bucketName}`);
|
|
112
112
|
}
|
|
113
113
|
const definition = (0, ossTypes_1.extractOssBucketDefinition)(config);
|
|
114
|
-
const
|
|
114
|
+
const sid = (0, common_1.buildSid)('aliyun', 'oss', context.stage, config.bucketName);
|
|
115
115
|
const logicalId = `buckets.${bucket.key}`;
|
|
116
116
|
// Save state immediately after bucket creation, before file upload
|
|
117
117
|
const partialResourceState = {
|
|
118
118
|
mode: 'managed',
|
|
119
119
|
region: context.region,
|
|
120
120
|
definition,
|
|
121
|
-
instances: [buildOssInstanceFromProvider(bucketInfo,
|
|
121
|
+
instances: [buildOssInstanceFromProvider(bucketInfo, sid)],
|
|
122
122
|
lastUpdated: new Date().toISOString(),
|
|
123
123
|
};
|
|
124
124
|
state = (0, common_1.setResource)(state, logicalId, partialResourceState);
|
|
@@ -134,7 +134,7 @@ const createBucketResource = async (context, bucket, state) => {
|
|
|
134
134
|
mode: 'managed',
|
|
135
135
|
region: context.region,
|
|
136
136
|
definition,
|
|
137
|
-
instances: [buildOssInstanceFromProvider(bucketInfo,
|
|
137
|
+
instances: [buildOssInstanceFromProvider(bucketInfo, sid)],
|
|
138
138
|
lastUpdated: new Date().toISOString(),
|
|
139
139
|
};
|
|
140
140
|
return (0, common_1.setResource)(state, logicalId, updatedResourceState);
|
|
@@ -176,12 +176,12 @@ const updateBucketResource = async (context, bucket, state) => {
|
|
|
176
176
|
throw new Error(`Failed to refresh state for bucket: ${config.bucketName}`);
|
|
177
177
|
}
|
|
178
178
|
const definition = (0, ossTypes_1.extractOssBucketDefinition)(config);
|
|
179
|
-
const
|
|
179
|
+
const sid = (0, common_1.buildSid)('aliyun', 'oss', context.stage, config.bucketName);
|
|
180
180
|
const resourceState = {
|
|
181
181
|
mode: 'managed',
|
|
182
182
|
region: context.region,
|
|
183
183
|
definition,
|
|
184
|
-
instances: [buildOssInstanceFromProvider(bucketInfo,
|
|
184
|
+
instances: [buildOssInstanceFromProvider(bucketInfo, sid)],
|
|
185
185
|
lastUpdated: new Date().toISOString(),
|
|
186
186
|
};
|
|
187
187
|
const logicalId = `buckets.${bucket.key}`;
|
|
@@ -190,7 +190,18 @@ const updateBucketResource = async (context, bucket, state) => {
|
|
|
190
190
|
exports.updateBucketResource = updateBucketResource;
|
|
191
191
|
const deleteBucketResource = async (context, bucketName, logicalId, state) => {
|
|
192
192
|
const client = (0, aliyunClient_1.createAliyunClient)(context);
|
|
193
|
-
|
|
193
|
+
try {
|
|
194
|
+
await client.oss.deleteBucket(bucketName);
|
|
195
|
+
}
|
|
196
|
+
catch (err) {
|
|
197
|
+
const errorCode = err?.code;
|
|
198
|
+
if (errorCode === 'NoSuchBucket') {
|
|
199
|
+
logger_1.logger.warn(`Bucket ${bucketName} not found in provider, skipping deletion`);
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
throw err;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
194
205
|
return (0, common_1.removeResource)(state, logicalId);
|
|
195
206
|
};
|
|
196
207
|
exports.deleteBucketResource = deleteBucketResource;
|
|
@@ -4,10 +4,11 @@ exports.deleteTableResource = exports.updateTableResource = exports.readTableRes
|
|
|
4
4
|
const aliyunClient_1 = require("../../common/aliyunClient");
|
|
5
5
|
const common_1 = require("../../common");
|
|
6
6
|
const tablestoreTypes_1 = require("./tablestoreTypes");
|
|
7
|
-
const
|
|
7
|
+
const logger_1 = require("../../common/logger");
|
|
8
|
+
const buildTableStoreInstanceFromProvider = (info, sid, instanceName, clusterType) => {
|
|
8
9
|
return {
|
|
9
10
|
type: 'ALIYUN_TABLESTORE_TABLE',
|
|
10
|
-
|
|
11
|
+
sid,
|
|
11
12
|
id: `${instanceName}/${info.tableName}`,
|
|
12
13
|
instanceName,
|
|
13
14
|
tableName: info.tableName,
|
|
@@ -57,13 +58,13 @@ const createTableResource = async (context, table, state) => {
|
|
|
57
58
|
throw new Error(`Failed to refresh state for table: ${config.tableName}`);
|
|
58
59
|
}
|
|
59
60
|
const definition = (0, tablestoreTypes_1.extractTableStoreDefinition)(config);
|
|
60
|
-
const
|
|
61
|
+
const sid = (0, common_1.buildSid)('aliyun', 'ots', context.stage, `${config.instanceName}/${config.tableName}`);
|
|
61
62
|
const resourceState = {
|
|
62
63
|
mode: 'managed',
|
|
63
64
|
region: context.region,
|
|
64
65
|
definition,
|
|
65
66
|
instances: [
|
|
66
|
-
buildTableStoreInstanceFromProvider(tableInfo,
|
|
67
|
+
buildTableStoreInstanceFromProvider(tableInfo, sid, config.instanceName, config.clusterType),
|
|
67
68
|
],
|
|
68
69
|
lastUpdated: new Date().toISOString(),
|
|
69
70
|
};
|
|
@@ -97,13 +98,13 @@ const updateTableResource = async (context, table, state) => {
|
|
|
97
98
|
throw new Error(`Failed to refresh state for table: ${config.tableName}`);
|
|
98
99
|
}
|
|
99
100
|
const definition = (0, tablestoreTypes_1.extractTableStoreDefinition)(config);
|
|
100
|
-
const
|
|
101
|
+
const sid = (0, common_1.buildSid)('aliyun', 'ots', context.stage, `${config.instanceName}/${config.tableName}`);
|
|
101
102
|
const resourceState = {
|
|
102
103
|
mode: 'managed',
|
|
103
104
|
region: context.region,
|
|
104
105
|
definition,
|
|
105
106
|
instances: [
|
|
106
|
-
buildTableStoreInstanceFromProvider(tableInfo,
|
|
107
|
+
buildTableStoreInstanceFromProvider(tableInfo, sid, config.instanceName, config.clusterType),
|
|
107
108
|
],
|
|
108
109
|
lastUpdated: new Date().toISOString(),
|
|
109
110
|
};
|
|
@@ -114,7 +115,18 @@ exports.updateTableResource = updateTableResource;
|
|
|
114
115
|
const deleteTableResource = async (context, instanceName, tableName, logicalId, state) => {
|
|
115
116
|
const client = (0, aliyunClient_1.createAliyunClient)(context);
|
|
116
117
|
const tablestoreClient = client.tablestore(instanceName);
|
|
117
|
-
|
|
118
|
+
try {
|
|
119
|
+
await tablestoreClient.deleteTable(tableName);
|
|
120
|
+
}
|
|
121
|
+
catch (err) {
|
|
122
|
+
const errorMessage = err?.message ?? '';
|
|
123
|
+
if (errorMessage.includes('OTSObjectNotExist') || errorMessage.includes('does not exist')) {
|
|
124
|
+
logger_1.logger.warn(`Table ${tableName} in instance ${instanceName} not found in provider, skipping deletion`);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
throw err;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
118
130
|
return (0, common_1.removeResource)(state, logicalId);
|
|
119
131
|
};
|
|
120
132
|
exports.deleteTableResource = deleteTableResource;
|
|
@@ -4,9 +4,11 @@ exports.deleteBucketResource = exports.updateBucketResource = exports.readBucket
|
|
|
4
4
|
const tencentClient_1 = require("../../common/tencentClient");
|
|
5
5
|
const cosTypes_1 = require("./cosTypes");
|
|
6
6
|
const stateManager_1 = require("../../common/stateManager");
|
|
7
|
-
const
|
|
7
|
+
const common_1 = require("../../common");
|
|
8
|
+
const logger_1 = require("../../common/logger");
|
|
9
|
+
const buildCosInstanceFromProvider = (info, sid) => {
|
|
8
10
|
return {
|
|
9
|
-
|
|
11
|
+
sid,
|
|
10
12
|
id: info.Name,
|
|
11
13
|
bucket: info.Name,
|
|
12
14
|
location: info.Location,
|
|
@@ -72,12 +74,12 @@ const createBucketResource = async (context, bucket, state) => {
|
|
|
72
74
|
throw new Error(`Failed to refresh state for bucket: ${bucket.name}`);
|
|
73
75
|
}
|
|
74
76
|
const definition = (0, cosTypes_1.extractCosBucketDefinition)(config);
|
|
75
|
-
const
|
|
77
|
+
const sid = (0, common_1.buildSid)('tencent', 'cos', context.stage, bucket.name);
|
|
76
78
|
const resourceState = {
|
|
77
79
|
mode: 'managed',
|
|
78
80
|
region: context.region,
|
|
79
81
|
definition,
|
|
80
|
-
instances: [buildCosInstanceFromProvider(bucketInfo,
|
|
82
|
+
instances: [buildCosInstanceFromProvider(bucketInfo, sid)],
|
|
81
83
|
lastUpdated: new Date().toISOString(),
|
|
82
84
|
};
|
|
83
85
|
const logicalId = `buckets.${bucket.key}`;
|
|
@@ -106,12 +108,12 @@ const updateBucketResource = async (context, bucket, state) => {
|
|
|
106
108
|
throw new Error(`Failed to refresh state for bucket: ${bucket.name}`);
|
|
107
109
|
}
|
|
108
110
|
const definition = (0, cosTypes_1.extractCosBucketDefinition)(config);
|
|
109
|
-
const
|
|
111
|
+
const sid = (0, common_1.buildSid)('tencent', 'cos', context.stage, bucket.name);
|
|
110
112
|
const resourceState = {
|
|
111
113
|
mode: 'managed',
|
|
112
114
|
region: context.region,
|
|
113
115
|
definition,
|
|
114
|
-
instances: [buildCosInstanceFromProvider(bucketInfo,
|
|
116
|
+
instances: [buildCosInstanceFromProvider(bucketInfo, sid)],
|
|
115
117
|
lastUpdated: new Date().toISOString(),
|
|
116
118
|
};
|
|
117
119
|
const logicalId = `buckets.${bucket.key}`;
|
|
@@ -120,7 +122,19 @@ const updateBucketResource = async (context, bucket, state) => {
|
|
|
120
122
|
exports.updateBucketResource = updateBucketResource;
|
|
121
123
|
const deleteBucketResource = async (context, bucketName, region, logicalId, state) => {
|
|
122
124
|
const client = (0, tencentClient_1.createTencentClient)(context);
|
|
123
|
-
|
|
125
|
+
try {
|
|
126
|
+
await client.cos.deleteBucket(bucketName, region);
|
|
127
|
+
}
|
|
128
|
+
catch (err) {
|
|
129
|
+
const errorCode = err?.code;
|
|
130
|
+
const statusCode = err?.statusCode;
|
|
131
|
+
if (errorCode === 'NoSuchBucket' || statusCode === 404) {
|
|
132
|
+
logger_1.logger.warn(`Bucket ${bucketName} not found in provider, skipping deletion`);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
throw err;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
124
138
|
return (0, stateManager_1.removeResource)(state, logicalId);
|
|
125
139
|
};
|
|
126
140
|
exports.deleteBucketResource = deleteBucketResource;
|