diff --git a/internal/eventstore/v2/event_base.go b/internal/eventstore/v2/event_base.go index f303a1cab5..8c5a8e7789 100644 --- a/internal/eventstore/v2/event_base.go +++ b/internal/eventstore/v2/event_base.go @@ -1,8 +1,10 @@ package eventstore import ( + "context" "time" + "github.com/caos/zitadel/internal/api/authz" "github.com/caos/zitadel/internal/eventstore/v2/repository" ) @@ -75,4 +77,10 @@ func BaseEventFromRepo(event *repository.Event) *BaseEvent { } } -func NewBaseEvent() +func NewBaseEventForPush(ctx context.Context, service string, typ EventType) *BaseEvent { + return &BaseEvent{ + User: authz.GetCtxData(ctx).UserID, + Service: service, + EventType: typ, + } +} diff --git a/internal/eventstore/v2/eventstore.go b/internal/eventstore/v2/eventstore.go index f87f55837b..41642187c3 100644 --- a/internal/eventstore/v2/eventstore.go +++ b/internal/eventstore/v2/eventstore.go @@ -19,7 +19,7 @@ type Eventstore struct { } type eventTypeInterceptors struct { - eventMapper func(*repository.Event) (Event, error) + eventMapper func(*repository.Event) (EventReader, error) } func NewEventstore(repo repository.Repository) *Eventstore { @@ -166,7 +166,7 @@ func (es *Eventstore) LatestSequence(ctx context.Context, queryFactory *SearchQu } //RegisterFilterEventMapper registers a function for mapping an eventstore event to an event -func (es *Eventstore) RegisterFilterEventMapper(eventType EventType, mapper func(*repository.Event) (Event, error)) *Eventstore { +func (es *Eventstore) RegisterFilterEventMapper(eventType EventType, mapper func(*repository.Event) (EventReader, error)) *Eventstore { if mapper == nil || eventType == "" { return es } diff --git a/internal/eventstore/v2/eventstore_test.go b/internal/eventstore/v2/eventstore_test.go index 79ffbd19be..f81653d635 100644 --- a/internal/eventstore/v2/eventstore_test.go +++ b/internal/eventstore/v2/eventstore_test.go @@ -55,11 +55,11 @@ func newTestEvent(description string, data func() interface{}, checkPrevious boo description: description, data: data, shouldCheckPrevious: checkPrevious, - BaseEvent: BaseEvent{ - User: "editorUser", - Service: "editorService", - EventType: "test.event", - }, + BaseEvent: *NewBaseEventForPush( + "editorUser", + "editorService", + "test.event", + ), } } @@ -71,7 +71,7 @@ func (e *testEvent) Data() interface{} { return e.data() } -func testFilterMapper(event *repository.Event) (Event, error) { +func testFilterMapper(event *repository.Event) (EventReader, error) { if event == nil { return newTestEvent("hodor", nil, false), nil } @@ -84,7 +84,7 @@ func Test_eventstore_RegisterFilterEventMapper(t *testing.T) { } type args struct { eventType EventType - mapper func(*repository.Event) (Event, error) + mapper func(*repository.Event) (EventReader, error) } type res struct { event Event @@ -158,7 +158,7 @@ func Test_eventstore_RegisterFilterEventMapper(t *testing.T) { fields: fields{ eventMapper: map[EventType]eventTypeInterceptors{ "event.type": { - eventMapper: func(*repository.Event) (Event, error) { + eventMapper: func(*repository.Event) (EventReader, error) { return nil, errors.ThrowUnimplemented(nil, "V2-1qPvn", "unimplemented") }, }, @@ -627,7 +627,7 @@ func TestEventstore_Push(t *testing.T) { } type fields struct { repo *testRepo - eventMapper map[EventType]func(*repository.Event) (Event, error) + eventMapper map[EventType]func(*repository.Event) (EventReader, error) } type res struct { wantErr bool @@ -672,8 +672,8 @@ func TestEventstore_Push(t *testing.T) { }, }, }, - eventMapper: map[EventType]func(*repository.Event) (Event, error){ - "test.event": func(e *repository.Event) (Event, error) { + eventMapper: map[EventType]func(*repository.Event) (EventReader, error){ + "test.event": func(e *repository.Event) (EventReader, error) { return &testEvent{}, nil }, }, @@ -730,8 +730,8 @@ func TestEventstore_Push(t *testing.T) { }, ), }, - eventMapper: map[EventType]func(*repository.Event) (Event, error){ - "test.event": func(e *repository.Event) (Event, error) { + eventMapper: map[EventType]func(*repository.Event) (EventReader, error){ + "test.event": func(e *repository.Event) (EventReader, error) { return &testEvent{}, nil }, }, @@ -817,8 +817,8 @@ func TestEventstore_Push(t *testing.T) { }, ), }, - eventMapper: map[EventType]func(*repository.Event) (Event, error){ - "test.event": func(e *repository.Event) (Event, error) { + eventMapper: map[EventType]func(*repository.Event) (EventReader, error){ + "test.event": func(e *repository.Event) (EventReader, error) { return &testEvent{}, nil }, }, @@ -911,7 +911,7 @@ func TestEventstore_FilterEvents(t *testing.T) { } type fields struct { repo *testRepo - eventMapper map[EventType]func(*repository.Event) (Event, error) + eventMapper map[EventType]func(*repository.Event) (EventReader, error) } type res struct { wantErr bool @@ -944,8 +944,8 @@ func TestEventstore_FilterEvents(t *testing.T) { events: []*repository.Event{}, t: t, }, - eventMapper: map[EventType]func(*repository.Event) (Event, error){ - "test.event": func(e *repository.Event) (Event, error) { + eventMapper: map[EventType]func(*repository.Event) (EventReader, error){ + "test.event": func(e *repository.Event) (EventReader, error) { return &testEvent{}, nil }, }, @@ -967,8 +967,8 @@ func TestEventstore_FilterEvents(t *testing.T) { t: t, err: errors.ThrowInternal(nil, "V2-RfkBa", "test err"), }, - eventMapper: map[EventType]func(*repository.Event) (Event, error){ - "test.event": func(e *repository.Event) (Event, error) { + eventMapper: map[EventType]func(*repository.Event) (EventReader, error){ + "test.event": func(e *repository.Event) (EventReader, error) { return &testEvent{}, nil }, }, @@ -995,8 +995,8 @@ func TestEventstore_FilterEvents(t *testing.T) { }, t: t, }, - eventMapper: map[EventType]func(*repository.Event) (Event, error){ - "test.event": func(e *repository.Event) (Event, error) { + eventMapper: map[EventType]func(*repository.Event) (EventReader, error){ + "test.event": func(e *repository.Event) (EventReader, error) { return &testEvent{}, nil }, }, @@ -1126,7 +1126,7 @@ func TestEventstore_LatestSequence(t *testing.T) { type testReducer struct { t *testing.T - events []Event + events []EventReader expectedLength int err error } @@ -1142,7 +1142,7 @@ func (r *testReducer) Reduce() error { return nil } -func (r *testReducer) AppendEvents(e ...Event) error { +func (r *testReducer) AppendEvents(e ...EventReader) error { if r.err != nil { return r.err } @@ -1157,7 +1157,7 @@ func TestEventstore_FilterToReducer(t *testing.T) { } type fields struct { repo *testRepo - eventMapper map[EventType]func(*repository.Event) (Event, error) + eventMapper map[EventType]func(*repository.Event) (EventReader, error) } type res struct { wantErr bool @@ -1194,8 +1194,8 @@ func TestEventstore_FilterToReducer(t *testing.T) { events: []*repository.Event{}, t: t, }, - eventMapper: map[EventType]func(*repository.Event) (Event, error){ - "test.event": func(e *repository.Event) (Event, error) { + eventMapper: map[EventType]func(*repository.Event) (EventReader, error){ + "test.event": func(e *repository.Event) (EventReader, error) { return &testEvent{}, nil }, }, @@ -1221,8 +1221,8 @@ func TestEventstore_FilterToReducer(t *testing.T) { t: t, err: errors.ThrowInternal(nil, "V2-RfkBa", "test err"), }, - eventMapper: map[EventType]func(*repository.Event) (Event, error){ - "test.event": func(e *repository.Event) (Event, error) { + eventMapper: map[EventType]func(*repository.Event) (EventReader, error){ + "test.event": func(e *repository.Event) (EventReader, error) { return &testEvent{}, nil }, }, @@ -1253,8 +1253,8 @@ func TestEventstore_FilterToReducer(t *testing.T) { }, t: t, }, - eventMapper: map[EventType]func(*repository.Event) (Event, error){ - "test.event": func(e *repository.Event) (Event, error) { + eventMapper: map[EventType]func(*repository.Event) (EventReader, error){ + "test.event": func(e *repository.Event) (EventReader, error) { return &testEvent{}, nil }, }, @@ -1282,8 +1282,8 @@ func TestEventstore_FilterToReducer(t *testing.T) { }, t: t, }, - eventMapper: map[EventType]func(*repository.Event) (Event, error){ - "test.event": func(e *repository.Event) (Event, error) { + eventMapper: map[EventType]func(*repository.Event) (EventReader, error){ + "test.event": func(e *repository.Event) (EventReader, error) { return &testEvent{}, nil }, }, @@ -1371,13 +1371,13 @@ func compareEvents(t *testing.T, want, got *repository.Event) { func TestEventstore_mapEvents(t *testing.T) { type fields struct { - eventMapper map[EventType]func(*repository.Event) (Event, error) + eventMapper map[EventType]func(*repository.Event) (EventReader, error) } type args struct { events []*repository.Event } type res struct { - events []Event + events []EventReader wantErr bool } tests := []struct { @@ -1396,7 +1396,7 @@ func TestEventstore_mapEvents(t *testing.T) { }, }, fields: fields{ - eventMapper: map[EventType]func(*repository.Event) (Event, error){}, + eventMapper: map[EventType]func(*repository.Event) (EventReader, error){}, }, res: res{ wantErr: true, @@ -1412,8 +1412,8 @@ func TestEventstore_mapEvents(t *testing.T) { }, }, fields: fields{ - eventMapper: map[EventType]func(*repository.Event) (Event, error){ - "test.event": func(*repository.Event) (Event, error) { + eventMapper: map[EventType]func(*repository.Event) (EventReader, error){ + "test.event": func(*repository.Event) (EventReader, error) { return nil, errors.ThrowInternal(nil, "V2-8FbQk", "test err") }, }, @@ -1432,14 +1432,14 @@ func TestEventstore_mapEvents(t *testing.T) { }, }, fields: fields{ - eventMapper: map[EventType]func(*repository.Event) (Event, error){ - "test.event": func(*repository.Event) (Event, error) { + eventMapper: map[EventType]func(*repository.Event) (EventReader, error){ + "test.event": func(*repository.Event) (EventReader, error) { return &testEvent{}, nil }, }, }, res: res{ - events: []Event{ + events: []EventReader{ &testEvent{}, }, wantErr: false, diff --git a/internal/eventstore/v2/example_test.go b/internal/eventstore/v2/example_test.go index ea85ae5c0d..51336c3d57 100644 --- a/internal/eventstore/v2/example_test.go +++ b/internal/eventstore/v2/example_test.go @@ -92,8 +92,8 @@ func NewUserAddedEvent(firstName string) *UserAddedEvent { } } -func UserAddedEventMapper() (eventstore.EventType, func(*repository.Event) (eventstore.Event, error)) { - return "user.added", func(event *repository.Event) (eventstore.Event, error) { +func UserAddedEventMapper() (eventstore.EventType, func(*repository.Event) (eventstore.EventReader, error)) { + return "user.added", func(event *repository.Event) (eventstore.EventReader, error) { e := &UserAddedEvent{ BaseEvent: *eventstore.BaseEventFromRepo(event), } @@ -134,8 +134,8 @@ func NewUserFirstNameChangedEvent(firstName string) *UserFirstNameChangedEvent { } } -func UserFirstNameChangedMapper() (eventstore.EventType, func(*repository.Event) (eventstore.Event, error)) { - return "user.firstName.changed", func(event *repository.Event) (eventstore.Event, error) { +func UserFirstNameChangedMapper() (eventstore.EventType, func(*repository.Event) (eventstore.EventReader, error)) { + return "user.firstName.changed", func(event *repository.Event) (eventstore.EventReader, error) { e := &UserFirstNameChangedEvent{ BaseEvent: *eventstore.BaseEventFromRepo(event), } @@ -173,8 +173,8 @@ func NewUserPasswordCheckedEvent() *UserPasswordCheckedEvent { } } -func UserPasswordCheckedMapper() (eventstore.EventType, func(*repository.Event) (eventstore.Event, error)) { - return "user.password.checked", func(event *repository.Event) (eventstore.Event, error) { +func UserPasswordCheckedMapper() (eventstore.EventType, func(*repository.Event) (eventstore.EventReader, error)) { + return "user.password.checked", func(event *repository.Event) (eventstore.EventReader, error) { return &UserPasswordCheckedEvent{ BaseEvent: *eventstore.BaseEventFromRepo(event), }, nil @@ -207,8 +207,8 @@ func NewUserDeletedEvent() *UserDeletedEvent { } } -func UserDeletedMapper() (eventstore.EventType, func(*repository.Event) (eventstore.Event, error)) { - return "user.deleted", func(event *repository.Event) (eventstore.Event, error) { +func UserDeletedMapper() (eventstore.EventType, func(*repository.Event) (eventstore.EventReader, error)) { + return "user.deleted", func(event *repository.Event) (eventstore.EventReader, error) { return &UserDeletedEvent{ BaseEvent: *eventstore.BaseEventFromRepo(event), }, nil @@ -239,24 +239,24 @@ func NewUsersReadModel() *UsersReadModel { } } -func (rm *UsersReadModel) AppendEvents(events ...eventstore.Event) (err error) { +func (rm *UsersReadModel) AppendEvents(events ...eventstore.EventReader) (err error) { rm.ReadModel.AppendEvents(events...) for _, event := range events { switch e := event.(type) { case *UserAddedEvent: //insert - user := NewUserReadModel(e.Base().AggregateID) + user := NewUserReadModel(e.AggregateID()) rm.Users = append(rm.Users, user) err = user.AppendEvents(e) case *UserFirstNameChangedEvent, *UserPasswordCheckedEvent: //update - _, user := rm.userByID(e.Base().aggregateID) + _, user := rm.userByID(e.AggregateID()) if user == nil { return errors.New("user not found") } err = user.AppendEvents(e) case *UserDeletedEvent: - idx, _ := rm.userByID(e.Base().AggregateID) + idx, _ := rm.userByID(e.AggregateID()) if idx < 0 { return nil } @@ -310,7 +310,7 @@ func NewUserReadModel(id string) *UserReadModel { } } -func (rm *UserReadModel) AppendEvents(events ...eventstore.Event) error { +func (rm *UserReadModel) AppendEvents(events ...eventstore.EventReader) error { rm.ReadModel.AppendEvents(events...) return nil } @@ -324,7 +324,7 @@ func (rm *UserReadModel) Reduce() error { rm.FirstName = e.FirstName case *UserPasswordCheckedEvent: rm.pwCheckCount++ - rm.lastPasswordCheck = e.Base().CreationDate + rm.lastPasswordCheck = e.CreationDate() } } rm.ReadModel.Reduce() diff --git a/internal/eventstore/v2/read_model.go b/internal/eventstore/v2/read_model.go index 51a184df3c..c53be4264d 100644 --- a/internal/eventstore/v2/read_model.go +++ b/internal/eventstore/v2/read_model.go @@ -5,23 +5,23 @@ import "time" func NewReadModel(id string) *ReadModel { return &ReadModel{ ID: id, - Events: []Event{}, + Events: []EventReader{}, } } //ReadModel is the minimum representation of a View model. // it might be saved in a database or in memory type ReadModel struct { - ProcessedSequence uint64 `json:"-"` - ID string `json:"-"` - CreationDate time.Time `json:"-"` - ChangeDate time.Time `json:"-"` - Events []Event `json:"-"` + ProcessedSequence uint64 `json:"-"` + ID string `json:"-"` + CreationDate time.Time `json:"-"` + ChangeDate time.Time `json:"-"` + Events []EventReader `json:"-"` } //AppendEvents adds all the events to the read model. // The function doesn't compute the new state of the read model -func (rm *ReadModel) AppendEvents(events ...Event) *ReadModel { +func (rm *ReadModel) AppendEvents(events ...EventReader) *ReadModel { rm.Events = append(rm.Events, events...) return rm } @@ -33,13 +33,13 @@ func (rm *ReadModel) Reduce() error { } if rm.CreationDate.IsZero() { - rm.CreationDate = rm.Events[0].Base().creationDate + rm.CreationDate = rm.Events[0].CreationDate() } - rm.ChangeDate = rm.Events[len(rm.Events)-1].Base().creationDate - rm.ProcessedSequence = rm.Events[len(rm.Events)-1].Base().sequence + rm.ChangeDate = rm.Events[len(rm.Events)-1].CreationDate() + rm.ProcessedSequence = rm.Events[len(rm.Events)-1].Sequence() // all events processed and not needed anymore rm.Events = nil - rm.Events = []Event{} + rm.Events = []EventReader{} return nil } @@ -69,7 +69,7 @@ func (a *Aggregate) Reduce() error { return nil } - a.PreviousSequence = a.Events[len(a.Events)-1].Base().sequence + a.PreviousSequence = a.Events[len(a.Events)-1].Sequence() // all events processed and not needed anymore a.Events = nil a.Events = []Event{} diff --git a/internal/v2/repository/iam/aggregate.go b/internal/v2/repository/iam/aggregate.go index 2843071844..fd78082bdd 100644 --- a/internal/v2/repository/iam/aggregate.go +++ b/internal/v2/repository/iam/aggregate.go @@ -5,32 +5,3 @@ import "github.com/caos/zitadel/internal/eventstore/v2" type Aggregate struct { eventstore.Aggregate } - -type Step int8 - -type SetupStepEvent struct { - eventstore.BaseEvent `json:"-"` - - Step Step - //Done if the setup is started earlier - Done bool `json:"-"` -} - -func (e *SetupStepEvent) CheckPrevious() bool { - return e.Type() == "iam.setup.started" -} - -//Type implements event -func (e *SetupStepEvent) Type() eventstore.EventType { - if e.Done { - return "iam.setup.done" - } - return "iam.setup.started" -} - -func (e *SetupStepEvent) Data() interface{} { - return e -} - -type MemberAddedEvent struct { -} diff --git a/internal/v2/repository/iam/event_iam_added.go b/internal/v2/repository/iam/event_iam_added.go new file mode 100644 index 0000000000..1f670a2010 --- /dev/null +++ b/internal/v2/repository/iam/event_iam_added.go @@ -0,0 +1,36 @@ +package iam + +import ( + "context" + + "github.com/caos/zitadel/internal/eventstore/v2" +) + +const ( + GlobalOrgSetEventType eventstore.EventType = "iam.global.org.set" +) + +type GlobalOrgSetEvent struct { + eventstore.BaseEvent `json:"-"` + + OrgID string `json:"globalOrgId"` +} + +func (e *GlobalOrgSetEvent) CheckPrevious() bool { + return true +} + +func (e *GlobalOrgSetEvent) Data() interface{} { + return e +} + +func NewGlobalOrgSetEventEvent(ctx context.Context, service, orgID string) *GlobalOrgSetEvent { + return &GlobalOrgSetEvent{ + BaseEvent: *eventstore.NewBaseEventForPush( + ctx, + service, + GlobalOrgSetEventType, + ), + OrgID: orgID, + } +} diff --git a/internal/v2/repository/iam/event_iam_project_set.go b/internal/v2/repository/iam/event_iam_project_set.go new file mode 100644 index 0000000000..9b4c809b02 --- /dev/null +++ b/internal/v2/repository/iam/event_iam_project_set.go @@ -0,0 +1,36 @@ +package iam + +import ( + "context" + + "github.com/caos/zitadel/internal/eventstore/v2" +) + +const ( + IAMProjectSetEventType eventstore.EventType = "iam.project.iam.set" +) + +type IAMProjectSetEvent struct { + eventstore.BaseEvent `json:"-"` + + ProjectID string `json:"iamProjectId"` +} + +func (e *IAMProjectSetEvent) CheckPrevious() bool { + return e.Type() == SetupStartedEventType +} + +func (e *IAMProjectSetEvent) Data() interface{} { + return e +} + +func NewIAMProjectSetEvent(ctx context.Context, service, projectID string) *IAMProjectSetEvent { + return &IAMProjectSetEvent{ + BaseEvent: *eventstore.NewBaseEventForPush( + ctx, + service, + SetupDoneEventType, + ), + ProjectID: projectID, + } +} diff --git a/internal/v2/repository/iam/events_step.go b/internal/v2/repository/iam/events_step.go new file mode 100644 index 0000000000..5ec5d25cef --- /dev/null +++ b/internal/v2/repository/iam/events_step.go @@ -0,0 +1,48 @@ +package iam + +import ( + "context" + + "github.com/caos/zitadel/internal/eventstore/v2" +) + +const ( + SetupDoneEventType eventstore.EventType = "iam.setup.done" + SetupStartedEventType eventstore.EventType = "iam.setup.started" +) + +type Step int8 + +type SetupStepEvent struct { + eventstore.BaseEvent `json:"-"` + + Step Step `json:"Step"` +} + +func (e *SetupStepEvent) CheckPrevious() bool { + return e.Type() == SetupStartedEventType +} + +func (e *SetupStepEvent) Data() interface{} { + return e +} + +func NewSetupStepDoneEvent(ctx context.Context, service string) *SetupStepEvent { + return &SetupStepEvent{ + BaseEvent: *eventstore.NewBaseEventForPush( + ctx, + service, + SetupDoneEventType, + ), + } +} + +func NewSetupStepStartedEvent(ctx context.Context, service string) *SetupStepEvent { + return &SetupStepEvent{ + BaseEvent: *eventstore.NewBaseEventForPush( + ctx, + service, + SetupStartedEventType, + ), + } +} diff --git a/internal/v2/repository/member/event_added.go b/internal/v2/repository/member/event_added.go index 7cceb45035..a94bbb8678 100644 --- a/internal/v2/repository/member/event_added.go +++ b/internal/v2/repository/member/event_added.go @@ -6,14 +6,6 @@ import ( "github.com/caos/zitadel/internal/eventstore/v2" ) -func NewMemberAddedEvent(ctx context.Context, userID string, roles ...string) *MemberAddedEvent { - return &MemberAddedEvent{ - BaseEvent: eventstore.BaseEvent{}, - Roles: roles, - UserID: userID, - } -} - type MemberAddedEvent struct { eventstore.BaseEvent `json:"-"` @@ -28,3 +20,15 @@ func (e *MemberAddedEvent) CheckPrevious() bool { func (e *MemberAddedEvent) Data() interface{} { return e } + +func NewMemberAddedEvent(ctx context.Context, eventType eventstore.EventType, service, userID string, roles ...string) *MemberAddedEvent { + return &MemberAddedEvent{ + BaseEvent: *eventstore.NewBaseEventForPush( + ctx, + service, + eventType, + ), + Roles: roles, + UserID: userID, + } +} diff --git a/internal/v2/repository/member/event_removed.go b/internal/v2/repository/member/event_removed.go index eb13d27138..fd7cc9fa5a 100644 --- a/internal/v2/repository/member/event_removed.go +++ b/internal/v2/repository/member/event_removed.go @@ -1,6 +1,8 @@ package member import ( + "context" + "github.com/caos/zitadel/internal/eventstore/v2" ) @@ -17,3 +19,14 @@ func (e *MemberRemovedEvent) CheckPrevious() bool { func (e *MemberRemovedEvent) Data() interface{} { return e } + +func NewMemberRemovedEvent(ctx context.Context, eventType eventstore.EventType, service, userID string) *MemberRemovedEvent { + return &MemberRemovedEvent{ + BaseEvent: *eventstore.NewBaseEventForPush( + ctx, + service, + eventType, + ), + UserID: userID, + } +} diff --git a/internal/v2/repository/policy/events_label.go b/internal/v2/repository/policy/events_label.go new file mode 100644 index 0000000000..d8ff02258d --- /dev/null +++ b/internal/v2/repository/policy/events_label.go @@ -0,0 +1,44 @@ +package policy + +import ( + "context" + + "github.com/caos/zitadel/internal/eventstore/v2" +) + +const ( + LabelPolicyAddedEventType = "policy.label.added" +) + +type LabelPolicyAddedEvent struct { + eventstore.BaseEvent `json:"-"` + + PrimaryColor string `json:"primaryColor"` + SecondaryColor string `json:"secondaryColor"` +} + +func (e *LabelPolicyAddedEvent) CheckPrevious() bool { + return true +} + +func (e *LabelPolicyAddedEvent) Data() interface{} { + return e +} + +func NewLabelPolicyAddedEvent( + ctx context.Context, + service string, + primaryColor, + secondaryColor string, +) *LabelPolicyAddedEvent { + + return &LabelPolicyAddedEvent{ + BaseEvent: *eventstore.NewBaseEventForPush( + ctx, + service, + LabelPolicyAddedEventType, + ), + PrimaryColor: primaryColor, + SecondaryColor: secondaryColor, + } +} diff --git a/internal/v2/repository/policy/events_login.go b/internal/v2/repository/policy/events_login.go new file mode 100644 index 0000000000..7f939ddcce --- /dev/null +++ b/internal/v2/repository/policy/events_login.go @@ -0,0 +1,48 @@ +package policy + +import ( + "context" + + "github.com/caos/zitadel/internal/eventstore/v2" +) + +const ( + LoginPolicyAddedEventType = "policy.login.added" +) + +type LoginPolicyAddedEvent struct { + eventstore.BaseEvent `json:"-"` + + AllowUserNamePassword bool `json:"allowUsernamePassword"` + AllowRegister bool `json:"allowRegister"` + AllowExternalIDP bool `json:"allowExternalIdp"` + // TODO: IDPProviders +} + +func (e *LoginPolicyAddedEvent) CheckPrevious() bool { + return true +} + +func (e *LoginPolicyAddedEvent) Data() interface{} { + return e +} + +func NewLoginPolicyAddedEvent( + ctx context.Context, + service string, + allowUserNamePassword, + allowRegister, + allowExternalIDP bool, +) *LoginPolicyAddedEvent { + + return &LoginPolicyAddedEvent{ + BaseEvent: *eventstore.NewBaseEventForPush( + ctx, + service, + LoginPolicyAddedEventType, + ), + AllowExternalIDP: allowExternalIDP, + AllowRegister: allowRegister, + AllowUserNamePassword: allowUserNamePassword, + } +} diff --git a/internal/v2/repository/policy/events_org_iam.go b/internal/v2/repository/policy/events_org_iam.go new file mode 100644 index 0000000000..9f5ffb0226 --- /dev/null +++ b/internal/v2/repository/policy/events_org_iam.go @@ -0,0 +1,41 @@ +package policy + +import ( + "context" + + "github.com/caos/zitadel/internal/eventstore/v2" +) + +const ( + OrgIAMPolicyAddedEventType = "policy.org.iam.added" +) + +type OrgIAMPolicyAddedEvent struct { + eventstore.BaseEvent `json:"-"` + + UserLoginMustBeDomain bool `json:"allowUsernamePassword"` +} + +func (e *OrgIAMPolicyAddedEvent) CheckPrevious() bool { + return true +} + +func (e *OrgIAMPolicyAddedEvent) Data() interface{} { + return e +} + +func NewOrgIAMPolicyAddedEvent( + ctx context.Context, + service string, + userLoginMustBeDomain bool, +) *OrgIAMPolicyAddedEvent { + + return &OrgIAMPolicyAddedEvent{ + BaseEvent: *eventstore.NewBaseEventForPush( + ctx, + service, + OrgIAMPolicyAddedEventType, + ), + UserLoginMustBeDomain: userLoginMustBeDomain, + } +} diff --git a/internal/v2/repository/policy/events_password_age.go b/internal/v2/repository/policy/events_password_age.go new file mode 100644 index 0000000000..a1e5c166cd --- /dev/null +++ b/internal/v2/repository/policy/events_password_age.go @@ -0,0 +1,43 @@ +package policy + +import ( + "context" + + "github.com/caos/zitadel/internal/eventstore/v2" +) + +const ( + PasswordAgePolicyAddedEventType = "policy.password.age.added" +) + +type PasswordAgePolicyAddedEvent struct { + eventstore.BaseEvent `json:"-"` + + ExpireWarnDays int `json:"expireWarnDays"` + MaxAgeDays int `json:"maxAgeDays"` +} + +func (e *PasswordAgePolicyAddedEvent) CheckPrevious() bool { + return true +} + +func (e *PasswordAgePolicyAddedEvent) Data() interface{} { + return e +} + +func NewPasswordAgePolicyAddedEvent( + ctx context.Context, + service string, + expireWarnDays, + maxAgeDays int, +) *PasswordAgePolicyAddedEvent { + return &PasswordAgePolicyAddedEvent{ + BaseEvent: *eventstore.NewBaseEventForPush( + ctx, + service, + PasswordAgePolicyAddedEventType, + ), + ExpireWarnDays: expireWarnDays, + MaxAgeDays: maxAgeDays, + } +} diff --git a/internal/v2/repository/policy/events_password_complexity.go b/internal/v2/repository/policy/events_password_complexity.go new file mode 100644 index 0000000000..c8896c849f --- /dev/null +++ b/internal/v2/repository/policy/events_password_complexity.go @@ -0,0 +1,53 @@ +package policy + +import ( + "context" + + "github.com/caos/zitadel/internal/eventstore/v2" +) + +const ( + PasswordComplexityPolicyAddedEventType = "policy.password.complexity.added" +) + +type PasswordComplexityPolicyAddedEvent struct { + eventstore.BaseEvent `json:"-"` + + MinLength int `json:"minLength"` + HasLowercase bool `json:"hasLowercase"` + HasUpperCase bool `json:"hasUppercase"` + HasNumber bool `json:"hasNumber"` + HasSymbol bool `json:"hasSymbol"` +} + +func (e *PasswordComplexityPolicyAddedEvent) CheckPrevious() bool { + return true +} + +func (e *PasswordComplexityPolicyAddedEvent) Data() interface{} { + return e +} + +func NewPasswordComplexityPolicyAddedEvent( + ctx context.Context, + service string, + hasLowerCase, + hasUpperCase, + hasNumber, + hasSymbol bool, + minLength int, +) *PasswordComplexityPolicyAddedEvent { + + return &PasswordComplexityPolicyAddedEvent{ + BaseEvent: *eventstore.NewBaseEventForPush( + ctx, + service, + PasswordComplexityPolicyAddedEventType, + ), + HasLowercase: hasLowerCase, + HasNumber: hasNumber, + HasSymbol: hasSymbol, + HasUpperCase: hasUpperCase, + MinLength: minLength, + } +} diff --git a/internal/v2/repository/policy/events_password_lockout.go b/internal/v2/repository/policy/events_password_lockout.go new file mode 100644 index 0000000000..a5a123d6d1 --- /dev/null +++ b/internal/v2/repository/policy/events_password_lockout.go @@ -0,0 +1,44 @@ +package policy + +import ( + "context" + + "github.com/caos/zitadel/internal/eventstore/v2" +) + +const ( + PasswordLockoutPolicyAddedEventType = "policy.password.lockout.added" +) + +type PasswordLockoutPolicyAddedEvent struct { + eventstore.BaseEvent `json:"-"` + + MaxAttempts int `json:"maxAttempts"` + ShowLockOutFailures bool `json:"showLockOutFailures"` +} + +func (e *PasswordLockoutPolicyAddedEvent) CheckPrevious() bool { + return true +} + +func (e *PasswordLockoutPolicyAddedEvent) Data() interface{} { + return e +} + +func NewPasswordLockoutPolicyAddedEvent( + ctx context.Context, + service string, + maxAttempts int, + showLockOutFailures bool, +) *PasswordLockoutPolicyAddedEvent { + + return &PasswordLockoutPolicyAddedEvent{ + BaseEvent: *eventstore.NewBaseEventForPush( + ctx, + service, + LabelPolicyAddedEventType, + ), + MaxAttempts: maxAttempts, + ShowLockOutFailures: showLockOutFailures, + } +}