Skip to content

Commit

Permalink
fix: disable checker of server-side default value (api7#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
bzp2010 authored Mar 3, 2024
1 parent 8de83a4 commit 03dce26
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions apps/cli/src/differ/differv2.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as ADCSDK from '@api7/adc-sdk';
import { detailedDiff, diff as simpleDiff } from 'deep-object-diff';
import { merge, unset } from 'lodash';
import { unset } from 'lodash';

const order = {
[`${ADCSDK.EventResourceType.ROUTE}.${ADCSDK.EventType.DELETE}`]: 0,
Expand Down Expand Up @@ -255,7 +255,7 @@ export class DifferV2 {

// merge local configuration to remote configuration before diff to
// handle default values added by the server-side
const mergedItem = merge(structuredClone(remoteItem), localItem);
//const mergedItem = merge(structuredClone(remoteItem), localItem); //TODO

// for special handling of SSL resources, since neither APISIX nor API7
// outputs certificate private keys in plaintext, the local and remote
Expand All @@ -266,17 +266,17 @@ export class DifferV2 {
// public key checks the combination to find out the update of the certificate
// in the local configuration.
if (resourceType === ADCSDK.EventResourceType.SSL) {
(mergedItem as ADCSDK.SSL).certificates.forEach((cert) =>
(localItem as ADCSDK.SSL).certificates.forEach((cert) =>
unset(cert, 'key'),
);
(remoteItem as ADCSDK.SSL).certificates.forEach((cert) =>
(localItem as ADCSDK.SSL).certificates.forEach((cert) =>
unset(cert, 'key'),
);
}

// when the output of the object diff checker is not empty it means that
// the resource has changed: send update event
if (Object.keys(simpleDiff(mergedItem, remoteItem)).length !== 0) {
if (Object.keys(simpleDiff(localItem, remoteItem)).length !== 0) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
return result.push({
Expand All @@ -286,7 +286,7 @@ export class DifferV2 {
resourceName,
oldValue: remoteItem,
newValue: localItem, // use local configuration to avoid turn back the remote old configuration to server-side
diff: detailedDiff(mergedItem, remoteItem),
diff: detailedDiff(remoteItem, localItem),
});
}
});
Expand Down Expand Up @@ -365,18 +365,18 @@ export class DifferV2 {

// merge local configuration to remote configuration before diff to
// handle default values added by the server-side
const mergedItem = merge(structuredClone(remoteItem), localItem);
//const mergedItem = merge(structuredClone(remoteItem), localItem); //TODO

// when the output of the object diff checker is not empty it means that
// the resource has changed: send update event
if (Object.keys(simpleDiff(mergedItem, remoteItem)).length !== 0) {
if (Object.keys(simpleDiff(localItem, remoteItem)).length !== 0) {
if (resourceType === ADCSDK.EventResourceType.SERVICE) {
// service may have nested routes/stream_routes
const subEvents = new DifferV2()
.diff(
{
routes: (mergedItem as ADCSDK.Service).routes,
stream_routes: (mergedItem as ADCSDK.Service).stream_routes,
routes: (localItem as ADCSDK.Service).routes,
stream_routes: (localItem as ADCSDK.Service).stream_routes,
},
{
routes: (remoteItem as ADCSDK.Service).routes,
Expand All @@ -388,7 +388,7 @@ export class DifferV2 {
const withoutRoutes = { routes: undefined, stream_routes: undefined };
const [localServiceWithoutRoutes, remoteServiceWithoutRoutes] = [
{
...mergedItem,
...localItem,
...withoutRoutes,
} as ADCSDK.Service,
{
Expand All @@ -413,8 +413,8 @@ export class DifferV2 {
oldValue: remoteServiceWithoutRoutes,
newValue: localServiceWithoutRoutes,
diff: detailedDiff(
localServiceWithoutRoutes,
remoteServiceWithoutRoutes,
localServiceWithoutRoutes,
),
subEvents,
});
Expand All @@ -423,7 +423,7 @@ export class DifferV2 {
const subEvents = new DifferV2()
.diff(
{
consumers: (mergedItem as ADCSDK.ConsumerGroup).consumers,
consumers: (localItem as ADCSDK.ConsumerGroup).consumers,
},
{
consumers: (remoteItem as ADCSDK.ConsumerGroup).consumers,
Expand All @@ -433,17 +433,17 @@ export class DifferV2 {

const [
localConsumerGroupWithoutConsumers,
mergedConsumerGroupWithoutConsumers,
/* mergedConsumerGroupWithoutConsumers, */
remoteConsumerGroupWithoutConsumers,
] = [
{
...localItem,
consumers: undefined,
} as ADCSDK.ConsumerGroup,
{
/* {
...mergedItem,
consumers: undefined,
} as ADCSDK.ConsumerGroup,
} as ADCSDK.ConsumerGroup, */
{
...remoteItem,
consumers: undefined,
Expand All @@ -455,7 +455,7 @@ export class DifferV2 {
type:
Object.keys(
simpleDiff(
mergedConsumerGroupWithoutConsumers,
localConsumerGroupWithoutConsumers,
remoteConsumerGroupWithoutConsumers,
),
).length !== 0
Expand All @@ -466,8 +466,8 @@ export class DifferV2 {
oldValue: remoteConsumerGroupWithoutConsumers,
newValue: localConsumerGroupWithoutConsumers,
diff: detailedDiff(
mergedConsumerGroupWithoutConsumers,
remoteConsumerGroupWithoutConsumers,
localConsumerGroupWithoutConsumers,
),
subEvents,
});
Expand Down

0 comments on commit 03dce26

Please sign in to comment.