Convert Index Templates API routes to snakecase. (#68463)

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
CJ Cenizal 2020-06-09 06:36:56 -07:00 committed by GitHub
parent 994dba102c
commit 605b79e8ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 22 additions and 22 deletions

View file

@ -12,7 +12,7 @@ type HttpResponse = Record<string, any> | any[];
// Register helpers to mock HTTP Requests // Register helpers to mock HTTP Requests
const registerHttpRequestMockHelpers = (server: SinonFakeServer) => { const registerHttpRequestMockHelpers = (server: SinonFakeServer) => {
const setLoadTemplatesResponse = (response: HttpResponse = []) => { const setLoadTemplatesResponse = (response: HttpResponse = []) => {
server.respondWith('GET', `${API_BASE_PATH}/index-templates`, [ server.respondWith('GET', `${API_BASE_PATH}/index_templates`, [
200, 200,
{ 'Content-Type': 'application/json' }, { 'Content-Type': 'application/json' },
JSON.stringify(response), JSON.stringify(response),
@ -28,7 +28,7 @@ const registerHttpRequestMockHelpers = (server: SinonFakeServer) => {
}; };
const setDeleteTemplateResponse = (response: HttpResponse = []) => { const setDeleteTemplateResponse = (response: HttpResponse = []) => {
server.respondWith('POST', `${API_BASE_PATH}/delete-index-templates`, [ server.respondWith('POST', `${API_BASE_PATH}/delete_index_templates`, [
200, 200,
{ 'Content-Type': 'application/json' }, { 'Content-Type': 'application/json' },
JSON.stringify(response), JSON.stringify(response),
@ -39,7 +39,7 @@ const registerHttpRequestMockHelpers = (server: SinonFakeServer) => {
const status = error ? error.status || 400 : 200; const status = error ? error.status || 400 : 200;
const body = error ? error.body : response; 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, status,
{ 'Content-Type': 'application/json' }, { 'Content-Type': 'application/json' },
JSON.stringify(body), JSON.stringify(body),
@ -50,7 +50,7 @@ const registerHttpRequestMockHelpers = (server: SinonFakeServer) => {
const status = error ? error.body.status || 400 : 200; const status = error ? error.body.status || 400 : 200;
const body = error ? JSON.stringify(error.body) : JSON.stringify(response); 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, status,
{ 'Content-Type': 'application/json' }, { 'Content-Type': 'application/json' },
body, body,
@ -61,7 +61,7 @@ const registerHttpRequestMockHelpers = (server: SinonFakeServer) => {
const status = error ? error.status || 400 : 200; const status = error ? error.status || 400 : 200;
const body = error ? JSON.stringify(error.body) : JSON.stringify(response); 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, status,
{ 'Content-Type': 'application/json' }, { 'Content-Type': 'application/json' },
body, body,

View file

@ -188,7 +188,7 @@ describe('Index Templates tab', () => {
expect(server.requests.length).toBe(totalRequests + 1); expect(server.requests.length).toBe(totalRequests + 1);
expect(server.requests[server.requests.length - 1].url).toBe( 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]; const latestRequest = server.requests[server.requests.length - 1];
expect(latestRequest.method).toBe('POST'); 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({ expect(JSON.parse(JSON.parse(latestRequest.requestBody).body)).toEqual({
templates: [{ name: legacyTemplates[0].name, isLegacy }], templates: [{ name: legacyTemplates[0].name, isLegacy }],
}); });

View file

@ -211,14 +211,14 @@ export async function loadIndexData(type: string, indexName: string) {
export function useLoadIndexTemplates() { export function useLoadIndexTemplates() {
return useRequest<{ templates: TemplateListItem[]; legacyTemplates: TemplateListItem[] }>({ return useRequest<{ templates: TemplateListItem[]; legacyTemplates: TemplateListItem[] }>({
path: `${API_BASE_PATH}/index-templates`, path: `${API_BASE_PATH}/index_templates`,
method: 'get', method: 'get',
}); });
} }
export async function deleteTemplates(templates: Array<{ name: string; isLegacy?: boolean }>) { export async function deleteTemplates(templates: Array<{ name: string; isLegacy?: boolean }>) {
const result = sendRequest({ const result = sendRequest({
path: `${API_BASE_PATH}/delete-index-templates`, path: `${API_BASE_PATH}/delete_index_templates`,
method: 'post', method: 'post',
body: { templates }, body: { templates },
}); });
@ -232,7 +232,7 @@ export async function deleteTemplates(templates: Array<{ name: string; isLegacy?
export function useLoadIndexTemplate(name: TemplateDeserialized['name'], isLegacy?: boolean) { export function useLoadIndexTemplate(name: TemplateDeserialized['name'], isLegacy?: boolean) {
return useRequest<TemplateDeserialized>({ return useRequest<TemplateDeserialized>({
path: `${API_BASE_PATH}/index-templates/${encodeURIComponent(name)}`, path: `${API_BASE_PATH}/index_templates/${encodeURIComponent(name)}`,
method: 'get', method: 'get',
query: { query: {
legacy: isLegacy, legacy: isLegacy,
@ -242,7 +242,7 @@ export function useLoadIndexTemplate(name: TemplateDeserialized['name'], isLegac
export async function saveTemplate(template: TemplateDeserialized, isClone?: boolean) { export async function saveTemplate(template: TemplateDeserialized, isClone?: boolean) {
const result = await sendRequest({ const result = await sendRequest({
path: `${API_BASE_PATH}/index-templates`, path: `${API_BASE_PATH}/index_templates`,
method: 'post', method: 'post',
body: JSON.stringify(template), body: JSON.stringify(template),
}); });
@ -257,7 +257,7 @@ export async function saveTemplate(template: TemplateDeserialized, isClone?: boo
export async function updateTemplate(template: TemplateDeserialized) { export async function updateTemplate(template: TemplateDeserialized) {
const { name } = template; const { name } = template;
const result = await sendRequest({ const result = await sendRequest({
path: `${API_BASE_PATH}/index-templates/${encodeURIComponent(name)}`, path: `${API_BASE_PATH}/index_templates/${encodeURIComponent(name)}`,
method: 'put', method: 'put',
body: JSON.stringify(template), body: JSON.stringify(template),
}); });

View file

@ -16,7 +16,7 @@ const bodySchema = templateSchema;
export function registerCreateRoute({ router, license, lib }: RouteDependencies) { export function registerCreateRoute({ router, license, lib }: RouteDependencies) {
router.post( router.post(
{ path: addBasePath('/index-templates'), validate: { body: bodySchema } }, { path: addBasePath('/index_templates'), validate: { body: bodySchema } },
license.guardApiRoute(async (ctx, req, res) => { license.guardApiRoute(async (ctx, req, res) => {
const { callAsCurrentUser } = ctx.core.elasticsearch.legacy.client; const { callAsCurrentUser } = ctx.core.elasticsearch.legacy.client;
const template = req.body as TemplateDeserialized; const template = req.body as TemplateDeserialized;

View file

@ -24,7 +24,7 @@ const bodySchema = schema.object({
export function registerDeleteRoute({ router, license }: RouteDependencies) { export function registerDeleteRoute({ router, license }: RouteDependencies) {
router.post( router.post(
{ {
path: addBasePath('/delete-index-templates'), path: addBasePath('/delete_index_templates'),
validate: { body: bodySchema }, validate: { body: bodySchema },
}, },
license.guardApiRoute(async (ctx, req, res) => { license.guardApiRoute(async (ctx, req, res) => {

View file

@ -16,7 +16,7 @@ import { addBasePath } from '../index';
export function registerGetAllRoute({ router, license }: RouteDependencies) { export function registerGetAllRoute({ router, license }: RouteDependencies) {
router.get( router.get(
{ path: addBasePath('/index-templates'), validate: false }, { path: addBasePath('/index_templates'), validate: false },
license.guardApiRoute(async (ctx, req, res) => { license.guardApiRoute(async (ctx, req, res) => {
const { callAsCurrentUser } = ctx.core.elasticsearch.legacy.client; const { callAsCurrentUser } = ctx.core.elasticsearch.legacy.client;
const managedTemplatePrefix = await getManagedTemplatePrefix(callAsCurrentUser); const managedTemplatePrefix = await getManagedTemplatePrefix(callAsCurrentUser);
@ -55,7 +55,7 @@ const querySchema = schema.object({
export function registerGetOneRoute({ router, license, lib }: RouteDependencies) { export function registerGetOneRoute({ router, license, lib }: RouteDependencies) {
router.get( router.get(
{ {
path: addBasePath('/index-templates/{name}'), path: addBasePath('/index_templates/{name}'),
validate: { params: paramsSchema, query: querySchema }, validate: { params: paramsSchema, query: querySchema },
}, },
license.guardApiRoute(async (ctx, req, res) => { license.guardApiRoute(async (ctx, req, res) => {

View file

@ -19,7 +19,7 @@ const paramsSchema = schema.object({
export function registerUpdateRoute({ router, license, lib }: RouteDependencies) { export function registerUpdateRoute({ router, license, lib }: RouteDependencies) {
router.put( router.put(
{ {
path: addBasePath('/index-templates/{name}'), path: addBasePath('/index_templates/{name}'),
validate: { body: bodySchema, params: paramsSchema }, validate: { body: bodySchema, params: paramsSchema },
}, },
license.guardApiRoute(async (ctx, req, res) => { license.guardApiRoute(async (ctx, req, res) => {

View file

@ -7,10 +7,10 @@
import { API_BASE_PATH, INDEX_PATTERNS } from './constants'; import { API_BASE_PATH, INDEX_PATTERNS } from './constants';
export const registerHelpers = ({ supertest }) => { 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) => 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) => ({ const getTemplatePayload = (name, isLegacy = true) => ({
name, name,
@ -50,17 +50,17 @@ export const registerHelpers = ({ supertest }) => {
}); });
const createTemplate = (payload) => 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) => const deleteTemplates = (templates) =>
supertest supertest
.post(`${API_BASE_PATH}/delete-index-templates`) .post(`${API_BASE_PATH}/delete_index_templates`)
.set('kbn-xsrf', 'xxx') .set('kbn-xsrf', 'xxx')
.send({ templates }); .send({ templates });
const updateTemplate = (payload, templateName) => const updateTemplate = (payload, templateName) =>
supertest supertest
.put(`${API_BASE_PATH}/index-templates/${templateName}`) .put(`${API_BASE_PATH}/index_templates/${templateName}`)
.set('kbn-xsrf', 'xxx') .set('kbn-xsrf', 'xxx')
.send(payload); .send(payload);