fix: sms providers (#3801)

This commit is contained in:
Livio Spring
2022-06-13 08:34:11 +02:00
committed by GitHub
parent 504d91d424
commit f57e3df39d
12 changed files with 295 additions and 45 deletions

View File

@@ -1,8 +1,9 @@
package twilio
import (
twilio "github.com/kevinburke/twilio-go"
"github.com/kevinburke/twilio-go"
"github.com/zitadel/logging"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/notification/channels"
"github.com/zitadel/zitadel/internal/notification/messages"
@@ -11,7 +12,7 @@ import (
func InitTwilioChannel(config TwilioConfig) channels.NotificationChannel {
client := twilio.NewClient(config.SID, config.Token, nil)
logging.Log("NOTIF-KaxDZ").Debug("successfully initialized twilio sms channel")
logging.Debug("successfully initialized twilio sms channel")
return channels.HandleMessageFunc(func(message channels.Message) error {
twilioMsg, ok := message.(*messages.SMS)
@@ -22,7 +23,7 @@ func InitTwilioChannel(config TwilioConfig) channels.NotificationChannel {
if err != nil {
return caos_errs.ThrowInternal(err, "TWILI-osk3S", "could not send message")
}
logging.LogWithFields("SMS_-f335c523", "message_sid", m.Sid, "status", m.Status).Debug("sms sent")
logging.WithFields("message_sid", m.Sid, "status", m.Status).Debug("sms sent")
return nil
})
}

View File

@@ -494,14 +494,18 @@ func (n *Notification) getSMTPConfig(ctx context.Context) (*smtp.EmailConfig, er
// Read iam twilio config
func (n *Notification) getTwilioConfig(ctx context.Context) (*twilio.TwilioConfig, error) {
config, err := n.queries.SMSProviderConfigByID(ctx, authz.GetInstance(ctx).InstanceID())
active, err := query.NewSMSProviderStateQuery(domain.SMSConfigStateActive)
if err != nil {
return nil, err
}
config, err := n.queries.SMSProviderConfig(ctx, active)
if err != nil {
return nil, err
}
if config.TwilioConfig == nil {
return nil, errors.ThrowNotFound(nil, "HANDLER-8nfow", "Errors.SMS.Twilio.NotFound")
}
token, err := crypto.Decrypt(config.TwilioConfig.Token, n.smtpPasswordCrypto)
token, err := crypto.Decrypt(config.TwilioConfig.Token, n.smsTokenCrypto)
if err != nil {
return nil, err
}