2024-02-26 10:49:43 +00:00
|
|
|
package execution
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2024-05-04 09:55:57 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
2024-02-26 10:49:43 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
2024-07-31 12:42:12 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
2024-02-26 10:49:43 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
eventTypePrefix eventstore.EventType = "execution."
|
|
|
|
SetEventType = eventTypePrefix + "set"
|
2024-05-04 09:55:57 +00:00
|
|
|
SetEventV2Type = eventTypePrefix + "v2.set"
|
2024-02-26 10:49:43 +00:00
|
|
|
RemovedEventType = eventTypePrefix + "removed"
|
|
|
|
)
|
|
|
|
|
|
|
|
type SetEvent struct {
|
|
|
|
*eventstore.BaseEvent `json:"-"`
|
|
|
|
|
2024-03-14 09:56:23 +00:00
|
|
|
Targets []string `json:"targets"`
|
|
|
|
Includes []string `json:"includes"`
|
2024-02-26 10:49:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (e *SetEvent) SetBaseEvent(b *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = b
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *SetEvent) Payload() any {
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *SetEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-05-04 09:55:57 +00:00
|
|
|
type SetEventV2 struct {
|
|
|
|
*eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
Targets []*Target `json:"targets"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *SetEventV2) SetBaseEvent(b *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = b
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *SetEventV2) Payload() any {
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *SetEventV2) UniqueConstraints() []*eventstore.UniqueConstraint {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type Target struct {
|
|
|
|
Type domain.ExecutionTargetType `json:"type"`
|
|
|
|
Target string `json:"target"`
|
|
|
|
}
|
|
|
|
|
2024-07-31 12:42:12 +00:00
|
|
|
func (t *Target) Validate() error {
|
|
|
|
if t.Type == domain.ExecutionTargetTypeUnspecified || t.Target == "" {
|
|
|
|
return zerrors.ThrowInvalidArgument(nil, "COMMAND-hdm4zl1hmd", "Errors.Execution.Invalid")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-05-04 09:55:57 +00:00
|
|
|
func NewSetEventV2(
|
2024-02-26 10:49:43 +00:00
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
2024-05-04 09:55:57 +00:00
|
|
|
targets []*Target,
|
|
|
|
) *SetEventV2 {
|
|
|
|
return &SetEventV2{
|
2024-02-26 10:49:43 +00:00
|
|
|
BaseEvent: eventstore.NewBaseEventForPush(
|
2024-05-04 09:55:57 +00:00
|
|
|
ctx, aggregate, SetEventV2Type,
|
2024-02-26 10:49:43 +00:00
|
|
|
),
|
2024-05-04 09:55:57 +00:00
|
|
|
Targets: targets,
|
2024-02-26 10:49:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type RemovedEvent struct {
|
|
|
|
*eventstore.BaseEvent `json:"-"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *RemovedEvent) SetBaseEvent(b *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = b
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *RemovedEvent) Payload() any {
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *RemovedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewRemovedEvent(ctx context.Context, aggregate *eventstore.Aggregate) *RemovedEvent {
|
|
|
|
return &RemovedEvent{
|
|
|
|
eventstore.NewBaseEventForPush(ctx, aggregate, RemovedEventType),
|
|
|
|
}
|
|
|
|
}
|