2025-04-29 06:03:47 +02:00
|
|
|
package domain
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/rand/v2"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"github.com/zitadel/zitadel/backend/v3/storage/cache"
|
|
|
|
"github.com/zitadel/zitadel/backend/v3/storage/database"
|
2025-05-08 15:30:06 +02:00
|
|
|
"github.com/zitadel/zitadel/backend/v3/telemetry/logging"
|
2025-04-29 06:03:47 +02:00
|
|
|
"github.com/zitadel/zitadel/backend/v3/telemetry/tracing"
|
|
|
|
"github.com/zitadel/zitadel/internal/crypto"
|
|
|
|
)
|
|
|
|
|
2025-05-08 19:01:55 +02:00
|
|
|
// The variables could also be moved to a struct.
|
|
|
|
// I just started with the singleton pattern and kept it like this.
|
2025-04-29 06:03:47 +02:00
|
|
|
var (
|
|
|
|
pool database.Pool
|
|
|
|
userCodeAlgorithm crypto.EncryptionAlgorithm
|
|
|
|
tracer tracing.Tracer
|
2025-05-08 15:30:06 +02:00
|
|
|
logger logging.Logger
|
2025-04-29 06:03:47 +02:00
|
|
|
|
2025-04-30 09:30:48 +02:00
|
|
|
userRepo func(database.QueryExecutor) UserRepository
|
2025-04-29 06:03:47 +02:00
|
|
|
instanceRepo func(database.QueryExecutor) InstanceRepository
|
|
|
|
cryptoRepo func(database.QueryExecutor) CryptoRepository
|
|
|
|
orgRepo func(database.QueryExecutor) OrgRepository
|
|
|
|
|
2025-05-08 15:30:06 +02:00
|
|
|
instanceCache cache.Cache[instanceCacheIndex, string, *Instance]
|
|
|
|
orgCache cache.Cache[orgCacheIndex, string, *Org]
|
2025-04-29 06:03:47 +02:00
|
|
|
|
|
|
|
generateID func() (string, error) = func() (string, error) {
|
|
|
|
return strconv.FormatUint(rand.Uint64(), 10), nil
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func SetPool(p database.Pool) {
|
|
|
|
pool = p
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetUserCodeAlgorithm(algorithm crypto.EncryptionAlgorithm) {
|
|
|
|
userCodeAlgorithm = algorithm
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetTracer(t tracing.Tracer) {
|
|
|
|
tracer = t
|
|
|
|
}
|
|
|
|
|
2025-05-08 15:30:06 +02:00
|
|
|
func SetLogger(l logging.Logger) {
|
|
|
|
logger = l
|
|
|
|
}
|
|
|
|
|
2025-04-30 09:30:48 +02:00
|
|
|
func SetUserRepository(repo func(database.QueryExecutor) UserRepository) {
|
|
|
|
userRepo = repo
|
|
|
|
}
|
2025-04-29 06:03:47 +02:00
|
|
|
|
2025-05-08 15:30:06 +02:00
|
|
|
func SetOrgRepository(repo func(database.QueryExecutor) OrgRepository) {
|
|
|
|
orgRepo = repo
|
|
|
|
}
|
|
|
|
|
2025-04-29 06:03:47 +02:00
|
|
|
func SetInstanceRepository(repo func(database.QueryExecutor) InstanceRepository) {
|
|
|
|
instanceRepo = repo
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetCryptoRepository(repo func(database.QueryExecutor) CryptoRepository) {
|
|
|
|
cryptoRepo = repo
|
|
|
|
}
|