2022-01-06 09:00:24 +01:00
|
|
|
package senders
|
|
|
|
|
|
|
|
import (
|
2022-02-16 16:49:17 +01:00
|
|
|
"context"
|
|
|
|
|
2023-03-29 00:09:06 +02:00
|
|
|
"github.com/zitadel/logging"
|
2024-04-03 13:43:43 +03:00
|
|
|
|
2023-03-29 00:09:06 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
2022-05-13 14:13:07 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/notification/channels"
|
2022-04-27 01:01:45 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/notification/channels/fs"
|
2023-03-29 00:09:06 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/notification/channels/instrumenting"
|
2022-04-27 01:01:45 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/notification/channels/log"
|
|
|
|
"github.com/zitadel/zitadel/internal/notification/channels/smtp"
|
2022-01-06 09:00:24 +01:00
|
|
|
)
|
|
|
|
|
2023-03-29 00:09:06 +02:00
|
|
|
const smtpSpanName = "smtp.NotificationChannel"
|
|
|
|
|
|
|
|
func EmailChannels(
|
|
|
|
ctx context.Context,
|
2023-10-10 15:20:53 +02:00
|
|
|
emailConfig *smtp.Config,
|
2023-03-29 00:09:06 +02:00
|
|
|
getFileSystemProvider func(ctx context.Context) (*fs.Config, error),
|
|
|
|
getLogProvider func(ctx context.Context) (*log.Config, error),
|
|
|
|
successMetricName,
|
|
|
|
failureMetricName string,
|
|
|
|
) (chain *Chain, err error) {
|
2022-05-13 14:13:07 +02:00
|
|
|
channels := make([]channels.NotificationChannel, 0, 3)
|
2023-10-10 15:20:53 +02:00
|
|
|
p, err := smtp.InitChannel(emailConfig)
|
2023-03-29 00:09:06 +02:00
|
|
|
logging.WithFields(
|
|
|
|
"instance", authz.GetInstance(ctx).InstanceID(),
|
|
|
|
).OnError(err).Debug("initializing SMTP channel failed")
|
2022-03-07 14:22:37 +01:00
|
|
|
if err == nil {
|
2023-03-29 00:09:06 +02:00
|
|
|
channels = append(
|
|
|
|
channels,
|
|
|
|
instrumenting.Wrap(
|
|
|
|
ctx,
|
|
|
|
p,
|
|
|
|
smtpSpanName,
|
|
|
|
successMetricName,
|
|
|
|
failureMetricName,
|
|
|
|
),
|
|
|
|
)
|
2022-01-06 09:00:24 +01:00
|
|
|
}
|
2022-05-13 14:13:07 +02:00
|
|
|
channels = append(channels, debugChannels(ctx, getFileSystemProvider, getLogProvider)...)
|
2023-10-10 15:20:53 +02:00
|
|
|
return ChainChannels(channels...), nil
|
2022-01-06 09:00:24 +01:00
|
|
|
}
|