mirror of
https://github.com/coreos/prometheus-operator.git
synced 2026-02-05 15:46:31 +01:00
Feat: Add GlobalConfig RocketChat Validation (#8283)
* *: add validation for rocketchat for more validation * amcfg: move rocket chat version validation to validate in the check function instead * amcfg: update error method to user errorf for error format * amcfg: update method name change to private * amcfg: update method change to private method
This commit is contained in:
@@ -1936,10 +1936,6 @@ func (cb *ConfigBuilder) convertGlobalRocketChatConfig(ctx context.Context, out
|
||||
return nil
|
||||
}
|
||||
|
||||
if cb.amVersion.LT(semver.MustParse("0.28.0")) {
|
||||
return errors.New("rocket chat integration requires Alertmanager >= 0.28.0")
|
||||
}
|
||||
|
||||
if in.APIURL != nil {
|
||||
u, err := url.Parse(string(*in.APIURL))
|
||||
if err != nil {
|
||||
@@ -3185,6 +3181,10 @@ func (cb *ConfigBuilder) checkAlertmanagerGlobalConfigResource(
|
||||
return err
|
||||
}
|
||||
|
||||
if err := cb.checkGlobalRocketChatConfig(ctx, gc.RocketChatConfig, namespace); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := cb.checkGlobalWebexConfig(gc.WebexConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -3238,6 +3238,34 @@ func (cb *ConfigBuilder) checkGlobalVictorOpsConfig(
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cb *ConfigBuilder) checkGlobalRocketChatConfig(
|
||||
ctx context.Context,
|
||||
rc *monitoringv1.GlobalRocketChatConfig,
|
||||
namespace string,
|
||||
) error {
|
||||
if rc == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if cb.amVersion.LT(semver.MustParse("0.28.0")) {
|
||||
return fmt.Errorf(`'rocketChat' integration requires Alertmanager >= 0.28.0 - current %s`, cb.amVersion)
|
||||
}
|
||||
|
||||
if rc.Token != nil {
|
||||
if _, err := cb.store.GetSecretKey(ctx, namespace, *rc.Token); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if rc.TokenID != nil {
|
||||
if _, err := cb.store.GetSecretKey(ctx, namespace, *rc.TokenID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cb *ConfigBuilder) checkGlobalWebexConfig(wc *monitoringv1.GlobalWebexConfig) error {
|
||||
if wc == nil {
|
||||
return nil
|
||||
|
||||
@@ -38,14 +38,18 @@ func ValidateAlertmanagerGlobalConfig(gc *monitoringv1.AlertmanagerGlobalConfig)
|
||||
return fmt.Errorf("jira: %w", err)
|
||||
}
|
||||
|
||||
if err := validateGlobalWebexConfig(gc.WebexConfig); err != nil {
|
||||
return fmt.Errorf("webex: %w", err)
|
||||
}
|
||||
|
||||
if err := validateGlobalVictorOpsConfig(gc.VictorOpsConfig); err != nil {
|
||||
return fmt.Errorf("victorops: %w", err)
|
||||
}
|
||||
|
||||
if err := validateGlobalRocketChatConfig(gc.RocketChatConfig); err != nil {
|
||||
return fmt.Errorf("rocketChat: %w", err)
|
||||
}
|
||||
|
||||
if err := validateGlobalWebexConfig(gc.WebexConfig); err != nil {
|
||||
return fmt.Errorf("webex: %w", err)
|
||||
}
|
||||
|
||||
if err := validateGlobalWeChatConfig(gc.WeChatConfig); err != nil {
|
||||
return fmt.Errorf("wechatConfig: %w", err)
|
||||
}
|
||||
@@ -89,6 +93,18 @@ func validateGlobalVictorOpsConfig(vc *monitoringv1.GlobalVictorOpsConfig) error
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateGlobalRocketChatConfig(rc *monitoringv1.GlobalRocketChatConfig) error {
|
||||
if rc == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := validation.ValidateURLPtr((*string)(rc.APIURL)); err != nil {
|
||||
return fmt.Errorf("invalid apiURL: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateGlobalWebexConfig(wc *monitoringv1.GlobalWebexConfig) error {
|
||||
if wc == nil {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user