Alerting: validate that the receiver exist when updating routing tree (#51561)

* Alerting: validate that the receiver exist when updating routing tree

* rename interface

* add missing file

* change constructor

* fix e2e tests

* only import package once

* add unit test for bug

* wording

* close response body

* Update pkg/services/ngalert/api/tooling/definitions/alertmanager_validation.go

* refactor to remove database roundtrip
This commit is contained in:
Jean-Philippe Quéméner
2022-07-05 18:09:57 +02:00
committed by GitHub
parent 578ab71ba9
commit e64cde8727
4 changed files with 103 additions and 3 deletions
@@ -101,6 +101,19 @@ func (r *Route) Validate() error {
return r.validateChild()
}
func (r *Route) ValidateReceivers(receivers map[string]struct{}) error {
if _, exists := receivers[r.Receiver]; !exists {
return fmt.Errorf("receiver '%s' does not exist", r.Receiver)
}
for _, children := range r.Routes {
err := children.ValidateReceivers(receivers)
if err != nil {
return err
}
}
return nil
}
func (mt *MuteTimeInterval) Validate() error {
s, err := yaml.Marshal(mt.MuteTimeInterval)
if err != nil {