chore: move the go code into a subfolder

This commit is contained in:
Florian Forster
2025-08-05 15:20:32 -07:00
parent 4ad22ba456
commit cd2921de26
2978 changed files with 373 additions and 300 deletions

View File

@@ -0,0 +1,34 @@
package execution
import (
"strings"
"github.com/zitadel/zitadel/internal/domain"
"github.com/zitadel/zitadel/internal/eventstore"
)
const (
AggregateType = "execution"
AggregateVersion = "v1"
)
func NewAggregate(aggrID, instanceID string) *eventstore.Aggregate {
return &eventstore.Aggregate{
ID: aggrID,
Type: AggregateType,
ResourceOwner: instanceID,
InstanceID: instanceID,
Version: AggregateVersion,
}
}
func ID(executionType domain.ExecutionType, value string) string {
if strings.HasPrefix(value, "/") {
return strings.Join([]string{executionType.String(), value}, "")
}
return strings.Join([]string{executionType.String(), value}, "/")
}
func IDAll(executionType domain.ExecutionType) string {
return executionType.String()
}

View File

@@ -0,0 +1,9 @@
package execution
import "github.com/zitadel/zitadel/internal/eventstore"
func init() {
eventstore.RegisterFilterEventMapper(AggregateType, SetEventType, eventstore.GenericEventMapper[SetEvent])
eventstore.RegisterFilterEventMapper(AggregateType, SetEventV2Type, eventstore.GenericEventMapper[SetEventV2])
eventstore.RegisterFilterEventMapper(AggregateType, RemovedEventType, eventstore.GenericEventMapper[RemovedEvent])
}

View File

@@ -0,0 +1,100 @@
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),
}
}

View File

@@ -0,0 +1,71 @@
package execution
import (
"encoding/json"
"time"
"github.com/zitadel/zitadel/internal/eventstore"
)
const (
QueueName = "execution"
)
type Request struct {
Aggregate *eventstore.Aggregate `json:"aggregate"`
Sequence uint64 `json:"sequence"`
EventType eventstore.EventType `json:"eventType"`
CreatedAt time.Time `json:"createdAt"`
UserID string `json:"userID"`
EventData []byte `json:"eventData"`
TargetsData []byte `json:"targetsData"`
}
func (e *Request) Kind() string {
return "execution_request"
}
func ContextInfoFromRequest(e *Request) *ContextInfoEvent {
return &ContextInfoEvent{
AggregateID: e.Aggregate.ID,
AggregateType: string(e.Aggregate.Type),
ResourceOwner: e.Aggregate.ResourceOwner,
InstanceID: e.Aggregate.InstanceID,
Version: string(e.Aggregate.Version),
Sequence: e.Sequence,
EventType: string(e.EventType),
CreatedAt: e.CreatedAt.Format(time.RFC3339Nano),
UserID: e.UserID,
EventPayload: e.EventData,
}
}
type ContextInfoEvent struct {
AggregateID string `json:"aggregateID,omitempty"`
AggregateType string `json:"aggregateType,omitempty"`
ResourceOwner string `json:"resourceOwner,omitempty"`
InstanceID string `json:"instanceID,omitempty"`
Version string `json:"version,omitempty"`
Sequence uint64 `json:"sequence,omitempty"`
EventType string `json:"event_type,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
UserID string `json:"userID,omitempty"`
EventPayload json.RawMessage `json:"event_payload,omitempty"`
}
func (c *ContextInfoEvent) GetHTTPRequestBody() []byte {
data, err := json.Marshal(c)
if err != nil {
return nil
}
return data
}
func (c *ContextInfoEvent) SetHTTPResponseBody(resp []byte) error {
// response is irrelevant and will not be unmarshaled
return nil
}
func (c *ContextInfoEvent) GetContent() any {
return c.EventPayload
}