mirror of
https://github.com/zitadel/zitadel.git
synced 2025-01-07 16:17:50 +00:00
cleanup code
This commit is contained in:
parent
0780c23f76
commit
968f766a8f
@ -11,14 +11,12 @@ import (
|
|||||||
|
|
||||||
func (r *Repository) ChangeIDPOIDCConfig(ctx context.Context, config *iam_model.OIDCIDPConfig) (*iam_model.OIDCIDPConfig, error) {
|
func (r *Repository) ChangeIDPOIDCConfig(ctx context.Context, config *iam_model.OIDCIDPConfig) (*iam_model.OIDCIDPConfig, error) {
|
||||||
writeModel := iam.NewIDPOIDCConfigWriteModel(config.AggregateID, config.IDPConfigID)
|
writeModel := iam.NewIDPOIDCConfigWriteModel(config.AggregateID, config.IDPConfigID)
|
||||||
|
|
||||||
err := r.eventstore.FilterToQueryReducer(ctx, writeModel)
|
err := r.eventstore.FilterToQueryReducer(ctx, writeModel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var clientSecret *crypto.CryptoValue
|
var clientSecret *crypto.CryptoValue
|
||||||
|
|
||||||
if config.ClientSecretString != "" {
|
if config.ClientSecretString != "" {
|
||||||
clientSecret, err = crypto.Crypt([]byte(config.ClientSecretString), r.secretCrypto)
|
clientSecret, err = crypto.Crypt([]byte(config.ClientSecretString), r.secretCrypto)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -37,15 +35,10 @@ func (r *Repository) ChangeIDPOIDCConfig(ctx context.Context, config *iam_model.
|
|||||||
oidc.MappingField(config.UsernameMapping),
|
oidc.MappingField(config.UsernameMapping),
|
||||||
config.Scopes...)
|
config.Scopes...)
|
||||||
|
|
||||||
events, err := r.eventstore.PushAggregates(ctx, aggregate)
|
err = r.eventstore.PushAggregate(ctx, writeModel, aggregate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
writeModel.AppendEvents(events...)
|
|
||||||
if err = writeModel.Reduce(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return writeModelToIDPOIDCConfig(&writeModel.ConfigWriteModel), nil
|
return writeModelToIDPOIDCConfig(&writeModel.ConfigWriteModel), nil
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ import (
|
|||||||
|
|
||||||
"github.com/caos/zitadel/internal/errors"
|
"github.com/caos/zitadel/internal/errors"
|
||||||
caos_errs "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"
|
iam_model "github.com/caos/zitadel/internal/iam/model"
|
||||||
"github.com/caos/zitadel/internal/tracing"
|
"github.com/caos/zitadel/internal/tracing"
|
||||||
iam_repo "github.com/caos/zitadel/internal/v2/repository/iam"
|
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)
|
ctx, span := tracing.NewSpan(ctx)
|
||||||
defer func() { span.EndWithError(err) }()
|
defer func() { span.EndWithError(err) }()
|
||||||
|
|
||||||
member = new(iam_repo.MemberReadModel)
|
member = iam_repo.NewMemberReadModel(iamID, userID)
|
||||||
|
err = r.eventstore.FilterToQueryReducer(ctx, member)
|
||||||
//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)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ func (r *Repository) AddIDPProviderToLoginPolicy(ctx context.Context, idpProvide
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
aggregate := iam.AggregateFromWriteModel(&writeModel.WriteModel).
|
aggregate := iam.AggregateFromWriteModel(&writeModel.WriteModel).
|
||||||
PushLoginPolicyIDPProviderAddedEvent(ctx, idpProvider.IdpConfigID, provider.Type(idpProvider.Type))
|
PushLoginPolicyIDPProviderAddedEvent(ctx, idpProvider.IdpConfigID, provider.Type(idpProvider.Type))
|
||||||
|
|
||||||
|
@ -155,6 +155,7 @@ func (a *Aggregate) PushIDPOIDCConfigChanged(
|
|||||||
userNameMapping oidc.MappingField,
|
userNameMapping oidc.MappingField,
|
||||||
scopes ...string,
|
scopes ...string,
|
||||||
) *Aggregate {
|
) *Aggregate {
|
||||||
|
|
||||||
event, err := NewIDPOIDCConfigChangedEvent(ctx, current, clientID, issuer, clientSecret, idpDisplayNameMapping, userNameMapping, scopes...)
|
event, err := NewIDPOIDCConfigChangedEvent(ctx, current, clientID, issuer, clientSecret, idpDisplayNameMapping, userNameMapping, scopes...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return a
|
return a
|
||||||
@ -169,6 +170,7 @@ func (a *Aggregate) PushLoginPolicyIDPProviderAddedEvent(
|
|||||||
idpConfigID string,
|
idpConfigID string,
|
||||||
providerType provider.Type,
|
providerType provider.Type,
|
||||||
) *Aggregate {
|
) *Aggregate {
|
||||||
|
|
||||||
a.Aggregate = *a.PushEvents(NewLoginPolicyIDPProviderAddedEvent(ctx, idpConfigID, providerType))
|
a.Aggregate = *a.PushEvents(NewLoginPolicyIDPProviderAddedEvent(ctx, idpConfigID, providerType))
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
@ -178,6 +180,7 @@ func (a *Aggregate) PushLoginPolicyIDPProviderRemovedEvent(
|
|||||||
idpConfigID string,
|
idpConfigID string,
|
||||||
providerType provider.Type,
|
providerType provider.Type,
|
||||||
) *Aggregate {
|
) *Aggregate {
|
||||||
|
|
||||||
a.Aggregate = *a.PushEvents(NewLoginPolicyIDPProviderRemovedEvent(ctx, idpConfigID))
|
a.Aggregate = *a.PushEvents(NewLoginPolicyIDPProviderRemovedEvent(ctx, idpConfigID))
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
@ -181,6 +181,7 @@ func NewIDPConfigChangedEvent(
|
|||||||
configType idp.ConfigType,
|
configType idp.ConfigType,
|
||||||
stylingType idp.StylingType,
|
stylingType idp.StylingType,
|
||||||
) (*IDPConfigChangedEvent, error) {
|
) (*IDPConfigChangedEvent, error) {
|
||||||
|
|
||||||
event, err := idp.NewConfigChangedEvent(
|
event, err := idp.NewConfigChangedEvent(
|
||||||
eventstore.NewBaseEventForPush(
|
eventstore.NewBaseEventForPush(
|
||||||
ctx,
|
ctx,
|
||||||
|
@ -16,6 +16,16 @@ var (
|
|||||||
|
|
||||||
type MemberReadModel struct {
|
type MemberReadModel struct {
|
||||||
member.ReadModel
|
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) {
|
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 {
|
type MemberWriteModel struct {
|
||||||
eventstore.WriteModel
|
eventstore.WriteModel
|
||||||
Member member.WriteModel
|
Member member.WriteModel
|
||||||
|
@ -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,
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user