Skip to content

Commit

Permalink
Integration sequal - replace data client placeholders (opensearch-pro…
Browse files Browse the repository at this point in the history
…ject#2167)

Signed-off-by: Kristen Tian <[email protected]>

Signed-off-by: Kristen Tian <[email protected]>
  • Loading branch information
kristenTian committed Sep 12, 2022
1 parent 005343b commit 03eeed6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/plugins/data/opensearch_dashboards.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"expressions",
"uiActions"
],
"optionalPlugins": ["usageCollection"],
"optionalPlugins": ["usageCollection", "dataSource"],
"extraPublicDirs": ["common", "common/utils/abort_utils"],
"requiredBundles": [
"usageCollection",
"opensearchDashboardsUtils",
"opensearchDashboardsReact",
"inspector"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,13 @@ export async function callIndexAliasApi(
): Promise<IndicesAliasResponse> {
try {
if ('transport' in callCluster) {
return ((await callCluster.indices.getAlias({
index: indices,
ignore_unavailable: true,
allow_no_indices: true,
})) as unknown) as Promise<IndicesAliasResponse>; // todo: Pending #... verify test
return (
await callCluster.indices.getAlias({
index: indices,
ignore_unavailable: true,
allow_no_indices: true,
})
).body as IndicesAliasResponse;
}

return (await callCluster('indices.getAlias', {
Expand Down Expand Up @@ -98,12 +100,14 @@ export async function callFieldCapsApi(
) {
try {
if ('transport' in callCluster) {
return ((await callCluster.fieldCaps({
index: indices,
fields: '*',
ignore_unavailable: true,
allow_no_indices: fieldCapsOptions.allowNoIndices,
})) as unknown) as FieldCapsResponse; // todo: Pending #... verify test
return (
await callCluster.fieldCaps({
index: indices,
fields: '*',
ignore_unavailable: true,
allow_no_indices: fieldCapsOptions.allowNoIndices,
})
).body as FieldCapsResponse;
}

return (await callCluster('fieldCaps', {
Expand Down
11 changes: 6 additions & 5 deletions src/plugins/data/server/index_patterns/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function registerRoutes(http: HttpServiceSetup) {
},
},
async (context, request, response) => {
const callAsCurrentUser = decideClient(context, request);
const callAsCurrentUser = await decideClient(context, request);
const indexPatterns = new IndexPatternsFetcher(callAsCurrentUser);
const { pattern, meta_fields: metaFields } = request.query;

Expand Down Expand Up @@ -118,7 +118,7 @@ export function registerRoutes(http: HttpServiceSetup) {
},
},
async (context: RequestHandlerContext, request: any, response: any) => {
const callAsCurrentUser = decideClient(context, request);
const callAsCurrentUser = await decideClient(context, request);

const indexPatterns = new IndexPatternsFetcher(callAsCurrentUser);
const { pattern, interval, look_back: lookBack, meta_fields: metaFields } = request.query;
Expand Down Expand Up @@ -151,9 +151,10 @@ export function registerRoutes(http: HttpServiceSetup) {
);
}

const decideClient = (context: RequestHandlerContext, request: any) => {
if (request.query.data_source) {
// todo: # Pending
const decideClient = async (context: RequestHandlerContext, request: any) => {
const dataSourceId = request.query.data_source;
if (dataSourceId) {
return await context.dataSource.opensearch.getClient(dataSourceId);
}

return context.core.opensearch.legacy.client.callAsCurrentUser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,15 @@ export function registerResolveIndexRoute(router: IRouter): void {
? { expand_wildcards: req.query.expand_wildcards }
: null;

if (req.query.data_source) {
// const result = await (await context.data_source.opensearch.getClient(req.query.data_source)).indices.resolveIndex({
// name: encodeURIComponent(req.params.query),
// expand_wildcards: req.query.expand_wildcards,
// });
// return res.ok({ body: result.body }); //todo: Pending #
const dataSourceId = req.query.data_source;
if (dataSourceId) {
const result = await (
await context.dataSource.opensearch.getClient(dataSourceId)
).indices.resolveIndex({
name: encodeURIComponent(req.params.query),
expand_wildcards: req.query.expand_wildcards,
});
return res.ok({ body: result.body });
}

const result = await context.core.opensearch.legacy.client.callAsCurrentUser(
Expand Down

0 comments on commit 03eeed6

Please sign in to comment.