diff --git a/server/routes/data_connections/data_connections_router.ts b/server/routes/data_connections/data_connections_router.ts index 3ecd3d434..7e35f9676 100644 --- a/server/routes/data_connections/data_connections_router.ts +++ b/server/routes/data_connections/data_connections_router.ts @@ -221,9 +221,9 @@ export function registerDataConnectionsRoute(router: IRouter, dataSourceEnabled: const client = await context.dataSource.opensearch.legacy.getClient(dataSourceMDSId); dataConnectionsresponse = await client.callAPI('ppl.getDataConnections'); } else { - dataConnectionsresponse = await context.observability_plugin.observabilityClient.asScoped( - request - ); + dataConnectionsresponse = await context.observability_plugin.observabilityClient + .asScoped(request) + .callAsCurrentUser('ppl.getDataConnections'); } return response.ok({ body: dataConnectionsresponse, @@ -237,4 +237,43 @@ export function registerDataConnectionsRoute(router: IRouter, dataSourceEnabled: } } ); + + router.get( + { + path: `${DATACONNECTIONS_BASE}/{name}/dataSourceMDSId={dataSourceMDSId?}`, + validate: { + params: schema.object({ + name: schema.string(), + dataSourceMDSId: schema.maybe(schema.string({ defaultValue: '' })), + }), + }, + }, + async (context, request, response): Promise => { + const dataSourceMDSId = request.params.dataSourceMDSId; + try { + let dataConnectionsresponse; + if (dataSourceEnabled && dataSourceMDSId) { + const client = await context.dataSource.opensearch.legacy.getClient(dataSourceMDSId); + dataConnectionsresponse = await client.callAPI('ppl.getDataConnectionById', { + dataconnection: request.params.name, + }); + } else { + dataConnectionsresponse = await context.observability_plugin.observabilityClient + .asScoped(request) + .callAsCurrentUser('ppl.getDataConnectionById', { + dataconnection: request.params.name, + }); + } + return response.ok({ + body: dataConnectionsresponse, + }); + } catch (error: any) { + console.error('Issue in fetching data connection:', error); + return response.custom({ + statusCode: error.statusCode || 500, + body: error.message, + }); + } + } + ); } diff --git a/server/routes/dsl.ts b/server/routes/dsl.ts index 9bdc45342..0560ae049 100644 --- a/server/routes/dsl.ts +++ b/server/routes/dsl.ts @@ -15,7 +15,10 @@ import { DSL_SETTINGS, } from '../../common/constants/shared'; -export function registerDslRoute({ router }: { router: IRouter; facet: DSLFacet }) { +export function registerDslRoute( + { router }: { router: IRouter; facet: DSLFacet }, + dataSourceEnabled: boolean +) { router.post( { path: `${DSL_BASE}${DSL_SEARCH}`, @@ -122,4 +125,115 @@ export function registerDslRoute({ router }: { router: IRouter; facet: DSLFacet } } ); + + router.get( + { + path: `${DSL_BASE}${DSL_CAT}/dataSourceMDSId={dataSourceMDSId?}`, + validate: { + query: schema.object({ + format: schema.string(), + index: schema.maybe(schema.string()), + }), + params: schema.object({ + dataSourceMDSId: schema.maybe(schema.string({ defaultValue: '' })), + }), + }, + }, + async (context, request, response) => { + const dataSourceMDSId = request.params.dataSourceMDSId; + try { + let resp; + if (dataSourceEnabled && dataSourceMDSId) { + const client = await context.dataSource.opensearch.legacy.getClient(dataSourceMDSId); + resp = await client.callAPI('cat.indices', request.query); + } else { + resp = await context.core.opensearch.legacy.client.callAsCurrentUser( + 'cat.indices', + request.query + ); + } + return response.ok({ + body: resp, + }); + } catch (error) { + if (error.statusCode !== 404) console.error(error); + return response.custom({ + statusCode: error.statusCode || 500, + body: error.message, + }); + } + } + ); + + router.get( + { + path: `${DSL_BASE}${DSL_MAPPING}/dataSourceMDSId={dataSourceMDSId?}`, + validate: { + query: schema.any(), + params: schema.object({ + dataSourceMDSId: schema.maybe(schema.string({ defaultValue: '' })), + }), + }, + }, + async (context, request, response) => { + const dataSourceMDSId = request.params.dataSourceMDSId; + try { + let resp; + if (dataSourceEnabled && dataSourceMDSId) { + const client = await context.dataSource.opensearch.legacy.getClient(dataSourceMDSId); + resp = await client.callAPI('indices.getMapping', { index: request.query.index }); + } else { + resp = await context.core.opensearch.legacy.client.callAsCurrentUser( + 'indices.getMapping', + { index: request.query.index } + ); + } + return response.ok({ + body: resp, + }); + } catch (error) { + if (error.statusCode !== 404) console.error(error); + return response.custom({ + statusCode: error.statusCode || 500, + body: error.message, + }); + } + } + ); + + router.get( + { + path: `${DSL_BASE}${DSL_SETTINGS}/dataSourceMDSId={dataSourceMDSId?}`, + validate: { + query: schema.any(), + params: schema.object({ + dataSourceMDSId: schema.maybe(schema.string({ defaultValue: '' })), + }), + }, + }, + async (context, request, response) => { + const dataSourceMDSId = request.params.dataSourceMDSId; + try { + let resp; + if (dataSourceEnabled && dataSourceMDSId) { + const client = await context.dataSource.opensearch.legacy.getClient(dataSourceMDSId); + resp = await client.callAPI('indices.getSettings', { index: request.query.index }); + } else { + resp = await context.core.opensearch.legacy.client.callAsCurrentUser( + 'indices.getSettings', + { index: request.query.index } + ); + } + return response.ok({ + body: resp, + }); + } catch (error) { + if (error.statusCode !== 404) console.error(error); + return response.custom({ + statusCode: error.statusCode || 500, + body: error.message, + }); + } + } + ); } diff --git a/server/routes/index.ts b/server/routes/index.ts index 499fb2952..d8a695233 100644 --- a/server/routes/index.ts +++ b/server/routes/index.ts @@ -37,7 +37,7 @@ export function setupRoutes({ PanelsRouter(router); VisualizationsRouter(router); registerPplRoute({ router, facet: new PPLFacet(client) }); - registerDslRoute({ router, facet: new DSLFacet(client) }); + registerDslRoute({ router, facet: new DSLFacet(client) }, dataSourceEnabled); registerEventAnalyticsRouter({ router, savedObjectFacet: new SavedObjectFacet(client) }); registerAppAnalyticsRouter(router);