mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-05 08:02:07 +00:00
calculate and push 4 in 6 milestones
This commit is contained in:
@@ -13,15 +13,14 @@ type Aggregate struct {
|
||||
eventstore.Aggregate
|
||||
}
|
||||
|
||||
// Each data point receives its own aggregate
|
||||
func newAggregate(id, instanceId, resourceOwner string) *Aggregate {
|
||||
func NewAggregate(id, resourceOwner, instanceID string) *Aggregate {
|
||||
return &Aggregate{
|
||||
Aggregate: eventstore.Aggregate{
|
||||
Type: AggregateType,
|
||||
Version: AggregateVersion,
|
||||
ID: id,
|
||||
InstanceID: instanceId,
|
||||
ResourceOwner: resourceOwner,
|
||||
InstanceID: instanceID,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,66 +1,216 @@
|
||||
//go:
|
||||
|
||||
package milestone
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"time"
|
||||
"fmt"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
)
|
||||
|
||||
type PushedEventType eventstore.EventType
|
||||
|
||||
const (
|
||||
eventTypePrefix = eventstore.EventType("milestone.")
|
||||
PushedEventType = eventTypePrefix + "pushed"
|
||||
eventTypePrefix = PushedEventType("milestone.pushed.")
|
||||
PushedInstanceCreatedEventType = eventTypePrefix + "instance.created"
|
||||
PushedAuthenticationSucceededOnInstanceEventType = eventTypePrefix + "instance.authentication.succeeded"
|
||||
PushedProjectCreatedEventType = eventTypePrefix + "project.created"
|
||||
PushedApplicationCreatedEventType = eventTypePrefix + "application.created"
|
||||
PushedAuthenticationSucceededOnApplicationEventType = eventTypePrefix + "application.authentication.succeeded"
|
||||
PushedInstanceDeletedEventType = eventTypePrefix + "instance.deleted"
|
||||
)
|
||||
|
||||
type PushedEvent struct {
|
||||
func PushedEventTypes() []PushedEventType {
|
||||
return []PushedEventType{
|
||||
PushedInstanceCreatedEventType,
|
||||
PushedAuthenticationSucceededOnInstanceEventType,
|
||||
PushedProjectCreatedEventType,
|
||||
PushedApplicationCreatedEventType,
|
||||
PushedAuthenticationSucceededOnApplicationEventType,
|
||||
PushedInstanceDeletedEventType,
|
||||
}
|
||||
}
|
||||
|
||||
type PushedEvent interface {
|
||||
eventstore.Command
|
||||
IsMilestoneEvent()
|
||||
}
|
||||
|
||||
type basePushedEvent struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
Milestone Milestone `json:"milestone"`
|
||||
Reached time.Time `json:"reached"`
|
||||
Endpoints []string `json:"endpoints"`
|
||||
PrimaryDomain string `json:"primaryDomain"`
|
||||
PrimaryDomain string `json:"primaryDomain"`
|
||||
Endpoints []string `json:"endpoints"`
|
||||
}
|
||||
|
||||
func (e *PushedEvent) Data() interface{} {
|
||||
return e
|
||||
func (b *basePushedEvent) Data() interface{} {
|
||||
return b
|
||||
}
|
||||
|
||||
func (e *PushedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
||||
func (b *basePushedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewPushedEvent(
|
||||
func (b *basePushedEvent) SetBaseEvent(base *eventstore.BaseEvent) {
|
||||
b.BaseEvent = *base
|
||||
}
|
||||
|
||||
func NewPushedEventByType(
|
||||
ctx context.Context,
|
||||
newAggregate *Aggregate,
|
||||
milestone Milestone,
|
||||
reached time.Time,
|
||||
eventType PushedEventType,
|
||||
aggregate *Aggregate,
|
||||
endpoints []string,
|
||||
primaryDomain string,
|
||||
) *PushedEvent {
|
||||
return &PushedEvent{
|
||||
BaseEvent: *eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
&newAggregate.Aggregate,
|
||||
PushedEventType,
|
||||
),
|
||||
Milestone: milestone,
|
||||
Reached: reached,
|
||||
Endpoints: endpoints,
|
||||
PrimaryDomain: primaryDomain,
|
||||
) (PushedEvent, error) {
|
||||
switch eventType {
|
||||
case PushedInstanceCreatedEventType:
|
||||
return NewInstanceCreatedPushedEvent(ctx, aggregate, endpoints, primaryDomain), nil
|
||||
case PushedAuthenticationSucceededOnInstanceEventType:
|
||||
return NewAuthenticationSucceededOnInstancePushedEvent(ctx, aggregate, endpoints, primaryDomain), nil
|
||||
case PushedProjectCreatedEventType:
|
||||
return NewProjectCreatedPushedEvent(ctx, aggregate, endpoints, primaryDomain), nil
|
||||
case PushedApplicationCreatedEventType:
|
||||
return NewApplicationCreatedPushedEvent(ctx, aggregate, endpoints, primaryDomain), nil
|
||||
case PushedAuthenticationSucceededOnApplicationEventType:
|
||||
return NewAuthenticationSucceededOnApplicationPushedEvent(ctx, aggregate, endpoints, primaryDomain), nil
|
||||
case PushedInstanceDeletedEventType:
|
||||
return NewInstanceDeletedPushedEvent(ctx, aggregate, endpoints, primaryDomain), nil
|
||||
}
|
||||
return nil, fmt.Errorf("unknown event type %s", eventType)
|
||||
}
|
||||
|
||||
type InstanceCreatedPushedEvent struct{ basePushedEvent }
|
||||
|
||||
func (e *InstanceCreatedPushedEvent) IsMilestoneEvent() {}
|
||||
|
||||
func NewInstanceCreatedPushedEvent(
|
||||
ctx context.Context,
|
||||
aggregate *Aggregate,
|
||||
endpoints []string,
|
||||
primaryDomain string,
|
||||
) *InstanceCreatedPushedEvent {
|
||||
return &InstanceCreatedPushedEvent{
|
||||
basePushedEvent: basePushedEvent{
|
||||
BaseEvent: *eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
&aggregate.Aggregate,
|
||||
eventstore.EventType(PushedInstanceCreatedEventType),
|
||||
),
|
||||
Endpoints: endpoints,
|
||||
PrimaryDomain: primaryDomain,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func PushedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
||||
e := &PushedEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
type AuthenticationSucceededOnInstancePushedEvent struct{ basePushedEvent }
|
||||
|
||||
func (e *AuthenticationSucceededOnInstancePushedEvent) IsMilestoneEvent() {}
|
||||
|
||||
func NewAuthenticationSucceededOnInstancePushedEvent(
|
||||
ctx context.Context,
|
||||
aggregate *Aggregate,
|
||||
endpoints []string,
|
||||
primaryDomain string,
|
||||
) *AuthenticationSucceededOnInstancePushedEvent {
|
||||
return &AuthenticationSucceededOnInstancePushedEvent{
|
||||
basePushedEvent: basePushedEvent{
|
||||
BaseEvent: *eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
&aggregate.Aggregate,
|
||||
eventstore.EventType(PushedAuthenticationSucceededOnInstanceEventType),
|
||||
),
|
||||
Endpoints: endpoints,
|
||||
PrimaryDomain: primaryDomain,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type ProjectCreatedPushedEvent struct{ basePushedEvent }
|
||||
|
||||
func (e *ProjectCreatedPushedEvent) IsMilestoneEvent() {}
|
||||
|
||||
func NewProjectCreatedPushedEvent(
|
||||
ctx context.Context,
|
||||
aggregate *Aggregate,
|
||||
endpoints []string,
|
||||
primaryDomain string,
|
||||
) *ProjectCreatedPushedEvent {
|
||||
return &ProjectCreatedPushedEvent{
|
||||
basePushedEvent: basePushedEvent{
|
||||
BaseEvent: *eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
&aggregate.Aggregate,
|
||||
eventstore.EventType(PushedProjectCreatedEventType),
|
||||
),
|
||||
Endpoints: endpoints,
|
||||
PrimaryDomain: primaryDomain,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type ApplicationCreatedPushedEvent struct{ basePushedEvent }
|
||||
|
||||
func (e *ApplicationCreatedPushedEvent) IsMilestoneEvent() {}
|
||||
|
||||
func NewApplicationCreatedPushedEvent(
|
||||
ctx context.Context,
|
||||
aggregate *Aggregate,
|
||||
endpoints []string,
|
||||
primaryDomain string,
|
||||
) *ApplicationCreatedPushedEvent {
|
||||
return &ApplicationCreatedPushedEvent{
|
||||
basePushedEvent: basePushedEvent{
|
||||
BaseEvent: *eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
&aggregate.Aggregate,
|
||||
eventstore.EventType(PushedApplicationCreatedEventType),
|
||||
),
|
||||
Endpoints: endpoints,
|
||||
PrimaryDomain: primaryDomain,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type AuthenticationSucceededOnApplicationPushedEvent struct{ basePushedEvent }
|
||||
|
||||
func (e *AuthenticationSucceededOnApplicationPushedEvent) IsMilestoneEvent() {}
|
||||
|
||||
func NewAuthenticationSucceededOnApplicationPushedEvent(
|
||||
ctx context.Context,
|
||||
aggregate *Aggregate,
|
||||
endpoints []string,
|
||||
primaryDomain string,
|
||||
) *AuthenticationSucceededOnApplicationPushedEvent {
|
||||
return &AuthenticationSucceededOnApplicationPushedEvent{
|
||||
basePushedEvent: basePushedEvent{
|
||||
BaseEvent: *eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
&aggregate.Aggregate,
|
||||
eventstore.EventType(PushedAuthenticationSucceededOnApplicationEventType),
|
||||
),
|
||||
Endpoints: endpoints,
|
||||
PrimaryDomain: primaryDomain,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type InstanceDeletedPushedEvent struct{ basePushedEvent }
|
||||
|
||||
func (e *InstanceDeletedPushedEvent) IsMilestoneEvent() {}
|
||||
|
||||
func NewInstanceDeletedPushedEvent(
|
||||
ctx context.Context,
|
||||
aggregate *Aggregate,
|
||||
endpoints []string,
|
||||
primaryDomain string,
|
||||
) *InstanceDeletedPushedEvent {
|
||||
return &InstanceDeletedPushedEvent{
|
||||
basePushedEvent: basePushedEvent{
|
||||
BaseEvent: *eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
&aggregate.Aggregate,
|
||||
eventstore.EventType(PushedInstanceDeletedEventType),
|
||||
),
|
||||
Endpoints: endpoints,
|
||||
PrimaryDomain: primaryDomain,
|
||||
},
|
||||
}
|
||||
err := json.Unmarshal(event.Data, e)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "QUOTA-4n8vs", "unable to unmarshal milestone pushed")
|
||||
}
|
||||
return e, nil
|
||||
}
|
||||
|
||||
@@ -5,6 +5,10 @@ import (
|
||||
)
|
||||
|
||||
func RegisterEventMappers(es *eventstore.Eventstore) {
|
||||
es.RegisterFilterEventMapper(AggregateType, ReachedEventType, ReachedEventMapper).
|
||||
RegisterFilterEventMapper(AggregateType, PushedEventType, PushedEventMapper)
|
||||
es.RegisterFilterEventMapper(AggregateType, eventstore.EventType(PushedProjectCreatedEventType), eventstore.GenericEventMapper[InstanceCreatedPushedEvent]).
|
||||
RegisterFilterEventMapper(AggregateType, eventstore.EventType(PushedAuthenticationSucceededOnInstanceEventType), eventstore.GenericEventMapper[AuthenticationSucceededOnInstancePushedEvent]).
|
||||
RegisterFilterEventMapper(AggregateType, eventstore.EventType(PushedProjectCreatedEventType), eventstore.GenericEventMapper[ProjectCreatedPushedEvent]).
|
||||
RegisterFilterEventMapper(AggregateType, eventstore.EventType(PushedApplicationCreatedEventType), eventstore.GenericEventMapper[ApplicationCreatedPushedEvent]).
|
||||
RegisterFilterEventMapper(AggregateType, eventstore.EventType(PushedAuthenticationSucceededOnApplicationEventType), eventstore.GenericEventMapper[AuthenticationSucceededOnApplicationPushedEvent]).
|
||||
RegisterFilterEventMapper(AggregateType, eventstore.EventType(PushedInstanceDeletedEventType), eventstore.GenericEventMapper[InstanceDeletedPushedEvent])
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
// Code generated by "stringer -type=Milestone"; DO NOT EDIT.
|
||||
|
||||
package milestone
|
||||
|
||||
import "strconv"
|
||||
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[unknown-0]
|
||||
_ = x[InstanceCreated-1]
|
||||
_ = x[AuthenticationSucceededOnInstance-2]
|
||||
_ = x[ProjectCreated-3]
|
||||
_ = x[ApplicationCreated-4]
|
||||
_ = x[AuthenticationSucceededOnApplication-5]
|
||||
_ = x[InstanceDeleted-6]
|
||||
_ = x[milestonesCount-7]
|
||||
}
|
||||
|
||||
const _Milestone_name = "unknownInstanceCreatedAuthenticationSucceededOnInstanceProjectCreatedApplicationCreatedAuthenticationSucceededOnApplicationInstanceDeletedmilestonesCount"
|
||||
|
||||
var _Milestone_index = [...]uint8{0, 7, 22, 55, 69, 87, 123, 138, 153}
|
||||
|
||||
func (i Milestone) String() string {
|
||||
if i < 0 || i >= Milestone(len(_Milestone_index)-1) {
|
||||
return "Milestone(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
return _Milestone_name[_Milestone_index[i]:_Milestone_index[i+1]]
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
//go:generate stringer -type=Milestone
|
||||
|
||||
package milestone
|
||||
|
||||
type Milestone int
|
||||
|
||||
const (
|
||||
unknown Milestone = iota
|
||||
InstanceCreated
|
||||
AuthenticationSucceededOnInstance
|
||||
ProjectCreated
|
||||
ApplicationCreated
|
||||
AuthenticationSucceededOnApplication
|
||||
InstanceDeleted
|
||||
|
||||
milestonesCount
|
||||
)
|
||||
|
||||
func All() []Milestone {
|
||||
milestones := make([]Milestone, milestonesCount-1)
|
||||
for i := 1; i < int(milestonesCount); i++ {
|
||||
milestones[i] = Milestone(i)
|
||||
}
|
||||
return milestones
|
||||
}
|
||||
Reference in New Issue
Block a user