Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bzp2010 committed Dec 27, 2024
1 parent cd86776 commit 244e035
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 24 deletions.
6 changes: 1 addition & 5 deletions libs/backend-api7/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,7 @@ export class BackendAPI7 implements ADCSDK.Backend {
}

public async sync(): Promise<Listr> {
const operator = new Operator({
client: this.client,
gatewayGroupName: this.gatewayGroup,
version: this.version,
});
const operator = new Operator(this.client, this.gatewayGroup);
return new Listr<OperateContext>(
[
this.getAPI7VersionTask(),
Expand Down
28 changes: 9 additions & 19 deletions libs/backend-api7/src/operator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as ADCSDK from '@api7/adc-sdk';
import { Axios, AxiosResponse } from 'axios';
import { ListrTask } from 'listr2';
import { size } from 'lodash';
import { size, unset } from 'lodash';
import { SemVer, gte as semVerGTE } from 'semver';

import { FromADC } from './transformer';
Expand All @@ -17,19 +17,10 @@ export interface OperateContext {
type OperateTask = ListrTask<OperateContext>;

export class Operator {
private readonly client: Axios;
private readonly gatewayGroupName: string;
private readonly version: SemVer;

constructor(opts: {
client: Axios;
gatewayGroupName: string;
version: SemVer;
}) {
this.client = opts.client;
this.gatewayGroupName = opts.gatewayGroupName;
this.version = opts.version;
}
constructor(
private readonly client: Axios,
private readonly gatewayGroupName: string,
) {}

public updateResource(event: ADCSDK.Event): OperateTask {
return {
Expand All @@ -50,6 +41,8 @@ export class Operator {
task.output = buildReqAndRespDebugOutput(resp);
} else if (event.resourceType === ADCSDK.ResourceType.ROUTE) {
// Create a route template instead of create route directly
const route = this.fromADC(event);
if (!semVerGTE(ctx.api7Version, '3.2.16')) unset(route, 'vars');
resp = await this.client.put(
`/api/routes/template/${event.resourceId}`,
this.fromADC(event),
Expand Down Expand Up @@ -288,15 +281,12 @@ export class Operator {
case ADCSDK.ResourceType.SERVICE:
(event.newValue as ADCSDK.Service).id = event.resourceId;
return fromADC.transformService(event.newValue as ADCSDK.Service);
case ADCSDK.ResourceType.ROUTE: {
case ADCSDK.ResourceType.ROUTE:
(event.newValue as ADCSDK.Route).id = event.resourceId;
const route = fromADC.transformRoute(
return fromADC.transformRoute(
event.newValue as ADCSDK.Route,
event.parentId,
);
if (!semVerGTE(this.version, '3.2.16')) delete route.vars;
return route;
}
case ADCSDK.ResourceType.STREAM_ROUTE:
(event.newValue as ADCSDK.StreamRoute).id = event.resourceId;
return fromADC.transformStreamRoute(
Expand Down

0 comments on commit 244e035

Please sign in to comment.