mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 19:17:32 +00:00
refactor: rename config structs (#5459)
This commit is contained in:
@@ -19,7 +19,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/notification/messages"
|
||||
)
|
||||
|
||||
func InitFSChannel(config FSConfig) (channels.NotificationChannel, error) {
|
||||
func InitFSChannel(config Config) (channels.NotificationChannel, error) {
|
||||
if err := os.MkdirAll(config.Path, os.ModePerm); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package fs
|
||||
|
||||
type FSConfig struct {
|
||||
type Config struct {
|
||||
Enabled bool
|
||||
Compact bool
|
||||
Path string
|
||||
|
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/notification/channels"
|
||||
)
|
||||
|
||||
func InitStdoutChannel(config LogConfig) channels.NotificationChannel {
|
||||
func InitStdoutChannel(config Config) channels.NotificationChannel {
|
||||
|
||||
logging.Log("NOTIF-D0164").Debug("successfully initialized stdout email and sms channel")
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package log
|
||||
|
||||
type LogConfig struct {
|
||||
type Config struct {
|
||||
Enabled bool
|
||||
Compact bool
|
||||
}
|
||||
|
@@ -22,7 +22,7 @@ type Email struct {
|
||||
senderName string
|
||||
}
|
||||
|
||||
func InitSMTPChannel(ctx context.Context, getSMTPConfig func(ctx context.Context) (*EmailConfig, error)) (*Email, error) {
|
||||
func InitSMTPChannel(ctx context.Context, getSMTPConfig func(ctx context.Context) (*Config, error)) (*Email, error) {
|
||||
smtpConfig, err := getSMTPConfig(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package smtp
|
||||
|
||||
type EmailConfig struct {
|
||||
type Config struct {
|
||||
SMTP SMTP
|
||||
Tls bool
|
||||
From string
|
||||
|
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/notification/messages"
|
||||
)
|
||||
|
||||
func InitTwilioChannel(config TwilioConfig) channels.NotificationChannel {
|
||||
func InitTwilioChannel(config Config) channels.NotificationChannel {
|
||||
client := twilio.NewClient(config.SID, config.Token, nil)
|
||||
|
||||
logging.Debug("successfully initialized twilio sms channel")
|
||||
|
@@ -1,11 +1,11 @@
|
||||
package twilio
|
||||
|
||||
type TwilioConfig struct {
|
||||
type Config struct {
|
||||
SID string
|
||||
Token string
|
||||
SenderNumber string
|
||||
}
|
||||
|
||||
func (t *TwilioConfig) IsValid() bool {
|
||||
func (t *Config) IsValid() bool {
|
||||
return t.SID != "" && t.Token != "" && t.SenderNumber != ""
|
||||
}
|
||||
|
@@ -617,7 +617,7 @@ func (p *notificationsProjection) checkIfAlreadyHandled(ctx context.Context, eve
|
||||
}
|
||||
return len(events) > 0, nil
|
||||
}
|
||||
func (p *notificationsProjection) getSMTPConfig(ctx context.Context) (*smtp.EmailConfig, error) {
|
||||
func (p *notificationsProjection) getSMTPConfig(ctx context.Context) (*smtp.Config, error) {
|
||||
config, err := p.queries.SMTPConfigByAggregateID(ctx, authz.GetInstance(ctx).InstanceID())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -626,7 +626,7 @@ func (p *notificationsProjection) getSMTPConfig(ctx context.Context) (*smtp.Emai
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &smtp.EmailConfig{
|
||||
return &smtp.Config{
|
||||
From: config.SenderAddress,
|
||||
FromName: config.SenderName,
|
||||
Tls: config.TLS,
|
||||
@@ -639,7 +639,7 @@ func (p *notificationsProjection) getSMTPConfig(ctx context.Context) (*smtp.Emai
|
||||
}
|
||||
|
||||
// Read iam twilio config
|
||||
func (p *notificationsProjection) getTwilioConfig(ctx context.Context) (*twilio.TwilioConfig, error) {
|
||||
func (p *notificationsProjection) getTwilioConfig(ctx context.Context) (*twilio.Config, error) {
|
||||
active, err := query.NewSMSProviderStateQuery(domain.SMSConfigStateActive)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -655,7 +655,7 @@ func (p *notificationsProjection) getTwilioConfig(ctx context.Context) (*twilio.
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &twilio.TwilioConfig{
|
||||
return &twilio.Config{
|
||||
SID: config.TwilioConfig.SID,
|
||||
Token: token,
|
||||
SenderNumber: config.TwilioConfig.SenderNumber,
|
||||
@@ -663,24 +663,24 @@ func (p *notificationsProjection) getTwilioConfig(ctx context.Context) (*twilio.
|
||||
}
|
||||
|
||||
// Read iam filesystem provider config
|
||||
func (p *notificationsProjection) getFileSystemProvider(ctx context.Context) (*fs.FSConfig, error) {
|
||||
func (p *notificationsProjection) getFileSystemProvider(ctx context.Context) (*fs.Config, error) {
|
||||
config, err := p.queries.NotificationProviderByIDAndType(ctx, authz.GetInstance(ctx).InstanceID(), domain.NotificationProviderTypeFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &fs.FSConfig{
|
||||
return &fs.Config{
|
||||
Compact: config.Compact,
|
||||
Path: p.fileSystemPath,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Read iam log provider config
|
||||
func (p *notificationsProjection) getLogProvider(ctx context.Context) (*log.LogConfig, error) {
|
||||
func (p *notificationsProjection) getLogProvider(ctx context.Context) (*log.Config, error) {
|
||||
config, err := p.queries.NotificationProviderByIDAndType(ctx, authz.GetInstance(ctx).InstanceID(), domain.NotificationProviderTypeLog)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &log.LogConfig{
|
||||
return &log.Config{
|
||||
Compact: config.Compact,
|
||||
}, nil
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/notification/channels/log"
|
||||
)
|
||||
|
||||
func debugChannels(ctx context.Context, getFileSystemProvider func(ctx context.Context) (*fs.FSConfig, error), getLogProvider func(ctx context.Context) (*log.LogConfig, error)) []channels.NotificationChannel {
|
||||
func debugChannels(ctx context.Context, getFileSystemProvider func(ctx context.Context) (*fs.Config, error), getLogProvider func(ctx context.Context) (*log.Config, error)) []channels.NotificationChannel {
|
||||
var (
|
||||
providers []channels.NotificationChannel
|
||||
)
|
||||
|
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/notification/channels/smtp"
|
||||
)
|
||||
|
||||
func EmailChannels(ctx context.Context, emailConfig func(ctx context.Context) (*smtp.EmailConfig, error), getFileSystemProvider func(ctx context.Context) (*fs.FSConfig, error), getLogProvider func(ctx context.Context) (*log.LogConfig, error)) (chain *Chain, err error) {
|
||||
func EmailChannels(ctx context.Context, emailConfig func(ctx context.Context) (*smtp.Config, error), getFileSystemProvider func(ctx context.Context) (*fs.Config, error), getLogProvider func(ctx context.Context) (*log.Config, error)) (chain *Chain, err error) {
|
||||
channels := make([]channels.NotificationChannel, 0, 3)
|
||||
p, err := smtp.InitSMTPChannel(ctx, emailConfig)
|
||||
if err == nil {
|
||||
|
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/notification/channels/twilio"
|
||||
)
|
||||
|
||||
func SMSChannels(ctx context.Context, twilioConfig *twilio.TwilioConfig, getFileSystemProvider func(ctx context.Context) (*fs.FSConfig, error), getLogProvider func(ctx context.Context) (*log.LogConfig, error)) (chain *Chain, err error) {
|
||||
func SMSChannels(ctx context.Context, twilioConfig *twilio.Config, getFileSystemProvider func(ctx context.Context) (*fs.Config, error), getLogProvider func(ctx context.Context) (*log.Config, error)) (chain *Chain, err error) {
|
||||
channels := make([]channels.NotificationChannel, 0, 3)
|
||||
if twilioConfig != nil {
|
||||
channels = append(channels, twilio.InitTwilioChannel(*twilioConfig))
|
||||
|
@@ -24,9 +24,9 @@ func SendEmail(
|
||||
mailhtml string,
|
||||
translator *i18n.Translator,
|
||||
user *query.NotifyUser,
|
||||
emailConfig func(ctx context.Context) (*smtp.EmailConfig, error),
|
||||
getFileSystemProvider func(ctx context.Context) (*fs.FSConfig, error),
|
||||
getLogProvider func(ctx context.Context) (*log.LogConfig, error),
|
||||
emailConfig func(ctx context.Context) (*smtp.Config, error),
|
||||
getFileSystemProvider func(ctx context.Context) (*fs.Config, error),
|
||||
getLogProvider func(ctx context.Context) (*log.Config, error),
|
||||
colors *query.LabelPolicy,
|
||||
assetsPrefix string,
|
||||
) Notify {
|
||||
@@ -50,9 +50,9 @@ func SendSMSTwilio(
|
||||
ctx context.Context,
|
||||
translator *i18n.Translator,
|
||||
user *query.NotifyUser,
|
||||
twilioConfig func(ctx context.Context) (*twilio.TwilioConfig, error),
|
||||
getFileSystemProvider func(ctx context.Context) (*fs.FSConfig, error),
|
||||
getLogProvider func(ctx context.Context) (*log.LogConfig, error),
|
||||
twilioConfig func(ctx context.Context) (*twilio.Config, error),
|
||||
getFileSystemProvider func(ctx context.Context) (*fs.Config, error),
|
||||
getLogProvider func(ctx context.Context) (*log.Config, error),
|
||||
colors *query.LabelPolicy,
|
||||
assetsPrefix string,
|
||||
) Notify {
|
||||
|
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/query"
|
||||
)
|
||||
|
||||
func generateEmail(ctx context.Context, user *query.NotifyUser, subject, content string, smtpConfig func(ctx context.Context) (*smtp.EmailConfig, error), getFileSystemProvider func(ctx context.Context) (*fs.FSConfig, error), getLogProvider func(ctx context.Context) (*log.LogConfig, error), lastEmail bool) error {
|
||||
func generateEmail(ctx context.Context, user *query.NotifyUser, subject, content string, smtpConfig func(ctx context.Context) (*smtp.Config, error), getFileSystemProvider func(ctx context.Context) (*fs.Config, error), getLogProvider func(ctx context.Context) (*log.Config, error), lastEmail bool) error {
|
||||
content = html.UnescapeString(content)
|
||||
message := &messages.Email{
|
||||
Recipients: []string{user.VerifiedEmail},
|
||||
|
@@ -14,7 +14,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/query"
|
||||
)
|
||||
|
||||
func generateSms(ctx context.Context, user *query.NotifyUser, content string, getTwilioProvider func(ctx context.Context) (*twilio.TwilioConfig, error), getFileSystemProvider func(ctx context.Context) (*fs.FSConfig, error), getLogProvider func(ctx context.Context) (*log.LogConfig, error), lastPhone bool) error {
|
||||
func generateSms(ctx context.Context, user *query.NotifyUser, content string, getTwilioProvider func(ctx context.Context) (*twilio.Config, error), getFileSystemProvider func(ctx context.Context) (*fs.Config, error), getLogProvider func(ctx context.Context) (*log.Config, error), lastPhone bool) error {
|
||||
number := ""
|
||||
twilioConfig, err := getTwilioProvider(ctx)
|
||||
if err == nil {
|
||||
|
Reference in New Issue
Block a user