refactor: rename config structs (#5459)

This commit is contained in:
Elio Bischof
2023-03-16 18:24:30 +01:00
committed by GitHub
parent 1896f13952
commit 09abf06d4d
27 changed files with 92 additions and 92 deletions

View File

@@ -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
}

View File

@@ -1,6 +1,6 @@
package fs
type FSConfig struct {
type Config struct {
Enabled bool
Compact bool
Path string

View File

@@ -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")

View File

@@ -1,6 +1,6 @@
package log
type LogConfig struct {
type Config struct {
Enabled bool
Compact bool
}

View File

@@ -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

View File

@@ -1,6 +1,6 @@
package smtp
type EmailConfig struct {
type Config struct {
SMTP SMTP
Tls bool
From string

View File

@@ -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")

View File

@@ -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 != ""
}

View File

@@ -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
}

View File

@@ -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
)

View File

@@ -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 {

View File

@@ -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))

View File

@@ -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 {

View File

@@ -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},

View File

@@ -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 {