implementation done

This commit is contained in:
adlerhurst
2025-07-22 19:09:56 +02:00
parent bb2d0aff3f
commit 9c348c0429
14 changed files with 536 additions and 179 deletions

View File

@@ -2,28 +2,35 @@ package domain
import "github.com/zitadel/zitadel/backend/v3/storage/database"
type DomainVerificationType string
type DomainValidationType string
const (
DomainVerificationTypeDNS DomainVerificationType = "dns"
DomainVerificationTypeHTTP DomainVerificationType = "http"
DomainValidationTypeDNS DomainValidationType = "dns"
DomainValidationTypeHTTP DomainValidationType = "http"
)
type domainColumns interface {
// InstanceIDColumn returns the column for the instance id field.
InstanceIDColumn() database.Column
// `qualified` indicates if the column should be qualified with the table name.
InstanceIDColumn(qualified bool) database.Column
// DomainColumn returns the column for the domain field.
DomainColumn() database.Column
// `qualified` indicates if the column should be qualified with the table name.
DomainColumn(qualified bool) database.Column
// IsVerifiedColumn returns the column for the is verified field.
IsVerifiedColumn() database.Column
// `qualified` indicates if the column should be qualified with the table name.
IsVerifiedColumn(qualified bool) database.Column
// IsPrimaryColumn returns the column for the is primary field.
IsPrimaryColumn() database.Column
// VerificationTypeColumn returns the column for the verification type field.
VerificationTypeColumn() database.Column
// `qualified` indicates if the column should be qualified with the table name.
IsPrimaryColumn(qualified bool) database.Column
// ValidationTypeColumn returns the column for the verification type field.
// `qualified` indicates if the column should be qualified with the table name.
ValidationTypeColumn(qualified bool) database.Column
// CreatedAtColumn returns the column for the created at field.
CreatedAtColumn() database.Column
// `qualified` indicates if the column should be qualified with the table name.
CreatedAtColumn(qualified bool) database.Column
// UpdatedAtColumn returns the column for the updated at field.
UpdatedAtColumn() database.Column
// `qualified` indicates if the column should be qualified with the table name.
UpdatedAtColumn(qualified bool) database.Column
}
type domainConditions interface {
@@ -51,9 +58,9 @@ type domainChanges interface {
// - The domain is already primary.
// - No domain matches the condition.
SetPrimary() database.Change
// SetVerificationType sets the verification type column.
// SetValidationType sets the verification type column.
// If the domain is already verified, this is a no-op.
SetVerificationType(verificationType DomainVerificationType) database.Change
SetValidationType(verificationType DomainValidationType) database.Change
}
// import (

View File

@@ -18,6 +18,8 @@ type Instance struct {
DefaultLanguage string `json:"defaultLanguage,omitempty" db:"default_language"`
CreatedAt time.Time `json:"createdAt" db:"created_at"`
UpdatedAt time.Time `json:"updatedAt" db:"updated_at"`
Domains []*InstanceDomain `json:"domains,omitempty" db:"-"`
}
type instanceCacheIndex uint8
@@ -40,23 +42,32 @@ var _ cache.Entry[instanceCacheIndex, string] = (*Instance)(nil)
// instanceColumns define all the columns of the instance table.
type instanceColumns interface {
// IDColumn returns the column for the id field.
IDColumn() database.Column
// `qualified` indicates if the column should be qualified with the table name.
IDColumn(qualified bool) database.Column
// NameColumn returns the column for the name field.
NameColumn() database.Column
// `qualified` indicates if the column should be qualified with the table name.
NameColumn(qualified bool) database.Column
// DefaultOrgIDColumn returns the column for the default org id field
DefaultOrgIDColumn() database.Column
// `qualified` indicates if the column should be qualified with the table name.
DefaultOrgIDColumn(qualified bool) database.Column
// IAMProjectIDColumn returns the column for the default IAM org id field
IAMProjectIDColumn() database.Column
// `qualified` indicates if the column should be qualified with the table name.
IAMProjectIDColumn(qualified bool) database.Column
// ConsoleClientIDColumn returns the column for the default IAM org id field
ConsoleClientIDColumn() database.Column
// `qualified` indicates if the column should be qualified with the table name.
ConsoleClientIDColumn(qualified bool) database.Column
// ConsoleAppIDColumn returns the column for the console client id field
ConsoleAppIDColumn() database.Column
// `qualified` indicates if the column should be qualified with the table name.
ConsoleAppIDColumn(qualified bool) database.Column
// DefaultLanguageColumn returns the column for the default language field
DefaultLanguageColumn() database.Column
// `qualified` indicates if the column should be qualified with the table name.
DefaultLanguageColumn(qualified bool) database.Column
// CreatedAtColumn returns the column for the created at field.
CreatedAtColumn() database.Column
// `qualified` indicates if the column should be qualified with the table name.
CreatedAtColumn(qualified bool) database.Column
// UpdatedAtColumn returns the column for the updated at field.
UpdatedAtColumn() database.Column
// `qualified` indicates if the column should be qualified with the table name.
UpdatedAtColumn(qualified bool) database.Column
}
// instanceConditions define all the conditions for the instance table.
@@ -83,16 +94,27 @@ type InstanceRepository interface {
// Member returns the member repository which is a sub repository of the instance repository.
// Member() MemberRepository
Get(ctx context.Context, id string) (*Instance, error)
List(ctx context.Context, opts ...database.Condition) ([]*Instance, error)
Get(ctx context.Context, opts ...database.QueryOption) (*Instance, error)
List(ctx context.Context, opts ...database.QueryOption) ([]*Instance, error)
Create(ctx context.Context, instance *Instance) error
Update(ctx context.Context, id string, changes ...database.Change) (int64, error)
Delete(ctx context.Context, id string) (int64, error)
Domains() InstanceDomainRepository
// Domains returns the domain sub repository for the instance.
// If shouldLoad is true, the domains will be loaded from the database and written to the [Instance].Domains field.
// If shouldLoad is set to true once, the Domains field will be set event if shouldLoad is false in the future.
Domains(shouldLoad bool) InstanceDomainRepository
}
type CreateInstance struct {
Name string `json:"name"`
}
type InstanceQueryOption func(*InstanceQueryOpts)
type InstanceQueryOpts struct {
database.QueryOpts
JoinDomains bool
}

View File

@@ -2,17 +2,23 @@ package domain
import (
"context"
"encoding/json"
"time"
"github.com/zitadel/zitadel/backend/v3/storage/database"
)
type InstanceDomains struct {
domains []*InstanceDomain
Raw json.RawMessage
}
type InstanceDomain struct {
InstanceID string `json:"instanceId,omitempty" db:"instance_id"`
Domain string `json:"domain,omitempty" db:"domain"`
IsVerified bool `json:"isVerified,omitempty" db:"is_verified"`
IsPrimary bool `json:"isPrimary,omitempty" db:"is_primary"`
VerificationType DomainVerificationType `json:"verificationType,omitempty" db:"verification_type"`
ValidationType DomainValidationType `json:"validationType,omitempty" db:"validation_type"`
CreatedAt string `json:"createdAt,omitempty" db:"created_at"`
UpdatedAt string `json:"updatedAt,omitempty" db:"updated_at"`
@@ -23,7 +29,7 @@ type AddInstanceDomain struct {
Domain string `json:"domain,omitempty" db:"domain"`
IsVerified bool `json:"isVerified,omitempty" db:"is_verified"`
IsPrimary bool `json:"isPrimary,omitempty" db:"is_primary"`
VerificationType DomainVerificationType `json:"verificationType,omitempty" db:"verification_type"`
VerificationType DomainValidationType `json:"validationType,omitempty" db:"validation_type"`
// CreatedAt is the time when the domain was added.
// It is set by the repository and should not be set by the caller.
@@ -36,7 +42,8 @@ type AddInstanceDomain struct {
type instanceDomainColumns interface {
domainColumns
// IsGeneratedColumn returns the column for the is generated field.
IsGeneratedColumn() database.Column
// `qualified` indicates if the column should be qualified with the table name.
IsGeneratedColumn(qualified bool) database.Column
}
type instanceDomainConditions interface {

View File

@@ -19,8 +19,10 @@ type Organization struct {
Name string `json:"name,omitempty" db:"name"`
InstanceID string `json:"instanceId,omitempty" db:"instance_id"`
State OrgState `json:"state,omitempty" db:"state"`
CreatedAt time.Time `json:"createdAt,omitempty" db:"created_at"`
UpdatedAt time.Time `json:"updatedAt,omitempty" db:"updated_at"`
CreatedAt time.Time `json:"createdAt,omitzero" db:"created_at"`
UpdatedAt time.Time `json:"updatedAt,omitzero" db:"updated_at"`
Domains []*OrganizationDomain `json:"domains,omitempty" db:"-"`
}
// OrgIdentifierCondition is used to help specify a single Organization,
@@ -33,17 +35,23 @@ type OrgIdentifierCondition interface {
// organizationColumns define all the columns of the instance table.
type organizationColumns interface {
// IDColumn returns the column for the id field.
IDColumn() database.Column
// `qualified` indicates if the column should be qualified with the table name.
IDColumn(qualified bool) database.Column
// NameColumn returns the column for the name field.
NameColumn() database.Column
// `qualified` indicates if the column should be qualified with the table name.
NameColumn(qualified bool) database.Column
// InstanceIDColumn returns the column for the default org id field
InstanceIDColumn() database.Column
// `qualified` indicates if the column should be qualified with the table name.
InstanceIDColumn(qualified bool) database.Column
// StateColumn returns the column for the name field.
StateColumn() database.Column
// `qualified` indicates if the column should be qualified with the table name.
StateColumn(qualified bool) database.Column
// CreatedAtColumn returns the column for the created at field.
CreatedAtColumn() database.Column
// `qualified` indicates if the column should be qualified with the table name.
CreatedAtColumn(qualified bool) database.Column
// UpdatedAtColumn returns the column for the updated at field.
UpdatedAtColumn() database.Column
// `qualified` indicates if the column should be qualified with the table name.
UpdatedAtColumn(qualified bool) database.Column
}
// organizationConditions define all the conditions for the instance table.
@@ -72,15 +80,17 @@ type OrganizationRepository interface {
organizationConditions
organizationChanges
Get(ctx context.Context, id OrgIdentifierCondition, instance_id string, opts ...database.Condition) (*Organization, error)
List(ctx context.Context, conditions ...database.Condition) ([]*Organization, error)
Get(ctx context.Context, opts ...database.QueryOption) (*Organization, error)
List(ctx context.Context, opts ...database.QueryOption) ([]*Organization, error)
Create(ctx context.Context, instance *Organization) error
Update(ctx context.Context, id OrgIdentifierCondition, instance_id string, changes ...database.Change) (int64, error)
Delete(ctx context.Context, id OrgIdentifierCondition, instance_id string) (int64, error)
// Domains returns the domain sub repository for the organization.
Domains() OrganizationDomainRepository
// If shouldLoad is true, the domains will be loaded from the database and written to the [Instance].Domains field.
// If shouldLoad is set to true once, the Domains field will be set event if shouldLoad is false in the future.
Domains(shouldLoad bool) OrganizationDomainRepository
}
type CreateOrganization struct {

View File

@@ -13,7 +13,7 @@ type OrganizationDomain struct {
Domain string `json:"domain,omitempty" db:"domain"`
IsVerified bool `json:"isVerified,omitempty" db:"is_verified"`
IsPrimary bool `json:"isPrimary,omitempty" db:"is_primary"`
VerificationType DomainVerificationType `json:"verificationType,omitempty" db:"verification_type"`
ValidationType DomainValidationType `json:"validationType,omitempty" db:"validation_type"`
CreatedAt string `json:"createdAt,omitempty" db:"created_at"`
UpdatedAt string `json:"updatedAt,omitempty" db:"updated_at"`
@@ -25,7 +25,7 @@ type AddOrganizationDomain struct {
Domain string `json:"domain,omitempty" db:"domain"`
IsVerified bool `json:"isVerified,omitempty" db:"is_verified"`
IsPrimary bool `json:"isPrimary,omitempty" db:"is_primary"`
VerificationType DomainVerificationType `json:"verificationType,omitempty" db:"verification_type"`
ValidationType DomainValidationType `json:"validationType,omitempty" db:"validation_type"`
// CreatedAt is the time when the domain was added.
// It is set by the repository and should not be set by the caller.
@@ -38,7 +38,7 @@ type AddOrganizationDomain struct {
type organizationDomainColumns interface {
domainColumns
// OrgIDColumn returns the column for the org id field.
OrgIDColumn() database.Column
OrgIDColumn(qualified bool) database.Column
}
type organizationDomainConditions interface {