@@ -35,7 +35,7 @@ export class Validator extends ADCSDK.backend.BackendEventSource {
3535 public async validate (
3636 config : ADCSDK . Configuration ,
3737 ) : Promise < ADCSDK . BackendValidateResult > {
38- const body = this . buildRequestBody ( config ) ;
38+ const { body, nameIndex } = this . buildRequestBody ( config ) ;
3939
4040 try {
4141 const resp = await this . client . post (
@@ -58,35 +58,50 @@ export class Validator extends ADCSDK.backend.BackendEventSource {
5858 } ,
5959 } ) ;
6060 const data = error . response . data ;
61+ const errors : ADCSDK . BackendValidationError [ ] = ( data ?. errors ?? [ ] ) . map (
62+ ( e : ADCSDK . BackendValidationError ) => {
63+ const name = nameIndex [ e . resource_type ] ?. [ e . index ] ;
64+ return name ? { ...e , resource_name : name } : e ;
65+ } ,
66+ ) ;
6167 return {
6268 success : false ,
6369 errorMessage : data ?. error_msg ,
64- errors : data ?. errors ?? [ ] ,
70+ errors,
6571 } ;
6672 }
6773 throw error ;
6874 }
6975 }
7076
71- private buildRequestBody ( config : ADCSDK . Configuration ) : ValidateRequestBody {
77+ private buildRequestBody ( config : ADCSDK . Configuration ) : {
78+ body : ValidateRequestBody ;
79+ nameIndex : Record < string , string [ ] > ;
80+ } {
7281 const body : ValidateRequestBody = { } ;
82+ const nameIndex : Record < string , string [ ] > = { } ;
7383
7484 if ( config . services ?. length ) {
7585 const services : Array < typing . Service > = [ ] ;
7686 const routes : Array < typing . Route > = [ ] ;
7787 const streamRoutes : Array < typing . StreamRoute > = [ ] ;
88+ const serviceNames : string [ ] = [ ] ;
89+ const routeNames : string [ ] = [ ] ;
90+ const streamRouteNames : string [ ] = [ ] ;
7891
7992 for ( const service of config . services ) {
8093 const serviceId =
8194 service . id ?? ADCSDK . utils . generateId ( service . name ) ;
8295 const svc = { ...service , id : serviceId } ;
8396 const transformed = this . fromADC . transformService ( svc ) ;
8497 services . push ( transformed ) ;
98+ serviceNames . push ( service . name ) ;
8599
86100 for ( const route of service . routes ?? [ ] ) {
87101 const routeId = route . id ?? ADCSDK . utils . generateId ( route . name ) ;
88102 const r = { ...route , id : routeId } ;
89103 routes . push ( this . fromADC . transformRoute ( r , serviceId ) ) ;
104+ routeNames . push ( route . name ) ;
90105 }
91106
92107 for ( const streamRoute of service . stream_routes ?? [ ] ) {
@@ -96,31 +111,42 @@ export class Validator extends ADCSDK.backend.BackendEventSource {
96111 streamRoutes . push (
97112 this . fromADC . transformStreamRoute ( sr , serviceId ) ,
98113 ) ;
114+ streamRouteNames . push ( streamRoute . name ) ;
99115 }
100116 }
101117
102118 body . services = services ;
103- if ( routes . length ) body . routes = routes ;
104- if ( streamRoutes . length ) body . stream_routes = streamRoutes ;
119+ nameIndex . services = serviceNames ;
120+ if ( routes . length ) {
121+ body . routes = routes ;
122+ nameIndex . routes = routeNames ;
123+ }
124+ if ( streamRoutes . length ) {
125+ body . stream_routes = streamRoutes ;
126+ nameIndex . stream_routes = streamRouteNames ;
127+ }
105128 }
106129
107130 if ( config . consumers ?. length ) {
108131 body . consumers = config . consumers . map ( ( c ) =>
109132 this . fromADC . transformConsumer ( c ) ,
110133 ) ;
134+ nameIndex . consumers = config . consumers . map ( ( c ) => c . username ) ;
111135 }
112136
113137 if ( config . ssls ?. length ) {
114138 body . ssls = config . ssls . map ( ( ssl ) => {
115139 const sslId = ssl . id ?? ADCSDK . utils . generateId ( ssl . snis ?. [ 0 ] ?? '' ) ;
116140 return this . fromADC . transformSSL ( { ...ssl , id : sslId } ) ;
117141 } ) ;
142+ nameIndex . ssls = config . ssls . map ( ( ssl ) => ssl . snis ?. [ 0 ] ?? '' ) ;
118143 }
119144
120145 if ( config . global_rules && Object . keys ( config . global_rules ) . length ) {
121146 body . global_rules = this . fromADC . transformGlobalRule (
122147 config . global_rules as Record < string , ADCSDK . GlobalRule > ,
123148 ) ;
149+ nameIndex . global_rules = Object . keys ( config . global_rules ) ;
124150 }
125151
126152 if (
@@ -133,6 +159,7 @@ export class Validator extends ADCSDK.backend.BackendEventSource {
133159 ...ADCSDK . utils . recursiveOmitUndefined ( config ) ,
134160 } ) ,
135161 ) ;
162+ nameIndex . plugin_metadata = Object . keys ( config . plugin_metadata ) ;
136163 }
137164
138165 if ( config . consumer_groups ?. length ) {
@@ -146,8 +173,9 @@ export class Validator extends ADCSDK.backend.BackendEventSource {
146173 plugins : cg . plugins ,
147174 } ) as unknown as Record < string , unknown > ;
148175 } ) ;
176+ nameIndex . consumer_groups = config . consumer_groups . map ( ( cg ) => cg . name ) ;
149177 }
150178
151- return body ;
179+ return { body, nameIndex } ;
152180 }
153181}
0 commit comments