import { i18n } from '@kbn/i18n' ; import { MIN_SEARCHABLE_SNAPSHOT_LICENSE } from '../../../../common/constants' ; import { ListSnapshotReposResponse } from '../../../../common/types' ; import { RouteDependencies } from '../../../types' ; import { addBasePath } from '../../../services' ; import { handleEsError } from '../../../shared_imports' ; export const registerFetchRoute = ( { router , license } ) => { router . get ( { path : addBasePath ( '/snapshot_repositories' ) , validate : false } , async ( ctx , request , response ) => { if ( ! license . isCurrentLicenseAtLeast ( MIN_SEARCHABLE_SNAPSHOT_LICENSE ) ) { return response . forbidden ( { body : i18n . translate ( 'xpack.indexLifecycleMgmt.searchSnapshotlicenseCheckErrorMessage' , { defaultMessage : 'Use of searchable snapshots requires at least an enterprise level license.' , } ) , } ) ; } try { const esResult = await ctx . core . elasticsearch . client . asCurrentUser . snapshot . getRepository ( { name : '*' , } ) ; const repos = { repositories : Object . keys ( esResult . body ) , } ; return response . ok ( { body : repos } ) ; } catch ( e ) { if ( e ?. statusCode === 404 ) { const repos = { repositories : [ ] , } ; return response . ok ( { body : repos } ) ; } return handleEsError ( { error : e , response } ) ; } } ) ; } ;