cleanup code

This commit is contained in:
adlerhurst 2020-11-30 08:35:40 +01:00
parent 0780c23f76
commit 968f766a8f
7 changed files with 26 additions and 38 deletions

View File

@ -11,14 +11,12 @@ import (
func (r *Repository) ChangeIDPOIDCConfig(ctx context.Context, config *iam_model.OIDCIDPConfig) (*iam_model.OIDCIDPConfig, error) {
writeModel := iam.NewIDPOIDCConfigWriteModel(config.AggregateID, config.IDPConfigID)
err := r.eventstore.FilterToQueryReducer(ctx, writeModel)
if err != nil {
return nil, err
}
var clientSecret *crypto.CryptoValue
if config.ClientSecretString != "" {
clientSecret, err = crypto.Crypt([]byte(config.ClientSecretString), r.secretCrypto)
if err != nil {
@ -37,15 +35,10 @@ func (r *Repository) ChangeIDPOIDCConfig(ctx context.Context, config *iam_model.
oidc.MappingField(config.UsernameMapping),
config.Scopes...)
events, err := r.eventstore.PushAggregates(ctx, aggregate)
err = r.eventstore.PushAggregate(ctx, writeModel, aggregate)
if err != nil {
return nil, err
}
writeModel.AppendEvents(events...)
if err = writeModel.Reduce(); err != nil {
return nil, err
}
return writeModelToIDPOIDCConfig(&writeModel.ConfigWriteModel), nil
}

View File

@ -5,7 +5,6 @@ import (
"github.com/caos/zitadel/internal/errors"
caos_errs "github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/eventstore/v2"
iam_model "github.com/caos/zitadel/internal/iam/model"
"github.com/caos/zitadel/internal/tracing"
iam_repo "github.com/caos/zitadel/internal/v2/repository/iam"
@ -86,17 +85,8 @@ func (r *Repository) MemberByID(ctx context.Context, iamID, userID string) (memb
ctx, span := tracing.NewSpan(ctx)
defer func() { span.EndWithError(err) }()
member = new(iam_repo.MemberReadModel)
//query view
query := eventstore.NewSearchQueryFactory(eventstore.ColumnsEvent, iam_repo.AggregateType).
AggregateIDs(iamID).
EventData(map[string]interface{}{
"userId": userID,
}).SequenceGreater(member.ProcessedSequence)
err = r.eventstore.FilterToReducer(ctx, query, member)
member = iam_repo.NewMemberReadModel(iamID, userID)
err = r.eventstore.FilterToQueryReducer(ctx, member)
if err != nil {
return nil, err
}

View File

@ -14,6 +14,7 @@ func (r *Repository) AddIDPProviderToLoginPolicy(ctx context.Context, idpProvide
if err != nil {
return nil, err
}
aggregate := iam.AggregateFromWriteModel(&writeModel.WriteModel).
PushLoginPolicyIDPProviderAddedEvent(ctx, idpProvider.IdpConfigID, provider.Type(idpProvider.Type))

View File

@ -155,6 +155,7 @@ func (a *Aggregate) PushIDPOIDCConfigChanged(
userNameMapping oidc.MappingField,
scopes ...string,
) *Aggregate {
event, err := NewIDPOIDCConfigChangedEvent(ctx, current, clientID, issuer, clientSecret, idpDisplayNameMapping, userNameMapping, scopes...)
if err != nil {
return a
@ -169,6 +170,7 @@ func (a *Aggregate) PushLoginPolicyIDPProviderAddedEvent(
idpConfigID string,
providerType provider.Type,
) *Aggregate {
a.Aggregate = *a.PushEvents(NewLoginPolicyIDPProviderAddedEvent(ctx, idpConfigID, providerType))
return a
}
@ -178,6 +180,7 @@ func (a *Aggregate) PushLoginPolicyIDPProviderRemovedEvent(
idpConfigID string,
providerType provider.Type,
) *Aggregate {
a.Aggregate = *a.PushEvents(NewLoginPolicyIDPProviderRemovedEvent(ctx, idpConfigID))
return a
}

View File

@ -181,6 +181,7 @@ func NewIDPConfigChangedEvent(
configType idp.ConfigType,
stylingType idp.StylingType,
) (*IDPConfigChangedEvent, error) {
event, err := idp.NewConfigChangedEvent(
eventstore.NewBaseEventForPush(
ctx,

View File

@ -16,6 +16,16 @@ var (
type MemberReadModel struct {
member.ReadModel
userID string
iamID string
}
func NewMemberReadModel(iamID, userID string) *MemberReadModel {
return &MemberReadModel{
iamID: iamID,
userID: userID,
}
}
func (rm *MemberReadModel) AppendEvents(events ...eventstore.EventReader) {
@ -31,6 +41,14 @@ func (rm *MemberReadModel) AppendEvents(events ...eventstore.EventReader) {
}
}
func (rm *MemberReadModel) Query() *eventstore.SearchQueryFactory {
return eventstore.NewSearchQueryFactory(eventstore.ColumnsEvent, AggregateType).
AggregateIDs(rm.iamID).
EventData(map[string]interface{}{
"userId": rm.userID,
})
}
type MemberWriteModel struct {
eventstore.WriteModel
Member member.WriteModel

View File

@ -1,18 +0,0 @@
package member
import "github.com/caos/zitadel/internal/eventstore/v2"
type Aggregate struct {
eventstore.Aggregate
UserID string
Roles []string
}
func NewAggregate(aggregate *eventstore.Aggregate, userID string, roles ...string) *Aggregate {
return &Aggregate{
Aggregate: *aggregate,
Roles: roles,
UserID: userID,
}
}