Skip to content

Commit

Permalink
Merge branch 'master' of github.com:elastic/kibana into manifest-fixe…
Browse files Browse the repository at this point in the history
…s-7.9
  • Loading branch information
madirey committed Jul 28, 2020
2 parents 52f59d2 + 2ea2f10 commit 722b425
Show file tree
Hide file tree
Showing 19 changed files with 347 additions and 263 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@
"jest-cli": "^25.5.4",
"jest-environment-jsdom-thirteen": "^1.0.1",
"jest-raw-loader": "^1.0.1",
"jimp": "^0.9.6",
"jimp": "^0.14.0",
"json5": "^1.0.1",
"license-checker": "^16.0.0",
"listr": "^0.14.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ export class DashboardAppController {
chrome.docTitle.change(dash.title);
}

const incomingEmbeddable = embeddable
.getStateTransfer(scopedHistory())
.getIncomingEmbeddablePackage();

const dashboardStateManager = new DashboardStateManager({
savedDashboard: dash,
hideWriteControls: dashboardConfig.getHideWriteControls(),
Expand Down Expand Up @@ -444,21 +448,24 @@ export class DashboardAppController {
refreshDashboardContainer();
});

const incomingState = embeddable
.getStateTransfer(scopedHistory())
.getIncomingEmbeddablePackage();
if (incomingState) {
if ('id' in incomingState) {
container.addOrUpdateEmbeddable<SavedObjectEmbeddableInput>(incomingState.type, {
savedObjectId: incomingState.id,
});
} else if ('input' in incomingState) {
const input = incomingState.input;
if (incomingEmbeddable) {
if ('id' in incomingEmbeddable) {
container.addOrUpdateEmbeddable<SavedObjectEmbeddableInput>(
incomingEmbeddable.type,
{
savedObjectId: incomingEmbeddable.id,
}
);
} else if ('input' in incomingEmbeddable) {
const input = incomingEmbeddable.input;
delete input.id;
const explicitInput = {
savedVis: input,
};
container.addOrUpdateEmbeddable<EmbeddableInput>(incomingState.type, explicitInput);
container.addOrUpdateEmbeddable<EmbeddableInput>(
incomingEmbeddable.type,
explicitInput
);
}
}
}
Expand Down
6 changes: 1 addition & 5 deletions x-pack/plugins/canvas/public/state/reducers/workpad.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ export const workpadReducer = handleActions(
[setName]: (workpadState, { payload }) => {
platformService
.getService()
.coreStart.chrome.recentlyAccessed.add(
`${APP_ROUTE_WORKPAD}/${workpadState.id}`,
payload,
workpadState.id
);
.setRecentlyAccessed(`${APP_ROUTE_WORKPAD}/${workpadState.id}`, payload, workpadState.id);
return { ...workpadState, name: payload };
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const AgentDetailsActionMenu: React.FunctionComponent<{
onClick={() => {
setIsReassignFlyoutOpen(true);
}}
disabled={!agent.active}
key="reassignConfig"
>
<FormattedMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,18 @@ const RowActions = React.memo<{ agent: Agent; onReassignClick: () => void; refre
onClick={() => {
onReassignClick();
}}
disabled={!agent.active}
key="reassignConfig"
>
<FormattedMessage
id="xpack.ingestManager.agentList.reassignActionText"
defaultMessage="Assign new agent config"
/>
</EuiContextMenuItem>,

<AgentUnenrollProvider forceUnenroll={isUnenrolling}>
{(unenrollAgentsPrompt) => (
<EuiContextMenuItem
disabled={!hasWriteCapabilites}
disabled={!hasWriteCapabilites || !agent.active}
icon="cross"
onClick={() => {
unenrollAgentsPrompt([agent.id], 1, () => {
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/ingest_manager/server/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const createAppContextStartContractMock = (): IngestManagerAppContext =>
logger: loggingSystemMock.create().get(),
isProductionMode: true,
kibanaVersion: '8.0.0',
kibanaBranch: 'master',
};
};

Expand Down
5 changes: 5 additions & 0 deletions x-pack/plugins/ingest_manager/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
HttpServiceSetup,
} from 'kibana/server';
import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
import packageJSON from '../../../../package.json';
import { LicensingPluginSetup, ILicense } from '../../licensing/server';
import {
EncryptedSavedObjectsPluginStart,
Expand Down Expand Up @@ -85,6 +86,7 @@ export interface IngestManagerAppContext {
savedObjects: SavedObjectsServiceStart;
isProductionMode: boolean;
kibanaVersion: string;
kibanaBranch: string;
cloud?: CloudSetup;
logger?: Logger;
httpSetup?: HttpServiceSetup;
Expand Down Expand Up @@ -145,13 +147,15 @@ export class IngestManagerPlugin

private isProductionMode: boolean;
private kibanaVersion: string;
private kibanaBranch: string;
private httpSetup: HttpServiceSetup | undefined;
private encryptedSavedObjectsSetup: EncryptedSavedObjectsPluginSetup | undefined;

constructor(private readonly initializerContext: PluginInitializerContext) {
this.config$ = this.initializerContext.config.create<IngestManagerConfigType>();
this.isProductionMode = this.initializerContext.env.mode.prod;
this.kibanaVersion = this.initializerContext.env.packageInfo.version;
this.kibanaBranch = packageJSON.branch;
this.logger = this.initializerContext.logger.get();
}

Expand Down Expand Up @@ -257,6 +261,7 @@ export class IngestManagerPlugin
savedObjects: core.savedObjects,
isProductionMode: this.isProductionMode,
kibanaVersion: this.kibanaVersion,
kibanaBranch: this.kibanaBranch,
httpSetup: this.httpSetup,
cloud: this.cloud,
logger: this.logger,
Expand Down
9 changes: 9 additions & 0 deletions x-pack/plugins/ingest_manager/server/services/app_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class AppContextService {
private savedObjects: SavedObjectsServiceStart | undefined;
private isProductionMode: boolean = false;
private kibanaVersion: string | undefined;
private kibanaBranch: string | undefined;
private cloud?: CloudSetup;
private logger: Logger | undefined;
private httpSetup?: HttpServiceSetup;
Expand All @@ -38,6 +39,7 @@ class AppContextService {
this.cloud = appContext.cloud;
this.logger = appContext.logger;
this.kibanaVersion = appContext.kibanaVersion;
this.kibanaBranch = appContext.kibanaBranch;
this.httpSetup = appContext.httpSetup;

if (appContext.config$) {
Expand Down Expand Up @@ -125,6 +127,13 @@ class AppContextService {
return this.kibanaVersion;
}

public getKibanaBranch() {
if (!this.kibanaBranch) {
throw new Error('Kibana branch is not set.');
}
return this.kibanaBranch;
}

public addExternalCallback(type: ExternalCallback[0], callback: ExternalCallback[1]) {
if (!this.externalCallbacks.has(type)) {
this.externalCallbacks.set(type, new Set());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export const pkgToPkgKey = ({ name, version }: { name: string; version: string }
export async function fetchList(params?: SearchParams): Promise<RegistrySearchResults> {
const registryUrl = getRegistryUrl();
const url = new URL(`${registryUrl}/search`);
const kibanaVersion = appContextService.getKibanaVersion().split('-')[0]; // may be x.y.z-SNAPSHOT
const kibanaBranch = appContextService.getKibanaBranch();
if (params) {
if (params.category) {
url.searchParams.set('category', params.category);
Expand All @@ -48,8 +50,9 @@ export async function fetchList(params?: SearchParams): Promise<RegistrySearchRe
url.searchParams.set('experimental', params.experimental.toString());
}
}
const kibanaVersion = appContextService.getKibanaVersion().split('-')[0]; // may be 8.0.0-SNAPSHOT
if (kibanaVersion) {

// on master, request all packages regardless of version
if (kibanaVersion && kibanaBranch !== 'master') {
url.searchParams.set('kibana.version', kibanaVersion);
}

Expand All @@ -58,11 +61,14 @@ export async function fetchList(params?: SearchParams): Promise<RegistrySearchRe

export async function fetchFindLatestPackage(packageName: string): Promise<RegistrySearchResult> {
const registryUrl = getRegistryUrl();
const kibanaVersion = appContextService.getKibanaVersion().split('-')[0]; // may be x.y.z-SNAPSHOT
const kibanaBranch = appContextService.getKibanaBranch();
const url = new URL(
`${registryUrl}/search?package=${packageName}&internal=true&experimental=true`
);
const kibanaVersion = appContextService.getKibanaVersion().split('-')[0]; // may be 8.0.0-SNAPSHOT
if (kibanaVersion) {

// on master, request all packages regardless of version
if (kibanaVersion && kibanaBranch !== 'master') {
url.searchParams.set('kibana.version', kibanaVersion);
}
const res = await fetchUrl(url.toString());
Expand Down
14 changes: 13 additions & 1 deletion x-pack/plugins/lists/common/schemas/types/entries.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,22 @@ import { getEntryListMock } from './entry_list.mock';
import { getEntryExistsMock } from './entry_exists.mock';
import { getEntryNestedMock } from './entry_nested.mock';

export const getEntriesArrayMock = (): EntriesArray => [
export const getListAndNonListEntriesArrayMock = (): EntriesArray => [
{ ...getEntryMatchMock() },
{ ...getEntryMatchAnyMock() },
{ ...getEntryListMock() },
{ ...getEntryExistsMock() },
{ ...getEntryNestedMock() },
];

export const getListEntriesArrayMock = (): EntriesArray => [
{ ...getEntryListMock() },
{ ...getEntryListMock() },
];

export const getEntriesArrayMock = (): EntriesArray => [
{ ...getEntryMatchMock() },
{ ...getEntryMatchAnyMock() },
{ ...getEntryExistsMock() },
{ ...getEntryNestedMock() },
];
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ import { foldLeftRight, getPaths } from '../../siem_common_deps';

import { getEntryMatchMock } from './entry_match.mock';
import { getEntryMatchAnyMock } from './entry_match_any.mock';
import { getEntryListMock } from './entry_list.mock';
import { getEntryExistsMock } from './entry_exists.mock';
import { getEntryNestedMock } from './entry_nested.mock';
import { getEntriesArrayMock } from './entries.mock';
import {
getEntriesArrayMock,
getListAndNonListEntriesArrayMock,
getListEntriesArrayMock,
} from './entries.mock';
import { nonEmptyEntriesArray } from './non_empty_entries_array';
import { EntriesArray } from './entries';

Expand Down Expand Up @@ -80,7 +83,7 @@ describe('non_empty_entries_array', () => {
});

test('it should validate an array of "list" entries', () => {
const payload: EntriesArray = [{ ...getEntryListMock() }, { ...getEntryListMock() }];
const payload: EntriesArray = [...getListEntriesArrayMock()];
const decoded = nonEmptyEntriesArray.decode(payload);
const message = pipe(decoded, foldLeftRight);

Expand All @@ -106,6 +109,15 @@ describe('non_empty_entries_array', () => {
expect(message.schema).toEqual(payload);
});

test('it should NOT validate an array of entries of value list and non-value list entries', () => {
const payload: EntriesArray = [...getListAndNonListEntriesArrayMock()];
const decoded = nonEmptyEntriesArray.decode(payload);
const message = pipe(decoded, foldLeftRight);

expect(getPaths(left(message.errors))).toEqual(['Cannot have entry of type list and other']);
expect(message.schema).toEqual({});
});

test('it should NOT validate an array of non entries', () => {
const payload = [1];
const decoded = nonEmptyEntriesArray.decode(payload);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as t from 'io-ts';
import { Either } from 'fp-ts/lib/Either';

import { EntriesArray, entriesArray } from './entries';
import { entriesList } from './entry_list';

/**
* Types the nonEmptyEntriesArray as:
Expand All @@ -21,6 +22,14 @@ export const nonEmptyEntriesArray = new t.Type<EntriesArray, EntriesArray, unkno
if (Array.isArray(input) && input.length === 0) {
return t.failure(input, context);
} else {
if (
Array.isArray(input) &&
input.some((entry) => entriesList.is(entry)) &&
input.some((entry) => !entriesList.is(entry))
) {
// fail when an exception item contains both a value list entry and a non-value list entry
return t.failure(input, context, 'Cannot have entry of type list and other');
}
return entriesArray.validate(input, context);
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,6 @@ describe('Exception viewer helpers', () => {
operator: 'is one of',
value: ['some host name'],
},
{
fieldName: 'host.name',
isNested: false,
operator: 'is in list',
value: 'some-list-id',
},
{
fieldName: 'host.name',
isNested: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { NOTIFICATION_THROTTLE_NO_ACTIONS } from '../../../../../../common/const
import { transformAlertToRuleAction } from '../../../../../../common/detection_engine/transform_actions';
import { RuleType } from '../../../../../../common/detection_engine/types';
import { isMlRule } from '../../../../../../common/machine_learning/helpers';
import { isThresholdRule } from '../../../../../../common/detection_engine/utils';
import { List } from '../../../../../../common/detection_engine/schemas/types';
import { ENDPOINT_LIST_ID } from '../../../../../shared_imports';
import { NewRule, Rule } from '../../../../containers/detection_engine/rules';
Expand Down Expand Up @@ -57,7 +58,7 @@ export interface RuleFields {
}
type QueryRuleFields<T> = Omit<T, 'anomalyThreshold' | 'machineLearningJobId' | 'threshold'>;
type ThresholdRuleFields<T> = Omit<T, 'anomalyThreshold' | 'machineLearningJobId'>;
type MlRuleFields<T> = Omit<T, 'queryBar' | 'index'>;
type MlRuleFields<T> = Omit<T, 'queryBar' | 'index' | 'threshold'>;

const isMlFields = <T>(
fields: QueryRuleFields<T> | MlRuleFields<T> | ThresholdRuleFields<T>
Expand All @@ -69,9 +70,9 @@ const isThresholdFields = <T>(

export const filterRuleFieldsForType = <T extends RuleFields>(fields: T, type: RuleType) => {
if (isMlRule(type)) {
const { index, queryBar, ...mlRuleFields } = fields;
const { index, queryBar, threshold, ...mlRuleFields } = fields;
return mlRuleFields;
} else if (type === 'threshold') {
} else if (isThresholdRule(type)) {
const { anomalyThreshold, machineLearningJobId, ...thresholdRuleFields } = fields;
return thresholdRuleFields;
} else {
Expand Down
Loading

0 comments on commit 722b425

Please sign in to comment.