Skip to content

Commit

Permalink
registerDatasource from plugin lifecycle
Browse files Browse the repository at this point in the history
  • Loading branch information
parkiino committed Jun 3, 2020
1 parent 635d035 commit ac2441d
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import React from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiEmptyPrompt, EuiText } from '@elastic/eui';
import { ConfigureEndpointDatasource } from '../../../../../../../../siem/public';
import { NewDatasource } from '../../../../types';
import { CreateDatasourceFrom } from '../types';

Expand All @@ -17,14 +16,26 @@ export interface CustomConfigureDatasourceProps {
}

/**
* Allows external plugins to create custom content for the Ingest
* Custom content type that external plugins can provide to Ingest's
* Datasource configuration.
*/
export type CustomConfigureDatasourceContent = React.FC<CustomConfigureDatasourceProps>;

const ConfigureDatasourceMapping: { [key: string]: CustomConfigureDatasourceContent } = {
endpoint: ConfigureEndpointDatasource,
};
type AllowedDatasourceKey = 'endpoint';
const ConfigureDatasourceMapping: {
[key: string]: CustomConfigureDatasourceContent;
} = {};

/**
* Plugins can call this function from the start lifecycle to
* register a custom component in the Ingest Datasource configuration.
*/
export function registerDatasource(
key: AllowedDatasourceKey,
value: CustomConfigureDatasourceContent
) {
ConfigureDatasourceMapping[key] = value;
}

const EmptyConfigureDatasource: CustomConfigureDatasourceContent = () => (
<EuiEmptyPrompt
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/ingest_manager/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const plugin = (initializerContext: PluginInitializerContext) => {
export {
CustomConfigureDatasourceContent,
CustomConfigureDatasourceProps,
registerDatasource,
} from './applications/ingest_manager/sections/agent_config/create_datasource_page/components/custom_configure_datasource';

export { NewDatasource } from './applications/ingest_manager/types';
10 changes: 8 additions & 2 deletions x-pack/plugins/ingest_manager/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { PLUGIN_ID } from '../common/constants';

import { IngestManagerConfigType } from '../common/types';
import { setupRouteService, appRoutesService } from '../common';
import { registerDatasource } from './applications/ingest_manager/sections/agent_config/create_datasource_page/components/custom_configure_datasource';

export { IngestManagerConfigType } from '../common/types';

Expand All @@ -26,6 +27,7 @@ export type IngestManagerSetup = void;
* Describes public IngestManager plugin contract returned at the `start` stage.
*/
export interface IngestManagerStart {
registerDatasource: typeof registerDatasource;
success: boolean;
error?: {
message: string;
Expand Down Expand Up @@ -80,12 +82,16 @@ export class IngestManagerPlugin
const permissionsResponse = await core.http.get(appRoutesService.getCheckPermissionsPath());
if (permissionsResponse.success) {
const { isInitialized: success } = await core.http.post(setupRouteService.getSetupPath());
return { success };
return { success, registerDatasource };
} else {
throw new Error(permissionsResponse.error);
}
} catch (error) {
return { success: false, error: { message: error.body?.message || 'Unknown error' } };
return {
success: false,
error: { message: error.body?.message || 'Unknown error' },
registerDatasource,
};
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { IngestManagerStart } from '../../../../../ingest_manager/public';
import { IngestManagerStart, registerDatasource } from '../../../../../ingest_manager/public';
import {
dataPluginMock,
Start as DataPublicStartMock,
Expand Down Expand Up @@ -56,6 +56,6 @@ export const depsStartMock: () => DepsStartMock = () => {

return {
data: dataMock,
ingestManager: { success: true },
ingestManager: { success: true, registerDatasource },
};
};
2 changes: 0 additions & 2 deletions x-pack/plugins/siem/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,3 @@ import { PluginSetup, PluginStart } from './types';
export const plugin = (context: PluginInitializerContext): Plugin => new Plugin(context);

export { Plugin, PluginSetup, PluginStart };

export { ConfigureEndpointDatasource } from './management/pages/policy/view/ingest_manager_integration/configure_datasource';
2 changes: 2 additions & 0 deletions x-pack/plugins/siem/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { KibanaServices } from './common/lib/kibana/services';
import { serviceNowActionType, jiraActionType } from './common/lib/connectors';
import { PluginSetup, PluginStart, SetupPlugins, StartPlugins, StartServices } from './types';
import { APP_ID, APP_NAME, APP_ICON, APP_PATH } from '../common/constants';
import { ConfigureEndpointDatasource } from './management/pages/policy/view/ingest_manager_integration/configure_datasource';

export class Plugin implements IPlugin<PluginSetup, PluginStart, SetupPlugins, StartPlugins> {
private kibanaVersion: string;
Expand Down Expand Up @@ -131,6 +132,7 @@ export class Plugin implements IPlugin<PluginSetup, PluginStart, SetupPlugins, S

public start(core: CoreStart, plugins: StartPlugins) {
KibanaServices.init({ ...core, ...plugins, kibanaVersion: this.kibanaVersion });
plugins.ingestManager.registerDatasource('endpoint', ConfigureEndpointDatasource);

return {};
}
Expand Down

0 comments on commit ac2441d

Please sign in to comment.