mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 23:57:31 +00:00
fix: rename iam to instance (#3345)
* fix: rename iam command side to instance * fix: rename iam command side to instance * fix: rename iam command side to instance * fix: rename iam command side to instance * fix: rename orgiampolicy to domain policy * fix: merge conflicts * fix: protos * fix: md files * implement deprecated org iam policy again Co-authored-by: Livio Amstutz <livio.a@gmail.com>
This commit is contained in:
101
internal/command/instance_oidc_settings_model.go
Normal file
101
internal/command/instance_oidc_settings_model.go
Normal file
@@ -0,0 +1,101 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
type InstanceOIDCSettingsWriteModel struct {
|
||||
eventstore.WriteModel
|
||||
|
||||
AccessTokenLifetime time.Duration
|
||||
IdTokenLifetime time.Duration
|
||||
RefreshTokenIdleExpiration time.Duration
|
||||
RefreshTokenExpiration time.Duration
|
||||
State domain.OIDCSettingsState
|
||||
}
|
||||
|
||||
func NewInstanceOIDCSettingsWriteModel() *InstanceOIDCSettingsWriteModel {
|
||||
return &InstanceOIDCSettingsWriteModel{
|
||||
WriteModel: eventstore.WriteModel{
|
||||
AggregateID: domain.IAMID,
|
||||
ResourceOwner: domain.IAMID,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *InstanceOIDCSettingsWriteModel) Reduce() error {
|
||||
for _, event := range wm.Events {
|
||||
switch e := event.(type) {
|
||||
case *instance.OIDCSettingsAddedEvent:
|
||||
wm.AccessTokenLifetime = e.AccessTokenLifetime
|
||||
wm.IdTokenLifetime = e.IdTokenLifetime
|
||||
wm.RefreshTokenIdleExpiration = e.RefreshTokenIdleExpiration
|
||||
wm.RefreshTokenExpiration = e.RefreshTokenExpiration
|
||||
wm.State = domain.OIDCSettingsStateActive
|
||||
case *instance.OIDCSettingsChangedEvent:
|
||||
if e.AccessTokenLifetime != nil {
|
||||
wm.AccessTokenLifetime = *e.AccessTokenLifetime
|
||||
}
|
||||
if e.IdTokenLifetime != nil {
|
||||
wm.IdTokenLifetime = *e.IdTokenLifetime
|
||||
}
|
||||
if e.RefreshTokenIdleExpiration != nil {
|
||||
wm.RefreshTokenIdleExpiration = *e.RefreshTokenIdleExpiration
|
||||
}
|
||||
if e.RefreshTokenExpiration != nil {
|
||||
wm.RefreshTokenExpiration = *e.RefreshTokenExpiration
|
||||
}
|
||||
}
|
||||
}
|
||||
return wm.WriteModel.Reduce()
|
||||
}
|
||||
|
||||
func (wm *InstanceOIDCSettingsWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
ResourceOwner(wm.ResourceOwner).
|
||||
AddQuery().
|
||||
AggregateTypes(instance.AggregateType).
|
||||
AggregateIDs(wm.AggregateID).
|
||||
EventTypes(
|
||||
instance.OIDCSettingsAddedEventType,
|
||||
instance.OIDCSettingsChangedEventType).
|
||||
Builder()
|
||||
}
|
||||
|
||||
func (wm *InstanceOIDCSettingsWriteModel) NewChangedEvent(
|
||||
ctx context.Context,
|
||||
aggregate *eventstore.Aggregate,
|
||||
accessTokenLifetime,
|
||||
idTokenLifetime,
|
||||
refreshTokenIdleExpiration,
|
||||
refreshTokenExpiration time.Duration,
|
||||
) (*instance.OIDCSettingsChangedEvent, bool, error) {
|
||||
changes := make([]instance.OIDCSettingsChanges, 0, 4)
|
||||
var err error
|
||||
|
||||
if wm.AccessTokenLifetime != accessTokenLifetime {
|
||||
changes = append(changes, instance.ChangeOIDCSettingsAccessTokenLifetime(accessTokenLifetime))
|
||||
}
|
||||
if wm.IdTokenLifetime != idTokenLifetime {
|
||||
changes = append(changes, instance.ChangeOIDCSettingsIdTokenLifetime(idTokenLifetime))
|
||||
}
|
||||
if wm.RefreshTokenIdleExpiration != refreshTokenIdleExpiration {
|
||||
changes = append(changes, instance.ChangeOIDCSettingsRefreshTokenIdleExpiration(refreshTokenIdleExpiration))
|
||||
}
|
||||
if wm.RefreshTokenExpiration != refreshTokenExpiration {
|
||||
changes = append(changes, instance.ChangeOIDCSettingsRefreshTokenExpiration(refreshTokenExpiration))
|
||||
}
|
||||
if len(changes) == 0 {
|
||||
return nil, false, nil
|
||||
}
|
||||
changeEvent, err := instance.NewOIDCSettingsChangeEvent(ctx, aggregate, changes)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
return changeEvent, true, nil
|
||||
}
|
Reference in New Issue
Block a user