Skip to content

Commit

Permalink
[Console] Fix use of legacy config (elastic#56468)
Browse files Browse the repository at this point in the history
* Fix use of legacy config

* Add types for ssl
  • Loading branch information
jloleysens committed Feb 1, 2020
1 parent 9cd1559 commit 581716b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/plugins/console/server/lib/elasticsearch_proxy_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import _ from 'lodash';
import http from 'http';
import https from 'https';
import url from 'url';
import { Duration } from 'moment';

const createAgent = (legacyConfig: any) => {
import { ESConfigForProxy } from '../types';

const createAgent = (legacyConfig: ESConfigForProxy) => {
const target = url.parse(_.head(legacyConfig.hosts));
if (!/^https/.test(target.protocol || '')) return new http.Agent();

Expand Down Expand Up @@ -59,7 +60,7 @@ const createAgent = (legacyConfig: any) => {
return new https.Agent(agentOptions);
};

export const getElasticsearchProxyConfig = (legacyConfig: { requestTimeout: Duration }) => {
export const getElasticsearchProxyConfig = (legacyConfig: ESConfigForProxy) => {
return {
timeout: legacyConfig.requestTimeout.asMilliseconds(),
agent: createAgent(legacyConfig),
Expand Down
4 changes: 1 addition & 3 deletions src/plugins/console/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ export class ConsoleServerPlugin implements Plugin<ConsoleSetup> {
const legacyConfig = readLegacyEsConfig();
return {
...elasticsearch,
hosts: legacyConfig.hosts,
requestHeadersWhitelist: legacyConfig.requestHeadersWhitelist,
customHeaders: legacyConfig.customHeaders,
...legacyConfig,
};
},
pathFilters: proxyPathFilters,
Expand Down
8 changes: 8 additions & 0 deletions src/plugins/console/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,12 @@ export interface ESConfigForProxy {
requestHeadersWhitelist: string[];
customHeaders: Record<string, any>;
requestTimeout: Duration;
ssl?: {
verificationMode: 'none' | 'certificate' | 'full';
certificateAuthorities: string[] | string;
alwaysPresentCertificate: boolean;
certificate?: string;
key?: string;
keyPassphrase?: string;
};
}

0 comments on commit 581716b

Please sign in to comment.