mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 19:17:32 +00:00
feat: add stdout and filesystem notification channels (#2925)
* feat: add filesystem and stdout notification channels * configure through env vars * compile * feat: add compact option for debug notification channels * fix channel mock generation * avoid sensitive information in error message Co-authored-by: Livio Amstutz <livio.a@gmail.com> * add review improvements Co-authored-by: Livio Amstutz <livio.a@gmail.com>
This commit is contained in:
24
internal/notification/senders/chain.go
Normal file
24
internal/notification/senders/chain.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package senders
|
||||
|
||||
import "github.com/caos/zitadel/internal/notification/channels"
|
||||
|
||||
var _ channels.NotificationChannel = (*Chain)(nil)
|
||||
|
||||
type Chain struct {
|
||||
channels []channels.NotificationChannel
|
||||
}
|
||||
|
||||
func chainChannels(channel ...channels.NotificationChannel) *Chain {
|
||||
return &Chain{channels: channel}
|
||||
}
|
||||
|
||||
// HandleMessage returns a non nil error from a provider immediately if any occurs
|
||||
// messages are sent to channels in the same order they were provided to chainChannels()
|
||||
func (c *Chain) HandleMessage(message channels.Message) error {
|
||||
for i := range c.channels {
|
||||
if err := c.channels[i].HandleMessage(message); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
46
internal/notification/senders/debug.go
Normal file
46
internal/notification/senders/debug.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package senders
|
||||
|
||||
import (
|
||||
"github.com/caos/zitadel/internal/config/systemdefaults"
|
||||
"github.com/caos/zitadel/internal/notification/channels"
|
||||
"github.com/caos/zitadel/internal/notification/channels/chat"
|
||||
"github.com/caos/zitadel/internal/notification/channels/fs"
|
||||
"github.com/caos/zitadel/internal/notification/channels/log"
|
||||
)
|
||||
|
||||
func debugChannels(config systemdefaults.Notifications) (channels.NotificationChannel, error) {
|
||||
|
||||
var (
|
||||
providers []channels.NotificationChannel
|
||||
enableChat bool
|
||||
)
|
||||
|
||||
if config.Providers.Chat.Enabled != nil {
|
||||
enableChat = *config.Providers.Chat.Enabled
|
||||
} else {
|
||||
// ensures backward compatible configuration
|
||||
enableChat = config.DebugMode
|
||||
}
|
||||
|
||||
if enableChat {
|
||||
p, err := chat.InitChatChannel(config.Providers.Chat)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
providers = append(providers, p)
|
||||
}
|
||||
|
||||
if config.Providers.FileSystem.Enabled {
|
||||
p, err := fs.InitFSChannel(config.Providers.FileSystem)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
providers = append(providers, p)
|
||||
}
|
||||
|
||||
if config.Providers.Log.Enabled {
|
||||
providers = append(providers, log.InitStdoutChannel(config.Providers.Log))
|
||||
}
|
||||
|
||||
return chainChannels(providers...), nil
|
||||
}
|
25
internal/notification/senders/email.go
Normal file
25
internal/notification/senders/email.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package senders
|
||||
|
||||
import (
|
||||
"github.com/caos/zitadel/internal/config/systemdefaults"
|
||||
"github.com/caos/zitadel/internal/notification/channels"
|
||||
"github.com/caos/zitadel/internal/notification/channels/smtp"
|
||||
)
|
||||
|
||||
func EmailChannels(config systemdefaults.Notifications) (channels.NotificationChannel, error) {
|
||||
|
||||
debug, err := debugChannels(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !config.DebugMode {
|
||||
p, err := smtp.InitSMTPChannel(config.Providers.Email)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return chainChannels(debug, p), nil
|
||||
}
|
||||
|
||||
return debug, nil
|
||||
}
|
21
internal/notification/senders/sms.go
Normal file
21
internal/notification/senders/sms.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package senders
|
||||
|
||||
import (
|
||||
"github.com/caos/zitadel/internal/config/systemdefaults"
|
||||
"github.com/caos/zitadel/internal/notification/channels"
|
||||
"github.com/caos/zitadel/internal/notification/channels/twilio"
|
||||
)
|
||||
|
||||
func SMSChannels(config systemdefaults.Notifications) (channels.NotificationChannel, error) {
|
||||
|
||||
debug, err := debugChannels(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !config.DebugMode {
|
||||
return chainChannels(debug, twilio.InitTwilioChannel(config.Providers.Twilio)), nil
|
||||
}
|
||||
|
||||
return debug, nil
|
||||
}
|
Reference in New Issue
Block a user