-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Security Solution][Detections] Add Bulk Scheduling for rules #140166
Merged
jpdjere
merged 22 commits into
elastic:main
from
jpdjere:2172-v2-cp-bulk-scheduling-for-rules
Sep 19, 2022
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
cc8d5fd
Add bulk edit schema and serverside changes
jpdjere d10f9fd
Added BulkSetSchedule flyout
jpdjere 7fdf661
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine e5d82ca
Connected API
jpdjere 171a22a
Flyout design
jpdjere baba0a3
Fix label
jpdjere 3b1aea8
Update CSS of ScheduleItem
jpdjere 36cd38b
Type fixes
jpdjere 1a64d8e
Refactored types and added unit tests to perform bulk actions
jpdjere 5fee389
Add bulkEditActionToRulesClientOperation test
jpdjere b715f64
Ad test to rulesParamModifier
jpdjere 4f07e29
Add validation to form
jpdjere 797c5ea
Make ScheduleItem default to color version
jpdjere 3ecfc6b
Update type
jpdjere c4ca544
Added TimeLength io type
jpdjere fa14e5b
Fix payload
jpdjere dbbd4d4
Fix type
jpdjere 3fc9237
Update tests
jpdjere 5208840
Updated TimeDuration io-ts type
jpdjere fb0b855
Add integration and e2e tests according to test plan
jpdjere 985b86c
Add warning callout assertion
jpdjere ab26845
Fix Schedule container width conflict
jpdjere File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
packages/kbn-securitysolution-io-ts-types/src/time_duration/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { pipe } from 'fp-ts/lib/pipeable'; | ||
import { left } from 'fp-ts/lib/Either'; | ||
import { TimeDuration } from '.'; | ||
import { foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils'; | ||
|
||
describe('time_unit', () => { | ||
test('it should validate a correctly formed TimeDuration with time unit of seconds', () => { | ||
const payload = '1s'; | ||
const decoded = TimeDuration.decode(payload); | ||
const message = pipe(decoded, foldLeftRight); | ||
|
||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(payload); | ||
}); | ||
|
||
test('it should validate a correctly formed TimeDuration with time unit of minutes', () => { | ||
const payload = '100m'; | ||
const decoded = TimeDuration.decode(payload); | ||
const message = pipe(decoded, foldLeftRight); | ||
|
||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(payload); | ||
}); | ||
|
||
test('it should validate a correctly formed TimeDuration with time unit of hours', () => { | ||
const payload = '10000000h'; | ||
const decoded = TimeDuration.decode(payload); | ||
const message = pipe(decoded, foldLeftRight); | ||
|
||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(payload); | ||
}); | ||
|
||
test('it should NOT validate a negative TimeDuration', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about:
Let's cover these cases with tests to be explicit about whether they are supported or not? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixing in follow up PR |
||
const payload = '-10s'; | ||
const decoded = TimeDuration.decode(payload); | ||
const message = pipe(decoded, foldLeftRight); | ||
|
||
expect(getPaths(left(message.errors))).toEqual([ | ||
'Invalid value "-10s" supplied to "TimeDuration"', | ||
]); | ||
expect(message.schema).toEqual({}); | ||
}); | ||
|
||
test('it should NOT validate a TimeDuration with some other time unit', () => { | ||
const payload = '10000000w'; | ||
const decoded = TimeDuration.decode(payload); | ||
const message = pipe(decoded, foldLeftRight); | ||
|
||
expect(getPaths(left(message.errors))).toEqual([ | ||
'Invalid value "10000000w" supplied to "TimeDuration"', | ||
]); | ||
expect(message.schema).toEqual({}); | ||
}); | ||
|
||
test('it should NOT validate a TimeDuration with a time interval with incorrect format', () => { | ||
const payload = '100ff0000w'; | ||
const decoded = TimeDuration.decode(payload); | ||
const message = pipe(decoded, foldLeftRight); | ||
|
||
expect(getPaths(left(message.errors))).toEqual([ | ||
'Invalid value "100ff0000w" supplied to "TimeDuration"', | ||
]); | ||
expect(message.schema).toEqual({}); | ||
}); | ||
|
||
test('it should NOT validate an empty string', () => { | ||
const payload = ''; | ||
const decoded = TimeDuration.decode(payload); | ||
const message = pipe(decoded, foldLeftRight); | ||
|
||
expect(getPaths(left(message.errors))).toEqual(['Invalid value "" supplied to "TimeDuration"']); | ||
expect(message.schema).toEqual({}); | ||
}); | ||
|
||
test('it should NOT validate an number', () => { | ||
const payload = 100; | ||
const decoded = TimeDuration.decode(payload); | ||
const message = pipe(decoded, foldLeftRight); | ||
|
||
expect(getPaths(left(message.errors))).toEqual([ | ||
'Invalid value "100" supplied to "TimeDuration"', | ||
]); | ||
expect(message.schema).toEqual({}); | ||
}); | ||
|
||
test('it should NOT validate an TimeDuration with a valid time unit but unsafe integer', () => { | ||
const payload = `${Math.pow(2, 53)}h`; | ||
const decoded = TimeDuration.decode(payload); | ||
const message = pipe(decoded, foldLeftRight); | ||
|
||
expect(getPaths(left(message.errors))).toEqual([ | ||
`Invalid value "${Math.pow(2, 53)}h" supplied to "TimeDuration"`, | ||
]); | ||
expect(message.schema).toEqual({}); | ||
}); | ||
}); |
45 changes: 45 additions & 0 deletions
45
packages/kbn-securitysolution-io-ts-types/src/time_duration/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import * as t from 'io-ts'; | ||
import { Either } from 'fp-ts/lib/Either'; | ||
|
||
/** | ||
* Types the TimeDuration as: | ||
* - A string that is not empty, and composed of a positive integer greater than 0 followed by a unit of time | ||
* - in the format {safe_integer}{timeUnit}, e.g. "30s", "1m", "2h" | ||
*/ | ||
export const TimeDuration = new t.Type<string, string, unknown>( | ||
banderror marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'TimeDuration', | ||
t.string.is, | ||
(input, context): Either<t.Errors, string> => { | ||
if (typeof input === 'string' && input.trim() !== '') { | ||
try { | ||
const inputLength = input.length; | ||
const time = parseInt(input.trim().substring(0, inputLength - 1), 10); | ||
const unit = input.trim().at(-1); | ||
if ( | ||
time >= 1 && | ||
Number.isSafeInteger(time) && | ||
(unit === 's' || unit === 'm' || unit === 'h') | ||
) { | ||
return t.success(input); | ||
} else { | ||
return t.failure(input, context); | ||
} | ||
} catch (error) { | ||
return t.failure(input, context); | ||
} | ||
} else { | ||
return t.failure(input, context); | ||
} | ||
}, | ||
t.identity | ||
); | ||
|
||
export type TimeDurationC = typeof TimeDuration; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit:
TimeDuration