|
1 | 1 | import * as ADCSDK from '@api7/adc-sdk';
|
2 |
| -import { isEmpty, unset } from 'lodash'; |
| 2 | +import { filter, isEmpty, unset } from 'lodash'; |
3 | 3 |
|
4 | 4 | import * as typing from './typing';
|
5 | 5 |
|
6 | 6 | export class ToADC {
|
| 7 | + private static transformLabels(labels?: ADCSDK.Labels): ADCSDK.Labels { |
| 8 | + if (!labels) return undefined; |
| 9 | + const filteredLabels = filter( |
| 10 | + labels, |
| 11 | + (val, key) => key !== '__ADC_NAME', |
| 12 | + ) as unknown as ADCSDK.Labels; |
| 13 | + return Object.values(filteredLabels).length > 0 |
| 14 | + ? filteredLabels |
| 15 | + : undefined; |
| 16 | + } |
| 17 | + |
7 | 18 | public transformRoute(route: typing.Route): ADCSDK.Route {
|
8 | 19 | return ADCSDK.utils.recursiveOmitUndefined({
|
9 | 20 | name: route.name ?? route.id,
|
@@ -120,9 +131,9 @@ export class ToADC {
|
120 | 131 | streamRoute: typing.StreamRoute,
|
121 | 132 | ): ADCSDK.StreamRoute {
|
122 | 133 | return ADCSDK.utils.recursiveOmitUndefined({
|
123 |
| - name: streamRoute.name ?? streamRoute.id, |
| 134 | + name: streamRoute.labels?.__ADC_NAME ?? streamRoute.id, |
124 | 135 | description: streamRoute.desc,
|
125 |
| - labels: streamRoute.labels, |
| 136 | + labels: ToADC.transformLabels(streamRoute.labels), |
126 | 137 |
|
127 | 138 | remote_addr: streamRoute.remote_addr,
|
128 | 139 | server_addr: streamRoute.server_addr,
|
@@ -343,10 +354,18 @@ export class FromADC {
|
343 | 354 | streamRoute: ADCSDK.StreamRoute,
|
344 | 355 | ): typing.StreamRoute {
|
345 | 356 | return ADCSDK.utils.recursiveOmitUndefined({
|
346 |
| - ...streamRoute, |
347 | 357 | id: undefined,
|
348 |
| - labels: FromADC.transformLabels(streamRoute.labels), |
349 |
| - }); |
| 358 | + desc: streamRoute.description, |
| 359 | + labels: { |
| 360 | + ...FromADC.transformLabels(streamRoute.labels), |
| 361 | + __ADC_NAME: streamRoute.name, |
| 362 | + }, |
| 363 | + plugins: streamRoute.plugins, |
| 364 | + remote_addr: streamRoute.remote_addr, |
| 365 | + server_addr: streamRoute.server_addr, |
| 366 | + server_port: streamRoute.server_port, |
| 367 | + sni: streamRoute.sni, |
| 368 | + } as typing.StreamRoute); |
350 | 369 | }
|
351 | 370 |
|
352 | 371 | public transformUpstream(upstream: ADCSDK.Upstream): typing.Upstream {
|
|
0 commit comments