Skip to content

Commit b49a549

Browse files
Fixes the cycle deps issue by breaking out a file from utils
1 parent 01c8c88 commit b49a549

8 files changed

Lines changed: 27 additions & 21 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import moment from 'moment';
8+
import dateMath from '@elastic/datemath';
9+
10+
export const parseScheduleDates = (time: string): moment.Moment | null => {
11+
const isValidDateString = !isNaN(Date.parse(time));
12+
const isValidInput = isValidDateString || time.trim().startsWith('now');
13+
const formattedDate = isValidDateString
14+
? moment(time)
15+
: isValidInput
16+
? dateMath.parse(time)
17+
: null;
18+
19+
return formattedDate ?? null;
20+
};

x-pack/plugins/security_solution/common/detection_engine/schemas/common/schemas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { UUID } from '../types/uuid';
1414
import { IsoDateString } from '../types/iso_date_string';
1515
import { PositiveIntegerGreaterThanZero } from '../types/positive_integer_greater_than_zero';
1616
import { PositiveInteger } from '../types/positive_integer';
17-
import { parseScheduleDates } from '../../utils';
17+
import { parseScheduleDates } from '../../parse_schedule_dates';
1818

1919
export const author = t.array(t.string);
2020
export type Author = t.TypeOf<typeof author>;

x-pack/plugins/security_solution/common/detection_engine/utils.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import moment from 'moment';
8-
import dateMath from '@elastic/datemath';
9-
107
import { EntriesArray } from '../shared_imports';
118
import { Type } from './schemas/common/schemas';
129

@@ -21,15 +18,3 @@ export const hasNestedEntry = (entries: EntriesArray): boolean => {
2118
};
2219

2320
export const isThresholdRule = (ruleType: Type) => ruleType === 'threshold';
24-
25-
export const parseScheduleDates = (time: string): moment.Moment | null => {
26-
const isValidDateString = !isNaN(Date.parse(time));
27-
const isValidInput = isValidDateString || time.trim().startsWith('now');
28-
const formattedDate = isValidDateString
29-
? moment(time)
30-
: isValidInput
31-
? dateMath.parse(time)
32-
: null;
33-
34-
return formattedDate ?? null;
35-
};

x-pack/plugins/security_solution/server/lib/detection_engine/notifications/rules_notification_alert_type.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { RuleAlertAttributes } from '../signals/types';
1414
import { siemRuleActionGroups } from '../signals/siem_rule_action_groups';
1515
import { scheduleNotificationActions } from './schedule_notification_actions';
1616
import { getNotificationResultsLink } from './utils';
17-
import { parseScheduleDates } from '../../../../common/detection_engine/utils';
17+
import { parseScheduleDates } from '../../../../common/detection_engine/parse_schedule_dates';
1818

1919
export const rulesNotificationAlertType = ({
2020
logger,

x-pack/plugins/security_solution/server/lib/detection_engine/signals/signal_rule_alert_type.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
getExceptions,
1818
sortExceptionItems,
1919
} from './utils';
20-
import { parseScheduleDates } from '../../../../common/detection_engine/utils';
20+
import { parseScheduleDates } from '../../../../common/detection_engine/parse_schedule_dates';
2121
import { RuleExecutorOptions } from './types';
2222
import { searchAfterAndBulkCreate } from './search_after_bulk_create';
2323
import { scheduleNotificationActions } from '../notifications/schedule_notification_actions';

x-pack/plugins/security_solution/server/lib/detection_engine/signals/signal_rule_alert_type.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
SERVER_APP_ID,
1515
} from '../../../../common/constants';
1616
import { isJobStarted, isMlRule } from '../../../../common/machine_learning/helpers';
17-
import { parseScheduleDates } from '../../../../common/detection_engine/utils';
17+
import { parseScheduleDates } from '../../../../common/detection_engine/parse_schedule_dates';
1818
import { SetupPlugins } from '../../../plugin';
1919
import { getInputIndex } from './get_input_output_index';
2020
import {

x-pack/plugins/security_solution/server/lib/detection_engine/signals/utils.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { buildRuleMessageFactory } from './rule_messages';
1313
import { ExceptionListClient } from '../../../../../lists/server';
1414
import { getListArrayMock } from '../../../../common/detection_engine/schemas/types/lists.mock';
1515
import { getExceptionListItemSchemaMock } from '../../../../../lists/common/schemas/response/exception_list_item_schema.mock';
16-
import { parseScheduleDates } from '../../../../common/detection_engine/utils';
16+
import { parseScheduleDates } from '../../../../common/detection_engine/parse_schedule_dates';
1717

1818
import {
1919
generateId,

x-pack/plugins/security_solution/server/lib/detection_engine/signals/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import { ExceptionListItemSchema } from '../../../../../lists/common/schemas';
1414
import { ListArrayOrUndefined } from '../../../../common/detection_engine/schemas/types/lists';
1515
import { BulkResponse, BulkResponseErrorAggregation, isValidUnit } from './types';
1616
import { BuildRuleMessage } from './rule_messages';
17-
import { hasLargeValueList, parseScheduleDates } from '../../../../common/detection_engine/utils';
17+
import { parseScheduleDates } from '../../../../common/detection_engine/parse_schedule_dates';
18+
import { hasLargeValueList } from '../../../../common/detection_engine/utils';
1819
import { MAX_EXCEPTION_LIST_SIZE } from '../../../../../lists/common/constants';
1920

2021
interface SortExceptionsReturn {

0 commit comments

Comments
 (0)