mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 04:57:33 +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:
@@ -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