diff --git a/cmd/relayproxy/config/config_test.go b/cmd/relayproxy/config/config_test.go index a4269974cd0..988dde71900 100644 --- a/cmd/relayproxy/config/config_test.go +++ b/cmd/relayproxy/config/config_test.go @@ -70,8 +70,8 @@ func TestParseConfig_fileFromPflag(t *testing.T) { }, Notifiers: []config.NotifierConf{ { - Kind: "slack", - SlackWebhookURL: "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX", + Kind: "slack", + WebhookURL: "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX", }, }, StartWithRetrieverError: false, @@ -386,8 +386,8 @@ func TestConfig_IsValid(t *testing.T) { Secret: "xxxx", }, { - Kind: "slack", - SlackWebhookURL: "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX", + Kind: "slack", + WebhookURL: "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX", }, }, }, @@ -416,8 +416,8 @@ func TestConfig_IsValid(t *testing.T) { Secret: "xxxx", }, { - Kind: "slack", - SlackWebhookURL: "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX", + Kind: "slack", + WebhookURL: "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX", }, }, LogLevel: "info", diff --git a/cmd/relayproxy/config/notifier.go b/cmd/relayproxy/config/notifier.go index 9de2e7dd2bf..492fc8a8d46 100644 --- a/cmd/relayproxy/config/notifier.go +++ b/cmd/relayproxy/config/notifier.go @@ -17,7 +17,7 @@ func (c *NotifierConf) IsValid() error { if err := c.Kind.IsValid(); err != nil { return err } - if c.Kind == SlackNotifier && c.SlackWebhookURL == "" { + if c.Kind == SlackNotifier && (c.SlackWebhookURL == "" && c.WebhookURL == "") { return fmt.Errorf("invalid notifier: no \"slackWebhookUrl\" property found for kind \"%s\"", c.Kind) } if c.Kind == WebhookNotifier && c.EndpointURL == "" { diff --git a/cmd/relayproxy/config/notifier_test.go b/cmd/relayproxy/config/notifier_test.go index 64472345182..2cf186b6fc9 100644 --- a/cmd/relayproxy/config/notifier_test.go +++ b/cmd/relayproxy/config/notifier_test.go @@ -9,11 +9,11 @@ import ( func TestNotifierConf_IsValid(t *testing.T) { type fields struct { - Kind string - SlackWebhookURL string - EndpointURL string - Secret string - Meta map[string]string + Kind string + WebhookURL string + EndpointURL string + Secret string + Meta map[string]string } tests := []struct { name string @@ -38,8 +38,8 @@ func TestNotifierConf_IsValid(t *testing.T) { { name: "kind slack without URL", fields: fields{ - Kind: "slack", - SlackWebhookURL: "", + Kind: "slack", + WebhookURL: "", }, wantErr: true, errValue: "invalid notifier: no \"slackWebhookUrl\" property found for kind \"slack\"", @@ -56,8 +56,8 @@ func TestNotifierConf_IsValid(t *testing.T) { { name: "valid use-case slack", fields: fields{ - Kind: "slack", - SlackWebhookURL: "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX", + Kind: "slack", + WebhookURL: "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX", }, wantErr: false, }, @@ -74,11 +74,11 @@ func TestNotifierConf_IsValid(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { c := &config.NotifierConf{ - Kind: config.NotifierKind(tt.fields.Kind), - SlackWebhookURL: tt.fields.SlackWebhookURL, - EndpointURL: tt.fields.EndpointURL, - Secret: tt.fields.Secret, - Meta: tt.fields.Meta, + Kind: config.NotifierKind(tt.fields.Kind), + WebhookURL: tt.fields.WebhookURL, + EndpointURL: tt.fields.EndpointURL, + Secret: tt.fields.Secret, + Meta: tt.fields.Meta, } err := c.IsValid() assert.Equal(t, tt.wantErr, err != nil) diff --git a/cmd/relayproxy/service/gofeatureflag.go b/cmd/relayproxy/service/gofeatureflag.go index 3d797c7e706..ce1dcbf6389 100644 --- a/cmd/relayproxy/service/gofeatureflag.go +++ b/cmd/relayproxy/service/gofeatureflag.go @@ -318,7 +318,7 @@ func initNotifier(c []config.NotifierConf) ([]notifier.Notifier, error) { switch cNotif.Kind { case config.SlackNotifier: if cNotif.WebhookURL == "" && cNotif.SlackWebhookURL != "" { // nolint - cNotif.WebhookURL = cNotif.SlackWebhookURL // nolint + zap.L().Warn("slackWebhookURL field is deprecated, please use webhookURL instead") } notifiers = append(notifiers, &slacknotifier.Notifier{SlackWebhookURL: cNotif.WebhookURL}) diff --git a/cmd/relayproxy/service/gofeatureflag_test.go b/cmd/relayproxy/service/gofeatureflag_test.go index 88abc13168c..e9de5df3ccc 100644 --- a/cmd/relayproxy/service/gofeatureflag_test.go +++ b/cmd/relayproxy/service/gofeatureflag_test.go @@ -421,8 +421,8 @@ func Test_initNotifier(t *testing.T) { args: args{ c: []config.NotifierConf{ { - Kind: config.SlackNotifier, - SlackWebhookURL: "http:xxxx.xxx", + Kind: config.SlackNotifier, + WebhookURL: "http:xxxx.xxx", }, { Kind: config.WebhookNotifier, diff --git a/cmd/relayproxy/testdata/config/valid-yaml-notifier.yaml b/cmd/relayproxy/testdata/config/valid-yaml-notifier.yaml index 8b11daaa005..8fa72cb2929 100644 --- a/cmd/relayproxy/testdata/config/valid-yaml-notifier.yaml +++ b/cmd/relayproxy/testdata/config/valid-yaml-notifier.yaml @@ -13,4 +13,4 @@ authorizedKeys: - apikey2 # owner: userID2 notifier: kind: slack - slackWebhookUrl: https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX \ No newline at end of file + webhookUrl: https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX \ No newline at end of file