2020-05-20 14:28:08 +02:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
2020-12-18 16:47:45 +01:00
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
|
2022-04-27 01:01:45 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/command"
|
|
|
|
"github.com/zitadel/zitadel/internal/crypto"
|
|
|
|
v1 "github.com/zitadel/zitadel/internal/eventstore/v1"
|
|
|
|
queryv1 "github.com/zitadel/zitadel/internal/eventstore/v1/query"
|
|
|
|
"github.com/zitadel/zitadel/internal/notification/repository/eventsourcing/view"
|
|
|
|
"github.com/zitadel/zitadel/internal/query"
|
2020-05-20 14:28:08 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type Configs map[string]*Config
|
|
|
|
|
|
|
|
type Config struct {
|
2022-02-14 17:22:30 +01:00
|
|
|
MinimumCycleDuration time.Duration
|
2020-05-20 14:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type handler struct {
|
|
|
|
view *view.View
|
|
|
|
bulkLimit uint64
|
|
|
|
cycleDuration time.Duration
|
|
|
|
errorCountUntilSkip uint64
|
2020-12-18 16:47:45 +01:00
|
|
|
|
2021-02-23 15:13:04 +01:00
|
|
|
es v1.Eventstore
|
2020-12-18 16:47:45 +01:00
|
|
|
}
|
|
|
|
|
2021-02-23 15:13:04 +01:00
|
|
|
func (h *handler) Eventstore() v1.Eventstore {
|
2020-12-18 16:47:45 +01:00
|
|
|
return h.es
|
2020-05-20 14:28:08 +02:00
|
|
|
}
|
|
|
|
|
2022-03-14 07:55:09 +01:00
|
|
|
func Register(configs Configs,
|
|
|
|
bulkLimit,
|
|
|
|
errorCount uint64,
|
|
|
|
view *view.View,
|
|
|
|
es v1.Eventstore,
|
|
|
|
command *command.Commands,
|
|
|
|
queries *query.Queries,
|
2022-04-25 11:16:36 +02:00
|
|
|
externalPort uint16,
|
|
|
|
externalSecure bool,
|
2022-03-14 07:55:09 +01:00
|
|
|
dir http.FileSystem,
|
2022-05-02 16:41:57 +02:00
|
|
|
assetsPrefix,
|
|
|
|
fileSystemPath string,
|
2022-03-14 07:55:09 +01:00
|
|
|
userEncryption crypto.EncryptionAlgorithm,
|
|
|
|
smtpEncryption crypto.EncryptionAlgorithm,
|
|
|
|
smsEncryption crypto.EncryptionAlgorithm,
|
|
|
|
) []queryv1.Handler {
|
2021-12-16 15:21:37 +01:00
|
|
|
return []queryv1.Handler{
|
2020-12-18 16:47:45 +01:00
|
|
|
newNotifyUser(
|
|
|
|
handler{view, bulkLimit, configs.cycleDuration("User"), errorCount, es},
|
2022-01-21 08:52:12 +01:00
|
|
|
queries,
|
2020-12-18 16:47:45 +01:00
|
|
|
),
|
|
|
|
newNotification(
|
|
|
|
handler{view, bulkLimit, configs.cycleDuration("Notification"), errorCount, es},
|
2021-02-08 11:30:30 +01:00
|
|
|
command,
|
2021-12-16 15:21:37 +01:00
|
|
|
queries,
|
2022-04-25 11:16:36 +02:00
|
|
|
externalPort,
|
|
|
|
externalSecure,
|
2020-12-18 16:47:45 +01:00
|
|
|
dir,
|
2022-02-14 17:22:30 +01:00
|
|
|
assetsPrefix,
|
2022-05-02 16:41:57 +02:00
|
|
|
fileSystemPath,
|
2022-03-14 07:55:09 +01:00
|
|
|
userEncryption,
|
|
|
|
smtpEncryption,
|
|
|
|
smsEncryption,
|
2020-12-18 16:47:45 +01:00
|
|
|
),
|
2020-05-20 14:28:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (configs Configs) cycleDuration(viewModel string) time.Duration {
|
|
|
|
c, ok := configs[viewModel]
|
|
|
|
if !ok {
|
2022-01-24 15:22:27 +01:00
|
|
|
return 1 * time.Minute
|
2020-05-20 14:28:08 +02:00
|
|
|
}
|
2022-02-14 17:22:30 +01:00
|
|
|
return c.MinimumCycleDuration
|
2020-05-20 14:28:08 +02:00
|
|
|
}
|
2020-07-28 09:42:21 +02:00
|
|
|
|
|
|
|
func (h *handler) MinimumCycleDuration() time.Duration {
|
|
|
|
return h.cycleDuration
|
|
|
|
}
|
|
|
|
|
2020-12-22 12:27:55 +01:00
|
|
|
func (h *handler) LockDuration() time.Duration {
|
|
|
|
return h.cycleDuration / 3
|
|
|
|
}
|
|
|
|
|
2020-07-28 09:42:21 +02:00
|
|
|
func (h *handler) QueryLimit() uint64 {
|
|
|
|
return h.bulkLimit
|
|
|
|
}
|