Skip to content

Commit 468f9bc

Browse files
committed
updates and consolidates types
1 parent d48c696 commit 468f9bc

25 files changed

Lines changed: 99 additions & 111 deletions

File tree

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ export const threat_tactic = t.type({
413413
name: threat_tactic_name,
414414
reference: threat_tactic_reference,
415415
});
416+
export type ThreatTactic = t.TypeOf<typeof threat_tactic>;
416417
export const threat_subtechnique_id = t.string;
417418
export const threat_subtechnique_name = t.string;
418419
export const threat_subtechnique_reference = t.string;
@@ -421,6 +422,7 @@ export const threat_subtechnique = t.type({
421422
name: threat_subtechnique_name,
422423
reference: threat_subtechnique_reference,
423424
});
425+
export type ThreatSubtechnique = t.TypeOf<typeof threat_subtechnique>;
424426
export const threat_subtechniques = t.array(threat_subtechnique);
425427
export const threat_technique_id = t.string;
426428
export const threat_technique_name = t.string;
@@ -439,21 +441,22 @@ export const threat_technique = t.intersection([
439441
})
440442
),
441443
]);
444+
export type ThreatTechnique = t.TypeOf<typeof threat_technique>;
442445
export const threat_techniques = t.array(threat_technique);
443-
export const threat = t.array(
444-
t.exact(
445-
t.type({
446-
framework: threat_framework,
447-
tactic: threat_tactic,
448-
technique: threat_techniques,
449-
})
450-
)
446+
export const threat = t.exact(
447+
t.type({
448+
framework: threat_framework,
449+
tactic: threat_tactic,
450+
technique: threat_techniques,
451+
})
451452
);
452-
453453
export type Threat = t.TypeOf<typeof threat>;
454454

455-
export const threatOrUndefined = t.union([threat, t.undefined]);
456-
export type ThreatOrUndefined = t.TypeOf<typeof threatOrUndefined>;
455+
export const threats = t.array(threat);
456+
export type Threats = t.TypeOf<typeof threats>;
457+
458+
export const threatsOrUndefined = t.union([threats, t.undefined]);
459+
export type ThreatsOrUndefined = t.TypeOf<typeof threatsOrUndefined>;
457460

458461
export const threshold = t.exact(
459462
t.type({

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
Tags,
2424
To,
2525
type,
26-
Threat,
26+
Threats,
2727
threshold,
2828
ThrottleOrNull,
2929
note,
@@ -171,7 +171,7 @@ export type AddPrepackagedRulesSchemaDecoded = Omit<
171171
severity_mapping: SeverityMapping;
172172
tags: Tags;
173173
to: To;
174-
threat: Threat;
174+
threat: Threats;
175175
throttle: ThrottleOrNull;
176176
exceptions_list: ListArray;
177177
};

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
Tags,
2626
To,
2727
type,
28-
Threat,
28+
Threats,
2929
threshold,
3030
ThrottleOrNull,
3131
note,
@@ -193,7 +193,7 @@ export type ImportRulesSchemaDecoded = Omit<
193193
severity_mapping: SeverityMapping;
194194
tags: Tags;
195195
to: To;
196-
threat: Threat;
196+
threat: Threats;
197197
throttle: ThrottleOrNull;
198198
version: Version;
199199
exceptions_list: ListArray;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
from,
3232
enabled,
3333
tags,
34-
threat,
34+
threats,
3535
threshold,
3636
throttle,
3737
references,
@@ -98,7 +98,7 @@ export const patchRulesSchema = t.exact(
9898
severity_mapping,
9999
tags,
100100
to,
101-
threat,
101+
threat: threats,
102102
threshold,
103103
throttle,
104104
timestamp_override,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import {
4242
max_signals,
4343
risk_score,
4444
severity,
45-
threat,
45+
threats,
4646
to,
4747
references,
4848
version,
@@ -167,7 +167,7 @@ const commonParams = {
167167
max_signals,
168168
risk_score_mapping,
169169
severity_mapping,
170-
threat,
170+
threat: threats,
171171
to,
172172
references,
173173
version,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import {
4343
timeline_id,
4444
timeline_title,
4545
type,
46-
threat,
46+
threats,
4747
threshold,
4848
throttle,
4949
job_status,
@@ -106,7 +106,7 @@ export const requiredRulesSchema = t.type({
106106
tags,
107107
to,
108108
type,
109-
threat,
109+
threat: threats,
110110
created_at,
111111
updated_at,
112112
created_by,

x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_threat_array.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import { DefaultThreatArray } from './default_threat_array';
88
import { pipe } from 'fp-ts/lib/pipeable';
99
import { left } from 'fp-ts/lib/Either';
1010
import { foldLeftRight, getPaths } from '../../../test_utils';
11-
import { Threat } from '../common/schemas';
11+
import { Threats } from '../common/schemas';
1212

1313
describe('default_threat_null', () => {
1414
test('it should validate an empty array', () => {
15-
const payload: Threat = [];
15+
const payload: Threats = [];
1616
const decoded = DefaultThreatArray.decode(payload);
1717
const message = pipe(decoded, foldLeftRight);
1818

@@ -21,7 +21,7 @@ describe('default_threat_null', () => {
2121
});
2222

2323
test('it should validate an array of threats', () => {
24-
const payload: Threat = [
24+
const payload: Threats = [
2525
{
2626
framework: 'MITRE ATTACK',
2727
technique: [{ reference: 'https://test.com', name: 'Audio Capture', id: 'T1123' }],

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66

77
import * as t from 'io-ts';
88
import { Either } from 'fp-ts/lib/Either';
9-
import { Threat, threat } from '../common/schemas';
9+
import { Threats, threats } from '../common/schemas';
1010

1111
/**
1212
* Types the DefaultThreatArray as:
1313
* - If null or undefined, then an empty array will be set
1414
*/
15-
export const DefaultThreatArray = new t.Type<Threat, Threat | undefined, unknown>(
15+
export const DefaultThreatArray = new t.Type<Threats, Threats | undefined, unknown>(
1616
'DefaultThreatArray',
17-
threat.is,
18-
(input, context): Either<t.Errors, Threat> =>
19-
input == null ? t.success([]) : threat.validate(input, context),
17+
threats.is,
18+
(input, context): Either<t.Errors, Threats> =>
19+
input == null ? t.success([]) : threats.validate(input, context),
2020
t.identity
2121
);

x-pack/plugins/security_solution/common/detection_engine/schemas/types/threat.mock.ts

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

7-
import { Threat } from '../common/schemas';
7+
import { Threats } from '../common/schemas';
88

9-
export const getThreatMock = (): Threat => [
9+
export const getThreatMock = (): Threats => [
1010
{
1111
framework: 'MITRE ATT&CK',
1212
tactic: {

x-pack/plugins/security_solution/public/detections/components/rules/description_step/index.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@ import {
1818
} from '../../../../../../../../src/plugins/data/public';
1919
import { DEFAULT_TIMELINE_TITLE } from '../../../../timelines/components/timeline/translations';
2020
import { useKibana } from '../../../../common/lib/kibana';
21-
import {
22-
AboutStepRiskScore,
23-
AboutStepSeverity,
24-
IMitreEnterpriseAttack,
25-
} from '../../../pages/detection_engine/rules/types';
21+
import { AboutStepRiskScore, AboutStepSeverity } from '../../../pages/detection_engine/rules/types';
2622
import { FieldValueTimeline } from '../pick_timeline';
2723
import { FormSchema } from '../../../../shared_imports';
2824
import { ListItems } from './types';
@@ -42,7 +38,7 @@ import {
4238
import { buildMlJobDescription } from './ml_job_description';
4339
import { buildActionsDescription } from './actions_description';
4440
import { buildThrottleDescription } from './throttle_description';
45-
import { Type } from '../../../../../common/detection_engine/schemas/common/schemas';
41+
import { Threats, Type } from '../../../../../common/detection_engine/schemas/common/schemas';
4642
import { THREAT_QUERY_LABEL } from './translations';
4743
import { filterEmptyThreats } from '../../../pages/detection_engine/rules/create/helpers';
4844

@@ -179,7 +175,7 @@ export const getDescriptionItem = (
179175
indexPatterns,
180176
});
181177
} else if (field === 'threat') {
182-
const threats: IMitreEnterpriseAttack[] = get(field, data);
178+
const threats: Threats = get(field, data);
183179
return buildThreatDescription({ label, threat: filterEmptyThreats(threats) });
184180
} else if (field === 'threshold') {
185181
const threshold = get(field, data);

0 commit comments

Comments
 (0)