mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 13:19:21 +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"
|
"context"
|
||||||
|
|
||||||
"github.com/zitadel/zitadel/backend/v3/domain"
|
"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"
|
||||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
"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/instance"
|
||||||
"github.com/zitadel/zitadel/internal/repository/org"
|
"github.com/zitadel/zitadel/internal/repository/org"
|
||||||
"github.com/zitadel/zitadel/internal/zerrors"
|
"github.com/zitadel/zitadel/internal/zerrors"
|
||||||
@@ -36,26 +38,26 @@ func (p *idpRelationalProjection) Reducers() []handler.AggregateReducer {
|
|||||||
Event: instance.IDPConfigAddedEventType,
|
Event: instance.IDPConfigAddedEventType,
|
||||||
Reduce: p.reduceIDPRelationalAdded,
|
Reduce: p.reduceIDPRelationalAdded,
|
||||||
},
|
},
|
||||||
// {
|
{
|
||||||
// Event: instance.IDPConfigChangedEventType,
|
Event: instance.IDPConfigChangedEventType,
|
||||||
// Reduce: p.reduceIDPChanged,
|
Reduce: p.reduceIDPRelationalChanged,
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// Event: instance.IDPConfigDeactivatedEventType,
|
Event: instance.IDPConfigDeactivatedEventType,
|
||||||
// Reduce: p.reduceIDPDeactivated,
|
Reduce: p.reduceIDRelationalPDeactivated,
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// Event: instance.IDPConfigReactivatedEventType,
|
Event: instance.IDPConfigReactivatedEventType,
|
||||||
// Reduce: p.reduceIDPReactivated,
|
Reduce: p.reduceIDPRelationalReactivated,
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// Event: instance.IDPConfigRemovedEventType,
|
Event: instance.IDPConfigRemovedEventType,
|
||||||
// Reduce: p.reduceIDPRemoved,
|
Reduce: p.reduceIDPRelationalRemoved,
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// Event: instance.IDPOIDCConfigAddedEventType,
|
Event: instance.IDPOIDCConfigAddedEventType,
|
||||||
// Reduce: p.reduceOIDCConfigAdded,
|
Reduce: p.reduceOIDCRelationalConfigAdded,
|
||||||
// },
|
},
|
||||||
// {
|
// {
|
||||||
// Event: instance.IDPOIDCConfigChangedEventType,
|
// Event: instance.IDPOIDCConfigChangedEventType,
|
||||||
// Reduce: p.reduceOIDCConfigChanged,
|
// Reduce: p.reduceOIDCConfigChanged,
|
||||||
@@ -80,7 +82,7 @@ func (p *idpRelationalProjection) Reducers() []handler.AggregateReducer {
|
|||||||
func (p *idpRelationalProjection) reduceIDPRelationalAdded(event eventstore.Event) (*handler.Statement, error) {
|
func (p *idpRelationalProjection) reduceIDPRelationalAdded(event eventstore.Event) (*handler.Statement, error) {
|
||||||
e, ok := event.(*instance.IDPConfigAddedEvent)
|
e, ok := event.(*instance.IDPConfigAddedEvent)
|
||||||
if !ok {
|
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(
|
return handler.NewCreateStatement(
|
||||||
@@ -94,162 +96,149 @@ func (p *idpRelationalProjection) reduceIDPRelationalAdded(event eventstore.Even
|
|||||||
handler.NewCol(IDPStylingTypeCol, e.StylingType),
|
handler.NewCol(IDPStylingTypeCol, e.StylingType),
|
||||||
handler.NewCol(IDPRelationalAllowAutoCreationCol, e.AutoRegister),
|
handler.NewCol(IDPRelationalAllowAutoCreationCol, e.AutoRegister),
|
||||||
handler.NewCol(IDPTypeCol, domain.IDPTypeOIDC.String()),
|
handler.NewCol(IDPTypeCol, domain.IDPTypeOIDC.String()),
|
||||||
handler.NewCol(CreatedAt, e.CreationDate()),
|
|
||||||
handler.NewCol(UpdatedAt, e.CreationDate()),
|
handler.NewCol(UpdatedAt, e.CreationDate()),
|
||||||
|
handler.NewCol(CreatedAt, e.CreationDate()),
|
||||||
},
|
},
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// func (p *idpRelationalProjection) reduceIDPChanged(event eventstore.Event) (*handler.Statement, error) {
|
func (p *idpRelationalProjection) reduceIDPRelationalChanged(event eventstore.Event) (*handler.Statement, error) {
|
||||||
// var idpEvent idpconfig.IDPConfigChangedEvent
|
e, ok := event.(*instance.IDPConfigChangedEvent)
|
||||||
// switch e := event.(type) {
|
if !ok {
|
||||||
// case *org.IDPConfigChangedEvent:
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-NVvJD", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPConfigChangedEventType, instance.IDPConfigChangedEventType})
|
||||||
// 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})
|
|
||||||
// }
|
|
||||||
|
|
||||||
// cols := make([]handler.Column, 0, 5)
|
cols := make([]handler.Column, 0, 5)
|
||||||
// if idpEvent.Name != nil {
|
if e.Name != nil {
|
||||||
// cols = append(cols, handler.NewCol(IDPNameCol, *idpEvent.Name))
|
cols = append(cols, handler.NewCol(IDPNameCol, e.Name))
|
||||||
// }
|
}
|
||||||
// if idpEvent.StylingType != nil {
|
if e.StylingType != nil {
|
||||||
// cols = append(cols, handler.NewCol(IDPStylingTypeCol, *idpEvent.StylingType))
|
cols = append(cols, handler.NewCol(IDPStylingTypeCol, e.StylingType))
|
||||||
// }
|
}
|
||||||
// if idpEvent.AutoRegister != nil {
|
if e.AutoRegister != nil {
|
||||||
// cols = append(cols, handler.NewCol(IDPAutoRegisterCol, *idpEvent.AutoRegister))
|
cols = append(cols, handler.NewCol(IDPRelationalAllowAutoCreationCol, e.AutoRegister))
|
||||||
// }
|
}
|
||||||
// if len(cols) == 0 {
|
if len(cols) == 0 {
|
||||||
// return handler.NewNoOpStatement(&idpEvent), nil
|
return handler.NewNoOpStatement(e), nil
|
||||||
// }
|
}
|
||||||
|
|
||||||
// cols = append(cols,
|
cols = append(cols,
|
||||||
// handler.NewCol(IDPChangeDateCol, idpEvent.CreationDate()),
|
handler.NewCol(UpdatedAt, e.CreationDate()),
|
||||||
// handler.NewCol(IDPSequenceCol, idpEvent.Sequence()),
|
)
|
||||||
// )
|
|
||||||
|
|
||||||
// return handler.NewUpdateStatement(
|
return handler.NewUpdateStatement(
|
||||||
// &idpEvent,
|
e,
|
||||||
// cols,
|
cols,
|
||||||
// []handler.Condition{
|
[]handler.Condition{
|
||||||
// handler.NewCond(IDPIDCol, idpEvent.ConfigID),
|
handler.NewCond(IDPIDCol, e.ConfigID),
|
||||||
// handler.NewCond(IDPInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
handler.NewCond(IDPInstanceIDCol, e.Aggregate().InstanceID),
|
||||||
// },
|
},
|
||||||
// ), nil
|
), nil
|
||||||
// }
|
}
|
||||||
|
|
||||||
// func (p *idpRelationalProjection) reduceIDPDeactivated(event eventstore.Event) (*handler.Statement, error) {
|
func (p *idpRelationalProjection) reduceIDRelationalPDeactivated(event eventstore.Event) (*handler.Statement, error) {
|
||||||
// var idpEvent idpconfig.IDPConfigDeactivatedEvent
|
// var idpEvent idpconfig.IDPConfigDeactivatedEvent
|
||||||
// switch e := event.(type) {
|
// switch e := event.(type) {
|
||||||
// case *org.IDPConfigDeactivatedEvent:
|
// case *org.IDPConfigDeactivatedEvent:
|
||||||
// idpEvent = e.IDPConfigDeactivatedEvent
|
// idpEvent = e.IDPConfigDeactivatedEvent
|
||||||
// case *instance.IDPConfigDeactivatedEvent:
|
// case *instance.IDPConfigDeactivatedEvent:
|
||||||
// idpEvent = e.IDPConfigDeactivatedEvent
|
// idpEvent = e.IDPConfigDeactivatedEvent
|
||||||
// default:
|
// default:
|
||||||
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-94O5l", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPConfigDeactivatedEventType, instance.IDPConfigDeactivatedEventType})
|
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-94O5l", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPConfigDeactivatedEventType, instance.IDPConfigDeactivatedEventType})
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// return handler.NewUpdateStatement(
|
e, ok := event.(*instance.IDPConfigDeactivatedEvent)
|
||||||
// &idpEvent,
|
if !ok {
|
||||||
// []handler.Column{
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-94O5l", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPConfigDeactivatedEventType, instance.IDPConfigDeactivatedEventType})
|
||||||
// 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
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func (p *idpRelationalProjection) reduceIDPReactivated(event eventstore.Event) (*handler.Statement, error) {
|
return handler.NewUpdateStatement(
|
||||||
// var idpEvent idpconfig.IDPConfigReactivatedEvent
|
e,
|
||||||
// switch e := event.(type) {
|
[]handler.Column{
|
||||||
// case *org.IDPConfigReactivatedEvent:
|
handler.NewCol(IDPStateCol, domain.IDPStateInactive.String()),
|
||||||
// idpEvent = e.IDPConfigReactivatedEvent
|
handler.NewCol(UpdatedAt, e.CreationDate()),
|
||||||
// case *instance.IDPConfigReactivatedEvent:
|
},
|
||||||
// idpEvent = e.IDPConfigReactivatedEvent
|
[]handler.Condition{
|
||||||
// default:
|
handler.NewCond(IDPIDCol, e.ConfigID),
|
||||||
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-I8QyS", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPConfigReactivatedEventType, instance.IDPConfigReactivatedEventType})
|
handler.NewCond(IDPInstanceIDCol, e.Aggregate().InstanceID),
|
||||||
// }
|
},
|
||||||
|
), nil
|
||||||
|
}
|
||||||
|
|
||||||
// return handler.NewUpdateStatement(
|
func (p *idpRelationalProjection) reduceIDPRelationalReactivated(event eventstore.Event) (*handler.Statement, error) {
|
||||||
// &idpEvent,
|
e, ok := event.(*instance.IDPConfigReactivatedEvent)
|
||||||
// []handler.Column{
|
if !ok {
|
||||||
// handler.NewCol(IDPStateCol, domain.IDPConfigStateActive),
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-I8QyS", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPConfigReactivatedEventType, instance.IDPConfigReactivatedEventType})
|
||||||
// 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) reduceIDPRemoved(event eventstore.Event) (*handler.Statement, error) {
|
return handler.NewUpdateStatement(
|
||||||
// var idpEvent idpconfig.IDPConfigRemovedEvent
|
e,
|
||||||
// switch e := event.(type) {
|
[]handler.Column{
|
||||||
// case *org.IDPConfigRemovedEvent:
|
handler.NewCol(IDPStateCol, domain.IDPStateActive.String()),
|
||||||
// idpEvent = e.IDPConfigRemovedEvent
|
handler.NewCol(UpdatedAt, e.CreationDate()),
|
||||||
// case *instance.IDPConfigRemovedEvent:
|
},
|
||||||
// idpEvent = e.IDPConfigRemovedEvent
|
[]handler.Condition{
|
||||||
// default:
|
handler.NewCond(IDPIDCol, e.ConfigID),
|
||||||
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-B4zy8", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPConfigRemovedEventType, instance.IDPConfigRemovedEventType})
|
handler.NewCond(IDPInstanceIDCol, e.Aggregate().InstanceID),
|
||||||
// }
|
},
|
||||||
|
), nil
|
||||||
|
}
|
||||||
|
|
||||||
// return handler.NewDeleteStatement(
|
func (p *idpRelationalProjection) reduceIDPRelationalRemoved(event eventstore.Event) (*handler.Statement, error) {
|
||||||
// &idpEvent,
|
e, ok := event.(*instance.IDPConfigRemovedEvent)
|
||||||
// []handler.Condition{
|
if !ok {
|
||||||
// handler.NewCond(IDPIDCol, idpEvent.ConfigID),
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-B4zy8", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPConfigRemovedEventType, instance.IDPConfigRemovedEventType})
|
||||||
// handler.NewCond(IDPInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
}
|
||||||
// },
|
|
||||||
// ), nil
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func (p *idpRelationalProjection) reduceOIDCConfigAdded(event eventstore.Event) (*handler.Statement, error) {
|
return handler.NewDeleteStatement(
|
||||||
// var idpEvent idpconfig.OIDCConfigAddedEvent
|
e,
|
||||||
// switch e := event.(type) {
|
[]handler.Condition{
|
||||||
// case *org.IDPOIDCConfigAddedEvent:
|
handler.NewCond(IDPIDCol, e.ConfigID),
|
||||||
// idpEvent = e.OIDCConfigAddedEvent
|
handler.NewCond(IDPInstanceIDCol, e.Aggregate().InstanceID),
|
||||||
// case *instance.IDPOIDCConfigAddedEvent:
|
},
|
||||||
// idpEvent = e.OIDCConfigAddedEvent
|
), nil
|
||||||
// default:
|
}
|
||||||
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-2FuAA", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPOIDCConfigAddedEventType, instance.IDPOIDCConfigAddedEventType})
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return handler.NewMultiStatement(&idpEvent,
|
func (p *idpRelationalProjection) reduceOIDCRelationalConfigAdded(event eventstore.Event) (*handler.Statement, error) {
|
||||||
// handler.AddUpdateStatement(
|
var idpEvent idpconfig.OIDCConfigAddedEvent
|
||||||
// []handler.Column{
|
switch e := event.(type) {
|
||||||
// handler.NewCol(IDPChangeDateCol, idpEvent.CreationDate()),
|
case *org.IDPOIDCConfigAddedEvent:
|
||||||
// handler.NewCol(IDPSequenceCol, idpEvent.Sequence()),
|
idpEvent = e.OIDCConfigAddedEvent
|
||||||
// handler.NewCol(IDPTypeCol, domain.IDPConfigTypeOIDC),
|
case *instance.IDPOIDCConfigAddedEvent:
|
||||||
// },
|
idpEvent = e.OIDCConfigAddedEvent
|
||||||
// []handler.Condition{
|
default:
|
||||||
// handler.NewCond(IDPIDCol, idpEvent.IDPConfigID),
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-2FuAA", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPOIDCConfigAddedEventType, instance.IDPOIDCConfigAddedEventType})
|
||||||
// handler.NewCond(IDPInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
}
|
||||||
// },
|
|
||||||
// ),
|
return handler.NewMultiStatement(&idpEvent,
|
||||||
// handler.AddCreateStatement(
|
handler.AddUpdateStatement(
|
||||||
// []handler.Column{
|
[]handler.Column{
|
||||||
// handler.NewCol(OIDCConfigIDPIDCol, idpEvent.IDPConfigID),
|
handler.NewCol(IDPChangeDateCol, idpEvent.CreationDate()),
|
||||||
// handler.NewCol(OIDCConfigInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
handler.NewCol(IDPSequenceCol, idpEvent.Sequence()),
|
||||||
// handler.NewCol(OIDCConfigClientIDCol, idpEvent.ClientID),
|
handler.NewCol(IDPTypeCol, domain.IDPConfigTypeOIDC),
|
||||||
// handler.NewCol(OIDCConfigClientSecretCol, idpEvent.ClientSecret),
|
},
|
||||||
// handler.NewCol(OIDCConfigIssuerCol, idpEvent.Issuer),
|
[]handler.Condition{
|
||||||
// handler.NewCol(OIDCConfigScopesCol, database.TextArray[string](idpEvent.Scopes)),
|
handler.NewCond(IDPIDCol, idpEvent.IDPConfigID),
|
||||||
// handler.NewCol(OIDCConfigDisplayNameMappingCol, idpEvent.IDPDisplayNameMapping),
|
handler.NewCond(IDPInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
||||||
// handler.NewCol(OIDCConfigUsernameMappingCol, idpEvent.UserNameMapping),
|
},
|
||||||
// handler.NewCol(OIDCConfigAuthorizationEndpointCol, idpEvent.AuthorizationEndpoint),
|
),
|
||||||
// handler.NewCol(OIDCConfigTokenEndpointCol, idpEvent.TokenEndpoint),
|
handler.AddCreateStatement(
|
||||||
// },
|
[]handler.Column{
|
||||||
// handler.WithTableSuffix(IDPOIDCSuffix),
|
handler.NewCol(OIDCConfigIDPIDCol, idpEvent.IDPConfigID),
|
||||||
// ),
|
handler.NewCol(OIDCConfigInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
||||||
// ), nil
|
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) {
|
// func (p *idpRelationalProjection) reduceOIDCConfigChanged(event eventstore.Event) (*handler.Statement, error) {
|
||||||
// var idpEvent idpconfig.OIDCConfigChangedEvent
|
// var idpEvent idpconfig.OIDCConfigChangedEvent
|
||||||
|
Reference in New Issue
Block a user