Skip to content

Commit 6a8857c

Browse files
authored
feat(core): looser name length (#179)
1 parent b45f723 commit 6a8857c

File tree

9 files changed

+61
-20
lines changed

9 files changed

+61
-20
lines changed

.github/workflows/e2e.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
if: contains(github.event.pull_request.labels.*.name, 'test/api7') || github.event_name == 'push'
4040
strategy:
4141
matrix:
42-
version: [3.2.13.0, 3.2.14.5]
42+
version: [3.2.14.6]
4343
env:
4444
BACKEND_API7_DOWNLOAD_URL: https://run.api7.ai/api7-ee/api7-ee-v${{ matrix.version }}.tar.gz
4545
BACKEND_API7_LICENSE: ${{ secrets.BACKEND_API7_LICENSE }}

apps/cli/src/differ/differv3.ts

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as ADCSDK from '@api7/adc-sdk';
22
import { randomUUID } from 'crypto';
33
import { diff as objectDiff } from 'deep-diff';
4-
import { cloneDeep, isEmpty, isEqual, isNil, unset } from 'lodash';
4+
import { cloneDeep, has, isEmpty, isEqual, isNil, unset } from 'lodash';
55
import winston from 'winston';
66

77
const order = {
@@ -359,6 +359,20 @@ export class DifferV3 {
359359
);
360360
}
361361

362+
// Services will have two different default value rules depending on
363+
// the type of route they contain, one for HTTP services and another
364+
// for stream services.
365+
// Therefore, before merging the default values, we should decide
366+
// the default value table according to the type of service. This type
367+
// is only used for merging default values, other processes still
368+
// use the ResourceType.SERVICE type.
369+
const resourceTypeForDefault =
370+
resourceType != ADCSDK.ResourceType.SERVICE
371+
? resourceType
372+
: has(localItem, 'stream_routes')
373+
? ADCSDK.ResourceType.INTERNAL_STREAM_SERVICE
374+
: ADCSDK.ResourceType.SERVICE;
375+
362376
// Merges local resources into a table of default values for this type.
363377
// The Admin API merges the default values specified in the schema into
364378
// the data, so default values not contained in the local data will
@@ -368,7 +382,8 @@ export class DifferV3 {
368382
// As such, each backend implementation needs to provide its table of
369383
// default values, which merges the local resources to the defaults,
370384
// just as the Admin API does.
371-
const defaultValue = this.defaultValue?.core?.[resourceType] ?? {};
385+
const defaultValue =
386+
this.defaultValue?.core?.[resourceTypeForDefault] ?? {};
372387
const mergedLocalItem = this.mergeDefault(
373388
localItem,
374389
cloneDeep(defaultValue),

apps/cli/src/linter/schema.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { z } from 'zod';
22

3-
const nameSchema = z.string().min(1).max(100);
3+
const nameSchema = z
4+
.string()
5+
.min(1)
6+
.max(64 * 1024);
47
const descriptionSchema = z
58
.string()
69
.max(64 * 1024)

apps/cli/src/linter/specs/common.spec.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import { check } from '../';
55
describe('Common Linter', () => {
66
const cases = [
77
{
8-
name: 'should check description length (length <= 64 * 1024)',
8+
name: 'should check name/description length (length <= 64 * 1024)',
99
input: {
1010
services: [
1111
{
12-
name: 'test',
12+
name: ''.padEnd(64 * 1024, '0'),
1313
description: ''.padEnd(64 * 1024, '0'),
1414
routes: [],
1515
},
@@ -19,18 +19,27 @@ describe('Common Linter', () => {
1919
errors: [],
2020
},
2121
{
22-
name: 'should check description length (length > 64 * 1024)',
22+
name: 'should check name/description length (length > 64 * 1024)',
2323
input: {
2424
services: [
2525
{
26-
name: 'test',
26+
name: ''.padEnd(64 * 1024 + 1, '0'),
2727
description: ''.padEnd(64 * 1024 + 1, '0'),
2828
routes: [],
2929
},
3030
],
3131
} as ADCSDK.Configuration,
3232
expect: false,
3333
errors: [
34+
{
35+
code: 'too_big',
36+
exact: false,
37+
inclusive: true,
38+
maximum: 65536,
39+
message: 'String must contain at most 65536 character(s)',
40+
path: ['services', 0, 'name'],
41+
type: 'string',
42+
},
3443
{
3544
code: 'too_big',
3645
exact: false,

libs/backend-api7/e2e/misc.e2e-spec.ts

+17-11
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
import * as ADCSDK from '@api7/adc-sdk';
2-
import { unset } from 'lodash';
3-
import { readFileSync } from 'node:fs';
4-
import { join } from 'node:path';
52

63
import { BackendAPI7 } from '../src';
74
import {
85
createEvent,
96
deleteEvent,
107
dumpConfiguration,
118
syncEvents,
12-
updateEvent,
139
} from './support/utils';
1410

1511
describe('Miscellaneous', () => {
@@ -24,10 +20,15 @@ describe('Miscellaneous', () => {
2420
});
2521
});
2622

27-
describe('Sync resources with the description greater than 256 bytes', () => {
28-
const service1Name = 'service1';
29-
const service1 = {
30-
name: service1Name,
23+
describe('Sync resources with the name/description greater than 256 bytes', () => {
24+
const routeName = ''.padEnd(64 * 1024, '0'); // 65536 bytes
25+
const serviceName = ''.padEnd(64 * 1024, '0'); // 65536 bytes
26+
const route = {
27+
name: routeName,
28+
uris: ['/test'],
29+
};
30+
const service = {
31+
name: serviceName,
3132
description: ''.padEnd(64 * 1024, '0'), // 65536 bytes
3233
upstream: {
3334
scheme: 'https',
@@ -39,22 +40,27 @@ describe('Miscellaneous', () => {
3940
},
4041
],
4142
},
43+
routes: [route],
4244
} as ADCSDK.Service;
4345

4446
it('Create services', async () =>
4547
syncEvents(backend, [
46-
createEvent(ADCSDK.ResourceType.SERVICE, service1Name, service1),
48+
createEvent(ADCSDK.ResourceType.SERVICE, serviceName, service),
49+
createEvent(ADCSDK.ResourceType.ROUTE, routeName, route, serviceName),
4750
]));
4851

4952
it('Dump', async () => {
5053
const result = (await dumpConfiguration(backend)) as ADCSDK.Configuration;
5154
expect(result.services).toHaveLength(1);
52-
expect(result.services[0]).toMatchObject(service1);
55+
expect(result.services[0]).toMatchObject(service);
56+
expect(result.services[0]).toMatchObject(service);
57+
expect(result.services[0].routes[0]).toMatchObject(route);
5358
});
5459

5560
it('Delete service', async () =>
5661
syncEvents(backend, [
57-
deleteEvent(ADCSDK.ResourceType.SERVICE, service1Name),
62+
deleteEvent(ADCSDK.ResourceType.ROUTE, routeName, serviceName),
63+
deleteEvent(ADCSDK.ResourceType.SERVICE, serviceName),
5864
]));
5965

6066
it('Dump again', async () => {

libs/backend-api7/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ export class BackendAPI7 implements ADCSDK.Backend {
122122
switch (type) {
123123
case ADCSDK.ResourceType.ROUTE:
124124
return toADC.transformRoute;
125+
case ADCSDK.ResourceType.INTERNAL_STREAM_SERVICE:
125126
case ADCSDK.ResourceType.SERVICE:
126127
return toADC.transformService;
127128
case ADCSDK.ResourceType.SSL:

libs/backend-apisix/src/fetcher.ts

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ export class Fetcher {
3232

3333
private allTask(): Array<FetchTask> {
3434
return Object.values(ADCSDK.ResourceType)
35+
.filter(
36+
(resourceType) =>
37+
resourceType !== ADCSDK.ResourceType.INTERNAL_STREAM_SERVICE, // ignore internal only types
38+
)
3539
.map((resourceType): [ADCSDK.ResourceType, string] => [
3640
resourceType,
3741
resourceTypeToAPIName(resourceType),

libs/sdk/src/core/resource.ts

+3
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ export enum ResourceType {
99
CONSUMER = 'consumer',
1010
CONSUMER_GROUP = 'consumer_group',
1111
STREAM_ROUTE = 'stream_route',
12+
13+
// internal use only
14+
INTERNAL_STREAM_SERVICE = 'stream_service',
1215
}

schema.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"name": {
1010
"type": "string",
1111
"minLength": 1,
12-
"maxLength": 100
12+
"maxLength": 65536
1313
},
1414
"description": {
1515
"type": "string",

0 commit comments

Comments
 (0)