Skip to content

Commit

Permalink
Refactor types
Browse files Browse the repository at this point in the history
  • Loading branch information
sabarasaba committed Aug 10, 2023
1 parent 3013ecc commit adcb8d5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ export const serializeEnrichmentPolicies = (
});
};

export const fetchAll = async (client: IScopedClusterClient) => {
const fetchAll = async (client: IScopedClusterClient) => {
const res = await client.asCurrentUser.enrich.getPolicy();

return serializeEnrichmentPolicies(res.policies);
};

export const enrichPoliciesActions = {
fetchAll,
};
6 changes: 3 additions & 3 deletions x-pack/plugins/index_management/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import { Dependencies } from './types';
import { ApiRoutes } from './routes';
import { IndexDataEnricher } from './services';
import { handleEsError } from './shared_imports';
import * as enrichPoliciesApis from './lib/enrich_policies';
import { enrichPoliciesActions } from './lib/enrich_policies';

export interface IndexManagementPluginSetup {
enrichPolicies: typeof enrichPoliciesApis;
enrichPoliciesActions: typeof enrichPoliciesActions;
indexDataEnricher: {
add: IndexDataEnricher['add'];
};
Expand Down Expand Up @@ -61,7 +61,7 @@ export class IndexMgmtServerPlugin implements Plugin<IndexManagementPluginSetup,
});

return {
enrichPolicies: enrichPoliciesApis,
enrichPoliciesActions,
indexDataEnricher: {
add: this.indexDataEnricher.add.bind(this.indexDataEnricher),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
import { IScopedClusterClient } from '@kbn/core/server';
import { RouteDependencies } from '../../../types';
import { addBasePath } from '..';
import * as enrichPolicies from '../../../lib/enrich_policies';
import { enrichPoliciesActions } from '../../../lib/enrich_policies';

export function registerListRoute({ router, lib: { handleEsError } }: RouteDependencies) {
router.get(
{ path: addBasePath('/enrich_policies'), validate: false },
async (context, request, response) => {
const client = (await context.core).elasticsearch.client as IScopedClusterClient;
try {
const policies = await enrichPolicies.fetchAll(client);
const policies = await enrichPoliciesActions.fetchAll(client);
return response.ok({ body: policies });
} catch (error) {
return handleEsError({ error, response });
Expand Down

0 comments on commit adcb8d5

Please sign in to comment.