forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Response Ops][Rules] Version Get Rule Types API (elastic#195361)
## Summary `GET /api/alerting/rule_types` item in elastic#195181 (cherry picked from commit 512a31d)
- Loading branch information
Showing
16 changed files
with
248 additions
and
87 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
x-pack/plugins/alerting/common/routes/rule/apis/list_types/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,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'; |
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/alerting/common/routes/rule/apis/list_types/schemas/latest.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,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'; |
75 changes: 75 additions & 0 deletions
75
x-pack/plugins/alerting/common/routes/rule/apis/list_types/schemas/v1.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,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, | ||
}); |
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/alerting/common/routes/rule/apis/list_types/types/latest.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,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'; |
13 changes: 13 additions & 0 deletions
13
x-pack/plugins/alerting/common/routes/rule/apis/list_types/types/v1.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,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>; |
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
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/alerting/server/routes/rule/apis/list_types/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,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'; |
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
42 changes: 42 additions & 0 deletions
42
x-pack/plugins/alerting/server/routes/rule/apis/list_types/rule_types.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,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, | ||
}); | ||
}) | ||
) | ||
); | ||
}; |
9 changes: 9 additions & 0 deletions
9
x-pack/plugins/alerting/server/routes/rule/apis/list_types/transforms/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,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'; |
8 changes: 8 additions & 0 deletions
8
...ing/server/routes/rule/apis/list_types/transforms/transform_rule_types_response/latest.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,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'; |
42 changes: 42 additions & 0 deletions
42
...lerting/server/routes/rule/apis/list_types/transforms/transform_rule_types_response/v1.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,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> | ||
): 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 } : {}), | ||
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.
Oops, something went wrong.
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