Skip to content

Commit

Permalink
Merge branch 'master' into top_terms_filter
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine committed Apr 3, 2020
2 parents f139024 + 020e573 commit ffa3c32
Show file tree
Hide file tree
Showing 36 changed files with 825 additions and 330 deletions.
102 changes: 0 additions & 102 deletions src/plugins/advanced_settings/public/management_app/index.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* 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 React from 'react';
import ReactDOM from 'react-dom';
import { HashRouter, Switch, Route } from 'react-router-dom';

import { i18n } from '@kbn/i18n';
import { I18nProvider } from '@kbn/i18n/react';
import { StartServicesAccessor } from 'src/core/public';

import { AdvancedSettings } from './advanced_settings';
import { ManagementAppMountParams } from '../../../management/public';
import { ComponentRegistry } from '../types';

const title = i18n.translate('advancedSettings.advancedSettingsLabel', {
defaultMessage: 'Advanced Settings',
});
const crumb = [{ text: title }];

const readOnlyBadge = {
text: i18n.translate('advancedSettings.badge.readOnly.text', {
defaultMessage: 'Read only',
}),
tooltip: i18n.translate('advancedSettings.badge.readOnly.tooltip', {
defaultMessage: 'Unable to save advanced settings',
}),
iconType: 'glasses',
};

export async function mountManagementSection(
getStartServices: StartServicesAccessor,
params: ManagementAppMountParams,
componentRegistry: ComponentRegistry['start']
) {
params.setBreadcrumbs(crumb);
const [{ uiSettings, notifications, docLinks, application, chrome }] = await getStartServices();

const canSave = application.capabilities.advancedSettings.save as boolean;

if (!canSave) {
chrome.setBadge(readOnlyBadge);
}

ReactDOM.render(
<I18nProvider>
<HashRouter basename={params.basePath}>
<Switch>
<Route path={['/:query', '/']}>
<AdvancedSettings
enableSaving={canSave}
toasts={notifications.toasts}
dockLinks={docLinks.links}
uiSettings={uiSettings}
componentRegistry={componentRegistry}
/>
</Route>
</Switch>
</HashRouter>
</I18nProvider>,
params.element
);
return () => {
ReactDOM.unmountComponentAtNode(params.element);
};
}
32 changes: 26 additions & 6 deletions src/plugins/advanced_settings/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,37 @@
* specific language governing permissions and limitations
* under the License.
*/

import { i18n } from '@kbn/i18n';
import { CoreSetup, CoreStart, Plugin } from 'kibana/public';
import { ManagementApp } from '../../management/public';
import { ComponentRegistry } from './component_registry';
import { AdvancedSettingsSetup, AdvancedSettingsStart, AdvancedSettingsPluginSetup } from './types';
import { registerAdvSettingsMgmntApp } from './management_app';

const component = new ComponentRegistry();

const title = i18n.translate('advancedSettings.advancedSettingsLabel', {
defaultMessage: 'Advanced Settings',
});

