-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement RuleExecutionLog (#103463)
- Loading branch information
Showing
76 changed files
with
1,383 additions
and
395 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
packages/kbn-securitysolution-io-ts-types/src/enumeration/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,39 @@ | ||
/* | ||
* 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 { left } from 'fp-ts/lib/Either'; | ||
import { enumeration } from '.'; | ||
import { foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils'; | ||
|
||
describe('enumeration', () => { | ||
enum TestEnum { | ||
'test' = 'test', | ||
} | ||
|
||
it('should validate a string from the enum', () => { | ||
const input = TestEnum.test; | ||
const codec = enumeration('TestEnum', TestEnum); | ||
const decoded = codec.decode(input); | ||
const message = foldLeftRight(decoded); | ||
|
||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(input); | ||
}); | ||
|
||
it('should NOT validate a random string', () => { | ||
const input = 'some string'; | ||
const codec = enumeration('TestEnum', TestEnum); | ||
const decoded = codec.decode(input); | ||
const message = foldLeftRight(decoded); | ||
|
||
expect(getPaths(left(message.errors))).toEqual([ | ||
'Invalid value "some string" supplied to "TestEnum"', | ||
]); | ||
expect(message.schema).toEqual({}); | ||
}); | ||
}); |
24 changes: 24 additions & 0 deletions
24
packages/kbn-securitysolution-io-ts-types/src/enumeration/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,24 @@ | ||
/* | ||
* 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'; | ||
|
||
export function enumeration<EnumType extends string>( | ||
name: string, | ||
originalEnum: Record<string, EnumType> | ||
): t.Type<EnumType, EnumType, unknown> { | ||
const isEnumValue = (input: unknown): input is EnumType => | ||
Object.values<unknown>(originalEnum).includes(input); | ||
|
||
return new t.Type<EnumType>( | ||
name, | ||
isEnumValue, | ||
(input, context) => (isEnumValue(input) ? t.success(input) : t.failure(input, context)), | ||
t.identity | ||
); | ||
} |
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
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
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
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
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
23 changes: 23 additions & 0 deletions
23
x-pack/plugins/security_solution/common/utils/invariant.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,23 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export class InvariantError extends Error { | ||
name = 'Invariant violation'; | ||
} | ||
|
||
/** | ||
* Asserts that the provided condition is always true | ||
* and throws an invariant violation error otherwise | ||
* | ||
* @param condition Condition to assert | ||
* @param message Error message to throw if the condition is falsy | ||
*/ | ||
export function invariant(condition: unknown, message: string): asserts condition { | ||
if (!condition) { | ||
throw new InvariantError(message); | ||
} | ||
} |
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
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.