mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-27 22:48:52 +00:00
feat: idps (#1188)
* add setup steps * refactoring * omitempty * cleanup * begin org * create org * setup org * setup org * merge * fixes * fixes * fixes * add project * add oidc application * fix app creation * add resourceOwner to writemodels * resource owner * cleanup * global org, iam project and iam member in setup * logs * logs * logs * cleanup * Update internal/v2/command/project.go Co-authored-by: Fabi <[email protected]> * check project state * add org domain commands * add org status changes and member commands * fixes * policies * login policy * fix iam project event * mapper * label policy * change to command * fix * fix * handle change event differently and lot of fixes * idps * fixes * fixes * fixes * changedEvent handling * fix change events * remove creation date Co-authored-by: Fabi <[email protected]>
This commit is contained in:
@@ -8,14 +8,15 @@ import (
|
||||
"github.com/caos/zitadel/internal/eventstore/v2"
|
||||
"github.com/caos/zitadel/internal/v2/domain"
|
||||
"github.com/caos/zitadel/internal/v2/repository/iam"
|
||||
"github.com/caos/zitadel/internal/v2/repository/idpconfig"
|
||||
)
|
||||
|
||||
type IDPOIDCConfigWriteModel struct {
|
||||
type IAMIDPOIDCConfigWriteModel struct {
|
||||
OIDCConfigWriteModel
|
||||
}
|
||||
|
||||
func NewIAMIDPOIDCConfigWriteModel(idpConfigID string) *IDPOIDCConfigWriteModel {
|
||||
return &IDPOIDCConfigWriteModel{
|
||||
func NewIAMIDPOIDCConfigWriteModel(idpConfigID string) *IAMIDPOIDCConfigWriteModel {
|
||||
return &IAMIDPOIDCConfigWriteModel{
|
||||
OIDCConfigWriteModel{
|
||||
WriteModel: eventstore.WriteModel{
|
||||
AggregateID: domain.IAMID,
|
||||
@@ -26,7 +27,7 @@ func NewIAMIDPOIDCConfigWriteModel(idpConfigID string) *IDPOIDCConfigWriteModel
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IDPOIDCConfigWriteModel) AppendEvents(events ...eventstore.EventReader) {
|
||||
func (wm *IAMIDPOIDCConfigWriteModel) AppendEvents(events ...eventstore.EventReader) {
|
||||
for _, event := range events {
|
||||
switch e := event.(type) {
|
||||
case *iam.IDPOIDCConfigAddedEvent:
|
||||
@@ -60,21 +61,22 @@ func (wm *IDPOIDCConfigWriteModel) AppendEvents(events ...eventstore.EventReader
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IDPOIDCConfigWriteModel) Reduce() error {
|
||||
func (wm *IAMIDPOIDCConfigWriteModel) Reduce() error {
|
||||
if err := wm.OIDCConfigWriteModel.Reduce(); err != nil {
|
||||
return err
|
||||
}
|
||||
return wm.WriteModel.Reduce()
|
||||
}
|
||||
|
||||
func (wm *IDPOIDCConfigWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
func (wm *IAMIDPOIDCConfigWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent, iam.AggregateType).
|
||||
AggregateIDs(wm.AggregateID).
|
||||
ResourceOwner(wm.ResourceOwner)
|
||||
}
|
||||
|
||||
func (wm *IDPOIDCConfigWriteModel) NewChangedEvent(
|
||||
func (wm *IAMIDPOIDCConfigWriteModel) NewChangedEvent(
|
||||
ctx context.Context,
|
||||
idpConfigID,
|
||||
clientID,
|
||||
issuer,
|
||||
clientSecretString string,
|
||||
@@ -83,8 +85,8 @@ func (wm *IDPOIDCConfigWriteModel) NewChangedEvent(
|
||||
userNameMapping domain.OIDCMappingField,
|
||||
scopes ...string,
|
||||
) (*iam.IDPOIDCConfigChangedEvent, bool, error) {
|
||||
hasChanged := false
|
||||
changedEvent := iam.NewIDPOIDCConfigChangedEvent(ctx)
|
||||
|
||||
changes := make([]idpconfig.OIDCConfigChanges, 0)
|
||||
var clientSecret *crypto.CryptoValue
|
||||
var err error
|
||||
if clientSecretString != "" {
|
||||
@@ -92,27 +94,29 @@ func (wm *IDPOIDCConfigWriteModel) NewChangedEvent(
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
changedEvent.ClientSecret = clientSecret
|
||||
changes = append(changes, idpconfig.ChangeClientSecret(clientSecret))
|
||||
}
|
||||
if wm.ClientID != clientID {
|
||||
hasChanged = true
|
||||
changedEvent.ClientID = clientID
|
||||
changes = append(changes, idpconfig.ChangeClientID(clientID))
|
||||
}
|
||||
if wm.Issuer != issuer {
|
||||
hasChanged = true
|
||||
changedEvent.Issuer = issuer
|
||||
changes = append(changes, idpconfig.ChangeIssuer(issuer))
|
||||
}
|
||||
if idpDisplayNameMapping.Valid() && wm.IDPDisplayNameMapping != idpDisplayNameMapping {
|
||||
hasChanged = true
|
||||
changedEvent.IDPDisplayNameMapping = idpDisplayNameMapping
|
||||
changes = append(changes, idpconfig.ChangeIDPDisplayNameMapping(idpDisplayNameMapping))
|
||||
}
|
||||
if userNameMapping.Valid() && wm.UserNameMapping != userNameMapping {
|
||||
hasChanged = true
|
||||
changedEvent.UserNameMapping = userNameMapping
|
||||
changes = append(changes, idpconfig.ChangeUserNameMapping(userNameMapping))
|
||||
}
|
||||
if reflect.DeepEqual(wm.Scopes, scopes) {
|
||||
hasChanged = true
|
||||
changedEvent.Scopes = scopes
|
||||
changes = append(changes, idpconfig.ChangeScopes(scopes))
|
||||
}
|
||||
return changedEvent, hasChanged, nil
|
||||
if len(changes) == 0 {
|
||||
return nil, false, nil
|
||||
}
|
||||
changeEvent, err := iam.NewIDPOIDCConfigChangedEvent(ctx, idpConfigID, changes)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
return changeEvent, true, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user