elastic / kibana

Your window into the Elastic Stack
https://www.elastic.co/products/kibana
Other
19.82k stars 8.2k forks source link

[RAM] Execute `validateMutatedRuleTypeParams `in both `update` and `create` methods of rulesClient #140031

Open vitaliidm opened 2 years ago

vitaliidm commented 2 years ago

Describe the feature: Execute validateMutatedRuleTypeParamsin both update and create methods of rulesClient

In scope of implementation https://github.com/elastic/kibana/issues/124715 new rule params validation method validateMutatedParams has been added in this PR to rule type params validator.

export interface RuleTypeParamsValidator<Params extends RuleTypeParams> {
  validate: (object: unknown) => Params;
  validateMutatedParams?: (mutatedOject: unknown, origObject?: unknown) => Params;
}

It gets called during bulk editing of rule, and it executes any required validation of rule parameters during its mutation.


            const validatedMutatedAlertTypeParams = validateMutatedRuleTypeParams(
              validatedAlertTypeParams,
              rule.attributes.params,
              ruleType.validate?.params
            );

To make consistent behaviour within all rulesClient mutate methods, this validation function should be also called in update and create as well

elasticmachine commented 2 years ago

Pinging @elastic/response-ops (Team:ResponseOps)

vitaliidm commented 2 years ago

cc: @XavierM Small enhancement we would like to see in other rulesClient methods to make behaviour same as during bulkEdit. Let me know, if this makes sense