Convert Index Templates API routes to snakecase. (#68463)
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
994dba102c
commit
605b79e8ca
|
@ -12,7 +12,7 @@ type HttpResponse = Record<string, any> | any[];
|
|||
// Register helpers to mock HTTP Requests
|
||||
const registerHttpRequestMockHelpers = (server: SinonFakeServer) => {
|
||||
const setLoadTemplatesResponse = (response: HttpResponse = []) => {
|
||||
server.respondWith('GET', `${API_BASE_PATH}/index-templates`, [
|
||||
server.respondWith('GET', `${API_BASE_PATH}/index_templates`, [
|
||||
200,
|
||||
{ 'Content-Type': 'application/json' },
|
||||
JSON.stringify(response),
|
||||
|
@ -28,7 +28,7 @@ const registerHttpRequestMockHelpers = (server: SinonFakeServer) => {
|
|||
};
|
||||
|
||||
const setDeleteTemplateResponse = (response: HttpResponse = []) => {
|
||||
server.respondWith('POST', `${API_BASE_PATH}/delete-index-templates`, [
|
||||
server.respondWith('POST', `${API_BASE_PATH}/delete_index_templates`, [
|
||||
200,
|
||||
{ 'Content-Type': 'application/json' },
|
||||
JSON.stringify(response),
|
||||
|
@ -39,7 +39,7 @@ const registerHttpRequestMockHelpers = (server: SinonFakeServer) => {
|
|||
const status = error ? error.status || 400 : 200;
|
||||
const body = error ? error.body : response;
|
||||
|
||||
server.respondWith('GET', `${API_BASE_PATH}/index-templates/:id`, [
|
||||
server.respondWith('GET', `${API_BASE_PATH}/index_templates/:id`, [
|
||||
status,
|
||||
{ 'Content-Type': 'application/json' },
|
||||
JSON.stringify(body),
|
||||
|
@ -50,7 +50,7 @@ const registerHttpRequestMockHelpers = (server: SinonFakeServer) => {
|
|||
const status = error ? error.body.status || 400 : 200;
|
||||
const body = error ? JSON.stringify(error.body) : JSON.stringify(response);
|
||||
|
||||
server.respondWith('POST', `${API_BASE_PATH}/index-templates`, [
|
||||
server.respondWith('POST', `${API_BASE_PATH}/index_templates`, [
|
||||
status,
|
||||
{ 'Content-Type': 'application/json' },
|
||||
body,
|
||||
|
@ -61,7 +61,7 @@ const registerHttpRequestMockHelpers = (server: SinonFakeServer) => {
|
|||
const status = error ? error.status || 400 : 200;
|
||||
const body = error ? JSON.stringify(error.body) : JSON.stringify(response);
|
||||
|
||||
server.respondWith('PUT', `${API_BASE_PATH}/index-templates/:name`, [
|
||||
server.respondWith('PUT', `${API_BASE_PATH}/index_templates/:name`, [
|
||||
status,
|
||||
{ 'Content-Type': 'application/json' },
|
||||
body,
|
||||
|
|
|
@ -188,7 +188,7 @@ describe('Index Templates tab', () => {
|
|||
|
||||
expect(server.requests.length).toBe(totalRequests + 1);
|
||||
expect(server.requests[server.requests.length - 1].url).toBe(
|
||||
`${API_BASE_PATH}/index-templates`
|
||||
`${API_BASE_PATH}/index_templates`
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -318,7 +318,7 @@ describe('Index Templates tab', () => {
|
|||
const latestRequest = server.requests[server.requests.length - 1];
|
||||
|
||||
expect(latestRequest.method).toBe('POST');
|
||||
expect(latestRequest.url).toBe(`${API_BASE_PATH}/delete-index-templates`);
|
||||
expect(latestRequest.url).toBe(`${API_BASE_PATH}/delete_index_templates`);
|
||||
expect(JSON.parse(JSON.parse(latestRequest.requestBody).body)).toEqual({
|
||||
templates: [{ name: legacyTemplates[0].name, isLegacy }],
|
||||
});
|
||||
|
|
|
@ -211,14 +211,14 @@ export async function loadIndexData(type: string, indexName: string) {
|
|||
|
||||
export function useLoadIndexTemplates() {
|
||||
return useRequest<{ templates: TemplateListItem[]; legacyTemplates: TemplateListItem[] }>({
|
||||
path: `${API_BASE_PATH}/index-templates`,
|
||||
path: `${API_BASE_PATH}/index_templates`,
|
||||
method: 'get',
|
||||
});
|
||||
}
|
||||
|
||||
export async function deleteTemplates(templates: Array<{ name: string; isLegacy?: boolean }>) {
|
||||
const result = sendRequest({
|
||||
path: `${API_BASE_PATH}/delete-index-templates`,
|
||||
path: `${API_BASE_PATH}/delete_index_templates`,
|
||||
method: 'post',
|
||||
body: { templates },
|
||||
});
|
||||
|
@ -232,7 +232,7 @@ export async function deleteTemplates(templates: Array<{ name: string; isLegacy?
|
|||
|
||||
export function useLoadIndexTemplate(name: TemplateDeserialized['name'], isLegacy?: boolean) {
|
||||
return useRequest<TemplateDeserialized>({
|
||||
path: `${API_BASE_PATH}/index-templates/${encodeURIComponent(name)}`,
|
||||
path: `${API_BASE_PATH}/index_templates/${encodeURIComponent(name)}`,
|
||||
method: 'get',
|
||||
query: {
|
||||
legacy: isLegacy,
|
||||
|
@ -242,7 +242,7 @@ export function useLoadIndexTemplate(name: TemplateDeserialized['name'], isLegac
|
|||
|
||||
export async function saveTemplate(template: TemplateDeserialized, isClone?: boolean) {
|
||||
const result = await sendRequest({
|
||||
path: `${API_BASE_PATH}/index-templates`,
|
||||
path: `${API_BASE_PATH}/index_templates`,
|
||||
method: 'post',
|
||||
body: JSON.stringify(template),
|
||||
});
|
||||
|
@ -257,7 +257,7 @@ export async function saveTemplate(template: TemplateDeserialized, isClone?: boo
|
|||
export async function updateTemplate(template: TemplateDeserialized) {
|
||||
const { name } = template;
|
||||
const result = await sendRequest({
|
||||
path: `${API_BASE_PATH}/index-templates/${encodeURIComponent(name)}`,
|
||||
path: `${API_BASE_PATH}/index_templates/${encodeURIComponent(name)}`,
|
||||
method: 'put',
|
||||
body: JSON.stringify(template),
|
||||
});
|
||||
|
|
|
@ -16,7 +16,7 @@ const bodySchema = templateSchema;
|
|||
|
||||
export function registerCreateRoute({ router, license, lib }: RouteDependencies) {
|
||||
router.post(
|
||||
{ path: addBasePath('/index-templates'), validate: { body: bodySchema } },
|
||||
{ path: addBasePath('/index_templates'), validate: { body: bodySchema } },
|
||||
license.guardApiRoute(async (ctx, req, res) => {
|
||||
const { callAsCurrentUser } = ctx.core.elasticsearch.legacy.client;
|
||||
const template = req.body as TemplateDeserialized;
|
||||
|
|
|
@ -24,7 +24,7 @@ const bodySchema = schema.object({
|
|||
export function registerDeleteRoute({ router, license }: RouteDependencies) {
|
||||
router.post(
|
||||
{
|
||||
path: addBasePath('/delete-index-templates'),
|
||||
path: addBasePath('/delete_index_templates'),
|
||||
validate: { body: bodySchema },
|
||||
},
|
||||
license.guardApiRoute(async (ctx, req, res) => {
|
||||
|
|
|
@ -16,7 +16,7 @@ import { addBasePath } from '../index';
|
|||
|
||||
export function registerGetAllRoute({ router, license }: RouteDependencies) {
|
||||
router.get(
|
||||
{ path: addBasePath('/index-templates'), validate: false },
|
||||
{ path: addBasePath('/index_templates'), validate: false },
|
||||
license.guardApiRoute(async (ctx, req, res) => {
|
||||
const { callAsCurrentUser } = ctx.core.elasticsearch.legacy.client;
|
||||
const managedTemplatePrefix = await getManagedTemplatePrefix(callAsCurrentUser);
|
||||
|
@ -55,7 +55,7 @@ const querySchema = schema.object({
|
|||
export function registerGetOneRoute({ router, license, lib }: RouteDependencies) {
|
||||
router.get(
|
||||
{
|
||||
path: addBasePath('/index-templates/{name}'),
|
||||
path: addBasePath('/index_templates/{name}'),
|
||||
validate: { params: paramsSchema, query: querySchema },
|
||||
},
|
||||
license.guardApiRoute(async (ctx, req, res) => {
|
||||
|
|
|
@ -19,7 +19,7 @@ const paramsSchema = schema.object({
|
|||
export function registerUpdateRoute({ router, license, lib }: RouteDependencies) {
|
||||
router.put(
|
||||
{
|
||||
path: addBasePath('/index-templates/{name}'),
|
||||
path: addBasePath('/index_templates/{name}'),
|
||||
validate: { body: bodySchema, params: paramsSchema },
|
||||
},
|
||||
license.guardApiRoute(async (ctx, req, res) => {
|
||||
|
|
|
@ -7,10 +7,10 @@
|
|||
import { API_BASE_PATH, INDEX_PATTERNS } from './constants';
|
||||
|
||||
export const registerHelpers = ({ supertest }) => {
|
||||
const getAllTemplates = () => supertest.get(`${API_BASE_PATH}/index-templates`);
|
||||
const getAllTemplates = () => supertest.get(`${API_BASE_PATH}/index_templates`);
|
||||
|
||||
const getOneTemplate = (name, isLegacy = true) =>
|
||||
supertest.get(`${API_BASE_PATH}/index-templates/${name}?legacy=${isLegacy}`);
|
||||
supertest.get(`${API_BASE_PATH}/index_templates/${name}?legacy=${isLegacy}`);
|
||||
|
||||
const getTemplatePayload = (name, isLegacy = true) => ({
|
||||
name,
|
||||
|
@ -50,17 +50,17 @@ export const registerHelpers = ({ supertest }) => {
|
|||
});
|
||||
|
||||
const createTemplate = (payload) =>
|
||||
supertest.post(`${API_BASE_PATH}/index-templates`).set('kbn-xsrf', 'xxx').send(payload);
|
||||
supertest.post(`${API_BASE_PATH}/index_templates`).set('kbn-xsrf', 'xxx').send(payload);
|
||||
|
||||
const deleteTemplates = (templates) =>
|
||||
supertest
|
||||
.post(`${API_BASE_PATH}/delete-index-templates`)
|
||||
.post(`${API_BASE_PATH}/delete_index_templates`)
|
||||
.set('kbn-xsrf', 'xxx')
|
||||
.send({ templates });
|
||||
|
||||
const updateTemplate = (payload, templateName) =>
|
||||
supertest
|
||||
.put(`${API_BASE_PATH}/index-templates/${templateName}`)
|
||||
.put(`${API_BASE_PATH}/index_templates/${templateName}`)
|
||||
.set('kbn-xsrf', 'xxx')
|
||||
.send(payload);
|
||||
|
||||
|
|
Loading…
Reference in a new issue