-
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.
[RAM][HTTP Versioning] Version Public Rule Update Route (#179587)
## Summary Issue: #179476 Parent issue: #157883 This PR versions the update (`PUT '/api/alerting/rule/{id}'`) route. Still using `config-schema` for now, even though we will eventually switch to `zod` when core is ready with openapi doc generation support in the versioned router. We are now validating update data using the update data schema when calling `rulesClient->update`. We are also validating (but not throwing) the updated rule as well. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --------- Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
091fd14
commit ed4fade
Showing
54 changed files
with
1,555 additions
and
1,008 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
38 changes: 38 additions & 0 deletions
38
x-pack/plugins/alerting/common/routes/rule/apis/update/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,38 @@ | ||
/* | ||
* 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 { | ||
actionFrequencySchema, | ||
actionAlertsFilterSchema, | ||
actionSchema, | ||
updateBodySchema, | ||
updateParamsSchema, | ||
} from './schemas/latest'; | ||
|
||
export type { | ||
UpdateRuleAction, | ||
UpdateRuleActionFrequency, | ||
UpdateRuleRequestParams, | ||
UpdateRuleRequestBody, | ||
UpdateRuleResponse, | ||
} from './types/latest'; | ||
|
||
export { | ||
actionFrequencySchema as actionFrequencySchemaV1, | ||
actionAlertsFilterSchema as actionAlertsFilterSchemaV1, | ||
actionSchema as actionSchemaV1, | ||
updateBodySchema as updateBodySchemaV1, | ||
updateParamsSchema as updateParamsSchemaV1, | ||
} from './schemas/v1'; | ||
|
||
export type { | ||
UpdateRuleAction as UpdateRuleActionV1, | ||
UpdateRuleActionFrequency as UpdateRuleActionFrequencyV1, | ||
UpdateRuleRequestParams as UpdateRuleRequestParamsV1, | ||
UpdateRuleRequestBody as UpdateRuleRequestBodyV1, | ||
UpdateRuleResponse as UpdateRuleResponseV1, | ||
} from './types/v1'; |
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/alerting/common/routes/rule/apis/update/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'; |
72 changes: 72 additions & 0 deletions
72
x-pack/plugins/alerting/common/routes/rule/apis/update/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,72 @@ | ||
/* | ||
* 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'; | ||
import { validateDurationV1, validateHoursV1, validateTimezoneV1 } from '../../../validation'; | ||
import { notifyWhenSchemaV1, alertDelaySchemaV1 } from '../../../response'; | ||
import { alertsFilterQuerySchemaV1 } from '../../../../alerts_filter_query'; | ||
|
||
export const actionFrequencySchema = schema.object({ | ||
summary: schema.boolean(), | ||
notify_when: notifyWhenSchemaV1, | ||
throttle: schema.nullable(schema.string({ validate: validateDurationV1 })), | ||
}); | ||
|
||
export const actionAlertsFilterSchema = schema.object({ | ||
query: schema.maybe(alertsFilterQuerySchemaV1), | ||
timeframe: schema.maybe( | ||
schema.object({ | ||
days: schema.arrayOf( | ||
schema.oneOf([ | ||
schema.literal(1), | ||
schema.literal(2), | ||
schema.literal(3), | ||
schema.literal(4), | ||
schema.literal(5), | ||
schema.literal(6), | ||
schema.literal(7), | ||
]) | ||
), | ||
hours: schema.object({ | ||
start: schema.string({ | ||
validate: validateHoursV1, | ||
}), | ||
end: schema.string({ | ||
validate: validateHoursV1, | ||
}), | ||
}), | ||
timezone: schema.string({ validate: validateTimezoneV1 }), | ||
}) | ||
), | ||
}); | ||
|
||
export const actionSchema = schema.object({ | ||
group: schema.maybe(schema.string()), | ||
id: schema.string(), | ||
params: schema.recordOf(schema.string(), schema.any(), { defaultValue: {} }), | ||
frequency: schema.maybe(actionFrequencySchema), | ||
uuid: schema.maybe(schema.string()), | ||
alerts_filter: schema.maybe(actionAlertsFilterSchema), | ||
use_alert_data_for_template: schema.maybe(schema.boolean()), | ||
}); | ||
|
||
export const updateBodySchema = schema.object({ | ||
name: schema.string(), | ||
tags: schema.arrayOf(schema.string(), { defaultValue: [] }), | ||
schedule: schema.object({ | ||
interval: schema.string({ validate: validateDurationV1 }), | ||
}), | ||
throttle: schema.maybe(schema.nullable(schema.string({ validate: validateDurationV1 }))), | ||
params: schema.recordOf(schema.string(), schema.any(), { defaultValue: {} }), | ||
actions: schema.arrayOf(actionSchema, { defaultValue: [] }), | ||
notify_when: schema.maybe(schema.nullable(notifyWhenSchemaV1)), | ||
alert_delay: schema.maybe(alertDelaySchemaV1), | ||
}); | ||
|
||
export const updateParamsSchema = schema.object({ | ||
id: schema.string(), | ||
}); |
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/alerting/common/routes/rule/apis/update/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'; |
37 changes: 37 additions & 0 deletions
37
x-pack/plugins/alerting/common/routes/rule/apis/update/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,37 @@ | ||
/* | ||
* 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 { RuleParamsV1, RuleResponseV1 } from '../../../response'; | ||
|
||
import { | ||
actionSchemaV1, | ||
actionFrequencySchemaV1, | ||
updateParamsSchemaV1, | ||
updateBodySchemaV1, | ||
} from '..'; | ||
|
||
export type UpdateRuleAction = TypeOf<typeof actionSchemaV1>; | ||
export type UpdateRuleActionFrequency = TypeOf<typeof actionFrequencySchemaV1>; | ||
|
||
export type UpdateRuleRequestParams = TypeOf<typeof updateParamsSchemaV1>; | ||
type UpdateBodySchema = TypeOf<typeof updateBodySchemaV1>; | ||
|
||
export interface UpdateRuleRequestBody<Params extends RuleParamsV1 = never> { | ||
name: UpdateBodySchema['name']; | ||
tags: UpdateBodySchema['tags']; | ||
schedule: UpdateBodySchema['schedule']; | ||
throttle?: UpdateBodySchema['throttle']; | ||
params: Params; | ||
actions: UpdateBodySchema['actions']; | ||
notify_when?: UpdateBodySchema['notify_when']; | ||
alert_delay?: UpdateBodySchema['alert_delay']; | ||
} | ||
|
||
export interface UpdateRuleResponse<Params extends RuleParamsV1 = never> { | ||
body: RuleResponseV1<Params>; | ||
} |
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.