Skip to content

Commit

Permalink
Merge branch 'master' into issue-xxx-np-management
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Jan 18, 2020
2 parents e9cb504 + 2598d15 commit 28aff3b
Show file tree
Hide file tree
Showing 60 changed files with 689 additions and 477 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/pr-project-assigner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ jobs:
[
{ "label": "Team:AppArch", "projectName": "kibana-app-arch", "columnId": 6173897 },
{ "label": "Feature:Lens", "projectName": "Lens", "columnId": 6219362 },
{ "label": "Team:Platform", "projectName": "kibana-platform", "columnId": 5514360 },
{"label": "Team:Canvas", "projectName": "canvas", "columnId": 6187580}
{ "label": "Team:Canvas", "projectName": "canvas", "columnId": 6187580 }
]
ghToken: ${{ secrets.GITHUB_TOKEN }}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<kbn-management-app>
<div id="management-landing"></div>
<div id="management-landing" data-test-subj="management-landing"></div>
</kbn-management-app>
7 changes: 6 additions & 1 deletion src/plugins/management/public/management_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class ManagementApp {
readonly basePath: string;
readonly order: number;
readonly mount: ManagementSectionMount;
protected enabledStatus: boolean = true;
private enabledStatus = true;

constructor(
{ id, title, basePath, order = 100, mount }: CreateManagementApp,
Expand All @@ -54,6 +54,11 @@ export class ManagementApp {
title,
mount: async ({}, params) => {
let appUnmount: Unmount;
if (!this.enabledStatus) {
const [coreStart] = await getStartServices();
coreStart.application.navigateToApp('kibana#/management');
return () => {};
}
async function setBreadcrumbs(crumbs: ChromeBreadcrumb[]) {
const [coreStart] = await getStartServices();
coreStart.chrome.setBreadcrumbs([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@ export class ManagementTestPlugin
};
},
});

testSection!
.registerApp({
id: 'test-management-disabled',
title: 'Management Test Disabled',
mount(params) {
params.setBreadcrumbs([{ text: 'Management Test Disabled' }]);
ReactDOM.render(<div>This is a secret that should never be seen!</div>, params.element);

return () => {
ReactDOM.unmountComponentAtNode(params.element);
};
},
})
.disable();

return {};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,13 @@ export default function({ getService, getPageObjects }) {
await testSubjects.click('test-management-link-basepath');
await testSubjects.existOrFail('test-management-link-one');
});

it('should redirect when app is disabled', async () => {
await PageObjects.common.navigateToActualUrl(
'kibana',
'management/test-section/test-management-disabled'
);
await testSubjects.existOrFail('management-landing');
});
});
}
78 changes: 13 additions & 65 deletions x-pack/legacy/plugins/reporting/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,20 @@
import { resolve } from 'path';
import { i18n } from '@kbn/i18n';
import { Legacy } from 'kibana';
import { IUiSettingsClient } from 'src/core/server';
import { XPackMainPlugin } from '../xpack_main/server/xpack_main';
import { PLUGIN_ID, UI_SETTINGS_CUSTOM_PDF_LOGO } from './common/constants';
// @ts-ignore untyped module defintition
import { mirrorPluginStatus } from '../../server/lib/mirror_plugin_status';
import { registerRoutes } from './server/routes';
import {
LevelLogger,
checkLicenseFactory,
getExportTypesRegistry,
runValidations,
} from './server/lib';
import { createBrowserDriverFactory } from './server/browsers';
import { registerReportingUsageCollector } from './server/usage';
import { ReportingConfigOptions, ReportingPluginSpecOptions } from './types.d';
import { config as reportingConfig } from './config';
import { logConfiguration } from './log_configuration';
import {
LegacySetup,
ReportingPlugin,
ReportingSetupDeps,
reportingPluginFactory,
} from './server/plugin';

const kbToBase64Length = (kb: number) => {
return Math.floor((kb * 1024 * 8) / 6);
};

type LegacyPlugins = Legacy.Server['plugins'];

export interface ServerFacade {
config: Legacy.Server['config'];
info: Legacy.Server['info'];
log: Legacy.Server['log'];
plugins: {
elasticsearch: LegacyPlugins['elasticsearch'];
security: LegacyPlugins['security'];
xpack_main: XPackMainPlugin & {
status?: any;
};
};
route: Legacy.Server['route'];
savedObjects: Legacy.Server['savedObjects'];
uiSettingsServiceFactory: Legacy.Server['uiSettingsServiceFactory'];
fieldFormatServiceFactory: (uiConfig: IUiSettingsClient) => unknown;
}

