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:
Stefan Benz
2024-05-04 11:55:57 +02:00
committed by GitHub
parent 7e345444bf
commit 1c5ecba42a
67 changed files with 4397 additions and 1556 deletions

View File

@@ -8,44 +8,56 @@ import (
"regexp"
"testing"
"github.com/zitadel/zitadel/internal/database"
"github.com/zitadel/zitadel/internal/domain"
exec "github.com/zitadel/zitadel/internal/repository/execution"
"github.com/zitadel/zitadel/internal/zerrors"
)
var (
prepareExecutionsStmt = `SELECT projections.executions.id,` +
` projections.executions.change_date,` +
` projections.executions.resource_owner,` +
` projections.executions.sequence,` +
` projections.executions.targets,` +
` projections.executions.includes,` +
prepareExecutionsStmt = `SELECT projections.executions1.instance_id,` +
` projections.executions1.id,` +
` projections.executions1.change_date,` +
` projections.executions1.sequence,` +
` execution_targets.targets,` +
` COUNT(*) OVER ()` +
` FROM projections.executions`
` FROM projections.executions1` +
` JOIN (` +
`SELECT instance_id, execution_id, JSONB_AGG( JSON_OBJECT( 'position' : position, 'include' : include, 'target' : target_id ) ) as targets` +
` FROM projections.executions1_targets` +
` GROUP BY instance_id, execution_id` +
`)` +
` AS execution_targets` +
` ON execution_targets.instance_id = projections.executions1.instance_id` +
` AND execution_targets.execution_id = projections.executions1.id`
prepareExecutionsCols = []string{
"instance_id",
"id",
"change_date",
"resource_owner",
"sequence",
"targets",
"includes",
"count",
}
prepareExecutionStmt = `SELECT projections.executions.id,` +
` projections.executions.change_date,` +
` projections.executions.resource_owner,` +
` projections.executions.sequence,` +
` projections.executions.targets,` +
` projections.executions.includes` +
` FROM projections.executions`
prepareExecutionStmt = `SELECT projections.executions1.instance_id,` +
` projections.executions1.id,` +
` projections.executions1.change_date,` +
` projections.executions1.sequence,` +
` execution_targets.targets` +
` FROM projections.executions1` +
` JOIN (` +
`SELECT instance_id, execution_id, JSONB_AGG( JSON_OBJECT( 'position' : position, 'include' : include, 'target' : target_id ) ) as targets` +
` FROM projections.executions1_targets` +
` GROUP BY instance_id, execution_id` +
`)` +
` AS execution_targets` +
` ON execution_targets.instance_id = projections.executions1.instance_id` +
` AND execution_targets.execution_id = projections.executions1.id`
prepareExecutionCols = []string{
"instance_id",
"id",
"change_date",
"resource_owner",
"sequence",
"targets",
"includes",
}
)
@@ -81,12 +93,11 @@ func Test_ExecutionPrepares(t *testing.T) {
prepareExecutionsCols,
[][]driver.Value{
{
"ro",
"id",
testNow,
"ro",
uint64(20211109),
database.TextArray[string]{"target"},
database.TextArray[string]{"include"},
[]byte(`[{"position" : 1, "target" : "target"}, {"position" : 2, "include" : "include"}]`),
},
},
),
@@ -103,8 +114,10 @@ func Test_ExecutionPrepares(t *testing.T) {
ResourceOwner: "ro",
Sequence: 20211109,
},
Targets: database.TextArray[string]{"target"},
Includes: database.TextArray[string]{"include"},
Targets: []*exec.Target{
{Type: domain.ExecutionTargetTypeTarget, Target: "target"},
{Type: domain.ExecutionTargetTypeInclude, Target: "include"},
},
},
},
},
@@ -118,20 +131,18 @@ func Test_ExecutionPrepares(t *testing.T) {
prepareExecutionsCols,
[][]driver.Value{
{
"ro",
"id-1",
testNow,
"ro",
uint64(20211109),
database.TextArray[string]{"target1"},
database.TextArray[string]{"include1"},
[]byte(`[{"position" : 1, "target" : "target"}, {"position" : 2, "include" : "include"}]`),
},
{
"ro",
"id-2",
testNow,
"ro",
uint64(20211110),
database.TextArray[string]{"target2"},
database.TextArray[string]{"include2"},
[]byte(`[{"position" : 2, "target" : "target"}, {"position" : 1, "include" : "include"}]`),
},
},
),
@@ -148,8 +159,10 @@ func Test_ExecutionPrepares(t *testing.T) {
ResourceOwner: "ro",
Sequence: 20211109,
},
Targets: database.TextArray[string]{"target1"},
Includes: database.TextArray[string]{"include1"},
Targets: []*exec.Target{
{Type: domain.ExecutionTargetTypeTarget, Target: "target"},
{Type: domain.ExecutionTargetTypeInclude, Target: "include"},
},
},
{
ID: "id-2",
@@ -158,8 +171,10 @@ func Test_ExecutionPrepares(t *testing.T) {
ResourceOwner: "ro",
Sequence: 20211110,
},
Targets: database.TextArray[string]{"target2"},
Includes: database.TextArray[string]{"include2"},
Targets: []*exec.Target{
{Type: domain.ExecutionTargetTypeInclude, Target: "include"},
{Type: domain.ExecutionTargetTypeTarget, Target: "target"},
},
},
},
},
@@ -207,12 +222,11 @@ func Test_ExecutionPrepares(t *testing.T) {
regexp.QuoteMeta(prepareExecutionStmt),
prepareExecutionCols,
[]driver.Value{
"ro",
"id",
testNow,
"ro",
uint64(20211109),
database.TextArray[string]{"target"},
database.TextArray[string]{"include"},
[]byte(`[{"position" : 1, "target" : "target"}, {"position" : 2, "include" : "include"}]`),
},
),
},
@@ -223,8 +237,10 @@ func Test_ExecutionPrepares(t *testing.T) {
ResourceOwner: "ro",
Sequence: 20211109,
},
Targets: database.TextArray[string]{"target"},
Includes: database.TextArray[string]{"include"},
Targets: []*exec.Target{
{Type: domain.ExecutionTargetTypeTarget, Target: "target"},
{Type: domain.ExecutionTargetTypeInclude, Target: "include"},
},
},
},
{