zitadel/internal/repository/execution/execution.go
Elio Bischof cc3ec1e2a7
feat(v3alpha): write actions (#8225)
# Which Problems Are Solved

The current v3alpha actions APIs don't exactly adhere to the [new
resources API
design](https://zitadel.com/docs/apis/v3#standard-resources).

# How the Problems Are Solved

- **Breaking**: The current v3alpha actions APIs are removed. This is
breaking.
- **Resource Namespace**: New v3alpha actions APIs for targets and
executions are added under the namespace /resources.
- **Feature Flag**: New v3alpha actions APIs still have to be activated
using the actions feature flag
- **Reduced Executions Overhead**: Executions are managed similar to
settings according to the new API design: an empty list of targets
basically makes an execution a Noop. So a single method, SetExecution is
enough to cover all use cases. Noop executions are not returned in
future search requests.
- **Compatibility**: The executions created with previous v3alpha APIs
are still available to be managed with the new executions API.

# Additional Changes

- Removed integration tests which test executions but rely on readable
targets. They are added again with #8169

# Additional Context

Closes #8168
2024-07-31 14:42:12 +02:00

101 lines
2.1 KiB
Go

package execution
import (
"context"
"github.com/zitadel/zitadel/internal/domain"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/zerrors"
)
const (
eventTypePrefix eventstore.EventType = "execution."
SetEventType = eventTypePrefix + "set"
SetEventV2Type = eventTypePrefix + "v2.set"
RemovedEventType = eventTypePrefix + "removed"
)
type SetEvent struct {
*eventstore.BaseEvent `json:"-"`
Targets []string `json:"targets"`
Includes []string `json:"includes"`
}
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
}
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"`
}
func (t *Target) Validate() error {
if t.Type == domain.ExecutionTargetTypeUnspecified || t.Target == "" {
return zerrors.ThrowInvalidArgument(nil, "COMMAND-hdm4zl1hmd", "Errors.Execution.Invalid")
}
return nil
}
func NewSetEventV2(
ctx context.Context,
aggregate *eventstore.Aggregate,
targets []*Target,
) *SetEventV2 {
return &SetEventV2{
BaseEvent: eventstore.NewBaseEventForPush(
ctx, aggregate, SetEventV2Type,
),
Targets: targets,
}
}
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),
}
}