export const reporting = (kibana: any) => {
return new kibana.Plugin({
id: PLUGIN_ID,
Expand Down Expand Up @@ -93,7 +66,11 @@ export const reporting = (kibana: any) => {
},

async init(server: Legacy.Server) {
const serverFacade: ServerFacade = {
const coreSetup = server.newPlatform.setup.core;
const pluginsSetup: ReportingSetupDeps = {
usageCollection: server.newPlatform.setup.plugins.usageCollection,
};
const __LEGACY: LegacySetup = {
config: server.config,
info: server.info,
route: server.route.bind(server),
Expand All @@ -108,38 +85,9 @@ export const reporting = (kibana: any) => {
fieldFormatServiceFactory: server.fieldFormatServiceFactory,
log: server.log.bind(server),
};
const exportTypesRegistry = getExportTypesRegistry();

let isCollectorReady = false;
// Register a function with server to manage the collection of usage stats
const { usageCollection } = server.newPlatform.setup.plugins;
registerReportingUsageCollector(
usageCollection,
serverFacade,
() => isCollectorReady,
exportTypesRegistry
);

const logger = LevelLogger.createForServer(serverFacade, [PLUGIN_ID]);
const browserDriverFactory = await createBrowserDriverFactory(serverFacade);

logConfiguration(serverFacade, logger);
runValidations(serverFacade, logger, browserDriverFactory);

const { xpack_main: xpackMainPlugin } = serverFacade.plugins;
mirrorPluginStatus(xpackMainPlugin, this);
const checkLicense = checkLicenseFactory(exportTypesRegistry);
(xpackMainPlugin as any).status.once('green', () => {
// Register a function that is called whenever the xpack info changes,
// to re-compute the license check results for this plugin
xpackMainPlugin.info.feature(this.id).registerLicenseCheckResultsGenerator(checkLicense);
});

// Post initialization of the above code, the collector is now ready to fetch its data
isCollectorReady = true;

// Reporting routes
registerRoutes(serverFacade, exportTypesRegistry, browserDriverFactory, logger);
const plugin: ReportingPlugin = reportingPluginFactory(__LEGACY, this);
await plugin.setup(coreSetup, pluginsSetup);
},

deprecations({ unused }: any) {
Expand Down
107 changes: 107 additions & 0 deletions x-pack/legacy/plugins/reporting/server/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { Legacy } from 'kibana';
import { CoreSetup, CoreStart, Plugin } from 'src/core/server';
import { IUiSettingsClient } from 'src/core/server';
import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
import { XPackMainPlugin } from '../../xpack_main/server/xpack_main';
// @ts-ignore
import { mirrorPluginStatus } from '../../../server/lib/mirror_plugin_status';
import { PLUGIN_ID } from '../common/constants';
import { ReportingPluginSpecOptions } from '../types.d';
import { registerRoutes } from './routes';
import { LevelLogger, checkLicenseFactory, getExportTypesRegistry, runValidations } from './lib';
import { createBrowserDriverFactory } from './browsers';
import { registerReportingUsageCollector } from './usage';
import { logConfiguration } from '../log_configuration';

// For now there is no exposed functionality to other plugins
export type ReportingSetup = object;
export type ReportingStart = object;

export interface ReportingSetupDeps {
usageCollection: UsageCollectionSetup;
}
export type ReportingStartDeps = object;

type LegacyPlugins = Legacy.Server['plugins'];

export interface LegacySetup {
config: Legacy.Server['config'];
info: Legacy.Server['info'];
log: Legacy.Server['log'];
plugins: {
elasticsearch: LegacyPlugins['elasticsearch'];
security: LegacyPlugins['security'];
xpack_main: XPackMainPlugin & {
status?: any;
};
};
route: Legacy.Server['route'];
savedObjects: Legacy.Server['savedObjects'];
uiSettingsServiceFactory: Legacy.Server['uiSettingsServiceFactory'];
fieldFormatServiceFactory: (uiConfig: IUiSettingsClient) => unknown;
}

export type ReportingPlugin = Plugin<
ReportingSetup,
ReportingStart,
ReportingSetupDeps,
ReportingStartDeps
>;

/* We need a factory that returns an instance of the class because the class
* implementation itself restricts against having Legacy dependencies passed
* into `setup`. The factory parameters take the legacy dependencies, and the
* `setup` method gets it from enclosure */
export function reportingPluginFactory(
__LEGACY: LegacySetup,
legacyPlugin: ReportingPluginSpecOptions
) {
return new (class ReportingPlugin implements ReportingPlugin {
public async setup(core: CoreSetup, plugins: ReportingSetupDeps): Promise<ReportingSetup> {
const exportTypesRegistry = getExportTypesRegistry();

let isCollectorReady = false;
// Register a function with server to manage the collection of usage stats
const { usageCollection } = plugins;
registerReportingUsageCollector(
usageCollection,
__LEGACY,
() => isCollectorReady,
exportTypesRegistry
);

const logger = LevelLogger.createForServer(__LEGACY, [PLUGIN_ID]);
const browserDriverFactory = await createBrowserDriverFactory(__LEGACY);

logConfiguration(__LEGACY, logger);
runValidations(__LEGACY, logger, browserDriverFactory);

const { xpack_main: xpackMainPlugin } = __LEGACY.plugins;
mirrorPluginStatus(xpackMainPlugin, legacyPlugin);
const checkLicense = checkLicenseFactory(exportTypesRegistry);
(xpackMainPlugin as any).status.once('green', () => {
// Register a function that is called whenever the xpack info changes,
// to re-compute the license check results for this plugin
xpackMainPlugin.info.feature(PLUGIN_ID).registerLicenseCheckResultsGenerator(checkLicense);
});

// Post initialization of the above code, the collector is now ready to fetch its data
isCollectorReady = true;

// Reporting routes
registerRoutes(__LEGACY, exportTypesRegistry, browserDriverFactory, logger);

return {};
}

public start(core: CoreStart, plugins: ReportingStartDeps): ReportingStart {
return {};
}
})();
}
6 changes: 3 additions & 3 deletions x-pack/legacy/plugins/reporting/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { CancellationToken } from './common/cancellation_token';
import { LevelLogger } from './server/lib/level_logger';
import { HeadlessChromiumDriverFactory } from './server/browsers/chromium/driver_factory';
import { BrowserType } from './server/browsers/types';
import { ServerFacade } from './index';
import { LegacySetup } from './server/plugin';

export type ReportingPlugin = object; // For Plugin contract

Expand Down Expand Up @@ -69,6 +69,8 @@ interface GenerateExportTypePayload {
* Legacy System
*/

export type ServerFacade = LegacySetup;

export type ReportingPluginSpecOptions = Legacy.PluginSpecOptions;

export type EnqueueJobFn = <JobParamsType>(
Expand Down Expand Up @@ -353,5 +355,3 @@ export interface InterceptedRequest {
frameId: string;
resourceType: string;
}

export { ServerFacade };
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import { MatrixHistogramGqlQuery } from '../../containers/matrix_histogram/index
const ID = 'alertsOverTimeQuery';
export const alertsStackByOptions: MatrixHistogramOption[] = [
{
text: i18n.CATEGORY,
text: 'event.category',
value: 'event.category',
},
{
text: i18n.MODULE,
text: 'event.module',
value: 'event.module',
},
];
Expand Down Expand Up @@ -54,7 +54,6 @@ export const AlertsView = ({
<>
<MatrixHistogramContainer
dataKey={dataKey}
deleteQuery={deleteQuery}
defaultStackByOption={alertsStackByOptions[1]}
endDate={endDate}
errorMessage={i18n.ERROR_FETCHING_ALERTS_DATA}
Expand All @@ -68,7 +67,7 @@ export const AlertsView = ({
stackByOptions={alertsStackByOptions}
startDate={startDate}
subtitle={getSubtitle}
title={i18n.ALERTS_DOCUMENT_TYPE}
title={i18n.ALERTS_GRAPH_TITLE}
type={type}
updateDateRange={updateDateRange}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ export const TOTAL_COUNT_OF_ALERTS = i18n.translate('xpack.siem.alertsView.total
defaultMessage: 'alerts match the search criteria',
});

export const ALERTS_TABLE_TITLE = i18n.translate('xpack.siem.alertsView.alertsDocumentType', {
export const ALERTS_TABLE_TITLE = i18n.translate('xpack.siem.alertsView.alertsTableTitle', {
defaultMessage: 'Alerts',
});

export const ALERTS_GRAPH_TITLE = i18n.translate('xpack.siem.alertsView.alertsGraphTitle', {
defaultMessage: 'Alert detection frequency',
});

export const ALERTS_STACK_BY_MODULE = i18n.translate(
'xpack.siem.alertsView.alertsStackByOptions.module',
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { RedirectToHostsPage, RedirectToHostDetailsPage } from './redirect_to_ho
import { RedirectToNetworkPage } from './redirect_to_network';
import { RedirectToOverviewPage } from './redirect_to_overview';
import { RedirectToTimelinesPage } from './redirect_to_timelines';
import { DetectionEngineTab } from '../../pages/detection_engine/types';

interface LinkToPageProps {
match: RouteMatch<{}>;
Expand Down Expand Up @@ -63,6 +64,12 @@ export const LinkToPage = React.memo<LinkToPageProps>(({ match }) => (
path={`${match.url}/:pageName(${SiemPageName.detectionEngine})`}
strict
/>
<Route
component={RedirectToDetectionEnginePage}
exact
path={`${match.url}/:pageName(${SiemPageName.detectionEngine})/:tabName(${DetectionEngineTab.alerts}|${DetectionEngineTab.signals})`}
strict
/>
<Route
component={RedirectToRulesPage}
exact
Expand Down
Loading

0 comments on commit 28aff3b

Please sign in to comment.