mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:37: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:
@@ -3,21 +3,16 @@ package types
|
||||
import (
|
||||
"html"
|
||||
|
||||
"github.com/caos/zitadel/internal/notification/messages"
|
||||
"github.com/caos/zitadel/internal/notification/senders"
|
||||
|
||||
"github.com/caos/zitadel/internal/config/systemdefaults"
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/notification/providers"
|
||||
"github.com/caos/zitadel/internal/notification/providers/chat"
|
||||
"github.com/caos/zitadel/internal/notification/providers/email"
|
||||
view_model "github.com/caos/zitadel/internal/user/repository/view/model"
|
||||
)
|
||||
|
||||
func generateEmail(user *view_model.NotifyUser, subject, content string, config systemdefaults.Notifications, lastEmail bool) error {
|
||||
provider, err := email.InitEmailProvider(config.Providers.Email)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
content = html.UnescapeString(content)
|
||||
message := &email.EmailMessage{
|
||||
message := &messages.Email{
|
||||
SenderEmail: config.Providers.Email.From,
|
||||
Recipients: []string{user.VerifiedEmail},
|
||||
Subject: subject,
|
||||
@@ -26,21 +21,13 @@ func generateEmail(user *view_model.NotifyUser, subject, content string, config
|
||||
if lastEmail {
|
||||
message.Recipients = []string{user.LastEmail}
|
||||
}
|
||||
if provider.CanHandleMessage(message) {
|
||||
if config.DebugMode {
|
||||
return sendDebugEmail(message, config)
|
||||
}
|
||||
return provider.HandleMessage(message)
|
||||
}
|
||||
return caos_errs.ThrowInternalf(nil, "NOTIF-s8ipw", "Could not send init message: userid: %v", user.ID)
|
||||
}
|
||||
|
||||
func sendDebugEmail(message providers.Message, config systemdefaults.Notifications) error {
|
||||
provider, err := chat.InitChatProvider(config.Providers.Chat)
|
||||
channels, err := senders.EmailChannels(config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return provider.HandleMessage(message)
|
||||
|
||||
return channels.HandleMessage(message)
|
||||
}
|
||||
|
||||
func mapNotifyUserToArgs(user *view_model.NotifyUser) map[string]interface{} {
|
||||
|
@@ -2,16 +2,13 @@ package types
|
||||
|
||||
import (
|
||||
"github.com/caos/zitadel/internal/config/systemdefaults"
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/notification/providers"
|
||||
"github.com/caos/zitadel/internal/notification/providers/chat"
|
||||
"github.com/caos/zitadel/internal/notification/providers/twilio"
|
||||
"github.com/caos/zitadel/internal/notification/messages"
|
||||
"github.com/caos/zitadel/internal/notification/senders"
|
||||
view_model "github.com/caos/zitadel/internal/user/repository/view/model"
|
||||
)
|
||||
|
||||
func generateSms(user *view_model.NotifyUser, content string, config systemdefaults.Notifications, lastPhone bool) error {
|
||||
provider := twilio.InitTwilioProvider(config.Providers.Twilio)
|
||||
message := &twilio.TwilioMessage{
|
||||
message := &messages.SMS{
|
||||
SenderPhoneNumber: config.Providers.Twilio.From,
|
||||
RecipientPhoneNumber: user.VerifiedPhone,
|
||||
Content: content,
|
||||
@@ -19,19 +16,10 @@ func generateSms(user *view_model.NotifyUser, content string, config systemdefau
|
||||
if lastPhone {
|
||||
message.RecipientPhoneNumber = user.LastPhone
|
||||
}
|
||||
if provider.CanHandleMessage(message) {
|
||||
if config.DebugMode {
|
||||
return sendDebugPhone(message, config)
|
||||
}
|
||||
return provider.HandleMessage(message)
|
||||
}
|
||||
return caos_errs.ThrowInternalf(nil, "NOTIF-s8ipw", "Could not send init message: userid: %v", user.ID)
|
||||
}
|
||||
|
||||
func sendDebugPhone(message providers.Message, config systemdefaults.Notifications) error {
|
||||
provider, err := chat.InitChatProvider(config.Providers.Chat)
|
||||
channels, err := senders.SMSChannels(config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return provider.HandleMessage(message)
|
||||
return channels.HandleMessage(message)
|
||||
}
|
||||
|
Reference in New Issue
Block a user