2022-01-06 08:00:24 +00:00
|
|
|
package senders
|
|
|
|
|
|
|
|
import (
|
2022-03-07 13:22:37 +00:00
|
|
|
"context"
|
|
|
|
|
2024-09-06 13:11:36 +00:00
|
|
|
"github.com/zitadel/logging"
|
|
|
|
|
|
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
2022-05-13 12:13:07 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/notification/channels"
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/notification/channels/fs"
|
2023-03-28 22:09:06 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/notification/channels/instrumenting"
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/notification/channels/log"
|
2024-09-06 13:11:36 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/notification/channels/sms"
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/notification/channels/twilio"
|
2024-09-06 13:11:36 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/notification/channels/webhook"
|
2022-01-06 08:00:24 +00:00
|
|
|
)
|
|
|
|
|
2023-03-28 22:09:06 +00:00
|
|
|
const twilioSpanName = "twilio.NotificationChannel"
|
|
|
|
|
|
|
|
func SMSChannels(
|
|
|
|
ctx context.Context,
|
2024-09-06 13:11:36 +00:00
|
|
|
smsConfig *sms.Config,
|
2023-03-28 22:09:06 +00: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 12:13:07 +00:00
|
|
|
channels := make([]channels.NotificationChannel, 0, 3)
|
2024-09-06 13:11:36 +00:00
|
|
|
if smsConfig.TwilioConfig != nil {
|
2023-03-28 22:09:06 +00:00
|
|
|
channels = append(
|
|
|
|
channels,
|
|
|
|
instrumenting.Wrap(
|
|
|
|
ctx,
|
2024-09-06 13:11:36 +00:00
|
|
|
twilio.InitChannel(*smsConfig.TwilioConfig),
|
2023-03-28 22:09:06 +00:00
|
|
|
twilioSpanName,
|
|
|
|
successMetricName,
|
|
|
|
failureMetricName,
|
|
|
|
),
|
|
|
|
)
|
2022-03-07 13:22:37 +00:00
|
|
|
}
|
2024-09-06 13:11:36 +00:00
|
|
|
if smsConfig.WebhookConfig != nil {
|
|
|
|
webhookChannel, err := webhook.InitChannel(ctx, *smsConfig.WebhookConfig)
|
|
|
|
logging.WithFields(
|
|
|
|
"instance", authz.GetInstance(ctx).InstanceID(),
|
|
|
|
"callurl", smsConfig.WebhookConfig.CallURL,
|
|
|
|
).OnError(err).Debug("initializing JSON channel failed")
|
|
|
|
if err == nil {
|
|
|
|
channels = append(
|
|
|
|
channels,
|
|
|
|
instrumenting.Wrap(
|
|
|
|
ctx,
|
|
|
|
webhookChannel,
|
|
|
|
webhookSpanName,
|
|
|
|
successMetricName,
|
|
|
|
failureMetricName,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2022-05-13 12:13:07 +00:00
|
|
|
channels = append(channels, debugChannels(ctx, getFileSystemProvider, getLogProvider)...)
|
2023-10-10 13:20:53 +00:00
|
|
|
return ChainChannels(channels...), nil
|
2022-01-06 08:00:24 +00:00
|
|
|
}
|