Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@
* Side Public License, v 1.
*/

import { getAutocompleteInfo } from '../../../services';
import { getAutocompleteInfo, ENTITIES } from '../../../services';
import { ListComponent } from './list_component';

export class ComponentTemplateAutocompleteComponent extends ListComponent {
constructor(name, parent) {
super(name, getAutocompleteInfo().getEntityProvider('componentTemplates'), parent, true, true);
super(
name,
getAutocompleteInfo().getEntityProvider(ENTITIES.COMPONENT_TEMPLATES),
parent,
true,
true
);
}

getContextKey() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@
*/

import { ListComponent } from './list_component';
import { getAutocompleteInfo } from '../../../services';
import { getAutocompleteInfo, ENTITIES } from '../../../services';

export class DataStreamAutocompleteComponent extends ListComponent {
constructor(name, parent, multiValued) {
super(name, getAutocompleteInfo().getEntityProvider('dataStreams'), parent, multiValued);
super(
name,
getAutocompleteInfo().getEntityProvider(ENTITIES.DATA_STREAMS),
parent,
multiValued
);
}

getContextKey() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
*/

import _ from 'lodash';
import { getAutocompleteInfo } from '../../../services';
import { getAutocompleteInfo, ENTITIES } from '../../../services';
import { ListComponent } from './list_component';

function FieldGenerator(context) {
return _.map(getAutocompleteInfo().getEntityProvider('fields', context), function (field) {
return _.map(getAutocompleteInfo().getEntityProvider(ENTITIES.FIELDS, context), function (field) {
return { name: field.name, meta: field.type };
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import _ from 'lodash';
import { getAutocompleteInfo } from '../../../services';
import { getAutocompleteInfo, ENTITIES } from '../../../services';
import { ListComponent } from './list_component';

function nonValidIndexType(token) {
Expand All @@ -16,7 +16,7 @@ function nonValidIndexType(token) {

export class IndexAutocompleteComponent extends ListComponent {
constructor(name, parent, multiValued) {
super(name, getAutocompleteInfo().getEntityProvider('indices'), parent, multiValued);
super(name, getAutocompleteInfo().getEntityProvider(ENTITIES.INDICES), parent, multiValued);
}
validateTokens(tokens) {
if (!this.multiValued && tokens.length > 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@
* Side Public License, v 1.
*/

import { getAutocompleteInfo } from '../../../services';
import { getAutocompleteInfo, ENTITIES } from '../../../services';
import { ListComponent } from './list_component';

export class IndexTemplateAutocompleteComponent extends ListComponent {
constructor(name, parent) {
super(name, getAutocompleteInfo().getEntityProvider('indexTemplates'), parent, true, true);
super(
name,
getAutocompleteInfo().getEntityProvider(ENTITIES.INDEX_TEMPLATES),
parent,
true,
true
);
}

getContextKey() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import _ from 'lodash';
import { getAutocompleteInfo } from '../../../services';
import { getAutocompleteInfo, ENTITIES } from '../../../services';
import { ListComponent } from './list_component';

function nonValidUsernameType(token) {
Expand All @@ -16,7 +16,7 @@ function nonValidUsernameType(token) {

export class UsernameAutocompleteComponent extends ListComponent {
constructor(name, parent, multiValued) {
super(name, getAutocompleteInfo().getEntityProvider('indices'), parent, multiValued);
super(name, getAutocompleteInfo().getEntityProvider(ENTITIES.INDICES), parent, multiValued);
}
validateTokens(tokens) {
if (!this.multiValued && tokens.length > 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface FieldMapping {
fields?: FieldMapping[];
}

export interface MappingsApiResponse {
export interface AutoCompleteEntitiesApiResponse {
mappings: IndicesGetMappingResponse;
aliases: IndicesGetAliasResponse;
dataStreams: IndicesGetDataStreamResponse;
Expand Down
27 changes: 18 additions & 9 deletions src/plugins/console/public/services/autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { createGetterSetter } from '@kbn/kibana-utils-plugin/public';
import type { HttpSetup } from '@kbn/core/public';
import type { MappingsApiResponse } from '../lib/autocomplete_entities/types';
import type { AutoCompleteEntitiesApiResponse } from '../lib/autocomplete_entities/types';
import { API_BASE_PATH } from '../../common/constants';
import {
Alias,
Expand All @@ -20,6 +20,15 @@ import {
} from '../lib/autocomplete_entities';
import { DevToolsSettings, Settings } from './settings';

export enum ENTITIES {
INDICES = 'indices',
FIELDS = 'fields',
INDEX_TEMPLATES = 'indexTemplates',
COMPONENT_TEMPLATES = 'componentTemplates',
LEGACY_TEMPLATES = 'legacyTemplates',
DATA_STREAMS = 'dataStreams',
}

export class AutocompleteInfo {
public readonly alias = new Alias();
public readonly mapping = new Mapping();
Expand All @@ -39,19 +48,19 @@ export class AutocompleteInfo {
context: { indices: string[]; types: string[] } = { indices: [], types: [] }
) {
switch (type) {
case 'indices':
case ENTITIES.INDICES:
const includeAliases = true;
const collaborator = this.mapping;
return () => this.alias.getIndices(includeAliases, collaborator);
case 'fields':
case ENTITIES.FIELDS:
return this.mapping.getMappings(context.indices, context.types);
case 'indexTemplates':
case ENTITIES.INDEX_TEMPLATES:
return () => this.indexTemplate.getTemplates();
case 'componentTemplates':
case ENTITIES.COMPONENT_TEMPLATES:
return () => this.componentTemplate.getTemplates();
case 'legacyTemplates':
case ENTITIES.LEGACY_TEMPLATES:
return () => this.legacyTemplate.getTemplates();
case 'dataStreams':
case ENTITIES.DATA_STREAMS:
return () => this.dataStream.getDataStreams();
default:
throw new Error(`Unsupported type: ${type}`);
Expand All @@ -61,7 +70,7 @@ export class AutocompleteInfo {
public retrieve(settings: Settings, settingsToRetrieve: DevToolsSettings['autocomplete']) {
this.clearSubscriptions();
this.http
.get<MappingsApiResponse>(`${API_BASE_PATH}/autocomplete_entities`, {
.get<AutoCompleteEntitiesApiResponse>(`${API_BASE_PATH}/autocomplete_entities`, {
query: { ...settingsToRetrieve },
})
.then((data) => {
Expand All @@ -83,7 +92,7 @@ export class AutocompleteInfo {
}
}

private load(data: MappingsApiResponse) {
private load(data: AutoCompleteEntitiesApiResponse) {
this.mapping.loadMappings(data.mappings);
const collaborator = this.mapping;
this.alias.loadAliases(data.aliases, collaborator);
Expand Down
7 changes: 6 additions & 1 deletion src/plugins/console/public/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@ export { createHistory, History } from './history';
export { createStorage, Storage, StorageKeys, setStorage, getStorage } from './storage';
export type { DevToolsSettings } from './settings';
export { createSettings, Settings, DEFAULT_SETTINGS } from './settings';
export { AutocompleteInfo, getAutocompleteInfo, setAutocompleteInfo } from './autocomplete';
export {
AutocompleteInfo,
getAutocompleteInfo,
setAutocompleteInfo,
ENTITIES,
} from './autocomplete';
8 changes: 1 addition & 7 deletions src/plugins/console/server/lib/proxy_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import net from 'net';
import stream from 'stream';
import Boom from '@hapi/boom';
import { URL } from 'url';
import { sanitizeHostname } from './utils';

interface Args {
method: 'get' | 'post' | 'put' | 'delete' | 'patch' | 'head';
Expand All @@ -23,13 +24,6 @@ interface Args {
rejectUnauthorized?: boolean;
}

/**
* Node http request library does not expect there to be trailing "[" or "]"
* characters in ipv6 host names.
*/
const sanitizeHostname = (hostName: string): string =>
hostName.trim().replace(/^\[/, '').replace(/\]$/, '');

// We use a modified version of Hapi's Wreck because Hapi, Axios, and Superagent don't support GET requests
// with bodies, but ES APIs do. Similarly with DELETE requests with bodies. Another library, `request`
// diverged too much from current behaviour.
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/console/server/lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@

export { encodePath } from './encode_path';
export { toURL } from './to_url';
export { streamToJSON } from './stream_to_json';
export { sanitizeHostname } from './sanitize_hostname';
27 changes: 27 additions & 0 deletions src/plugins/console/server/lib/utils/sanitize_hostname.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { sanitizeHostname } from './sanitize_hostname';

describe('sanitizeHostname', () => {
it('should remove leading and trailing brackets', () => {
expect(sanitizeHostname('[::1]')).toBe('::1');
});

it('should remove leading brackets', () => {
expect(sanitizeHostname('[::1')).toBe('::1');
});

it('should remove trailing brackets', () => {
expect(sanitizeHostname('::1]')).toBe('::1');
});

it('should not remove brackets in the middle of the string', () => {
expect(sanitizeHostname('[::1]foo')).toBe('::1]foo');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* Side Public License, v 1.
*/

import type { RouteDependencies } from '../../..';
import { registerGetRoute } from './register_get_route';

export function registerMappingsRoute(deps: RouteDependencies) {
registerGetRoute(deps);
}
/**
* Node http request library does not expect there to be trailing "[" or "]"
* characters in ipv6 host names.
*/
export const sanitizeHostname = (hostName: string): string =>
Comment thread
mibragimov marked this conversation as resolved.
Outdated
hostName.trim().replace(/^\[/, '').replace(/\]$/, '');
35 changes: 0 additions & 35 deletions src/plugins/console/server/lib/utils/stream_to_json.test.ts

This file was deleted.

27 changes: 0 additions & 27 deletions src/plugins/console/server/lib/utils/stream_to_json.ts

This file was deleted.

Loading