mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 03:57:32 +00:00
feat: Instance domains (#3444)
* feat: add domain list * feat: domain tests * feat: add redirect url on adding instance domain * Update internal/command/instance_domain.go Co-authored-by: Livio Amstutz <livio.a@gmail.com> * feat: remove unused code * fix Co-authored-by: Livio Amstutz <livio.a@gmail.com>
This commit is contained in:
@@ -43,6 +43,10 @@ var (
|
||||
name: projection.InstanceColumnConsoleID,
|
||||
table: instanceTable,
|
||||
}
|
||||
InstanceColumnConsoleAppID = Column{
|
||||
name: projection.InstanceColumnConsoleAppID,
|
||||
table: instanceTable,
|
||||
}
|
||||
InstanceColumnSetupStarted = Column{
|
||||
name: projection.InstanceColumnSetUpStarted,
|
||||
table: instanceTable,
|
||||
@@ -65,6 +69,7 @@ type Instance struct {
|
||||
GlobalOrgID string
|
||||
IAMProjectID string
|
||||
ConsoleID string
|
||||
ConsoleAppID string
|
||||
DefaultLanguage language.Tag
|
||||
SetupStarted domain.Step
|
||||
SetupDone domain.Step
|
||||
@@ -83,6 +88,10 @@ func (i *Instance) ConsoleClientID() string {
|
||||
return i.ConsoleID
|
||||
}
|
||||
|
||||
func (i *Instance) ConsoleApplicationID() string {
|
||||
return i.ConsoleAppID
|
||||
}
|
||||
|
||||
func (i *Instance) RequestedDomain() string {
|
||||
return i.Host
|
||||
}
|
||||
@@ -142,6 +151,7 @@ func prepareInstanceQuery(host string) (sq.SelectBuilder, func(*sql.Row) (*Insta
|
||||
InstanceColumnGlobalOrgID.identifier(),
|
||||
InstanceColumnProjectID.identifier(),
|
||||
InstanceColumnConsoleID.identifier(),
|
||||
InstanceColumnConsoleAppID.identifier(),
|
||||
InstanceColumnSetupStarted.identifier(),
|
||||
InstanceColumnSetupDone.identifier(),
|
||||
InstanceColumnDefaultLanguage.identifier(),
|
||||
@@ -157,6 +167,7 @@ func prepareInstanceQuery(host string) (sq.SelectBuilder, func(*sql.Row) (*Insta
|
||||
&instance.GlobalOrgID,
|
||||
&instance.IAMProjectID,
|
||||
&instance.ConsoleID,
|
||||
&instance.ConsoleAppID,
|
||||
&instance.SetupStarted,
|
||||
&instance.SetupDone,
|
||||
&lang,
|
||||
|
@@ -19,6 +19,7 @@ type InstanceDomain struct {
|
||||
Domain string
|
||||
InstanceID string
|
||||
IsGenerated bool
|
||||
IsPrimary bool
|
||||
}
|
||||
|
||||
type InstanceDomains struct {
|
||||
@@ -47,8 +48,12 @@ func NewInstanceDomainInstanceIDSearchQuery(value string) (SearchQuery, error) {
|
||||
return NewTextQuery(InstanceDomainInstanceIDCol, value, TextEquals)
|
||||
}
|
||||
|
||||
func NewInstanceDomainGeneratedSearchQuery(verified bool) (SearchQuery, error) {
|
||||
return NewBoolQuery(InstanceDomainIsGeneratedCol, verified)
|
||||
func NewInstanceDomainGeneratedSearchQuery(generated bool) (SearchQuery, error) {
|
||||
return NewBoolQuery(InstanceDomainIsGeneratedCol, generated)
|
||||
}
|
||||
|
||||
func NewInstanceDomainPrimarySearchQuery(primary bool) (SearchQuery, error) {
|
||||
return NewBoolQuery(InstanceDomainIsPrimaryCol, primary)
|
||||
}
|
||||
|
||||
func (q *Queries) SearchInstanceDomains(ctx context.Context, queries *InstanceDomainSearchQueries) (domains *InstanceDomains, err error) {
|
||||
@@ -81,6 +86,7 @@ func prepareInstanceDomainsQuery() (sq.SelectBuilder, func(*sql.Rows) (*Instance
|
||||
InstanceDomainDomainCol.identifier(),
|
||||
InstanceDomainInstanceIDCol.identifier(),
|
||||
InstanceDomainIsGeneratedCol.identifier(),
|
||||
InstanceDomainIsPrimaryCol.identifier(),
|
||||
countColumn.identifier(),
|
||||
).From(instanceDomainsTable.identifier()).PlaceholderFormat(sq.Dollar),
|
||||
func(rows *sql.Rows) (*InstanceDomains, error) {
|
||||
@@ -95,6 +101,7 @@ func prepareInstanceDomainsQuery() (sq.SelectBuilder, func(*sql.Rows) (*Instance
|
||||
&domain.Domain,
|
||||
&domain.InstanceID,
|
||||
&domain.IsGenerated,
|
||||
&domain.IsPrimary,
|
||||
&count,
|
||||
)
|
||||
if err != nil {
|
||||
@@ -145,4 +152,8 @@ var (
|
||||
name: projection.InstanceDomainIsGeneratedCol,
|
||||
table: instanceDomainsTable,
|
||||
}
|
||||
InstanceDomainIsPrimaryCol = Column{
|
||||
name: projection.InstanceDomainIsPrimaryCol,
|
||||
table: instanceDomainsTable,
|
||||
}
|
||||
)
|
||||
|
@@ -31,6 +31,7 @@ func Test_InstanceDomainPrepares(t *testing.T) {
|
||||
` projections.instance_domains.domain,`+
|
||||
` projections.instance_domains.instance_id,`+
|
||||
` projections.instance_domains.is_generated,`+
|
||||
` projections.instance_domains.is_primary,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM projections.instance_domains`),
|
||||
nil,
|
||||
@@ -50,6 +51,7 @@ func Test_InstanceDomainPrepares(t *testing.T) {
|
||||
` projections.instance_domains.domain,`+
|
||||
` projections.instance_domains.instance_id,`+
|
||||
` projections.instance_domains.is_generated,`+
|
||||
` projections.instance_domains.is_primary,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM projections.instance_domains`),
|
||||
[]string{
|
||||
@@ -59,6 +61,7 @@ func Test_InstanceDomainPrepares(t *testing.T) {
|
||||
"domain",
|
||||
"instance_id",
|
||||
"is_generated",
|
||||
"is_primary",
|
||||
"count",
|
||||
},
|
||||
[][]driver.Value{
|
||||
@@ -69,6 +72,7 @@ func Test_InstanceDomainPrepares(t *testing.T) {
|
||||
"zitadel.ch",
|
||||
"inst-id",
|
||||
true,
|
||||
true,
|
||||
},
|
||||
},
|
||||
),
|
||||
@@ -85,6 +89,7 @@ func Test_InstanceDomainPrepares(t *testing.T) {
|
||||
Domain: "zitadel.ch",
|
||||
InstanceID: "inst-id",
|
||||
IsGenerated: true,
|
||||
IsPrimary: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -100,6 +105,7 @@ func Test_InstanceDomainPrepares(t *testing.T) {
|
||||
` projections.instance_domains.domain,`+
|
||||
` projections.instance_domains.instance_id,`+
|
||||
` projections.instance_domains.is_generated,`+
|
||||
` projections.instance_domains.is_primary,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM projections.instance_domains`),
|
||||
[]string{
|
||||
@@ -109,6 +115,7 @@ func Test_InstanceDomainPrepares(t *testing.T) {
|
||||
"domain",
|
||||
"instance_id",
|
||||
"is_generated",
|
||||
"is_primary",
|
||||
"count",
|
||||
},
|
||||
[][]driver.Value{
|
||||
@@ -119,6 +126,7 @@ func Test_InstanceDomainPrepares(t *testing.T) {
|
||||
"zitadel.ch",
|
||||
"inst-id",
|
||||
true,
|
||||
true,
|
||||
},
|
||||
{
|
||||
testNow,
|
||||
@@ -127,6 +135,7 @@ func Test_InstanceDomainPrepares(t *testing.T) {
|
||||
"zitadel.com",
|
||||
"inst-id",
|
||||
false,
|
||||
false,
|
||||
},
|
||||
},
|
||||
),
|
||||
@@ -143,6 +152,7 @@ func Test_InstanceDomainPrepares(t *testing.T) {
|
||||
Domain: "zitadel.ch",
|
||||
InstanceID: "inst-id",
|
||||
IsGenerated: true,
|
||||
IsPrimary: true,
|
||||
},
|
||||
{
|
||||
CreationDate: testNow,
|
||||
@@ -151,6 +161,7 @@ func Test_InstanceDomainPrepares(t *testing.T) {
|
||||
Domain: "zitadel.com",
|
||||
InstanceID: "inst-id",
|
||||
IsGenerated: false,
|
||||
IsPrimary: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -166,6 +177,7 @@ func Test_InstanceDomainPrepares(t *testing.T) {
|
||||
` projections.instance_domains.domain,`+
|
||||
` projections.instance_domains.instance_id,`+
|
||||
` projections.instance_domains.is_generated,`+
|
||||
` projections.instance_domains.is_primary,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM projections.instance_domains`),
|
||||
sql.ErrConnDone,
|
||||
|
@@ -39,6 +39,7 @@ func Test_InstancePrepares(t *testing.T) {
|
||||
` projections.instances.global_org_id,`+
|
||||
` projections.instances.iam_project_id,`+
|
||||
` projections.instances.console_client_id,`+
|
||||
` projections.instances.console_app_id,`+
|
||||
` projections.instances.setup_started,`+
|
||||
` projections.instances.setup_done,`+
|
||||
` projections.instances.default_language`+
|
||||
@@ -68,6 +69,7 @@ func Test_InstancePrepares(t *testing.T) {
|
||||
` projections.instances.global_org_id,`+
|
||||
` projections.instances.iam_project_id,`+
|
||||
` projections.instances.console_client_id,`+
|
||||
` projections.instances.console_app_id,`+
|
||||
` projections.instances.setup_started,`+
|
||||
` projections.instances.setup_done,`+
|
||||
` projections.instances.default_language`+
|
||||
@@ -79,6 +81,7 @@ func Test_InstancePrepares(t *testing.T) {
|
||||
"global_org_id",
|
||||
"iam_project_id",
|
||||
"console_client_id",
|
||||
"console_app_id",
|
||||
"setup_started",
|
||||
"setup_done",
|
||||
"default_language",
|
||||
@@ -90,6 +93,7 @@ func Test_InstancePrepares(t *testing.T) {
|
||||
"global-org-id",
|
||||
"project-id",
|
||||
"client-id",
|
||||
"app-id",
|
||||
domain.Step2,
|
||||
domain.Step1,
|
||||
"en",
|
||||
@@ -103,6 +107,7 @@ func Test_InstancePrepares(t *testing.T) {
|
||||
GlobalOrgID: "global-org-id",
|
||||
IAMProjectID: "project-id",
|
||||
ConsoleID: "client-id",
|
||||
ConsoleAppID: "app-id",
|
||||
SetupStarted: domain.Step2,
|
||||
SetupDone: domain.Step1,
|
||||
DefaultLanguage: language.English,
|
||||
@@ -121,6 +126,7 @@ func Test_InstancePrepares(t *testing.T) {
|
||||
` projections.instances.global_org_id,`+
|
||||
` projections.instances.iam_project_id,`+
|
||||
` projections.instances.console_client_id,`+
|
||||
` projections.instances.console_app_id,`+
|
||||
` projections.instances.setup_started,`+
|
||||
` projections.instances.setup_done,`+
|
||||
` projections.instances.default_language`+
|
||||
|
@@ -18,6 +18,7 @@ const (
|
||||
InstanceColumnGlobalOrgID = "global_org_id"
|
||||
InstanceColumnProjectID = "iam_project_id"
|
||||
InstanceColumnConsoleID = "console_client_id"
|
||||
InstanceColumnConsoleAppID = "console_app_id"
|
||||
InstanceColumnSequence = "sequence"
|
||||
InstanceColumnSetUpStarted = "setup_started"
|
||||
InstanceColumnSetUpDone = "setup_done"
|
||||
@@ -129,6 +130,7 @@ func (p *InstanceProjection) reduceConsoleSet(event eventstore.Event) (*handler.
|
||||
handler.NewCol(InstanceColumnChangeDate, e.CreationDate()),
|
||||
handler.NewCol(InstanceColumnSequence, e.Sequence()),
|
||||
handler.NewCol(InstanceColumnConsoleID, e.ClientID),
|
||||
handler.NewCol(InstanceColumnConsoleAppID, e.AppID),
|
||||
},
|
||||
), nil
|
||||
}
|
||||
|
@@ -19,6 +19,7 @@ const (
|
||||
InstanceDomainSequenceCol = "sequence"
|
||||
InstanceDomainDomainCol = "domain"
|
||||
InstanceDomainIsGeneratedCol = "is_generated"
|
||||
InstanceDomainIsPrimaryCol = "is_primary"
|
||||
)
|
||||
|
||||
type InstanceDomainProjection struct {
|
||||
@@ -37,6 +38,7 @@ func NewInstanceDomainProjection(ctx context.Context, config crdb.StatementHandl
|
||||
crdb.NewColumn(InstanceDomainSequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(InstanceDomainDomainCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(InstanceDomainIsGeneratedCol, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(InstanceDomainIsPrimaryCol, crdb.ColumnTypeBool),
|
||||
},
|
||||
crdb.NewPrimaryKey(InstanceDomainInstanceIDCol, InstanceDomainDomainCol),
|
||||
),
|
||||
@@ -54,6 +56,10 @@ func (p *InstanceDomainProjection) reducers() []handler.AggregateReducer {
|
||||
Event: instance.InstanceDomainAddedEventType,
|
||||
Reduce: p.reduceDomainAdded,
|
||||
},
|
||||
{
|
||||
Event: instance.InstanceDomainAddedEventType,
|
||||
Reduce: p.reduceDomainPrimarySet,
|
||||
},
|
||||
{
|
||||
Event: instance.InstanceDomainRemovedEventType,
|
||||
Reduce: p.reduceDomainRemoved,
|
||||
@@ -77,10 +83,43 @@ func (p *InstanceDomainProjection) reduceDomainAdded(event eventstore.Event) (*h
|
||||
handler.NewCol(InstanceDomainDomainCol, e.Domain),
|
||||
handler.NewCol(InstanceDomainInstanceIDCol, e.Aggregate().ID),
|
||||
handler.NewCol(InstanceDomainIsGeneratedCol, e.Generated),
|
||||
handler.NewCol(InstanceDomainIsPrimaryCol, false),
|
||||
},
|
||||
), nil
|
||||
}
|
||||
|
||||
func (p *InstanceDomainProjection) reduceDomainPrimarySet(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*instance.DomainPrimarySetEvent)
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-f8nlw", "reduce.wrong.event.type %s", instance.InstanceDomainPrimarySetEventType)
|
||||
}
|
||||
return crdb.NewMultiStatement(
|
||||
e,
|
||||
crdb.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(InstanceDomainChangeDateCol, e.CreationDate()),
|
||||
handler.NewCol(InstanceDomainSequenceCol, e.Sequence()),
|
||||
handler.NewCol(InstanceDomainIsPrimaryCol, false),
|
||||
},
|
||||
[]handler.Condition{
|
||||
handler.NewCond(InstanceDomainInstanceIDCol, e.Aggregate().InstanceID),
|
||||
handler.NewCond(InstanceDomainIsPrimaryCol, true),
|
||||
},
|
||||
),
|
||||
crdb.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(InstanceDomainChangeDateCol, e.CreationDate()),
|
||||
handler.NewCol(InstanceDomainSequenceCol, e.Sequence()),
|
||||
handler.NewCol(InstanceDomainIsPrimaryCol, true),
|
||||
},
|
||||
[]handler.Condition{
|
||||
handler.NewCond(InstanceDomainDomainCol, e.Domain),
|
||||
handler.NewCond(InstanceDomainInstanceIDCol, e.Aggregate().ID),
|
||||
},
|
||||
),
|
||||
), nil
|
||||
}
|
||||
|
||||
func (p *InstanceDomainProjection) reduceDomainRemoved(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*instance.DomainRemovedEvent)
|
||||
if !ok {
|
||||
|
@@ -38,7 +38,7 @@ func TestInstanceDomainProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO projections.instance_domains (creation_date, change_date, sequence, domain, instance_id, is_generated) VALUES ($1, $2, $3, $4, $5, $6)",
|
||||
expectedStmt: "INSERT INTO projections.instance_domains (creation_date, change_date, sequence, domain, instance_id, is_generated, is_primary) VALUES ($1, $2, $3, $4, $5, $6, $7)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
anyArg{},
|
||||
@@ -46,6 +46,7 @@ func TestInstanceDomainProjection_reduces(t *testing.T) {
|
||||
"domain.new",
|
||||
"agg-id",
|
||||
true,
|
||||
false,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
Reference in New Issue
Block a user