mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 10:47:37 +00:00
fixup! added first event
This commit is contained in:
309
backend/v3/storage/database/events_testing/id_provider_test.go
Normal file
309
backend/v3/storage/database/events_testing/id_provider_test.go
Normal file
@@ -0,0 +1,309 @@
|
||||
//go:build integration
|
||||
|
||||
package events_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/brianvoe/gofakeit/v6"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/zitadel/zitadel/backend/v3/domain"
|
||||
"github.com/zitadel/zitadel/backend/v3/storage/database/repository"
|
||||
"github.com/zitadel/zitadel/internal/integration"
|
||||
"github.com/zitadel/zitadel/pkg/grpc/admin"
|
||||
"github.com/zitadel/zitadel/pkg/grpc/idp"
|
||||
idp_grpc "github.com/zitadel/zitadel/pkg/grpc/idp"
|
||||
)
|
||||
|
||||
func TestServer_TestIDProviderReduces(t *testing.T) {
|
||||
instanceID := Instance.ID()
|
||||
|
||||
t.Run("test idp add reduces", func(t *testing.T) {
|
||||
name := gofakeit.Name()
|
||||
|
||||
beforeCreate := time.Now()
|
||||
addOCID, err := AdminClient.AddOIDCIDP(CTX, &admin.AddOIDCIDPRequest{
|
||||
Name: name,
|
||||
StylingType: idp_grpc.IDPStylingType_STYLING_TYPE_GOOGLE,
|
||||
ClientId: "clientID",
|
||||
ClientSecret: "clientSecret",
|
||||
Issuer: "issuer",
|
||||
Scopes: []string{"scope"},
|
||||
DisplayNameMapping: idp.OIDCMappingField_OIDC_MAPPING_FIELD_EMAIL,
|
||||
UsernameMapping: idp.OIDCMappingField_OIDC_MAPPING_FIELD_EMAIL,
|
||||
AutoRegister: true,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
afterCreate := time.Now()
|
||||
|
||||
idpRepo := repository.IDProviderRepository(pool)
|
||||
|
||||
retryDuration, tick := integration.WaitForAndTickWithMaxDuration(CTX, time.Minute)
|
||||
assert.EventuallyWithT(t, func(t *assert.CollectT) {
|
||||
idp, err := idpRepo.Get(CTX,
|
||||
idpRepo.NameCondition(name),
|
||||
instanceID,
|
||||
nil,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
// event iam.idp.config.added
|
||||
assert.Equal(t, addOCID.IdpId, idp.ID)
|
||||
assert.Equal(t, name, idp.Name)
|
||||
assert.Equal(t, instanceID, idp.InstanceID)
|
||||
assert.Equal(t, domain.IDPStateActive.String(), idp.State)
|
||||
assert.Equal(t, true, idp.AllowAutoCreation)
|
||||
assert.Equal(t, int16(idp_grpc.IDPStylingType_STYLING_TYPE_GOOGLE), idp.StylingType)
|
||||
assert.WithinRange(t, idp.UpdatedAt, beforeCreate, afterCreate)
|
||||
assert.WithinRange(t, idp.CreatedAt, beforeCreate, afterCreate)
|
||||
}, retryDuration, tick)
|
||||
})
|
||||
|
||||
t.Run("test idp update reduces", func(t *testing.T) {
|
||||
name := gofakeit.Name()
|
||||
|
||||
addOCID, err := AdminClient.AddOIDCIDP(CTX, &admin.AddOIDCIDPRequest{
|
||||
Name: name,
|
||||
StylingType: idp_grpc.IDPStylingType_STYLING_TYPE_GOOGLE,
|
||||
ClientId: "clientID",
|
||||
ClientSecret: "clientSecret",
|
||||
Issuer: "issuer",
|
||||
Scopes: []string{"scope"},
|
||||
DisplayNameMapping: idp.OIDCMappingField_OIDC_MAPPING_FIELD_EMAIL,
|
||||
UsernameMapping: idp.OIDCMappingField_OIDC_MAPPING_FIELD_EMAIL,
|
||||
AutoRegister: true,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
name = "new_" + name
|
||||
|
||||
beforeCreate := time.Now()
|
||||
_, err = AdminClient.UpdateIDP(CTX, &admin.UpdateIDPRequest{
|
||||
IdpId: addOCID.IdpId,
|
||||
Name: name,
|
||||
StylingType: idp_grpc.IDPStylingType_STYLING_TYPE_UNSPECIFIED,
|
||||
AutoRegister: false,
|
||||
})
|
||||
afterCreate := time.Now()
|
||||
require.NoError(t, err)
|
||||
|
||||
idpRepo := repository.IDProviderRepository(pool)
|
||||
|
||||
retryDuration, tick := integration.WaitForAndTickWithMaxDuration(CTX, time.Minute)
|
||||
assert.EventuallyWithT(t, func(t *assert.CollectT) {
|
||||
idp, err := idpRepo.Get(CTX,
|
||||
idpRepo.NameCondition(name),
|
||||
// idpRepo.IDCondition(addOCID.IdpId),
|
||||
instanceID,
|
||||
nil,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
// event "iam.idp.config.changed"
|
||||
assert.Equal(t, addOCID.IdpId, idp.ID)
|
||||
assert.Equal(t, name, idp.Name)
|
||||
assert.Equal(t, false, idp.AllowAutoCreation)
|
||||
assert.Equal(t, int16(idp_grpc.IDPStylingType_STYLING_TYPE_UNSPECIFIED), idp.StylingType)
|
||||
assert.WithinRange(t, idp.UpdatedAt, beforeCreate, afterCreate)
|
||||
}, retryDuration, tick)
|
||||
})
|
||||
|
||||
t.Run("test idp deactivate reduces", func(t *testing.T) {
|
||||
name := gofakeit.Name()
|
||||
|
||||
addOCID, err := AdminClient.AddOIDCIDP(CTX, &admin.AddOIDCIDPRequest{
|
||||
Name: name,
|
||||
StylingType: idp_grpc.IDPStylingType_STYLING_TYPE_GOOGLE,
|
||||
ClientId: "clientID",
|
||||
ClientSecret: "clientSecret",
|
||||
Issuer: "issuer",
|
||||
Scopes: []string{"scope"},
|
||||
DisplayNameMapping: idp.OIDCMappingField_OIDC_MAPPING_FIELD_EMAIL,
|
||||
UsernameMapping: idp.OIDCMappingField_OIDC_MAPPING_FIELD_EMAIL,
|
||||
AutoRegister: true,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
// deactivate idp
|
||||
beforeCreate := time.Now()
|
||||
_, err = AdminClient.DeactivateIDP(CTX, &admin.DeactivateIDPRequest{
|
||||
IdpId: addOCID.IdpId,
|
||||
})
|
||||
afterCreate := time.Now()
|
||||
require.NoError(t, err)
|
||||
|
||||
idpRepo := repository.IDProviderRepository(pool)
|
||||
|
||||
retryDuration, tick := integration.WaitForAndTickWithMaxDuration(CTX, time.Minute)
|
||||
assert.EventuallyWithT(t, func(t *assert.CollectT) {
|
||||
idp, err := idpRepo.Get(CTX,
|
||||
// idpRepo.NameCondition(name),
|
||||
idpRepo.IDCondition(addOCID.IdpId),
|
||||
instanceID,
|
||||
nil,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
// event "iam.idp.config.deactivated"
|
||||
assert.Equal(t, addOCID.IdpId, idp.ID)
|
||||
assert.Equal(t, domain.IDPStateInactive.String(), idp.State)
|
||||
assert.WithinRange(t, idp.UpdatedAt, beforeCreate, afterCreate)
|
||||
}, retryDuration, tick)
|
||||
})
|
||||
|
||||
t.Run("test idp reactivate reduces", func(t *testing.T) {
|
||||
name := gofakeit.Name()
|
||||
|
||||
addOCID, err := AdminClient.AddOIDCIDP(CTX, &admin.AddOIDCIDPRequest{
|
||||
Name: name,
|
||||
StylingType: idp_grpc.IDPStylingType_STYLING_TYPE_GOOGLE,
|
||||
ClientId: "clientID",
|
||||
ClientSecret: "clientSecret",
|
||||
Issuer: "issuer",
|
||||
Scopes: []string{"scope"},
|
||||
DisplayNameMapping: idp.OIDCMappingField_OIDC_MAPPING_FIELD_EMAIL,
|
||||
UsernameMapping: idp.OIDCMappingField_OIDC_MAPPING_FIELD_EMAIL,
|
||||
AutoRegister: true,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
idpRepo := repository.IDProviderRepository(pool)
|
||||
|
||||
// deactivate idp
|
||||
_, err = AdminClient.DeactivateIDP(CTX, &admin.DeactivateIDPRequest{
|
||||
IdpId: addOCID.IdpId,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
// wait for idp to be deactivated
|
||||
retryDuration, tick := integration.WaitForAndTickWithMaxDuration(CTX, time.Minute)
|
||||
assert.EventuallyWithT(t, func(t *assert.CollectT) {
|
||||
idp, err := idpRepo.Get(CTX,
|
||||
idpRepo.IDCondition(addOCID.IdpId),
|
||||
instanceID,
|
||||
nil,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, addOCID.IdpId, idp.ID)
|
||||
assert.Equal(t, domain.IDPStateInactive.String(), idp.State)
|
||||
}, retryDuration, tick)
|
||||
|
||||
// reactivate idp
|
||||
// beforeCreate := time.Now().Add(-time.Second)
|
||||
beforeCreate := time.Now()
|
||||
_, err = AdminClient.ReactivateIDP(CTX, &admin.ReactivateIDPRequest{
|
||||
IdpId: addOCID.IdpId,
|
||||
})
|
||||
afterCreate := time.Now()
|
||||
require.NoError(t, err)
|
||||
|
||||
retryDuration, tick = integration.WaitForAndTickWithMaxDuration(CTX, time.Minute)
|
||||
assert.EventuallyWithT(t, func(t *assert.CollectT) {
|
||||
idp, err := idpRepo.Get(CTX,
|
||||
// idpRepo.NameCondition(name),
|
||||
idpRepo.IDCondition(addOCID.IdpId),
|
||||
instanceID,
|
||||
nil,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
// event "iam.idp.config.reactivated"
|
||||
assert.Equal(t, addOCID.IdpId, idp.ID)
|
||||
assert.Equal(t, domain.IDPStateActive.String(), idp.State)
|
||||
assert.WithinRange(t, idp.UpdatedAt, beforeCreate, afterCreate)
|
||||
}, retryDuration, tick)
|
||||
})
|
||||
|
||||
t.Run("test idp remove reduces", func(t *testing.T) {
|
||||
name := gofakeit.Name()
|
||||
|
||||
// add idp
|
||||
addOCID, err := AdminClient.AddOIDCIDP(CTX, &admin.AddOIDCIDPRequest{
|
||||
Name: name,
|
||||
StylingType: idp_grpc.IDPStylingType_STYLING_TYPE_GOOGLE,
|
||||
ClientId: "clientID",
|
||||
ClientSecret: "clientSecret",
|
||||
Issuer: "issuer",
|
||||
Scopes: []string{"scope"},
|
||||
DisplayNameMapping: idp.OIDCMappingField_OIDC_MAPPING_FIELD_EMAIL,
|
||||
UsernameMapping: idp.OIDCMappingField_OIDC_MAPPING_FIELD_EMAIL,
|
||||
AutoRegister: true,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
idpRepo := repository.IDProviderRepository(pool)
|
||||
|
||||
// remove idp
|
||||
_, err = AdminClient.RemoveIDP(CTX, &admin.RemoveIDPRequest{
|
||||
IdpId: addOCID.IdpId,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
// retryDuration, tick := integration.WaitForAndTickWithMaxDuration(CTX, time.Minute)
|
||||
retryDuration, tick := integration.WaitForAndTickWithMaxDuration(CTX, time.Second*20)
|
||||
assert.EventuallyWithT(t, func(t *assert.CollectT) {
|
||||
idp, err := idpRepo.Delete(CTX,
|
||||
// idpRepo.NameCondition(name),
|
||||
idpRepo.IDCondition(addOCID.IdpId),
|
||||
instanceID,
|
||||
nil,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
// event "iam.idp.config.remove"
|
||||
assert.Nil(t, idp)
|
||||
}, retryDuration, tick)
|
||||
})
|
||||
|
||||
t.Run("test idp oidc addded reduces", func(t *testing.T) {
|
||||
name := gofakeit.Name()
|
||||
|
||||
// add idp
|
||||
addOCID, err := AdminClient.AddOIDCIDP(CTX, &admin.AddOIDCIDPRequest{
|
||||
Name: name,
|
||||
StylingType: idp_grpc.IDPStylingType_STYLING_TYPE_GOOGLE,
|
||||
ClientId: "clientID",
|
||||
ClientSecret: "clientSecret",
|
||||
Issuer: "issuer",
|
||||
Scopes: []string{"scope"},
|
||||
DisplayNameMapping: idp.OIDCMappingField_OIDC_MAPPING_FIELD_EMAIL,
|
||||
UsernameMapping: idp.OIDCMappingField_OIDC_MAPPING_FIELD_EMAIL,
|
||||
AutoRegister: true,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
idpRepo := repository.IDProviderRepository(pool)
|
||||
|
||||
// remove idp
|
||||
_, err = AdminClient.AddOIDCIDP(CTX, &admin.AddOIDCIDPRequest{
|
||||
Name: name,
|
||||
StylingType: idp_grpc.IDPStylingType_STYLING_TYPE_GOOGLE,
|
||||
ClientId: "clientID",
|
||||
ClientSecret: "clientSecret",
|
||||
Issuer: "issuer",
|
||||
Scopes: []string{"scope"},
|
||||
DisplayNameMapping: idp.OIDCMappingField_OIDC_MAPPING_FIELD_EMAIL,
|
||||
UsernameMapping: idp.OIDCMappingField_OIDC_MAPPING_FIELD_EMAIL,
|
||||
AutoRegister: true,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
// retryDuration, tick := integration.WaitForAndTickWithMaxDuration(CTX, time.Minute)
|
||||
retryDuration, tick := integration.WaitForAndTickWithMaxDuration(CTX, time.Second*20)
|
||||
assert.EventuallyWithT(t, func(t *assert.CollectT) {
|
||||
idp, err := idpRepo.Delete(CTX,
|
||||
// idpRepo.NameCondition(name),
|
||||
idpRepo.IDCondition(addOCID.IdpId),
|
||||
instanceID,
|
||||
nil,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
// event "iam.idp.config.remove"
|
||||
assert.Nil(t, idp)
|
||||
}, retryDuration, tick)
|
||||
})
|
||||
}
|
@@ -4,8 +4,10 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/zitadel/zitadel/backend/v3/domain"
|
||||
"github.com/zitadel/zitadel/internal/database"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/idpconfig"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
@@ -36,26 +38,26 @@ func (p *idpRelationalProjection) Reducers() []handler.AggregateReducer {
|
||||
Event: instance.IDPConfigAddedEventType,
|
||||
Reduce: p.reduceIDPRelationalAdded,
|
||||
},
|
||||
// {
|
||||
// Event: instance.IDPConfigChangedEventType,
|
||||
// Reduce: p.reduceIDPChanged,
|
||||
// },
|
||||
// {
|
||||
// Event: instance.IDPConfigDeactivatedEventType,
|
||||
// Reduce: p.reduceIDPDeactivated,
|
||||
// },
|
||||
// {
|
||||
// Event: instance.IDPConfigReactivatedEventType,
|
||||
// Reduce: p.reduceIDPReactivated,
|
||||
// },
|
||||
// {
|
||||
// Event: instance.IDPConfigRemovedEventType,
|
||||
// Reduce: p.reduceIDPRemoved,
|
||||
// },
|
||||
// {
|
||||
// Event: instance.IDPOIDCConfigAddedEventType,
|
||||
// Reduce: p.reduceOIDCConfigAdded,
|
||||
// },
|
||||
{
|
||||
Event: instance.IDPConfigChangedEventType,
|
||||
Reduce: p.reduceIDPRelationalChanged,
|
||||
},
|
||||
{
|
||||
Event: instance.IDPConfigDeactivatedEventType,
|
||||
Reduce: p.reduceIDRelationalPDeactivated,
|
||||
},
|
||||
{
|
||||
Event: instance.IDPConfigReactivatedEventType,
|
||||
Reduce: p.reduceIDPRelationalReactivated,
|
||||
},
|
||||
{
|
||||
Event: instance.IDPConfigRemovedEventType,
|
||||
Reduce: p.reduceIDPRelationalRemoved,
|
||||
},
|
||||
{
|
||||
Event: instance.IDPOIDCConfigAddedEventType,
|
||||
Reduce: p.reduceOIDCRelationalConfigAdded,
|
||||
},
|
||||
// {
|
||||
// Event: instance.IDPOIDCConfigChangedEventType,
|
||||
// Reduce: p.reduceOIDCConfigChanged,
|
||||
@@ -80,7 +82,7 @@ func (p *idpRelationalProjection) Reducers() []handler.AggregateReducer {
|
||||
func (p *idpRelationalProjection) reduceIDPRelationalAdded(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*instance.IDPConfigAddedEvent)
|
||||
if !ok {
|
||||
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-uYR5R", "reduce.wrong.event.type %s", org.OrgAddedEventType)
|
||||
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-fcUdQ", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPConfigAddedEventType, instance.IDPConfigAddedEventType})
|
||||
}
|
||||
|
||||
return handler.NewCreateStatement(
|
||||
@@ -94,162 +96,149 @@ func (p *idpRelationalProjection) reduceIDPRelationalAdded(event eventstore.Even
|
||||
handler.NewCol(IDPStylingTypeCol, e.StylingType),
|
||||
handler.NewCol(IDPRelationalAllowAutoCreationCol, e.AutoRegister),
|
||||
handler.NewCol(IDPTypeCol, domain.IDPTypeOIDC.String()),
|
||||
handler.NewCol(CreatedAt, e.CreationDate()),
|
||||
handler.NewCol(UpdatedAt, e.CreationDate()),
|
||||
handler.NewCol(CreatedAt, e.CreationDate()),
|
||||
},
|
||||
), nil
|
||||
}
|
||||
|
||||
// func (p *idpRelationalProjection) reduceIDPChanged(event eventstore.Event) (*handler.Statement, error) {
|
||||
// var idpEvent idpconfig.IDPConfigChangedEvent
|
||||
// switch e := event.(type) {
|
||||
// case *org.IDPConfigChangedEvent:
|
||||
// idpEvent = e.IDPConfigChangedEvent
|
||||
// case *instance.IDPConfigChangedEvent:
|
||||
// idpEvent = e.IDPConfigChangedEvent
|
||||
// default:
|
||||
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-NVvJD", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPConfigChangedEventType, instance.IDPConfigChangedEventType})
|
||||
// }
|
||||
func (p *idpRelationalProjection) reduceIDPRelationalChanged(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*instance.IDPConfigChangedEvent)
|
||||
if !ok {
|
||||
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-NVvJD", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPConfigChangedEventType, instance.IDPConfigChangedEventType})
|
||||
}
|
||||
|
||||
// cols := make([]handler.Column, 0, 5)
|
||||
// if idpEvent.Name != nil {
|
||||
// cols = append(cols, handler.NewCol(IDPNameCol, *idpEvent.Name))
|
||||
// }
|
||||
// if idpEvent.StylingType != nil {
|
||||
// cols = append(cols, handler.NewCol(IDPStylingTypeCol, *idpEvent.StylingType))
|
||||
// }
|
||||
// if idpEvent.AutoRegister != nil {
|
||||
// cols = append(cols, handler.NewCol(IDPAutoRegisterCol, *idpEvent.AutoRegister))
|
||||
// }
|
||||
// if len(cols) == 0 {
|
||||
// return handler.NewNoOpStatement(&idpEvent), nil
|
||||
// }
|
||||
cols := make([]handler.Column, 0, 5)
|
||||
if e.Name != nil {
|
||||
cols = append(cols, handler.NewCol(IDPNameCol, e.Name))
|
||||
}
|
||||
if e.StylingType != nil {
|
||||
cols = append(cols, handler.NewCol(IDPStylingTypeCol, e.StylingType))
|
||||
}
|
||||
if e.AutoRegister != nil {
|
||||
cols = append(cols, handler.NewCol(IDPRelationalAllowAutoCreationCol, e.AutoRegister))
|
||||
}
|
||||
if len(cols) == 0 {
|
||||
return handler.NewNoOpStatement(e), nil
|
||||
}
|
||||
|
||||
// cols = append(cols,
|
||||
// handler.NewCol(IDPChangeDateCol, idpEvent.CreationDate()),
|
||||
// handler.NewCol(IDPSequenceCol, idpEvent.Sequence()),
|
||||
// )
|
||||
cols = append(cols,
|
||||
handler.NewCol(UpdatedAt, e.CreationDate()),
|
||||
)
|
||||
|
||||
// return handler.NewUpdateStatement(
|
||||
// &idpEvent,
|
||||
// cols,
|
||||
// []handler.Condition{
|
||||
// handler.NewCond(IDPIDCol, idpEvent.ConfigID),
|
||||
// handler.NewCond(IDPInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
||||
// },
|
||||
// ), nil
|
||||
// }
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
cols,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(IDPIDCol, e.ConfigID),
|
||||
handler.NewCond(IDPInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
), nil
|
||||
}
|
||||
|
||||
// func (p *idpRelationalProjection) reduceIDPDeactivated(event eventstore.Event) (*handler.Statement, error) {
|
||||
// var idpEvent idpconfig.IDPConfigDeactivatedEvent
|
||||
// switch e := event.(type) {
|
||||
// case *org.IDPConfigDeactivatedEvent:
|
||||
// idpEvent = e.IDPConfigDeactivatedEvent
|
||||
// case *instance.IDPConfigDeactivatedEvent:
|
||||
// idpEvent = e.IDPConfigDeactivatedEvent
|
||||
// default:
|
||||
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-94O5l", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPConfigDeactivatedEventType, instance.IDPConfigDeactivatedEventType})
|
||||
// }
|
||||
func (p *idpRelationalProjection) reduceIDRelationalPDeactivated(event eventstore.Event) (*handler.Statement, error) {
|
||||
// var idpEvent idpconfig.IDPConfigDeactivatedEvent
|
||||
// switch e := event.(type) {
|
||||
// case *org.IDPConfigDeactivatedEvent:
|
||||
// idpEvent = e.IDPConfigDeactivatedEvent
|
||||
// case *instance.IDPConfigDeactivatedEvent:
|
||||
// idpEvent = e.IDPConfigDeactivatedEvent
|
||||
// default:
|
||||
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-94O5l", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPConfigDeactivatedEventType, instance.IDPConfigDeactivatedEventType})
|
||||
// }
|
||||
|
||||
// return handler.NewUpdateStatement(
|
||||
// &idpEvent,
|
||||
// []handler.Column{
|
||||
// handler.NewCol(IDPStateCol, domain.IDPConfigStateInactive),
|
||||
// handler.NewCol(IDPChangeDateCol, idpEvent.CreationDate()),
|
||||
// handler.NewCol(IDPSequenceCol, idpEvent.Sequence()),
|
||||
// },
|
||||
// []handler.Condition{
|
||||
// handler.NewCond(IDPIDCol, idpEvent.ConfigID),
|
||||
// handler.NewCond(IDPInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
||||
// },
|
||||
// ), nil
|
||||
// }
|
||||
e, ok := event.(*instance.IDPConfigDeactivatedEvent)
|
||||
if !ok {
|
||||
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-94O5l", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPConfigDeactivatedEventType, instance.IDPConfigDeactivatedEventType})
|
||||
}
|
||||
|
||||
// func (p *idpRelationalProjection) reduceIDPReactivated(event eventstore.Event) (*handler.Statement, error) {
|
||||
// var idpEvent idpconfig.IDPConfigReactivatedEvent
|
||||
// switch e := event.(type) {
|
||||
// case *org.IDPConfigReactivatedEvent:
|
||||
// idpEvent = e.IDPConfigReactivatedEvent
|
||||
// case *instance.IDPConfigReactivatedEvent:
|
||||
// idpEvent = e.IDPConfigReactivatedEvent
|
||||
// default:
|
||||
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-I8QyS", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPConfigReactivatedEventType, instance.IDPConfigReactivatedEventType})
|
||||
// }
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(IDPStateCol, domain.IDPStateInactive.String()),
|
||||
handler.NewCol(UpdatedAt, e.CreationDate()),
|
||||
},
|
||||
[]handler.Condition{
|
||||
handler.NewCond(IDPIDCol, e.ConfigID),
|
||||
handler.NewCond(IDPInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
), nil
|
||||
}
|
||||
|
||||
// return handler.NewUpdateStatement(
|
||||
// &idpEvent,
|
||||
// []handler.Column{
|
||||
// handler.NewCol(IDPStateCol, domain.IDPConfigStateActive),
|
||||
// handler.NewCol(IDPChangeDateCol, idpEvent.CreationDate()),
|
||||
// handler.NewCol(IDPSequenceCol, idpEvent.Sequence()),
|
||||
// },
|
||||
// []handler.Condition{
|
||||
// handler.NewCond(IDPIDCol, idpEvent.ConfigID),
|
||||
// handler.NewCond(IDPInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
||||
// },
|
||||
// ), nil
|
||||
// }
|
||||
func (p *idpRelationalProjection) reduceIDPRelationalReactivated(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*instance.IDPConfigReactivatedEvent)
|
||||
if !ok {
|
||||
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-I8QyS", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPConfigReactivatedEventType, instance.IDPConfigReactivatedEventType})
|
||||
}
|
||||
|
||||
// func (p *idpRelationalProjection) reduceIDPRemoved(event eventstore.Event) (*handler.Statement, error) {
|
||||
// var idpEvent idpconfig.IDPConfigRemovedEvent
|
||||
// switch e := event.(type) {
|
||||
// case *org.IDPConfigRemovedEvent:
|
||||
// idpEvent = e.IDPConfigRemovedEvent
|
||||
// case *instance.IDPConfigRemovedEvent:
|
||||
// idpEvent = e.IDPConfigRemovedEvent
|
||||
// default:
|
||||
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-B4zy8", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPConfigRemovedEventType, instance.IDPConfigRemovedEventType})
|
||||
// }
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(IDPStateCol, domain.IDPStateActive.String()),
|
||||
handler.NewCol(UpdatedAt, e.CreationDate()),
|
||||
},
|
||||
[]handler.Condition{
|
||||
handler.NewCond(IDPIDCol, e.ConfigID),
|
||||
handler.NewCond(IDPInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
), nil
|
||||
}
|
||||
|
||||
// return handler.NewDeleteStatement(
|
||||
// &idpEvent,
|
||||
// []handler.Condition{
|
||||
// handler.NewCond(IDPIDCol, idpEvent.ConfigID),
|
||||
// handler.NewCond(IDPInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
||||
// },
|
||||
// ), nil
|
||||
// }
|
||||
func (p *idpRelationalProjection) reduceIDPRelationalRemoved(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*instance.IDPConfigRemovedEvent)
|
||||
if !ok {
|
||||
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-B4zy8", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPConfigRemovedEventType, instance.IDPConfigRemovedEventType})
|
||||
}
|
||||
|
||||
// func (p *idpRelationalProjection) reduceOIDCConfigAdded(event eventstore.Event) (*handler.Statement, error) {
|
||||
// var idpEvent idpconfig.OIDCConfigAddedEvent
|
||||
// switch e := event.(type) {
|
||||
// case *org.IDPOIDCConfigAddedEvent:
|
||||
// idpEvent = e.OIDCConfigAddedEvent
|
||||
// case *instance.IDPOIDCConfigAddedEvent:
|
||||
// idpEvent = e.OIDCConfigAddedEvent
|
||||
// default:
|
||||
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-2FuAA", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPOIDCConfigAddedEventType, instance.IDPOIDCConfigAddedEventType})
|
||||
// }
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(IDPIDCol, e.ConfigID),
|
||||
handler.NewCond(IDPInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
), nil
|
||||
}
|
||||
|
||||
// return handler.NewMultiStatement(&idpEvent,
|
||||
// handler.AddUpdateStatement(
|
||||
// []handler.Column{
|
||||
// handler.NewCol(IDPChangeDateCol, idpEvent.CreationDate()),
|
||||
// handler.NewCol(IDPSequenceCol, idpEvent.Sequence()),
|
||||
// handler.NewCol(IDPTypeCol, domain.IDPConfigTypeOIDC),
|
||||
// },
|
||||
// []handler.Condition{
|
||||
// handler.NewCond(IDPIDCol, idpEvent.IDPConfigID),
|
||||
// handler.NewCond(IDPInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
||||
// },
|
||||
// ),
|
||||
// handler.AddCreateStatement(
|
||||
// []handler.Column{
|
||||
// handler.NewCol(OIDCConfigIDPIDCol, idpEvent.IDPConfigID),
|
||||
// handler.NewCol(OIDCConfigInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
||||
// handler.NewCol(OIDCConfigClientIDCol, idpEvent.ClientID),
|
||||
// handler.NewCol(OIDCConfigClientSecretCol, idpEvent.ClientSecret),
|
||||
// handler.NewCol(OIDCConfigIssuerCol, idpEvent.Issuer),
|
||||
// handler.NewCol(OIDCConfigScopesCol, database.TextArray[string](idpEvent.Scopes)),
|
||||
// handler.NewCol(OIDCConfigDisplayNameMappingCol, idpEvent.IDPDisplayNameMapping),
|
||||
// handler.NewCol(OIDCConfigUsernameMappingCol, idpEvent.UserNameMapping),
|
||||
// handler.NewCol(OIDCConfigAuthorizationEndpointCol, idpEvent.AuthorizationEndpoint),
|
||||
// handler.NewCol(OIDCConfigTokenEndpointCol, idpEvent.TokenEndpoint),
|
||||
// },
|
||||
// handler.WithTableSuffix(IDPOIDCSuffix),
|
||||
// ),
|
||||
// ), nil
|
||||
// }
|
||||
func (p *idpRelationalProjection) reduceOIDCRelationalConfigAdded(event eventstore.Event) (*handler.Statement, error) {
|
||||
var idpEvent idpconfig.OIDCConfigAddedEvent
|
||||
switch e := event.(type) {
|
||||
case *org.IDPOIDCConfigAddedEvent:
|
||||
idpEvent = e.OIDCConfigAddedEvent
|
||||
case *instance.IDPOIDCConfigAddedEvent:
|
||||
idpEvent = e.OIDCConfigAddedEvent
|
||||
default:
|
||||
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-2FuAA", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPOIDCConfigAddedEventType, instance.IDPOIDCConfigAddedEventType})
|
||||
}
|
||||
|
||||
return handler.NewMultiStatement(&idpEvent,
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(IDPChangeDateCol, idpEvent.CreationDate()),
|
||||
handler.NewCol(IDPSequenceCol, idpEvent.Sequence()),
|
||||
handler.NewCol(IDPTypeCol, domain.IDPConfigTypeOIDC),
|
||||
},
|
||||
[]handler.Condition{
|
||||
handler.NewCond(IDPIDCol, idpEvent.IDPConfigID),
|
||||
handler.NewCond(IDPInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
||||
},
|
||||
),
|
||||
handler.AddCreateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(OIDCConfigIDPIDCol, idpEvent.IDPConfigID),
|
||||
handler.NewCol(OIDCConfigInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
||||
handler.NewCol(OIDCConfigClientIDCol, idpEvent.ClientID),
|
||||
handler.NewCol(OIDCConfigClientSecretCol, idpEvent.ClientSecret),
|
||||
handler.NewCol(OIDCConfigIssuerCol, idpEvent.Issuer),
|
||||
handler.NewCol(OIDCConfigScopesCol, database.TextArray[string](idpEvent.Scopes)),
|
||||
handler.NewCol(OIDCConfigDisplayNameMappingCol, idpEvent.IDPDisplayNameMapping),
|
||||
handler.NewCol(OIDCConfigUsernameMappingCol, idpEvent.UserNameMapping),
|
||||
handler.NewCol(OIDCConfigAuthorizationEndpointCol, idpEvent.AuthorizationEndpoint),
|
||||
handler.NewCol(OIDCConfigTokenEndpointCol, idpEvent.TokenEndpoint),
|
||||
},
|
||||
handler.WithTableSuffix(IDPOIDCSuffix),
|
||||
),
|
||||
), nil
|
||||
}
|
||||
|
||||
// func (p *idpRelationalProjection) reduceOIDCConfigChanged(event eventstore.Event) (*handler.Statement, error) {
|
||||
// var idpEvent idpconfig.OIDCConfigChangedEvent
|
||||
|
Reference in New Issue
Block a user