-
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.
Merge branch 'main' into tsvb_discacrded_searches
- Loading branch information
Showing
20 changed files
with
708 additions
and
24 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
*/ | ||
|
||
export const BASE_RAC_ALERTS_API_PATH = '/internal/rac/alerts'; | ||
export const MAX_ALERT_SEARCH_SIZE = 1000; |
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
58 changes: 58 additions & 0 deletions
58
x-pack/plugins/rule_registry/common/search_strategy/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,58 @@ | ||
/* | ||
* 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 { ValidFeatureId } from '@kbn/rule-data-utils'; | ||
import { Ecs } from 'kibana/server'; | ||
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; | ||
import { IEsSearchRequest, IEsSearchResponse } from 'src/plugins/data/common'; | ||
|
||
export type RuleRegistrySearchRequest = IEsSearchRequest & { | ||
featureIds: ValidFeatureId[]; | ||
query?: { bool: estypes.QueryDslBoolQuery }; | ||
}; | ||
|
||
type Prev = [ | ||
never, | ||
0, | ||
1, | ||
2, | ||
3, | ||
4, | ||
5, | ||
6, | ||
7, | ||
8, | ||
9, | ||
10, | ||
11, | ||
12, | ||
13, | ||
14, | ||
15, | ||
16, | ||
17, | ||
18, | ||
19, | ||
20, | ||
...Array<0> | ||
]; | ||
|
||
type Join<K, P> = K extends string | number | ||
? P extends string | number | ||
? `${K}${'' extends P ? '' : '.'}${P}` | ||
: never | ||
: never; | ||
|
||
type DotNestedKeys<T, D extends number = 10> = [D] extends [never] | ||
? never | ||
: T extends object | ||
? { [K in keyof T]-?: Join<K, DotNestedKeys<T[K], Prev[D]>> }[keyof T] | ||
: ''; | ||
|
||
type EcsFieldsResponse = { | ||
[Property in DotNestedKeys<Ecs>]: string[]; | ||
}; | ||
export type RuleRegistrySearchResponse = IEsSearchResponse<EcsFieldsResponse>; |
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
20 changes: 20 additions & 0 deletions
20
x-pack/plugins/rule_registry/server/lib/get_authz_filter.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,20 @@ | ||
/* | ||
* 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 { alertingAuthorizationMock } from '../../../alerting/server/authorization/alerting_authorization.mock'; | ||
import { ReadOperations } from '../../../alerting/server'; | ||
import { getAuthzFilter } from './get_authz_filter'; | ||
|
||
describe('getAuthzFilter()', () => { | ||
it('should call `getAuthorizationFilter`', async () => { | ||
const authorization = alertingAuthorizationMock.create(); | ||
authorization.getAuthorizationFilter.mockImplementationOnce(async () => { | ||
return { filter: { test: true }, ensureRuleTypeIsAuthorized: () => {} }; | ||
}); | ||
const filter = await getAuthzFilter(authorization, ReadOperations.Find); | ||
expect(filter).toStrictEqual({ test: true }); | ||
}); | ||
}); |
33 changes: 33 additions & 0 deletions
33
x-pack/plugins/rule_registry/server/lib/get_authz_filter.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,33 @@ | ||
/* | ||
* 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 { PublicMethodsOf } from '@kbn/utility-types'; | ||
import { | ||
ReadOperations, | ||
WriteOperations, | ||
AlertingAuthorization, | ||
AlertingAuthorizationEntity, | ||
AlertingAuthorizationFilterType, | ||
} from '../../../alerting/server'; | ||
import { | ||
ALERT_RULE_CONSUMER, | ||
ALERT_RULE_TYPE_ID, | ||
} from '../../common/technical_rule_data_field_names'; | ||
|
||
export async function getAuthzFilter( | ||
authorization: PublicMethodsOf<AlertingAuthorization>, | ||
operation: WriteOperations.Update | ReadOperations.Get | ReadOperations.Find | ||
) { | ||
const { filter } = await authorization.getAuthorizationFilter( | ||
AlertingAuthorizationEntity.Alert, | ||
{ | ||
type: AlertingAuthorizationFilterType.ESDSL, | ||
fieldNames: { consumer: ALERT_RULE_CONSUMER, ruleTypeId: ALERT_RULE_TYPE_ID }, | ||
}, | ||
operation | ||
); | ||
return filter; | ||
} |
20 changes: 20 additions & 0 deletions
20
x-pack/plugins/rule_registry/server/lib/get_spaces_filter.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,20 @@ | ||
/* | ||
* 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 { getSpacesFilter } from '.'; | ||
describe('getSpacesFilter()', () => { | ||
it('should return a spaces filter', () => { | ||
expect(getSpacesFilter('1')).toStrictEqual({ | ||
term: { | ||
'kibana.space_ids': '1', | ||
}, | ||
}); | ||
}); | ||
|
||
it('should return undefined if no space id is provided', () => { | ||
expect(getSpacesFilter()).toBeUndefined(); | ||
}); | ||
}); |
11 changes: 11 additions & 0 deletions
11
x-pack/plugins/rule_registry/server/lib/get_spaces_filter.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,11 @@ | ||
/* | ||
* 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 { SPACE_IDS } from '../../common/technical_rule_data_field_names'; | ||
|
||
export function getSpacesFilter(spaceId?: string) { | ||
return spaceId ? { term: { [SPACE_IDS]: spaceId } } : undefined; | ||
} |
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,8 @@ | ||
/* | ||
* 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 { getAuthzFilter } from './get_authz_filter'; | ||
export { getSpacesFilter } from './get_spaces_filter'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* 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 { ruleRegistrySearchStrategyProvider } from './search_strategy'; |
Oops, something went wrong.