|
56 | 56 | errMSTeamsV2WebhookUrlFileNotAllowed = errors.New("setting MSTeamsV2 webhook_url_file is not allowed") |
57 | 57 | errRocketChatTokenIdFileNotAllowed = errors.New("setting RocketChat token_id_file is not allowed") |
58 | 58 | errRocketChatTokenFileNotAllowed = errors.New("setting RocketChat token_file is not allowed") |
| 59 | + errDiscordWebhookUrlFileNotAllowed = errors.New("setting Discord webhook_url_file is not allowed") |
| 60 | + errEmailAuthPasswordFileNotAllowed = errors.New("setting Email auth_password_file is not allowed") |
59 | 61 | ) |
60 | 62 |
|
61 | 63 | // UserConfig is used to communicate a users alertmanager configs |
@@ -399,6 +401,14 @@ func validateAlertmanagerConfig(cfg any) error { |
399 | 401 | if err := validateRocketChatConfig(v.Interface().(config.RocketchatConfig)); err != nil { |
400 | 402 | return err |
401 | 403 | } |
| 404 | + case reflect.TypeOf(config.DiscordConfig{}): |
| 405 | + if err := validateDiscordConfig(v.Interface().(config.DiscordConfig)); err != nil { |
| 406 | + return err |
| 407 | + } |
| 408 | + case reflect.TypeOf(config.EmailConfig{}): |
| 409 | + if err := validateEmailConfig(v.Interface().(config.EmailConfig)); err != nil { |
| 410 | + return err |
| 411 | + } |
402 | 412 | } |
403 | 413 |
|
404 | 414 | // If the input config is a struct, recursively iterate on all fields. |
@@ -588,3 +598,21 @@ func validateRocketChatConfig(cfg config.RocketchatConfig) error { |
588 | 598 |
|
589 | 599 | return nil |
590 | 600 | } |
| 601 | + |
| 602 | +// validateDiscordConfig validates the Discord Config and returns an error if it contains |
| 603 | +// settings not allowed by Cortex. |
| 604 | +func validateDiscordConfig(cfg config.DiscordConfig) error { |
| 605 | + if cfg.WebhookURLFile != "" { |
| 606 | + return errDiscordWebhookUrlFileNotAllowed |
| 607 | + } |
| 608 | + return nil |
| 609 | +} |
| 610 | + |
| 611 | +// validateEmailConfig validates the Email Config and returns an error if it contains |
| 612 | +// settings not allowed by Cortex. |
| 613 | +func validateEmailConfig(cfg config.EmailConfig) error { |
| 614 | + if cfg.AuthPasswordFile != "" { |
| 615 | + return errEmailAuthPasswordFileNotAllowed |
| 616 | + } |
| 617 | + return nil |
| 618 | +} |
0 commit comments