@@ -158,4 +158,54 @@ export class PluginServer extends pluginV3.cloudquery.plugin.v3.UnimplementedPlu
158158 return callback ( error , null ) ;
159159 } ) ;
160160 }
161+
162+ TestConnection (
163+ call : grpc . ServerUnaryCall <
164+ pluginV3 . cloudquery . plugin . v3 . TestConnection . Request ,
165+ pluginV3 . cloudquery . plugin . v3 . TestConnection . Response
166+ > ,
167+ callback : grpc . sendUnaryData < pluginV3 . cloudquery . plugin . v3 . TestConnection . Response > ,
168+ ) : void {
169+ const { spec = new Uint8Array ( ) } = call . request . toObject ( ) ;
170+
171+ const stringSpec = new TextDecoder ( ) . decode ( spec ) ;
172+ if ( this . plugin . testConnection ) {
173+ this . plugin
174+ . testConnection ( stringSpec )
175+ . then ( ( { success, failureCode, failureDescription } ) => {
176+ // eslint-disable-next-line promise/no-callback-in-promise
177+ return callback (
178+ null ,
179+ new pluginV3 . cloudquery . plugin . v3 . TestConnection . Response ( {
180+ success,
181+ failure_code : failureCode ,
182+ failure_description : failureDescription ,
183+ } ) ,
184+ ) ;
185+ } )
186+ . catch ( ( error ) => {
187+ // eslint-disable-next-line promise/no-callback-in-promise
188+ return callback ( error , null ) ;
189+ } ) ;
190+ } else {
191+ // fall back to init
192+ this . plugin
193+ . init ( stringSpec , { noConnection : false } )
194+ . then ( ( ) => {
195+ // eslint-disable-next-line promise/no-callback-in-promise
196+ return callback ( null , new pluginV3 . cloudquery . plugin . v3 . TestConnection . Response ( { success : true } ) ) ;
197+ } )
198+ . catch ( ( ) => {
199+ // eslint-disable-next-line promise/no-callback-in-promise
200+ return callback (
201+ null ,
202+ new pluginV3 . cloudquery . plugin . v3 . TestConnection . Response ( {
203+ success : false ,
204+ failure_code : 'UNKNOWN' ,
205+ failure_description : 'Failed to connect' ,
206+ } ) ,
207+ ) ;
208+ } ) ;
209+ }
210+ }
161211}
0 commit comments