mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-14 03:54:21 +00:00
1c5ecba42a
* 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>
160 lines
5.0 KiB
Go
160 lines
5.0 KiB
Go
package projection
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
|
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
|
"github.com/zitadel/zitadel/internal/repository/instance"
|
|
"github.com/zitadel/zitadel/internal/repository/target"
|
|
)
|
|
|
|
const (
|
|
TargetTable = "projections.targets1"
|
|
TargetIDCol = "id"
|
|
TargetCreationDateCol = "creation_date"
|
|
TargetChangeDateCol = "change_date"
|
|
TargetResourceOwnerCol = "resource_owner"
|
|
TargetInstanceIDCol = "instance_id"
|
|
TargetSequenceCol = "sequence"
|
|
TargetNameCol = "name"
|
|
TargetTargetType = "target_type"
|
|
TargetEndpointCol = "endpoint"
|
|
TargetTimeoutCol = "timeout"
|
|
TargetInterruptOnErrorCol = "interrupt_on_error"
|
|
)
|
|
|
|
type targetProjection struct{}
|
|
|
|
func newTargetProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
|
return handler.NewHandler(ctx, &config, new(targetProjection))
|
|
}
|
|
|
|
func (*targetProjection) Name() string {
|
|
return TargetTable
|
|
}
|
|
|
|
func (*targetProjection) Init() *old_handler.Check {
|
|
return handler.NewTableCheck(
|
|
handler.NewTable([]*handler.InitColumn{
|
|
handler.NewColumn(TargetIDCol, handler.ColumnTypeText),
|
|
handler.NewColumn(TargetCreationDateCol, handler.ColumnTypeTimestamp),
|
|
handler.NewColumn(TargetChangeDateCol, handler.ColumnTypeTimestamp),
|
|
handler.NewColumn(TargetResourceOwnerCol, handler.ColumnTypeText),
|
|
handler.NewColumn(TargetInstanceIDCol, handler.ColumnTypeText),
|
|
handler.NewColumn(TargetTargetType, handler.ColumnTypeEnum),
|
|
handler.NewColumn(TargetSequenceCol, handler.ColumnTypeInt64),
|
|
handler.NewColumn(TargetNameCol, handler.ColumnTypeText),
|
|
handler.NewColumn(TargetEndpointCol, handler.ColumnTypeText),
|
|
handler.NewColumn(TargetTimeoutCol, handler.ColumnTypeInt64),
|
|
handler.NewColumn(TargetInterruptOnErrorCol, handler.ColumnTypeBool),
|
|
},
|
|
handler.NewPrimaryKey(TargetInstanceIDCol, TargetIDCol),
|
|
),
|
|
)
|
|
}
|
|
|
|
func (p *targetProjection) Reducers() []handler.AggregateReducer {
|
|
return []handler.AggregateReducer{
|
|
{
|
|
Aggregate: target.AggregateType,
|
|
EventReducers: []handler.EventReducer{
|
|
{
|
|
Event: target.AddedEventType,
|
|
Reduce: p.reduceTargetAdded,
|
|
},
|
|
{
|
|
Event: target.ChangedEventType,
|
|
Reduce: p.reduceTargetChanged,
|
|
},
|
|
{
|
|
Event: target.RemovedEventType,
|
|
Reduce: p.reduceTargetRemoved,
|
|
},
|
|
},
|
|
},
|
|
{
|
|
Aggregate: instance.AggregateType,
|
|
EventReducers: []handler.EventReducer{
|
|
{
|
|
Event: instance.InstanceRemovedEventType,
|
|
Reduce: reduceInstanceRemovedHelper(TargetInstanceIDCol),
|
|
},
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func (p *targetProjection) reduceTargetAdded(event eventstore.Event) (*handler.Statement, error) {
|
|
e, err := assertEvent[*target.AddedEvent](event)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return handler.NewCreateStatement(
|
|
e,
|
|
[]handler.Column{
|
|
handler.NewCol(TargetInstanceIDCol, e.Aggregate().InstanceID),
|
|
handler.NewCol(TargetResourceOwnerCol, e.Aggregate().ResourceOwner),
|
|
handler.NewCol(TargetIDCol, e.Aggregate().ID),
|
|
handler.NewCol(TargetCreationDateCol, e.CreationDate()),
|
|
handler.NewCol(TargetChangeDateCol, e.CreationDate()),
|
|
handler.NewCol(TargetSequenceCol, e.Sequence()),
|
|
handler.NewCol(TargetNameCol, e.Name),
|
|
handler.NewCol(TargetEndpointCol, e.Endpoint),
|
|
handler.NewCol(TargetTargetType, e.TargetType),
|
|
handler.NewCol(TargetTimeoutCol, e.Timeout),
|
|
handler.NewCol(TargetInterruptOnErrorCol, e.InterruptOnError),
|
|
},
|
|
), nil
|
|
}
|
|
|
|
func (p *targetProjection) reduceTargetChanged(event eventstore.Event) (*handler.Statement, error) {
|
|
e, err := assertEvent[*target.ChangedEvent](event)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
values := []handler.Column{
|
|
handler.NewCol(TargetChangeDateCol, e.CreationDate()),
|
|
handler.NewCol(TargetSequenceCol, e.Sequence()),
|
|
handler.NewCol(TargetResourceOwnerCol, e.Aggregate().ResourceOwner),
|
|
}
|
|
if e.Name != nil {
|
|
values = append(values, handler.NewCol(TargetNameCol, *e.Name))
|
|
}
|
|
if e.TargetType != nil {
|
|
values = append(values, handler.NewCol(TargetTargetType, *e.TargetType))
|
|
}
|
|
if e.Endpoint != nil {
|
|
values = append(values, handler.NewCol(TargetEndpointCol, *e.Endpoint))
|
|
}
|
|
if e.Timeout != nil {
|
|
values = append(values, handler.NewCol(TargetTimeoutCol, *e.Timeout))
|
|
}
|
|
if e.InterruptOnError != nil {
|
|
values = append(values, handler.NewCol(TargetInterruptOnErrorCol, *e.InterruptOnError))
|
|
}
|
|
return handler.NewUpdateStatement(
|
|
e,
|
|
values,
|
|
[]handler.Condition{
|
|
handler.NewCond(TargetInstanceIDCol, e.Aggregate().InstanceID),
|
|
handler.NewCond(TargetIDCol, e.Aggregate().ID),
|
|
},
|
|
), nil
|
|
}
|
|
|
|
func (p *targetProjection) reduceTargetRemoved(event eventstore.Event) (*handler.Statement, error) {
|
|
e, err := assertEvent[*target.RemovedEvent](event)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return handler.NewDeleteStatement(
|
|
e,
|
|
[]handler.Condition{
|
|
handler.NewCond(TargetInstanceIDCol, e.Aggregate().InstanceID),
|
|
handler.NewCond(TargetIDCol, e.Aggregate().ID),
|
|
},
|
|
), nil
|
|
}
|