-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EnterpriseSearch] engines list proxy endpoint (#148352)
## Summary Added a proxy endpoint to list engines from enterprise search.
- Loading branch information
1 parent
8c7a426
commit b991c59
Showing
4 changed files
with
263 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export interface EnterpriseSearchEnginesResponse { | ||
meta: { | ||
from: number; | ||
size: number; | ||
total: number; | ||
}; | ||
results: EnterpriseSearchEngine[]; | ||
} | ||
|
||
export interface EnterpriseSearchEngine { | ||
name: string; | ||
indices: string[]; | ||
} |
174 changes: 174 additions & 0 deletions
174
x-pack/plugins/enterprise_search/server/routes/enterprise_search/engines.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { mockDependencies, mockRequestHandler, MockRouter } from '../../__mocks__'; | ||
|
||
import { registerEnginesRoutes } from './engines'; | ||
|
||
describe('engines routes', () => { | ||
describe('GET /internal/enterprise_search/engines', () => { | ||
let mockRouter: MockRouter; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
mockRouter = new MockRouter({ | ||
method: 'get', | ||
path: '/internal/enterprise_search/engines', | ||
}); | ||
|
||
registerEnginesRoutes({ | ||
...mockDependencies, | ||
router: mockRouter.router, | ||
}); | ||
}); | ||
|
||
it('creates a request to enterprise search', () => { | ||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({ | ||
path: '/api/engines', | ||
}); | ||
}); | ||
|
||
it('validates query parameters', () => { | ||
const request = { query: { from: 20, size: 20 } }; | ||
|
||
mockRouter.shouldValidate(request); | ||
}); | ||
|
||
it('fails validation with invalid from parameter', () => { | ||
const request = { query: { from: -10 } }; | ||
|
||
mockRouter.shouldThrow(request); | ||
}); | ||
|
||
it('fails validation with invalid size parameter', () => { | ||
const request = { query: { size: 0 } }; | ||
|
||
mockRouter.shouldThrow(request); | ||
}); | ||
}); | ||
|
||
describe('GET /internal/enterprise_search/engines/{engine_name}', () => { | ||
let mockRouter: MockRouter; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
mockRouter = new MockRouter({ | ||
method: 'get', | ||
path: '/internal/enterprise_search/engines/{engine_name}', | ||
}); | ||
|
||
registerEnginesRoutes({ | ||
...mockDependencies, | ||
router: mockRouter.router, | ||
}); | ||
}); | ||
|
||
it('creates a request to enterprise search', () => { | ||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({ | ||
path: '/api/engines/:engine_name', | ||
}); | ||
}); | ||
|
||
it('validates correctly with engine_name', () => { | ||
const request = { params: { engine_name: 'some-engine' } }; | ||
|
||
mockRouter.shouldValidate(request); | ||
}); | ||
|
||
it('fails validation without name', () => { | ||
const request = { params: {} }; | ||
|
||
mockRouter.shouldThrow(request); | ||
}); | ||
}); | ||
|
||
describe('PUT /internal/enterprise_search/engines/{engine_name}', () => { | ||
let mockRouter: MockRouter; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
mockRouter = new MockRouter({ | ||
method: 'put', | ||
path: '/internal/enterprise_search/engines/{engine_name}', | ||
}); | ||
|
||
registerEnginesRoutes({ | ||
...mockDependencies, | ||
router: mockRouter.router, | ||
}); | ||
}); | ||
|
||
it('creates a request to enterprise search', () => { | ||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({ | ||
path: '/api/engines/:engine_name', | ||
}); | ||
}); | ||
|
||
it('validates correctly with engine_name', () => { | ||
const request = { | ||
params: { engine_name: 'some-engine' }, | ||
body: { | ||
indices: ['search-unit-test'], | ||
}, | ||
}; | ||
|
||
mockRouter.shouldValidate(request); | ||
}); | ||
|
||
it('fails validation without name', () => { | ||
const request = { params: {} }; | ||
|
||
mockRouter.shouldThrow(request); | ||
}); | ||
|
||
it('fails validation without indices', () => { | ||
const request = { | ||
params: { engine_name: 'some-engine' }, | ||
body: { | ||
name: 'some-engine', | ||
}, | ||
}; | ||
|
||
mockRouter.shouldThrow(request); | ||
}); | ||
}); | ||
|
||
describe('DELETE /internal/enterprise_search/engines/{engine_name}', () => { | ||
let mockRouter: MockRouter; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
mockRouter = new MockRouter({ | ||
method: 'delete', | ||
path: '/internal/enterprise_search/engines/{engine_name}', | ||
}); | ||
|
||
registerEnginesRoutes({ | ||
...mockDependencies, | ||
router: mockRouter.router, | ||
}); | ||
}); | ||
|
||
it('creates a request to enterprise search', () => { | ||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({ | ||
path: '/api/engines/:engine_name', | ||
}); | ||
}); | ||
|
||
it('validates correctly with engine_name', () => { | ||
const request = { params: { engine_name: 'some-engine' } }; | ||
|
||
mockRouter.shouldValidate(request); | ||
}); | ||
|
||
it('fails validation without name', () => { | ||
const request = { params: {} }; | ||
|
||
mockRouter.shouldThrow(request); | ||
}); | ||
}); | ||
}); |
67 changes: 67 additions & 0 deletions
67
x-pack/plugins/enterprise_search/server/routes/enterprise_search/engines.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import { schema } from '@kbn/config-schema'; | ||
|
||
import { RouteDependencies } from '../../plugin'; | ||
|
||
export function registerEnginesRoutes({ | ||
router, | ||
enterpriseSearchRequestHandler, | ||
}: RouteDependencies) { | ||
router.get( | ||
{ | ||
path: '/internal/enterprise_search/engines', | ||
validate: { | ||
query: schema.object({ | ||
from: schema.number({ defaultValue: 0, min: 0 }), | ||
size: schema.number({ defaultValue: 10, min: 1 }), | ||
}), | ||
}, | ||
}, | ||
enterpriseSearchRequestHandler.createRequest({ path: '/api/engines' }) | ||
); | ||
|
||
router.get( | ||
{ | ||
path: '/internal/enterprise_search/engines/{engine_name}', | ||
validate: { | ||
params: schema.object({ | ||
engine_name: schema.string(), | ||
}), | ||
}, | ||
}, | ||
enterpriseSearchRequestHandler.createRequest({ path: '/api/engines/:engine_name' }) | ||
); | ||
|
||
router.put( | ||
{ | ||
path: '/internal/enterprise_search/engines/{engine_name}', | ||
validate: { | ||
params: schema.object({ | ||
engine_name: schema.string(), | ||
}), | ||
body: schema.object({ | ||
name: schema.maybe(schema.string()), | ||
indices: schema.arrayOf(schema.string()), | ||
}), | ||
}, | ||
}, | ||
enterpriseSearchRequestHandler.createRequest({ path: '/api/engines/:engine_name' }) | ||
); | ||
|
||
router.delete( | ||
{ | ||
path: '/internal/enterprise_search/engines/{engine_name}', | ||
validate: { | ||
params: schema.object({ | ||
engine_name: schema.string(), | ||
}), | ||
}, | ||
}, | ||
enterpriseSearchRequestHandler.createRequest({ path: '/api/engines/:engine_name' }) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters