@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,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.deleteResource = exports.updateResource = exports.readResource = exports.createResource = exports.deriveScfExecutionStatements = void 0;
|
|
4
|
+
const functionDefinition_1 = require("../../common/functionDefinition");
|
|
5
|
+
const planCompare_1 = require("../../common/planCompare");
|
|
6
|
+
const scfHttpTrigger_1 = require("./scfHttpTrigger");
|
|
4
7
|
const types_1 = require("../../types");
|
|
8
|
+
const siCron_1 = require("../../common/siCron");
|
|
5
9
|
const tencentClient_1 = require("../../common/tencentClient");
|
|
6
10
|
const fileUtils_1 = require("../../common/fileUtils");
|
|
7
11
|
const scfTypes_1 = require("./scfTypes");
|
|
@@ -15,26 +19,148 @@ const ownershipTag_1 = require("../ownershipTag");
|
|
|
15
19
|
const alreadyExists_1 = require("../alreadyExists");
|
|
16
20
|
const sharedLogset_1 = require("./sharedLogset");
|
|
17
21
|
const clsOperations_1 = require("../../common/tencentClient/clsOperations");
|
|
22
|
+
const TIMER_TRIGGER_INSTANCE_TYPE = 'TENCENT_SCF_TIMER_TRIGGER';
|
|
23
|
+
/** Tencent timer dialect: 7-field cron (UTC+8, `*` year), payload → CustomArgument. */
|
|
24
|
+
const buildScfTimerTriggerConfig = (timer) => ({
|
|
25
|
+
cron: (0, siCron_1.translateSiCron)(timer.cron, 'tencent'),
|
|
26
|
+
...(timer.payload !== undefined ? { payload: timer.payload } : {}),
|
|
27
|
+
enable: timer.enable,
|
|
28
|
+
...(timer.description !== undefined ? { description: timer.description } : {}),
|
|
29
|
+
});
|
|
30
|
+
const normalizeScfLiveTimerConfig = (trigger) => ({
|
|
31
|
+
cron: trigger.TriggerDesc ?? '',
|
|
32
|
+
...(trigger.CustomArgument !== undefined && trigger.CustomArgument !== ''
|
|
33
|
+
? { payload: trigger.CustomArgument }
|
|
34
|
+
: {}),
|
|
35
|
+
enable: trigger.Enable === 1 || trigger.Enable === 'OPEN',
|
|
36
|
+
...(trigger.Description ? { description: trigger.Description } : {}),
|
|
37
|
+
});
|
|
38
|
+
const scfTimerConfigFromAttributes = (attrs) => {
|
|
39
|
+
const cron = typeof attrs.cron === 'string' ? attrs.cron : undefined;
|
|
40
|
+
if (!cron) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
return {
|
|
45
|
+
cron: (0, siCron_1.translateSiCron)(cron, 'tencent'),
|
|
46
|
+
...(attrs.payload !== undefined ? { payload: String(attrs.payload) } : {}),
|
|
47
|
+
enable: attrs.enable !== false,
|
|
48
|
+
...(attrs.description !== undefined ? { description: String(attrs.description) } : {}),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const buildScfTimerTriggerInstance = (context, fn, timer) => ({
|
|
56
|
+
sid: (0, common_1.buildSid)('tencent', 'scf-timer-trigger', context.stage, `${fn.name}.${timer.name}`),
|
|
57
|
+
type: TIMER_TRIGGER_INSTANCE_TYPE,
|
|
58
|
+
id: timer.name,
|
|
59
|
+
cron: timer.cron,
|
|
60
|
+
...(timer.payload !== undefined ? { payload: timer.payload } : {}),
|
|
61
|
+
enable: timer.enable,
|
|
62
|
+
...(timer.description !== undefined ? { description: timer.description } : {}),
|
|
63
|
+
});
|
|
64
|
+
const deleteScfTimerTrigger = async (fnName, triggerName, client) => {
|
|
65
|
+
try {
|
|
66
|
+
await client.scf.deleteTrigger({
|
|
67
|
+
FunctionName: fnName,
|
|
68
|
+
TriggerName: triggerName,
|
|
69
|
+
Type: 'timer',
|
|
70
|
+
});
|
|
71
|
+
logger_1.logger.info(lang_1.lang.__('TIMER_TRIGGER_DELETED', { triggerName }));
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
const errorCode = err?.code;
|
|
76
|
+
if (errorCode === 'ResourceNotFound.TriggerName' || errorCode === 'ResourceNotFound') {
|
|
77
|
+
logger_1.logger.warn(lang_1.lang.__('TIMER_TRIGGER_NOT_FOUND', { triggerName }));
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
throw err;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
18
83
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
84
|
+
* Reconcile the function's timer triggers against the provider (issue #258).
|
|
85
|
+
*
|
|
86
|
+
* The live trigger list from GetFunction is the reconcile baseline, so
|
|
87
|
+
* console-side cron edits, manual deletions and extra triggers converge on
|
|
88
|
+
* every deploy. When the probe fails the state-recorded instances take over.
|
|
89
|
+
* Name is the drift key; si-cron stays stored and is translated only here.
|
|
25
90
|
*/
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
91
|
+
const reconcileScfTimerTriggers = async (context, fn, previousInstances, client) => {
|
|
92
|
+
const desiredTimers = fn.triggers?.timer ?? [];
|
|
93
|
+
const previousTimers = previousInstances.filter((i) => i.type === TIMER_TRIGGER_INSTANCE_TYPE);
|
|
94
|
+
if (desiredTimers.length === 0 && previousTimers.length === 0) {
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
97
|
+
let liveTimers = [];
|
|
98
|
+
let liveAvailable = true;
|
|
99
|
+
try {
|
|
100
|
+
const probe = await client.scf.getFunction(fn.name);
|
|
101
|
+
liveTimers = (probe?.Triggers ?? [])
|
|
102
|
+
.filter((trigger) => trigger.Type === 'timer' && trigger.TriggerName)
|
|
103
|
+
.map((trigger) => ({
|
|
104
|
+
name: trigger.TriggerName,
|
|
105
|
+
config: normalizeScfLiveTimerConfig(trigger),
|
|
106
|
+
}));
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
liveAvailable = false;
|
|
110
|
+
logger_1.logger.warn(lang_1.lang.__('PLAN_TIMER_TRIGGER_PROBE_FAILED', { functionName: fn.name, error: String(error) }));
|
|
111
|
+
}
|
|
112
|
+
const baseline = liveAvailable
|
|
113
|
+
? liveTimers
|
|
114
|
+
: previousTimers.flatMap((instance) => {
|
|
115
|
+
const config = scfTimerConfigFromAttributes(instance);
|
|
116
|
+
return config ? [{ name: String(instance.id), config }] : [];
|
|
117
|
+
});
|
|
118
|
+
const resultingInstances = [];
|
|
119
|
+
for (const timer of desiredTimers) {
|
|
120
|
+
const desiredConfig = buildScfTimerTriggerConfig(timer);
|
|
121
|
+
const live = baseline.find((entry) => entry.name === timer.name);
|
|
122
|
+
if (!live) {
|
|
123
|
+
logger_1.logger.info(lang_1.lang.__('CREATING_TIMER_TRIGGER', { triggerName: timer.name, functionName: fn.name }));
|
|
124
|
+
}
|
|
125
|
+
else if (!(0, common_1.attributesEqual)(live.config, desiredConfig)) {
|
|
126
|
+
logger_1.logger.info(lang_1.lang.__('UPDATING_TIMER_TRIGGER', { triggerName: timer.name, functionName: fn.name }));
|
|
127
|
+
await deleteScfTimerTrigger(fn.name, timer.name, client);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
resultingInstances.push(buildScfTimerTriggerInstance(context, fn, timer));
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
try {
|
|
134
|
+
await client.scf.createTrigger({
|
|
135
|
+
FunctionName: fn.name,
|
|
136
|
+
TriggerName: timer.name,
|
|
137
|
+
Type: 'timer',
|
|
138
|
+
TriggerDesc: desiredConfig.cron,
|
|
139
|
+
...(desiredConfig.payload !== undefined ? { CustomArgument: desiredConfig.payload } : {}),
|
|
140
|
+
Qualifier: '$DEFAULT',
|
|
141
|
+
Enable: desiredConfig.enable ? 'OPEN' : 'CLOSE',
|
|
142
|
+
...(desiredConfig.description ? { Description: desiredConfig.description } : {}),
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
// a leftover trigger from an adopted function may already carry the name
|
|
147
|
+
if (!(0, alreadyExists_1.isResourceAlreadyExistsError)(error))
|
|
148
|
+
throw error;
|
|
149
|
+
logger_1.logger.warn(lang_1.lang.__('TIMER_TRIGGER_ALREADY_ATTACHED', {
|
|
150
|
+
triggerName: timer.name,
|
|
151
|
+
functionName: fn.name,
|
|
152
|
+
}));
|
|
153
|
+
}
|
|
154
|
+
logger_1.logger.info(lang_1.lang.__('TIMER_TRIGGER_CREATED', { triggerName: timer.name, functionName: fn.name }));
|
|
155
|
+
resultingInstances.push(buildScfTimerTriggerInstance(context, fn, timer));
|
|
156
|
+
}
|
|
157
|
+
const desiredNames = new Set(desiredTimers.map((timer) => timer.name));
|
|
158
|
+
for (const stale of baseline.filter((entry) => !desiredNames.has(entry.name))) {
|
|
159
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_TIMER_TRIGGER', { triggerName: stale.name, functionName: fn.name }));
|
|
160
|
+
await deleteScfTimerTrigger(fn.name, stale.name, client);
|
|
161
|
+
}
|
|
162
|
+
return resultingInstances;
|
|
163
|
+
};
|
|
38
164
|
/**
|
|
39
165
|
* Best-effort extraction of a cloud-SDK error's useful details. Tencent SDK
|
|
40
166
|
* errors carry `code`/`message`/`requestId` (and may throw with an empty
|
|
@@ -100,13 +226,15 @@ const isLogConfigChanged = (desiredDefinition, existingDefinition) => {
|
|
|
100
226
|
}
|
|
101
227
|
return !(0, common_1.attributesEqual)(desiredLogConfig, existingDefinition.logConfig ?? {});
|
|
102
228
|
};
|
|
103
|
-
const
|
|
229
|
+
const isScfFunctionInstance = (instance) => typeof instance.functionName === 'string' || instance.type == null;
|
|
230
|
+
const buildScfInstanceFromProvider = (info, sid, ownedHttpIds = []) => {
|
|
104
231
|
const envMap = info.Environment?.Variables?.reduce((acc, v) => ({ ...acc, [v.Key]: v.Value }), {}) ?? {};
|
|
105
232
|
const triggersArray = info.Triggers?.map((t) => ({
|
|
106
233
|
modTime: t.ModTime,
|
|
107
234
|
type: t.Type,
|
|
108
235
|
triggerDesc: t.TriggerDesc,
|
|
109
236
|
triggerName: t.TriggerName,
|
|
237
|
+
...(t.Type === 'http' ? { owned: ownedHttpIds.includes(t.TriggerName) } : {}),
|
|
110
238
|
addTime: t.AddTime,
|
|
111
239
|
enable: t.Enable,
|
|
112
240
|
customArgument: t.CustomArgument ?? null,
|
|
@@ -330,7 +458,7 @@ const createDependentResources = async (context, fn, existingInstances = [], sta
|
|
|
330
458
|
clsInstances.push(logsetInstance, topicInstance);
|
|
331
459
|
}
|
|
332
460
|
else {
|
|
333
|
-
const legacyFn = existingInstances.find((i) => i
|
|
461
|
+
const legacyFn = existingInstances.find((i) => isScfFunctionInstance(i));
|
|
334
462
|
if (legacyFn?.clsLogsetId && legacyFn?.clsTopicId) {
|
|
335
463
|
clsConfig = {
|
|
336
464
|
logsetId: legacyFn.clsLogsetId,
|
|
@@ -474,7 +602,7 @@ const createResource = async (context, fn, state) => {
|
|
|
474
602
|
const codePath = fn.code.path;
|
|
475
603
|
const codeBase64 = (0, fileUtils_1.readFileAsBase64)(codePath);
|
|
476
604
|
const codeHash = await (0, hashUtils_1.computeZipContentHash)(codePath);
|
|
477
|
-
const definition = (0, scfTypes_1.extractScfDefinition)(config, codeHash, fn.iam);
|
|
605
|
+
const definition = (0, scfTypes_1.extractScfDefinition)(config, codeHash, fn.iam, fn);
|
|
478
606
|
const dependentInstances = [...dependentResources.clsInstances];
|
|
479
607
|
if (dependentResources.role) {
|
|
480
608
|
const iamConfig = fn.iam?.role;
|
|
@@ -499,14 +627,10 @@ const createResource = async (context, fn, state) => {
|
|
|
499
627
|
const stateWithShared = dependentResources.sharedInstance
|
|
500
628
|
? (0, stateManager_1.setSharedResource)(state, context.stage, sharedLogset_1.SHARED_LOGSET_KEY, dependentResources.sharedInstance)
|
|
501
629
|
: state;
|
|
502
|
-
|
|
630
|
+
let stateAfterDependents = (0, stateManager_1.setResource)(stateWithShared, logicalId, taintedResourceState);
|
|
503
631
|
const client = (0, tencentClient_1.createTencentClient)(context);
|
|
504
632
|
const isTainted = existingResourceState?.status === 'tainted';
|
|
505
633
|
const existingFunctionOnRetry = isTainted ? await client.scf.getFunction(fn.name) : null;
|
|
506
|
-
// Provider info of a function adopted from a previous partial run (tainted
|
|
507
|
-
// retry or reconciled after a create error) — used to skip already-attached
|
|
508
|
-
// triggers below.
|
|
509
|
-
let adoptedInfo = existingFunctionOnRetry;
|
|
510
634
|
if (existingFunctionOnRetry) {
|
|
511
635
|
logger_1.logger.info(lang_1.lang.__('TAINTED_RECOVERY_SKIP_CREATE', { resourceType: 'Function', resourceName: fn.name }));
|
|
512
636
|
}
|
|
@@ -526,7 +650,6 @@ const createResource = async (context, fn, state) => {
|
|
|
526
650
|
await delay(RECOVERY_GET_FUNCTION_DELAY_MS);
|
|
527
651
|
const afterError = await client.scf.getFunction(fn.name);
|
|
528
652
|
if (afterError) {
|
|
529
|
-
adoptedInfo = afterError;
|
|
530
653
|
logger_1.logger.info(lang_1.lang.__('FC3_FOUND_AFTER_CREATE_RECONCILE', { functionName: fn.name }));
|
|
531
654
|
}
|
|
532
655
|
else {
|
|
@@ -542,7 +665,6 @@ const createResource = async (context, fn, state) => {
|
|
|
542
665
|
// a resource that was never ours).
|
|
543
666
|
const probe = await client.scf.getFunction(fn.name);
|
|
544
667
|
if (probe && (0, ownershipTag_1.isOwnedByStack)(context, logicalId, probe.Tags)) {
|
|
545
|
-
adoptedInfo = probe;
|
|
546
668
|
logger_1.logger.info(lang_1.lang.__('RESOURCE_OWNERSHIP_TAG_ADOPT', {
|
|
547
669
|
resourceType: 'Function',
|
|
548
670
|
name: fn.name,
|
|
@@ -561,55 +683,28 @@ const createResource = async (context, fn, state) => {
|
|
|
561
683
|
throw new types_1.PartialResourceError(stateAfterDependents, new Error(toErrorMessage(error)));
|
|
562
684
|
}
|
|
563
685
|
}
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
}
|
|
582
|
-
const triggerAlreadyAttached = providerTriggers.some(isFunctionUrlTrigger);
|
|
583
|
-
if (triggerAlreadyAttached) {
|
|
584
|
-
logger_1.logger.info(lang_1.lang.__('SCF_HTTP_TRIGGER_ALREADY_ATTACHED', { triggerName, functionName: fn.name }));
|
|
686
|
+
try {
|
|
687
|
+
const httpInstances = await (0, scfHttpTrigger_1.reconcileScfHttpTrigger)(context, fn, existingResourceState?.instances ?? [], existingResourceState?.definition ?? {}, client, false, existingResourceState?.status === 'tainted');
|
|
688
|
+
dependentInstances.push(...httpInstances);
|
|
689
|
+
if (httpInstances.length)
|
|
690
|
+
stateAfterDependents = (0, stateManager_1.setResource)(stateAfterDependents, logicalId, {
|
|
691
|
+
...taintedResourceState,
|
|
692
|
+
instances: [...dependentInstances],
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
catch (error) {
|
|
696
|
+
throw new types_1.PartialResourceError(stateAfterDependents, new Error(toErrorMessage(error)));
|
|
697
|
+
}
|
|
698
|
+
// Create timer triggers if configured — a failure mid-way persists the
|
|
699
|
+
// tainted state so a re-run reconciles instead of duplicating triggers.
|
|
700
|
+
if (fn.triggers?.timer) {
|
|
701
|
+
try {
|
|
702
|
+
dependentInstances.push(...(await reconcileScfTimerTriggers(context, fn, [], client)));
|
|
585
703
|
}
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
FunctionName: fn.name,
|
|
591
|
-
TriggerName: triggerName,
|
|
592
|
-
Type: 'http',
|
|
593
|
-
TriggerDesc: triggerDesc,
|
|
594
|
-
Qualifier: '$DEFAULT',
|
|
595
|
-
Enable: 'OPEN',
|
|
596
|
-
});
|
|
597
|
-
logger_1.logger.info(lang_1.lang.__('HTTP_TRIGGER_CREATED', { triggerName, functionName: fn.name }));
|
|
598
|
-
}
|
|
599
|
-
catch (error) {
|
|
600
|
-
if ((0, alreadyExists_1.isResourceAlreadyExistsError)(error)) {
|
|
601
|
-
logger_1.logger.warn(lang_1.lang.__('SCF_HTTP_TRIGGER_ALREADY_EXISTS', {
|
|
602
|
-
triggerName,
|
|
603
|
-
functionName: fn.name,
|
|
604
|
-
error: String(error),
|
|
605
|
-
}));
|
|
606
|
-
}
|
|
607
|
-
else {
|
|
608
|
-
// The function exists in the cloud but the trigger failed to attach —
|
|
609
|
-
// persist the tainted state so a re-run reconciles instead of losing it.
|
|
610
|
-
throw new types_1.PartialResourceError(stateAfterDependents, new Error(toErrorMessage(error)));
|
|
611
|
-
}
|
|
612
|
-
}
|
|
704
|
+
catch (error) {
|
|
705
|
+
if (error instanceof types_1.PartialResourceError)
|
|
706
|
+
throw error;
|
|
707
|
+
throw new types_1.PartialResourceError(stateAfterDependents, new Error(toErrorMessage(error)));
|
|
613
708
|
}
|
|
614
709
|
}
|
|
615
710
|
// Create custom domain if configured
|
|
@@ -661,7 +756,9 @@ const createResource = async (context, fn, state) => {
|
|
|
661
756
|
region: context.region,
|
|
662
757
|
definition,
|
|
663
758
|
instances: [
|
|
664
|
-
buildScfInstanceFromProvider(functionInfo, sid
|
|
759
|
+
buildScfInstanceFromProvider(functionInfo, sid, dependentInstances
|
|
760
|
+
.filter((instance) => instance.type === scfHttpTrigger_1.SCF_HTTP_TRIGGER_TYPE)
|
|
761
|
+
.map((instance) => instance.id)),
|
|
665
762
|
...dependentInstances,
|
|
666
763
|
],
|
|
667
764
|
lastUpdated: new Date().toISOString(),
|
|
@@ -675,11 +772,12 @@ const readResource = async (context, functionName) => {
|
|
|
675
772
|
return await client.scf.getFunction(functionName);
|
|
676
773
|
};
|
|
677
774
|
exports.readResource = readResource;
|
|
678
|
-
const updateResource = async (context,
|
|
679
|
-
const logicalId = `functions.${
|
|
775
|
+
const updateResource = async (context, providedFn, state, options) => {
|
|
776
|
+
const logicalId = `functions.${providedFn.key}`;
|
|
680
777
|
const existingState = (0, stateManager_1.getResource)(state, logicalId);
|
|
778
|
+
const fn = (0, functionDefinition_1.withStoredFunctionIam)(providedFn, existingState?.definition);
|
|
681
779
|
const existingInstances = (existingState?.instances ?? []);
|
|
682
|
-
const existingFnInstance = existingInstances.find((i) => i
|
|
780
|
+
const existingFnInstance = existingInstances.find((i) => isScfFunctionInstance(i));
|
|
683
781
|
const existingClsTopicInstance = existingInstances.find((i) => i.type === types_1.ResourceTypeEnum.TENCENT_CLS_TOPIC);
|
|
684
782
|
const existingDefinition = (existingState?.definition ?? {});
|
|
685
783
|
const legacyLogsetId = existingFnInstance?.clsLogsetId;
|
|
@@ -772,7 +870,7 @@ const updateResource = async (context, fn, state, options) => {
|
|
|
772
870
|
let clsConfig;
|
|
773
871
|
let clsTopicInstance;
|
|
774
872
|
let clsSharedInstance;
|
|
775
|
-
const disableLog =
|
|
873
|
+
const disableLog = fn.log === false && wasLogEnabled;
|
|
776
874
|
let topicToDelete;
|
|
777
875
|
let topicNameToDelete;
|
|
778
876
|
let sharedLogsetReleased = false;
|
|
@@ -839,7 +937,7 @@ const updateResource = async (context, fn, state, options) => {
|
|
|
839
937
|
// Tencent's UpdateFunctionConfiguration rejects Handler/Runtime (immutable at
|
|
840
938
|
// creation) and we don't want to re-send unchanged values. Handler/Runtime
|
|
841
939
|
// changes are a hard error: the platform cannot apply them on update.
|
|
842
|
-
const desiredDefinition = (0, scfTypes_1.extractScfDefinition)(config, codeHash, fn.iam);
|
|
940
|
+
const desiredDefinition = (0, scfTypes_1.extractScfDefinition)(config, codeHash, fn.iam, fn);
|
|
843
941
|
const CONFIG_DIFF_KEYS = ['runtime', 'handler', 'memorySize', 'timeout', 'environment', 'role'];
|
|
844
942
|
const mutableKeys = CONFIG_DIFF_KEYS.filter((k) => k !== 'runtime' && k !== 'handler');
|
|
845
943
|
if (desiredDefinition.handler &&
|
|
@@ -858,7 +956,7 @@ const updateResource = async (context, fn, state, options) => {
|
|
|
858
956
|
newRuntime: String(desiredDefinition.runtime),
|
|
859
957
|
}));
|
|
860
958
|
}
|
|
861
|
-
const configChanged = mutableKeys.some((k) =>
|
|
959
|
+
const configChanged = mutableKeys.some((k) => (0, planCompare_1.definitionsDiffer)({ [k]: existingDefinition[k] }, { [k]: desiredDefinition[k] })) ||
|
|
862
960
|
isLogConfigChanged(desiredDefinition, existingDefinition) ||
|
|
863
961
|
// Disabling log always re-pushes config so the empty Cls ids reach the
|
|
864
962
|
// UpdateFunctionConfiguration unbind contract.
|
|
@@ -888,146 +986,26 @@ const updateResource = async (context, fn, state, options) => {
|
|
|
888
986
|
}
|
|
889
987
|
// Update code
|
|
890
988
|
await client.scf.updateFunctionCode(fn.name, codeBase64);
|
|
891
|
-
const
|
|
892
|
-
const
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
catch (err) {
|
|
912
|
-
const errorCode = err?.code;
|
|
913
|
-
if (errorCode !== 'ResourceNotFound.TriggerName' && errorCode !== 'ResourceNotFound') {
|
|
914
|
-
throw err;
|
|
915
|
-
}
|
|
916
|
-
}
|
|
917
|
-
await client.scf.createTrigger({
|
|
918
|
-
FunctionName: fn.name,
|
|
919
|
-
TriggerName: triggerName,
|
|
920
|
-
Type: 'http',
|
|
921
|
-
TriggerDesc: desiredTriggerDesc,
|
|
922
|
-
Qualifier: '$DEFAULT',
|
|
923
|
-
Enable: 'OPEN',
|
|
924
|
-
});
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
else {
|
|
928
|
-
// No trigger recorded in state — but a leftover trigger may still exist
|
|
929
|
-
// in the provider (e.g. adopted function whose state lacked trigger
|
|
930
|
-
// records). Probe before creating to stay idempotent.
|
|
931
|
-
const probe = await client.scf.getFunction(fn.name);
|
|
932
|
-
const providerTriggerAttached = (probe?.Triggers ?? []).some(isFunctionUrlTrigger);
|
|
933
|
-
if (providerTriggerAttached) {
|
|
934
|
-
logger_1.logger.info(lang_1.lang.__('SCF_HTTP_TRIGGER_ALREADY_ATTACHED', { triggerName, functionName: fn.name }));
|
|
935
|
-
}
|
|
936
|
-
else {
|
|
937
|
-
logger_1.logger.info(lang_1.lang.__('CREATING_HTTP_TRIGGER', { triggerName, functionName: fn.name }));
|
|
938
|
-
try {
|
|
939
|
-
await client.scf.createTrigger({
|
|
940
|
-
FunctionName: fn.name,
|
|
941
|
-
TriggerName: triggerName,
|
|
942
|
-
Type: 'http',
|
|
943
|
-
TriggerDesc: desiredTriggerDesc,
|
|
944
|
-
Qualifier: '$DEFAULT',
|
|
945
|
-
Enable: 'OPEN',
|
|
946
|
-
});
|
|
947
|
-
logger_1.logger.info(lang_1.lang.__('HTTP_TRIGGER_CREATED', { triggerName, functionName: fn.name }));
|
|
948
|
-
}
|
|
949
|
-
catch (error) {
|
|
950
|
-
if ((0, alreadyExists_1.isResourceAlreadyExistsError)(error)) {
|
|
951
|
-
logger_1.logger.warn(lang_1.lang.__('SCF_HTTP_TRIGGER_ALREADY_EXISTS', {
|
|
952
|
-
triggerName,
|
|
953
|
-
functionName: fn.name,
|
|
954
|
-
error: String(error),
|
|
955
|
-
}));
|
|
956
|
-
}
|
|
957
|
-
else {
|
|
958
|
-
throw error;
|
|
959
|
-
}
|
|
960
|
-
}
|
|
961
|
-
}
|
|
962
|
-
}
|
|
963
|
-
}
|
|
964
|
-
else if (existingHttpTrigger) {
|
|
965
|
-
const tName = existingHttpTrigger.triggerName;
|
|
966
|
-
logger_1.logger.info(lang_1.lang.__('DELETING_HTTP_TRIGGER', { triggerName: tName, functionName: fn.name }));
|
|
967
|
-
try {
|
|
968
|
-
await client.scf.deleteTrigger({
|
|
969
|
-
FunctionName: fn.name,
|
|
970
|
-
TriggerName: tName,
|
|
971
|
-
Type: 'http',
|
|
972
|
-
});
|
|
973
|
-
logger_1.logger.info(lang_1.lang.__('HTTP_TRIGGER_DELETED', { triggerName: tName }));
|
|
974
|
-
}
|
|
975
|
-
catch (err) {
|
|
976
|
-
const errorCode = err?.code;
|
|
977
|
-
if (errorCode === 'ResourceNotFound.TriggerName' || errorCode === 'ResourceNotFound') {
|
|
978
|
-
logger_1.logger.warn(lang_1.lang.__('HTTP_TRIGGER_NOT_FOUND', { triggerName: tName }));
|
|
979
|
-
}
|
|
980
|
-
else {
|
|
981
|
-
throw err;
|
|
982
|
-
}
|
|
983
|
-
}
|
|
984
|
-
}
|
|
985
|
-
// Reconcile custom domain
|
|
986
|
-
const existingCustomDomain = existingInstances.find((i) => i.type === 'TENCENT_SCF_CUSTOM_DOMAIN');
|
|
987
|
-
if (fn.domain && !existingCustomDomain) {
|
|
988
|
-
logger_1.logger.info(lang_1.lang.__('CREATING_CUSTOM_DOMAIN', { domainName: fn.domain.domain_name }));
|
|
989
|
-
await client.scf.createCustomDomain({
|
|
990
|
-
Domain: fn.domain.domain_name,
|
|
991
|
-
Protocol: fn.domain.protocol,
|
|
992
|
-
EndpointsConfig: [
|
|
993
|
-
{
|
|
994
|
-
Namespace: 'default',
|
|
995
|
-
FunctionName: fn.name,
|
|
996
|
-
Qualifier: '$DEFAULT',
|
|
997
|
-
PathMatch: '/*',
|
|
998
|
-
},
|
|
999
|
-
],
|
|
1000
|
-
...(fn.domain.certificate_id
|
|
1001
|
-
? { CertConfig: { CertificateId: fn.domain.certificate_id } }
|
|
1002
|
-
: {}),
|
|
1003
|
-
});
|
|
1004
|
-
logger_1.logger.info(lang_1.lang.__('CUSTOM_DOMAIN_CREATED', { domainName: fn.domain.domain_name }));
|
|
1005
|
-
}
|
|
1006
|
-
else if (!fn.domain && existingCustomDomain) {
|
|
1007
|
-
logger_1.logger.info(lang_1.lang.__('DELETING_CUSTOM_DOMAIN', { domainName: existingCustomDomain.id }));
|
|
1008
|
-
try {
|
|
1009
|
-
await client.scf.deleteCustomDomain(existingCustomDomain.id);
|
|
1010
|
-
logger_1.logger.info(lang_1.lang.__('CUSTOM_DOMAIN_DELETED', { domainName: existingCustomDomain.id }));
|
|
1011
|
-
}
|
|
1012
|
-
catch (err) {
|
|
1013
|
-
const errorCode = err?.code;
|
|
1014
|
-
if (errorCode === 'ResourceNotFound') {
|
|
1015
|
-
logger_1.logger.warn(lang_1.lang.__('RESOURCE_NOT_FOUND_PROVIDER', {
|
|
1016
|
-
resourceType: 'Custom Domain',
|
|
1017
|
-
name: existingCustomDomain.id,
|
|
1018
|
-
}));
|
|
1019
|
-
}
|
|
1020
|
-
else {
|
|
1021
|
-
throw err;
|
|
1022
|
-
}
|
|
1023
|
-
}
|
|
1024
|
-
}
|
|
1025
|
-
else if (fn.domain && existingCustomDomain) {
|
|
1026
|
-
const domainChanged = fn.domain.domain_name !== existingCustomDomain.id ||
|
|
1027
|
-
fn.domain.protocol !== existingCustomDomain.protocol;
|
|
1028
|
-
if (domainChanged) {
|
|
1029
|
-
logger_1.logger.info(lang_1.lang.__('DELETING_CUSTOM_DOMAIN', { domainName: existingCustomDomain.id }));
|
|
1030
|
-
await client.scf.deleteCustomDomain(existingCustomDomain.id);
|
|
989
|
+
const httpInstances = await (0, scfHttpTrigger_1.reconcileScfHttpTrigger)(context, fn, existingInstances, existingState?.definition ?? {}, client, options?.repairHttp);
|
|
990
|
+
const stateAfterHttp = (0, stateManager_1.setResource)(state, logicalId, {
|
|
991
|
+
...(existingState ?? {
|
|
992
|
+
mode: 'managed',
|
|
993
|
+
region: context.region,
|
|
994
|
+
definition: existingDefinition,
|
|
995
|
+
lastUpdated: new Date().toISOString(),
|
|
996
|
+
}),
|
|
997
|
+
instances: [
|
|
998
|
+
...(existingState?.instances ?? []).filter((instance) => instance.type !== scfHttpTrigger_1.SCF_HTTP_TRIGGER_TYPE),
|
|
999
|
+
...httpInstances,
|
|
1000
|
+
],
|
|
1001
|
+
});
|
|
1002
|
+
try {
|
|
1003
|
+
// Reconcile timer triggers against the provider (issue #258) — the live
|
|
1004
|
+
// GetFunction trigger list is the baseline so console edits converge.
|
|
1005
|
+
const timerInstances = await reconcileScfTimerTriggers(context, fn, existingInstances, client);
|
|
1006
|
+
// Reconcile custom domain
|
|
1007
|
+
const existingCustomDomain = existingInstances.find((i) => i.type === 'TENCENT_SCF_CUSTOM_DOMAIN');
|
|
1008
|
+
if (fn.domain && !existingCustomDomain) {
|
|
1031
1009
|
logger_1.logger.info(lang_1.lang.__('CREATING_CUSTOM_DOMAIN', { domainName: fn.domain.domain_name }));
|
|
1032
1010
|
await client.scf.createCustomDomain({
|
|
1033
1011
|
Domain: fn.domain.domain_name,
|
|
@@ -1046,100 +1024,137 @@ const updateResource = async (context, fn, state, options) => {
|
|
|
1046
1024
|
});
|
|
1047
1025
|
logger_1.logger.info(lang_1.lang.__('CUSTOM_DOMAIN_CREATED', { domainName: fn.domain.domain_name }));
|
|
1048
1026
|
}
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1027
|
+
else if (!fn.domain && existingCustomDomain) {
|
|
1028
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_CUSTOM_DOMAIN', { domainName: existingCustomDomain.id }));
|
|
1029
|
+
try {
|
|
1030
|
+
await client.scf.deleteCustomDomain(existingCustomDomain.id);
|
|
1031
|
+
logger_1.logger.info(lang_1.lang.__('CUSTOM_DOMAIN_DELETED', { domainName: existingCustomDomain.id }));
|
|
1032
|
+
}
|
|
1033
|
+
catch (err) {
|
|
1034
|
+
const errorCode = err?.code;
|
|
1035
|
+
if (errorCode !== 'ResourceNotFound')
|
|
1036
|
+
throw err;
|
|
1037
|
+
logger_1.logger.warn(lang_1.lang.__('RESOURCE_NOT_FOUND_PROVIDER', {
|
|
1038
|
+
resourceType: 'Custom Domain',
|
|
1039
|
+
name: existingCustomDomain.id,
|
|
1040
|
+
}));
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
else if (fn.domain && existingCustomDomain) {
|
|
1044
|
+
const domainChanged = options?.repairDomain ||
|
|
1045
|
+
!(0, common_1.attributesEqual)(existingState?.definition?.domain ?? {}, fn.domain) ||
|
|
1046
|
+
fn.domain.domain_name !== existingCustomDomain.id ||
|
|
1047
|
+
fn.domain.protocol !== existingCustomDomain.protocol;
|
|
1048
|
+
if (domainChanged) {
|
|
1049
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_CUSTOM_DOMAIN', { domainName: existingCustomDomain.id }));
|
|
1050
|
+
await client.scf.deleteCustomDomain(existingCustomDomain.id);
|
|
1051
|
+
logger_1.logger.info(lang_1.lang.__('CREATING_CUSTOM_DOMAIN', { domainName: fn.domain.domain_name }));
|
|
1052
|
+
await client.scf.createCustomDomain({
|
|
1053
|
+
Domain: fn.domain.domain_name,
|
|
1054
|
+
Protocol: fn.domain.protocol,
|
|
1055
|
+
EndpointsConfig: [
|
|
1056
|
+
{
|
|
1057
|
+
Namespace: 'default',
|
|
1058
|
+
FunctionName: fn.name,
|
|
1059
|
+
Qualifier: '$DEFAULT',
|
|
1060
|
+
PathMatch: '/*',
|
|
1061
|
+
},
|
|
1062
|
+
],
|
|
1063
|
+
...(fn.domain.certificate_id
|
|
1064
|
+
? { CertConfig: { CertificateId: fn.domain.certificate_id } }
|
|
1065
|
+
: {}),
|
|
1066
|
+
});
|
|
1067
|
+
logger_1.logger.info(lang_1.lang.__('CUSTOM_DOMAIN_CREATED', { domainName: fn.domain.domain_name }));
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
// Refresh state from provider to get all attributes (including triggers)
|
|
1071
|
+
const functionInfo = await client.scf.getFunction(fn.name);
|
|
1072
|
+
if (!functionInfo) {
|
|
1073
|
+
throw new Error(lang_1.lang.__('REFRESH_STATE_FUNCTION', { name: fn.name }));
|
|
1074
|
+
}
|
|
1075
|
+
const definition = (0, scfTypes_1.extractScfDefinition)(config, codeHash, fn.iam, fn);
|
|
1076
|
+
const sid = (0, common_1.buildSid)('tencent', 'scf', context.stage, fn.name);
|
|
1077
|
+
const existingDependentInstances = existingInstances
|
|
1078
|
+
.filter((i) => !isScfFunctionInstance(i) &&
|
|
1079
|
+
i.type !== 'TENCENT_SCF_CUSTOM_DOMAIN' &&
|
|
1080
|
+
// timers are fully rebuilt from the reconcile result below
|
|
1081
|
+
i.type !== TIMER_TRIGGER_INSTANCE_TYPE &&
|
|
1082
|
+
i.type !== scfHttpTrigger_1.SCF_HTTP_TRIGGER_TYPE &&
|
|
1083
|
+
!((clsTopicInstance || disableLog) &&
|
|
1084
|
+
(i.type === types_1.ResourceTypeEnum.TENCENT_CLS_TOPIC ||
|
|
1085
|
+
i.type === types_1.ResourceTypeEnum.TENCENT_CLS_LOGSET)))
|
|
1086
|
+
.map((i) => {
|
|
1087
|
+
const { type, id, sid, roleArn, external } = i;
|
|
1088
|
+
return {
|
|
1089
|
+
sid: sid ?? (0, common_1.buildSid)('tencent', 'scf-role', context.stage, id),
|
|
1090
|
+
type,
|
|
1091
|
+
id,
|
|
1092
|
+
...(roleArn ? { roleArn } : {}),
|
|
1093
|
+
...(external ? { external } : {}),
|
|
1094
|
+
};
|
|
1090
1095
|
});
|
|
1096
|
+
const newDependentInstances = [];
|
|
1097
|
+
if (role && !hasCamRole && typeof newIamRole !== 'string') {
|
|
1098
|
+
const newRoleSid = (0, common_1.buildSid)('tencent', 'scf-role', context.stage, role.roleName ?? '');
|
|
1099
|
+
newDependentInstances.push({
|
|
1100
|
+
sid: newRoleSid,
|
|
1101
|
+
type: types_1.ResourceTypeEnum.TENCENT_SCF_ROLE,
|
|
1102
|
+
id: role.roleName ?? '',
|
|
1103
|
+
...(role.arn ? { roleArn: role.arn } : {}),
|
|
1104
|
+
});
|
|
1105
|
+
}
|
|
1106
|
+
if (fn.domain) {
|
|
1107
|
+
const domainSid = (0, common_1.buildSid)('tencent', 'scf-custom-domain', context.stage, fn.domain.domain_name);
|
|
1108
|
+
newDependentInstances.push({
|
|
1109
|
+
sid: domainSid,
|
|
1110
|
+
type: 'TENCENT_SCF_CUSTOM_DOMAIN',
|
|
1111
|
+
id: fn.domain.domain_name,
|
|
1112
|
+
protocol: fn.domain.protocol,
|
|
1113
|
+
});
|
|
1114
|
+
}
|
|
1115
|
+
if (clsTopicInstance) {
|
|
1116
|
+
newDependentInstances.push(clsTopicInstance);
|
|
1117
|
+
}
|
|
1118
|
+
const resourceState = {
|
|
1119
|
+
mode: 'managed',
|
|
1120
|
+
region: context.region,
|
|
1121
|
+
definition: (0, functionDefinition_1.withLifecycleIntent)((0, planCompare_1.mergeManagedIntent)(existingState?.definition ?? {}, definition), definition, ['http', 'domain', 'timers']),
|
|
1122
|
+
instances: [
|
|
1123
|
+
buildScfInstanceFromProvider(functionInfo, sid, httpInstances.map((instance) => instance.id)),
|
|
1124
|
+
...existingDependentInstances,
|
|
1125
|
+
...newDependentInstances,
|
|
1126
|
+
...timerInstances,
|
|
1127
|
+
...httpInstances,
|
|
1128
|
+
],
|
|
1129
|
+
lastUpdated: new Date().toISOString(),
|
|
1130
|
+
};
|
|
1131
|
+
const stateWithShared = clsSharedInstance
|
|
1132
|
+
? (0, stateManager_1.setSharedResource)(state, context.stage, sharedLogset_1.SHARED_LOGSET_KEY, clsSharedInstance)
|
|
1133
|
+
: sharedLogsetReleased
|
|
1134
|
+
? (0, stateManager_1.removeSharedResource)(state, context.stage, sharedLogset_1.SHARED_LOGSET_KEY)
|
|
1135
|
+
: state;
|
|
1136
|
+
return (0, stateManager_1.setResource)(stateWithShared, logicalId, resourceState);
|
|
1091
1137
|
}
|
|
1092
|
-
|
|
1093
|
-
|
|
1138
|
+
catch (error) {
|
|
1139
|
+
if (error instanceof types_1.PartialResourceError)
|
|
1140
|
+
throw error;
|
|
1141
|
+
throw new types_1.PartialResourceError(stateAfterHttp, new Error(toErrorMessage(error)));
|
|
1094
1142
|
}
|
|
1095
|
-
const resourceState = {
|
|
1096
|
-
mode: 'managed',
|
|
1097
|
-
region: context.region,
|
|
1098
|
-
definition,
|
|
1099
|
-
instances: [
|
|
1100
|
-
buildScfInstanceFromProvider(functionInfo, sid),
|
|
1101
|
-
...existingDependentInstances,
|
|
1102
|
-
...newDependentInstances,
|
|
1103
|
-
],
|
|
1104
|
-
lastUpdated: new Date().toISOString(),
|
|
1105
|
-
};
|
|
1106
|
-
const stateWithShared = clsSharedInstance
|
|
1107
|
-
? (0, stateManager_1.setSharedResource)(state, context.stage, sharedLogset_1.SHARED_LOGSET_KEY, clsSharedInstance)
|
|
1108
|
-
: sharedLogsetReleased
|
|
1109
|
-
? (0, stateManager_1.removeSharedResource)(state, context.stage, sharedLogset_1.SHARED_LOGSET_KEY)
|
|
1110
|
-
: state;
|
|
1111
|
-
return (0, stateManager_1.setResource)(stateWithShared, logicalId, resourceState);
|
|
1112
1143
|
};
|
|
1113
1144
|
exports.updateResource = updateResource;
|
|
1114
1145
|
const deleteResource = async (context, functionName, logicalId, state) => {
|
|
1115
1146
|
const existingState = (0, stateManager_1.getResource)(state, logicalId);
|
|
1116
1147
|
const existingInstances = (existingState?.instances ?? []);
|
|
1117
1148
|
const client = (0, tencentClient_1.createTencentClient)(context);
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
TriggerName: triggerName,
|
|
1128
|
-
Type: 'http',
|
|
1129
|
-
});
|
|
1130
|
-
logger_1.logger.info(lang_1.lang.__('HTTP_TRIGGER_DELETED', { triggerName }));
|
|
1131
|
-
}
|
|
1132
|
-
catch (err) {
|
|
1133
|
-
const errorCode = err?.code;
|
|
1134
|
-
if (errorCode === 'ResourceNotFound.TriggerName' || errorCode === 'ResourceNotFound') {
|
|
1135
|
-
logger_1.logger.warn(lang_1.lang.__('HTTP_TRIGGER_NOT_FOUND', {
|
|
1136
|
-
triggerName: httpTrigger.triggerName,
|
|
1137
|
-
}));
|
|
1138
|
-
}
|
|
1139
|
-
else {
|
|
1140
|
-
throw err;
|
|
1141
|
-
}
|
|
1142
|
-
}
|
|
1149
|
+
const ownedHttp = (0, scfHttpTrigger_1.ownedScfHttpTrigger)(existingInstances, existingState?.definition ?? {});
|
|
1150
|
+
if (ownedHttp) {
|
|
1151
|
+
await (0, scfHttpTrigger_1.reconcileScfHttpTrigger)(context, { name: functionName }, existingInstances, existingState?.definition ?? {}, client);
|
|
1152
|
+
}
|
|
1153
|
+
// Delete timer triggers before deleting function
|
|
1154
|
+
const timerTriggerInstances = existingInstances.filter((i) => i.type === TIMER_TRIGGER_INSTANCE_TYPE);
|
|
1155
|
+
for (const timerInstance of timerTriggerInstances) {
|
|
1156
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_TIMER_TRIGGER', { triggerName: timerInstance.id, functionName }));
|
|
1157
|
+
await deleteScfTimerTrigger(functionName, timerInstance.id, client);
|
|
1143
1158
|
}
|
|
1144
1159
|
// Delete custom domain before deleting function
|
|
1145
1160
|
const existingCustomDomain = existingInstances.find((i) => i.type === 'TENCENT_SCF_CUSTOM_DOMAIN');
|
|
@@ -1162,7 +1177,7 @@ const deleteResource = async (context, functionName, logicalId, state) => {
|
|
|
1162
1177
|
}
|
|
1163
1178
|
}
|
|
1164
1179
|
}
|
|
1165
|
-
const hasFunction = existingInstances.some((i) => i
|
|
1180
|
+
const hasFunction = existingInstances.some((i) => isScfFunctionInstance(i));
|
|
1166
1181
|
if (hasFunction) {
|
|
1167
1182
|
try {
|
|
1168
1183
|
await client.scf.deleteFunction(functionName);
|
|
@@ -1177,8 +1192,11 @@ const deleteResource = async (context, functionName, logicalId, state) => {
|
|
|
1177
1192
|
}
|
|
1178
1193
|
}
|
|
1179
1194
|
}
|
|
1180
|
-
const dependentInstances = existingInstances.filter((i) => i
|
|
1181
|
-
i.type !== 'TENCENT_SCF_CUSTOM_DOMAIN'
|
|
1195
|
+
const dependentInstances = existingInstances.filter((i) => !isScfFunctionInstance(i) &&
|
|
1196
|
+
i.type !== 'TENCENT_SCF_CUSTOM_DOMAIN' &&
|
|
1197
|
+
// timers were deleted explicitly above
|
|
1198
|
+
i.type !== TIMER_TRIGGER_INSTANCE_TYPE &&
|
|
1199
|
+
i.type !== scfHttpTrigger_1.SCF_HTTP_TRIGGER_TYPE);
|
|
1182
1200
|
if (dependentInstances.length > 0) {
|
|
1183
1201
|
await deleteDependentResources(context, dependentInstances);
|
|
1184
1202
|
}
|