@geek-fun/serverlessinsight 0.8.3 → 0.8.5
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 +3 -2
- package/.serverlessinsight/state-iam-test-app-iam-test-service.json.backup +21 -2
- package/.serverlessinsight/state-insight-poc-deploy-app-insight-poc-deploy.json.backup +46 -35
- package/.serverlessinsight/state-insight-poc-destroy-app-insight-poc-destroy.json.backup +3 -2
- package/.serverlessinsight/state-insight-volc-app-insight-volc.json.backup +63 -23
- package/CHANGELOG.md +55 -0
- package/README.md +1 -1
- package/dist/package.json +26 -25
- package/dist/src/common/aliyunClient/apigwOperations.js +36 -0
- package/dist/src/common/aliyunClient/fc3Operations.js +7 -0
- package/dist/src/common/aliyunClient/slsOperations.js +35 -3
- package/dist/src/common/constants.js +5 -1
- package/dist/src/common/index.js +2 -0
- package/dist/src/common/nameBuilder.js +80 -0
- package/dist/src/common/providerNames.js +54 -0
- package/dist/src/common/runtimeMapper.js +25 -4
- package/dist/src/common/stateBackend/remoteStateBackend.js +4 -1
- package/dist/src/common/stateManager.js +52 -2
- package/dist/src/common/tencentClient/clsOperations.js +137 -0
- package/dist/src/common/tencentClient/index.js +21 -1
- package/dist/src/common/tencentClient/scfOperations.js +11 -0
- package/dist/src/common/volcengineClient/iamOperations.js +33 -0
- package/dist/src/common/volcengineClient/tlsOperations.js +84 -1
- package/dist/src/lang/en.js +29 -1
- package/dist/src/lang/zh-CN.js +29 -1
- package/dist/src/parser/index.js +2 -1
- package/dist/src/stack/aliyunStack/apigwPlanner.js +2 -0
- package/dist/src/stack/aliyunStack/apigwResource.js +118 -1
- package/dist/src/stack/aliyunStack/apigwTypes.js +32 -20
- package/dist/src/stack/aliyunStack/destroyer.js +25 -0
- package/dist/src/stack/aliyunStack/fc3Resource.js +91 -32
- package/dist/src/stack/aliyunStack/sharedLogProject.js +137 -0
- package/dist/src/stack/ownershipTag.js +19 -1
- package/dist/src/stack/scfStack/destroyer.js +13 -0
- package/dist/src/stack/scfStack/scfPlanner.js +9 -1
- package/dist/src/stack/scfStack/scfResource.js +205 -13
- package/dist/src/stack/scfStack/scfTypes.js +6 -0
- package/dist/src/stack/scfStack/sharedLogset.js +126 -0
- package/dist/src/stack/volcengineStack/apigwResource.js +64 -48
- package/dist/src/stack/volcengineStack/apigwTypes.js +10 -7
- package/dist/src/stack/volcengineStack/destroyer.js +12 -0
- package/dist/src/stack/volcengineStack/sharedLogProject.js +190 -0
- package/dist/src/stack/volcengineStack/vefaasPlanner.js +20 -13
- package/dist/src/stack/volcengineStack/vefaasResource.js +76 -76
- package/dist/src/types/domains/state.js +3 -0
- package/dist/src/validator/bucketSchema.js +3 -5
- package/dist/src/validator/eventSchema.js +7 -4
- package/dist/src/validator/functionSchema.js +3 -2
- package/dist/src/validator/iacSchema.js +11 -4
- package/dist/src/validator/rootSchema.js +27 -0
- package/dist/src/validator/semanticValidation.js +122 -0
- package/dist/src/validator/tableschema.js +2 -0
- package/dist/src/validator/templateRefSchema.js +23 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +26 -25
- package/samples/aliyun-poc-fc-gpu.yml +2 -2
- package/samples/aliyun-poc-table.yml +1 -1
- package/samples/volcengine-poc-advanced.yml +4 -8
- package/samples/volcengine-poc-api.yml +1 -1
- package/samples/volcengine-poc-function.yml +1 -1
- package/samples/volcengine-poc-vpc.yml +3 -7
|
@@ -9,6 +9,7 @@ const logger_1 = require("../../common/logger");
|
|
|
9
9
|
const lang_1 = require("../../lang");
|
|
10
10
|
const ownershipTag_1 = require("../ownershipTag");
|
|
11
11
|
const alreadyExists_1 = require("../alreadyExists");
|
|
12
|
+
const sharedLogProject_1 = require("./sharedLogProject");
|
|
12
13
|
const RECOVERY_GET_FUNCTION_DELAY_MS = 1500;
|
|
13
14
|
// volcengine role TRN format: trn:iam::{accountId}:role/{roleName}. Prefer the
|
|
14
15
|
// stored TRN; else construct from the known accountId, else fetch it via STS.
|
|
@@ -102,10 +103,11 @@ const buildVefaasInstanceFromProvider = (info, sid) => {
|
|
|
102
103
|
asyncTaskConfig: info.asyncTaskConfig,
|
|
103
104
|
};
|
|
104
105
|
};
|
|
105
|
-
const createDependentResources = async (context, fn, serviceName, existingInstances = []) => {
|
|
106
|
+
const createDependentResources = async (context, fn, serviceName, existingInstances = [], state) => {
|
|
106
107
|
const client = (0, volcengineClient_1.createVolcengineClient)(context);
|
|
107
108
|
const instances = [];
|
|
108
109
|
let logConfig;
|
|
110
|
+
let sharedInstance;
|
|
109
111
|
const hasTlsProject = existingInstances.some((i) => i.type === 'VOLCENGINE_TLS_PROJECT');
|
|
110
112
|
const hasIamRole = existingInstances.some((i) => i.type === 'VOLCENGINE_IAM_ROLE');
|
|
111
113
|
if (fn.log) {
|
|
@@ -119,49 +121,27 @@ const createDependentResources = async (context, fn, serviceName, existingInstan
|
|
|
119
121
|
}
|
|
120
122
|
}
|
|
121
123
|
else {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
});
|
|
130
|
-
instances.push({
|
|
131
|
-
type: 'VOLCENGINE_TLS_PROJECT',
|
|
132
|
-
id: projectName,
|
|
133
|
-
attributes: { ...project },
|
|
134
|
-
});
|
|
135
|
-
logger_1.logger.info(lang_1.lang.__('CREATING_TLS_TOPIC', { topicName }));
|
|
136
|
-
const topic = await client.tls.createTopic({
|
|
137
|
-
projectName,
|
|
124
|
+
// Shared app-scoped TLS project (#214): the project is tracked in the
|
|
125
|
+
// stage shared slot, the function's topic stays nested under the function.
|
|
126
|
+
const shared = await (0, sharedLogProject_1.ensureSharedLogProject)(context, client, state);
|
|
127
|
+
sharedInstance = (0, sharedLogProject_1.buildSharedProjectResourceState)(context, shared);
|
|
128
|
+
const topicName = `${context.service}-${context.stage}-fn-logs`;
|
|
129
|
+
const topic = await (0, sharedLogProject_1.ensureOwnedTopic)(context, client, {
|
|
130
|
+
projectName: shared.projectName,
|
|
138
131
|
topicName,
|
|
139
|
-
|
|
140
|
-
ttl: 30,
|
|
132
|
+
logicalId: `functions.${fn.key}`,
|
|
141
133
|
});
|
|
142
134
|
instances.push({
|
|
143
135
|
type: 'VOLCENGINE_TLS_TOPIC',
|
|
144
|
-
id: `${projectName}/${topicName}`,
|
|
136
|
+
id: `${shared.projectName}/${topic.topicName}`,
|
|
145
137
|
attributes: { ...topic },
|
|
146
138
|
});
|
|
147
|
-
logger_1.logger.info(lang_1.lang.__('CREATING_TLS_INDEX', { topicName }));
|
|
148
|
-
await client.tls.createIndex({
|
|
149
|
-
projectName,
|
|
150
|
-
topicName,
|
|
151
|
-
fullTextIndex: {
|
|
152
|
-
delimiter: ' ,.?;!\n\t',
|
|
153
|
-
caseSensitive: false,
|
|
154
|
-
},
|
|
155
|
-
});
|
|
156
139
|
instances.push({
|
|
157
140
|
type: 'VOLCENGINE_TLS_INDEX',
|
|
158
|
-
id: `${projectName}/${topicName}/index`,
|
|
141
|
+
id: `${shared.projectName}/${topic.topicName}/index`,
|
|
159
142
|
attributes: {},
|
|
160
143
|
});
|
|
161
|
-
|
|
162
|
-
await client.tls.waitForProject(projectName);
|
|
163
|
-
await client.tls.waitForTopic(projectName, topicName);
|
|
164
|
-
logConfig = { project: projectName, topic: topicName };
|
|
144
|
+
logConfig = { project: shared.projectName, topic: topic.topicName };
|
|
165
145
|
}
|
|
166
146
|
}
|
|
167
147
|
const iamConfig = fn.iam?.role;
|
|
@@ -170,7 +150,9 @@ const createDependentResources = async (context, fn, serviceName, existingInstan
|
|
|
170
150
|
const customRoleName = iamConfig && typeof iamConfig !== 'string' ? iamConfig.name : undefined;
|
|
171
151
|
if (iamConfig && typeof iamConfig === 'string') {
|
|
172
152
|
const role = { roleName: iamConfig, trn: iamConfig };
|
|
173
|
-
|
|
153
|
+
// External role: never create/manage it, but keep TLS instances and the
|
|
154
|
+
// sharedInstance so log resources are tracked and torn down correctly.
|
|
155
|
+
return { logConfig, role, instances, sharedInstance };
|
|
174
156
|
}
|
|
175
157
|
const roleName = customRoleName ?? `${serviceName}-${context.stage}-role`;
|
|
176
158
|
const trustedServices = (0, vefaasTypes_1.getTrustedServicesForFunction)(fn, context);
|
|
@@ -215,27 +197,19 @@ const createDependentResources = async (context, fn, serviceName, existingInstan
|
|
|
215
197
|
logConfig,
|
|
216
198
|
role,
|
|
217
199
|
instances,
|
|
200
|
+
sharedInstance,
|
|
218
201
|
};
|
|
219
202
|
};
|
|
220
203
|
const deleteDependentResources = async (context, instances) => {
|
|
221
204
|
const client = (0, volcengineClient_1.createVolcengineClient)(context);
|
|
222
|
-
|
|
205
|
+
// TLS children (index → topic) then any legacy per-resource own-project are
|
|
206
|
+
// deleted in dependency order; the stage-shared project is never touched.
|
|
207
|
+
await (0, sharedLogProject_1.deleteTlsLogResources)(context, client, instances);
|
|
208
|
+
for (const instance of instances) {
|
|
223
209
|
switch (instance.type) {
|
|
224
|
-
case 'VOLCENGINE_TLS_INDEX':
|
|
225
|
-
|
|
226
|
-
logger_1.logger.info(lang_1.lang.__('DELETING_TLS_INDEX', { id: instance.id }));
|
|
227
|
-
await client.tls.deleteIndex(projectName, topicName);
|
|
228
|
-
break;
|
|
229
|
-
}
|
|
230
|
-
case 'VOLCENGINE_TLS_TOPIC': {
|
|
231
|
-
const [projectName, topicName] = instance.id.split('/');
|
|
232
|
-
logger_1.logger.info(lang_1.lang.__('DELETING_TLS_TOPIC', { id: instance.id }));
|
|
233
|
-
await client.tls.deleteTopic(projectName, topicName);
|
|
234
|
-
break;
|
|
235
|
-
}
|
|
210
|
+
case 'VOLCENGINE_TLS_INDEX':
|
|
211
|
+
case 'VOLCENGINE_TLS_TOPIC':
|
|
236
212
|
case 'VOLCENGINE_TLS_PROJECT':
|
|
237
|
-
logger_1.logger.info(lang_1.lang.__('DELETING_TLS_PROJECT', { id: instance.id }));
|
|
238
|
-
await client.tls.deleteProject(instance.id);
|
|
239
213
|
break;
|
|
240
214
|
case 'VOLCENGINE_IAM_ROLE': {
|
|
241
215
|
const attrs = instance.attributes;
|
|
@@ -257,7 +231,7 @@ const createResource = async (context, fn, state) => {
|
|
|
257
231
|
const serviceName = `${context.app}-${context.service}`;
|
|
258
232
|
const existingResourceState = (0, common_1.getResource)(state, logicalId);
|
|
259
233
|
const existingDependentInstances = (existingResourceState?.instances ?? []).filter((i) => i.type !== 'VOLCENGINE_VEFAAS_FUNCTION');
|
|
260
|
-
const dependentResources = await createDependentResources(context, fn, serviceName, existingDependentInstances);
|
|
234
|
+
const dependentResources = await createDependentResources(context, fn, serviceName, existingDependentInstances, state);
|
|
261
235
|
const config = (0, vefaasTypes_1.functionToVefaasConfig)(fn, {
|
|
262
236
|
role: dependentResources.role?.trn,
|
|
263
237
|
logConfig: dependentResources.logConfig,
|
|
@@ -306,7 +280,10 @@ const createResource = async (context, fn, state) => {
|
|
|
306
280
|
status: 'tainted',
|
|
307
281
|
lastUpdated: new Date().toISOString(),
|
|
308
282
|
};
|
|
309
|
-
const
|
|
283
|
+
const stateWithShared = dependentResources.sharedInstance
|
|
284
|
+
? (0, common_1.setSharedResource)(state, context.stage, 'logs.project', dependentResources.sharedInstance)
|
|
285
|
+
: state;
|
|
286
|
+
const stateAfterDependents = (0, common_1.setResource)(stateWithShared, logicalId, taintedResourceState);
|
|
310
287
|
const client = (0, volcengineClient_1.createVolcengineClient)(context);
|
|
311
288
|
const isTainted = existingResourceState?.status === 'tainted';
|
|
312
289
|
const existingFunctionOnRetry = isTainted ? await client.vefaas.getFunction(fn.name) : null;
|
|
@@ -389,37 +366,59 @@ const updateResource = async (context, fn, state) => {
|
|
|
389
366
|
}
|
|
390
367
|
const existingInstances = (currentState.instances ?? []);
|
|
391
368
|
const isTainted = currentState.status === 'tainted';
|
|
392
|
-
const hasTlsResources = existingInstances.some((i) => i.type === 'VOLCENGINE_TLS_PROJECT');
|
|
393
369
|
const hasIamRole = existingInstances.some((i) => i.type === 'VOLCENGINE_IAM_ROLE');
|
|
394
370
|
const client = (0, volcengineClient_1.createVolcengineClient)(context);
|
|
395
371
|
const newDependentInstances = [];
|
|
396
372
|
let logConfig;
|
|
397
373
|
let role;
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
// partial failure (e.g. project created but topic creation fails) leaves a
|
|
401
|
-
// tainted marker for the executor instead of orphaning cloud resources
|
|
402
|
-
// untracked. A retry then resumes with the tainted state.
|
|
403
|
-
const stateAfterDependents = (0, common_1.setResource)(state, logicalId, {
|
|
404
|
-
...currentState,
|
|
405
|
-
status: 'tainted',
|
|
406
|
-
});
|
|
407
|
-
try {
|
|
408
|
-
const deps = await createDependentResources(context, { ...fn, network: undefined, storage: { disk: undefined, nas: undefined } }, serviceName);
|
|
409
|
-
logConfig = deps.logConfig;
|
|
410
|
-
newDependentInstances.push(...deps.instances.filter((i) => i.type.startsWith('VOLCENGINE_TLS_')));
|
|
411
|
-
}
|
|
412
|
-
catch (error) {
|
|
413
|
-
throw new types_1.PartialResourceError(stateAfterDependents, error instanceof Error ? error : new Error(String(error)));
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
else if (hasTlsResources) {
|
|
417
|
-
const tlsProjectInstance = existingInstances.find((i) => i.type === 'VOLCENGINE_TLS_PROJECT');
|
|
374
|
+
let logState;
|
|
375
|
+
if (fn.log) {
|
|
418
376
|
const tlsTopicInstance = existingInstances.find((i) => i.type === 'VOLCENGINE_TLS_TOPIC');
|
|
419
|
-
if (
|
|
377
|
+
if (tlsTopicInstance) {
|
|
378
|
+
// Reuse the tracked topic — legacy own-project/topic instances behave
|
|
379
|
+
// exactly as before; shared-scheme topics live under the shared project.
|
|
420
380
|
const [projectName, topicName] = tlsTopicInstance.id.split('/');
|
|
421
381
|
logConfig = { project: projectName, topic: topicName };
|
|
422
382
|
}
|
|
383
|
+
else if (!isTainted) {
|
|
384
|
+
// Persist a tainted state BEFORE creating dependent TLS resources so a
|
|
385
|
+
// partial failure (e.g. project created but topic creation fails) leaves a
|
|
386
|
+
// tainted marker for the executor instead of orphaning cloud resources
|
|
387
|
+
// untracked. A retry then resumes with the tainted state.
|
|
388
|
+
const tainted = (0, common_1.setResource)(state, logicalId, {
|
|
389
|
+
...currentState,
|
|
390
|
+
status: 'tainted',
|
|
391
|
+
});
|
|
392
|
+
try {
|
|
393
|
+
const deps = await createDependentResources(context, { ...fn, network: undefined, storage: { disk: undefined, nas: undefined } }, serviceName, [], tainted);
|
|
394
|
+
logState = deps.sharedInstance
|
|
395
|
+
? (0, common_1.setSharedResource)(tainted, context.stage, 'logs.project', deps.sharedInstance)
|
|
396
|
+
: tainted;
|
|
397
|
+
logConfig = deps.logConfig;
|
|
398
|
+
newDependentInstances.push(...deps.instances.filter((i) => i.type.startsWith('VOLCENGINE_TLS_')));
|
|
399
|
+
}
|
|
400
|
+
catch (error) {
|
|
401
|
+
throw new types_1.PartialResourceError(logState ?? tainted, error instanceof Error ? error : new Error(String(error)));
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
else {
|
|
406
|
+
const tlsToRemove = existingInstances.filter((i) => i.type.startsWith('VOLCENGINE_TLS_'));
|
|
407
|
+
if (tlsToRemove.length > 0) {
|
|
408
|
+
try {
|
|
409
|
+
await (0, sharedLogProject_1.deleteTlsLogResources)(context, client, tlsToRemove);
|
|
410
|
+
// Release the shared project when this was its last topic; keep the
|
|
411
|
+
// stage slot when other topics still reference it.
|
|
412
|
+
const shared = (0, common_1.getSharedResource)(state, context.stage, sharedLogProject_1.SHARED_LOG_PROJECT_KEY);
|
|
413
|
+
const releaseResult = await (0, sharedLogProject_1.releaseSharedLogProjectIfUnused)(context, client, shared);
|
|
414
|
+
if (releaseResult === 'deleted') {
|
|
415
|
+
logState = (0, common_1.removeSharedResource)(state, context.stage, sharedLogProject_1.SHARED_LOG_PROJECT_KEY);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
catch (error) {
|
|
419
|
+
throw new types_1.PartialResourceError(state, error instanceof Error ? error : new Error(String(error)));
|
|
420
|
+
}
|
|
421
|
+
}
|
|
423
422
|
}
|
|
424
423
|
// Determine if the current role is external (string TRN)
|
|
425
424
|
const currentIam = currentState.definition?.iam;
|
|
@@ -546,7 +545,8 @@ const updateResource = async (context, fn, state) => {
|
|
|
546
545
|
}
|
|
547
546
|
}
|
|
548
547
|
const existingDependentInstances = existingInstances
|
|
549
|
-
.filter((i) => i.type !== 'VOLCENGINE_VEFAAS_FUNCTION'
|
|
548
|
+
.filter((i) => i.type !== 'VOLCENGINE_VEFAAS_FUNCTION' &&
|
|
549
|
+
(!!fn.log || !i.type.startsWith('VOLCENGINE_TLS_')))
|
|
550
550
|
.map((i) => {
|
|
551
551
|
const { sid: existingSid, id: existingId, ...rest } = i;
|
|
552
552
|
return {
|
|
@@ -572,7 +572,7 @@ const updateResource = async (context, fn, state) => {
|
|
|
572
572
|
status: 'ready',
|
|
573
573
|
lastUpdated: new Date().toISOString(),
|
|
574
574
|
};
|
|
575
|
-
return (0, common_1.setResource)(state, logicalId, resourceState);
|
|
575
|
+
return (0, common_1.setResource)(logState ?? state, logicalId, resourceState);
|
|
576
576
|
};
|
|
577
577
|
exports.updateResource = updateResource;
|
|
578
578
|
const deleteResource = async (context, functionName, logicalId, state) => {
|
|
@@ -13,6 +13,7 @@ var ResourceTypeEnum;
|
|
|
13
13
|
ResourceTypeEnum["ALIYUN_APIGW_GROUP"] = "ALIYUN_APIGW_GROUP";
|
|
14
14
|
ResourceTypeEnum["ALIYUN_APIGW_API"] = "ALIYUN_APIGW_API";
|
|
15
15
|
ResourceTypeEnum["ALIYUN_APIGW_DEPLOYMENT"] = "ALIYUN_APIGW_DEPLOYMENT";
|
|
16
|
+
ResourceTypeEnum["ALIYUN_APIGW_LOG_CONFIG"] = "ALIYUN_APIGW_LOG_CONFIG";
|
|
16
17
|
ResourceTypeEnum["ALIYUN_APIGW_DNS_VERIFICATION"] = "ALIYUN_APIGW_DNS_VERIFICATION";
|
|
17
18
|
ResourceTypeEnum["ALIYUN_OSS_BUCKET"] = "ALIYUN_OSS_BUCKET";
|
|
18
19
|
ResourceTypeEnum["ALIYUN_OSS_DNS_CNAME"] = "ALIYUN_OSS_DNS_CNAME";
|
|
@@ -29,6 +30,8 @@ var ResourceTypeEnum;
|
|
|
29
30
|
ResourceTypeEnum["ALIYUN_RAM_ROLE"] = "ALIYUN_RAM_ROLE";
|
|
30
31
|
ResourceTypeEnum["VOLCENGINE_IAM_ROLE"] = "VOLCENGINE_IAM_ROLE";
|
|
31
32
|
ResourceTypeEnum["TENCENT_SCF_ROLE"] = "TENCENT_SCF_ROLE";
|
|
33
|
+
ResourceTypeEnum["TENCENT_CLS_LOGSET"] = "TENCENT_CLS_LOGSET";
|
|
34
|
+
ResourceTypeEnum["TENCENT_CLS_TOPIC"] = "TENCENT_CLS_TOPIC";
|
|
32
35
|
ResourceTypeEnum["ALIYUN_ECS_SECURITY_GROUP"] = "ALIYUN_ECS_SECURITY_GROUP";
|
|
33
36
|
ResourceTypeEnum["ALIYUN_NAS_ACCESS_GROUP"] = "ALIYUN_NAS_ACCESS_GROUP";
|
|
34
37
|
ResourceTypeEnum["ALIYUN_NAS_FILE_SYSTEM"] = "ALIYUN_NAS_FILE_SYSTEM";
|
|
@@ -27,7 +27,7 @@ const bucketDomainSchema = {
|
|
|
27
27
|
{
|
|
28
28
|
type: 'object',
|
|
29
29
|
properties: {
|
|
30
|
-
domain_name: {
|
|
30
|
+
domain_name: (0, templateRefSchema_1.resolvableConstrained)({ pattern: templateRefSchema_1.HOST_NAME_PATTERN }),
|
|
31
31
|
certificate_id: { type: 'string' },
|
|
32
32
|
certificate_body: { type: 'string' },
|
|
33
33
|
certificate_private_key: { type: 'string' },
|
|
@@ -78,7 +78,7 @@ const bucketWebsiteDomainSchema = {
|
|
|
78
78
|
{
|
|
79
79
|
type: 'object',
|
|
80
80
|
properties: {
|
|
81
|
-
domain_name: {
|
|
81
|
+
domain_name: (0, templateRefSchema_1.resolvableConstrained)({ pattern: templateRefSchema_1.HOST_NAME_PATTERN }),
|
|
82
82
|
certificate_id: { type: 'string' },
|
|
83
83
|
certificate_body: { type: 'string' },
|
|
84
84
|
certificate_private_key: { type: 'string' },
|
|
@@ -173,9 +173,7 @@ exports.bucketSchema = {
|
|
|
173
173
|
'.*': {
|
|
174
174
|
type: 'object',
|
|
175
175
|
properties: {
|
|
176
|
-
name: {
|
|
177
|
-
type: 'string',
|
|
178
|
-
},
|
|
176
|
+
name: (0, templateRefSchema_1.resolvableConstrained)({ pattern: templateRefSchema_1.BUCKET_NAME_PATTERN }),
|
|
179
177
|
storage: {
|
|
180
178
|
type: 'object',
|
|
181
179
|
properties: {
|
|
@@ -43,9 +43,12 @@ exports.eventSchema = {
|
|
|
43
43
|
triggers: {
|
|
44
44
|
type: 'array',
|
|
45
45
|
items: {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
type: 'object',
|
|
47
|
+
properties: {
|
|
48
|
+
method: (0, templateRefSchema_1.resolvableEnum)(['GET', 'POST', 'PUT', 'DELETE', 'ANY']),
|
|
49
|
+
path: (0, templateRefSchema_1.resolvableConstrained)({ pattern: '^/\\S*$' }),
|
|
50
|
+
backend: { type: 'string' },
|
|
51
|
+
},
|
|
49
52
|
required: ['method', 'path', 'backend'],
|
|
50
53
|
},
|
|
51
54
|
},
|
|
@@ -54,7 +57,7 @@ exports.eventSchema = {
|
|
|
54
57
|
additionalProperties: false,
|
|
55
58
|
required: ['domain_name'],
|
|
56
59
|
properties: {
|
|
57
|
-
domain_name: {
|
|
60
|
+
domain_name: (0, templateRefSchema_1.resolvableConstrained)({ pattern: templateRefSchema_1.HOST_NAME_PATTERN }),
|
|
58
61
|
certificate_id: { type: 'string' },
|
|
59
62
|
certificate_body: { type: 'string' },
|
|
60
63
|
certificate_private_key: { type: 'string' },
|
|
@@ -52,8 +52,9 @@ exports.functionSchema = {
|
|
|
52
52
|
'node20/v1',
|
|
53
53
|
'nodeprime14/v1',
|
|
54
54
|
'python3.12/v1',
|
|
55
|
-
'python3.8/v1',
|
|
56
55
|
'python3.9/v1',
|
|
56
|
+
'native-python3.12/v1',
|
|
57
|
+
'native-node20/v1',
|
|
57
58
|
]),
|
|
58
59
|
handler: { type: 'string' },
|
|
59
60
|
path: { type: 'string' },
|
|
@@ -179,7 +180,7 @@ exports.functionSchema = {
|
|
|
179
180
|
required: ['domain_name'],
|
|
180
181
|
additionalProperties: false,
|
|
181
182
|
properties: {
|
|
182
|
-
domain_name: {
|
|
183
|
+
domain_name: (0, templateRefSchema_1.resolvableConstrained)({ pattern: templateRefSchema_1.HOST_NAME_PATTERN }),
|
|
183
184
|
certificate_id: { type: 'string' },
|
|
184
185
|
protocol: (0, templateRefSchema_1.resolvableEnum)(['HTTP', 'HTTPS']),
|
|
185
186
|
},
|
|
@@ -13,6 +13,7 @@ const functionSchema_1 = require("./functionSchema");
|
|
|
13
13
|
const bucketSchema_1 = require("./bucketSchema");
|
|
14
14
|
const tableschema_1 = require("./tableschema");
|
|
15
15
|
const lang_1 = require("../lang");
|
|
16
|
+
const semanticValidation_1 = require("./semanticValidation");
|
|
16
17
|
class IacSchemaErrors extends Error {
|
|
17
18
|
schemaErrors;
|
|
18
19
|
constructor(errors) {
|
|
@@ -31,7 +32,7 @@ class IacSchemaErrors extends Error {
|
|
|
31
32
|
` Type: ${error.type}`,
|
|
32
33
|
` Message: ${error.message}`,
|
|
33
34
|
];
|
|
34
|
-
if (error.allowedValues) {
|
|
35
|
+
if (error.allowedValues && error.allowedValues.length > 0) {
|
|
35
36
|
parts.push(` Allowed values: ${error.allowedValues.join(', ')}`);
|
|
36
37
|
}
|
|
37
38
|
return parts.join('\n');
|
|
@@ -86,9 +87,15 @@ const validateRuntimeCompatibility = (iacJson) => {
|
|
|
86
87
|
};
|
|
87
88
|
const validateYaml = (iacJson) => {
|
|
88
89
|
const valid = validate(iacJson);
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
const semanticErrors = (0, semanticValidation_1.validateSemantics)(iacJson);
|
|
91
|
+
if (!valid || semanticErrors.length > 0) {
|
|
92
|
+
common_1.logger.debug(lang_1.lang.__('INVALID_YAML', {
|
|
93
|
+
errors: JSON.stringify([...(validate.errors ?? []), ...semanticErrors]),
|
|
94
|
+
}));
|
|
95
|
+
throw new IacSchemaErrors([
|
|
96
|
+
...(validate.errors ?? []),
|
|
97
|
+
...semanticErrors,
|
|
98
|
+
]);
|
|
92
99
|
}
|
|
93
100
|
validateRuntimeCompatibility(iacJson);
|
|
94
101
|
return true;
|
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.rootSchema = void 0;
|
|
4
|
+
const templateRefSchema_1 = require("./templateRefSchema");
|
|
5
|
+
// Provider-enforced function-name maximums (audit of issue #222)
|
|
6
|
+
const FUNCTION_NAME_MAX_LENGTH = {
|
|
7
|
+
aliyun: 64,
|
|
8
|
+
tencent: 60,
|
|
9
|
+
};
|
|
10
|
+
const functionNameLimitBranch = (provider, maxLength) => ({
|
|
11
|
+
if: {
|
|
12
|
+
properties: { provider: { properties: { name: { const: provider } }, required: ['name'] } },
|
|
13
|
+
required: ['provider'],
|
|
14
|
+
},
|
|
15
|
+
then: {
|
|
16
|
+
properties: {
|
|
17
|
+
functions: {
|
|
18
|
+
patternProperties: {
|
|
19
|
+
'.*': {
|
|
20
|
+
properties: {
|
|
21
|
+
// Whole-value template references bypass the literal limit.
|
|
22
|
+
name: { anyOf: [{ type: 'string', maxLength }, templateRefSchema_1.templateRefSchema] },
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
});
|
|
4
30
|
exports.rootSchema = {
|
|
5
31
|
$id: 'https://serverlessinsight.geekfun.club/schemas/schema.json',
|
|
6
32
|
type: 'object',
|
|
@@ -118,4 +144,5 @@ exports.rootSchema = {
|
|
|
118
144
|
},
|
|
119
145
|
required: ['version', 'provider', 'app', 'service'],
|
|
120
146
|
additionalProperties: false,
|
|
147
|
+
allOf: Object.entries(FUNCTION_NAME_MAX_LENGTH).map(([provider, maxLength]) => functionNameLimitBranch(provider, maxLength)),
|
|
121
148
|
};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateSemantics = void 0;
|
|
4
|
+
const lang_1 = require("../lang");
|
|
5
|
+
// Direct leaf import on purpose: routing through the src/common barrel would
|
|
6
|
+
// drag stateManager/lockManager/fs surfaces into the validator graph and
|
|
7
|
+
// recreate an import cycle with src/parser. These helpers are pure.
|
|
8
|
+
const providerNames_1 = require("../common/providerNames");
|
|
9
|
+
const FUNCTION_BACKEND_PATTERN = /^\$\{functions\.([\w.]+)\}$/;
|
|
10
|
+
/**
|
|
11
|
+
* Stage is intentionally empty here: it is identical for every generated name
|
|
12
|
+
* inside one validation run, so collision detection is unaffected while avoiding
|
|
13
|
+
* coupling the validator to CLI context state.
|
|
14
|
+
*/
|
|
15
|
+
const STAGE_PLACEHOLDER = '';
|
|
16
|
+
const validateSemantics = (iacJson) => {
|
|
17
|
+
const errors = [];
|
|
18
|
+
if (!iacJson || typeof iacJson !== 'object') {
|
|
19
|
+
return errors;
|
|
20
|
+
}
|
|
21
|
+
const providerName = typeof iacJson.provider?.name === 'string' ? iacJson.provider.name : '';
|
|
22
|
+
const events = (iacJson.events ?? {});
|
|
23
|
+
const functionDefinitions = (iacJson.functions ?? {});
|
|
24
|
+
const definedFunctionKeys = new Set(Object.keys(functionDefinitions));
|
|
25
|
+
Object.entries(events).forEach(([eventKey, rawEvent]) => {
|
|
26
|
+
const triggers = Array.isArray(rawEvent.triggers)
|
|
27
|
+
? rawEvent.triggers
|
|
28
|
+
: [];
|
|
29
|
+
const eventName = typeof rawEvent.name === 'string' ? rawEvent.name : '';
|
|
30
|
+
// Aliyun groups are per-event (each API_GATEWAY event owns its group), so
|
|
31
|
+
// apiName collisions are checked event-locally, matching Volcengine's
|
|
32
|
+
// per-event route scope.
|
|
33
|
+
const seenTriggerKeys = new Map();
|
|
34
|
+
const seenRouteNames = new Map();
|
|
35
|
+
const seenApiNames = new Map();
|
|
36
|
+
triggers.forEach((trigger, index) => {
|
|
37
|
+
const method = typeof trigger.method === 'string' ? trigger.method.toUpperCase() : '';
|
|
38
|
+
const path = typeof trigger.path === 'string' ? trigger.path : '';
|
|
39
|
+
const instancePath = `/events/${eventKey}/triggers/${index}`;
|
|
40
|
+
let isDuplicateTrigger = false;
|
|
41
|
+
if (method.length > 0 && path.length > 0) {
|
|
42
|
+
const triggerKey = `${method}:${path}`;
|
|
43
|
+
if (seenTriggerKeys.has(triggerKey)) {
|
|
44
|
+
isDuplicateTrigger = true;
|
|
45
|
+
errors.push({
|
|
46
|
+
instancePath,
|
|
47
|
+
schemaPath: '#/semantic/duplicateTrigger',
|
|
48
|
+
keyword: 'duplicateTrigger',
|
|
49
|
+
params: {},
|
|
50
|
+
message: lang_1.lang.__('SEMANTIC_DUPLICATE_TRIGGER', { eventKey, method, path }),
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
seenTriggerKeys.set(triggerKey, path);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const backendRef = typeof trigger.backend === 'string'
|
|
58
|
+
? FUNCTION_BACKEND_PATTERN.exec(trigger.backend)?.[1]
|
|
59
|
+
: undefined;
|
|
60
|
+
if (backendRef && !definedFunctionKeys.has(backendRef)) {
|
|
61
|
+
errors.push({
|
|
62
|
+
instancePath,
|
|
63
|
+
schemaPath: '#/semantic/unresolvedBackendFunction',
|
|
64
|
+
keyword: 'unresolvedBackendFunction',
|
|
65
|
+
params: {},
|
|
66
|
+
message: lang_1.lang.__('SEMANTIC_UNRESOLVED_FUNCTION_BACKEND', {
|
|
67
|
+
reference: `\${functions.${backendRef}}`,
|
|
68
|
+
eventKey,
|
|
69
|
+
}),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
// Generated names derive from method+path, so a duplicate trigger would
|
|
73
|
+
// only re-report the duplicateTrigger error — skip name collision checks.
|
|
74
|
+
if (isDuplicateTrigger || method.length === 0 || path.length === 0) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (providerName === 'aliyun') {
|
|
78
|
+
const apiKey = (0, providerNames_1.generateApiKey)(method, path);
|
|
79
|
+
const apiName = (0, providerNames_1.buildAliyunApigwApiName)(eventName, STAGE_PLACEHOLDER, apiKey);
|
|
80
|
+
const firstPath = seenApiNames.get(apiName);
|
|
81
|
+
if (firstPath !== undefined) {
|
|
82
|
+
errors.push({
|
|
83
|
+
instancePath,
|
|
84
|
+
schemaPath: '#/semantic/duplicateGeneratedApiName',
|
|
85
|
+
keyword: 'duplicateGeneratedApiName',
|
|
86
|
+
params: {},
|
|
87
|
+
message: lang_1.lang.__('SEMANTIC_DUPLICATE_GENERATED_API_NAME', {
|
|
88
|
+
apiName,
|
|
89
|
+
firstPath,
|
|
90
|
+
secondPath: path,
|
|
91
|
+
}),
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
seenApiNames.set(apiName, path);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (providerName === 'volcengine') {
|
|
99
|
+
const routeName = (0, providerNames_1.buildVolcengineRouteName)(eventName, method, path);
|
|
100
|
+
const firstPath = seenRouteNames.get(routeName);
|
|
101
|
+
if (firstPath !== undefined) {
|
|
102
|
+
errors.push({
|
|
103
|
+
instancePath,
|
|
104
|
+
schemaPath: '#/semantic/duplicateRouteName',
|
|
105
|
+
keyword: 'duplicateRouteName',
|
|
106
|
+
params: {},
|
|
107
|
+
message: lang_1.lang.__('SEMANTIC_DUPLICATE_ROUTE_NAME', {
|
|
108
|
+
routeName,
|
|
109
|
+
firstPath,
|
|
110
|
+
secondPath: path,
|
|
111
|
+
}),
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
seenRouteNames.set(routeName, path);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
return errors;
|
|
121
|
+
};
|
|
122
|
+
exports.validateSemantics = validateSemantics;
|
|
@@ -17,12 +17,14 @@ exports.tableSchema = {
|
|
|
17
17
|
type: 'object',
|
|
18
18
|
properties: {
|
|
19
19
|
type: (0, templateRefSchema_1.resolvableEnum)(['PUBLIC', 'PRIVATE']),
|
|
20
|
+
vpc_id: { type: 'string' },
|
|
20
21
|
ingress_rules: {
|
|
21
22
|
type: 'array',
|
|
22
23
|
items: { type: 'string' },
|
|
23
24
|
},
|
|
24
25
|
},
|
|
25
26
|
required: ['type'],
|
|
27
|
+
additionalProperties: false,
|
|
26
28
|
},
|
|
27
29
|
throughput: {
|
|
28
30
|
type: 'object',
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolvableEnum = exports.resolvableBoolean = exports.resolvableInteger = exports.resolvableNumber = void 0;
|
|
3
|
+
exports.BUCKET_NAME_PATTERN = exports.HOST_NAME_PATTERN = exports.resolvableConstrained = exports.resolvableEnum = exports.resolvableBoolean = exports.resolvableInteger = exports.resolvableNumber = exports.templateRefSchema = void 0;
|
|
4
4
|
// Template reference pattern that matches ${vars.xxx}, ${stages.xxx}, ${ctx.xxx}, ${functions.xxx}, ${certificates.xxx}
|
|
5
5
|
// Note: ${functions.xxx} and ${certificates.xxx} references are kept as strings and resolved by the deployment engine
|
|
6
6
|
// Only ${vars.xxx}, ${stages.xxx}, and ${ctx.xxx} are resolved at parse time
|
|
7
7
|
const templateRefPattern = '^\\$\\{(vars|stages|ctx|functions|certificates)\\.[\\w.]+\\}$';
|
|
8
8
|
// Schema definition for a template reference string
|
|
9
|
-
|
|
9
|
+
exports.templateRefSchema = {
|
|
10
10
|
type: 'string',
|
|
11
11
|
pattern: templateRefPattern,
|
|
12
12
|
};
|
|
13
13
|
// Helper function to create a oneOf schema for a type that can also be a template reference
|
|
14
14
|
const withTemplateRef = (schema) => ({
|
|
15
|
-
oneOf: [schema, templateRefSchema],
|
|
15
|
+
oneOf: [schema, exports.templateRefSchema],
|
|
16
16
|
});
|
|
17
17
|
// Common resolvable type schemas
|
|
18
18
|
exports.resolvableNumber = withTemplateRef({ type: 'number' });
|
|
@@ -21,3 +21,23 @@ exports.resolvableBoolean = withTemplateRef({ type: 'boolean' });
|
|
|
21
21
|
// Helper for enum types that can also be template refs
|
|
22
22
|
const resolvableEnum = (enumValues) => withTemplateRef({ type: 'string', enum: enumValues });
|
|
23
23
|
exports.resolvableEnum = resolvableEnum;
|
|
24
|
+
/**
|
|
25
|
+
* String field accepting either a whole template reference (`${vars.x}`) or a
|
|
26
|
+
* literal satisfying the given JSON-Schema string constraints. Partial
|
|
27
|
+
* interpolations deliberately fail so unresolved values never reach deploy.
|
|
28
|
+
*/
|
|
29
|
+
const resolvableConstrained = (constraints) => withTemplateRef({
|
|
30
|
+
type: 'string',
|
|
31
|
+
...(constraints.pattern !== undefined ? { pattern: constraints.pattern } : {}),
|
|
32
|
+
...(constraints.minLength !== undefined ? { minLength: constraints.minLength } : {}),
|
|
33
|
+
...(constraints.maxLength !== undefined ? { maxLength: constraints.maxLength } : {}),
|
|
34
|
+
});
|
|
35
|
+
exports.resolvableConstrained = resolvableConstrained;
|
|
36
|
+
/** Hostname optionally prefixed with a wildcard label (`*.example.com`). */
|
|
37
|
+
exports.HOST_NAME_PATTERN = '^(?:\\*\\.)?(?:[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?\\.)+[A-Za-z]{2,63}$';
|
|
38
|
+
/**
|
|
39
|
+
* Resource-style bucket name: lowercase labels (dotted forms permitted), 3–63
|
|
40
|
+
* chars total. Both branches share the total-length lookahead; dotted labels
|
|
41
|
+
* each follow the hyphen rules (no leading/trailing hyphen per label).
|
|
42
|
+
*/
|
|
43
|
+
exports.BUCKET_NAME_PATTERN = '^(?=.{3,63}$)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?|(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)$';
|