Skip to content

Commit

Permalink
Merge branch 'thomaspoignant:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
martinvibes authored Nov 6, 2024
2 parents 3da8e50 + cba1570 commit 254c763
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 24 deletions.
12 changes: 6 additions & 6 deletions cmd/relayproxy/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
},
},
},
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion cmd/relayproxy/config/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == MicrosoftTeamsNotifier && c.WebhookURL == "" {
Expand Down
28 changes: 14 additions & 14 deletions cmd/relayproxy/config/notifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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\"",
Expand All @@ -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,
},
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions cmd/relayproxy/service/gofeatureflag.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ func initNotifier(c []config.NotifierConf) ([]notifier.Notifier, error) {
switch cNotif.Kind {
case config.SlackNotifier:
if cNotif.WebhookURL == "" && cNotif.SlackWebhookURL != "" { // nolint
zap.L().Warn("slackWebhookURL field is deprecated, please use webhookURL instead")
cNotif.WebhookURL = cNotif.SlackWebhookURL // nolint
}
notifiers = append(notifiers, &slacknotifier.Notifier{SlackWebhookURL: cNotif.WebhookURL})
Expand Down
4 changes: 2 additions & 2 deletions cmd/relayproxy/service/gofeatureflag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,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.MicrosoftTeamsNotifier,
Expand Down
2 changes: 1 addition & 1 deletion cmd/relayproxy/testdata/config/valid-yaml-notifier.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ authorizedKeys:
- apikey2 # owner: userID2
notifier:
kind: slack
slackWebhookUrl: https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX
webhookUrl: https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX

0 comments on commit 254c763

Please sign in to comment.