mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 19:14:23 +00:00
8dcbbc87ca
* fix: adaot config to commands (and queries) * remove dependency on vv2 in v1 * add queries user to operator * set password for queries on tests * set password for queries on tests * fix config
50 lines
1.4 KiB
Go
50 lines
1.4 KiB
Go
package command
|
|
|
|
import (
|
|
"context"
|
|
"github.com/caos/zitadel/internal/domain"
|
|
caos_errs "github.com/caos/zitadel/internal/errors"
|
|
)
|
|
|
|
func (c *Commands) ChangeIDPOIDCConfig(ctx context.Context, config *domain.OIDCIDPConfig) (*domain.OIDCIDPConfig, error) {
|
|
existingConfig := NewOrgIDPOIDCConfigWriteModel(config.IDPConfigID, config.AggregateID)
|
|
err := c.eventstore.FilterToQueryReducer(ctx, existingConfig)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if existingConfig.State == domain.IDPConfigStateRemoved || existingConfig.State == domain.IDPConfigStateUnspecified {
|
|
return nil, caos_errs.ThrowAlreadyExists(nil, "Org-67J9d", "Errors.Org.IDPConfig.AlreadyExists")
|
|
}
|
|
|
|
orgAgg := OrgAggregateFromWriteModel(&existingConfig.WriteModel)
|
|
changedEvent, hasChanged, err := existingConfig.NewChangedEvent(
|
|
ctx,
|
|
orgAgg,
|
|
config.IDPConfigID,
|
|
config.ClientID,
|
|
config.Issuer,
|
|
config.ClientSecretString,
|
|
c.idpConfigSecretCrypto,
|
|
config.IDPDisplayNameMapping,
|
|
config.UsernameMapping,
|
|
config.Scopes...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if !hasChanged {
|
|
return nil, caos_errs.ThrowPreconditionFailed(nil, "Org-4M9vs", "Errors.Org.LabelPolicy.NotChanged")
|
|
}
|
|
|
|
pushedEvents, err := c.eventstore.PushEvents(ctx, changedEvent)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
err = AppendAndReduce(existingConfig, pushedEvents...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return writeModelToIDPOIDCConfig(&existingConfig.OIDCConfigWriteModel), nil
|
|
}
|