@geek-fun/serverlessinsight 0.9.6 → 0.9.8
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/AGENTS.md +1 -0
- package/CHANGELOG.md +68 -0
- package/README.md +52 -11
- package/README.zh-CN.md +44 -10
- package/dist/package.json +2 -1
- package/dist/src/commands/deploy.js +3 -1
- package/dist/src/commands/destroy.js +3 -1
- package/dist/src/commands/forceUnlock.js +2 -2
- package/dist/src/commands/index.js +28 -8
- package/dist/src/commands/local.js +3 -2
- package/dist/src/commands/login.js +120 -37
- package/dist/src/commands/logout.js +3 -5
- package/dist/src/commands/migrate.js +17 -10
- package/dist/src/commands/plan.js +5 -1
- package/dist/src/commands/show.js +3 -1
- package/dist/src/commands/whoami.js +24 -6
- package/dist/src/common/aliyunClient/cdnOperations.js +64 -29
- package/dist/src/common/aliyunClient/dnsOperations.js +10 -0
- package/dist/src/common/aliyunClient/fc3Operations.js +36 -7
- package/dist/src/common/apiClient.js +1 -0
- package/dist/src/common/bindingReconcile.js +182 -0
- package/dist/src/common/cdnCapabilities.js +80 -0
- package/dist/src/common/certUtils.js +44 -5
- package/dist/src/common/consoleLines.js +126 -0
- package/dist/src/common/constants.js +4 -2
- package/dist/src/common/credentialStore.js +136 -39
- package/dist/src/common/domainUtils.js +23 -4
- package/dist/src/common/functionDefinition.js +4 -1
- package/dist/src/common/functionDomainCapabilities.js +28 -0
- package/dist/src/common/functionDomainReconcile.js +197 -0
- package/dist/src/common/lineContext.js +164 -0
- package/dist/src/common/planCapabilities.js +14 -27
- package/dist/src/common/planCompare.js +8 -7
- package/dist/src/common/planFormatter.js +71 -37
- package/dist/src/common/stateBackend/cosStateBackend.js +0 -46
- package/dist/src/common/stateBackend/index.js +24 -16
- package/dist/src/common/stateBackend/ossStateBackend.js +0 -25
- package/dist/src/common/stateBackend/remoteStateBackend.js +5 -22
- package/dist/src/common/stateBackend/saasStateBackend.js +46 -53
- package/dist/src/common/stateBackend/tosStateBackend.js +100 -0
- package/dist/src/common/stateBackend/types.js +0 -9
- package/dist/src/common/tencentClient/cdnOperations.js +165 -0
- package/dist/src/common/tencentClient/cosOperations.js +18 -2
- package/dist/src/common/tencentClient/dnspodOperations.js +12 -0
- package/dist/src/common/tencentClient/index.js +16 -0
- package/dist/src/common/tencentClient/scfOperations.js +23 -1
- package/dist/src/common/tencentClient/sslOperations.js +147 -77
- package/dist/src/common/volcengineClient/cdnOperations.js +221 -0
- package/dist/src/common/volcengineClient/dnsOperations.js +132 -0
- package/dist/src/common/volcengineClient/index.js +28 -0
- package/dist/src/common/volcengineClient/tosOperations.js +131 -1
- package/dist/src/lang/en.js +89 -12
- package/dist/src/lang/zh-CN.js +90 -11
- package/dist/src/parser/bucketParser.js +22 -79
- package/dist/src/parser/functionParser.js +13 -9
- package/dist/src/stack/aliyunStack/apigwResource.js +2 -1
- package/dist/src/stack/aliyunStack/fc3Planner.js +32 -12
- package/dist/src/stack/aliyunStack/fc3Resource.js +169 -121
- package/dist/src/stack/aliyunStack/ossPlanner.js +12 -4
- package/dist/src/stack/aliyunStack/ossResource.js +484 -501
- package/dist/src/stack/aliyunStack/ossTypes.js +21 -67
- package/dist/src/stack/localStack/aliyunFc.js +59 -9
- package/dist/src/stack/localStack/bucket.js +75 -28
- package/dist/src/stack/localStack/event.js +33 -24
- package/dist/src/stack/localStack/httpAdapter.js +1 -13
- package/dist/src/stack/localStack/index.js +2 -2
- package/dist/src/stack/localStack/localServer.js +85 -7
- package/dist/src/stack/scfStack/cosPlanner.js +11 -3
- package/dist/src/stack/scfStack/cosResource.js +339 -161
- package/dist/src/stack/scfStack/cosTypes.js +25 -34
- package/dist/src/stack/scfStack/scfPlanner.js +26 -8
- package/dist/src/stack/scfStack/scfResource.js +191 -124
- package/dist/src/stack/volcengineStack/tosPlanner.js +13 -1
- package/dist/src/stack/volcengineStack/tosResource.js +398 -7
- package/dist/src/stack/volcengineStack/tosTypes.js +27 -0
- package/dist/src/stack/volcengineStack/vefaasTypes.js +1 -1
- package/dist/src/types/domains/state.js +6 -0
- package/dist/src/validator/bucketSchema.js +35 -113
- package/dist/src/validator/cdnSchema.js +30 -0
- package/dist/src/validator/eventSchema.js +2 -20
- package/dist/src/validator/functionSchema.js +55 -8
- package/dist/src/validator/rootSchema.js +3 -3
- package/dist/src/validator/semanticValidation.js +504 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -1
- package/release-notes.md +82 -6
- package/samples/aliyun-poc-api-cdn.yml +1 -1
- package/samples/aliyun-poc-bucket-cdn.yml +28 -26
- package/samples/aliyun-poc-domain.yml +2 -1
- package/samples/volcengine-poc-tos-state.yml +36 -0
|
@@ -11,6 +11,7 @@ const refreshCache_1 = require("../../common/refreshCache");
|
|
|
11
11
|
const clsOperations_1 = require("../../common/tencentClient/clsOperations");
|
|
12
12
|
const concurrency_1 = require("../../common/concurrency");
|
|
13
13
|
const siCron_1 = require("../../common/siCron");
|
|
14
|
+
const functionDomainReconcile_1 = require("../../common/functionDomainReconcile");
|
|
14
15
|
const scfTypes_1 = require("./scfTypes");
|
|
15
16
|
const stateManager_1 = require("../../common/stateManager");
|
|
16
17
|
const hashUtils_1 = require("../../common/hashUtils");
|
|
@@ -47,7 +48,7 @@ const generateFunctionPlan = async (context, state, functions) => {
|
|
|
47
48
|
const desiredCodeHash = await (0, hashUtils_1.computeZipContentHash)(codePath);
|
|
48
49
|
const desiredDefinition = (0, scfTypes_1.extractScfDefinition)(config, desiredCodeHash, fn.iam, fn);
|
|
49
50
|
const client = (0, tencentClient_1.createTencentClient)(context);
|
|
50
|
-
const
|
|
51
|
+
const recordedDomainInstances = (currentState?.instances ?? []).filter((i) => i.type === 'TENCENT_SCF_CUSTOM_DOMAIN');
|
|
51
52
|
const recordedTimers = (currentState?.instances ?? []).filter((i) => i.type === 'TENCENT_SCF_TIMER_TRIGGER');
|
|
52
53
|
return (0, refreshPlanner_1.planRefreshedResource)({
|
|
53
54
|
logicalId,
|
|
@@ -59,8 +60,20 @@ const generateFunctionPlan = async (context, state, functions) => {
|
|
|
59
60
|
(0, scfHttpTrigger_1.ownedScfHttpTrigger)(currentState?.instances ?? [], currentState?.definition ?? {})
|
|
60
61
|
? { http: currentState?.definition.http ?? { auth_type: 'public' } }
|
|
61
62
|
: {}),
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
// Removed domain bindings surface the stored canonicalized entries;
|
|
64
|
+
// a pre-#286 state (no definition.domains) reconstructs the legacy
|
|
65
|
+
// `/*` binding so the diff still shows the removal.
|
|
66
|
+
...(!(fn.domains?.length ?? 0) && recordedDomainInstances.length > 0
|
|
67
|
+
? {
|
|
68
|
+
domains: (Array.isArray(currentState?.definition?.domains) &&
|
|
69
|
+
(currentState?.definition?.domains).length > 0
|
|
70
|
+
? currentState?.definition?.domains
|
|
71
|
+
: recordedDomainInstances.map((i) => (0, functionDomainReconcile_1.functionDomainDefinitionEntry)({
|
|
72
|
+
domain_name: String(i.id),
|
|
73
|
+
path: i.paths?.[0] ?? '/*',
|
|
74
|
+
protocol: ['HTTPS'],
|
|
75
|
+
}))),
|
|
76
|
+
}
|
|
64
77
|
: {}),
|
|
65
78
|
...(!fn.triggers?.timer && recordedTimers.length > 0
|
|
66
79
|
? { timers: currentState?.definition?.timers ?? [] }
|
|
@@ -89,14 +102,19 @@ const generateFunctionPlan = async (context, state, functions) => {
|
|
|
89
102
|
reason: 'PLAN_DRIFT_HTTP_TRIGGER',
|
|
90
103
|
});
|
|
91
104
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
105
|
+
// Domain bindings (issue #286): every declared domain must exist
|
|
106
|
+
// with the expected protocol. Route drift is not probed here — the
|
|
107
|
+
// executor converges routes on every apply; certificate changes
|
|
108
|
+
// ride the state's certificate_hash.
|
|
109
|
+
for (const binding of fn.domains ?? []) {
|
|
110
|
+
const domainName = (0, functionDomainReconcile_1.normalizeFunctionDomainName)(binding.domain_name);
|
|
111
|
+
const domain = await (0, refreshCache_1.cachedRefreshRead)(context, `scf.getCustomDomain:${domainName}`, () => client.scf.getCustomDomain(domainName));
|
|
112
|
+
const protocolString = (0, functionDomainReconcile_1.mapFunctionProtocol)('tencent', binding.protocol);
|
|
113
|
+
if (!domain || (domain.Protocol !== undefined && domain.Protocol !== protocolString))
|
|
96
114
|
updates.push({
|
|
97
115
|
update: true,
|
|
98
116
|
drifted: !(0, planCompare_1.definitionsDiffer)(currentState?.definition ?? {}, {
|
|
99
|
-
|
|
117
|
+
domains: desiredDefinition.domains,
|
|
100
118
|
}),
|
|
101
119
|
reason: 'PLAN_DRIFT_FUNCTION_DOMAIN',
|
|
102
120
|
});
|
|
@@ -8,6 +8,8 @@ const types_1 = require("../../types");
|
|
|
8
8
|
const siCron_1 = require("../../common/siCron");
|
|
9
9
|
const tencentClient_1 = require("../../common/tencentClient");
|
|
10
10
|
const fileUtils_1 = require("../../common/fileUtils");
|
|
11
|
+
const certUtils_1 = require("../../common/certUtils");
|
|
12
|
+
const functionDomainReconcile_1 = require("../../common/functionDomainReconcile");
|
|
11
13
|
const scfTypes_1 = require("./scfTypes");
|
|
12
14
|
const stateManager_1 = require("../../common/stateManager");
|
|
13
15
|
const common_1 = require("../../common");
|
|
@@ -161,6 +163,168 @@ const reconcileScfTimerTriggers = async (context, fn, previousInstances, client)
|
|
|
161
163
|
}
|
|
162
164
|
return resultingInstances;
|
|
163
165
|
};
|
|
166
|
+
const SCF_DOMAIN_INSTANCE_TYPE = 'TENCENT_SCF_CUSTOM_DOMAIN';
|
|
167
|
+
const SCF_NAMESPACE_PARAMETER_KEY = 'namespace';
|
|
168
|
+
const resolveScfNamespace = (context) => context.parameters?.find((parameter) => parameter.key === SCF_NAMESPACE_PARAMETER_KEY)?.value ??
|
|
169
|
+
'default';
|
|
170
|
+
/** Resolves a binding's certificate for SCF: a reference id passes through, inline PEM uploads to SSL service (Repeatable:false makes re-upload idempotent) and delivers an id. */
|
|
171
|
+
const resolveScfCertConfig = async (client, binding) => {
|
|
172
|
+
if (binding.certificate_id)
|
|
173
|
+
return { CertificateId: binding.certificate_id };
|
|
174
|
+
if (binding.certificate_body && binding.certificate_private_key) {
|
|
175
|
+
const body = (0, certUtils_1.readPemContent)(binding.certificate_body);
|
|
176
|
+
const key = (0, certUtils_1.readPemContent)(binding.certificate_private_key);
|
|
177
|
+
const certInfo = await client.ssl.uploadCertificate(binding.domain_name.replace(/\./g, '_'), body, key);
|
|
178
|
+
return { CertificateId: certInfo.certificateId };
|
|
179
|
+
}
|
|
180
|
+
return undefined;
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
* Releases a function's routes from a cloud-side domain (issue #286): pure
|
|
184
|
+
* route subtraction — the domain is deleted when the function was the last
|
|
185
|
+
* binding (per-owner teardown with a live-route check).
|
|
186
|
+
*/
|
|
187
|
+
const releaseScfDomainRoutes = async (context, client, domainName, own) => {
|
|
188
|
+
const live = await client.scf.getCustomDomain(domainName);
|
|
189
|
+
const liveRoutes = (live?.EndpointsConfig ?? []).map((endpoint) => ({
|
|
190
|
+
path: endpoint.PathMatch ?? '',
|
|
191
|
+
functionName: endpoint.FunctionName ?? '',
|
|
192
|
+
qualifier: endpoint.Qualifier,
|
|
193
|
+
}));
|
|
194
|
+
const remaining = (0, functionDomainReconcile_1.mergeDomainRoutes)(liveRoutes, own, 'remove');
|
|
195
|
+
if (liveRoutes.length === 0)
|
|
196
|
+
return;
|
|
197
|
+
if (remaining.length === 0) {
|
|
198
|
+
logger_1.logger.info(lang_1.lang.__('FUNCTION_DOMAIN_ROUTE_RELEASED', { functionName: own.functionName, domainName }));
|
|
199
|
+
await client.scf.deleteCustomDomain(domainName);
|
|
200
|
+
logger_1.logger.info(lang_1.lang.__('CUSTOM_DOMAIN_DELETED', { domainName }));
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if ((0, functionDomainReconcile_1.routesEqual)(liveRoutes, remaining))
|
|
204
|
+
return;
|
|
205
|
+
logger_1.logger.info(lang_1.lang.__('REMOVING_FUNCTION_DOMAIN_ROUTES', { functionName: own.functionName, domainName }));
|
|
206
|
+
const namespace = resolveScfNamespace(context);
|
|
207
|
+
await client.scf.updateCustomDomain({
|
|
208
|
+
Domain: domainName,
|
|
209
|
+
EndpointsConfig: remaining.map((route) => ({
|
|
210
|
+
Namespace: namespace,
|
|
211
|
+
FunctionName: route.functionName,
|
|
212
|
+
Qualifier: route.qualifier ?? functionDomainReconcile_1.DEFAULT_FUNCTION_QUALIFIER,
|
|
213
|
+
PathMatch: route.path,
|
|
214
|
+
})),
|
|
215
|
+
});
|
|
216
|
+
};
|
|
217
|
+
const buildScfDomainBindingInstance = (context, binding, protocolString) => ({
|
|
218
|
+
type: SCF_DOMAIN_INSTANCE_TYPE,
|
|
219
|
+
id: binding.domainName,
|
|
220
|
+
sid: (0, common_1.buildSid)('tencent', 'scf-custom-domain', context.stage, binding.domainName),
|
|
221
|
+
paths: binding.paths,
|
|
222
|
+
protocol: protocolString,
|
|
223
|
+
});
|
|
224
|
+
/**
|
|
225
|
+
* Converges one domain binding: creates the domain (with state-less adoption
|
|
226
|
+
* when a previous partial run already created it — ownership proven by live
|
|
227
|
+
* routes referencing this stack's functions) or updates routes/protocol/cert
|
|
228
|
+
* in place via UpdateCustomDomain. Certificates redeploy only on content
|
|
229
|
+
* change (certificate_hash in state, issue #283 pattern).
|
|
230
|
+
*/
|
|
231
|
+
const applyScfDomainBinding = async (context, fn, existingState, client, desired, options) => {
|
|
232
|
+
const protocolString = (0, functionDomainReconcile_1.mapFunctionProtocol)('tencent', desired.representative.protocol);
|
|
233
|
+
const endpointsFor = (routes) => routes.map((route) => ({
|
|
234
|
+
Namespace: resolveScfNamespace(context),
|
|
235
|
+
FunctionName: route.functionName,
|
|
236
|
+
Qualifier: route.qualifier ?? functionDomainReconcile_1.DEFAULT_FUNCTION_QUALIFIER,
|
|
237
|
+
PathMatch: route.path,
|
|
238
|
+
}));
|
|
239
|
+
const live = await client.scf.getCustomDomain(desired.domainName);
|
|
240
|
+
const liveRoutes = (live?.EndpointsConfig ?? []).map((endpoint) => ({
|
|
241
|
+
path: endpoint.PathMatch ?? '',
|
|
242
|
+
functionName: endpoint.FunctionName ?? '',
|
|
243
|
+
qualifier: endpoint.Qualifier,
|
|
244
|
+
}));
|
|
245
|
+
const desiredRoutes = (0, functionDomainReconcile_1.mergeDomainRoutes)(liveRoutes, { functionName: fn.name, paths: desired.paths }, 'apply');
|
|
246
|
+
const desiredCertHash = (0, functionDomainReconcile_1.functionDomainDefinitionEntry)(desired.representative).certificate_hash ?? undefined;
|
|
247
|
+
const storedCertHash = (0, functionDomainReconcile_1.storedFunctionDomainCertHash)(existingState?.definition, desired.domainName);
|
|
248
|
+
const certConfig = storedCertHash !== desiredCertHash || options?.repairDomain === true
|
|
249
|
+
? await resolveScfCertConfig(client, desired.representative)
|
|
250
|
+
: undefined;
|
|
251
|
+
const converge = async (current) => {
|
|
252
|
+
const currentRoutes = (current.EndpointsConfig ?? []).map((endpoint) => ({
|
|
253
|
+
path: endpoint.PathMatch ?? '',
|
|
254
|
+
functionName: endpoint.FunctionName ?? '',
|
|
255
|
+
qualifier: endpoint.Qualifier,
|
|
256
|
+
}));
|
|
257
|
+
const protocolChanged = current.Protocol !== undefined && current.Protocol !== protocolString;
|
|
258
|
+
const routesChanged = !(0, functionDomainReconcile_1.routesEqual)(currentRoutes, desiredRoutes);
|
|
259
|
+
if (protocolChanged || routesChanged || certConfig) {
|
|
260
|
+
logger_1.logger.info(lang_1.lang.__('UPDATING_FUNCTION_DOMAIN_ROUTES', {
|
|
261
|
+
domainName: desired.domainName,
|
|
262
|
+
count: String(desiredRoutes.length),
|
|
263
|
+
}));
|
|
264
|
+
await client.scf.updateCustomDomain({
|
|
265
|
+
Domain: desired.domainName,
|
|
266
|
+
Protocol: protocolString,
|
|
267
|
+
EndpointsConfig: endpointsFor(desiredRoutes),
|
|
268
|
+
...(certConfig ? { CertConfig: certConfig } : {}),
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
if (!live) {
|
|
273
|
+
const stackFunctionNames = (0, functionDomainReconcile_1.collectStackFunctionNames)(context.iac?.functions, fn.name);
|
|
274
|
+
try {
|
|
275
|
+
logger_1.logger.info(lang_1.lang.__('CREATING_CUSTOM_DOMAIN', { domainName: desired.domainName }));
|
|
276
|
+
await client.scf.createCustomDomain({
|
|
277
|
+
Domain: desired.domainName,
|
|
278
|
+
Protocol: protocolString,
|
|
279
|
+
EndpointsConfig: endpointsFor(desiredRoutes),
|
|
280
|
+
...(certConfig ? { CertConfig: certConfig } : {}),
|
|
281
|
+
});
|
|
282
|
+
logger_1.logger.info(lang_1.lang.__('CUSTOM_DOMAIN_CREATED', { domainName: desired.domainName }));
|
|
283
|
+
}
|
|
284
|
+
catch (error) {
|
|
285
|
+
if (!(0, alreadyExists_1.isResourceAlreadyExistsError)(error))
|
|
286
|
+
throw error;
|
|
287
|
+
const existing = await client.scf.getCustomDomain(desired.domainName);
|
|
288
|
+
const existingRoutes = (existing?.EndpointsConfig ?? []).map((endpoint) => ({
|
|
289
|
+
functionName: endpoint.FunctionName ?? '',
|
|
290
|
+
}));
|
|
291
|
+
if (!existing ||
|
|
292
|
+
!existingRoutes.some((route) => stackFunctionNames.has(route.functionName))) {
|
|
293
|
+
throw new Error(lang_1.lang.__('FUNCTION_DOMAIN_EXISTS_NOT_OWNED', { domainName: desired.domainName }), error instanceof Error ? { cause: error } : undefined);
|
|
294
|
+
}
|
|
295
|
+
logger_1.logger.info(lang_1.lang.__('FUNCTION_DOMAIN_OWNED_ADOPT', { domainName: desired.domainName }));
|
|
296
|
+
await converge(existing);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
await converge(live);
|
|
301
|
+
}
|
|
302
|
+
return buildScfDomainBindingInstance(context, desired, protocolString);
|
|
303
|
+
};
|
|
304
|
+
/**
|
|
305
|
+
* Reconciles every domain this function touches: desired bindings converge
|
|
306
|
+
* the shared domain resource, removed bindings release routes. Returns the
|
|
307
|
+
* fresh binding instances.
|
|
308
|
+
*/
|
|
309
|
+
const reconcileScfFunctionDomains = async (context, fn, existingInstances, existingState, client, options) => {
|
|
310
|
+
const storedBindings = (0, functionDomainReconcile_1.storedFunctionDomainBindings)(existingInstances, SCF_DOMAIN_INSTANCE_TYPE);
|
|
311
|
+
const desiredBindings = (0, functionDomainReconcile_1.aggregateFunctionDomainBindings)(fn.domains);
|
|
312
|
+
const touched = [...new Set([...storedBindings.keys(), ...desiredBindings.keys()])].sort();
|
|
313
|
+
const instances = [];
|
|
314
|
+
for (const domainName of touched) {
|
|
315
|
+
const desired = desiredBindings.get(domainName);
|
|
316
|
+
if (desired) {
|
|
317
|
+
instances.push(await applyScfDomainBinding(context, fn, existingState, client, desired, options));
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
await releaseScfDomainRoutes(context, client, domainName, {
|
|
321
|
+
functionName: fn.name,
|
|
322
|
+
paths: storedBindings.get(domainName)?.paths ?? [],
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
return instances;
|
|
327
|
+
};
|
|
164
328
|
/**
|
|
165
329
|
* Best-effort extraction of a cloud-SDK error's useful details. Tencent SDK
|
|
166
330
|
* errors carry `code`/`message`/`requestId` (and may throw with an empty
|
|
@@ -707,37 +871,20 @@ const createResource = async (context, fn, state) => {
|
|
|
707
871
|
throw new types_1.PartialResourceError(stateAfterDependents, new Error(toErrorMessage(error)));
|
|
708
872
|
}
|
|
709
873
|
}
|
|
710
|
-
//
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
Namespace: 'default',
|
|
720
|
-
FunctionName: fn.name,
|
|
721
|
-
Qualifier: '$DEFAULT',
|
|
722
|
-
PathMatch: '/*',
|
|
723
|
-
},
|
|
724
|
-
],
|
|
725
|
-
...(fn.domain.certificate_id
|
|
726
|
-
? { CertConfig: { CertificateId: fn.domain.certificate_id } }
|
|
727
|
-
: {}),
|
|
874
|
+
// Reconcile custom domain bindings (issue #286): cross-function merged
|
|
875
|
+
// routes; a failure here persists the tainted state for retry.
|
|
876
|
+
try {
|
|
877
|
+
const domainInstances = await reconcileScfFunctionDomains(context, fn, (existingResourceState?.instances ?? []), existingResourceState, client);
|
|
878
|
+
dependentInstances.push(...domainInstances);
|
|
879
|
+
if (domainInstances.length > 0) {
|
|
880
|
+
stateAfterDependents = (0, stateManager_1.setResource)(stateAfterDependents, logicalId, {
|
|
881
|
+
...taintedResourceState,
|
|
882
|
+
instances: [...dependentInstances],
|
|
728
883
|
});
|
|
729
884
|
}
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
logger_1.logger.info(lang_1.lang.__('CUSTOM_DOMAIN_CREATED', { domainName: fn.domain.domain_name }));
|
|
734
|
-
const domainSid = (0, common_1.buildSid)('tencent', 'scf-custom-domain', context.stage, fn.domain.domain_name);
|
|
735
|
-
dependentInstances.push({
|
|
736
|
-
sid: domainSid,
|
|
737
|
-
type: 'TENCENT_SCF_CUSTOM_DOMAIN',
|
|
738
|
-
id: fn.domain.domain_name,
|
|
739
|
-
protocol: fn.domain.protocol,
|
|
740
|
-
});
|
|
885
|
+
}
|
|
886
|
+
catch (error) {
|
|
887
|
+
throw new types_1.PartialResourceError(stateAfterDependents, new Error(toErrorMessage(error)));
|
|
741
888
|
}
|
|
742
889
|
// Refresh state from provider to get all attributes (including triggers)
|
|
743
890
|
let functionInfo;
|
|
@@ -1003,70 +1150,9 @@ const updateResource = async (context, providedFn, state, options) => {
|
|
|
1003
1150
|
// Reconcile timer triggers against the provider (issue #258) — the live
|
|
1004
1151
|
// GetFunction trigger list is the baseline so console edits converge.
|
|
1005
1152
|
const timerInstances = await reconcileScfTimerTriggers(context, fn, existingInstances, client);
|
|
1006
|
-
// Reconcile custom domain
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
logger_1.logger.info(lang_1.lang.__('CREATING_CUSTOM_DOMAIN', { domainName: fn.domain.domain_name }));
|
|
1010
|
-
await client.scf.createCustomDomain({
|
|
1011
|
-
Domain: fn.domain.domain_name,
|
|
1012
|
-
Protocol: fn.domain.protocol,
|
|
1013
|
-
EndpointsConfig: [
|
|
1014
|
-
{
|
|
1015
|
-
Namespace: 'default',
|
|
1016
|
-
FunctionName: fn.name,
|
|
1017
|
-
Qualifier: '$DEFAULT',
|
|
1018
|
-
PathMatch: '/*',
|
|
1019
|
-
},
|
|
1020
|
-
],
|
|
1021
|
-
...(fn.domain.certificate_id
|
|
1022
|
-
? { CertConfig: { CertificateId: fn.domain.certificate_id } }
|
|
1023
|
-
: {}),
|
|
1024
|
-
});
|
|
1025
|
-
logger_1.logger.info(lang_1.lang.__('CUSTOM_DOMAIN_CREATED', { domainName: fn.domain.domain_name }));
|
|
1026
|
-
}
|
|
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
|
-
}
|
|
1153
|
+
// Reconcile custom domain bindings (issue #286): cross-function merged
|
|
1154
|
+
// routes converge via UpdateCustomDomain; removed bindings release routes.
|
|
1155
|
+
const domainInstances = await reconcileScfFunctionDomains(context, fn, existingInstances, existingState, client, { repairDomain: options?.repairDomain });
|
|
1070
1156
|
// Refresh state from provider to get all attributes (including triggers)
|
|
1071
1157
|
const functionInfo = await client.scf.getFunction(fn.name);
|
|
1072
1158
|
if (!functionInfo) {
|
|
@@ -1103,28 +1189,20 @@ const updateResource = async (context, providedFn, state, options) => {
|
|
|
1103
1189
|
...(role.arn ? { roleArn: role.arn } : {}),
|
|
1104
1190
|
});
|
|
1105
1191
|
}
|
|
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
1192
|
if (clsTopicInstance) {
|
|
1116
1193
|
newDependentInstances.push(clsTopicInstance);
|
|
1117
1194
|
}
|
|
1118
1195
|
const resourceState = {
|
|
1119
1196
|
mode: 'managed',
|
|
1120
1197
|
region: context.region,
|
|
1121
|
-
definition: (0, functionDefinition_1.withLifecycleIntent)((0, planCompare_1.mergeManagedIntent)(existingState?.definition ?? {}, definition), definition, ['http', '
|
|
1198
|
+
definition: (0, functionDefinition_1.withLifecycleIntent)((0, planCompare_1.mergeManagedIntent)(existingState?.definition ?? {}, definition), definition, ['http', 'domains', 'timers']),
|
|
1122
1199
|
instances: [
|
|
1123
1200
|
buildScfInstanceFromProvider(functionInfo, sid, httpInstances.map((instance) => instance.id)),
|
|
1124
1201
|
...existingDependentInstances,
|
|
1125
1202
|
...newDependentInstances,
|
|
1126
1203
|
...timerInstances,
|
|
1127
1204
|
...httpInstances,
|
|
1205
|
+
...domainInstances,
|
|
1128
1206
|
],
|
|
1129
1207
|
lastUpdated: new Date().toISOString(),
|
|
1130
1208
|
};
|
|
@@ -1146,6 +1224,16 @@ const deleteResource = async (context, functionName, logicalId, state) => {
|
|
|
1146
1224
|
const existingState = (0, stateManager_1.getResource)(state, logicalId);
|
|
1147
1225
|
const existingInstances = (existingState?.instances ?? []);
|
|
1148
1226
|
const client = (0, tencentClient_1.createTencentClient)(context);
|
|
1227
|
+
// Domain routes are released before the trigger/function teardown (issue
|
|
1228
|
+
// #286 contract: domain 摘除 → trigger → function). Other functions' routes
|
|
1229
|
+
// survive; the domain itself is deleted only when this was the last binding.
|
|
1230
|
+
const storedDomainBindings = (0, functionDomainReconcile_1.storedFunctionDomainBindings)(existingInstances, SCF_DOMAIN_INSTANCE_TYPE);
|
|
1231
|
+
for (const [domainName, binding] of storedDomainBindings) {
|
|
1232
|
+
await releaseScfDomainRoutes(context, client, domainName, {
|
|
1233
|
+
functionName,
|
|
1234
|
+
paths: binding.paths,
|
|
1235
|
+
});
|
|
1236
|
+
}
|
|
1149
1237
|
const ownedHttp = (0, scfHttpTrigger_1.ownedScfHttpTrigger)(existingInstances, existingState?.definition ?? {});
|
|
1150
1238
|
if (ownedHttp) {
|
|
1151
1239
|
await (0, scfHttpTrigger_1.reconcileScfHttpTrigger)(context, { name: functionName }, existingInstances, existingState?.definition ?? {}, client);
|
|
@@ -1156,27 +1244,6 @@ const deleteResource = async (context, functionName, logicalId, state) => {
|
|
|
1156
1244
|
logger_1.logger.info(lang_1.lang.__('DELETING_TIMER_TRIGGER', { triggerName: timerInstance.id, functionName }));
|
|
1157
1245
|
await deleteScfTimerTrigger(functionName, timerInstance.id, client);
|
|
1158
1246
|
}
|
|
1159
|
-
// Delete custom domain before deleting function
|
|
1160
|
-
const existingCustomDomain = existingInstances.find((i) => i.type === 'TENCENT_SCF_CUSTOM_DOMAIN');
|
|
1161
|
-
if (existingCustomDomain) {
|
|
1162
|
-
try {
|
|
1163
|
-
logger_1.logger.info(lang_1.lang.__('DELETING_CUSTOM_DOMAIN', { domainName: existingCustomDomain.id }));
|
|
1164
|
-
await client.scf.deleteCustomDomain(existingCustomDomain.id);
|
|
1165
|
-
logger_1.logger.info(lang_1.lang.__('CUSTOM_DOMAIN_DELETED', { domainName: existingCustomDomain.id }));
|
|
1166
|
-
}
|
|
1167
|
-
catch (err) {
|
|
1168
|
-
const errorCode = err?.code;
|
|
1169
|
-
if (errorCode === 'ResourceNotFound') {
|
|
1170
|
-
logger_1.logger.warn(lang_1.lang.__('RESOURCE_NOT_FOUND_PROVIDER', {
|
|
1171
|
-
resourceType: 'Custom Domain',
|
|
1172
|
-
name: existingCustomDomain.id,
|
|
1173
|
-
}));
|
|
1174
|
-
}
|
|
1175
|
-
else {
|
|
1176
|
-
throw err;
|
|
1177
|
-
}
|
|
1178
|
-
}
|
|
1179
|
-
}
|
|
1180
1247
|
const hasFunction = existingInstances.some((i) => isScfFunctionInstance(i));
|
|
1181
1248
|
if (hasFunction) {
|
|
1182
1249
|
try {
|
|
@@ -7,6 +7,7 @@ exports.generateBucketPlan = void 0;
|
|
|
7
7
|
const bucketPolicy_1 = require("../../common/bucketPolicy");
|
|
8
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
9
|
const lang_1 = require("../../lang");
|
|
10
|
+
const types_1 = require("../../types");
|
|
10
11
|
const volcengineClient_1 = require("../../common/volcengineClient");
|
|
11
12
|
const refreshCache_1 = require("../../common/refreshCache");
|
|
12
13
|
const concurrency_1 = require("../../common/concurrency");
|
|
@@ -60,7 +61,18 @@ const generateBucketPlan = async (context, state, buckets) => {
|
|
|
60
61
|
})),
|
|
61
62
|
normalizeForDisplay: (definition) => (0, bucketPolicy_1.normalizeBucketPolicyDefinition)(definition, 'volcengine'),
|
|
62
63
|
cloudToDefinition: tosTypes_1.cloudTosToDefinition,
|
|
63
|
-
removedDependents:
|
|
64
|
+
removedDependents: {
|
|
65
|
+
...(0, bucketPolicy_1.removedBucketPolicy)(tosTypes_1.TOS_BUCKET_POLICY_INSTANCE_TYPE, currentState, desiredDefinition),
|
|
66
|
+
// Binding dependents (issue #294): when every declared binding is
|
|
67
|
+
// gone but binding instances still exist, the stored `domains` list
|
|
68
|
+
// must be removed from the saved definition so convergence is visible.
|
|
69
|
+
...(!(config.domains?.length ?? 0) &&
|
|
70
|
+
(currentState?.instances ?? []).some((i) => i.type === types_1.ResourceTypeEnum.VOLCENGINE_TOS_DNS_CNAME ||
|
|
71
|
+
i.type === types_1.ResourceTypeEnum.VOLCENGINE_CDN_DOMAIN ||
|
|
72
|
+
i.type === types_1.ResourceTypeEnum.VOLCENGINE_CDN_DNS_CNAME)
|
|
73
|
+
? { domains: currentState?.definition.domains ?? null }
|
|
74
|
+
: {}),
|
|
75
|
+
},
|
|
64
76
|
enrichRemoteAttributes: async (_remote, attributes) => {
|
|
65
77
|
if (desiredDefinition.policy === null)
|
|
66
78
|
return attributes;
|