export class AdvancedSettingsPlugin
implements Plugin<AdvancedSettingsSetup, AdvancedSettingsStart, AdvancedSettingsPluginSetup> {
private managementApp?: ManagementApp;
public setup(core: CoreSetup, { management }: AdvancedSettingsPluginSetup) {
registerAdvSettingsMgmntApp({
management,
getStartServices: core.getStartServices,
componentRegistry: component.start,
const kibanaSection = management.sections.getSection('kibana');
if (!kibanaSection) {
throw new Error('`kibana` management section not found.');
}

this.managementApp = kibanaSection.registerApp({
id: 'settings',
title,
order: 20,
async mount(params) {
const { mountManagementSection } = await import(
'./management_app/mount_management_section'
);
return mountManagementSection(core.getStartServices, params, component.start);
},
});

return {
Expand All @@ -39,6 +55,10 @@ export class AdvancedSettingsPlugin
}

public start(core: CoreStart) {
if (!core.application.capabilities.management.kibana.settings) {
this.managementApp!.disable();
}

return {
component: component.start,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ describe('parseInterval', () => {
validateDuration(parseInterval('5m'), 'm', 5);
});

test('should correctly parse 500m interval', () => {
validateDuration(parseInterval('500m'), 'm', 500);
});

test('should correctly parse 250ms interval', () => {
validateDuration(parseInterval('250ms'), 'ms', 250);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ export function parseInterval(interval: string): moment.Duration | null {
u => Math.abs(duration.as(u)) >= 1
) as unitOfTime.Base;

// however if we do this fhe other way around it will also fail
// go from 500m to hours as this will result in infinite number (dividing 500/60 = 8.3*)
// so we can only do this if we are changing to smaller units
if (dateMath.units.indexOf(selectedUnit as any) < dateMath.units.indexOf(unit as any)) {
return duration;
}

return moment.duration(duration.as(selectedUnit), selectedUnit);
} catch (e) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,6 @@
* under the License.
*/

/*
* 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 { ValidationFunc } from '../../hook_form_lib';
import { isJSON } from '../../../validators/string';
import { ERROR_CODE } from './types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,23 @@ describe('buildRuleMessageFactory', () => {
expect(message).toEqual(expect.stringContaining('signals index: "index"'));
});

it('joins message parts with newlines', () => {
it('joins message parts with spaces', () => {
const buildMessage = buildRuleMessageFactory(factoryParams);

const message = buildMessage('my message');
const messageParts = message.split('\n');
expect(messageParts).toContain('my message');
expect(messageParts).toContain('name: "name"');
expect(messageParts).toContain('id: "id"');
expect(messageParts).toContain('rule id: "ruleId"');
expect(messageParts).toContain('signals index: "index"');
expect(message).toEqual(expect.stringContaining('my message '));
expect(message).toEqual(expect.stringContaining(' name: "name" '));
expect(message).toEqual(expect.stringContaining(' id: "id" '));
expect(message).toEqual(expect.stringContaining(' rule id: "ruleId" '));
expect(message).toEqual(expect.stringContaining(' signals index: "index"'));
});

it('joins multiple arguments with newlines', () => {
it('joins multiple arguments with spaces', () => {
const buildMessage = buildRuleMessageFactory(factoryParams);

const message = buildMessage('my message', 'here is more');
const messageParts = message.split('\n');
expect(messageParts).toContain('my message');
expect(messageParts).toContain('here is more');
expect(message).toEqual(expect.stringContaining('my message '));
expect(message).toEqual(expect.stringContaining(' here is more'));
});

it('defaults the rule ID if not provided ', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ export const buildRuleMessageFactory = ({
`id: "${id}"`,
`rule id: "${ruleId ?? '(unknown rule id)'}"`,
`signals index: "${index}"`,
].join('\n');
].join(' ');
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const signalRulesAlertType = ({
'Machine learning rule is missing job id and/or anomaly threshold:',
`job id: "${machineLearningJobId}"`,
`anomaly threshold: "${anomalyThreshold}"`,
].join('\n')
].join(' ')
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export const saveNotes = (
existingNoteIds?: string[],
newNotes?: NoteResult[]
) => {
return (
return Promise.all(
newNotes?.map(note => {
const newNote: SavedNote = {
eventId: note.eventId,
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 { PolicyConfig } from '../types';
import { PolicyConfig, ProtectionModes } from '../types';

/**
* Generate a new Policy model.
Expand All @@ -19,7 +19,7 @@ export const generatePolicy = (): PolicyConfig => {
network: true,
},
malware: {
mode: 'prevent',
mode: ProtectionModes.prevent,
},
logging: {
stdout: 'debug',
Expand All @@ -44,7 +44,7 @@ export const generatePolicy = (): PolicyConfig => {
process: true,
},
malware: {
mode: 'detect',
mode: ProtectionModes.detect,
},
logging: {
stdout: 'debug',
Expand Down
Loading

0 comments on commit ffa3c32

Please sign in to comment.