Skip to content

Commit

Permalink
Address CR changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sabarasaba committed Aug 14, 2023
1 parent 379011c commit a4e984e
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
*/

export const API_BASE_PATH = '/api/index_management';

export const INTERNAL_API_BASE_PATH = '/internal/index_management';
2 changes: 1 addition & 1 deletion x-pack/plugins/index_management/common/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

export { BASE_PATH } from './base_path';
export { API_BASE_PATH } from './api_base_path';
export { API_BASE_PATH, INTERNAL_API_BASE_PATH } from './api_base_path';
export { INVALID_INDEX_PATTERN_CHARS, INVALID_TEMPLATE_NAME_CHARS } from './invalid_characters';
export * from './index_statuses';

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/index_management/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// TODO: https://github.com/elastic/kibana/issues/110892
/* eslint-disable @kbn/eslint/no_export_all */

export { API_BASE_PATH, BASE_PATH, MAJOR_VERSION } from './constants';
export { API_BASE_PATH, INTERNAL_API_BASE_PATH, BASE_PATH, MAJOR_VERSION } from './constants';

export { getTemplateParameter } from './lib';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
*/

import { HttpSetup } from '@kbn/core/public';
import { sendRequest } from '../shared_imports';
import { sendRequest, SendRequestResponse } from '../shared_imports';
import { API_BASE_PATH } from '../../common/constants';
import { SerializedEnrichPolicy } from '../../common/types';

export interface PublicApiServiceSetup {
getAllEnrichPolicies(): void;
getAllEnrichPolicies(): Promise<SendRequestResponse<SerializedEnrichPolicy[]>>;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { addBasePath } from '..';
import { addInternalBasePath } from '..';
import { RouterMock, routeDependencies, RequestMock } from '../../../test/helpers';
import { serializeEnrichmentPolicies } from '../../../lib/enrich_policies';
import { createTestESEnrichPolicy } from '../../../test/helpers';
Expand All @@ -28,13 +28,13 @@ describe('Enrich policies API', () => {
jest.resetAllMocks();
});

describe('Get all policies - GET /api/index_management/enrich_policies', () => {
describe('Get all policies - GET /internal/index_management/enrich_policies', () => {
const getEnrichPolicies = router.getMockESApiFn('enrich.getPolicy');

it('returns all available policies', async () => {
const mockRequest: RequestMock = {
method: 'get',
path: addBasePath('/enrich_policies'),
path: addInternalBasePath('/enrich_policies'),
};

getEnrichPolicies.mockResolvedValue({ policies: [mockedPolicy] });
Expand All @@ -49,7 +49,7 @@ describe('Enrich policies API', () => {
it('should return an error if it fails', async () => {
const mockRequest: RequestMock = {
method: 'get',
path: addBasePath('/enrich_policies'),
path: addInternalBasePath('/enrich_policies'),
};

const error = new Error('Oh no!');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

import { IScopedClusterClient } from '@kbn/core/server';
import { RouteDependencies } from '../../../types';
import { addBasePath } from '..';
import { addInternalBasePath } from '..';
import { enrichPoliciesActions } from '../../../lib/enrich_policies';

export function registerListRoute({ router, lib: { handleEsError } }: RouteDependencies) {
router.get(
{ path: addBasePath('/enrich_policies'), validate: false },
{ path: addInternalBasePath('/enrich_policies'), validate: false },
async (context, request, response) => {
const client = (await context.core).elasticsearch.client as IScopedClusterClient;
try {
Expand Down
4 changes: 3 additions & 1 deletion x-pack/plugins/index_management/server/routes/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* 2.0.
*/

import { API_BASE_PATH } from '../../../common';
import { API_BASE_PATH, INTERNAL_API_BASE_PATH } from '../../../common';

export const addBasePath = (uri: string): string => API_BASE_PATH + uri;

export const addInternalBasePath = (uri: string): string => INTERNAL_API_BASE_PATH + uri;

0 comments on commit a4e984e

Please sign in to comment.