2025-04-29 06:03:47 +02:00
|
|
|
package domain
|
|
|
|
|
2025-07-25 16:17:14 +02:00
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/zitadel/zitadel/backend/v3/storage/database"
|
|
|
|
)
|
2025-07-16 09:26:46 +02:00
|
|
|
|
2025-08-07 10:52:57 +02:00
|
|
|
//go:generate enumer -type DomainValidationType -transform lower -trimprefix DomainValidationType -sql
|
|
|
|
type DomainValidationType uint8
|
2025-07-16 09:26:46 +02:00
|
|
|
|
|
|
|
const (
|
2025-08-07 10:52:57 +02:00
|
|
|
DomainValidationTypeDNS DomainValidationType = iota
|
|
|
|
DomainValidationTypeHTTP
|
2025-07-16 09:26:46 +02:00
|
|
|
)
|
|
|
|
|
2025-08-07 10:52:57 +02:00
|
|
|
//go:generate enumer -type DomainType -transform lower -trimprefix DomainType -sql
|
|
|
|
type DomainType uint8
|
2025-07-28 09:10:33 +02:00
|
|
|
|
|
|
|
const (
|
2025-08-07 10:52:57 +02:00
|
|
|
DomainTypeCustom DomainType = iota
|
|
|
|
DomainTypeTrusted
|
2025-07-28 09:10:33 +02:00
|
|
|
)
|
|
|
|
|
2025-07-16 09:26:46 +02:00
|
|
|
type domainColumns interface {
|
|
|
|
// InstanceIDColumn returns the column for the instance id field.
|
2025-07-22 19:09:56 +02:00
|
|
|
// `qualified` indicates if the column should be qualified with the table name.
|
|
|
|
InstanceIDColumn(qualified bool) database.Column
|
2025-07-16 09:26:46 +02:00
|
|
|
// DomainColumn returns the column for the domain field.
|
2025-07-22 19:09:56 +02:00
|
|
|
// `qualified` indicates if the column should be qualified with the table name.
|
|
|
|
DomainColumn(qualified bool) database.Column
|
2025-07-16 09:26:46 +02:00
|
|
|
// IsPrimaryColumn returns the column for the is primary field.
|
2025-07-22 19:09:56 +02:00
|
|
|
// `qualified` indicates if the column should be qualified with the table name.
|
|
|
|
IsPrimaryColumn(qualified bool) database.Column
|
2025-07-16 09:26:46 +02:00
|
|
|
// CreatedAtColumn returns the column for the created at field.
|
2025-07-22 19:09:56 +02:00
|
|
|
// `qualified` indicates if the column should be qualified with the table name.
|
|
|
|
CreatedAtColumn(qualified bool) database.Column
|
2025-07-16 09:26:46 +02:00
|
|
|
// UpdatedAtColumn returns the column for the updated at field.
|
2025-07-22 19:09:56 +02:00
|
|
|
// `qualified` indicates if the column should be qualified with the table name.
|
|
|
|
UpdatedAtColumn(qualified bool) database.Column
|
2025-07-16 09:26:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type domainConditions interface {
|
|
|
|
// InstanceIDCondition returns a filter on the instance id field.
|
|
|
|
InstanceIDCondition(instanceID string) database.Condition
|
|
|
|
// DomainCondition returns a filter on the domain field.
|
|
|
|
DomainCondition(op database.TextOperation, domain string) database.Condition
|
|
|
|
// IsPrimaryCondition returns a filter on the is primary field.
|
|
|
|
IsPrimaryCondition(isPrimary bool) database.Condition
|
|
|
|
}
|
|
|
|
|
|
|
|
type domainChanges interface {
|
|
|
|
// SetPrimary sets a domain as primary based on the condition.
|
|
|
|
// All other domains will be set to non-primary.
|
|
|
|
//
|
|
|
|
// An error is returned if:
|
|
|
|
// - The condition identifies multiple domains.
|
|
|
|
// - The condition does not identify any domain.
|
|
|
|
//
|
|
|
|
// This is a no-op if:
|
|
|
|
// - The domain is already primary.
|
|
|
|
// - No domain matches the condition.
|
|
|
|
SetPrimary() database.Change
|
2025-07-25 16:17:14 +02:00
|
|
|
// SetUpdatedAt sets the updated at column.
|
|
|
|
// This is used for reducing events.
|
|
|
|
SetUpdatedAt(t time.Time) database.Change
|
2025-07-16 09:26:46 +02:00
|
|
|
}
|
|
|
|
|
2025-06-13 17:05:37 +02:00
|
|
|
// import (
|
|
|
|
// "math/rand/v2"
|
|
|
|
// "strconv"
|
2025-04-29 06:03:47 +02:00
|
|
|
|
2025-06-13 17:05:37 +02:00
|
|
|
// "github.com/zitadel/zitadel/backend/v3/storage/cache"
|
|
|
|
// "github.com/zitadel/zitadel/backend/v3/storage/database"
|
2025-04-29 06:03:47 +02:00
|
|
|
|
2025-06-13 17:05:37 +02:00
|
|
|
// // "github.com/zitadel/zitadel/backend/v3/telemetry/logging"
|
|
|
|
// "github.com/zitadel/zitadel/backend/v3/telemetry/tracing"
|
|
|
|
// "github.com/zitadel/zitadel/internal/crypto"
|
|
|
|
// )
|
2025-04-29 06:03:47 +02:00
|
|
|
|
2025-06-13 17:05:37 +02:00
|
|
|
// // The variables could also be moved to a struct.
|
|
|
|
// // I just started with the singleton pattern and kept it like this.
|
|
|
|
// var (
|
|
|
|
// pool database.Pool
|
|
|
|
// userCodeAlgorithm crypto.EncryptionAlgorithm
|
|
|
|
// tracer tracing.Tracer
|
|
|
|
// // logger logging.Logger
|
2025-04-29 06:03:47 +02:00
|
|
|
|
2025-06-13 17:05:37 +02:00
|
|
|
// userRepo func(database.QueryExecutor) UserRepository
|
|
|
|
// // instanceRepo func(database.QueryExecutor) InstanceRepository
|
|
|
|
// cryptoRepo func(database.QueryExecutor) CryptoRepository
|
|
|
|
// orgRepo func(database.QueryExecutor) OrgRepository
|
2025-04-29 06:03:47 +02:00
|
|
|
|
2025-06-13 17:05:37 +02:00
|
|
|
// // instanceCache cache.Cache[instanceCacheIndex, string, *Instance]
|
|
|
|
// orgCache cache.Cache[orgCacheIndex, string, *Org]
|
2025-04-29 06:03:47 +02:00
|
|
|
|
2025-06-13 17:05:37 +02:00
|
|
|
// generateID func() (string, error) = func() (string, error) {
|
|
|
|
// return strconv.FormatUint(rand.Uint64(), 10), nil
|
|
|
|
// }
|
|
|
|
// )
|
2025-04-29 06:03:47 +02:00
|
|
|
|
2025-06-13 17:05:37 +02:00
|
|
|
// func SetPool(p database.Pool) {
|
|
|
|
// pool = p
|
|
|
|
// }
|
2025-04-29 06:03:47 +02:00
|
|
|
|
2025-06-13 17:05:37 +02:00
|
|
|
// func SetUserCodeAlgorithm(algorithm crypto.EncryptionAlgorithm) {
|
|
|
|
// userCodeAlgorithm = algorithm
|
|
|
|
// }
|
2025-04-29 06:03:47 +02:00
|
|
|
|
2025-06-13 17:05:37 +02:00
|
|
|
// func SetTracer(t tracing.Tracer) {
|
|
|
|
// tracer = t
|
|
|
|
// }
|
2025-05-08 15:30:06 +02:00
|
|
|
|
2025-06-13 17:05:37 +02:00
|
|
|
// // func SetLogger(l logging.Logger) {
|
|
|
|
// // logger = l
|
|
|
|
// // }
|
2025-04-29 06:03:47 +02:00
|
|
|
|
2025-06-13 17:05:37 +02:00
|
|
|
// func SetUserRepository(repo func(database.QueryExecutor) UserRepository) {
|
|
|
|
// userRepo = repo
|
|
|
|
// }
|
2025-05-08 15:30:06 +02:00
|
|
|
|
2025-06-13 17:05:37 +02:00
|
|
|
// func SetOrgRepository(repo func(database.QueryExecutor) OrgRepository) {
|
|
|
|
// orgRepo = repo
|
|
|
|
// }
|
2025-04-29 06:03:47 +02:00
|
|
|
|
2025-06-13 17:05:37 +02:00
|
|
|
// // func SetInstanceRepository(repo func(database.QueryExecutor) InstanceRepository) {
|
|
|
|
// // instanceRepo = repo
|
|
|
|
// // }
|
|
|
|
|
|
|
|
// func SetCryptoRepository(repo func(database.QueryExecutor) CryptoRepository) {
|
|
|
|
// cryptoRepo = repo
|
|
|
|
// }
|