@geek-fun/serverlessinsight 0.9.1 → 0.9.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 +1 -1
- package/.serverlessinsight/state-iam-test-app-iam-test-service.json.backup +2 -2
- package/.serverlessinsight/state-insight-poc-app-insight-poc-tencent.json.backup +4 -8
- package/.serverlessinsight/state-insight-poc-app-log-insight-poc-tencent-log.json.backup +3 -8
- package/.serverlessinsight/state-insight-poc-deploy-app-insight-poc-deploy.json.backup +4 -4
- package/.serverlessinsight/state-insight-poc-destroy-app-insight-poc-destroy.json.backup +1 -1
- package/.serverlessinsight/state-insight-poc-timer-app-insight-poc-timer.json.backup +132 -0
- package/.serverlessinsight/state-insight-volc-app-insight-volc.json.backup +2 -2
- package/.serverlessinsight/state-insight-volc-nested-app-insight-volc-nested.json.backup +3 -3
- package/.serverlessinsight/state-nested-drift-app-nested-drift-service.json.backup +20 -5
- package/.serverlessinsight/state-role-reconcile-test-app-role-reconcile-test-service.json.backup +3 -3
- package/AGENTS.md +10 -0
- package/CHANGELOG.md +51 -0
- package/README.md +103 -13
- package/README.zh-CN.md +73 -13
- package/codecov +0 -0
- package/codecov.SHA256SUM +1 -0
- package/codecov.SHA256SUM.sig +16 -0
- package/dist/package.json +1 -1
- package/dist/src/commands/index.js +92 -24
- package/dist/src/commands/local.js +16 -3
- package/dist/src/commands/plan.js +31 -4
- package/dist/src/commands/schema.js +24 -0
- package/dist/src/commands/show.js +64 -10
- package/dist/src/commands/validate.js +34 -2
- package/dist/src/common/aliyunClient/apigwOperations.js +17 -1
- package/dist/src/common/aliyunClient/fc3Operations.js +39 -2
- package/dist/src/common/aliyunClient/ossOperations.js +214 -221
- package/dist/src/common/bucketPolicy.js +63 -0
- package/dist/src/common/constants.js +7 -1
- package/dist/src/common/domainUtils.js +4 -1
- package/dist/src/common/functionDefinition.js +25 -0
- package/dist/src/common/index.js +4 -0
- package/dist/src/common/jsonOutput.js +82 -0
- package/dist/src/common/logger.js +6 -3
- package/dist/src/common/nameBuilder.js +3 -1
- package/dist/src/common/noColor.js +9 -0
- package/dist/src/common/planCapabilities.js +119 -0
- package/dist/src/common/planCompare.js +119 -66
- package/dist/src/common/planFormatter.js +34 -20
- package/dist/src/common/planRedaction.js +26 -0
- package/dist/src/common/refreshPlanner.js +66 -21
- package/dist/src/common/siCron.js +415 -0
- package/dist/src/common/stateBackend/saasStateBackend.js +5 -4
- package/dist/src/common/tencentClient/cosOperations.js +326 -322
- package/dist/src/common/tencentClient/scfOperations.js +11 -2
- package/dist/src/common/tencentClient/tdsqlcOperations.js +6 -11
- package/dist/src/common/triggerMapper.js +16 -1
- package/dist/src/common/volcengineClient/apigwOperations.js +82 -0
- package/dist/src/common/volcengineClient/iamOperations.js +27 -3
- package/dist/src/common/volcengineClient/tosOperations.js +62 -56
- package/dist/src/common/volcengineClient/vefaasOperations.js +45 -0
- package/dist/src/lang/en.js +70 -3
- package/dist/src/lang/index.js +36 -1
- package/dist/src/lang/zh-CN.js +70 -3
- package/dist/src/parser/eventParser.js +1 -0
- package/dist/src/parser/functionParser.js +48 -2
- package/dist/src/stack/aliyunStack/apigwExecutor.js +1 -1
- package/dist/src/stack/aliyunStack/apigwPlanner.js +103 -23
- package/dist/src/stack/aliyunStack/apigwResource.js +4 -3
- package/dist/src/stack/aliyunStack/apigwTypes.js +3 -7
- package/dist/src/stack/aliyunStack/deployer.js +2 -0
- package/dist/src/stack/aliyunStack/esServerlessTypes.js +8 -4
- package/dist/src/stack/aliyunStack/fc3Executor.js +7 -3
- package/dist/src/stack/aliyunStack/fc3Planner.js +148 -153
- package/dist/src/stack/aliyunStack/fc3Resource.js +206 -53
- package/dist/src/stack/aliyunStack/fc3Types.js +30 -16
- package/dist/src/stack/aliyunStack/ossPlanner.js +15 -1
- package/dist/src/stack/aliyunStack/ossResource.js +113 -102
- package/dist/src/stack/aliyunStack/ossTypes.js +20 -20
- package/dist/src/stack/localStack/aliyunFc.js +1 -6
- package/dist/src/stack/localStack/event.js +31 -71
- package/dist/src/stack/localStack/function.js +25 -77
- package/dist/src/stack/localStack/functionRunner.js +10 -2
- package/dist/src/stack/localStack/httpAdapter.js +54 -0
- package/dist/src/stack/localStack/httpError.js +5 -0
- package/dist/src/stack/localStack/index.js +8 -1
- package/dist/src/stack/localStack/legacyLambda.js +26 -0
- package/dist/src/stack/localStack/localContext.js +29 -0
- package/dist/src/stack/localStack/localRoute.js +12 -0
- package/dist/src/stack/localStack/localRuntimes.js +22 -0
- package/dist/src/stack/localStack/localServer.js +8 -3
- package/dist/src/stack/localStack/requestBody.js +24 -0
- package/dist/src/stack/localStack/requestId.js +18 -0
- package/dist/src/stack/localStack/tencent.js +147 -0
- package/dist/src/stack/localStack/timer.js +183 -0
- package/dist/src/stack/localStack/utils.js +19 -1
- package/dist/src/stack/localStack/volcengine.js +68 -0
- package/dist/src/stack/scfStack/cosPlanner.js +9 -14
- package/dist/src/stack/scfStack/cosResource.js +42 -50
- package/dist/src/stack/scfStack/cosTypes.js +19 -14
- package/dist/src/stack/scfStack/deployer.js +2 -0
- package/dist/src/stack/scfStack/scfExecutor.js +7 -3
- package/dist/src/stack/scfStack/scfHttpTrigger.js +106 -0
- package/dist/src/stack/scfStack/scfPlanner.js +114 -29
- package/dist/src/stack/scfStack/scfResource.js +329 -311
- package/dist/src/stack/scfStack/scfTypes.js +4 -3
- package/dist/src/stack/scfStack/tdsqlcPlanner.js +10 -13
- package/dist/src/stack/volcengineStack/apigwDomains.js +64 -0
- package/dist/src/stack/volcengineStack/apigwPlanner.js +71 -15
- package/dist/src/stack/volcengineStack/apigwResource.js +60 -24
- package/dist/src/stack/volcengineStack/apigwTypes.js +5 -1
- package/dist/src/stack/volcengineStack/deployer.js +6 -0
- package/dist/src/stack/volcengineStack/tosPlanner.js +8 -13
- package/dist/src/stack/volcengineStack/tosResource.js +22 -35
- package/dist/src/stack/volcengineStack/tosTypes.js +5 -8
- package/dist/src/stack/volcengineStack/vefaasPlanner.js +186 -44
- package/dist/src/stack/volcengineStack/vefaasResource.js +232 -14
- package/dist/src/stack/volcengineStack/vefaasTypes.js +6 -3
- package/dist/src/validator/functionSchema.js +25 -2
- package/dist/src/validator/iacSchema.js +2 -1
- package/dist/src/validator/index.js +4 -1
- package/dist/src/validator/rootSchema.js +49 -18
- package/dist/src/validator/schemaExport.js +60 -0
- package/dist/src/validator/semanticValidation.js +79 -0
- package/dist/src/validator/templateRefSchema.js +9 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/release-notes.md +79 -0
- package/samples/aliyun-poc-timer.yml +39 -0
- package/samples/tencent-local/index.js +13 -0
- package/samples/tencent-local/serverlessinsight.yml +23 -0
- package/samples/volcengine-local/index.js +13 -0
- package/samples/volcengine-local/serverlessinsight.yml +28 -0
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateFunctionPlan = void 0;
|
|
4
|
+
const refreshPlanner_1 = require("../../common/refreshPlanner");
|
|
5
|
+
const fc3Types_1 = require("./fc3Types");
|
|
6
|
+
const triggerMapper_1 = require("../../common/triggerMapper");
|
|
4
7
|
const common_1 = require("../../common");
|
|
5
8
|
const aliyunClient_1 = require("../../common/aliyunClient");
|
|
6
9
|
const ramOperations_1 = require("../../common/aliyunClient/ramOperations");
|
|
@@ -9,7 +12,8 @@ const ecsOperations_1 = require("../../common/aliyunClient/ecsOperations");
|
|
|
9
12
|
const refreshCache_1 = require("../../common/refreshCache");
|
|
10
13
|
const planCompare_1 = require("../../common/planCompare");
|
|
11
14
|
const concurrency_1 = require("../../common/concurrency");
|
|
12
|
-
const
|
|
15
|
+
const siCron_1 = require("../../common/siCron");
|
|
16
|
+
const fc3Types_2 = require("./fc3Types");
|
|
13
17
|
const fc3Resource_1 = require("./fc3Resource");
|
|
14
18
|
const lang_1 = require("../../lang");
|
|
15
19
|
const ownershipTag_1 = require("../ownershipTag");
|
|
@@ -64,6 +68,27 @@ const resolveVpcConfigSecurityGroup = async (context, config) => {
|
|
|
64
68
|
},
|
|
65
69
|
};
|
|
66
70
|
};
|
|
71
|
+
const removedFc3Dependents = (fn, currentState) => {
|
|
72
|
+
const recorded = (type) => currentState?.instances?.find((i) => i.type === type);
|
|
73
|
+
const recordedTimers = (currentState?.instances ?? []).filter((i) => i.type === 'ALIYUN_FC3_TIMER_TRIGGER');
|
|
74
|
+
return {
|
|
75
|
+
...(!fn.triggers?.http && recorded('ALIYUN_FC3_HTTP_TRIGGER')
|
|
76
|
+
? {
|
|
77
|
+
http: currentState?.definition?.http ?? recorded('ALIYUN_FC3_HTTP_TRIGGER')?.attributes ?? {},
|
|
78
|
+
}
|
|
79
|
+
: {}),
|
|
80
|
+
...(!fn.domain && recorded('ALIYUN_FC3_CUSTOM_DOMAIN')
|
|
81
|
+
? {
|
|
82
|
+
domain: currentState?.definition?.domain ?? {
|
|
83
|
+
domain_name: recorded('ALIYUN_FC3_CUSTOM_DOMAIN')?.id,
|
|
84
|
+
},
|
|
85
|
+
}
|
|
86
|
+
: {}),
|
|
87
|
+
...(!fn.triggers?.timer && recordedTimers.length > 0
|
|
88
|
+
? { timers: currentState?.definition?.timers ?? [] }
|
|
89
|
+
: {}),
|
|
90
|
+
};
|
|
91
|
+
};
|
|
67
92
|
const planFunctionDeletion = (logicalId, definition) => ({
|
|
68
93
|
logicalId,
|
|
69
94
|
action: 'delete',
|
|
@@ -173,7 +198,8 @@ const detectRolePolicyDrift = async (context, state, fn, currentState, roleName,
|
|
|
173
198
|
},
|
|
174
199
|
],
|
|
175
200
|
};
|
|
176
|
-
if (cloudTrust &&
|
|
201
|
+
if (cloudTrust &&
|
|
202
|
+
(0, planCompare_1.remoteDiffersFromDesired)({ policy: JSON.stringify(cloudTrust) }, { policy: JSON.stringify(desiredTrust) })) {
|
|
177
203
|
return 'PLAN_DRIFT_ROLE_POLICY';
|
|
178
204
|
}
|
|
179
205
|
// b. execution + custom policy (the `<roleName>-policy` custom document). An
|
|
@@ -184,7 +210,7 @@ const detectRolePolicyDrift = async (context, state, fn, currentState, roleName,
|
|
|
184
210
|
const desiredPolicyDocument = parseRolePolicyDocument((0, ramOperations_1.buildFc3ExecutionPolicyDocument)(roleGrant.executionStatements, roleGrant.customStatements));
|
|
185
211
|
if (!cloudPolicy ||
|
|
186
212
|
!desiredPolicyDocument ||
|
|
187
|
-
|
|
213
|
+
(0, planCompare_1.remoteDiffersFromDesired)({ policy: JSON.stringify(cloudPolicy) }, { policy: JSON.stringify(desiredPolicyDocument) })) {
|
|
188
214
|
return 'PLAN_DRIFT_ROLE_POLICY';
|
|
189
215
|
}
|
|
190
216
|
// c. managed (system) policies as sorted name sets; desired ARNs strip the
|
|
@@ -192,7 +218,8 @@ const detectRolePolicyDrift = async (context, state, fn, currentState, roleName,
|
|
|
192
218
|
const desiredManagedNames = (iamRole.managed_policies ?? []).map((policyArn) => policyArn.split('/').pop() ?? '');
|
|
193
219
|
const cloudManagedNames = await (0, refreshCache_1.cachedRefreshRead)(context, `ram.listAttachedRolePolicies:${roleName}`, () => client.ram.listAttachedRolePolicies(roleName));
|
|
194
220
|
const asSortedSetKey = (names) => [...names].sort().join(',');
|
|
195
|
-
if (
|
|
221
|
+
if (iamRole.managed_policies !== undefined &&
|
|
222
|
+
asSortedSetKey(desiredManagedNames) !== asSortedSetKey(cloudManagedNames ?? [])) {
|
|
196
223
|
return 'PLAN_DRIFT_ROLE_POLICY';
|
|
197
224
|
}
|
|
198
225
|
return null;
|
|
@@ -204,6 +231,28 @@ const detectRolePolicyDrift = async (context, state, fn, currentState, roleName,
|
|
|
204
231
|
* cannot shrink shards, so only a shard deficit counts as drift.
|
|
205
232
|
* Returns an i18n drift-reason key (issue #246); null means no drift.
|
|
206
233
|
*/
|
|
234
|
+
const detectFunctionLifecycleDrift = async (context, client, fn) => {
|
|
235
|
+
const reasons = [];
|
|
236
|
+
if (fn.triggers?.http) {
|
|
237
|
+
const triggers = await (0, refreshCache_1.cachedRefreshRead)(context, `fc3.listTriggers:${fn.name}`, () => client.fc3.listTriggers(fn.name));
|
|
238
|
+
const trigger = (triggers ?? []).find((entry) => entry.triggerType === 'http' && entry.triggerName === 'http-trigger');
|
|
239
|
+
if (!trigger ||
|
|
240
|
+
(0, planCompare_1.remoteDiffersFromDesired)({ http: trigger.triggerConfig }, { http: (0, triggerMapper_1.buildAliyunHttpTriggerConfig)(fn.triggers.http) })) {
|
|
241
|
+
reasons.push('PLAN_DRIFT_HTTP_TRIGGER');
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
if (fn.domain) {
|
|
245
|
+
const domain = await (0, refreshCache_1.cachedRefreshRead)(context, `fc3.getCustomDomain:${fn.domain.domain_name}`, () => client.fc3.getCustomDomain(fn.domain.domain_name));
|
|
246
|
+
if (!domain ||
|
|
247
|
+
(domain.protocol !== undefined && domain.protocol !== fn.domain.protocol) ||
|
|
248
|
+
(domain.certConfig?.certificateId !== undefined &&
|
|
249
|
+
fn.domain.certificate_id !== undefined &&
|
|
250
|
+
domain.certConfig.certificateId !== fn.domain.certificate_id)) {
|
|
251
|
+
reasons.push('PLAN_DRIFT_FUNCTION_DOMAIN');
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return reasons;
|
|
255
|
+
};
|
|
207
256
|
const detectFunctionNestedDrift = async (context, client, fn, currentState) => {
|
|
208
257
|
// Each declared dimension contributes its own probe; undeclared dimensions
|
|
209
258
|
// fall through so later dimensions still run.
|
|
@@ -278,6 +327,31 @@ const detectFunctionNestedDrift = async (context, client, fn, currentState) => {
|
|
|
278
327
|
}
|
|
279
328
|
}
|
|
280
329
|
}
|
|
330
|
+
// Issue #258: timer trigger drift — the live trigger list is compared
|
|
331
|
+
// against the desired timers (name-keyed). A trigger missing from the cloud
|
|
332
|
+
// (manual delete), an edited cron/payload/enable, or an extra undeclared
|
|
333
|
+
// timer all count as drift.
|
|
334
|
+
const desiredTimers = fn.triggers?.timer ?? [];
|
|
335
|
+
if (fn.triggers?.timer !== undefined) {
|
|
336
|
+
const liveTriggerList = await (0, refreshCache_1.cachedRefreshRead)(context, `fc3.listTriggers:${fn.name}`, () => client.fc3.listTriggers(fn.name));
|
|
337
|
+
const liveTimers = (liveTriggerList ?? []).filter((trigger) => trigger.triggerType === 'timer' && trigger.triggerName);
|
|
338
|
+
const desiredNames = new Set(desiredTimers.map((timer) => timer.name));
|
|
339
|
+
const extraTimer = liveTimers.some((trigger) => !desiredNames.has(trigger.triggerName));
|
|
340
|
+
const desiredChanged = desiredTimers.some((timer) => {
|
|
341
|
+
const live = liveTimers.find((trigger) => trigger.triggerName === timer.name);
|
|
342
|
+
if (!live) {
|
|
343
|
+
return true;
|
|
344
|
+
}
|
|
345
|
+
const liveConfig = (live.triggerConfig ?? {});
|
|
346
|
+
return (liveConfig.cronExpression !== (0, siCron_1.translateSiCron)(timer.cron, 'aliyun') ||
|
|
347
|
+
(liveConfig.payload ?? '') !== (timer.payload ?? '') ||
|
|
348
|
+
(live.description ?? undefined) !== timer.description ||
|
|
349
|
+
(liveConfig.enable === true || liveConfig.enable === 'true') !== timer.enable);
|
|
350
|
+
});
|
|
351
|
+
if (extraTimer || desiredChanged) {
|
|
352
|
+
return 'PLAN_DRIFT_TIMER_TRIGGER';
|
|
353
|
+
}
|
|
354
|
+
}
|
|
281
355
|
return null;
|
|
282
356
|
};
|
|
283
357
|
const generateFunctionPlan = async (context, state, functions) => {
|
|
@@ -292,161 +366,82 @@ const generateFunctionPlan = async (context, state, functions) => {
|
|
|
292
366
|
const functionItems = await (0, concurrency_1.mapWithConcurrency)(functions, concurrency_1.PLAN_READ_CONCURRENCY, async (fn) => {
|
|
293
367
|
const logicalId = `functions.${fn.key}`;
|
|
294
368
|
const currentState = (0, common_1.getResource)(state, logicalId);
|
|
295
|
-
const rawConfig = (0,
|
|
296
|
-
const config = await resolveVpcConfigSecurityGroup(context, rawConfig);
|
|
369
|
+
const rawConfig = (0, fc3Types_2.functionToFc3Config)(fn);
|
|
370
|
+
const config = (0, fc3Types_1.resolveRecordedFc3NasConfig)(await resolveVpcConfigSecurityGroup(context, rawConfig), fn, currentState?.instances ?? []);
|
|
297
371
|
const desiredCodeHash = fn.code ? await (0, common_1.computeZipContentHash)(fn.code.path) : null;
|
|
298
|
-
const baseDefinition = (0,
|
|
372
|
+
const baseDefinition = (0, fc3Types_2.extractFc3Definition)(config, desiredCodeHash, fn);
|
|
299
373
|
const desiredDefinition = fn.iam ? { ...baseDefinition, iam: fn.iam } : baseDefinition;
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
changes: { before: normalizedCurrent, after: normalizedDesired },
|
|
374
|
+
const client = (0, aliyunClient_1.createAliyunClient)(context);
|
|
375
|
+
return (0, refreshPlanner_1.planRefreshedResource)({
|
|
376
|
+
logicalId,
|
|
377
|
+
resourceType: 'ALIYUN_FC3',
|
|
378
|
+
currentState,
|
|
379
|
+
desiredDefinition,
|
|
380
|
+
removedDependents: removedFc3Dependents(fn, currentState),
|
|
381
|
+
read: () => (0, refreshCache_1.cachedRefreshRead)(context, `fc3.getFunction:${fn.name}`, () => client.fc3.getFunction(fn.name)),
|
|
382
|
+
isOwned: (remote) => (0, ownershipTag_1.isOwnedByStack)(context, logicalId, remote.tags),
|
|
383
|
+
foreignError: () => new Error(lang_1.lang.__('RESOURCE_EXISTS_NOT_OWNED', {
|
|
384
|
+
resourceType: 'Function',
|
|
385
|
+
resourceName: fn.name,
|
|
386
|
+
tagKey: ownershipTag_1.OWNERSHIP_TAG_KEY,
|
|
387
|
+
})),
|
|
388
|
+
cloudToDefinition: fc3Types_2.cloudFc3ToDefinition,
|
|
389
|
+
normalizeForDisplay: normalizeDefinitionForComparison,
|
|
390
|
+
extraUpdate: async () => {
|
|
391
|
+
if (!currentState)
|
|
392
|
+
return { update: false, drifted: false };
|
|
393
|
+
const roleProbe = resolveManagedRoleProbe(context, fn, currentState);
|
|
394
|
+
const roleReason = roleProbe
|
|
395
|
+
? await (async () => {
|
|
396
|
+
const role = await (0, refreshCache_1.cachedRefreshRead)(context, `ram.getRole:${roleProbe.roleName}`, () => client.ram.getRole(roleProbe.roleName));
|
|
397
|
+
return role
|
|
398
|
+
? detectRolePolicyDrift(context, state, fn, currentState, roleProbe.roleName, role)
|
|
399
|
+
: 'PLAN_DRIFT_ROLE_MISSING';
|
|
400
|
+
})()
|
|
401
|
+
: null;
|
|
402
|
+
const lifecycleReasons = await detectFunctionLifecycleDrift(context, client, fn);
|
|
403
|
+
const nestedReason = await detectFunctionNestedDrift(context, client, fn, currentState);
|
|
404
|
+
const reasons = [roleReason, ...lifecycleReasons, nestedReason].filter((reason) => reason !== null);
|
|
405
|
+
const fields = {
|
|
406
|
+
PLAN_DRIFT_HTTP_TRIGGER: 'http',
|
|
407
|
+
PLAN_DRIFT_FUNCTION_DOMAIN: 'domain',
|
|
408
|
+
PLAN_DRIFT_TIMER_TRIGGER: 'timers',
|
|
336
409
|
};
|
|
337
|
-
}
|
|
338
|
-
const remoteFunction = await (0, refreshCache_1.cachedRefreshRead)(context, `fc3.getFunction:${fn.name}`, () => client.fc3.getFunction(fn.name));
|
|
339
|
-
if (!remoteFunction) {
|
|
340
|
-
return {
|
|
341
|
-
logicalId,
|
|
342
|
-
action: 'create',
|
|
343
|
-
resourceType: 'ALIYUN_FC3',
|
|
344
|
-
changes: {
|
|
345
|
-
before: normalizeDefinitionForComparison(currentState.definition),
|
|
346
|
-
after: normalizeDefinitionForComparison(desiredDefinition),
|
|
347
|
-
},
|
|
348
|
-
drifted: true,
|
|
349
|
-
};
|
|
350
|
-
}
|
|
351
|
-
// Issue #234 phase 1: live attribute drift. The stored definition can
|
|
352
|
-
// be untouched while the console edited the deployed function
|
|
353
|
-
// (memory/timeout/env/...). One-directional: only mapper-emitted keys
|
|
354
|
-
// the desired definition declares are compared, so cloud-only extras
|
|
355
|
-
// the config never asked for are ignored (desired-declared contract).
|
|
356
|
-
// Issue #246: the diff baseline is cloud reality — live attributes
|
|
357
|
-
// merged over the stored definition — and revertKeys marks the fields
|
|
358
|
-
// whose difference is purely an out-of-config cloud edit.
|
|
359
|
-
const remoteAttributes = (0, fc3Types_1.cloudFc3ToDefinition)(remoteFunction);
|
|
360
|
-
const remoteDiffers = (0, planCompare_1.remoteDiffersFromDesired)(remoteAttributes, desiredDefinition);
|
|
361
|
-
const liveBefore = normalizeDefinitionForComparison((0, planCompare_1.mergeLiveBefore)(currentState.definition || {}, remoteAttributes));
|
|
362
|
-
const revertKeys = (0, planCompare_1.computeRevertKeys)(normalizedCurrent, normalizeDefinitionForComparison(remoteAttributes), normalizedDesired);
|
|
363
|
-
if (definitionChanged || remoteDiffers) {
|
|
364
410
|
return {
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
411
|
+
update: reasons.length > 0,
|
|
412
|
+
drifted: reasons.some((reason) => {
|
|
413
|
+
if (reason === 'PLAN_DRIFT_ROLE_POLICY') {
|
|
414
|
+
return !(0, planCompare_1.definitionsDiffer)(currentState.definition ?? {}, {
|
|
415
|
+
iam: desiredDefinition.iam,
|
|
416
|
+
vpcConfig: desiredDefinition.vpcConfig,
|
|
417
|
+
nasStorage: desiredDefinition.nasStorage,
|
|
418
|
+
logConfig: desiredDefinition.logConfig,
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
const field = fields[reason];
|
|
422
|
+
return (!field ||
|
|
423
|
+
!(0, planCompare_1.definitionsDiffer)(currentState.definition ?? {}, {
|
|
424
|
+
[field]: desiredDefinition[field],
|
|
425
|
+
}));
|
|
426
|
+
}),
|
|
427
|
+
reasons,
|
|
371
428
|
};
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
action: 'update',
|
|
385
|
-
resourceType: 'ALIYUN_FC3',
|
|
386
|
-
changes: { before: liveBefore, after: normalizedDesired },
|
|
387
|
-
drifted: true,
|
|
388
|
-
driftReasons: ['PLAN_DRIFT_ROLE_MISSING'],
|
|
389
|
-
};
|
|
390
|
-
}
|
|
391
|
-
const roleDriftReason = await detectRolePolicyDrift(context, state, fn, currentState, roleProbe.roleName, cloudRole);
|
|
392
|
-
if (roleDriftReason) {
|
|
393
|
-
return {
|
|
394
|
-
logicalId,
|
|
395
|
-
action: 'update',
|
|
396
|
-
resourceType: 'ALIYUN_FC3',
|
|
397
|
-
changes: { before: liveBefore, after: normalizedDesired },
|
|
398
|
-
drifted: true,
|
|
399
|
-
driftReasons: [roleDriftReason],
|
|
400
|
-
};
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
catch (error) {
|
|
404
|
-
common_1.logger.warn(lang_1.lang.__('PLAN_FUNCTION_ROLE_PROBE_FAILED', {
|
|
405
|
-
roleName: roleProbe.roleName,
|
|
406
|
-
functionName: fn.name,
|
|
407
|
-
error: String(error),
|
|
408
|
-
}));
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
// Issue #234 M1/M2: nested drift probe — the probe itself skips
|
|
412
|
-
// dimensions the config does not declare.
|
|
413
|
-
try {
|
|
414
|
-
const nestedDriftReason = await detectFunctionNestedDrift(context, client, fn, currentState);
|
|
415
|
-
if (nestedDriftReason) {
|
|
416
|
-
return {
|
|
417
|
-
logicalId,
|
|
418
|
-
action: 'update',
|
|
419
|
-
resourceType: 'ALIYUN_FC3',
|
|
420
|
-
changes: { before: liveBefore, after: normalizedDesired },
|
|
421
|
-
drifted: true,
|
|
422
|
-
driftReasons: [nestedDriftReason],
|
|
429
|
+
},
|
|
430
|
+
enrichRemoteAttributes: async (_remote, attributes) => {
|
|
431
|
+
// Lifecycle probes below verify these dimensions separately. Existing
|
|
432
|
+
// intent remains the baseline until those probes confirm equality.
|
|
433
|
+
const reason = currentState
|
|
434
|
+
? await detectFunctionLifecycleDrift(context, client, fn)
|
|
435
|
+
: [];
|
|
436
|
+
return reason.length > 0
|
|
437
|
+
? attributes
|
|
438
|
+
: {
|
|
439
|
+
...attributes,
|
|
440
|
+
...(fn.triggers?.http ? { http: fn.triggers.http } : {}),
|
|
423
441
|
};
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
common_1.logger.warn(lang_1.lang.__('PLAN_FUNCTION_NESTED_PROBE_FAILED', {
|
|
428
|
-
functionName: fn.name,
|
|
429
|
-
error: String(error),
|
|
430
|
-
}));
|
|
431
|
-
}
|
|
432
|
-
return { logicalId, action: 'noop', resourceType: 'ALIYUN_FC3' };
|
|
433
|
-
}
|
|
434
|
-
catch (error) {
|
|
435
|
-
common_1.logger.warn(lang_1.lang.__('PLAN_LIVE_READ_FAILED', {
|
|
436
|
-
logicalId,
|
|
437
|
-
error: error instanceof Error ? error.message : String(error),
|
|
438
|
-
}));
|
|
439
|
-
return {
|
|
440
|
-
logicalId,
|
|
441
|
-
action: 'create',
|
|
442
|
-
resourceType: 'ALIYUN_FC3',
|
|
443
|
-
changes: {
|
|
444
|
-
before: normalizeDefinitionForComparison(currentState.definition),
|
|
445
|
-
after: normalizeDefinitionForComparison(desiredDefinition),
|
|
446
|
-
},
|
|
447
|
-
drifted: true,
|
|
448
|
-
};
|
|
449
|
-
}
|
|
442
|
+
},
|
|
443
|
+
refresh: context.refresh,
|
|
444
|
+
});
|
|
450
445
|
});
|
|
451
446
|
const allStates = (0, common_1.getAllResources)(state);
|
|
452
447
|
const deletionItems = Object.entries(allStates)
|