-
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
[Response Ops][Rules] Version Get Rule Types API #195361
Changes from all commits
f84c695
dc89661
361c464
31ca0e0
e30a305
fcd0187
e315cd5
e9203bf
11a2387
a5e86bb
314a88e
f74aaa1
0078888
ca3004b
98f5dfb
693bdc6
887d716
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* 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 { typesRulesResponseSchema, typesRulesResponseBodySchema } from './schemas/latest'; | ||
export type { TypesRulesResponse, TypesRulesResponseBody } from './types/latest'; | ||
|
||
export { | ||
typesRulesResponseSchema as typesRulesResponseSchemaV1, | ||
typesRulesResponseBodySchema as typesRulesResponseBodySchemaV1, | ||
} from './schemas/v1'; | ||
export type { | ||
TypesRulesResponse as TypesRulesResponseV1, | ||
TypesRulesResponseBody as TypesRulesResponseBodyV1, | ||
} from './types/v1'; |
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 * from './v1'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* 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 { schema } from '@kbn/config-schema'; | ||
|
||
const actionVariableSchema = schema.object({ | ||
name: schema.string(), | ||
description: schema.string(), | ||
usesPublicBaseUrl: schema.maybe(schema.boolean()), | ||
}); | ||
|
||
const actionGroupSchema = schema.object({ | ||
id: schema.string(), | ||
name: schema.string(), | ||
}); | ||
|
||
export const typesRulesResponseBodySchema = schema.arrayOf( | ||
schema.object({ | ||
action_groups: schema.maybe(schema.arrayOf(actionGroupSchema)), | ||
action_variables: schema.maybe( | ||
schema.object({ | ||
context: schema.maybe(schema.arrayOf(actionVariableSchema)), | ||
state: schema.maybe(schema.arrayOf(actionVariableSchema)), | ||
params: schema.maybe(schema.arrayOf(actionVariableSchema)), | ||
}) | ||
), | ||
alerts: schema.maybe( | ||
schema.object({ | ||
context: schema.string(), | ||
mappings: schema.maybe( | ||
schema.object({ | ||
dynamic: schema.maybe(schema.oneOf([schema.literal(false), schema.literal('strict')])), | ||
fieldMap: schema.recordOf(schema.string(), schema.any()), | ||
shouldWrite: schema.maybe(schema.boolean()), | ||
useEcs: schema.maybe(schema.boolean()), | ||
}) | ||
), | ||
}) | ||
), | ||
authorized_consumers: schema.recordOf( | ||
schema.string(), | ||
schema.object({ read: schema.boolean(), all: schema.boolean() }) | ||
), | ||
category: schema.string(), | ||
default_action_group_id: schema.string(), | ||
default_schedule_interval: schema.maybe(schema.string()), | ||
does_set_recovery_context: schema.maybe(schema.boolean()), | ||
enabled_in_license: schema.boolean(), | ||
fieldsForAAD: schema.maybe(schema.arrayOf(schema.string())), | ||
has_alerts_mappings: schema.boolean(), | ||
has_fields_for_a_a_d: schema.boolean(), | ||
id: schema.string(), | ||
is_exportable: schema.boolean(), | ||
minimum_license_required: schema.oneOf([ | ||
schema.literal('basic'), | ||
schema.literal('gold'), | ||
schema.literal('platinum'), | ||
schema.literal('standard'), | ||
schema.literal('enterprise'), | ||
schema.literal('trial'), | ||
]), | ||
name: schema.string(), | ||
producer: schema.string(), | ||
recovery_action_group: actionGroupSchema, | ||
rule_task_timeout: schema.maybe(schema.string()), | ||
}) | ||
); | ||
|
||
export const typesRulesResponseSchema = schema.object({ | ||
body: typesRulesResponseBodySchema, | ||
}); |
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 * from './v1'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* 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 type { TypeOf } from '@kbn/config-schema'; | ||
|
||
import { typesRulesResponseSchemaV1, typesRulesResponseBodySchemaV1 } from '..'; | ||
|
||
export type TypesRulesResponse = TypeOf<typeof typesRulesResponseSchemaV1>; | ||
export type TypesRulesResponseBody = TypeOf<typeof typesRulesResponseBodySchemaV1>; |
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 { ruleTypesRoute } from './rule_types'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* 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 { IRouter } from '@kbn/core/server'; | ||
import { TypesRulesResponseBodyV1 } from '../../../../../common/routes/rule/apis/list_types'; | ||
import { ILicenseState } from '../../../../lib'; | ||
import { verifyAccessAndContext } from '../../../lib'; | ||
import { AlertingRequestHandlerContext, BASE_ALERTING_API_PATH } from '../../../../types'; | ||
import { transformRuleTypesResponseV1 } from './transforms'; | ||
|
||
export const ruleTypesRoute = ( | ||
router: IRouter<AlertingRequestHandlerContext>, | ||
licenseState: ILicenseState | ||
) => { | ||
router.get( | ||
{ | ||
path: `${BASE_ALERTING_API_PATH}/rule_types`, | ||
options: { | ||
access: 'public', | ||
summary: `Get the rule types`, | ||
tags: ['oas-tag:alerting'], | ||
}, | ||
validate: {}, | ||
}, | ||
router.handleLegacyErrors( | ||
verifyAccessAndContext(licenseState, async function (context, req, res) { | ||
const rulesClient = (await context.alerting).getRulesClient(); | ||
const ruleTypes = await rulesClient.listRuleTypes(); | ||
|
||
const responseBody: TypesRulesResponseBodyV1 = transformRuleTypesResponseV1(ruleTypes); | ||
|
||
return res.ok({ | ||
body: responseBody, | ||
}); | ||
}) | ||
) | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* 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 { transformRuleTypesResponse } from './transform_rule_types_response/latest'; | ||
export { transformRuleTypesResponse as transformRuleTypesResponseV1 } from './transform_rule_types_response/v1'; |
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 * from './v1'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* 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 { isBoolean } from 'lodash/fp'; | ||
import { RegistryAlertTypeWithAuth } from '../../../../../../authorization'; | ||
import type { TypesRulesResponseBodyV1 } from '../../../../../../../common/routes/rule/apis/list_types'; | ||
|
||
export const transformRuleTypesResponse = ( | ||
ruleTypes: Set<RegistryAlertTypeWithAuth> | ||
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. I talked with @JiaweiWu about RegistryAlertTypeWithAuth Ideally it would be moved to be an application type but it's a complete mess. As long as it's not been used anywhere else, we should be fine. Wdyt? 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. I agree that it should be an application type and the rule client returns a more suitable structure. I would say it is out of the scope of this PR. |
||
): TypesRulesResponseBodyV1 => { | ||
return Array.from(ruleTypes).map((ruleType: RegistryAlertTypeWithAuth) => { | ||
return { | ||
...(ruleType.actionGroups ? { action_groups: ruleType.actionGroups } : {}), | ||
...(ruleType.actionVariables ? { action_variables: ruleType.actionVariables } : {}), | ||
...(ruleType.alerts ? { alerts: ruleType.alerts } : {}), | ||
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. This one throws an error: Property 'alerts' does not exist on type 'RegistryAlertTypeWithAuth'. I'll add it to the type (see x-pack/plugins/alerting/server/rule_type_registry.ts changes), just let me know if you have more info/know a better option |
||
authorized_consumers: ruleType.authorizedConsumers, | ||
category: ruleType.category, | ||
default_action_group_id: ruleType.defaultActionGroupId, | ||
...(ruleType.defaultScheduleInterval | ||
? { default_schedule_interval: ruleType.defaultScheduleInterval } | ||
: {}), | ||
...(isBoolean(ruleType.doesSetRecoveryContext) | ||
? { does_set_recovery_context: ruleType.doesSetRecoveryContext } | ||
: {}), | ||
enabled_in_license: ruleType.enabledInLicense, | ||
...(ruleType.fieldsForAAD ? { fieldsForAAD: ruleType.fieldsForAAD } : {}), | ||
has_alerts_mappings: ruleType.hasAlertsMappings, | ||
has_fields_for_a_a_d: ruleType.hasFieldsForAAD, | ||
id: ruleType.id, | ||
is_exportable: ruleType.isExportable, | ||
minimum_license_required: ruleType.minimumLicenseRequired, | ||
name: ruleType.name, | ||
producer: ruleType.producer, | ||
recovery_action_group: ruleType.recoveryActionGroup, | ||
...(ruleType.ruleTaskTimeout ? { rule_task_timeout: ruleType.ruleTaskTimeout } : {}), | ||
}; | ||
}); | ||
}; |
This file was deleted.
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.
I think the schema is missing
default_schedule_interval
.