mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:07:31 +00:00
feat: add action v2 execution on requests and responses (#7637)
* feat: add execution of targets to grpc calls * feat: add execution of targets to grpc calls * feat: add execution of targets to grpc calls * feat: add execution of targets to grpc calls * feat: add execution of targets to grpc calls * feat: add execution of targets to grpc calls * feat: add execution of targets to grpc calls * feat: split request and response logic to handle the different context information * feat: split request and response logic to handle the different context information * fix: integration test * fix: import alias * fix: refactor execution package * fix: refactor execution interceptor integration and unit tests * fix: refactor execution interceptor integration and unit tests * fix: refactor execution interceptor integration and unit tests * fix: refactor execution interceptor integration and unit tests * fix: refactor execution interceptor integration and unit tests * docs: basic documentation for executions and targets * fix: change order for interceptors * fix: merge back origin/main * fix: change target definition command and query side (#7735) * fix: change target definition command and query side * fix: correct refactoring name changes * fix: correct refactoring name changes * fix: changing execution defintion with target list and type * fix: changing execution definition with target list and type * fix: add back search queries for target and include * fix: projections change for execution with targets suffix table * fix: projections change for execution with targets suffix table * fix: projections change for execution with targets suffix table * fix: projections change for execution with targets suffix table * fix: projections change for execution with targets suffix table * fix: projections change for execution with targets suffix table * fix: projections change for execution with targets suffix table * docs: add example to actions v2 * docs: add example to actions v2 * fix: correct integration tests on query for executions * fix: add separate event for execution v2 as content changed * fix: add separate event for execution v2 as content changed * fix: added review comment changes * fix: added review comment changes * fix: added review comment changes --------- Co-authored-by: adlerhurst <silvan.reusser@gmail.com> * fix: added review comment changes * fix: added review comment changes * Update internal/api/grpc/server/middleware/execution_interceptor.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * fix: added review comment changes * fix: added review comment changes * fix: added review comment changes * fix: added review comment changes * fix: added review comment changes * fix: added review comment changes --------- Co-authored-by: adlerhurst <silvan.reusser@gmail.com> Co-authored-by: Elio Bischof <elio@zitadel.com>
This commit is contained in:
@@ -3,6 +3,7 @@ package projection
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
@@ -11,15 +12,19 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
ExecutionTable = "projections.executions"
|
||||
ExecutionIDCol = "id"
|
||||
ExecutionCreationDateCol = "creation_date"
|
||||
ExecutionChangeDateCol = "change_date"
|
||||
ExecutionResourceOwnerCol = "resource_owner"
|
||||
ExecutionInstanceIDCol = "instance_id"
|
||||
ExecutionSequenceCol = "sequence"
|
||||
ExecutionTargetsCol = "targets"
|
||||
ExecutionIncludesCol = "includes"
|
||||
ExecutionTable = "projections.executions1"
|
||||
ExecutionIDCol = "id"
|
||||
ExecutionCreationDateCol = "creation_date"
|
||||
ExecutionChangeDateCol = "change_date"
|
||||
ExecutionInstanceIDCol = "instance_id"
|
||||
ExecutionSequenceCol = "sequence"
|
||||
|
||||
ExecutionTargetSuffix = "targets"
|
||||
ExecutionTargetExecutionIDCol = "execution_id"
|
||||
ExecutionTargetInstanceIDCol = "instance_id"
|
||||
ExecutionTargetPositionCol = "position"
|
||||
ExecutionTargetTargetIDCol = "target_id"
|
||||
ExecutionTargetIncludeCol = "include"
|
||||
)
|
||||
|
||||
type executionProjection struct{}
|
||||
@@ -33,19 +38,28 @@ func (*executionProjection) Name() string {
|
||||
}
|
||||
|
||||
func (*executionProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
return handler.NewMultiTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(ExecutionIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(ExecutionCreationDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(ExecutionChangeDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(ExecutionResourceOwnerCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(ExecutionInstanceIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(ExecutionSequenceCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(ExecutionTargetsCol, handler.ColumnTypeTextArray, handler.Nullable()),
|
||||
handler.NewColumn(ExecutionIncludesCol, handler.ColumnTypeTextArray, handler.Nullable()),
|
||||
handler.NewColumn(ExecutionInstanceIDCol, handler.ColumnTypeText),
|
||||
},
|
||||
handler.NewPrimaryKey(ExecutionInstanceIDCol, ExecutionIDCol),
|
||||
),
|
||||
handler.NewSuffixedTable([]*handler.InitColumn{
|
||||
handler.NewColumn(ExecutionTargetInstanceIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(ExecutionTargetExecutionIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(ExecutionTargetPositionCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(ExecutionTargetIncludeCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(ExecutionTargetTargetIDCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
},
|
||||
handler.NewPrimaryKey(ExecutionTargetInstanceIDCol, ExecutionTargetExecutionIDCol, ExecutionTargetPositionCol),
|
||||
ExecutionTargetSuffix,
|
||||
handler.WithForeignKey(handler.NewForeignKey("execution", []string{ExecutionTargetInstanceIDCol, ExecutionTargetExecutionIDCol}, []string{ExecutionInstanceIDCol, ExecutionIDCol})),
|
||||
handler.WithIndex(handler.NewIndex("execution", []string{ExecutionTargetInstanceIDCol, ExecutionTargetExecutionIDCol})),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -55,7 +69,7 @@ func (p *executionProjection) Reducers() []handler.AggregateReducer {
|
||||
Aggregate: exec.AggregateType,
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: exec.SetEventType,
|
||||
Event: exec.SetEventV2Type,
|
||||
Reduce: p.reduceExecutionSet,
|
||||
},
|
||||
{
|
||||
@@ -77,21 +91,65 @@ func (p *executionProjection) Reducers() []handler.AggregateReducer {
|
||||
}
|
||||
|
||||
func (p *executionProjection) reduceExecutionSet(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, err := assertEvent[*exec.SetEvent](event)
|
||||
e, err := assertEvent[*exec.SetEventV2](event)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
columns := []handler.Column{
|
||||
handler.NewCol(ExecutionInstanceIDCol, e.Aggregate().InstanceID),
|
||||
handler.NewCol(ExecutionIDCol, e.Aggregate().ID),
|
||||
handler.NewCol(ExecutionResourceOwnerCol, e.Aggregate().ResourceOwner),
|
||||
handler.NewCol(ExecutionCreationDateCol, handler.OnlySetValueOnInsert(ExecutionTable, e.CreationDate())),
|
||||
handler.NewCol(ExecutionChangeDateCol, e.CreationDate()),
|
||||
handler.NewCol(ExecutionSequenceCol, e.Sequence()),
|
||||
handler.NewCol(ExecutionTargetsCol, e.Targets),
|
||||
handler.NewCol(ExecutionIncludesCol, e.Includes),
|
||||
|
||||
stmts := []func(eventstore.Event) handler.Exec{
|
||||
handler.AddUpsertStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(ExecutionInstanceIDCol, e.Aggregate().InstanceID),
|
||||
handler.NewCol(ExecutionIDCol, e.Aggregate().ID),
|
||||
},
|
||||
[]handler.Column{
|
||||
handler.NewCol(ExecutionInstanceIDCol, e.Aggregate().InstanceID),
|
||||
handler.NewCol(ExecutionIDCol, e.Aggregate().ID),
|
||||
handler.NewCol(ExecutionCreationDateCol, handler.OnlySetValueOnInsert(ExecutionTable, e.CreationDate())),
|
||||
handler.NewCol(ExecutionChangeDateCol, e.CreationDate()),
|
||||
handler.NewCol(ExecutionSequenceCol, e.Sequence()),
|
||||
},
|
||||
),
|
||||
// cleanup execution targets to re-insert them
|
||||
handler.AddDeleteStatement(
|
||||
[]handler.Condition{
|
||||
handler.NewCond(ExecutionTargetInstanceIDCol, e.Aggregate().InstanceID),
|
||||
handler.NewCond(ExecutionTargetExecutionIDCol, e.Aggregate().ID),
|
||||
},
|
||||
handler.WithTableSuffix(ExecutionTargetSuffix),
|
||||
),
|
||||
}
|
||||
return handler.NewUpsertStatement(e, columns[0:2], columns), nil
|
||||
|
||||
if len(e.Targets) > 0 {
|
||||
for i, target := range e.Targets {
|
||||
var targetStr, includeStr string
|
||||
switch target.Type {
|
||||
case domain.ExecutionTargetTypeTarget:
|
||||
targetStr = target.Target
|
||||
case domain.ExecutionTargetTypeInclude:
|
||||
includeStr = target.Target
|
||||
case domain.ExecutionTargetTypeUnspecified:
|
||||
continue
|
||||
default:
|
||||
continue
|
||||
}
|
||||
|
||||
stmts = append(stmts,
|
||||
handler.AddCreateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(ExecutionTargetInstanceIDCol, e.Aggregate().InstanceID),
|
||||
handler.NewCol(ExecutionTargetExecutionIDCol, e.Aggregate().ID),
|
||||
handler.NewCol(ExecutionTargetPositionCol, i+1),
|
||||
handler.NewCol(ExecutionTargetIncludeCol, includeStr),
|
||||
handler.NewCol(ExecutionTargetTargetIDCol, targetStr),
|
||||
},
|
||||
handler.WithTableSuffix(ExecutionTargetSuffix),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return handler.NewMultiStatement(e, stmts...), nil
|
||||
}
|
||||
|
||||
func (p *executionProjection) reduceExecutionRemoved(event eventstore.Event) (*handler.Statement, error) {
|
||||
@@ -99,8 +157,8 @@ func (p *executionProjection) reduceExecutionRemoved(event eventstore.Event) (*h
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
|
||||
return handler.NewDeleteStatement(e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(ExecutionInstanceIDCol, e.Aggregate().InstanceID),
|
||||
handler.NewCond(ExecutionIDCol, e.Aggregate().ID),
|
||||
|
Reference in New Issue
Block a user