import { schema } from '@kbn/config-schema' ; import type { RouteDefinitionParams } from '.' ; import { ERROR_OUTSIDE_PREBOOT_STAGE , ERROR_PING_FAILURE } from '../../common' ; import type { PingResult } from '../../common/types' ; export function definePingRoute ( { router , logger , elasticsearch , preboot } ) { router . post ( { path : '/internal/interactive_setup/ping' , validate : { body : schema . object ( { host : schema . uri ( { scheme : [ 'http' , 'https' ] } ) , } ) , } , options : { authRequired : false } , } , async ( context , request , response ) => { if ( ! preboot . isSetupOnHold ( ) ) { logger . error ( `Invalid request to [path=${ request . url . pathname }] outside of preboot stage` ) ; return response . badRequest ( { body : { message : 'Cannot process request outside of preboot stage.' , attributes : { type : ERROR_OUTSIDE_PREBOOT_STAGE } , } , } ) ; } let result ; try { result = await elasticsearch . ping ( request . body . host ) ; } catch { return response . customError ( { statusCode : 500 , body : { message : 'Failed to ping cluster.' , attributes : { type : ERROR_PING_FAILURE } } , } ) ; } return response . ok ( { body : result } ) ; } ) ; }