2023-03-28 22:09:06 +00:00
|
|
|
package notification
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-10-31 14:57:17 +00:00
|
|
|
"time"
|
2023-03-28 22:09:06 +00:00
|
|
|
|
|
|
|
"github.com/zitadel/zitadel/internal/command"
|
|
|
|
"github.com/zitadel/zitadel/internal/crypto"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
2024-01-25 16:28:20 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
2023-03-28 22:09:06 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/notification/handlers"
|
|
|
|
_ "github.com/zitadel/zitadel/internal/notification/statik"
|
|
|
|
"github.com/zitadel/zitadel/internal/query"
|
|
|
|
"github.com/zitadel/zitadel/internal/query/projection"
|
|
|
|
)
|
|
|
|
|
2024-01-25 16:28:20 +00:00
|
|
|
var projections []*handler.Handler
|
|
|
|
|
|
|
|
func Register(
|
2023-03-28 22:09:06 +00:00
|
|
|
ctx context.Context,
|
2024-10-31 14:57:17 +00:00
|
|
|
userHandlerCustomConfig, quotaHandlerCustomConfig, telemetryHandlerCustomConfig, backChannelLogoutHandlerCustomConfig projection.CustomConfig,
|
2023-07-06 06:38:13 +00:00
|
|
|
telemetryCfg handlers.TelemetryPusherConfig,
|
2023-07-06 17:31:08 +00:00
|
|
|
externalDomain string,
|
2023-03-28 22:09:06 +00:00
|
|
|
externalPort uint16,
|
|
|
|
externalSecure bool,
|
|
|
|
commands *command.Commands,
|
|
|
|
queries *query.Queries,
|
|
|
|
es *eventstore.Eventstore,
|
2024-10-31 14:57:17 +00:00
|
|
|
otpEmailTmpl, fileSystemPath string,
|
|
|
|
userEncryption, smtpEncryption, smsEncryption, keysEncryptionAlg crypto.EncryptionAlgorithm,
|
|
|
|
tokenLifetime time.Duration,
|
2023-03-28 22:09:06 +00:00
|
|
|
) {
|
2023-12-05 11:12:01 +00:00
|
|
|
q := handlers.NewNotificationQueries(queries, es, externalDomain, externalPort, externalSecure, fileSystemPath, userEncryption, smtpEncryption, smsEncryption)
|
2023-10-10 13:20:53 +00:00
|
|
|
c := newChannels(q)
|
2024-01-25 16:28:20 +00:00
|
|
|
projections = append(projections, handlers.NewUserNotifier(ctx, projection.ApplyCustomConfig(userHandlerCustomConfig), commands, q, c, otpEmailTmpl))
|
|
|
|
projections = append(projections, handlers.NewQuotaNotifier(ctx, projection.ApplyCustomConfig(quotaHandlerCustomConfig), commands, q, c))
|
2024-10-31 14:57:17 +00:00
|
|
|
projections = append(projections, handlers.NewBackChannelLogoutNotifier(
|
|
|
|
ctx,
|
|
|
|
projection.ApplyCustomConfig(backChannelLogoutHandlerCustomConfig),
|
|
|
|
commands,
|
|
|
|
q,
|
|
|
|
es,
|
|
|
|
keysEncryptionAlg,
|
|
|
|
c,
|
|
|
|
tokenLifetime,
|
|
|
|
))
|
2023-07-06 06:38:13 +00:00
|
|
|
if telemetryCfg.Enabled {
|
2024-01-25 16:28:20 +00:00
|
|
|
projections = append(projections, handlers.NewTelemetryPusher(ctx, telemetryCfg, projection.ApplyCustomConfig(telemetryHandlerCustomConfig), commands, q, c))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Start(ctx context.Context) {
|
|
|
|
for _, projection := range projections {
|
|
|
|
projection.Start(ctx)
|
2023-07-06 06:38:13 +00:00
|
|
|
}
|
2023-03-28 22:09:06 +00:00
|
|
|
}
|
2024-01-25 16:28:20 +00:00
|
|
|
|
2024-05-30 09:35:30 +00:00
|
|
|
func ProjectInstance(ctx context.Context) error {
|
|
|
|
for _, projection := range projections {
|
|
|
|
_, err := projection.Trigger(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-01-25 16:28:20 +00:00
|
|
|
func Projections() []*handler.Handler {
|
|
|
|
return projections
|
|
|
|
}
|