From 605b79e8ca5e2d88d11814443530bc7316d76827 Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Tue, 9 Jun 2020 06:36:56 -0700 Subject: [PATCH] Convert Index Templates API routes to snakecase. (#68463) Co-authored-by: Elastic Machine --- .../client_integration/helpers/http_requests.ts | 10 +++++----- .../home/index_templates_tab.test.ts | 4 ++-- .../public/application/services/api.ts | 10 +++++----- .../routes/api/templates/register_create_route.ts | 2 +- .../routes/api/templates/register_delete_route.ts | 2 +- .../server/routes/api/templates/register_get_routes.ts | 4 ++-- .../routes/api/templates/register_update_route.ts | 2 +- .../management/index_management/templates.helpers.js | 10 +++++----- 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/x-pack/plugins/index_management/__jest__/client_integration/helpers/http_requests.ts b/x-pack/plugins/index_management/__jest__/client_integration/helpers/http_requests.ts index da461609f0b8..75d1b69eb615 100644 --- a/x-pack/plugins/index_management/__jest__/client_integration/helpers/http_requests.ts +++ b/x-pack/plugins/index_management/__jest__/client_integration/helpers/http_requests.ts @@ -12,7 +12,7 @@ type HttpResponse = Record | 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, diff --git a/x-pack/plugins/index_management/__jest__/client_integration/home/index_templates_tab.test.ts b/x-pack/plugins/index_management/__jest__/client_integration/home/index_templates_tab.test.ts index 8f6a8dddeb19..7c79c7e61174 100644 --- a/x-pack/plugins/index_management/__jest__/client_integration/home/index_templates_tab.test.ts +++ b/x-pack/plugins/index_management/__jest__/client_integration/home/index_templates_tab.test.ts @@ -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 }], }); diff --git a/x-pack/plugins/index_management/public/application/services/api.ts b/x-pack/plugins/index_management/public/application/services/api.ts index 3961942b83ea..d1950ae71455 100644 --- a/x-pack/plugins/index_management/public/application/services/api.ts +++ b/x-pack/plugins/index_management/public/application/services/api.ts @@ -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({ - 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), }); diff --git a/x-pack/plugins/index_management/server/routes/api/templates/register_create_route.ts b/x-pack/plugins/index_management/server/routes/api/templates/register_create_route.ts index 26e74847e3e0..e0d92b380078 100644 --- a/x-pack/plugins/index_management/server/routes/api/templates/register_create_route.ts +++ b/x-pack/plugins/index_management/server/routes/api/templates/register_create_route.ts @@ -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; diff --git a/x-pack/plugins/index_management/server/routes/api/templates/register_delete_route.ts b/x-pack/plugins/index_management/server/routes/api/templates/register_delete_route.ts index b5cc00ad6d8c..1527af12a92a 100644 --- a/x-pack/plugins/index_management/server/routes/api/templates/register_delete_route.ts +++ b/x-pack/plugins/index_management/server/routes/api/templates/register_delete_route.ts @@ -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) => { diff --git a/x-pack/plugins/index_management/server/routes/api/templates/register_get_routes.ts b/x-pack/plugins/index_management/server/routes/api/templates/register_get_routes.ts index 12ec005258a6..ae5f7802a840 100644 --- a/x-pack/plugins/index_management/server/routes/api/templates/register_get_routes.ts +++ b/x-pack/plugins/index_management/server/routes/api/templates/register_get_routes.ts @@ -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) => { diff --git a/x-pack/plugins/index_management/server/routes/api/templates/register_update_route.ts b/x-pack/plugins/index_management/server/routes/api/templates/register_update_route.ts index 5b2a0d8722e4..7e9c3174d059 100644 --- a/x-pack/plugins/index_management/server/routes/api/templates/register_update_route.ts +++ b/x-pack/plugins/index_management/server/routes/api/templates/register_update_route.ts @@ -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) => { diff --git a/x-pack/test/api_integration/apis/management/index_management/templates.helpers.js b/x-pack/test/api_integration/apis/management/index_management/templates.helpers.js index 9f1fab403939..292aabad8505 100644 --- a/x-pack/test/api_integration/apis/management/index_management/templates.helpers.js +++ b/x-pack/test/api_integration/apis/management/index_management/templates.helpers.js @@ -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);