Skip to content

Commit

Permalink
WiP on getting server side working
Browse files Browse the repository at this point in the history
  • Loading branch information
jloleysens committed Jan 22, 2020
1 parent 29db598 commit 0e8fae1
Show file tree
Hide file tree
Showing 204 changed files with 420 additions and 367 deletions.
183 changes: 0 additions & 183 deletions src/legacy/core_plugins/console/index.ts

This file was deleted.

53 changes: 0 additions & 53 deletions src/legacy/core_plugins/console/public/legacy.ts

This file was deleted.

117 changes: 117 additions & 0 deletions src/legacy/core_plugins/console_legacy/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { first } from 'rxjs/operators';
import { resolve } from 'path';
import url from 'url';
import { has, isEmpty, head, pick } from 'lodash';

// @ts-ignore
// import { setHeaders } from './server/set_headers';
// @ts-ignore
// import { ProxyConfigCollection, getElasticsearchProxyConfig, createProxyRoute } from './server';

let _legacyEsConfig: any;
export const readLegacyEsConfig = () => {
return _legacyEsConfig;
};

function filterHeaders(originalHeaders: any, headersToKeep: any) {
const normalizeHeader = function(header: any) {
if (!header) {
return '';
}
header = header.toString();
return header.trim().toLowerCase();
};

// Normalize list of headers we want to allow in upstream request
const headersToKeepNormalized = headersToKeep.map(normalizeHeader);

return pick(originalHeaders, headersToKeepNormalized);
}

// eslint-disable-next-line
export default function(kibana: any) {
return new kibana.Plugin({
id: 'console_legacy',

async init(server: any, options: any) {
// server.expose('addExtensionSpecFilePath', addExtensionSpecFilePath);
// server.expose('addProcessorDefinition', addProcessorDefinition);

// const config = server.config();
_legacyEsConfig = await server.newPlatform.__internals.elasticsearch.legacy.config$
.pipe(first())
.toPromise();
// const proxyConfigCollection = new ProxyConfigCollection(options.proxyConfig);
// const proxyPathFilters = options.proxyFilter.map((str: string) => new RegExp(str));

// defaultVars = {
// elasticsearchUrl: url.format(
// Object.assign(url.parse(head(legacyEsConfig.hosts)), { auth: false })
// ),
// };

// server.route(
// createProxyRoute({
// hosts: legacyEsConfig.hosts,
// pathFilters: proxyPathFilters,
// getConfigForReq(req: any, uri: any) {
// const filteredHeaders = filterHeaders(
// req.headers,
// legacyEsConfig.requestHeadersWhitelist
// );
// const headers = setHeaders(filteredHeaders, legacyEsConfig.customHeaders);
//
// if (!isEmpty(config.get('console.proxyConfig'))) {
// return {
// ...proxyConfigCollection.configForUri(uri),
// headers,
// };
// }
//
// return {
// ...getElasticsearchProxyConfig(legacyEsConfig),
// headers,
// };
// },
// })
// );
//
// server.route({
// path: '/api/console/api_server',
// method: ['GET', 'POST'],
// handler(req: any, h: any) {
// const { sense_version: version, apis } = req.query;
// if (!apis) {
// throw Boom.badRequest('"apis" is a required param.');
// }
//
// return resolveApi(version, apis.split(','), h);
// },
// });
},

uiExports: {
styleSheetPaths: resolve(__dirname, 'public/styles/index.scss'),
// injectDefaultVars: () => defaultVars,
},
} as any);
}
4 changes: 4 additions & 0 deletions src/legacy/core_plugins/console_legacy/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "console_legacy",
"version": "kibana"
}
2 changes: 1 addition & 1 deletion src/plugins/console/common/types/plugin_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
* under the License.
*/

export interface PluginConfig {
export interface PluginServerConfig {
elasticsearchUrl: string;
}
2 changes: 1 addition & 1 deletion src/plugins/console/kibana.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "console",
"version": "kibana",
"server": false,
"server": true,
"ui": true,
"requiredPlugins": ["dev_tools", "home"],
"optionalPlugins": ["usageCollection"]
Expand Down
4 changes: 1 addition & 3 deletions src/plugins/console/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import { CoreSetup, CoreStart, Plugin, PluginInitializerContext } from 'kibana/p

import { FeatureCatalogueCategory } from '../../home/public';

import { PluginConfig } from '../common/types';

import { AppSetupUIPluginDependencies } from './types';

export class ConsoleUIPlugin implements Plugin<void, void, AppSetupUIPluginDependencies> {
Expand Down Expand Up @@ -58,7 +56,7 @@ export class ConsoleUIPlugin implements Plugin<void, void, AppSetupUIPluginDepen
enableRouting: false,
mount: async ({ core: { docLinks, i18n: i18nDep } }, { element }) => {
const { boot } = await import('./application');
const { elasticsearchUrl } = this.ctx.config.get<PluginConfig>();
const { elasticsearchUrl } = this.ctx.config.get<any>();
render(
boot({
docLinkVersion: docLinks.DOC_LINK_VERSION,
Expand Down
Loading

0 comments on commit 0e8fae1

Please sign in to comment.