import { API_BASE_PATH , CLOUD_SNAPSHOT_REPOSITORY } from '../../common/constants' ; import { versionCheckHandlerWrapper } from '../lib/es_version_precheck' ; import { RouteDependencies } from '../types' ; export function registerCloudBackupStatusRoutes ( { router , lib : { handleEsError } , } ) { router . get ( { path : `${ API_BASE_PATH }/cloud_backup_status` , validate : false } , versionCheckHandlerWrapper ( async ( context , request , response ) => { const { client : clusterClient } = context . core . elasticsearch ; try { const { body : { snapshots } , } = await clusterClient . asCurrentUser . snapshot . get ( { repository : CLOUD_SNAPSHOT_REPOSITORY , snapshot : '_all' , ignore_unavailable : true , order : 'desc' , sort : 'start_time' , size : 1 , } ) ; let isBackedUp = false ; let lastBackupTime ; if ( snapshots && snapshots [ 0 ] ) { isBackedUp = true ; lastBackupTime = snapshots ! [ 0 ] . start_time ; } return response . ok ( { body : { isBackedUp , lastBackupTime , } , } ) ; } catch ( error ) { return handleEsError ( { error , response } ) ; } } ) ) ; }