Skip to content

Commit

Permalink
Merge branch 'main' into microsoft_notify
Browse files Browse the repository at this point in the history
  • Loading branch information
martinvibes committed Nov 6, 2024
2 parents b399264 + 254c763 commit 396033c
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 32 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
7 changes: 3 additions & 4 deletions cmd/relayproxy/config/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ type NotifierConf struct {
Kind NotifierKind `mapstructure:"kind" koanf:"kind"`
// Deprecated: Use WebhookURL instead
SlackWebhookURL string `mapstructure:"slackWebhookUrl" koanf:"slackWebhookUrl"`
MicrosoftTeamsWebhookURL string `mapstructure:"microsoftteamsWebhookUrl" koanf:"microsoftteamsWebhookUrl"`
EndpointURL string `mapstructure:"endpointUrl" koanf:"endpointUrl"`
Secret string `mapstructure:"secret" koanf:"secret"`
Meta map[string]string `mapstructure:"meta" koanf:"meta"`
Expand All @@ -18,11 +17,11 @@ 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.MicrosoftTeamsWebhookURL == "" {
return fmt.Errorf("invalid notifier: no \"microsoftteamsWebhookUrl\" property found for kind \"%s\"", c.Kind)
if c.Kind == MicrosoftTeamsNotifier && c.WebhookURL == "" {
return fmt.Errorf("invalid notifier: no \"webhookURL\" property found for kind \"%s\"", c.Kind)
}
if c.Kind == WebhookNotifier && c.EndpointURL == "" {
return fmt.Errorf("invalid notifier: no \"endpointUrl\" property found for kind \"%s\"", c.Kind)
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
10 changes: 5 additions & 5 deletions notifier/microsoftteamsnotifier/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func convertUpdatedFlagsToMicrosoftTeamsMessage(diffCache notifier.DiffCache) []
}
}

sort.Sort(ByTitle(attachment.Fields))
sort.Sort(byTitle(attachment.Fields))

attachments = append(attachments, attachment)
}
Expand Down Expand Up @@ -205,8 +205,8 @@ type Field struct {
Short bool `json:"short"`
}

type ByTitle []Field
type byTitle []Field

func (a ByTitle) Len() int { return len(a) }
func (a ByTitle) Less(i, j int) bool { return a[i].Title < a[j].Title }
func (a ByTitle) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a byTitle) Len() int { return len(a) }
func (a byTitle) Less(i, j int) bool { return a[i].Title < a[j].Title }
func (a byTitle) Swap(i, j int) { a[i], a[j] = a[j], a[i] }

0 comments on commit 396033c

Please sign in to comment.