Skip to content

Commit

Permalink
Remove dead legacy signals code
Browse files Browse the repository at this point in the history
  • Loading branch information
marshallmain committed Mar 23, 2022
1 parent 461415b commit 25f07aa
Show file tree
Hide file tree
Showing 23 changed files with 539 additions and 1,776 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { alertsMock } from '../../../alerting/server/mocks';
import { PersistenceServices } from './persistence_types';

export const createPersistenceServicesMock = (): jest.Mocked<PersistenceServices> => {
return {
alertWithPersistence: jest.fn(),
};
};

export const createPersistenceExecutorOptionsMock = () => {
return {
...alertsMock.createAlertServices(),
...createPersistenceServicesMock(),
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import { isEmpty } from 'lodash';

import { parseScheduleDates } from '@kbn/securitysolution-io-ts-utils';
import { ListArray } from '@kbn/securitysolution-io-ts-list-types';
import agent from 'elastic-apm-node';

import { createPersistenceRuleTypeWrapper } from '../../../../../rule_registry/server';
Expand All @@ -19,11 +18,7 @@ import {
getRuleRangeTuples,
hasReadIndexPrivileges,
hasTimestampFields,
isEqlParams,
isQueryParams,
isSavedQueryParams,
isThreatParams,
isThresholdParams,
isMachineLearningParams,
} from '../signals/utils';
import { DEFAULT_MAX_SIGNALS, DEFAULT_SEARCH_AFTER_PAGE_SIZE } from '../../../../common/constants';
import { CreateSecurityRuleTypeWrapper } from './types';
Expand Down Expand Up @@ -132,22 +127,13 @@ export const createSecurityRuleTypeWrapper: CreateSecurityRuleTypeWrapper =
...params,
name,
id: alertId,
} as unknown as NotificationRuleTypeParams;
};

// check if rule has permissions to access given index pattern
// move this collection of lines into a function in utils
// so that we can use it in create rules route, bulk, etc.
try {
// Typescript 4.1.3 can't figure out that `!isMachineLearningParams(params)` also excludes the only rule type
// of rule params that doesn't include `params.index`, but Typescript 4.3.5 does compute the stricter type correctly.
// When we update Typescript to >= 4.3.5, we can replace this logic with `!isMachineLearningParams(params)` again.
if (
isEqlParams(params) ||
isThresholdParams(params) ||
isQueryParams(params) ||
isSavedQueryParams(params) ||
isThreatParams(params)
) {
if (!isMachineLearningParams(params)) {
const index = params.index;
const hasTimestampOverride = !!timestampOverride;

Expand All @@ -169,17 +155,15 @@ export const createSecurityRuleTypeWrapper: CreateSecurityRuleTypeWrapper =
{
index,
fields: hasTimestampOverride
? ['@timestamp', timestampOverride as string]
? ['@timestamp', timestampOverride]
: ['@timestamp'],
include_unmapped: true,
},
{ meta: true }
)
);
wroteWarningStatus = await hasTimestampFields({
timestampField: hasTimestampOverride
? (timestampOverride as string)
: '@timestamp',
timestampField: hasTimestampOverride ? timestampOverride : '@timestamp',
timestampFieldCapsResponse: timestampFieldCaps,
inputIndices,
ruleExecutionLogger,
Expand All @@ -201,8 +185,8 @@ export const createSecurityRuleTypeWrapper: CreateSecurityRuleTypeWrapper =
const { tuples, remainingGap } = getRuleRangeTuples({
logger,
previousStartedAt,
from: from as string,
to: to as string,
from,
to,
interval,
maxSignals: maxSignals ?? DEFAULT_MAX_SIGNALS,
buildRuleMessage,
Expand Down Expand Up @@ -235,7 +219,7 @@ export const createSecurityRuleTypeWrapper: CreateSecurityRuleTypeWrapper =

const exceptionItems = await getExceptions({
client: exceptionsClient,
lists: (params.exceptionsList as ListArray) ?? [],
lists: params.exceptionsList,
});

const bulkCreate = bulkCreateFactory(
Expand Down
Loading

0 comments on commit 25f07aa

Please sign in to comment.