mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-16 18:55:11 +00:00
feat: projections auto create their tables (#3324)
* begin init checks for projections * first projection checks * debug notification providers with query fixes * more projections and first index * more projections * more projections * finish projections * fix tests (remove db name) * create tables in setup * fix logging / error handling * add tenant to views * rename tenant to instance_id * add instance_id to all projections * add instance_id to all queries * correct instance_id on projections * add instance_id to failed_events * use separate context for instance * implement features projection * implement features projection * remove unique constraint from setup when migration failed * add error to failed setup event * add instance_id to primary keys * fix IAM projection * remove old migrations folder * fix keysFromYAML test
This commit is contained in:
@@ -8,6 +8,8 @@ import (
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/query/projection"
|
||||
@@ -33,6 +35,10 @@ var (
|
||||
name: projection.ActionResourceOwnerCol,
|
||||
table: actionTable,
|
||||
}
|
||||
ActionColumnInstanceID = Column{
|
||||
name: projection.ActionInstanceIDCol,
|
||||
table: actionTable,
|
||||
}
|
||||
ActionColumnSequence = Column{
|
||||
name: projection.ActionSequenceCol,
|
||||
table: actionTable,
|
||||
@@ -93,7 +99,11 @@ func (q *ActionSearchQueries) toQuery(query sq.SelectBuilder) sq.SelectBuilder {
|
||||
|
||||
func (q *Queries) SearchActions(ctx context.Context, queries *ActionSearchQueries) (actions *Actions, err error) {
|
||||
query, scan := prepareActionsQuery()
|
||||
stmt, args, err := queries.toQuery(query).ToSql()
|
||||
stmt, args, err := queries.toQuery(query).
|
||||
Where(sq.Eq{
|
||||
ActionColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInvalidArgument(err, "QUERY-SDgwg", "Errors.Query.InvalidRequest")
|
||||
}
|
||||
@@ -116,6 +126,7 @@ func (q *Queries) GetActionByID(ctx context.Context, id string, orgID string) (*
|
||||
sq.Eq{
|
||||
ActionColumnID.identifier(): id,
|
||||
ActionColumnResourceOwner.identifier(): orgID,
|
||||
ActionColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "QUERY-Dgff3", "Errors.Query.SQLStatement")
|
||||
|
||||
@@ -8,6 +8,8 @@ import (
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
"github.com/lib/pq"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/query/projection"
|
||||
@@ -21,6 +23,14 @@ var (
|
||||
name: projection.FlowTypeCol,
|
||||
table: flowsTriggersTable,
|
||||
}
|
||||
FlowsTriggersColumnChangeDate = Column{
|
||||
name: projection.FlowChangeDateCol,
|
||||
table: flowsTriggersTable,
|
||||
}
|
||||
FlowsTriggersColumnSequence = Column{
|
||||
name: projection.FlowSequenceCol,
|
||||
table: flowsTriggersTable,
|
||||
}
|
||||
FlowsTriggersColumnTriggerType = Column{
|
||||
name: projection.FlowTriggerTypeCol,
|
||||
table: flowsTriggersTable,
|
||||
@@ -29,6 +39,10 @@ var (
|
||||
name: projection.FlowResourceOwnerCol,
|
||||
table: flowsTriggersTable,
|
||||
}
|
||||
FlowsTriggersColumnInstanceID = Column{
|
||||
name: projection.FlowInstanceIDCol,
|
||||
table: flowsTriggersTable,
|
||||
}
|
||||
FlowsTriggersColumnTriggerSequence = Column{
|
||||
name: projection.FlowActionTriggerSequenceCol,
|
||||
table: flowsTriggersTable,
|
||||
@@ -40,10 +54,9 @@ var (
|
||||
)
|
||||
|
||||
type Flow struct {
|
||||
CreationDate time.Time //TODO: add in projection
|
||||
ChangeDate time.Time //TODO: add in projection
|
||||
ResourceOwner string //TODO: add in projection
|
||||
Sequence uint64 //TODO: add in projection
|
||||
ChangeDate time.Time
|
||||
ResourceOwner string
|
||||
Sequence uint64
|
||||
Type domain.FlowType
|
||||
|
||||
TriggerActions map[domain.TriggerType][]*Action
|
||||
@@ -55,6 +68,7 @@ func (q *Queries) GetFlow(ctx context.Context, flowType domain.FlowType, orgID s
|
||||
sq.Eq{
|
||||
FlowsTriggersColumnFlowType.identifier(): flowType,
|
||||
FlowsTriggersColumnResourceOwner.identifier(): orgID,
|
||||
FlowsTriggersColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInvalidArgument(err, "QUERY-HBRh3", "Errors.Query.InvalidRequest")
|
||||
@@ -74,6 +88,7 @@ func (q *Queries) GetActiveActionsByFlowAndTriggerType(ctx context.Context, flow
|
||||
FlowsTriggersColumnFlowType.identifier(): flowType,
|
||||
FlowsTriggersColumnTriggerType.identifier(): triggerType,
|
||||
FlowsTriggersColumnResourceOwner.identifier(): orgID,
|
||||
FlowsTriggersColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
ActionColumnState.identifier(): domain.ActionStateActive,
|
||||
},
|
||||
).ToSql()
|
||||
@@ -92,7 +107,8 @@ func (q *Queries) GetFlowTypesOfActionID(ctx context.Context, actionID string) (
|
||||
stmt, scan := prepareFlowTypesQuery()
|
||||
query, args, err := stmt.Where(
|
||||
sq.Eq{
|
||||
FlowsTriggersColumnActionID.identifier(): actionID,
|
||||
FlowsTriggersColumnActionID.identifier(): actionID,
|
||||
FlowsTriggersColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
},
|
||||
).ToSql()
|
||||
if err != nil {
|
||||
@@ -185,6 +201,9 @@ func prepareFlowQuery() (sq.SelectBuilder, func(*sql.Rows) (*Flow, error)) {
|
||||
FlowsTriggersColumnTriggerType.identifier(),
|
||||
FlowsTriggersColumnTriggerSequence.identifier(),
|
||||
FlowsTriggersColumnFlowType.identifier(),
|
||||
FlowsTriggersColumnChangeDate.identifier(),
|
||||
FlowsTriggersColumnSequence.identifier(),
|
||||
FlowsTriggersColumnResourceOwner.identifier(),
|
||||
).
|
||||
From(flowsTriggersTable.name).
|
||||
LeftJoin(join(ActionColumnID, FlowsTriggersColumnActionID)).
|
||||
@@ -194,7 +213,6 @@ func prepareFlowQuery() (sq.SelectBuilder, func(*sql.Rows) (*Flow, error)) {
|
||||
TriggerActions: make(map[domain.TriggerType][]*Action),
|
||||
}
|
||||
for rows.Next() {
|
||||
// action := new(Action)
|
||||
var (
|
||||
actionID sql.NullString
|
||||
actionCreationDate pq.NullTime
|
||||
@@ -207,7 +225,6 @@ func prepareFlowQuery() (sq.SelectBuilder, func(*sql.Rows) (*Flow, error)) {
|
||||
|
||||
triggerType domain.TriggerType
|
||||
triggerSequence int
|
||||
flowType domain.FlowType
|
||||
)
|
||||
err := rows.Scan(
|
||||
&actionID,
|
||||
@@ -220,12 +237,14 @@ func prepareFlowQuery() (sq.SelectBuilder, func(*sql.Rows) (*Flow, error)) {
|
||||
&actionScript,
|
||||
&triggerType,
|
||||
&triggerSequence,
|
||||
&flowType,
|
||||
&flow.Type,
|
||||
&flow.ChangeDate,
|
||||
&flow.Sequence,
|
||||
&flow.ResourceOwner,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
flow.Type = flowType
|
||||
if !actionID.Valid {
|
||||
continue
|
||||
}
|
||||
|
||||
+163
-115
@@ -27,19 +27,22 @@ func Test_FlowPrepares(t *testing.T) {
|
||||
prepare: prepareFlowQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.actions.id,`+
|
||||
` zitadel.projections.actions.creation_date,`+
|
||||
` zitadel.projections.actions.change_date,`+
|
||||
` zitadel.projections.actions.resource_owner,`+
|
||||
` zitadel.projections.actions.action_state,`+
|
||||
` zitadel.projections.actions.sequence,`+
|
||||
` zitadel.projections.actions.name,`+
|
||||
` zitadel.projections.actions.script,`+
|
||||
` zitadel.projections.flows_triggers.trigger_type,`+
|
||||
` zitadel.projections.flows_triggers.trigger_sequence,`+
|
||||
` zitadel.projections.flows_triggers.flow_type`+
|
||||
` FROM zitadel.projections.flows_triggers`+
|
||||
` LEFT JOIN zitadel.projections.actions ON zitadel.projections.flows_triggers.action_id = zitadel.projections.actions.id`),
|
||||
regexp.QuoteMeta(`SELECT projections.actions.id,`+
|
||||
` projections.actions.creation_date,`+
|
||||
` projections.actions.change_date,`+
|
||||
` projections.actions.resource_owner,`+
|
||||
` projections.actions.action_state,`+
|
||||
` projections.actions.sequence,`+
|
||||
` projections.actions.name,`+
|
||||
` projections.actions.script,`+
|
||||
` projections.flows_triggers.trigger_type,`+
|
||||
` projections.flows_triggers.trigger_sequence,`+
|
||||
` projections.flows_triggers.flow_type,`+
|
||||
` projections.flows_triggers.change_date,`+
|
||||
` projections.flows_triggers.sequence,`+
|
||||
` projections.flows_triggers.resource_owner`+
|
||||
` FROM projections.flows_triggers`+
|
||||
` LEFT JOIN projections.actions ON projections.flows_triggers.action_id = projections.actions.id`),
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -51,19 +54,22 @@ func Test_FlowPrepares(t *testing.T) {
|
||||
prepare: prepareFlowQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.actions.id,`+
|
||||
` zitadel.projections.actions.creation_date,`+
|
||||
` zitadel.projections.actions.change_date,`+
|
||||
` zitadel.projections.actions.resource_owner,`+
|
||||
` zitadel.projections.actions.action_state,`+
|
||||
` zitadel.projections.actions.sequence,`+
|
||||
` zitadel.projections.actions.name,`+
|
||||
` zitadel.projections.actions.script,`+
|
||||
` zitadel.projections.flows_triggers.trigger_type,`+
|
||||
` zitadel.projections.flows_triggers.trigger_sequence,`+
|
||||
` zitadel.projections.flows_triggers.flow_type`+
|
||||
` FROM zitadel.projections.flows_triggers`+
|
||||
` LEFT JOIN zitadel.projections.actions ON zitadel.projections.flows_triggers.action_id = zitadel.projections.actions.id`),
|
||||
regexp.QuoteMeta(`SELECT projections.actions.id,`+
|
||||
` projections.actions.creation_date,`+
|
||||
` projections.actions.change_date,`+
|
||||
` projections.actions.resource_owner,`+
|
||||
` projections.actions.action_state,`+
|
||||
` projections.actions.sequence,`+
|
||||
` projections.actions.name,`+
|
||||
` projections.actions.script,`+
|
||||
` projections.flows_triggers.trigger_type,`+
|
||||
` projections.flows_triggers.trigger_sequence,`+
|
||||
` projections.flows_triggers.flow_type,`+
|
||||
` projections.flows_triggers.change_date,`+
|
||||
` projections.flows_triggers.sequence,`+
|
||||
` projections.flows_triggers.resource_owner`+
|
||||
` FROM projections.flows_triggers`+
|
||||
` LEFT JOIN projections.actions ON projections.flows_triggers.action_id = projections.actions.id`),
|
||||
[]string{
|
||||
"id",
|
||||
"creation_date",
|
||||
@@ -73,9 +79,13 @@ func Test_FlowPrepares(t *testing.T) {
|
||||
"sequence",
|
||||
"name",
|
||||
"script",
|
||||
//flow
|
||||
"trigger_type",
|
||||
"trigger_sequence",
|
||||
"flow_type",
|
||||
"change_date",
|
||||
"sequence",
|
||||
"resource_owner",
|
||||
},
|
||||
[][]driver.Value{
|
||||
{
|
||||
@@ -90,12 +100,18 @@ func Test_FlowPrepares(t *testing.T) {
|
||||
domain.TriggerTypePreCreation,
|
||||
uint64(20211109),
|
||||
domain.FlowTypeExternalAuthentication,
|
||||
testNow,
|
||||
uint64(20211115),
|
||||
"owner",
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
object: &Flow{
|
||||
Type: domain.FlowTypeExternalAuthentication,
|
||||
ChangeDate: testNow,
|
||||
ResourceOwner: "owner",
|
||||
Sequence: 20211115,
|
||||
Type: domain.FlowTypeExternalAuthentication,
|
||||
TriggerActions: map[domain.TriggerType][]*Action{
|
||||
domain.TriggerTypePreCreation: {
|
||||
{
|
||||
@@ -117,19 +133,22 @@ func Test_FlowPrepares(t *testing.T) {
|
||||
prepare: prepareFlowQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.actions.id,`+
|
||||
` zitadel.projections.actions.creation_date,`+
|
||||
` zitadel.projections.actions.change_date,`+
|
||||
` zitadel.projections.actions.resource_owner,`+
|
||||
` zitadel.projections.actions.action_state,`+
|
||||
` zitadel.projections.actions.sequence,`+
|
||||
` zitadel.projections.actions.name,`+
|
||||
` zitadel.projections.actions.script,`+
|
||||
` zitadel.projections.flows_triggers.trigger_type,`+
|
||||
` zitadel.projections.flows_triggers.trigger_sequence,`+
|
||||
` zitadel.projections.flows_triggers.flow_type`+
|
||||
` FROM zitadel.projections.flows_triggers`+
|
||||
` LEFT JOIN zitadel.projections.actions ON zitadel.projections.flows_triggers.action_id = zitadel.projections.actions.id`),
|
||||
regexp.QuoteMeta(`SELECT projections.actions.id,`+
|
||||
` projections.actions.creation_date,`+
|
||||
` projections.actions.change_date,`+
|
||||
` projections.actions.resource_owner,`+
|
||||
` projections.actions.action_state,`+
|
||||
` projections.actions.sequence,`+
|
||||
` projections.actions.name,`+
|
||||
` projections.actions.script,`+
|
||||
` projections.flows_triggers.trigger_type,`+
|
||||
` projections.flows_triggers.trigger_sequence,`+
|
||||
` projections.flows_triggers.flow_type,`+
|
||||
` projections.flows_triggers.change_date,`+
|
||||
` projections.flows_triggers.sequence,`+
|
||||
` projections.flows_triggers.resource_owner`+
|
||||
` FROM projections.flows_triggers`+
|
||||
` LEFT JOIN projections.actions ON projections.flows_triggers.action_id = projections.actions.id`),
|
||||
[]string{
|
||||
"id",
|
||||
"creation_date",
|
||||
@@ -139,9 +158,13 @@ func Test_FlowPrepares(t *testing.T) {
|
||||
"sequence",
|
||||
"name",
|
||||
"script",
|
||||
//flow
|
||||
"trigger_type",
|
||||
"trigger_sequence",
|
||||
"flow_type",
|
||||
"change_date",
|
||||
"sequence",
|
||||
"resource_owner",
|
||||
},
|
||||
[][]driver.Value{
|
||||
{
|
||||
@@ -156,6 +179,9 @@ func Test_FlowPrepares(t *testing.T) {
|
||||
domain.TriggerTypePreCreation,
|
||||
uint64(20211109),
|
||||
domain.FlowTypeExternalAuthentication,
|
||||
testNow,
|
||||
uint64(20211115),
|
||||
"owner",
|
||||
},
|
||||
{
|
||||
"action-id-post",
|
||||
@@ -169,12 +195,18 @@ func Test_FlowPrepares(t *testing.T) {
|
||||
domain.TriggerTypePostCreation,
|
||||
uint64(20211109),
|
||||
domain.FlowTypeExternalAuthentication,
|
||||
testNow,
|
||||
uint64(20211115),
|
||||
"owner",
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
object: &Flow{
|
||||
Type: domain.FlowTypeExternalAuthentication,
|
||||
ChangeDate: testNow,
|
||||
ResourceOwner: "owner",
|
||||
Sequence: 20211115,
|
||||
Type: domain.FlowTypeExternalAuthentication,
|
||||
TriggerActions: map[domain.TriggerType][]*Action{
|
||||
domain.TriggerTypePreCreation: {
|
||||
{
|
||||
@@ -208,19 +240,22 @@ func Test_FlowPrepares(t *testing.T) {
|
||||
prepare: prepareFlowQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.actions.id,`+
|
||||
` zitadel.projections.actions.creation_date,`+
|
||||
` zitadel.projections.actions.change_date,`+
|
||||
` zitadel.projections.actions.resource_owner,`+
|
||||
` zitadel.projections.actions.action_state,`+
|
||||
` zitadel.projections.actions.sequence,`+
|
||||
` zitadel.projections.actions.name,`+
|
||||
` zitadel.projections.actions.script,`+
|
||||
` zitadel.projections.flows_triggers.trigger_type,`+
|
||||
` zitadel.projections.flows_triggers.trigger_sequence,`+
|
||||
` zitadel.projections.flows_triggers.flow_type`+
|
||||
` FROM zitadel.projections.flows_triggers`+
|
||||
` LEFT JOIN zitadel.projections.actions ON zitadel.projections.flows_triggers.action_id = zitadel.projections.actions.id`),
|
||||
regexp.QuoteMeta(`SELECT projections.actions.id,`+
|
||||
` projections.actions.creation_date,`+
|
||||
` projections.actions.change_date,`+
|
||||
` projections.actions.resource_owner,`+
|
||||
` projections.actions.action_state,`+
|
||||
` projections.actions.sequence,`+
|
||||
` projections.actions.name,`+
|
||||
` projections.actions.script,`+
|
||||
` projections.flows_triggers.trigger_type,`+
|
||||
` projections.flows_triggers.trigger_sequence,`+
|
||||
` projections.flows_triggers.flow_type,`+
|
||||
` projections.flows_triggers.change_date,`+
|
||||
` projections.flows_triggers.sequence,`+
|
||||
` projections.flows_triggers.resource_owner`+
|
||||
` FROM projections.flows_triggers`+
|
||||
` LEFT JOIN projections.actions ON projections.flows_triggers.action_id = projections.actions.id`),
|
||||
[]string{
|
||||
"id",
|
||||
"creation_date",
|
||||
@@ -230,9 +265,13 @@ func Test_FlowPrepares(t *testing.T) {
|
||||
"sequence",
|
||||
"name",
|
||||
"script",
|
||||
//flow
|
||||
"trigger_type",
|
||||
"trigger_sequence",
|
||||
"flow_type",
|
||||
"change_date",
|
||||
"sequence",
|
||||
"resource_owner",
|
||||
},
|
||||
[][]driver.Value{
|
||||
{
|
||||
@@ -247,11 +286,17 @@ func Test_FlowPrepares(t *testing.T) {
|
||||
domain.TriggerTypePostCreation,
|
||||
uint64(20211109),
|
||||
domain.FlowTypeExternalAuthentication,
|
||||
testNow,
|
||||
uint64(20211115),
|
||||
"owner",
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
object: &Flow{
|
||||
ChangeDate: testNow,
|
||||
ResourceOwner: "owner",
|
||||
Sequence: 20211115,
|
||||
Type: domain.FlowTypeExternalAuthentication,
|
||||
TriggerActions: map[domain.TriggerType][]*Action{},
|
||||
},
|
||||
@@ -261,19 +306,22 @@ func Test_FlowPrepares(t *testing.T) {
|
||||
prepare: prepareFlowQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.actions.id,`+
|
||||
` zitadel.projections.actions.creation_date,`+
|
||||
` zitadel.projections.actions.change_date,`+
|
||||
` zitadel.projections.actions.resource_owner,`+
|
||||
` zitadel.projections.actions.action_state,`+
|
||||
` zitadel.projections.actions.sequence,`+
|
||||
` zitadel.projections.actions.name,`+
|
||||
` zitadel.projections.actions.script,`+
|
||||
` zitadel.projections.flows_triggers.trigger_type,`+
|
||||
` zitadel.projections.flows_triggers.trigger_sequence,`+
|
||||
` zitadel.projections.flows_triggers.flow_type`+
|
||||
` FROM zitadel.projections.flows_triggers`+
|
||||
` LEFT JOIN zitadel.projections.actions ON zitadel.projections.flows_triggers.action_id = zitadel.projections.actions.id`),
|
||||
regexp.QuoteMeta(`SELECT projections.actions.id,`+
|
||||
` projections.actions.creation_date,`+
|
||||
` projections.actions.change_date,`+
|
||||
` projections.actions.resource_owner,`+
|
||||
` projections.actions.action_state,`+
|
||||
` projections.actions.sequence,`+
|
||||
` projections.actions.name,`+
|
||||
` projections.actions.script,`+
|
||||
` projections.flows_triggers.trigger_type,`+
|
||||
` projections.flows_triggers.trigger_sequence,`+
|
||||
` projections.flows_triggers.flow_type,`+
|
||||
` projections.flows_triggers.change_date,`+
|
||||
` projections.flows_triggers.sequence,`+
|
||||
` projections.flows_triggers.resource_owner`+
|
||||
` FROM projections.flows_triggers`+
|
||||
` LEFT JOIN projections.actions ON projections.flows_triggers.action_id = projections.actions.id`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
@@ -290,16 +338,16 @@ func Test_FlowPrepares(t *testing.T) {
|
||||
prepare: prepareTriggerActionsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.actions.id,`+
|
||||
` zitadel.projections.actions.creation_date,`+
|
||||
` zitadel.projections.actions.change_date,`+
|
||||
` zitadel.projections.actions.resource_owner,`+
|
||||
` zitadel.projections.actions.action_state,`+
|
||||
` zitadel.projections.actions.sequence,`+
|
||||
` zitadel.projections.actions.name,`+
|
||||
` zitadel.projections.actions.script`+
|
||||
` FROM zitadel.projections.flows_triggers`+
|
||||
` LEFT JOIN zitadel.projections.actions ON zitadel.projections.flows_triggers.action_id = zitadel.projections.actions.id`),
|
||||
regexp.QuoteMeta(`SELECT projections.actions.id,`+
|
||||
` projections.actions.creation_date,`+
|
||||
` projections.actions.change_date,`+
|
||||
` projections.actions.resource_owner,`+
|
||||
` projections.actions.action_state,`+
|
||||
` projections.actions.sequence,`+
|
||||
` projections.actions.name,`+
|
||||
` projections.actions.script`+
|
||||
` FROM projections.flows_triggers`+
|
||||
` LEFT JOIN projections.actions ON projections.flows_triggers.action_id = projections.actions.id`),
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -311,16 +359,16 @@ func Test_FlowPrepares(t *testing.T) {
|
||||
prepare: prepareTriggerActionsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.actions.id,`+
|
||||
` zitadel.projections.actions.creation_date,`+
|
||||
` zitadel.projections.actions.change_date,`+
|
||||
` zitadel.projections.actions.resource_owner,`+
|
||||
` zitadel.projections.actions.action_state,`+
|
||||
` zitadel.projections.actions.sequence,`+
|
||||
` zitadel.projections.actions.name,`+
|
||||
` zitadel.projections.actions.script`+
|
||||
` FROM zitadel.projections.flows_triggers`+
|
||||
` LEFT JOIN zitadel.projections.actions ON zitadel.projections.flows_triggers.action_id = zitadel.projections.actions.id`),
|
||||
regexp.QuoteMeta(`SELECT projections.actions.id,`+
|
||||
` projections.actions.creation_date,`+
|
||||
` projections.actions.change_date,`+
|
||||
` projections.actions.resource_owner,`+
|
||||
` projections.actions.action_state,`+
|
||||
` projections.actions.sequence,`+
|
||||
` projections.actions.name,`+
|
||||
` projections.actions.script`+
|
||||
` FROM projections.flows_triggers`+
|
||||
` LEFT JOIN projections.actions ON projections.flows_triggers.action_id = projections.actions.id`),
|
||||
[]string{
|
||||
"id",
|
||||
"creation_date",
|
||||
@@ -363,16 +411,16 @@ func Test_FlowPrepares(t *testing.T) {
|
||||
prepare: prepareTriggerActionsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.actions.id,`+
|
||||
` zitadel.projections.actions.creation_date,`+
|
||||
` zitadel.projections.actions.change_date,`+
|
||||
` zitadel.projections.actions.resource_owner,`+
|
||||
` zitadel.projections.actions.action_state,`+
|
||||
` zitadel.projections.actions.sequence,`+
|
||||
` zitadel.projections.actions.name,`+
|
||||
` zitadel.projections.actions.script`+
|
||||
` FROM zitadel.projections.flows_triggers`+
|
||||
` LEFT JOIN zitadel.projections.actions ON zitadel.projections.flows_triggers.action_id = zitadel.projections.actions.id`),
|
||||
regexp.QuoteMeta(`SELECT projections.actions.id,`+
|
||||
` projections.actions.creation_date,`+
|
||||
` projections.actions.change_date,`+
|
||||
` projections.actions.resource_owner,`+
|
||||
` projections.actions.action_state,`+
|
||||
` projections.actions.sequence,`+
|
||||
` projections.actions.name,`+
|
||||
` projections.actions.script`+
|
||||
` FROM projections.flows_triggers`+
|
||||
` LEFT JOIN projections.actions ON projections.flows_triggers.action_id = projections.actions.id`),
|
||||
[]string{
|
||||
"id",
|
||||
"creation_date",
|
||||
@@ -435,16 +483,16 @@ func Test_FlowPrepares(t *testing.T) {
|
||||
prepare: prepareTriggerActionsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.actions.id,`+
|
||||
` zitadel.projections.actions.creation_date,`+
|
||||
` zitadel.projections.actions.change_date,`+
|
||||
` zitadel.projections.actions.resource_owner,`+
|
||||
` zitadel.projections.actions.action_state,`+
|
||||
` zitadel.projections.actions.sequence,`+
|
||||
` zitadel.projections.actions.name,`+
|
||||
` zitadel.projections.actions.script`+
|
||||
` FROM zitadel.projections.flows_triggers`+
|
||||
` LEFT JOIN zitadel.projections.actions ON zitadel.projections.flows_triggers.action_id = zitadel.projections.actions.id`),
|
||||
regexp.QuoteMeta(`SELECT projections.actions.id,`+
|
||||
` projections.actions.creation_date,`+
|
||||
` projections.actions.change_date,`+
|
||||
` projections.actions.resource_owner,`+
|
||||
` projections.actions.action_state,`+
|
||||
` projections.actions.sequence,`+
|
||||
` projections.actions.name,`+
|
||||
` projections.actions.script`+
|
||||
` FROM projections.flows_triggers`+
|
||||
` LEFT JOIN projections.actions ON projections.flows_triggers.action_id = projections.actions.id`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
@@ -461,8 +509,8 @@ func Test_FlowPrepares(t *testing.T) {
|
||||
prepare: prepareFlowTypesQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.flows_triggers.flow_type`+
|
||||
` FROM zitadel.projections.flows_triggers`),
|
||||
regexp.QuoteMeta(`SELECT projections.flows_triggers.flow_type`+
|
||||
` FROM projections.flows_triggers`),
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -474,8 +522,8 @@ func Test_FlowPrepares(t *testing.T) {
|
||||
prepare: prepareFlowTypesQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.flows_triggers.flow_type`+
|
||||
` FROM zitadel.projections.flows_triggers`),
|
||||
regexp.QuoteMeta(`SELECT projections.flows_triggers.flow_type`+
|
||||
` FROM projections.flows_triggers`),
|
||||
[]string{
|
||||
"flow_type",
|
||||
},
|
||||
@@ -495,8 +543,8 @@ func Test_FlowPrepares(t *testing.T) {
|
||||
prepare: prepareFlowTypesQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.flows_triggers.flow_type`+
|
||||
` FROM zitadel.projections.flows_triggers`),
|
||||
regexp.QuoteMeta(`SELECT projections.flows_triggers.flow_type`+
|
||||
` FROM projections.flows_triggers`),
|
||||
[]string{
|
||||
"flow_type",
|
||||
},
|
||||
@@ -520,8 +568,8 @@ func Test_FlowPrepares(t *testing.T) {
|
||||
prepare: prepareFlowTypesQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.flows_triggers.flow_type`+
|
||||
` FROM zitadel.projections.flows_triggers`),
|
||||
regexp.QuoteMeta(`SELECT projections.flows_triggers.flow_type`+
|
||||
` FROM projections.flows_triggers`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
|
||||
@@ -29,18 +29,18 @@ func Test_ActionPrepares(t *testing.T) {
|
||||
prepare: prepareActionsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.actions.id,`+
|
||||
` zitadel.projections.actions.creation_date,`+
|
||||
` zitadel.projections.actions.change_date,`+
|
||||
` zitadel.projections.actions.resource_owner,`+
|
||||
` zitadel.projections.actions.sequence,`+
|
||||
` zitadel.projections.actions.action_state,`+
|
||||
` zitadel.projections.actions.name,`+
|
||||
` zitadel.projections.actions.script,`+
|
||||
` zitadel.projections.actions.timeout,`+
|
||||
` zitadel.projections.actions.allowed_to_fail,`+
|
||||
regexp.QuoteMeta(`SELECT projections.actions.id,`+
|
||||
` projections.actions.creation_date,`+
|
||||
` projections.actions.change_date,`+
|
||||
` projections.actions.resource_owner,`+
|
||||
` projections.actions.sequence,`+
|
||||
` projections.actions.action_state,`+
|
||||
` projections.actions.name,`+
|
||||
` projections.actions.script,`+
|
||||
` projections.actions.timeout,`+
|
||||
` projections.actions.allowed_to_fail,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.actions`),
|
||||
` FROM projections.actions`),
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -52,18 +52,18 @@ func Test_ActionPrepares(t *testing.T) {
|
||||
prepare: prepareActionsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.actions.id,`+
|
||||
` zitadel.projections.actions.creation_date,`+
|
||||
` zitadel.projections.actions.change_date,`+
|
||||
` zitadel.projections.actions.resource_owner,`+
|
||||
` zitadel.projections.actions.sequence,`+
|
||||
` zitadel.projections.actions.action_state,`+
|
||||
` zitadel.projections.actions.name,`+
|
||||
` zitadel.projections.actions.script,`+
|
||||
` zitadel.projections.actions.timeout,`+
|
||||
` zitadel.projections.actions.allowed_to_fail,`+
|
||||
regexp.QuoteMeta(`SELECT projections.actions.id,`+
|
||||
` projections.actions.creation_date,`+
|
||||
` projections.actions.change_date,`+
|
||||
` projections.actions.resource_owner,`+
|
||||
` projections.actions.sequence,`+
|
||||
` projections.actions.action_state,`+
|
||||
` projections.actions.name,`+
|
||||
` projections.actions.script,`+
|
||||
` projections.actions.timeout,`+
|
||||
` projections.actions.allowed_to_fail,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.actions`),
|
||||
` FROM projections.actions`),
|
||||
[]string{
|
||||
"id",
|
||||
"creation_date",
|
||||
@@ -118,18 +118,18 @@ func Test_ActionPrepares(t *testing.T) {
|
||||
prepare: prepareActionsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.actions.id,`+
|
||||
` zitadel.projections.actions.creation_date,`+
|
||||
` zitadel.projections.actions.change_date,`+
|
||||
` zitadel.projections.actions.resource_owner,`+
|
||||
` zitadel.projections.actions.sequence,`+
|
||||
` zitadel.projections.actions.action_state,`+
|
||||
` zitadel.projections.actions.name,`+
|
||||
` zitadel.projections.actions.script,`+
|
||||
` zitadel.projections.actions.timeout,`+
|
||||
` zitadel.projections.actions.allowed_to_fail,`+
|
||||
regexp.QuoteMeta(`SELECT projections.actions.id,`+
|
||||
` projections.actions.creation_date,`+
|
||||
` projections.actions.change_date,`+
|
||||
` projections.actions.resource_owner,`+
|
||||
` projections.actions.sequence,`+
|
||||
` projections.actions.action_state,`+
|
||||
` projections.actions.name,`+
|
||||
` projections.actions.script,`+
|
||||
` projections.actions.timeout,`+
|
||||
` projections.actions.allowed_to_fail,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.actions`),
|
||||
` FROM projections.actions`),
|
||||
[]string{
|
||||
"id",
|
||||
"creation_date",
|
||||
@@ -208,18 +208,18 @@ func Test_ActionPrepares(t *testing.T) {
|
||||
prepare: prepareActionsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.actions.id,`+
|
||||
` zitadel.projections.actions.creation_date,`+
|
||||
` zitadel.projections.actions.change_date,`+
|
||||
` zitadel.projections.actions.resource_owner,`+
|
||||
` zitadel.projections.actions.sequence,`+
|
||||
` zitadel.projections.actions.action_state,`+
|
||||
` zitadel.projections.actions.name,`+
|
||||
` zitadel.projections.actions.script,`+
|
||||
` zitadel.projections.actions.timeout,`+
|
||||
` zitadel.projections.actions.allowed_to_fail,`+
|
||||
regexp.QuoteMeta(`SELECT projections.actions.id,`+
|
||||
` projections.actions.creation_date,`+
|
||||
` projections.actions.change_date,`+
|
||||
` projections.actions.resource_owner,`+
|
||||
` projections.actions.sequence,`+
|
||||
` projections.actions.action_state,`+
|
||||
` projections.actions.name,`+
|
||||
` projections.actions.script,`+
|
||||
` projections.actions.timeout,`+
|
||||
` projections.actions.allowed_to_fail,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.actions`),
|
||||
` FROM projections.actions`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
@@ -236,17 +236,17 @@ func Test_ActionPrepares(t *testing.T) {
|
||||
prepare: prepareActionQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.actions.id,`+
|
||||
` zitadel.projections.actions.creation_date,`+
|
||||
` zitadel.projections.actions.change_date,`+
|
||||
` zitadel.projections.actions.resource_owner,`+
|
||||
` zitadel.projections.actions.sequence,`+
|
||||
` zitadel.projections.actions.action_state,`+
|
||||
` zitadel.projections.actions.name,`+
|
||||
` zitadel.projections.actions.script,`+
|
||||
` zitadel.projections.actions.timeout,`+
|
||||
` zitadel.projections.actions.allowed_to_fail`+
|
||||
` FROM zitadel.projections.actions`),
|
||||
regexp.QuoteMeta(`SELECT projections.actions.id,`+
|
||||
` projections.actions.creation_date,`+
|
||||
` projections.actions.change_date,`+
|
||||
` projections.actions.resource_owner,`+
|
||||
` projections.actions.sequence,`+
|
||||
` projections.actions.action_state,`+
|
||||
` projections.actions.name,`+
|
||||
` projections.actions.script,`+
|
||||
` projections.actions.timeout,`+
|
||||
` projections.actions.allowed_to_fail`+
|
||||
` FROM projections.actions`),
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -264,17 +264,17 @@ func Test_ActionPrepares(t *testing.T) {
|
||||
prepare: prepareActionQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.actions.id,`+
|
||||
` zitadel.projections.actions.creation_date,`+
|
||||
` zitadel.projections.actions.change_date,`+
|
||||
` zitadel.projections.actions.resource_owner,`+
|
||||
` zitadel.projections.actions.sequence,`+
|
||||
` zitadel.projections.actions.action_state,`+
|
||||
` zitadel.projections.actions.name,`+
|
||||
` zitadel.projections.actions.script,`+
|
||||
` zitadel.projections.actions.timeout,`+
|
||||
` zitadel.projections.actions.allowed_to_fail`+
|
||||
` FROM zitadel.projections.actions`),
|
||||
regexp.QuoteMeta(`SELECT projections.actions.id,`+
|
||||
` projections.actions.creation_date,`+
|
||||
` projections.actions.change_date,`+
|
||||
` projections.actions.resource_owner,`+
|
||||
` projections.actions.sequence,`+
|
||||
` projections.actions.action_state,`+
|
||||
` projections.actions.name,`+
|
||||
` projections.actions.script,`+
|
||||
` projections.actions.timeout,`+
|
||||
` projections.actions.allowed_to_fail`+
|
||||
` FROM projections.actions`),
|
||||
[]string{
|
||||
"id",
|
||||
"creation_date",
|
||||
@@ -319,17 +319,17 @@ func Test_ActionPrepares(t *testing.T) {
|
||||
prepare: prepareActionQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.actions.id,`+
|
||||
` zitadel.projections.actions.creation_date,`+
|
||||
` zitadel.projections.actions.change_date,`+
|
||||
` zitadel.projections.actions.resource_owner,`+
|
||||
` zitadel.projections.actions.sequence,`+
|
||||
` zitadel.projections.actions.action_state,`+
|
||||
` zitadel.projections.actions.name,`+
|
||||
` zitadel.projections.actions.script,`+
|
||||
` zitadel.projections.actions.timeout,`+
|
||||
` zitadel.projections.actions.allowed_to_fail`+
|
||||
` FROM zitadel.projections.actions`),
|
||||
regexp.QuoteMeta(`SELECT projections.actions.id,`+
|
||||
` projections.actions.creation_date,`+
|
||||
` projections.actions.change_date,`+
|
||||
` projections.actions.resource_owner,`+
|
||||
` projections.actions.sequence,`+
|
||||
` projections.actions.action_state,`+
|
||||
` projections.actions.name,`+
|
||||
` projections.actions.script,`+
|
||||
` projections.actions.timeout,`+
|
||||
` projections.actions.allowed_to_fail`+
|
||||
` FROM projections.actions`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
|
||||
+42
-13
@@ -9,6 +9,8 @@ import (
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
"github.com/lib/pq"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
|
||||
"github.com/caos/logging"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
@@ -102,6 +104,10 @@ var (
|
||||
name: projection.AppColumnResourceOwner,
|
||||
table: appsTable,
|
||||
}
|
||||
AppColumnInstanceID = Column{
|
||||
name: projection.AppColumnInstanceID,
|
||||
table: appsTable,
|
||||
}
|
||||
AppColumnState = Column{
|
||||
name: projection.AppColumnState,
|
||||
table: appsTable,
|
||||
@@ -204,8 +210,9 @@ func (q *Queries) AppByProjectAndAppID(ctx context.Context, projectID, appID str
|
||||
stmt, scan := prepareAppQuery()
|
||||
query, args, err := stmt.Where(
|
||||
sq.Eq{
|
||||
AppColumnID.identifier(): appID,
|
||||
AppColumnProjectID.identifier(): projectID,
|
||||
AppColumnID.identifier(): appID,
|
||||
AppColumnProjectID.identifier(): projectID,
|
||||
AppColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
},
|
||||
).ToSql()
|
||||
if err != nil {
|
||||
@@ -219,7 +226,10 @@ func (q *Queries) AppByProjectAndAppID(ctx context.Context, projectID, appID str
|
||||
func (q *Queries) AppByID(ctx context.Context, appID string) (*App, error) {
|
||||
stmt, scan := prepareAppQuery()
|
||||
query, args, err := stmt.Where(
|
||||
sq.Eq{AppColumnID.identifier(): appID},
|
||||
sq.Eq{
|
||||
AppColumnID.identifier(): appID,
|
||||
AppColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
},
|
||||
).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "QUERY-immt9", "Errors.Query.SQLStatement")
|
||||
@@ -232,7 +242,10 @@ func (q *Queries) AppByID(ctx context.Context, appID string) (*App, error) {
|
||||
func (q *Queries) ProjectIDFromOIDCClientID(ctx context.Context, appID string) (string, error) {
|
||||
stmt, scan := prepareProjectIDByAppQuery()
|
||||
query, args, err := stmt.Where(
|
||||
sq.Eq{AppOIDCConfigColumnClientID.identifier(): appID},
|
||||
sq.Eq{
|
||||
AppOIDCConfigColumnClientID.identifier(): appID,
|
||||
AppColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
},
|
||||
).ToSql()
|
||||
if err != nil {
|
||||
return "", errors.ThrowInternal(err, "QUERY-7d92U", "Errors.Query.SQLStatement")
|
||||
@@ -245,9 +258,12 @@ func (q *Queries) ProjectIDFromOIDCClientID(ctx context.Context, appID string) (
|
||||
func (q *Queries) ProjectIDFromClientID(ctx context.Context, appID string) (string, error) {
|
||||
stmt, scan := prepareProjectIDByAppQuery()
|
||||
query, args, err := stmt.Where(
|
||||
sq.Or{
|
||||
sq.Eq{AppOIDCConfigColumnClientID.identifier(): appID},
|
||||
sq.Eq{AppAPIConfigColumnClientID.identifier(): appID},
|
||||
sq.And{
|
||||
sq.Eq{AppColumnInstanceID.identifier(): authz.GetInstance(ctx).ID},
|
||||
sq.Or{
|
||||
sq.Eq{AppOIDCConfigColumnClientID.identifier(): appID},
|
||||
sq.Eq{AppAPIConfigColumnClientID.identifier(): appID},
|
||||
},
|
||||
},
|
||||
).ToSql()
|
||||
if err != nil {
|
||||
@@ -261,7 +277,10 @@ func (q *Queries) ProjectIDFromClientID(ctx context.Context, appID string) (stri
|
||||
func (q *Queries) ProjectByOIDCClientID(ctx context.Context, id string) (*Project, error) {
|
||||
stmt, scan := prepareProjectByAppQuery()
|
||||
query, args, err := stmt.Where(
|
||||
sq.Eq{AppOIDCConfigColumnClientID.identifier(): id},
|
||||
sq.Eq{
|
||||
AppOIDCConfigColumnClientID.identifier(): id,
|
||||
AppColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
},
|
||||
).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "QUERY-XhJi4", "Errors.Query.SQLStatement")
|
||||
@@ -276,6 +295,7 @@ func (q *Queries) AppByOIDCClientID(ctx context.Context, clientID string) (*App,
|
||||
query, args, err := stmt.Where(
|
||||
sq.Eq{
|
||||
AppOIDCConfigColumnClientID.identifier(): clientID,
|
||||
AppColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
},
|
||||
).ToSql()
|
||||
if err != nil {
|
||||
@@ -289,9 +309,12 @@ func (q *Queries) AppByOIDCClientID(ctx context.Context, clientID string) (*App,
|
||||
func (q *Queries) AppByClientID(ctx context.Context, clientID string) (*App, error) {
|
||||
stmt, scan := prepareAppQuery()
|
||||
query, args, err := stmt.Where(
|
||||
sq.Or{
|
||||
sq.Eq{AppOIDCConfigColumnClientID.identifier(): clientID},
|
||||
sq.Eq{AppAPIConfigColumnClientID.identifier(): clientID},
|
||||
sq.And{
|
||||
sq.Eq{AppColumnInstanceID.identifier(): authz.GetInstance(ctx).ID},
|
||||
sq.Or{
|
||||
sq.Eq{AppOIDCConfigColumnClientID.identifier(): clientID},
|
||||
sq.Eq{AppAPIConfigColumnClientID.identifier(): clientID},
|
||||
},
|
||||
},
|
||||
).ToSql()
|
||||
if err != nil {
|
||||
@@ -304,7 +327,10 @@ func (q *Queries) AppByClientID(ctx context.Context, clientID string) (*App, err
|
||||
|
||||
func (q *Queries) SearchApps(ctx context.Context, queries *AppSearchQueries) (*Apps, error) {
|
||||
query, scan := prepareAppsQuery()
|
||||
stmt, args, err := queries.toQuery(query).ToSql()
|
||||
stmt, args, err := queries.toQuery(query).
|
||||
Where(
|
||||
sq.Eq{AppColumnInstanceID.identifier(): authz.GetInstance(ctx).ID},
|
||||
).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInvalidArgument(err, "QUERY-fajp8", "Errors.Query.InvalidRequest")
|
||||
}
|
||||
@@ -323,7 +349,10 @@ func (q *Queries) SearchApps(ctx context.Context, queries *AppSearchQueries) (*A
|
||||
|
||||
func (q *Queries) SearchClientIDs(ctx context.Context, queries *AppSearchQueries) ([]string, error) {
|
||||
query, scan := prepareClientIDsQuery()
|
||||
stmt, args, err := queries.toQuery(query).ToSql()
|
||||
stmt, args, err := queries.toQuery(query).
|
||||
Where(
|
||||
sq.Eq{AppColumnInstanceID.identifier(): authz.GetInstance(ctx).ID},
|
||||
).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInvalidArgument(err, "QUERY-fajp8", "Errors.Query.InvalidRequest")
|
||||
}
|
||||
|
||||
+84
-84
@@ -16,95 +16,95 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
expectedAppQuery = regexp.QuoteMeta(`SELECT zitadel.projections.apps.id,` +
|
||||
` zitadel.projections.apps.name,` +
|
||||
` zitadel.projections.apps.project_id,` +
|
||||
` zitadel.projections.apps.creation_date,` +
|
||||
` zitadel.projections.apps.change_date,` +
|
||||
` zitadel.projections.apps.resource_owner,` +
|
||||
` zitadel.projections.apps.state,` +
|
||||
` zitadel.projections.apps.sequence,` +
|
||||
expectedAppQuery = regexp.QuoteMeta(`SELECT projections.apps.id,` +
|
||||
` projections.apps.name,` +
|
||||
` projections.apps.project_id,` +
|
||||
` projections.apps.creation_date,` +
|
||||
` projections.apps.change_date,` +
|
||||
` projections.apps.resource_owner,` +
|
||||
` projections.apps.state,` +
|
||||
` projections.apps.sequence,` +
|
||||
// api config
|
||||
` zitadel.projections.apps_api_configs.app_id,` +
|
||||
` zitadel.projections.apps_api_configs.client_id,` +
|
||||
` zitadel.projections.apps_api_configs.auth_method,` +
|
||||
` projections.apps_api_configs.app_id,` +
|
||||
` projections.apps_api_configs.client_id,` +
|
||||
` projections.apps_api_configs.auth_method,` +
|
||||
// oidc config
|
||||
` zitadel.projections.apps_oidc_configs.app_id,` +
|
||||
` zitadel.projections.apps_oidc_configs.version,` +
|
||||
` zitadel.projections.apps_oidc_configs.client_id,` +
|
||||
` zitadel.projections.apps_oidc_configs.redirect_uris,` +
|
||||
` zitadel.projections.apps_oidc_configs.response_types,` +
|
||||
` zitadel.projections.apps_oidc_configs.grant_types,` +
|
||||
` zitadel.projections.apps_oidc_configs.application_type,` +
|
||||
` zitadel.projections.apps_oidc_configs.auth_method_type,` +
|
||||
` zitadel.projections.apps_oidc_configs.post_logout_redirect_uris,` +
|
||||
` zitadel.projections.apps_oidc_configs.is_dev_mode,` +
|
||||
` zitadel.projections.apps_oidc_configs.access_token_type,` +
|
||||
` zitadel.projections.apps_oidc_configs.access_token_role_assertion,` +
|
||||
` zitadel.projections.apps_oidc_configs.id_token_role_assertion,` +
|
||||
` zitadel.projections.apps_oidc_configs.id_token_userinfo_assertion,` +
|
||||
` zitadel.projections.apps_oidc_configs.clock_skew,` +
|
||||
` zitadel.projections.apps_oidc_configs.additional_origins` +
|
||||
` FROM zitadel.projections.apps` +
|
||||
` LEFT JOIN zitadel.projections.apps_api_configs ON zitadel.projections.apps.id = zitadel.projections.apps_api_configs.app_id` +
|
||||
` LEFT JOIN zitadel.projections.apps_oidc_configs ON zitadel.projections.apps.id = zitadel.projections.apps_oidc_configs.app_id`)
|
||||
expectedAppsQuery = regexp.QuoteMeta(`SELECT zitadel.projections.apps.id,` +
|
||||
` zitadel.projections.apps.name,` +
|
||||
` zitadel.projections.apps.project_id,` +
|
||||
` zitadel.projections.apps.creation_date,` +
|
||||
` zitadel.projections.apps.change_date,` +
|
||||
` zitadel.projections.apps.resource_owner,` +
|
||||
` zitadel.projections.apps.state,` +
|
||||
` zitadel.projections.apps.sequence,` +
|
||||
` projections.apps_oidc_configs.app_id,` +
|
||||
` projections.apps_oidc_configs.version,` +
|
||||
` projections.apps_oidc_configs.client_id,` +
|
||||
` projections.apps_oidc_configs.redirect_uris,` +
|
||||
` projections.apps_oidc_configs.response_types,` +
|
||||
` projections.apps_oidc_configs.grant_types,` +
|
||||
` projections.apps_oidc_configs.application_type,` +
|
||||
` projections.apps_oidc_configs.auth_method_type,` +
|
||||
` projections.apps_oidc_configs.post_logout_redirect_uris,` +
|
||||
` projections.apps_oidc_configs.is_dev_mode,` +
|
||||
` projections.apps_oidc_configs.access_token_type,` +
|
||||
` projections.apps_oidc_configs.access_token_role_assertion,` +
|
||||
` projections.apps_oidc_configs.id_token_role_assertion,` +
|
||||
` projections.apps_oidc_configs.id_token_userinfo_assertion,` +
|
||||
` projections.apps_oidc_configs.clock_skew,` +
|
||||
` projections.apps_oidc_configs.additional_origins` +
|
||||
` FROM projections.apps` +
|
||||
` LEFT JOIN projections.apps_api_configs ON projections.apps.id = projections.apps_api_configs.app_id` +
|
||||
` LEFT JOIN projections.apps_oidc_configs ON projections.apps.id = projections.apps_oidc_configs.app_id`)
|
||||
expectedAppsQuery = regexp.QuoteMeta(`SELECT projections.apps.id,` +
|
||||
` projections.apps.name,` +
|
||||
` projections.apps.project_id,` +
|
||||
` projections.apps.creation_date,` +
|
||||
` projections.apps.change_date,` +
|
||||
` projections.apps.resource_owner,` +
|
||||
` projections.apps.state,` +
|
||||
` projections.apps.sequence,` +
|
||||
// api config
|
||||
` zitadel.projections.apps_api_configs.app_id,` +
|
||||
` zitadel.projections.apps_api_configs.client_id,` +
|
||||
` zitadel.projections.apps_api_configs.auth_method,` +
|
||||
` projections.apps_api_configs.app_id,` +
|
||||
` projections.apps_api_configs.client_id,` +
|
||||
` projections.apps_api_configs.auth_method,` +
|
||||
// oidc config
|
||||
` zitadel.projections.apps_oidc_configs.app_id,` +
|
||||
` zitadel.projections.apps_oidc_configs.version,` +
|
||||
` zitadel.projections.apps_oidc_configs.client_id,` +
|
||||
` zitadel.projections.apps_oidc_configs.redirect_uris,` +
|
||||
` zitadel.projections.apps_oidc_configs.response_types,` +
|
||||
` zitadel.projections.apps_oidc_configs.grant_types,` +
|
||||
` zitadel.projections.apps_oidc_configs.application_type,` +
|
||||
` zitadel.projections.apps_oidc_configs.auth_method_type,` +
|
||||
` zitadel.projections.apps_oidc_configs.post_logout_redirect_uris,` +
|
||||
` zitadel.projections.apps_oidc_configs.is_dev_mode,` +
|
||||
` zitadel.projections.apps_oidc_configs.access_token_type,` +
|
||||
` zitadel.projections.apps_oidc_configs.access_token_role_assertion,` +
|
||||
` zitadel.projections.apps_oidc_configs.id_token_role_assertion,` +
|
||||
` zitadel.projections.apps_oidc_configs.id_token_userinfo_assertion,` +
|
||||
` zitadel.projections.apps_oidc_configs.clock_skew,` +
|
||||
` zitadel.projections.apps_oidc_configs.additional_origins,` +
|
||||
` projections.apps_oidc_configs.app_id,` +
|
||||
` projections.apps_oidc_configs.version,` +
|
||||
` projections.apps_oidc_configs.client_id,` +
|
||||
` projections.apps_oidc_configs.redirect_uris,` +
|
||||
` projections.apps_oidc_configs.response_types,` +
|
||||
` projections.apps_oidc_configs.grant_types,` +
|
||||
` projections.apps_oidc_configs.application_type,` +
|
||||
` projections.apps_oidc_configs.auth_method_type,` +
|
||||
` projections.apps_oidc_configs.post_logout_redirect_uris,` +
|
||||
` projections.apps_oidc_configs.is_dev_mode,` +
|
||||
` projections.apps_oidc_configs.access_token_type,` +
|
||||
` projections.apps_oidc_configs.access_token_role_assertion,` +
|
||||
` projections.apps_oidc_configs.id_token_role_assertion,` +
|
||||
` projections.apps_oidc_configs.id_token_userinfo_assertion,` +
|
||||
` projections.apps_oidc_configs.clock_skew,` +
|
||||
` projections.apps_oidc_configs.additional_origins,` +
|
||||
` COUNT(*) OVER ()` +
|
||||
` FROM zitadel.projections.apps` +
|
||||
` LEFT JOIN zitadel.projections.apps_api_configs ON zitadel.projections.apps.id = zitadel.projections.apps_api_configs.app_id` +
|
||||
` LEFT JOIN zitadel.projections.apps_oidc_configs ON zitadel.projections.apps.id = zitadel.projections.apps_oidc_configs.app_id`)
|
||||
expectedAppIDsQuery = regexp.QuoteMeta(`SELECT zitadel.projections.apps_api_configs.client_id,` +
|
||||
` zitadel.projections.apps_oidc_configs.client_id` +
|
||||
` FROM zitadel.projections.apps` +
|
||||
` LEFT JOIN zitadel.projections.apps_api_configs ON zitadel.projections.apps.id = zitadel.projections.apps_api_configs.app_id` +
|
||||
` LEFT JOIN zitadel.projections.apps_oidc_configs ON zitadel.projections.apps.id = zitadel.projections.apps_oidc_configs.app_id`)
|
||||
expectedProjectIDByAppQuery = regexp.QuoteMeta(`SELECT zitadel.projections.apps.project_id` +
|
||||
` FROM zitadel.projections.apps` +
|
||||
` LEFT JOIN zitadel.projections.apps_api_configs ON zitadel.projections.apps.id = zitadel.projections.apps_api_configs.app_id` +
|
||||
` LEFT JOIN zitadel.projections.apps_oidc_configs ON zitadel.projections.apps.id = zitadel.projections.apps_oidc_configs.app_id`)
|
||||
expectedProjectByAppQuery = regexp.QuoteMeta(`SELECT zitadel.projections.projects.id,` +
|
||||
` zitadel.projections.projects.creation_date,` +
|
||||
` zitadel.projections.projects.change_date,` +
|
||||
` zitadel.projections.projects.resource_owner,` +
|
||||
` zitadel.projections.projects.state,` +
|
||||
` zitadel.projections.projects.sequence,` +
|
||||
` zitadel.projections.projects.name,` +
|
||||
` zitadel.projections.projects.project_role_assertion,` +
|
||||
` zitadel.projections.projects.project_role_check,` +
|
||||
` zitadel.projections.projects.has_project_check,` +
|
||||
` zitadel.projections.projects.private_labeling_setting` +
|
||||
` FROM zitadel.projections.projects` +
|
||||
` JOIN zitadel.projections.apps ON zitadel.projections.projects.id = zitadel.projections.apps.project_id` +
|
||||
` LEFT JOIN zitadel.projections.apps_api_configs ON zitadel.projections.apps.id = zitadel.projections.apps_api_configs.app_id` +
|
||||
` LEFT JOIN zitadel.projections.apps_oidc_configs ON zitadel.projections.apps.id = zitadel.projections.apps_oidc_configs.app_id`)
|
||||
` FROM projections.apps` +
|
||||
` LEFT JOIN projections.apps_api_configs ON projections.apps.id = projections.apps_api_configs.app_id` +
|
||||
` LEFT JOIN projections.apps_oidc_configs ON projections.apps.id = projections.apps_oidc_configs.app_id`)
|
||||
expectedAppIDsQuery = regexp.QuoteMeta(`SELECT projections.apps_api_configs.client_id,` +
|
||||
` projections.apps_oidc_configs.client_id` +
|
||||
` FROM projections.apps` +
|
||||
` LEFT JOIN projections.apps_api_configs ON projections.apps.id = projections.apps_api_configs.app_id` +
|
||||
` LEFT JOIN projections.apps_oidc_configs ON projections.apps.id = projections.apps_oidc_configs.app_id`)
|
||||
expectedProjectIDByAppQuery = regexp.QuoteMeta(`SELECT projections.apps.project_id` +
|
||||
` FROM projections.apps` +
|
||||
` LEFT JOIN projections.apps_api_configs ON projections.apps.id = projections.apps_api_configs.app_id` +
|
||||
` LEFT JOIN projections.apps_oidc_configs ON projections.apps.id = projections.apps_oidc_configs.app_id`)
|
||||
expectedProjectByAppQuery = regexp.QuoteMeta(`SELECT projections.projects.id,` +
|
||||
` projections.projects.creation_date,` +
|
||||
` projections.projects.change_date,` +
|
||||
` projections.projects.resource_owner,` +
|
||||
` projections.projects.state,` +
|
||||
` projections.projects.sequence,` +
|
||||
` projections.projects.name,` +
|
||||
` projections.projects.project_role_assertion,` +
|
||||
` projections.projects.project_role_check,` +
|
||||
` projections.projects.has_project_check,` +
|
||||
` projections.projects.private_labeling_setting` +
|
||||
` FROM projections.projects` +
|
||||
` JOIN projections.apps ON projections.projects.id = projections.apps.project_id` +
|
||||
` LEFT JOIN projections.apps_api_configs ON projections.apps.id = projections.apps_api_configs.app_id` +
|
||||
` LEFT JOIN projections.apps_oidc_configs ON projections.apps.id = projections.apps_oidc_configs.app_id`)
|
||||
|
||||
appCols = []string{
|
||||
"id",
|
||||
|
||||
@@ -8,6 +8,8 @@ import (
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/query/projection"
|
||||
@@ -29,6 +31,10 @@ var (
|
||||
name: projection.AuthNKeyResourceOwnerCol,
|
||||
table: authNKeyTable,
|
||||
}
|
||||
AuthNKeyColumnInstanceID = Column{
|
||||
name: projection.AuthNKeyInstanceIDCol,
|
||||
table: authNKeyTable,
|
||||
}
|
||||
AuthNKeyColumnAggregateID = Column{
|
||||
name: projection.AuthNKeyAggregateIDCol,
|
||||
table: authNKeyTable,
|
||||
@@ -96,7 +102,8 @@ func (q *Queries) SearchAuthNKeys(ctx context.Context, queries *AuthNKeySearchQu
|
||||
query = queries.toQuery(query)
|
||||
stmt, args, err := query.Where(
|
||||
sq.Eq{
|
||||
AuthNKeyColumnEnabled.identifier(): true,
|
||||
AuthNKeyColumnEnabled.identifier(): true,
|
||||
AuthNKeyColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
},
|
||||
).ToSql()
|
||||
if err != nil {
|
||||
@@ -122,8 +129,9 @@ func (q *Queries) GetAuthNKeyByID(ctx context.Context, id string, queries ...Sea
|
||||
}
|
||||
stmt, args, err := query.Where(
|
||||
sq.Eq{
|
||||
AuthNKeyColumnID.identifier(): id,
|
||||
AuthNKeyColumnEnabled.identifier(): true,
|
||||
AuthNKeyColumnID.identifier(): id,
|
||||
AuthNKeyColumnEnabled.identifier(): true,
|
||||
AuthNKeyColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "QUERY-AGhg4", "Errors.Query.SQLStatement")
|
||||
@@ -141,6 +149,7 @@ func (q *Queries) GetAuthNKeyPublicKeyByIDAndIdentifier(ctx context.Context, id
|
||||
AuthNKeyColumnID.identifier(): id,
|
||||
AuthNKeyColumnIdentifier.identifier(): identifier,
|
||||
AuthNKeyColumnEnabled.identifier(): true,
|
||||
AuthNKeyColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
},
|
||||
sq.Gt{
|
||||
AuthNKeyColumnExpiration.identifier(): time.Now(),
|
||||
|
||||
@@ -28,14 +28,14 @@ func Test_AuthNKeyPrepares(t *testing.T) {
|
||||
prepare: prepareAuthNKeysQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.authn_keys.id,`+
|
||||
` zitadel.projections.authn_keys.creation_date,`+
|
||||
` zitadel.projections.authn_keys.resource_owner,`+
|
||||
` zitadel.projections.authn_keys.sequence,`+
|
||||
` zitadel.projections.authn_keys.expiration,`+
|
||||
` zitadel.projections.authn_keys.type,`+
|
||||
regexp.QuoteMeta(`SELECT projections.authn_keys.id,`+
|
||||
` projections.authn_keys.creation_date,`+
|
||||
` projections.authn_keys.resource_owner,`+
|
||||
` projections.authn_keys.sequence,`+
|
||||
` projections.authn_keys.expiration,`+
|
||||
` projections.authn_keys.type,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.authn_keys`),
|
||||
` FROM projections.authn_keys`),
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -47,14 +47,14 @@ func Test_AuthNKeyPrepares(t *testing.T) {
|
||||
prepare: prepareAuthNKeysQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.authn_keys.id,`+
|
||||
` zitadel.projections.authn_keys.creation_date,`+
|
||||
` zitadel.projections.authn_keys.resource_owner,`+
|
||||
` zitadel.projections.authn_keys.sequence,`+
|
||||
` zitadel.projections.authn_keys.expiration,`+
|
||||
` zitadel.projections.authn_keys.type,`+
|
||||
regexp.QuoteMeta(`SELECT projections.authn_keys.id,`+
|
||||
` projections.authn_keys.creation_date,`+
|
||||
` projections.authn_keys.resource_owner,`+
|
||||
` projections.authn_keys.sequence,`+
|
||||
` projections.authn_keys.expiration,`+
|
||||
` projections.authn_keys.type,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.authn_keys`),
|
||||
` FROM projections.authn_keys`),
|
||||
[]string{
|
||||
"id",
|
||||
"creation_date",
|
||||
@@ -97,14 +97,14 @@ func Test_AuthNKeyPrepares(t *testing.T) {
|
||||
prepare: prepareAuthNKeysQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.authn_keys.id,`+
|
||||
` zitadel.projections.authn_keys.creation_date,`+
|
||||
` zitadel.projections.authn_keys.resource_owner,`+
|
||||
` zitadel.projections.authn_keys.sequence,`+
|
||||
` zitadel.projections.authn_keys.expiration,`+
|
||||
` zitadel.projections.authn_keys.type,`+
|
||||
regexp.QuoteMeta(`SELECT projections.authn_keys.id,`+
|
||||
` projections.authn_keys.creation_date,`+
|
||||
` projections.authn_keys.resource_owner,`+
|
||||
` projections.authn_keys.sequence,`+
|
||||
` projections.authn_keys.expiration,`+
|
||||
` projections.authn_keys.type,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.authn_keys`),
|
||||
` FROM projections.authn_keys`),
|
||||
[]string{
|
||||
"id",
|
||||
"creation_date",
|
||||
@@ -163,14 +163,14 @@ func Test_AuthNKeyPrepares(t *testing.T) {
|
||||
prepare: prepareAuthNKeysQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.authn_keys.id,`+
|
||||
` zitadel.projections.authn_keys.creation_date,`+
|
||||
` zitadel.projections.authn_keys.resource_owner,`+
|
||||
` zitadel.projections.authn_keys.sequence,`+
|
||||
` zitadel.projections.authn_keys.expiration,`+
|
||||
` zitadel.projections.authn_keys.type,`+
|
||||
regexp.QuoteMeta(`SELECT projections.authn_keys.id,`+
|
||||
` projections.authn_keys.creation_date,`+
|
||||
` projections.authn_keys.resource_owner,`+
|
||||
` projections.authn_keys.sequence,`+
|
||||
` projections.authn_keys.expiration,`+
|
||||
` projections.authn_keys.type,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.authn_keys`),
|
||||
` FROM projections.authn_keys`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
@@ -187,13 +187,13 @@ func Test_AuthNKeyPrepares(t *testing.T) {
|
||||
prepare: prepareAuthNKeyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.authn_keys.id,`+
|
||||
` zitadel.projections.authn_keys.creation_date,`+
|
||||
` zitadel.projections.authn_keys.resource_owner,`+
|
||||
` zitadel.projections.authn_keys.sequence,`+
|
||||
` zitadel.projections.authn_keys.expiration,`+
|
||||
` zitadel.projections.authn_keys.type`+
|
||||
` FROM zitadel.projections.authn_keys`),
|
||||
regexp.QuoteMeta(`SELECT projections.authn_keys.id,`+
|
||||
` projections.authn_keys.creation_date,`+
|
||||
` projections.authn_keys.resource_owner,`+
|
||||
` projections.authn_keys.sequence,`+
|
||||
` projections.authn_keys.expiration,`+
|
||||
` projections.authn_keys.type`+
|
||||
` FROM projections.authn_keys`),
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -211,13 +211,13 @@ func Test_AuthNKeyPrepares(t *testing.T) {
|
||||
prepare: prepareAuthNKeyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.authn_keys.id,`+
|
||||
` zitadel.projections.authn_keys.creation_date,`+
|
||||
` zitadel.projections.authn_keys.resource_owner,`+
|
||||
` zitadel.projections.authn_keys.sequence,`+
|
||||
` zitadel.projections.authn_keys.expiration,`+
|
||||
` zitadel.projections.authn_keys.type`+
|
||||
` FROM zitadel.projections.authn_keys`),
|
||||
regexp.QuoteMeta(`SELECT projections.authn_keys.id,`+
|
||||
` projections.authn_keys.creation_date,`+
|
||||
` projections.authn_keys.resource_owner,`+
|
||||
` projections.authn_keys.sequence,`+
|
||||
` projections.authn_keys.expiration,`+
|
||||
` projections.authn_keys.type`+
|
||||
` FROM projections.authn_keys`),
|
||||
[]string{
|
||||
"id",
|
||||
"creation_date",
|
||||
@@ -250,13 +250,13 @@ func Test_AuthNKeyPrepares(t *testing.T) {
|
||||
prepare: prepareAuthNKeyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.authn_keys.id,`+
|
||||
` zitadel.projections.authn_keys.creation_date,`+
|
||||
` zitadel.projections.authn_keys.resource_owner,`+
|
||||
` zitadel.projections.authn_keys.sequence,`+
|
||||
` zitadel.projections.authn_keys.expiration,`+
|
||||
` zitadel.projections.authn_keys.type`+
|
||||
` FROM zitadel.projections.authn_keys`),
|
||||
regexp.QuoteMeta(`SELECT projections.authn_keys.id,`+
|
||||
` projections.authn_keys.creation_date,`+
|
||||
` projections.authn_keys.resource_owner,`+
|
||||
` projections.authn_keys.sequence,`+
|
||||
` projections.authn_keys.expiration,`+
|
||||
` projections.authn_keys.type`+
|
||||
` FROM projections.authn_keys`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
@@ -273,8 +273,8 @@ func Test_AuthNKeyPrepares(t *testing.T) {
|
||||
prepare: prepareAuthNKeyPublicKeyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.authn_keys.public_key`+
|
||||
` FROM zitadel.projections.authn_keys`),
|
||||
regexp.QuoteMeta(`SELECT projections.authn_keys.public_key`+
|
||||
` FROM projections.authn_keys`),
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -292,8 +292,8 @@ func Test_AuthNKeyPrepares(t *testing.T) {
|
||||
prepare: prepareAuthNKeyPublicKeyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.authn_keys.public_key`+
|
||||
` FROM zitadel.projections.authn_keys`),
|
||||
regexp.QuoteMeta(`SELECT projections.authn_keys.public_key`+
|
||||
` FROM projections.authn_keys`),
|
||||
[]string{
|
||||
"public_key",
|
||||
},
|
||||
@@ -309,8 +309,8 @@ func Test_AuthNKeyPrepares(t *testing.T) {
|
||||
prepare: prepareAuthNKeyPublicKeyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.authn_keys.public_key`+
|
||||
` FROM zitadel.projections.authn_keys`),
|
||||
regexp.QuoteMeta(`SELECT projections.authn_keys.public_key`+
|
||||
` FROM projections.authn_keys`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
|
||||
@@ -105,11 +105,11 @@ func (q *Queries) ClearCurrentSequence(ctx context.Context, projectionName strin
|
||||
|
||||
func (q *Queries) checkAndLock(ctx context.Context, projectionName string) error {
|
||||
projectionQuery, args, err := sq.Select("count(*)").
|
||||
From("[show tables from zitadel.projections]").
|
||||
From("[show tables from projections]").
|
||||
Where(
|
||||
sq.And{
|
||||
sq.NotEq{"table_name": []string{"locks", "current_sequences", "failed_events"}},
|
||||
sq.Eq{"concat('zitadel.projections.', table_name)": projectionName},
|
||||
sq.Eq{"concat('projections.', table_name)": projectionName},
|
||||
}).
|
||||
PlaceholderFormat(sq.Dollar).
|
||||
ToSql()
|
||||
@@ -139,13 +139,13 @@ func (q *Queries) checkAndLock(ctx context.Context, projectionName string) error
|
||||
}
|
||||
|
||||
func tablesForReset(ctx context.Context, tx *sql.Tx, projectionName string) ([]string, error) {
|
||||
tablesQuery, args, err := sq.Select("concat('zitadel.projections.', table_name)").
|
||||
From("[show tables from zitadel.projections]").
|
||||
tablesQuery, args, err := sq.Select("concat('projections.', table_name)").
|
||||
From("[show tables from projections]").
|
||||
Where(
|
||||
sq.And{
|
||||
sq.Eq{"type": "table"},
|
||||
sq.NotEq{"table_name": []string{"locks", "current_sequences", "failed_events"}},
|
||||
sq.Like{"concat('zitadel.projections.', table_name)": projectionName + "%"},
|
||||
sq.Like{"concat('projections.', table_name)": projectionName + "%"},
|
||||
}).
|
||||
PlaceholderFormat(sq.Dollar).
|
||||
ToSql()
|
||||
|
||||
@@ -12,6 +12,8 @@ import (
|
||||
"golang.org/x/text/language"
|
||||
"sigs.k8s.io/yaml"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
@@ -43,6 +45,10 @@ var (
|
||||
name: projection.CustomTextAggregateIDCol,
|
||||
table: customTextTable,
|
||||
}
|
||||
CustomTextColInstanceID = Column{
|
||||
name: projection.CustomTextInstanceIDCol,
|
||||
table: customTextTable,
|
||||
}
|
||||
CustomTextColSequence = Column{
|
||||
name: projection.CustomTextSequenceCol,
|
||||
table: customTextTable,
|
||||
@@ -80,6 +86,7 @@ func (q *Queries) CustomTextList(ctx context.Context, aggregateID, template, lan
|
||||
CustomTextColAggregateID.identifier(): aggregateID,
|
||||
CustomTextColTemplate.identifier(): template,
|
||||
CustomTextColLanguage.identifier(): language,
|
||||
CustomTextColInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
},
|
||||
).ToSql()
|
||||
if err != nil {
|
||||
@@ -104,6 +111,7 @@ func (q *Queries) CustomTextListByTemplate(ctx context.Context, aggregateID, tem
|
||||
sq.Eq{
|
||||
CustomTextColAggregateID.identifier(): aggregateID,
|
||||
CustomTextColTemplate.identifier(): template,
|
||||
CustomTextColInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
},
|
||||
).ToSql()
|
||||
if err != nil {
|
||||
|
||||
@@ -8,8 +8,9 @@ import (
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
errs "github.com/caos/zitadel/internal/errors"
|
||||
"golang.org/x/text/language"
|
||||
|
||||
errs "github.com/caos/zitadel/internal/errors"
|
||||
)
|
||||
|
||||
func Test_CustomTextPrepares(t *testing.T) {
|
||||
@@ -28,16 +29,16 @@ func Test_CustomTextPrepares(t *testing.T) {
|
||||
prepare: prepareCustomTextsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.custom_texts.aggregate_id,`+
|
||||
` zitadel.projections.custom_texts.sequence,`+
|
||||
` zitadel.projections.custom_texts.creation_date,`+
|
||||
` zitadel.projections.custom_texts.change_date,`+
|
||||
` zitadel.projections.custom_texts.language,`+
|
||||
` zitadel.projections.custom_texts.template,`+
|
||||
` zitadel.projections.custom_texts.key,`+
|
||||
` zitadel.projections.custom_texts.text,`+
|
||||
regexp.QuoteMeta(`SELECT projections.custom_texts.aggregate_id,`+
|
||||
` projections.custom_texts.sequence,`+
|
||||
` projections.custom_texts.creation_date,`+
|
||||
` projections.custom_texts.change_date,`+
|
||||
` projections.custom_texts.language,`+
|
||||
` projections.custom_texts.template,`+
|
||||
` projections.custom_texts.key,`+
|
||||
` projections.custom_texts.text,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.custom_texts`),
|
||||
` FROM projections.custom_texts`),
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -55,16 +56,16 @@ func Test_CustomTextPrepares(t *testing.T) {
|
||||
prepare: prepareCustomTextsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.custom_texts.aggregate_id,`+
|
||||
` zitadel.projections.custom_texts.sequence,`+
|
||||
` zitadel.projections.custom_texts.creation_date,`+
|
||||
` zitadel.projections.custom_texts.change_date,`+
|
||||
` zitadel.projections.custom_texts.language,`+
|
||||
` zitadel.projections.custom_texts.template,`+
|
||||
` zitadel.projections.custom_texts.key,`+
|
||||
` zitadel.projections.custom_texts.text,`+
|
||||
regexp.QuoteMeta(`SELECT projections.custom_texts.aggregate_id,`+
|
||||
` projections.custom_texts.sequence,`+
|
||||
` projections.custom_texts.creation_date,`+
|
||||
` projections.custom_texts.change_date,`+
|
||||
` projections.custom_texts.language,`+
|
||||
` projections.custom_texts.template,`+
|
||||
` projections.custom_texts.key,`+
|
||||
` projections.custom_texts.text,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.custom_texts`),
|
||||
` FROM projections.custom_texts`),
|
||||
[]string{
|
||||
"aggregate_id",
|
||||
"sequence",
|
||||
@@ -113,16 +114,16 @@ func Test_CustomTextPrepares(t *testing.T) {
|
||||
prepare: prepareCustomTextsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.custom_texts.aggregate_id,`+
|
||||
` zitadel.projections.custom_texts.sequence,`+
|
||||
` zitadel.projections.custom_texts.creation_date,`+
|
||||
` zitadel.projections.custom_texts.change_date,`+
|
||||
` zitadel.projections.custom_texts.language,`+
|
||||
` zitadel.projections.custom_texts.template,`+
|
||||
` zitadel.projections.custom_texts.key,`+
|
||||
` zitadel.projections.custom_texts.text,`+
|
||||
regexp.QuoteMeta(`SELECT projections.custom_texts.aggregate_id,`+
|
||||
` projections.custom_texts.sequence,`+
|
||||
` projections.custom_texts.creation_date,`+
|
||||
` projections.custom_texts.change_date,`+
|
||||
` projections.custom_texts.language,`+
|
||||
` projections.custom_texts.template,`+
|
||||
` projections.custom_texts.key,`+
|
||||
` projections.custom_texts.text,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.custom_texts`),
|
||||
` FROM projections.custom_texts`),
|
||||
[]string{
|
||||
"aggregate_id",
|
||||
"sequence",
|
||||
@@ -191,16 +192,16 @@ func Test_CustomTextPrepares(t *testing.T) {
|
||||
prepare: prepareCustomTextsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.custom_texts.aggregate_id,`+
|
||||
` zitadel.projections.custom_texts.sequence,`+
|
||||
` zitadel.projections.custom_texts.creation_date,`+
|
||||
` zitadel.projections.custom_texts.change_date,`+
|
||||
` zitadel.projections.custom_texts.language,`+
|
||||
` zitadel.projections.custom_texts.template,`+
|
||||
` zitadel.projections.custom_texts.key,`+
|
||||
` zitadel.projections.custom_texts.text,`+
|
||||
regexp.QuoteMeta(`SELECT projections.custom_texts.aggregate_id,`+
|
||||
` projections.custom_texts.sequence,`+
|
||||
` projections.custom_texts.creation_date,`+
|
||||
` projections.custom_texts.change_date,`+
|
||||
` projections.custom_texts.language,`+
|
||||
` projections.custom_texts.template,`+
|
||||
` projections.custom_texts.key,`+
|
||||
` projections.custom_texts.text,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.custom_texts`),
|
||||
` FROM projections.custom_texts`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
|
||||
@@ -16,6 +16,7 @@ const (
|
||||
failedEventsColumnFailedSequence = "failed_sequence"
|
||||
failedEventsColumnFailureCount = "failure_count"
|
||||
failedEventsColumnError = "error"
|
||||
failedEventsColumnInstanceID = "instance_id"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -38,6 +39,10 @@ var (
|
||||
name: failedEventsColumnError,
|
||||
table: failedEventsTable,
|
||||
}
|
||||
FailedEventsColumnInstanceID = Column{
|
||||
name: failedEventsColumnInstanceID,
|
||||
table: failedEventsTable,
|
||||
}
|
||||
)
|
||||
|
||||
type FailedEvents struct {
|
||||
|
||||
@@ -8,6 +8,8 @@ import (
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/query/projection"
|
||||
@@ -50,6 +52,10 @@ var (
|
||||
name: projection.FeatureAggregateIDCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureColumnInstanceID = Column{
|
||||
name: projection.FeatureInstanceIDCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureColumnChangeDate = Column{
|
||||
name: projection.FeatureChangeDateCol,
|
||||
table: featureTable,
|
||||
@@ -155,12 +161,17 @@ var (
|
||||
func (q *Queries) FeaturesByOrgID(ctx context.Context, orgID string) (*Features, error) {
|
||||
query, scan := prepareFeaturesQuery()
|
||||
stmt, args, err := query.Where(
|
||||
sq.Or{
|
||||
sq.And{
|
||||
sq.Eq{
|
||||
FeatureColumnAggregateID.identifier(): orgID,
|
||||
FeatureColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
},
|
||||
sq.Eq{
|
||||
FeatureColumnAggregateID.identifier(): domain.IAMID,
|
||||
sq.Or{
|
||||
sq.Eq{
|
||||
FeatureColumnAggregateID.identifier(): orgID,
|
||||
},
|
||||
sq.Eq{
|
||||
FeatureColumnAggregateID.identifier(): domain.IAMID,
|
||||
},
|
||||
},
|
||||
}).
|
||||
OrderBy(FeatureColumnIsDefault.identifier()).
|
||||
@@ -177,6 +188,7 @@ func (q *Queries) DefaultFeatures(ctx context.Context) (*Features, error) {
|
||||
query, scan := prepareFeaturesQuery()
|
||||
stmt, args, err := query.Where(sq.Eq{
|
||||
FeatureColumnAggregateID.identifier(): domain.IAMID,
|
||||
FeatureColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "QUERY-1Ndlg", "Errors.Query.SQLStatement")
|
||||
|
||||
+108
-108
@@ -29,33 +29,33 @@ func Test_FeaturesPrepares(t *testing.T) {
|
||||
prepare: prepareFeaturesQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.features.aggregate_id,`+
|
||||
` zitadel.projections.features.change_date,`+
|
||||
` zitadel.projections.features.sequence,`+
|
||||
` zitadel.projections.features.is_default,`+
|
||||
` zitadel.projections.features.tier_name,`+
|
||||
` zitadel.projections.features.tier_description,`+
|
||||
` zitadel.projections.features.state,`+
|
||||
` zitadel.projections.features.state_description,`+
|
||||
` zitadel.projections.features.audit_log_retention,`+
|
||||
` zitadel.projections.features.login_policy_factors,`+
|
||||
` zitadel.projections.features.login_policy_idp,`+
|
||||
` zitadel.projections.features.login_policy_passwordless,`+
|
||||
` zitadel.projections.features.login_policy_registration,`+
|
||||
` zitadel.projections.features.login_policy_username_login,`+
|
||||
` zitadel.projections.features.login_policy_password_reset,`+
|
||||
` zitadel.projections.features.password_complexity_policy,`+
|
||||
` zitadel.projections.features.label_policy_private_label,`+
|
||||
` zitadel.projections.features.label_policy_watermark,`+
|
||||
` zitadel.projections.features.custom_domain,`+
|
||||
` zitadel.projections.features.privacy_policy,`+
|
||||
` zitadel.projections.features.metadata_user,`+
|
||||
` zitadel.projections.features.custom_text_message,`+
|
||||
` zitadel.projections.features.custom_text_login,`+
|
||||
` zitadel.projections.features.lockout_policy,`+
|
||||
` zitadel.projections.features.actions_allowed,`+
|
||||
` zitadel.projections.features.max_actions`+
|
||||
` FROM zitadel.projections.features`),
|
||||
regexp.QuoteMeta(`SELECT projections.features.aggregate_id,`+
|
||||
` projections.features.change_date,`+
|
||||
` projections.features.sequence,`+
|
||||
` projections.features.is_default,`+
|
||||
` projections.features.tier_name,`+
|
||||
` projections.features.tier_description,`+
|
||||
` projections.features.state,`+
|
||||
` projections.features.state_description,`+
|
||||
` projections.features.audit_log_retention,`+
|
||||
` projections.features.login_policy_factors,`+
|
||||
` projections.features.login_policy_idp,`+
|
||||
` projections.features.login_policy_passwordless,`+
|
||||
` projections.features.login_policy_registration,`+
|
||||
` projections.features.login_policy_username_login,`+
|
||||
` projections.features.login_policy_password_reset,`+
|
||||
` projections.features.password_complexity_policy,`+
|
||||
` projections.features.label_policy_private_label,`+
|
||||
` projections.features.label_policy_watermark,`+
|
||||
` projections.features.custom_domain,`+
|
||||
` projections.features.privacy_policy,`+
|
||||
` projections.features.metadata_user,`+
|
||||
` projections.features.custom_text_message,`+
|
||||
` projections.features.custom_text_login,`+
|
||||
` projections.features.lockout_policy,`+
|
||||
` projections.features.actions_allowed,`+
|
||||
` projections.features.max_actions`+
|
||||
` FROM projections.features`),
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -73,33 +73,33 @@ func Test_FeaturesPrepares(t *testing.T) {
|
||||
prepare: prepareFeaturesQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.features.aggregate_id,`+
|
||||
` zitadel.projections.features.change_date,`+
|
||||
` zitadel.projections.features.sequence,`+
|
||||
` zitadel.projections.features.is_default,`+
|
||||
` zitadel.projections.features.tier_name,`+
|
||||
` zitadel.projections.features.tier_description,`+
|
||||
` zitadel.projections.features.state,`+
|
||||
` zitadel.projections.features.state_description,`+
|
||||
` zitadel.projections.features.audit_log_retention,`+
|
||||
` zitadel.projections.features.login_policy_factors,`+
|
||||
` zitadel.projections.features.login_policy_idp,`+
|
||||
` zitadel.projections.features.login_policy_passwordless,`+
|
||||
` zitadel.projections.features.login_policy_registration,`+
|
||||
` zitadel.projections.features.login_policy_username_login,`+
|
||||
` zitadel.projections.features.login_policy_password_reset,`+
|
||||
` zitadel.projections.features.password_complexity_policy,`+
|
||||
` zitadel.projections.features.label_policy_private_label,`+
|
||||
` zitadel.projections.features.label_policy_watermark,`+
|
||||
` zitadel.projections.features.custom_domain,`+
|
||||
` zitadel.projections.features.privacy_policy,`+
|
||||
` zitadel.projections.features.metadata_user,`+
|
||||
` zitadel.projections.features.custom_text_message,`+
|
||||
` zitadel.projections.features.custom_text_login,`+
|
||||
` zitadel.projections.features.lockout_policy,`+
|
||||
` zitadel.projections.features.actions_allowed,`+
|
||||
` zitadel.projections.features.max_actions`+
|
||||
` FROM zitadel.projections.features`),
|
||||
regexp.QuoteMeta(`SELECT projections.features.aggregate_id,`+
|
||||
` projections.features.change_date,`+
|
||||
` projections.features.sequence,`+
|
||||
` projections.features.is_default,`+
|
||||
` projections.features.tier_name,`+
|
||||
` projections.features.tier_description,`+
|
||||
` projections.features.state,`+
|
||||
` projections.features.state_description,`+
|
||||
` projections.features.audit_log_retention,`+
|
||||
` projections.features.login_policy_factors,`+
|
||||
` projections.features.login_policy_idp,`+
|
||||
` projections.features.login_policy_passwordless,`+
|
||||
` projections.features.login_policy_registration,`+
|
||||
` projections.features.login_policy_username_login,`+
|
||||
` projections.features.login_policy_password_reset,`+
|
||||
` projections.features.password_complexity_policy,`+
|
||||
` projections.features.label_policy_private_label,`+
|
||||
` projections.features.label_policy_watermark,`+
|
||||
` projections.features.custom_domain,`+
|
||||
` projections.features.privacy_policy,`+
|
||||
` projections.features.metadata_user,`+
|
||||
` projections.features.custom_text_message,`+
|
||||
` projections.features.custom_text_login,`+
|
||||
` projections.features.lockout_policy,`+
|
||||
` projections.features.actions_allowed,`+
|
||||
` projections.features.max_actions`+
|
||||
` FROM projections.features`),
|
||||
[]string{
|
||||
"aggregate_id",
|
||||
"change_date",
|
||||
@@ -192,33 +192,33 @@ func Test_FeaturesPrepares(t *testing.T) {
|
||||
prepare: prepareFeaturesQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.features.aggregate_id,`+
|
||||
` zitadel.projections.features.change_date,`+
|
||||
` zitadel.projections.features.sequence,`+
|
||||
` zitadel.projections.features.is_default,`+
|
||||
` zitadel.projections.features.tier_name,`+
|
||||
` zitadel.projections.features.tier_description,`+
|
||||
` zitadel.projections.features.state,`+
|
||||
` zitadel.projections.features.state_description,`+
|
||||
` zitadel.projections.features.audit_log_retention,`+
|
||||
` zitadel.projections.features.login_policy_factors,`+
|
||||
` zitadel.projections.features.login_policy_idp,`+
|
||||
` zitadel.projections.features.login_policy_passwordless,`+
|
||||
` zitadel.projections.features.login_policy_registration,`+
|
||||
` zitadel.projections.features.login_policy_username_login,`+
|
||||
` zitadel.projections.features.login_policy_password_reset,`+
|
||||
` zitadel.projections.features.password_complexity_policy,`+
|
||||
` zitadel.projections.features.label_policy_private_label,`+
|
||||
` zitadel.projections.features.label_policy_watermark,`+
|
||||
` zitadel.projections.features.custom_domain,`+
|
||||
` zitadel.projections.features.privacy_policy,`+
|
||||
` zitadel.projections.features.metadata_user,`+
|
||||
` zitadel.projections.features.custom_text_message,`+
|
||||
` zitadel.projections.features.custom_text_login,`+
|
||||
` zitadel.projections.features.lockout_policy,`+
|
||||
` zitadel.projections.features.actions_allowed,`+
|
||||
` zitadel.projections.features.max_actions`+
|
||||
` FROM zitadel.projections.features`),
|
||||
regexp.QuoteMeta(`SELECT projections.features.aggregate_id,`+
|
||||
` projections.features.change_date,`+
|
||||
` projections.features.sequence,`+
|
||||
` projections.features.is_default,`+
|
||||
` projections.features.tier_name,`+
|
||||
` projections.features.tier_description,`+
|
||||
` projections.features.state,`+
|
||||
` projections.features.state_description,`+
|
||||
` projections.features.audit_log_retention,`+
|
||||
` projections.features.login_policy_factors,`+
|
||||
` projections.features.login_policy_idp,`+
|
||||
` projections.features.login_policy_passwordless,`+
|
||||
` projections.features.login_policy_registration,`+
|
||||
` projections.features.login_policy_username_login,`+
|
||||
` projections.features.login_policy_password_reset,`+
|
||||
` projections.features.password_complexity_policy,`+
|
||||
` projections.features.label_policy_private_label,`+
|
||||
` projections.features.label_policy_watermark,`+
|
||||
` projections.features.custom_domain,`+
|
||||
` projections.features.privacy_policy,`+
|
||||
` projections.features.metadata_user,`+
|
||||
` projections.features.custom_text_message,`+
|
||||
` projections.features.custom_text_login,`+
|
||||
` projections.features.lockout_policy,`+
|
||||
` projections.features.actions_allowed,`+
|
||||
` projections.features.max_actions`+
|
||||
` FROM projections.features`),
|
||||
[]string{
|
||||
"aggregate_id",
|
||||
"change_date",
|
||||
@@ -311,33 +311,33 @@ func Test_FeaturesPrepares(t *testing.T) {
|
||||
prepare: prepareFeaturesQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.features.aggregate_id,`+
|
||||
` zitadel.projections.features.change_date,`+
|
||||
` zitadel.projections.features.sequence,`+
|
||||
` zitadel.projections.features.is_default,`+
|
||||
` zitadel.projections.features.tier_name,`+
|
||||
` zitadel.projections.features.tier_description,`+
|
||||
` zitadel.projections.features.state,`+
|
||||
` zitadel.projections.features.state_description,`+
|
||||
` zitadel.projections.features.audit_log_retention,`+
|
||||
` zitadel.projections.features.login_policy_factors,`+
|
||||
` zitadel.projections.features.login_policy_idp,`+
|
||||
` zitadel.projections.features.login_policy_passwordless,`+
|
||||
` zitadel.projections.features.login_policy_registration,`+
|
||||
` zitadel.projections.features.login_policy_username_login,`+
|
||||
` zitadel.projections.features.login_policy_password_reset,`+
|
||||
` zitadel.projections.features.password_complexity_policy,`+
|
||||
` zitadel.projections.features.label_policy_private_label,`+
|
||||
` zitadel.projections.features.label_policy_watermark,`+
|
||||
` zitadel.projections.features.custom_domain,`+
|
||||
` zitadel.projections.features.privacy_policy,`+
|
||||
` zitadel.projections.features.metadata_user,`+
|
||||
` zitadel.projections.features.custom_text_message,`+
|
||||
` zitadel.projections.features.custom_text_login,`+
|
||||
` zitadel.projections.features.lockout_policy,`+
|
||||
` zitadel.projections.features.actions_allowed,`+
|
||||
` zitadel.projections.features.max_actions`+
|
||||
` FROM zitadel.projections.features`),
|
||||
regexp.QuoteMeta(`SELECT projections.features.aggregate_id,`+
|
||||
` projections.features.change_date,`+
|
||||
` projections.features.sequence,`+
|
||||
` projections.features.is_default,`+
|
||||
` projections.features.tier_name,`+
|
||||
` projections.features.tier_description,`+
|
||||
` projections.features.state,`+
|
||||
` projections.features.state_description,`+
|
||||
` projections.features.audit_log_retention,`+
|
||||
` projections.features.login_policy_factors,`+
|
||||
` projections.features.login_policy_idp,`+
|
||||
` projections.features.login_policy_passwordless,`+
|
||||
` projections.features.login_policy_registration,`+
|
||||
` projections.features.login_policy_username_login,`+
|
||||
` projections.features.login_policy_password_reset,`+
|
||||
` projections.features.password_complexity_policy,`+
|
||||
` projections.features.label_policy_private_label,`+
|
||||
` projections.features.label_policy_watermark,`+
|
||||
` projections.features.custom_domain,`+
|
||||
` projections.features.privacy_policy,`+
|
||||
` projections.features.metadata_user,`+
|
||||
` projections.features.custom_text_message,`+
|
||||
` projections.features.custom_text_login,`+
|
||||
` projections.features.lockout_policy,`+
|
||||
` projections.features.actions_allowed,`+
|
||||
` projections.features.max_actions`+
|
||||
` FROM projections.features`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
|
||||
@@ -7,10 +7,12 @@ import (
|
||||
"time"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
"golang.org/x/text/language"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/query/projection"
|
||||
"golang.org/x/text/language"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -76,10 +78,10 @@ func (q *IAMSearchQueries) toQuery(query sq.SelectBuilder) sq.SelectBuilder {
|
||||
return query
|
||||
}
|
||||
|
||||
func (q *Queries) IAMByID(ctx context.Context, id string) (*IAM, error) {
|
||||
func (q *Queries) IAM(ctx context.Context) (*IAM, error) {
|
||||
stmt, scan := prepareIAMQuery()
|
||||
query, args, err := stmt.Where(sq.Eq{
|
||||
IAMColumnID.identifier(): id,
|
||||
IAMColumnID.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "QUERY-d9ngs", "Errors.Query.SQLStatement")
|
||||
@@ -90,7 +92,7 @@ func (q *Queries) IAMByID(ctx context.Context, id string) (*IAM, error) {
|
||||
}
|
||||
|
||||
func (q *Queries) GetDefaultLanguage(ctx context.Context) language.Tag {
|
||||
iam, err := q.IAMByID(ctx, domain.IAMID)
|
||||
iam, err := q.IAM(ctx)
|
||||
if err != nil {
|
||||
return language.Und
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
"github.com/lib/pq"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/query/projection"
|
||||
)
|
||||
@@ -40,6 +42,10 @@ var (
|
||||
name: projection.MemberResourceOwner,
|
||||
table: iamMemberTable,
|
||||
}
|
||||
IAMMemberInstanceID = Column{
|
||||
name: projection.MemberInstanceID,
|
||||
table: iamMemberTable,
|
||||
}
|
||||
IAMMemberIAMID = Column{
|
||||
name: projection.IAMMemberIAMIDCol,
|
||||
table: iamMemberTable,
|
||||
@@ -57,7 +63,10 @@ func (q *IAMMembersQuery) toQuery(query sq.SelectBuilder) sq.SelectBuilder {
|
||||
|
||||
func (q *Queries) IAMMembers(ctx context.Context, queries *IAMMembersQuery) (*Members, error) {
|
||||
query, scan := prepareIAMMembersQuery()
|
||||
stmt, args, err := queries.toQuery(query).ToSql()
|
||||
stmt, args, err := queries.toQuery(query).
|
||||
Where(sq.Eq{
|
||||
IAMMemberInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInvalidArgument(err, "QUERY-USNwM", "Errors.Query.InvalidRequest")
|
||||
}
|
||||
|
||||
@@ -19,22 +19,22 @@ var (
|
||||
", members.resource_owner" +
|
||||
", members.user_id" +
|
||||
", members.roles" +
|
||||
", zitadel.projections.login_names.login_name" +
|
||||
", zitadel.projections.users_humans.email" +
|
||||
", zitadel.projections.users_humans.first_name" +
|
||||
", zitadel.projections.users_humans.last_name" +
|
||||
", zitadel.projections.users_humans.display_name" +
|
||||
", zitadel.projections.users_machines.name" +
|
||||
", zitadel.projections.users_humans.avatar_key" +
|
||||
", projections.login_names.login_name" +
|
||||
", projections.users_humans.email" +
|
||||
", projections.users_humans.first_name" +
|
||||
", projections.users_humans.last_name" +
|
||||
", projections.users_humans.display_name" +
|
||||
", projections.users_machines.name" +
|
||||
", projections.users_humans.avatar_key" +
|
||||
", COUNT(*) OVER () " +
|
||||
"FROM zitadel.projections.iam_members as members " +
|
||||
"LEFT JOIN zitadel.projections.users_humans " +
|
||||
"ON members.user_id = zitadel.projections.users_humans.user_id " +
|
||||
"LEFT JOIN zitadel.projections.users_machines " +
|
||||
"ON members.user_id = zitadel.projections.users_machines.user_id " +
|
||||
"LEFT JOIN zitadel.projections.login_names " +
|
||||
"ON members.user_id = zitadel.projections.login_names.user_id " +
|
||||
"WHERE zitadel.projections.login_names.is_primary = $1")
|
||||
"FROM projections.iam_members as members " +
|
||||
"LEFT JOIN projections.users_humans " +
|
||||
"ON members.user_id = projections.users_humans.user_id " +
|
||||
"LEFT JOIN projections.users_machines " +
|
||||
"ON members.user_id = projections.users_machines.user_id " +
|
||||
"LEFT JOIN projections.login_names " +
|
||||
"ON members.user_id = projections.login_names.user_id " +
|
||||
"WHERE projections.login_names.is_primary = $1")
|
||||
iamMembersColumns = []string{
|
||||
"creation_date",
|
||||
"change_date",
|
||||
|
||||
+29
-28
@@ -8,9 +8,10 @@ import (
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/text/language"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
errs "github.com/caos/zitadel/internal/errors"
|
||||
"golang.org/x/text/language"
|
||||
)
|
||||
|
||||
func Test_IAMPrepares(t *testing.T) {
|
||||
@@ -29,15 +30,15 @@ func Test_IAMPrepares(t *testing.T) {
|
||||
prepare: prepareIAMQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.iam.id,`+
|
||||
` zitadel.projections.iam.change_date,`+
|
||||
` zitadel.projections.iam.sequence,`+
|
||||
` zitadel.projections.iam.global_org_id,`+
|
||||
` zitadel.projections.iam.iam_project_id,`+
|
||||
` zitadel.projections.iam.setup_started,`+
|
||||
` zitadel.projections.iam.setup_done,`+
|
||||
` zitadel.projections.iam.default_language`+
|
||||
` FROM zitadel.projections.iam`),
|
||||
regexp.QuoteMeta(`SELECT projections.iam.id,`+
|
||||
` projections.iam.change_date,`+
|
||||
` projections.iam.sequence,`+
|
||||
` projections.iam.global_org_id,`+
|
||||
` projections.iam.iam_project_id,`+
|
||||
` projections.iam.setup_started,`+
|
||||
` projections.iam.setup_done,`+
|
||||
` projections.iam.default_language`+
|
||||
` FROM projections.iam`),
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -55,15 +56,15 @@ func Test_IAMPrepares(t *testing.T) {
|
||||
prepare: prepareIAMQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.iam.id,`+
|
||||
` zitadel.projections.iam.change_date,`+
|
||||
` zitadel.projections.iam.sequence,`+
|
||||
` zitadel.projections.iam.global_org_id,`+
|
||||
` zitadel.projections.iam.iam_project_id,`+
|
||||
` zitadel.projections.iam.setup_started,`+
|
||||
` zitadel.projections.iam.setup_done,`+
|
||||
` zitadel.projections.iam.default_language`+
|
||||
` FROM zitadel.projections.iam`),
|
||||
regexp.QuoteMeta(`SELECT projections.iam.id,`+
|
||||
` projections.iam.change_date,`+
|
||||
` projections.iam.sequence,`+
|
||||
` projections.iam.global_org_id,`+
|
||||
` projections.iam.iam_project_id,`+
|
||||
` projections.iam.setup_started,`+
|
||||
` projections.iam.setup_done,`+
|
||||
` projections.iam.default_language`+
|
||||
` FROM projections.iam`),
|
||||
[]string{
|
||||
"id",
|
||||
"change_date",
|
||||
@@ -102,15 +103,15 @@ func Test_IAMPrepares(t *testing.T) {
|
||||
prepare: prepareIAMQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.iam.id,`+
|
||||
` zitadel.projections.iam.change_date,`+
|
||||
` zitadel.projections.iam.sequence,`+
|
||||
` zitadel.projections.iam.global_org_id,`+
|
||||
` zitadel.projections.iam.iam_project_id,`+
|
||||
` zitadel.projections.iam.setup_started,`+
|
||||
` zitadel.projections.iam.setup_done,`+
|
||||
` zitadel.projections.iam.default_language`+
|
||||
` FROM zitadel.projections.iam`),
|
||||
regexp.QuoteMeta(`SELECT projections.iam.id,`+
|
||||
` projections.iam.change_date,`+
|
||||
` projections.iam.sequence,`+
|
||||
` projections.iam.global_org_id,`+
|
||||
` projections.iam.iam_project_id,`+
|
||||
` projections.iam.setup_started,`+
|
||||
` projections.iam.setup_done,`+
|
||||
` projections.iam.default_language`+
|
||||
` FROM projections.iam`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
|
||||
+12
-2
@@ -9,6 +9,8 @@ import (
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
"github.com/lib/pq"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
|
||||
"github.com/caos/zitadel/internal/crypto"
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
@@ -79,6 +81,10 @@ var (
|
||||
name: projection.IDPResourceOwnerCol,
|
||||
table: idpTable,
|
||||
}
|
||||
IDPInstanceIDCol = Column{
|
||||
name: projection.IDPInstanceIDCol,
|
||||
table: idpTable,
|
||||
}
|
||||
IDPStateCol = Column{
|
||||
name: projection.IDPStateCol,
|
||||
table: idpTable,
|
||||
@@ -179,7 +185,8 @@ func (q *Queries) IDPByIDAndResourceOwner(ctx context.Context, id, resourceOwner
|
||||
query, args, err := stmt.Where(
|
||||
sq.And{
|
||||
sq.Eq{
|
||||
IDPIDCol.identifier(): id,
|
||||
IDPIDCol.identifier(): id,
|
||||
IDPInstanceIDCol.identifier(): authz.GetInstance(ctx).ID,
|
||||
},
|
||||
sq.Or{
|
||||
sq.Eq{
|
||||
@@ -202,7 +209,10 @@ func (q *Queries) IDPByIDAndResourceOwner(ctx context.Context, id, resourceOwner
|
||||
//IDPs searches idps matching the query
|
||||
func (q *Queries) IDPs(ctx context.Context, queries *IDPSearchQueries) (idps *IDPs, err error) {
|
||||
query, scan := prepareIDPsQuery()
|
||||
stmt, args, err := queries.toQuery(query).ToSql()
|
||||
stmt, args, err := queries.toQuery(query).
|
||||
Where(sq.Eq{
|
||||
IDPInstanceIDCol.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInvalidArgument(err, "QUERY-X6X7y", "Errors.Query.InvalidRequest")
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import (
|
||||
"database/sql"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/query/projection"
|
||||
@@ -58,6 +60,10 @@ var (
|
||||
name: projection.IDPLoginPolicyLinkResourceOwnerCol,
|
||||
table: idpLoginPolicyLinkTable,
|
||||
}
|
||||
IDPLoginPolicyLinkInstanceIDCol = Column{
|
||||
name: projection.IDPLoginPolicyLinkInstanceIDCol,
|
||||
table: idpLoginPolicyLinkTable,
|
||||
}
|
||||
IDPLoginPolicyLinkProviderTypeCol = Column{
|
||||
name: projection.IDPLoginPolicyLinkProviderTypeCol,
|
||||
table: idpLoginPolicyLinkTable,
|
||||
@@ -67,7 +73,10 @@ var (
|
||||
func (q *Queries) IDPLoginPolicyLinks(ctx context.Context, resourceOwner string, queries *IDPLoginPolicyLinksSearchQuery) (idps *IDPLoginPolicyLinks, err error) {
|
||||
query, scan := prepareIDPLoginPolicyLinksQuery()
|
||||
stmt, args, err := queries.toQuery(query).Where(
|
||||
sq.Eq{IDPLoginPolicyLinkResourceOwnerCol.identifier(): resourceOwner},
|
||||
sq.Eq{
|
||||
IDPLoginPolicyLinkResourceOwnerCol.identifier(): resourceOwner,
|
||||
IDPLoginPolicyLinkInstanceIDCol.identifier(): authz.GetInstance(ctx).ID,
|
||||
},
|
||||
).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInvalidArgument(err, "QUERY-FDbKW", "Errors.Query.InvalidRequest")
|
||||
|
||||
@@ -12,12 +12,12 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
loginPolicyIDPLinksQuery = regexp.QuoteMeta(`SELECT zitadel.projections.idp_login_policy_links.idp_id,` +
|
||||
` zitadel.projections.idps.name,` +
|
||||
` zitadel.projections.idps.type,` +
|
||||
loginPolicyIDPLinksQuery = regexp.QuoteMeta(`SELECT projections.idp_login_policy_links.idp_id,` +
|
||||
` projections.idps.name,` +
|
||||
` projections.idps.type,` +
|
||||
` COUNT(*) OVER ()` +
|
||||
` FROM zitadel.projections.idp_login_policy_links` +
|
||||
` LEFT JOIN zitadel.projections.idps ON zitadel.projections.idp_login_policy_links.idp_id = zitadel.projections.idps.id`)
|
||||
` FROM projections.idp_login_policy_links` +
|
||||
` LEFT JOIN projections.idps ON projections.idp_login_policy_links.idp_id = projections.idps.id`)
|
||||
loginPolicyIDPLinksCols = []string{
|
||||
"idp_id",
|
||||
"name",
|
||||
|
||||
+299
-298
@@ -8,10 +8,11 @@ import (
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"github.com/lib/pq"
|
||||
|
||||
"github.com/caos/zitadel/internal/crypto"
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/lib/pq"
|
||||
)
|
||||
|
||||
func Test_IDPPrepares(t *testing.T) {
|
||||
@@ -30,33 +31,33 @@ func Test_IDPPrepares(t *testing.T) {
|
||||
prepare: prepareIDPByIDQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.idps.id,`+
|
||||
` zitadel.projections.idps.resource_owner,`+
|
||||
` zitadel.projections.idps.creation_date,`+
|
||||
` zitadel.projections.idps.change_date,`+
|
||||
` zitadel.projections.idps.sequence,`+
|
||||
` zitadel.projections.idps.state,`+
|
||||
` zitadel.projections.idps.name,`+
|
||||
` zitadel.projections.idps.styling_type,`+
|
||||
` zitadel.projections.idps.owner_type,`+
|
||||
` zitadel.projections.idps.auto_register,`+
|
||||
` zitadel.projections.idps_oidc_config.idp_id,`+
|
||||
` zitadel.projections.idps_oidc_config.client_id,`+
|
||||
` zitadel.projections.idps_oidc_config.client_secret,`+
|
||||
` zitadel.projections.idps_oidc_config.issuer,`+
|
||||
` zitadel.projections.idps_oidc_config.scopes,`+
|
||||
` zitadel.projections.idps_oidc_config.display_name_mapping,`+
|
||||
` zitadel.projections.idps_oidc_config.username_mapping,`+
|
||||
` zitadel.projections.idps_oidc_config.authorization_endpoint,`+
|
||||
` zitadel.projections.idps_oidc_config.token_endpoint,`+
|
||||
` zitadel.projections.idps_jwt_config.idp_id,`+
|
||||
` zitadel.projections.idps_jwt_config.issuer,`+
|
||||
` zitadel.projections.idps_jwt_config.keys_endpoint,`+
|
||||
` zitadel.projections.idps_jwt_config.header_name,`+
|
||||
` zitadel.projections.idps_jwt_config.endpoint`+
|
||||
` FROM zitadel.projections.idps`+
|
||||
` LEFT JOIN zitadel.projections.idps_oidc_config ON zitadel.projections.idps.id = zitadel.projections.idps_oidc_config.idp_id`+
|
||||
` LEFT JOIN zitadel.projections.idps_jwt_config ON zitadel.projections.idps.id = zitadel.projections.idps_jwt_config.idp_id`),
|
||||
regexp.QuoteMeta(`SELECT projections.idps.id,`+
|
||||
` projections.idps.resource_owner,`+
|
||||
` projections.idps.creation_date,`+
|
||||
` projections.idps.change_date,`+
|
||||
` projections.idps.sequence,`+
|
||||
` projections.idps.state,`+
|
||||
` projections.idps.name,`+
|
||||
` projections.idps.styling_type,`+
|
||||
` projections.idps.owner_type,`+
|
||||
` projections.idps.auto_register,`+
|
||||
` projections.idps_oidc_config.idp_id,`+
|
||||
` projections.idps_oidc_config.client_id,`+
|
||||
` projections.idps_oidc_config.client_secret,`+
|
||||
` projections.idps_oidc_config.issuer,`+
|
||||
` projections.idps_oidc_config.scopes,`+
|
||||
` projections.idps_oidc_config.display_name_mapping,`+
|
||||
` projections.idps_oidc_config.username_mapping,`+
|
||||
` projections.idps_oidc_config.authorization_endpoint,`+
|
||||
` projections.idps_oidc_config.token_endpoint,`+
|
||||
` projections.idps_jwt_config.idp_id,`+
|
||||
` projections.idps_jwt_config.issuer,`+
|
||||
` projections.idps_jwt_config.keys_endpoint,`+
|
||||
` projections.idps_jwt_config.header_name,`+
|
||||
` projections.idps_jwt_config.endpoint`+
|
||||
` FROM projections.idps`+
|
||||
` LEFT JOIN projections.idps_oidc_config ON projections.idps.id = projections.idps_oidc_config.idp_id`+
|
||||
` LEFT JOIN projections.idps_jwt_config ON projections.idps.id = projections.idps_jwt_config.idp_id`),
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -74,33 +75,33 @@ func Test_IDPPrepares(t *testing.T) {
|
||||
prepare: prepareIDPByIDQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.idps.id,`+
|
||||
` zitadel.projections.idps.resource_owner,`+
|
||||
` zitadel.projections.idps.creation_date,`+
|
||||
` zitadel.projections.idps.change_date,`+
|
||||
` zitadel.projections.idps.sequence,`+
|
||||
` zitadel.projections.idps.state,`+
|
||||
` zitadel.projections.idps.name,`+
|
||||
` zitadel.projections.idps.styling_type,`+
|
||||
` zitadel.projections.idps.owner_type,`+
|
||||
` zitadel.projections.idps.auto_register,`+
|
||||
` zitadel.projections.idps_oidc_config.idp_id,`+
|
||||
` zitadel.projections.idps_oidc_config.client_id,`+
|
||||
` zitadel.projections.idps_oidc_config.client_secret,`+
|
||||
` zitadel.projections.idps_oidc_config.issuer,`+
|
||||
` zitadel.projections.idps_oidc_config.scopes,`+
|
||||
` zitadel.projections.idps_oidc_config.display_name_mapping,`+
|
||||
` zitadel.projections.idps_oidc_config.username_mapping,`+
|
||||
` zitadel.projections.idps_oidc_config.authorization_endpoint,`+
|
||||
` zitadel.projections.idps_oidc_config.token_endpoint,`+
|
||||
` zitadel.projections.idps_jwt_config.idp_id,`+
|
||||
` zitadel.projections.idps_jwt_config.issuer,`+
|
||||
` zitadel.projections.idps_jwt_config.keys_endpoint,`+
|
||||
` zitadel.projections.idps_jwt_config.header_name,`+
|
||||
` zitadel.projections.idps_jwt_config.endpoint`+
|
||||
` FROM zitadel.projections.idps`+
|
||||
` LEFT JOIN zitadel.projections.idps_oidc_config ON zitadel.projections.idps.id = zitadel.projections.idps_oidc_config.idp_id`+
|
||||
` LEFT JOIN zitadel.projections.idps_jwt_config ON zitadel.projections.idps.id = zitadel.projections.idps_jwt_config.idp_id`),
|
||||
regexp.QuoteMeta(`SELECT projections.idps.id,`+
|
||||
` projections.idps.resource_owner,`+
|
||||
` projections.idps.creation_date,`+
|
||||
` projections.idps.change_date,`+
|
||||
` projections.idps.sequence,`+
|
||||
` projections.idps.state,`+
|
||||
` projections.idps.name,`+
|
||||
` projections.idps.styling_type,`+
|
||||
` projections.idps.owner_type,`+
|
||||
` projections.idps.auto_register,`+
|
||||
` projections.idps_oidc_config.idp_id,`+
|
||||
` projections.idps_oidc_config.client_id,`+
|
||||
` projections.idps_oidc_config.client_secret,`+
|
||||
` projections.idps_oidc_config.issuer,`+
|
||||
` projections.idps_oidc_config.scopes,`+
|
||||
` projections.idps_oidc_config.display_name_mapping,`+
|
||||
` projections.idps_oidc_config.username_mapping,`+
|
||||
` projections.idps_oidc_config.authorization_endpoint,`+
|
||||
` projections.idps_oidc_config.token_endpoint,`+
|
||||
` projections.idps_jwt_config.idp_id,`+
|
||||
` projections.idps_jwt_config.issuer,`+
|
||||
` projections.idps_jwt_config.keys_endpoint,`+
|
||||
` projections.idps_jwt_config.header_name,`+
|
||||
` projections.idps_jwt_config.endpoint`+
|
||||
` FROM projections.idps`+
|
||||
` LEFT JOIN projections.idps_oidc_config ON projections.idps.id = projections.idps_oidc_config.idp_id`+
|
||||
` LEFT JOIN projections.idps_jwt_config ON projections.idps.id = projections.idps_jwt_config.idp_id`),
|
||||
[]string{
|
||||
"id",
|
||||
"resource_owner",
|
||||
@@ -188,33 +189,33 @@ func Test_IDPPrepares(t *testing.T) {
|
||||
prepare: prepareIDPByIDQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.idps.id,`+
|
||||
` zitadel.projections.idps.resource_owner,`+
|
||||
` zitadel.projections.idps.creation_date,`+
|
||||
` zitadel.projections.idps.change_date,`+
|
||||
` zitadel.projections.idps.sequence,`+
|
||||
` zitadel.projections.idps.state,`+
|
||||
` zitadel.projections.idps.name,`+
|
||||
` zitadel.projections.idps.styling_type,`+
|
||||
` zitadel.projections.idps.owner_type,`+
|
||||
` zitadel.projections.idps.auto_register,`+
|
||||
` zitadel.projections.idps_oidc_config.idp_id,`+
|
||||
` zitadel.projections.idps_oidc_config.client_id,`+
|
||||
` zitadel.projections.idps_oidc_config.client_secret,`+
|
||||
` zitadel.projections.idps_oidc_config.issuer,`+
|
||||
` zitadel.projections.idps_oidc_config.scopes,`+
|
||||
` zitadel.projections.idps_oidc_config.display_name_mapping,`+
|
||||
` zitadel.projections.idps_oidc_config.username_mapping,`+
|
||||
` zitadel.projections.idps_oidc_config.authorization_endpoint,`+
|
||||
` zitadel.projections.idps_oidc_config.token_endpoint,`+
|
||||
` zitadel.projections.idps_jwt_config.idp_id,`+
|
||||
` zitadel.projections.idps_jwt_config.issuer,`+
|
||||
` zitadel.projections.idps_jwt_config.keys_endpoint,`+
|
||||
` zitadel.projections.idps_jwt_config.header_name,`+
|
||||
` zitadel.projections.idps_jwt_config.endpoint`+
|
||||
` FROM zitadel.projections.idps`+
|
||||
` LEFT JOIN zitadel.projections.idps_oidc_config ON zitadel.projections.idps.id = zitadel.projections.idps_oidc_config.idp_id`+
|
||||
` LEFT JOIN zitadel.projections.idps_jwt_config ON zitadel.projections.idps.id = zitadel.projections.idps_jwt_config.idp_id`),
|
||||
regexp.QuoteMeta(`SELECT projections.idps.id,`+
|
||||
` projections.idps.resource_owner,`+
|
||||
` projections.idps.creation_date,`+
|
||||
` projections.idps.change_date,`+
|
||||
` projections.idps.sequence,`+
|
||||
` projections.idps.state,`+
|
||||
` projections.idps.name,`+
|
||||
` projections.idps.styling_type,`+
|
||||
` projections.idps.owner_type,`+
|
||||
` projections.idps.auto_register,`+
|
||||
` projections.idps_oidc_config.idp_id,`+
|
||||
` projections.idps_oidc_config.client_id,`+
|
||||
` projections.idps_oidc_config.client_secret,`+
|
||||
` projections.idps_oidc_config.issuer,`+
|
||||
` projections.idps_oidc_config.scopes,`+
|
||||
` projections.idps_oidc_config.display_name_mapping,`+
|
||||
` projections.idps_oidc_config.username_mapping,`+
|
||||
` projections.idps_oidc_config.authorization_endpoint,`+
|
||||
` projections.idps_oidc_config.token_endpoint,`+
|
||||
` projections.idps_jwt_config.idp_id,`+
|
||||
` projections.idps_jwt_config.issuer,`+
|
||||
` projections.idps_jwt_config.keys_endpoint,`+
|
||||
` projections.idps_jwt_config.header_name,`+
|
||||
` projections.idps_jwt_config.endpoint`+
|
||||
` FROM projections.idps`+
|
||||
` LEFT JOIN projections.idps_oidc_config ON projections.idps.id = projections.idps_oidc_config.idp_id`+
|
||||
` LEFT JOIN projections.idps_jwt_config ON projections.idps.id = projections.idps_jwt_config.idp_id`),
|
||||
[]string{
|
||||
"id",
|
||||
"resource_owner",
|
||||
@@ -298,33 +299,33 @@ func Test_IDPPrepares(t *testing.T) {
|
||||
prepare: prepareIDPByIDQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.idps.id,`+
|
||||
` zitadel.projections.idps.resource_owner,`+
|
||||
` zitadel.projections.idps.creation_date,`+
|
||||
` zitadel.projections.idps.change_date,`+
|
||||
` zitadel.projections.idps.sequence,`+
|
||||
` zitadel.projections.idps.state,`+
|
||||
` zitadel.projections.idps.name,`+
|
||||
` zitadel.projections.idps.styling_type,`+
|
||||
` zitadel.projections.idps.owner_type,`+
|
||||
` zitadel.projections.idps.auto_register,`+
|
||||
` zitadel.projections.idps_oidc_config.idp_id,`+
|
||||
` zitadel.projections.idps_oidc_config.client_id,`+
|
||||
` zitadel.projections.idps_oidc_config.client_secret,`+
|
||||
` zitadel.projections.idps_oidc_config.issuer,`+
|
||||
` zitadel.projections.idps_oidc_config.scopes,`+
|
||||
` zitadel.projections.idps_oidc_config.display_name_mapping,`+
|
||||
` zitadel.projections.idps_oidc_config.username_mapping,`+
|
||||
` zitadel.projections.idps_oidc_config.authorization_endpoint,`+
|
||||
` zitadel.projections.idps_oidc_config.token_endpoint,`+
|
||||
` zitadel.projections.idps_jwt_config.idp_id,`+
|
||||
` zitadel.projections.idps_jwt_config.issuer,`+
|
||||
` zitadel.projections.idps_jwt_config.keys_endpoint,`+
|
||||
` zitadel.projections.idps_jwt_config.header_name,`+
|
||||
` zitadel.projections.idps_jwt_config.endpoint`+
|
||||
` FROM zitadel.projections.idps`+
|
||||
` LEFT JOIN zitadel.projections.idps_oidc_config ON zitadel.projections.idps.id = zitadel.projections.idps_oidc_config.idp_id`+
|
||||
` LEFT JOIN zitadel.projections.idps_jwt_config ON zitadel.projections.idps.id = zitadel.projections.idps_jwt_config.idp_id`),
|
||||
regexp.QuoteMeta(`SELECT projections.idps.id,`+
|
||||
` projections.idps.resource_owner,`+
|
||||
` projections.idps.creation_date,`+
|
||||
` projections.idps.change_date,`+
|
||||
` projections.idps.sequence,`+
|
||||
` projections.idps.state,`+
|
||||
` projections.idps.name,`+
|
||||
` projections.idps.styling_type,`+
|
||||
` projections.idps.owner_type,`+
|
||||
` projections.idps.auto_register,`+
|
||||
` projections.idps_oidc_config.idp_id,`+
|
||||
` projections.idps_oidc_config.client_id,`+
|
||||
` projections.idps_oidc_config.client_secret,`+
|
||||
` projections.idps_oidc_config.issuer,`+
|
||||
` projections.idps_oidc_config.scopes,`+
|
||||
` projections.idps_oidc_config.display_name_mapping,`+
|
||||
` projections.idps_oidc_config.username_mapping,`+
|
||||
` projections.idps_oidc_config.authorization_endpoint,`+
|
||||
` projections.idps_oidc_config.token_endpoint,`+
|
||||
` projections.idps_jwt_config.idp_id,`+
|
||||
` projections.idps_jwt_config.issuer,`+
|
||||
` projections.idps_jwt_config.keys_endpoint,`+
|
||||
` projections.idps_jwt_config.header_name,`+
|
||||
` projections.idps_jwt_config.endpoint`+
|
||||
` FROM projections.idps`+
|
||||
` LEFT JOIN projections.idps_oidc_config ON projections.idps.id = projections.idps_oidc_config.idp_id`+
|
||||
` LEFT JOIN projections.idps_jwt_config ON projections.idps.id = projections.idps_jwt_config.idp_id`),
|
||||
[]string{
|
||||
"id",
|
||||
"resource_owner",
|
||||
@@ -401,33 +402,33 @@ func Test_IDPPrepares(t *testing.T) {
|
||||
prepare: prepareIDPByIDQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.idps.id,`+
|
||||
` zitadel.projections.idps.resource_owner,`+
|
||||
` zitadel.projections.idps.creation_date,`+
|
||||
` zitadel.projections.idps.change_date,`+
|
||||
` zitadel.projections.idps.sequence,`+
|
||||
` zitadel.projections.idps.state,`+
|
||||
` zitadel.projections.idps.name,`+
|
||||
` zitadel.projections.idps.styling_type,`+
|
||||
` zitadel.projections.idps.owner_type,`+
|
||||
` zitadel.projections.idps.auto_register,`+
|
||||
` zitadel.projections.idps_oidc_config.idp_id,`+
|
||||
` zitadel.projections.idps_oidc_config.client_id,`+
|
||||
` zitadel.projections.idps_oidc_config.client_secret,`+
|
||||
` zitadel.projections.idps_oidc_config.issuer,`+
|
||||
` zitadel.projections.idps_oidc_config.scopes,`+
|
||||
` zitadel.projections.idps_oidc_config.display_name_mapping,`+
|
||||
` zitadel.projections.idps_oidc_config.username_mapping,`+
|
||||
` zitadel.projections.idps_oidc_config.authorization_endpoint,`+
|
||||
` zitadel.projections.idps_oidc_config.token_endpoint,`+
|
||||
` zitadel.projections.idps_jwt_config.idp_id,`+
|
||||
` zitadel.projections.idps_jwt_config.issuer,`+
|
||||
` zitadel.projections.idps_jwt_config.keys_endpoint,`+
|
||||
` zitadel.projections.idps_jwt_config.header_name,`+
|
||||
` zitadel.projections.idps_jwt_config.endpoint`+
|
||||
` FROM zitadel.projections.idps`+
|
||||
` LEFT JOIN zitadel.projections.idps_oidc_config ON zitadel.projections.idps.id = zitadel.projections.idps_oidc_config.idp_id`+
|
||||
` LEFT JOIN zitadel.projections.idps_jwt_config ON zitadel.projections.idps.id = zitadel.projections.idps_jwt_config.idp_id`),
|
||||
regexp.QuoteMeta(`SELECT projections.idps.id,`+
|
||||
` projections.idps.resource_owner,`+
|
||||
` projections.idps.creation_date,`+
|
||||
` projections.idps.change_date,`+
|
||||
` projections.idps.sequence,`+
|
||||
` projections.idps.state,`+
|
||||
` projections.idps.name,`+
|
||||
` projections.idps.styling_type,`+
|
||||
` projections.idps.owner_type,`+
|
||||
` projections.idps.auto_register,`+
|
||||
` projections.idps_oidc_config.idp_id,`+
|
||||
` projections.idps_oidc_config.client_id,`+
|
||||
` projections.idps_oidc_config.client_secret,`+
|
||||
` projections.idps_oidc_config.issuer,`+
|
||||
` projections.idps_oidc_config.scopes,`+
|
||||
` projections.idps_oidc_config.display_name_mapping,`+
|
||||
` projections.idps_oidc_config.username_mapping,`+
|
||||
` projections.idps_oidc_config.authorization_endpoint,`+
|
||||
` projections.idps_oidc_config.token_endpoint,`+
|
||||
` projections.idps_jwt_config.idp_id,`+
|
||||
` projections.idps_jwt_config.issuer,`+
|
||||
` projections.idps_jwt_config.keys_endpoint,`+
|
||||
` projections.idps_jwt_config.header_name,`+
|
||||
` projections.idps_jwt_config.endpoint`+
|
||||
` FROM projections.idps`+
|
||||
` LEFT JOIN projections.idps_oidc_config ON projections.idps.id = projections.idps_oidc_config.idp_id`+
|
||||
` LEFT JOIN projections.idps_jwt_config ON projections.idps.id = projections.idps_jwt_config.idp_id`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
@@ -444,34 +445,34 @@ func Test_IDPPrepares(t *testing.T) {
|
||||
prepare: prepareIDPsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.idps.id,`+
|
||||
` zitadel.projections.idps.resource_owner,`+
|
||||
` zitadel.projections.idps.creation_date,`+
|
||||
` zitadel.projections.idps.change_date,`+
|
||||
` zitadel.projections.idps.sequence,`+
|
||||
` zitadel.projections.idps.state,`+
|
||||
` zitadel.projections.idps.name,`+
|
||||
` zitadel.projections.idps.styling_type,`+
|
||||
` zitadel.projections.idps.owner_type,`+
|
||||
` zitadel.projections.idps.auto_register,`+
|
||||
` zitadel.projections.idps_oidc_config.idp_id,`+
|
||||
` zitadel.projections.idps_oidc_config.client_id,`+
|
||||
` zitadel.projections.idps_oidc_config.client_secret,`+
|
||||
` zitadel.projections.idps_oidc_config.issuer,`+
|
||||
` zitadel.projections.idps_oidc_config.scopes,`+
|
||||
` zitadel.projections.idps_oidc_config.display_name_mapping,`+
|
||||
` zitadel.projections.idps_oidc_config.username_mapping,`+
|
||||
` zitadel.projections.idps_oidc_config.authorization_endpoint,`+
|
||||
` zitadel.projections.idps_oidc_config.token_endpoint,`+
|
||||
` zitadel.projections.idps_jwt_config.idp_id,`+
|
||||
` zitadel.projections.idps_jwt_config.issuer,`+
|
||||
` zitadel.projections.idps_jwt_config.keys_endpoint,`+
|
||||
` zitadel.projections.idps_jwt_config.header_name,`+
|
||||
` zitadel.projections.idps_jwt_config.endpoint,`+
|
||||
regexp.QuoteMeta(`SELECT projections.idps.id,`+
|
||||
` projections.idps.resource_owner,`+
|
||||
` projections.idps.creation_date,`+
|
||||
` projections.idps.change_date,`+
|
||||
` projections.idps.sequence,`+
|
||||
` projections.idps.state,`+
|
||||
` projections.idps.name,`+
|
||||
` projections.idps.styling_type,`+
|
||||
` projections.idps.owner_type,`+
|
||||
` projections.idps.auto_register,`+
|
||||
` projections.idps_oidc_config.idp_id,`+
|
||||
` projections.idps_oidc_config.client_id,`+
|
||||
` projections.idps_oidc_config.client_secret,`+
|
||||
` projections.idps_oidc_config.issuer,`+
|
||||
` projections.idps_oidc_config.scopes,`+
|
||||
` projections.idps_oidc_config.display_name_mapping,`+
|
||||
` projections.idps_oidc_config.username_mapping,`+
|
||||
` projections.idps_oidc_config.authorization_endpoint,`+
|
||||
` projections.idps_oidc_config.token_endpoint,`+
|
||||
` projections.idps_jwt_config.idp_id,`+
|
||||
` projections.idps_jwt_config.issuer,`+
|
||||
` projections.idps_jwt_config.keys_endpoint,`+
|
||||
` projections.idps_jwt_config.header_name,`+
|
||||
` projections.idps_jwt_config.endpoint,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.idps`+
|
||||
` LEFT JOIN zitadel.projections.idps_oidc_config ON zitadel.projections.idps.id = zitadel.projections.idps_oidc_config.idp_id`+
|
||||
` LEFT JOIN zitadel.projections.idps_jwt_config ON zitadel.projections.idps.id = zitadel.projections.idps_jwt_config.idp_id`),
|
||||
` FROM projections.idps`+
|
||||
` LEFT JOIN projections.idps_oidc_config ON projections.idps.id = projections.idps_oidc_config.idp_id`+
|
||||
` LEFT JOIN projections.idps_jwt_config ON projections.idps.id = projections.idps_jwt_config.idp_id`),
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -489,34 +490,34 @@ func Test_IDPPrepares(t *testing.T) {
|
||||
prepare: prepareIDPsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.idps.id,`+
|
||||
` zitadel.projections.idps.resource_owner,`+
|
||||
` zitadel.projections.idps.creation_date,`+
|
||||
` zitadel.projections.idps.change_date,`+
|
||||
` zitadel.projections.idps.sequence,`+
|
||||
` zitadel.projections.idps.state,`+
|
||||
` zitadel.projections.idps.name,`+
|
||||
` zitadel.projections.idps.styling_type,`+
|
||||
` zitadel.projections.idps.owner_type,`+
|
||||
` zitadel.projections.idps.auto_register,`+
|
||||
` zitadel.projections.idps_oidc_config.idp_id,`+
|
||||
` zitadel.projections.idps_oidc_config.client_id,`+
|
||||
` zitadel.projections.idps_oidc_config.client_secret,`+
|
||||
` zitadel.projections.idps_oidc_config.issuer,`+
|
||||
` zitadel.projections.idps_oidc_config.scopes,`+
|
||||
` zitadel.projections.idps_oidc_config.display_name_mapping,`+
|
||||
` zitadel.projections.idps_oidc_config.username_mapping,`+
|
||||
` zitadel.projections.idps_oidc_config.authorization_endpoint,`+
|
||||
` zitadel.projections.idps_oidc_config.token_endpoint,`+
|
||||
` zitadel.projections.idps_jwt_config.idp_id,`+
|
||||
` zitadel.projections.idps_jwt_config.issuer,`+
|
||||
` zitadel.projections.idps_jwt_config.keys_endpoint,`+
|
||||
` zitadel.projections.idps_jwt_config.header_name,`+
|
||||
` zitadel.projections.idps_jwt_config.endpoint,`+
|
||||
regexp.QuoteMeta(`SELECT projections.idps.id,`+
|
||||
` projections.idps.resource_owner,`+
|
||||
` projections.idps.creation_date,`+
|
||||
` projections.idps.change_date,`+
|
||||
` projections.idps.sequence,`+
|
||||
` projections.idps.state,`+
|
||||
` projections.idps.name,`+
|
||||
` projections.idps.styling_type,`+
|
||||
` projections.idps.owner_type,`+
|
||||
` projections.idps.auto_register,`+
|
||||
` projections.idps_oidc_config.idp_id,`+
|
||||
` projections.idps_oidc_config.client_id,`+
|
||||
` projections.idps_oidc_config.client_secret,`+
|
||||
` projections.idps_oidc_config.issuer,`+
|
||||
` projections.idps_oidc_config.scopes,`+
|
||||
` projections.idps_oidc_config.display_name_mapping,`+
|
||||
` projections.idps_oidc_config.username_mapping,`+
|
||||
` projections.idps_oidc_config.authorization_endpoint,`+
|
||||
` projections.idps_oidc_config.token_endpoint,`+
|
||||
` projections.idps_jwt_config.idp_id,`+
|
||||
` projections.idps_jwt_config.issuer,`+
|
||||
` projections.idps_jwt_config.keys_endpoint,`+
|
||||
` projections.idps_jwt_config.header_name,`+
|
||||
` projections.idps_jwt_config.endpoint,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.idps`+
|
||||
` LEFT JOIN zitadel.projections.idps_oidc_config ON zitadel.projections.idps.id = zitadel.projections.idps_oidc_config.idp_id`+
|
||||
` LEFT JOIN zitadel.projections.idps_jwt_config ON zitadel.projections.idps.id = zitadel.projections.idps_jwt_config.idp_id`),
|
||||
` FROM projections.idps`+
|
||||
` LEFT JOIN projections.idps_oidc_config ON projections.idps.id = projections.idps_oidc_config.idp_id`+
|
||||
` LEFT JOIN projections.idps_jwt_config ON projections.idps.id = projections.idps_jwt_config.idp_id`),
|
||||
[]string{
|
||||
"id",
|
||||
"resource_owner",
|
||||
@@ -614,34 +615,34 @@ func Test_IDPPrepares(t *testing.T) {
|
||||
prepare: prepareIDPsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.idps.id,`+
|
||||
` zitadel.projections.idps.resource_owner,`+
|
||||
` zitadel.projections.idps.creation_date,`+
|
||||
` zitadel.projections.idps.change_date,`+
|
||||
` zitadel.projections.idps.sequence,`+
|
||||
` zitadel.projections.idps.state,`+
|
||||
` zitadel.projections.idps.name,`+
|
||||
` zitadel.projections.idps.styling_type,`+
|
||||
` zitadel.projections.idps.owner_type,`+
|
||||
` zitadel.projections.idps.auto_register,`+
|
||||
` zitadel.projections.idps_oidc_config.idp_id,`+
|
||||
` zitadel.projections.idps_oidc_config.client_id,`+
|
||||
` zitadel.projections.idps_oidc_config.client_secret,`+
|
||||
` zitadel.projections.idps_oidc_config.issuer,`+
|
||||
` zitadel.projections.idps_oidc_config.scopes,`+
|
||||
` zitadel.projections.idps_oidc_config.display_name_mapping,`+
|
||||
` zitadel.projections.idps_oidc_config.username_mapping,`+
|
||||
` zitadel.projections.idps_oidc_config.authorization_endpoint,`+
|
||||
` zitadel.projections.idps_oidc_config.token_endpoint,`+
|
||||
` zitadel.projections.idps_jwt_config.idp_id,`+
|
||||
` zitadel.projections.idps_jwt_config.issuer,`+
|
||||
` zitadel.projections.idps_jwt_config.keys_endpoint,`+
|
||||
` zitadel.projections.idps_jwt_config.header_name,`+
|
||||
` zitadel.projections.idps_jwt_config.endpoint,`+
|
||||
regexp.QuoteMeta(`SELECT projections.idps.id,`+
|
||||
` projections.idps.resource_owner,`+
|
||||
` projections.idps.creation_date,`+
|
||||
` projections.idps.change_date,`+
|
||||
` projections.idps.sequence,`+
|
||||
` projections.idps.state,`+
|
||||
` projections.idps.name,`+
|
||||
` projections.idps.styling_type,`+
|
||||
` projections.idps.owner_type,`+
|
||||
` projections.idps.auto_register,`+
|
||||
` projections.idps_oidc_config.idp_id,`+
|
||||
` projections.idps_oidc_config.client_id,`+
|
||||
` projections.idps_oidc_config.client_secret,`+
|
||||
` projections.idps_oidc_config.issuer,`+
|
||||
` projections.idps_oidc_config.scopes,`+
|
||||
` projections.idps_oidc_config.display_name_mapping,`+
|
||||
` projections.idps_oidc_config.username_mapping,`+
|
||||
` projections.idps_oidc_config.authorization_endpoint,`+
|
||||
` projections.idps_oidc_config.token_endpoint,`+
|
||||
` projections.idps_jwt_config.idp_id,`+
|
||||
` projections.idps_jwt_config.issuer,`+
|
||||
` projections.idps_jwt_config.keys_endpoint,`+
|
||||
` projections.idps_jwt_config.header_name,`+
|
||||
` projections.idps_jwt_config.endpoint,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.idps`+
|
||||
` LEFT JOIN zitadel.projections.idps_oidc_config ON zitadel.projections.idps.id = zitadel.projections.idps_oidc_config.idp_id`+
|
||||
` LEFT JOIN zitadel.projections.idps_jwt_config ON zitadel.projections.idps.id = zitadel.projections.idps_jwt_config.idp_id`),
|
||||
` FROM projections.idps`+
|
||||
` LEFT JOIN projections.idps_oidc_config ON projections.idps.id = projections.idps_oidc_config.idp_id`+
|
||||
` LEFT JOIN projections.idps_jwt_config ON projections.idps.id = projections.idps_jwt_config.idp_id`),
|
||||
[]string{
|
||||
"id",
|
||||
"resource_owner",
|
||||
@@ -734,34 +735,34 @@ func Test_IDPPrepares(t *testing.T) {
|
||||
prepare: prepareIDPsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.idps.id,`+
|
||||
` zitadel.projections.idps.resource_owner,`+
|
||||
` zitadel.projections.idps.creation_date,`+
|
||||
` zitadel.projections.idps.change_date,`+
|
||||
` zitadel.projections.idps.sequence,`+
|
||||
` zitadel.projections.idps.state,`+
|
||||
` zitadel.projections.idps.name,`+
|
||||
` zitadel.projections.idps.styling_type,`+
|
||||
` zitadel.projections.idps.owner_type,`+
|
||||
` zitadel.projections.idps.auto_register,`+
|
||||
` zitadel.projections.idps_oidc_config.idp_id,`+
|
||||
` zitadel.projections.idps_oidc_config.client_id,`+
|
||||
` zitadel.projections.idps_oidc_config.client_secret,`+
|
||||
` zitadel.projections.idps_oidc_config.issuer,`+
|
||||
` zitadel.projections.idps_oidc_config.scopes,`+
|
||||
` zitadel.projections.idps_oidc_config.display_name_mapping,`+
|
||||
` zitadel.projections.idps_oidc_config.username_mapping,`+
|
||||
` zitadel.projections.idps_oidc_config.authorization_endpoint,`+
|
||||
` zitadel.projections.idps_oidc_config.token_endpoint,`+
|
||||
` zitadel.projections.idps_jwt_config.idp_id,`+
|
||||
` zitadel.projections.idps_jwt_config.issuer,`+
|
||||
` zitadel.projections.idps_jwt_config.keys_endpoint,`+
|
||||
` zitadel.projections.idps_jwt_config.header_name,`+
|
||||
` zitadel.projections.idps_jwt_config.endpoint,`+
|
||||
regexp.QuoteMeta(`SELECT projections.idps.id,`+
|
||||
` projections.idps.resource_owner,`+
|
||||
` projections.idps.creation_date,`+
|
||||
` projections.idps.change_date,`+
|
||||
` projections.idps.sequence,`+
|
||||
` projections.idps.state,`+
|
||||
` projections.idps.name,`+
|
||||
` projections.idps.styling_type,`+
|
||||
` projections.idps.owner_type,`+
|
||||
` projections.idps.auto_register,`+
|
||||
` projections.idps_oidc_config.idp_id,`+
|
||||
` projections.idps_oidc_config.client_id,`+
|
||||
` projections.idps_oidc_config.client_secret,`+
|
||||
` projections.idps_oidc_config.issuer,`+
|
||||
` projections.idps_oidc_config.scopes,`+
|
||||
` projections.idps_oidc_config.display_name_mapping,`+
|
||||
` projections.idps_oidc_config.username_mapping,`+
|
||||
` projections.idps_oidc_config.authorization_endpoint,`+
|
||||
` projections.idps_oidc_config.token_endpoint,`+
|
||||
` projections.idps_jwt_config.idp_id,`+
|
||||
` projections.idps_jwt_config.issuer,`+
|
||||
` projections.idps_jwt_config.keys_endpoint,`+
|
||||
` projections.idps_jwt_config.header_name,`+
|
||||
` projections.idps_jwt_config.endpoint,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.idps`+
|
||||
` LEFT JOIN zitadel.projections.idps_oidc_config ON zitadel.projections.idps.id = zitadel.projections.idps_oidc_config.idp_id`+
|
||||
` LEFT JOIN zitadel.projections.idps_jwt_config ON zitadel.projections.idps.id = zitadel.projections.idps_jwt_config.idp_id`),
|
||||
` FROM projections.idps`+
|
||||
` LEFT JOIN projections.idps_oidc_config ON projections.idps.id = projections.idps_oidc_config.idp_id`+
|
||||
` LEFT JOIN projections.idps_jwt_config ON projections.idps.id = projections.idps_jwt_config.idp_id`),
|
||||
[]string{
|
||||
"id",
|
||||
"resource_owner",
|
||||
@@ -847,34 +848,34 @@ func Test_IDPPrepares(t *testing.T) {
|
||||
prepare: prepareIDPsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.idps.id,`+
|
||||
` zitadel.projections.idps.resource_owner,`+
|
||||
` zitadel.projections.idps.creation_date,`+
|
||||
` zitadel.projections.idps.change_date,`+
|
||||
` zitadel.projections.idps.sequence,`+
|
||||
` zitadel.projections.idps.state,`+
|
||||
` zitadel.projections.idps.name,`+
|
||||
` zitadel.projections.idps.styling_type,`+
|
||||
` zitadel.projections.idps.owner_type,`+
|
||||
` zitadel.projections.idps.auto_register,`+
|
||||
` zitadel.projections.idps_oidc_config.idp_id,`+
|
||||
` zitadel.projections.idps_oidc_config.client_id,`+
|
||||
` zitadel.projections.idps_oidc_config.client_secret,`+
|
||||
` zitadel.projections.idps_oidc_config.issuer,`+
|
||||
` zitadel.projections.idps_oidc_config.scopes,`+
|
||||
` zitadel.projections.idps_oidc_config.display_name_mapping,`+
|
||||
` zitadel.projections.idps_oidc_config.username_mapping,`+
|
||||
` zitadel.projections.idps_oidc_config.authorization_endpoint,`+
|
||||
` zitadel.projections.idps_oidc_config.token_endpoint,`+
|
||||
` zitadel.projections.idps_jwt_config.idp_id,`+
|
||||
` zitadel.projections.idps_jwt_config.issuer,`+
|
||||
` zitadel.projections.idps_jwt_config.keys_endpoint,`+
|
||||
` zitadel.projections.idps_jwt_config.header_name,`+
|
||||
` zitadel.projections.idps_jwt_config.endpoint,`+
|
||||
regexp.QuoteMeta(`SELECT projections.idps.id,`+
|
||||
` projections.idps.resource_owner,`+
|
||||
` projections.idps.creation_date,`+
|
||||
` projections.idps.change_date,`+
|
||||
` projections.idps.sequence,`+
|
||||
` projections.idps.state,`+
|
||||
` projections.idps.name,`+
|
||||
` projections.idps.styling_type,`+
|
||||
` projections.idps.owner_type,`+
|
||||
` projections.idps.auto_register,`+
|
||||
` projections.idps_oidc_config.idp_id,`+
|
||||
` projections.idps_oidc_config.client_id,`+
|
||||
` projections.idps_oidc_config.client_secret,`+
|
||||
` projections.idps_oidc_config.issuer,`+
|
||||
` projections.idps_oidc_config.scopes,`+
|
||||
` projections.idps_oidc_config.display_name_mapping,`+
|
||||
` projections.idps_oidc_config.username_mapping,`+
|
||||
` projections.idps_oidc_config.authorization_endpoint,`+
|
||||
` projections.idps_oidc_config.token_endpoint,`+
|
||||
` projections.idps_jwt_config.idp_id,`+
|
||||
` projections.idps_jwt_config.issuer,`+
|
||||
` projections.idps_jwt_config.keys_endpoint,`+
|
||||
` projections.idps_jwt_config.header_name,`+
|
||||
` projections.idps_jwt_config.endpoint,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.idps`+
|
||||
` LEFT JOIN zitadel.projections.idps_oidc_config ON zitadel.projections.idps.id = zitadel.projections.idps_oidc_config.idp_id`+
|
||||
` LEFT JOIN zitadel.projections.idps_jwt_config ON zitadel.projections.idps.id = zitadel.projections.idps_jwt_config.idp_id`),
|
||||
` FROM projections.idps`+
|
||||
` LEFT JOIN projections.idps_oidc_config ON projections.idps.id = projections.idps_oidc_config.idp_id`+
|
||||
` LEFT JOIN projections.idps_jwt_config ON projections.idps.id = projections.idps_jwt_config.idp_id`),
|
||||
[]string{
|
||||
"id",
|
||||
"resource_owner",
|
||||
@@ -1058,34 +1059,34 @@ func Test_IDPPrepares(t *testing.T) {
|
||||
prepare: prepareIDPsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.idps.id,`+
|
||||
` zitadel.projections.idps.resource_owner,`+
|
||||
` zitadel.projections.idps.creation_date,`+
|
||||
` zitadel.projections.idps.change_date,`+
|
||||
` zitadel.projections.idps.sequence,`+
|
||||
` zitadel.projections.idps.state,`+
|
||||
` zitadel.projections.idps.name,`+
|
||||
` zitadel.projections.idps.styling_type,`+
|
||||
` zitadel.projections.idps.owner_type,`+
|
||||
` zitadel.projections.idps.auto_register,`+
|
||||
` zitadel.projections.idps_oidc_config.idp_id,`+
|
||||
` zitadel.projections.idps_oidc_config.client_id,`+
|
||||
` zitadel.projections.idps_oidc_config.client_secret,`+
|
||||
` zitadel.projections.idps_oidc_config.issuer,`+
|
||||
` zitadel.projections.idps_oidc_config.scopes,`+
|
||||
` zitadel.projections.idps_oidc_config.display_name_mapping,`+
|
||||
` zitadel.projections.idps_oidc_config.username_mapping,`+
|
||||
` zitadel.projections.idps_oidc_config.authorization_endpoint,`+
|
||||
` zitadel.projections.idps_oidc_config.token_endpoint,`+
|
||||
` zitadel.projections.idps_jwt_config.idp_id,`+
|
||||
` zitadel.projections.idps_jwt_config.issuer,`+
|
||||
` zitadel.projections.idps_jwt_config.keys_endpoint,`+
|
||||
` zitadel.projections.idps_jwt_config.header_name,`+
|
||||
` zitadel.projections.idps_jwt_config.endpoint,`+
|
||||
regexp.QuoteMeta(`SELECT projections.idps.id,`+
|
||||
` projections.idps.resource_owner,`+
|
||||
` projections.idps.creation_date,`+
|
||||
` projections.idps.change_date,`+
|
||||
` projections.idps.sequence,`+
|
||||
` projections.idps.state,`+
|
||||
` projections.idps.name,`+
|
||||
` projections.idps.styling_type,`+
|
||||
` projections.idps.owner_type,`+
|
||||
` projections.idps.auto_register,`+
|
||||
` projections.idps_oidc_config.idp_id,`+
|
||||
` projections.idps_oidc_config.client_id,`+
|
||||
` projections.idps_oidc_config.client_secret,`+
|
||||
` projections.idps_oidc_config.issuer,`+
|
||||
` projections.idps_oidc_config.scopes,`+
|
||||
` projections.idps_oidc_config.display_name_mapping,`+
|
||||
` projections.idps_oidc_config.username_mapping,`+
|
||||
` projections.idps_oidc_config.authorization_endpoint,`+
|
||||
` projections.idps_oidc_config.token_endpoint,`+
|
||||
` projections.idps_jwt_config.idp_id,`+
|
||||
` projections.idps_jwt_config.issuer,`+
|
||||
` projections.idps_jwt_config.keys_endpoint,`+
|
||||
` projections.idps_jwt_config.header_name,`+
|
||||
` projections.idps_jwt_config.endpoint,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.idps`+
|
||||
` LEFT JOIN zitadel.projections.idps_oidc_config ON zitadel.projections.idps.id = zitadel.projections.idps_oidc_config.idp_id`+
|
||||
` LEFT JOIN zitadel.projections.idps_jwt_config ON zitadel.projections.idps.id = zitadel.projections.idps_jwt_config.idp_id`),
|
||||
` FROM projections.idps`+
|
||||
` LEFT JOIN projections.idps_oidc_config ON projections.idps.id = projections.idps_oidc_config.idp_id`+
|
||||
` LEFT JOIN projections.idps_jwt_config ON projections.idps.id = projections.idps_jwt_config.idp_id`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
|
||||
@@ -5,6 +5,8 @@ import (
|
||||
"database/sql"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/query/projection"
|
||||
@@ -70,6 +72,10 @@ var (
|
||||
name: projection.IDPUserLinkResourceOwnerCol,
|
||||
table: idpUserLinkTable,
|
||||
}
|
||||
IDPUserLinkInstanceIDCol = Column{
|
||||
name: projection.IDPUserLinkInstanceIDCol,
|
||||
table: idpUserLinkTable,
|
||||
}
|
||||
IDPUserLinkDisplayNameCol = Column{
|
||||
name: projection.IDPUserLinkDisplayNameCol,
|
||||
table: idpUserLinkTable,
|
||||
@@ -78,7 +84,10 @@ var (
|
||||
|
||||
func (q *Queries) IDPUserLinks(ctx context.Context, queries *IDPUserLinksSearchQuery) (idps *IDPUserLinks, err error) {
|
||||
query, scan := prepareIDPUserLinksQuery()
|
||||
stmt, args, err := queries.toQuery(query).ToSql()
|
||||
stmt, args, err := queries.toQuery(query).
|
||||
Where(sq.Eq{
|
||||
IDPUserLinkInstanceIDCol.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInvalidArgument(err, "QUERY-4zzFK", "Errors.Query.InvalidRequest")
|
||||
}
|
||||
|
||||
@@ -12,16 +12,16 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
idpUserLinksQuery = regexp.QuoteMeta(`SELECT zitadel.projections.idp_user_links.idp_id,` +
|
||||
` zitadel.projections.idp_user_links.user_id,` +
|
||||
` zitadel.projections.idps.name,` +
|
||||
` zitadel.projections.idp_user_links.external_user_id,` +
|
||||
` zitadel.projections.idp_user_links.display_name,` +
|
||||
` zitadel.projections.idps.type,` +
|
||||
` zitadel.projections.idp_user_links.resource_owner,` +
|
||||
idpUserLinksQuery = regexp.QuoteMeta(`SELECT projections.idp_user_links.idp_id,` +
|
||||
` projections.idp_user_links.user_id,` +
|
||||
` projections.idps.name,` +
|
||||
` projections.idp_user_links.external_user_id,` +
|
||||
` projections.idp_user_links.display_name,` +
|
||||
` projections.idps.type,` +
|
||||
` projections.idp_user_links.resource_owner,` +
|
||||
` COUNT(*) OVER ()` +
|
||||
` FROM zitadel.projections.idp_user_links` +
|
||||
` LEFT JOIN zitadel.projections.idps ON zitadel.projections.idp_user_links.idp_id = zitadel.projections.idps.id`)
|
||||
` FROM projections.idp_user_links` +
|
||||
` LEFT JOIN projections.idps ON projections.idp_user_links.idp_id = projections.idps.id`)
|
||||
idpUserLinksCols = []string{
|
||||
"idp_id",
|
||||
"user_id",
|
||||
|
||||
+15
-3
@@ -8,6 +8,8 @@ import (
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
|
||||
"github.com/caos/zitadel/internal/crypto"
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
@@ -117,6 +119,10 @@ var (
|
||||
name: projection.KeyColumnResourceOwner,
|
||||
table: keyTable,
|
||||
}
|
||||
KeyColInstanceID = Column{
|
||||
name: projection.KeyColumnInstanceID,
|
||||
table: keyTable,
|
||||
}
|
||||
KeyColSequence = Column{
|
||||
name: projection.KeyColumnSequence,
|
||||
table: keyTable,
|
||||
@@ -173,8 +179,13 @@ func (q *Queries) ActivePublicKeys(ctx context.Context, t time.Time) (*PublicKey
|
||||
t = time.Now()
|
||||
}
|
||||
stmt, args, err := query.Where(
|
||||
sq.Gt{
|
||||
KeyPublicColExpiry.identifier(): t,
|
||||
sq.And{
|
||||
sq.Eq{
|
||||
KeyColInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
},
|
||||
sq.Gt{
|
||||
KeyPublicColExpiry.identifier(): t,
|
||||
},
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "QUERY-SDFfg", "Errors.Query.SQLStatement")
|
||||
@@ -200,7 +211,8 @@ func (q *Queries) ActivePrivateSigningKey(ctx context.Context, t time.Time) (*Pr
|
||||
query, args, err := stmt.Where(
|
||||
sq.And{
|
||||
sq.Eq{
|
||||
KeyColUse.identifier(): domain.KeyUsageSigning,
|
||||
KeyColUse.identifier(): domain.KeyUsageSigning,
|
||||
KeyColInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
},
|
||||
sq.Gt{
|
||||
KeyPrivateColExpiry.identifier(): t,
|
||||
|
||||
+66
-66
@@ -31,18 +31,18 @@ func Test_KeyPrepares(t *testing.T) {
|
||||
prepare: preparePublicKeysQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.keys.id,`+
|
||||
` zitadel.projections.keys.creation_date,`+
|
||||
` zitadel.projections.keys.change_date,`+
|
||||
` zitadel.projections.keys.sequence,`+
|
||||
` zitadel.projections.keys.resource_owner,`+
|
||||
` zitadel.projections.keys.algorithm,`+
|
||||
` zitadel.projections.keys.use,`+
|
||||
` zitadel.projections.keys_public.expiry,`+
|
||||
` zitadel.projections.keys_public.key,`+
|
||||
regexp.QuoteMeta(`SELECT projections.keys.id,`+
|
||||
` projections.keys.creation_date,`+
|
||||
` projections.keys.change_date,`+
|
||||
` projections.keys.sequence,`+
|
||||
` projections.keys.resource_owner,`+
|
||||
` projections.keys.algorithm,`+
|
||||
` projections.keys.use,`+
|
||||
` projections.keys_public.expiry,`+
|
||||
` projections.keys_public.key,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.keys`+
|
||||
` LEFT JOIN zitadel.projections.keys_public ON zitadel.projections.keys.id = zitadel.projections.keys_public.id`),
|
||||
` FROM projections.keys`+
|
||||
` LEFT JOIN projections.keys_public ON projections.keys.id = projections.keys_public.id`),
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -60,18 +60,18 @@ func Test_KeyPrepares(t *testing.T) {
|
||||
prepare: preparePublicKeysQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.keys.id,`+
|
||||
` zitadel.projections.keys.creation_date,`+
|
||||
` zitadel.projections.keys.change_date,`+
|
||||
` zitadel.projections.keys.sequence,`+
|
||||
` zitadel.projections.keys.resource_owner,`+
|
||||
` zitadel.projections.keys.algorithm,`+
|
||||
` zitadel.projections.keys.use,`+
|
||||
` zitadel.projections.keys_public.expiry,`+
|
||||
` zitadel.projections.keys_public.key,`+
|
||||
regexp.QuoteMeta(`SELECT projections.keys.id,`+
|
||||
` projections.keys.creation_date,`+
|
||||
` projections.keys.change_date,`+
|
||||
` projections.keys.sequence,`+
|
||||
` projections.keys.resource_owner,`+
|
||||
` projections.keys.algorithm,`+
|
||||
` projections.keys.use,`+
|
||||
` projections.keys_public.expiry,`+
|
||||
` projections.keys_public.key,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.keys`+
|
||||
` LEFT JOIN zitadel.projections.keys_public ON zitadel.projections.keys.id = zitadel.projections.keys_public.id`),
|
||||
` FROM projections.keys`+
|
||||
` LEFT JOIN projections.keys_public ON projections.keys.id = projections.keys_public.id`),
|
||||
[]string{
|
||||
"id",
|
||||
"creation_date",
|
||||
@@ -128,18 +128,18 @@ func Test_KeyPrepares(t *testing.T) {
|
||||
prepare: preparePublicKeysQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.keys.id,`+
|
||||
` zitadel.projections.keys.creation_date,`+
|
||||
` zitadel.projections.keys.change_date,`+
|
||||
` zitadel.projections.keys.sequence,`+
|
||||
` zitadel.projections.keys.resource_owner,`+
|
||||
` zitadel.projections.keys.algorithm,`+
|
||||
` zitadel.projections.keys.use,`+
|
||||
` zitadel.projections.keys_public.expiry,`+
|
||||
` zitadel.projections.keys_public.key,`+
|
||||
regexp.QuoteMeta(`SELECT projections.keys.id,`+
|
||||
` projections.keys.creation_date,`+
|
||||
` projections.keys.change_date,`+
|
||||
` projections.keys.sequence,`+
|
||||
` projections.keys.resource_owner,`+
|
||||
` projections.keys.algorithm,`+
|
||||
` projections.keys.use,`+
|
||||
` projections.keys_public.expiry,`+
|
||||
` projections.keys_public.key,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.keys`+
|
||||
` LEFT JOIN zitadel.projections.keys_public ON zitadel.projections.keys.id = zitadel.projections.keys_public.id`),
|
||||
` FROM projections.keys`+
|
||||
` LEFT JOIN projections.keys_public ON projections.keys.id = projections.keys_public.id`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
@@ -156,18 +156,18 @@ func Test_KeyPrepares(t *testing.T) {
|
||||
prepare: preparePrivateKeysQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.keys.id,`+
|
||||
` zitadel.projections.keys.creation_date,`+
|
||||
` zitadel.projections.keys.change_date,`+
|
||||
` zitadel.projections.keys.sequence,`+
|
||||
` zitadel.projections.keys.resource_owner,`+
|
||||
` zitadel.projections.keys.algorithm,`+
|
||||
` zitadel.projections.keys.use,`+
|
||||
` zitadel.projections.keys_private.expiry,`+
|
||||
` zitadel.projections.keys_private.key,`+
|
||||
regexp.QuoteMeta(`SELECT projections.keys.id,`+
|
||||
` projections.keys.creation_date,`+
|
||||
` projections.keys.change_date,`+
|
||||
` projections.keys.sequence,`+
|
||||
` projections.keys.resource_owner,`+
|
||||
` projections.keys.algorithm,`+
|
||||
` projections.keys.use,`+
|
||||
` projections.keys_private.expiry,`+
|
||||
` projections.keys_private.key,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.keys`+
|
||||
` LEFT JOIN zitadel.projections.keys_private ON zitadel.projections.keys.id = zitadel.projections.keys_private.id`),
|
||||
` FROM projections.keys`+
|
||||
` LEFT JOIN projections.keys_private ON projections.keys.id = projections.keys_private.id`),
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -185,18 +185,18 @@ func Test_KeyPrepares(t *testing.T) {
|
||||
prepare: preparePrivateKeysQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.keys.id,`+
|
||||
` zitadel.projections.keys.creation_date,`+
|
||||
` zitadel.projections.keys.change_date,`+
|
||||
` zitadel.projections.keys.sequence,`+
|
||||
` zitadel.projections.keys.resource_owner,`+
|
||||
` zitadel.projections.keys.algorithm,`+
|
||||
` zitadel.projections.keys.use,`+
|
||||
` zitadel.projections.keys_private.expiry,`+
|
||||
` zitadel.projections.keys_private.key,`+
|
||||
regexp.QuoteMeta(`SELECT projections.keys.id,`+
|
||||
` projections.keys.creation_date,`+
|
||||
` projections.keys.change_date,`+
|
||||
` projections.keys.sequence,`+
|
||||
` projections.keys.resource_owner,`+
|
||||
` projections.keys.algorithm,`+
|
||||
` projections.keys.use,`+
|
||||
` projections.keys_private.expiry,`+
|
||||
` projections.keys_private.key,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.keys`+
|
||||
` LEFT JOIN zitadel.projections.keys_private ON zitadel.projections.keys.id = zitadel.projections.keys_private.id`),
|
||||
` FROM projections.keys`+
|
||||
` LEFT JOIN projections.keys_private ON projections.keys.id = projections.keys_private.id`),
|
||||
[]string{
|
||||
"id",
|
||||
"creation_date",
|
||||
@@ -255,18 +255,18 @@ func Test_KeyPrepares(t *testing.T) {
|
||||
prepare: preparePrivateKeysQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.keys.id,`+
|
||||
` zitadel.projections.keys.creation_date,`+
|
||||
` zitadel.projections.keys.change_date,`+
|
||||
` zitadel.projections.keys.sequence,`+
|
||||
` zitadel.projections.keys.resource_owner,`+
|
||||
` zitadel.projections.keys.algorithm,`+
|
||||
` zitadel.projections.keys.use,`+
|
||||
` zitadel.projections.keys_private.expiry,`+
|
||||
` zitadel.projections.keys_private.key,`+
|
||||
regexp.QuoteMeta(`SELECT projections.keys.id,`+
|
||||
` projections.keys.creation_date,`+
|
||||
` projections.keys.change_date,`+
|
||||
` projections.keys.sequence,`+
|
||||
` projections.keys.resource_owner,`+
|
||||
` projections.keys.algorithm,`+
|
||||
` projections.keys.use,`+
|
||||
` projections.keys_private.expiry,`+
|
||||
` projections.keys_private.key,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.keys`+
|
||||
` LEFT JOIN zitadel.projections.keys_private ON zitadel.projections.keys.id = zitadel.projections.keys_private.id`),
|
||||
` FROM projections.keys`+
|
||||
` LEFT JOIN projections.keys_private ON projections.keys.id = projections.keys_private.id`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
"time"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/query/projection"
|
||||
@@ -51,7 +53,8 @@ func (q *Queries) ActiveLabelPolicyByOrg(ctx context.Context, orgID string) (*La
|
||||
},
|
||||
},
|
||||
sq.Eq{
|
||||
LabelPolicyColState.identifier(): domain.LabelPolicyStateActive,
|
||||
LabelPolicyColState.identifier(): domain.LabelPolicyStateActive,
|
||||
LabelPolicyColInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
},
|
||||
}).
|
||||
OrderBy(LabelPolicyColIsDefault.identifier()).
|
||||
@@ -77,7 +80,8 @@ func (q *Queries) PreviewLabelPolicyByOrg(ctx context.Context, orgID string) (*L
|
||||
},
|
||||
},
|
||||
sq.Eq{
|
||||
LabelPolicyColState.identifier(): domain.LabelPolicyStatePreview,
|
||||
LabelPolicyColState.identifier(): domain.LabelPolicyStatePreview,
|
||||
LabelPolicyColInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
},
|
||||
}).
|
||||
OrderBy(LabelPolicyColIsDefault.identifier()).
|
||||
@@ -93,8 +97,9 @@ func (q *Queries) PreviewLabelPolicyByOrg(ctx context.Context, orgID string) (*L
|
||||
func (q *Queries) DefaultActiveLabelPolicy(ctx context.Context) (*LabelPolicy, error) {
|
||||
stmt, scan := prepareLabelPolicyQuery()
|
||||
query, args, err := stmt.Where(sq.Eq{
|
||||
LabelPolicyColID.identifier(): domain.IAMID,
|
||||
LabelPolicyColState.identifier(): domain.LabelPolicyStateActive,
|
||||
LabelPolicyColID.identifier(): domain.IAMID,
|
||||
LabelPolicyColState.identifier(): domain.LabelPolicyStateActive,
|
||||
LabelPolicyColInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).
|
||||
OrderBy(LabelPolicyColIsDefault.identifier()).
|
||||
Limit(1).ToSql()
|
||||
@@ -109,8 +114,9 @@ func (q *Queries) DefaultActiveLabelPolicy(ctx context.Context) (*LabelPolicy, e
|
||||
func (q *Queries) DefaultPreviewLabelPolicy(ctx context.Context) (*LabelPolicy, error) {
|
||||
stmt, scan := prepareLabelPolicyQuery()
|
||||
query, args, err := stmt.Where(sq.Eq{
|
||||
LabelPolicyColID.identifier(): domain.IAMID,
|
||||
LabelPolicyColState.identifier(): domain.LabelPolicyStatePreview,
|
||||
LabelPolicyColID.identifier(): domain.IAMID,
|
||||
LabelPolicyColState.identifier(): domain.LabelPolicyStatePreview,
|
||||
LabelPolicyColInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).
|
||||
OrderBy(LabelPolicyColIsDefault.identifier()).
|
||||
Limit(1).ToSql()
|
||||
@@ -147,6 +153,9 @@ var (
|
||||
LabelPolicyColResourceOwner = Column{
|
||||
name: projection.LabelPolicyResourceOwnerCol,
|
||||
}
|
||||
LabelPolicyColInstanceID = Column{
|
||||
name: projection.LabelPolicyInstanceIDCol,
|
||||
}
|
||||
LabelPolicyColHideLoginNameSuffix = Column{
|
||||
name: projection.LabelPolicyHideLoginNameSuffixCol,
|
||||
}
|
||||
|
||||
@@ -7,6 +7,9 @@ import (
|
||||
"time"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/query/projection"
|
||||
@@ -34,6 +37,10 @@ var (
|
||||
name: projection.LockoutPolicyIDCol,
|
||||
table: lockoutTable,
|
||||
}
|
||||
LockoutColInstanceID = Column{
|
||||
name: projection.LockoutPolicyInstanceIDCol,
|
||||
table: lockoutTable,
|
||||
}
|
||||
LockoutColSequence = Column{
|
||||
name: projection.LockoutPolicySequenceCol,
|
||||
table: lockoutTable,
|
||||
@@ -71,12 +78,17 @@ var (
|
||||
func (q *Queries) LockoutPolicyByOrg(ctx context.Context, orgID string) (*LockoutPolicy, error) {
|
||||
stmt, scan := prepareLockoutPolicyQuery()
|
||||
query, args, err := stmt.Where(
|
||||
sq.Or{
|
||||
sq.And{
|
||||
sq.Eq{
|
||||
LockoutColID.identifier(): orgID,
|
||||
LockoutColInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
},
|
||||
sq.Eq{
|
||||
LockoutColID.identifier(): domain.IAMID,
|
||||
sq.Or{
|
||||
sq.Eq{
|
||||
LockoutColID.identifier(): orgID,
|
||||
},
|
||||
sq.Eq{
|
||||
LockoutColID.identifier(): domain.IAMID,
|
||||
},
|
||||
},
|
||||
}).
|
||||
OrderBy(LockoutColIsDefault.identifier()).
|
||||
@@ -92,7 +104,8 @@ func (q *Queries) LockoutPolicyByOrg(ctx context.Context, orgID string) (*Lockou
|
||||
func (q *Queries) DefaultLockoutPolicy(ctx context.Context) (*LockoutPolicy, error) {
|
||||
stmt, scan := prepareLockoutPolicyQuery()
|
||||
query, args, err := stmt.Where(sq.Eq{
|
||||
LockoutColID.identifier(): domain.IAMID,
|
||||
LockoutColID.identifier(): domain.IAMID,
|
||||
LockoutColInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).
|
||||
OrderBy(LockoutColIsDefault.identifier()).
|
||||
Limit(1).ToSql()
|
||||
|
||||
@@ -28,16 +28,16 @@ func Test_LockoutPolicyPrepares(t *testing.T) {
|
||||
prepare: prepareLockoutPolicyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.lockout_policies.id,`+
|
||||
` zitadel.projections.lockout_policies.sequence,`+
|
||||
` zitadel.projections.lockout_policies.creation_date,`+
|
||||
` zitadel.projections.lockout_policies.change_date,`+
|
||||
` zitadel.projections.lockout_policies.resource_owner,`+
|
||||
` zitadel.projections.lockout_policies.show_failure,`+
|
||||
` zitadel.projections.lockout_policies.max_password_attempts,`+
|
||||
` zitadel.projections.lockout_policies.is_default,`+
|
||||
` zitadel.projections.lockout_policies.state`+
|
||||
` FROM zitadel.projections.lockout_policies`),
|
||||
regexp.QuoteMeta(`SELECT projections.lockout_policies.id,`+
|
||||
` projections.lockout_policies.sequence,`+
|
||||
` projections.lockout_policies.creation_date,`+
|
||||
` projections.lockout_policies.change_date,`+
|
||||
` projections.lockout_policies.resource_owner,`+
|
||||
` projections.lockout_policies.show_failure,`+
|
||||
` projections.lockout_policies.max_password_attempts,`+
|
||||
` projections.lockout_policies.is_default,`+
|
||||
` projections.lockout_policies.state`+
|
||||
` FROM projections.lockout_policies`),
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -55,16 +55,16 @@ func Test_LockoutPolicyPrepares(t *testing.T) {
|
||||
prepare: prepareLockoutPolicyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.lockout_policies.id,`+
|
||||
` zitadel.projections.lockout_policies.sequence,`+
|
||||
` zitadel.projections.lockout_policies.creation_date,`+
|
||||
` zitadel.projections.lockout_policies.change_date,`+
|
||||
` zitadel.projections.lockout_policies.resource_owner,`+
|
||||
` zitadel.projections.lockout_policies.show_failure,`+
|
||||
` zitadel.projections.lockout_policies.max_password_attempts,`+
|
||||
` zitadel.projections.lockout_policies.is_default,`+
|
||||
` zitadel.projections.lockout_policies.state`+
|
||||
` FROM zitadel.projections.lockout_policies`),
|
||||
regexp.QuoteMeta(`SELECT projections.lockout_policies.id,`+
|
||||
` projections.lockout_policies.sequence,`+
|
||||
` projections.lockout_policies.creation_date,`+
|
||||
` projections.lockout_policies.change_date,`+
|
||||
` projections.lockout_policies.resource_owner,`+
|
||||
` projections.lockout_policies.show_failure,`+
|
||||
` projections.lockout_policies.max_password_attempts,`+
|
||||
` projections.lockout_policies.is_default,`+
|
||||
` projections.lockout_policies.state`+
|
||||
` FROM projections.lockout_policies`),
|
||||
[]string{
|
||||
"id",
|
||||
"sequence",
|
||||
@@ -106,16 +106,16 @@ func Test_LockoutPolicyPrepares(t *testing.T) {
|
||||
prepare: prepareLockoutPolicyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.lockout_policies.id,`+
|
||||
` zitadel.projections.lockout_policies.sequence,`+
|
||||
` zitadel.projections.lockout_policies.creation_date,`+
|
||||
` zitadel.projections.lockout_policies.change_date,`+
|
||||
` zitadel.projections.lockout_policies.resource_owner,`+
|
||||
` zitadel.projections.lockout_policies.show_failure,`+
|
||||
` zitadel.projections.lockout_policies.max_password_attempts,`+
|
||||
` zitadel.projections.lockout_policies.is_default,`+
|
||||
` zitadel.projections.lockout_policies.state`+
|
||||
` FROM zitadel.projections.lockout_policies`),
|
||||
regexp.QuoteMeta(`SELECT projections.lockout_policies.id,`+
|
||||
` projections.lockout_policies.sequence,`+
|
||||
` projections.lockout_policies.creation_date,`+
|
||||
` projections.lockout_policies.change_date,`+
|
||||
` projections.lockout_policies.resource_owner,`+
|
||||
` projections.lockout_policies.show_failure,`+
|
||||
` projections.lockout_policies.max_password_attempts,`+
|
||||
` projections.lockout_policies.is_default,`+
|
||||
` projections.lockout_policies.state`+
|
||||
` FROM projections.lockout_policies`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
|
||||
@@ -18,4 +18,8 @@ var (
|
||||
name: projection.LoginNameDomainIsPrimaryCol,
|
||||
table: loginNameTable,
|
||||
}
|
||||
LoginNameInstanceIDCol = Column{
|
||||
name: projection.LoginNameUserInstanceIDCol,
|
||||
table: loginNameTable,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -7,10 +7,13 @@ import (
|
||||
"time"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
"github.com/lib/pq"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/query/projection"
|
||||
"github.com/lib/pq"
|
||||
)
|
||||
|
||||
type LoginPolicy struct {
|
||||
@@ -52,6 +55,10 @@ var (
|
||||
name: projection.LoginPolicyIDCol,
|
||||
table: loginPolicyTable,
|
||||
}
|
||||
LoginPolicyColumnInstanceID = Column{
|
||||
name: projection.LoginPolicyInstanceIDCol,
|
||||
table: loginPolicyTable,
|
||||
}
|
||||
LoginPolicyColumnCreationDate = Column{
|
||||
name: projection.LoginPolicyCreationDateCol,
|
||||
table: loginPolicyTable,
|
||||
@@ -125,12 +132,17 @@ var (
|
||||
func (q *Queries) LoginPolicyByID(ctx context.Context, orgID string) (*LoginPolicy, error) {
|
||||
query, scan := prepareLoginPolicyQuery()
|
||||
stmt, args, err := query.Where(
|
||||
sq.Or{
|
||||
sq.And{
|
||||
sq.Eq{
|
||||
LoginPolicyColumnOrgID.identifier(): orgID,
|
||||
LoginPolicyColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
},
|
||||
sq.Eq{
|
||||
LoginPolicyColumnOrgID.identifier(): domain.IAMID,
|
||||
sq.Or{
|
||||
sq.Eq{
|
||||
LoginPolicyColumnOrgID.identifier(): orgID,
|
||||
},
|
||||
sq.Eq{
|
||||
LoginPolicyColumnOrgID.identifier(): domain.IAMID,
|
||||
},
|
||||
},
|
||||
}).
|
||||
OrderBy(LoginPolicyColumnIsDefault.identifier()).
|
||||
@@ -146,7 +158,8 @@ func (q *Queries) LoginPolicyByID(ctx context.Context, orgID string) (*LoginPoli
|
||||
func (q *Queries) DefaultLoginPolicy(ctx context.Context) (*LoginPolicy, error) {
|
||||
query, scan := prepareLoginPolicyQuery()
|
||||
stmt, args, err := query.Where(sq.Eq{
|
||||
LoginPolicyColumnOrgID.identifier(): domain.IAMID,
|
||||
LoginPolicyColumnOrgID.identifier(): domain.IAMID,
|
||||
LoginPolicyColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).OrderBy(LoginPolicyColumnIsDefault.identifier()).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "QUERY-t4TBK", "Errors.Query.SQLStatement")
|
||||
@@ -159,12 +172,17 @@ func (q *Queries) DefaultLoginPolicy(ctx context.Context) (*LoginPolicy, error)
|
||||
func (q *Queries) SecondFactorsByOrg(ctx context.Context, orgID string) (*SecondFactors, error) {
|
||||
query, scan := prepareLoginPolicy2FAsQuery()
|
||||
stmt, args, err := query.Where(
|
||||
sq.Or{
|
||||
sq.And{
|
||||
sq.Eq{
|
||||
LoginPolicyColumnOrgID.identifier(): orgID,
|
||||
LoginPolicyColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
},
|
||||
sq.Eq{
|
||||
LoginPolicyColumnOrgID.identifier(): domain.IAMID,
|
||||
sq.Or{
|
||||
sq.Eq{
|
||||
LoginPolicyColumnOrgID.identifier(): orgID,
|
||||
},
|
||||
sq.Eq{
|
||||
LoginPolicyColumnOrgID.identifier(): domain.IAMID,
|
||||
},
|
||||
},
|
||||
}).
|
||||
OrderBy(LoginPolicyColumnIsDefault.identifier()).
|
||||
@@ -185,7 +203,8 @@ func (q *Queries) SecondFactorsByOrg(ctx context.Context, orgID string) (*Second
|
||||
func (q *Queries) DefaultSecondFactors(ctx context.Context) (*SecondFactors, error) {
|
||||
query, scan := prepareLoginPolicy2FAsQuery()
|
||||
stmt, args, err := query.Where(sq.Eq{
|
||||
LoginPolicyColumnOrgID.identifier(): domain.IAMID,
|
||||
LoginPolicyColumnOrgID.identifier(): domain.IAMID,
|
||||
LoginPolicyColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).OrderBy(LoginPolicyColumnIsDefault.identifier()).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "QUERY-CZ2Nv", "Errors.Query.SQLStatement")
|
||||
@@ -203,12 +222,17 @@ func (q *Queries) DefaultSecondFactors(ctx context.Context) (*SecondFactors, err
|
||||
func (q *Queries) MultiFactorsByOrg(ctx context.Context, orgID string) (*MultiFactors, error) {
|
||||
query, scan := prepareLoginPolicyMFAsQuery()
|
||||
stmt, args, err := query.Where(
|
||||
sq.Or{
|
||||
sq.And{
|
||||
sq.Eq{
|
||||
LoginPolicyColumnOrgID.identifier(): orgID,
|
||||
LoginPolicyColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
},
|
||||
sq.Eq{
|
||||
LoginPolicyColumnOrgID.identifier(): domain.IAMID,
|
||||
sq.Or{
|
||||
sq.Eq{
|
||||
LoginPolicyColumnOrgID.identifier(): orgID,
|
||||
},
|
||||
sq.Eq{
|
||||
LoginPolicyColumnOrgID.identifier(): domain.IAMID,
|
||||
},
|
||||
},
|
||||
}).
|
||||
OrderBy(LoginPolicyColumnIsDefault.identifier()).
|
||||
@@ -229,7 +253,8 @@ func (q *Queries) MultiFactorsByOrg(ctx context.Context, orgID string) (*MultiFa
|
||||
func (q *Queries) DefaultMultiFactors(ctx context.Context) (*MultiFactors, error) {
|
||||
query, scan := prepareLoginPolicyMFAsQuery()
|
||||
stmt, args, err := query.Where(sq.Eq{
|
||||
LoginPolicyColumnOrgID.identifier(): domain.IAMID,
|
||||
LoginPolicyColumnOrgID.identifier(): domain.IAMID,
|
||||
LoginPolicyColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).OrderBy(LoginPolicyColumnIsDefault.identifier()).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "QUERY-WxYjr", "Errors.Query.SQLStatement")
|
||||
|
||||
@@ -9,9 +9,10 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/lib/pq"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/lib/pq"
|
||||
)
|
||||
|
||||
func Test_LoginPolicyPrepares(t *testing.T) {
|
||||
@@ -30,25 +31,25 @@ func Test_LoginPolicyPrepares(t *testing.T) {
|
||||
prepare: prepareLoginPolicyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.login_policies.aggregate_id,`+
|
||||
` zitadel.projections.login_policies.creation_date,`+
|
||||
` zitadel.projections.login_policies.change_date,`+
|
||||
` zitadel.projections.login_policies.sequence,`+
|
||||
` zitadel.projections.login_policies.allow_register,`+
|
||||
` zitadel.projections.login_policies.allow_username_password,`+
|
||||
` zitadel.projections.login_policies.allow_external_idps,`+
|
||||
` zitadel.projections.login_policies.force_mfa,`+
|
||||
` zitadel.projections.login_policies.second_factors,`+
|
||||
` zitadel.projections.login_policies.multi_factors,`+
|
||||
` zitadel.projections.login_policies.passwordless_type,`+
|
||||
` zitadel.projections.login_policies.is_default,`+
|
||||
` zitadel.projections.login_policies.hide_password_reset,`+
|
||||
` zitadel.projections.login_policies.password_check_lifetime,`+
|
||||
` zitadel.projections.login_policies.external_login_check_lifetime,`+
|
||||
` zitadel.projections.login_policies.mfa_init_skip_lifetime,`+
|
||||
` zitadel.projections.login_policies.second_factor_check_lifetime,`+
|
||||
` zitadel.projections.login_policies.multi_factor_check_lifetime`+
|
||||
` FROM zitadel.projections.login_policies`),
|
||||
regexp.QuoteMeta(`SELECT projections.login_policies.aggregate_id,`+
|
||||
` projections.login_policies.creation_date,`+
|
||||
` projections.login_policies.change_date,`+
|
||||
` projections.login_policies.sequence,`+
|
||||
` projections.login_policies.allow_register,`+
|
||||
` projections.login_policies.allow_username_password,`+
|
||||
` projections.login_policies.allow_external_idps,`+
|
||||
` projections.login_policies.force_mfa,`+
|
||||
` projections.login_policies.second_factors,`+
|
||||
` projections.login_policies.multi_factors,`+
|
||||
` projections.login_policies.passwordless_type,`+
|
||||
` projections.login_policies.is_default,`+
|
||||
` projections.login_policies.hide_password_reset,`+
|
||||
` projections.login_policies.password_check_lifetime,`+
|
||||
` projections.login_policies.external_login_check_lifetime,`+
|
||||
` projections.login_policies.mfa_init_skip_lifetime,`+
|
||||
` projections.login_policies.second_factor_check_lifetime,`+
|
||||
` projections.login_policies.multi_factor_check_lifetime`+
|
||||
` FROM projections.login_policies`),
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -66,25 +67,25 @@ func Test_LoginPolicyPrepares(t *testing.T) {
|
||||
prepare: prepareLoginPolicyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.login_policies.aggregate_id,`+
|
||||
` zitadel.projections.login_policies.creation_date,`+
|
||||
` zitadel.projections.login_policies.change_date,`+
|
||||
` zitadel.projections.login_policies.sequence,`+
|
||||
` zitadel.projections.login_policies.allow_register,`+
|
||||
` zitadel.projections.login_policies.allow_username_password,`+
|
||||
` zitadel.projections.login_policies.allow_external_idps,`+
|
||||
` zitadel.projections.login_policies.force_mfa,`+
|
||||
` zitadel.projections.login_policies.second_factors,`+
|
||||
` zitadel.projections.login_policies.multi_factors,`+
|
||||
` zitadel.projections.login_policies.passwordless_type,`+
|
||||
` zitadel.projections.login_policies.is_default,`+
|
||||
` zitadel.projections.login_policies.hide_password_reset,`+
|
||||
` zitadel.projections.login_policies.password_check_lifetime,`+
|
||||
` zitadel.projections.login_policies.external_login_check_lifetime,`+
|
||||
` zitadel.projections.login_policies.mfa_init_skip_lifetime,`+
|
||||
` zitadel.projections.login_policies.second_factor_check_lifetime,`+
|
||||
` zitadel.projections.login_policies.multi_factor_check_lifetime`+
|
||||
` FROM zitadel.projections.login_policies`),
|
||||
regexp.QuoteMeta(`SELECT projections.login_policies.aggregate_id,`+
|
||||
` projections.login_policies.creation_date,`+
|
||||
` projections.login_policies.change_date,`+
|
||||
` projections.login_policies.sequence,`+
|
||||
` projections.login_policies.allow_register,`+
|
||||
` projections.login_policies.allow_username_password,`+
|
||||
` projections.login_policies.allow_external_idps,`+
|
||||
` projections.login_policies.force_mfa,`+
|
||||
` projections.login_policies.second_factors,`+
|
||||
` projections.login_policies.multi_factors,`+
|
||||
` projections.login_policies.passwordless_type,`+
|
||||
` projections.login_policies.is_default,`+
|
||||
` projections.login_policies.hide_password_reset,`+
|
||||
` projections.login_policies.password_check_lifetime,`+
|
||||
` projections.login_policies.external_login_check_lifetime,`+
|
||||
` projections.login_policies.mfa_init_skip_lifetime,`+
|
||||
` projections.login_policies.second_factor_check_lifetime,`+
|
||||
` projections.login_policies.multi_factor_check_lifetime`+
|
||||
` FROM projections.login_policies`),
|
||||
[]string{
|
||||
"aggregate_id",
|
||||
"creation_date",
|
||||
@@ -153,25 +154,25 @@ func Test_LoginPolicyPrepares(t *testing.T) {
|
||||
prepare: prepareLoginPolicyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.login_policies.aggregate_id,`+
|
||||
` zitadel.projections.login_policies.creation_date,`+
|
||||
` zitadel.projections.login_policies.change_date,`+
|
||||
` zitadel.projections.login_policies.sequence,`+
|
||||
` zitadel.projections.login_policies.allow_register,`+
|
||||
` zitadel.projections.login_policies.allow_username_password,`+
|
||||
` zitadel.projections.login_policies.allow_external_idps,`+
|
||||
` zitadel.projections.login_policies.force_mfa,`+
|
||||
` zitadel.projections.login_policies.second_factors,`+
|
||||
` zitadel.projections.login_policies.multi_factors,`+
|
||||
` zitadel.projections.login_policies.passwordless_type,`+
|
||||
` zitadel.projections.login_policies.is_default,`+
|
||||
` zitadel.projections.login_policies.hide_password_reset,`+
|
||||
` zitadel.projections.login_policies.password_check_lifetime,`+
|
||||
` zitadel.projections.login_policies.external_login_check_lifetime,`+
|
||||
` zitadel.projections.login_policies.mfa_init_skip_lifetime,`+
|
||||
` zitadel.projections.login_policies.second_factor_check_lifetime,`+
|
||||
` zitadel.projections.login_policies.multi_factor_check_lifetime`+
|
||||
` FROM zitadel.projections.login_policies`),
|
||||
regexp.QuoteMeta(`SELECT projections.login_policies.aggregate_id,`+
|
||||
` projections.login_policies.creation_date,`+
|
||||
` projections.login_policies.change_date,`+
|
||||
` projections.login_policies.sequence,`+
|
||||
` projections.login_policies.allow_register,`+
|
||||
` projections.login_policies.allow_username_password,`+
|
||||
` projections.login_policies.allow_external_idps,`+
|
||||
` projections.login_policies.force_mfa,`+
|
||||
` projections.login_policies.second_factors,`+
|
||||
` projections.login_policies.multi_factors,`+
|
||||
` projections.login_policies.passwordless_type,`+
|
||||
` projections.login_policies.is_default,`+
|
||||
` projections.login_policies.hide_password_reset,`+
|
||||
` projections.login_policies.password_check_lifetime,`+
|
||||
` projections.login_policies.external_login_check_lifetime,`+
|
||||
` projections.login_policies.mfa_init_skip_lifetime,`+
|
||||
` projections.login_policies.second_factor_check_lifetime,`+
|
||||
` projections.login_policies.multi_factor_check_lifetime`+
|
||||
` FROM projections.login_policies`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
@@ -188,8 +189,8 @@ func Test_LoginPolicyPrepares(t *testing.T) {
|
||||
prepare: prepareLoginPolicy2FAsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.login_policies.second_factors`+
|
||||
` FROM zitadel.projections.login_policies`),
|
||||
regexp.QuoteMeta(`SELECT projections.login_policies.second_factors`+
|
||||
` FROM projections.login_policies`),
|
||||
[]string{
|
||||
"second_factors",
|
||||
},
|
||||
@@ -209,8 +210,8 @@ func Test_LoginPolicyPrepares(t *testing.T) {
|
||||
prepare: prepareLoginPolicy2FAsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.login_policies.second_factors`+
|
||||
` FROM zitadel.projections.login_policies`),
|
||||
regexp.QuoteMeta(`SELECT projections.login_policies.second_factors`+
|
||||
` FROM projections.login_policies`),
|
||||
[]string{
|
||||
"second_factors",
|
||||
},
|
||||
@@ -231,8 +232,8 @@ func Test_LoginPolicyPrepares(t *testing.T) {
|
||||
prepare: prepareLoginPolicy2FAsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.login_policies.second_factors`+
|
||||
` FROM zitadel.projections.login_policies`),
|
||||
regexp.QuoteMeta(`SELECT projections.login_policies.second_factors`+
|
||||
` FROM projections.login_policies`),
|
||||
[]string{
|
||||
"second_factors",
|
||||
},
|
||||
@@ -248,8 +249,8 @@ func Test_LoginPolicyPrepares(t *testing.T) {
|
||||
prepare: prepareLoginPolicy2FAsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.login_policies.second_factors`+
|
||||
` FROM zitadel.projections.login_policies`),
|
||||
regexp.QuoteMeta(`SELECT projections.login_policies.second_factors`+
|
||||
` FROM projections.login_policies`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
@@ -267,8 +268,8 @@ func Test_LoginPolicyPrepares(t *testing.T) {
|
||||
prepare: prepareLoginPolicyMFAsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.login_policies.multi_factors`+
|
||||
` FROM zitadel.projections.login_policies`),
|
||||
regexp.QuoteMeta(`SELECT projections.login_policies.multi_factors`+
|
||||
` FROM projections.login_policies`),
|
||||
[]string{
|
||||
"multi_factors",
|
||||
},
|
||||
@@ -288,8 +289,8 @@ func Test_LoginPolicyPrepares(t *testing.T) {
|
||||
prepare: prepareLoginPolicyMFAsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.login_policies.multi_factors`+
|
||||
` FROM zitadel.projections.login_policies`),
|
||||
regexp.QuoteMeta(`SELECT projections.login_policies.multi_factors`+
|
||||
` FROM projections.login_policies`),
|
||||
[]string{
|
||||
"multi_factors",
|
||||
},
|
||||
@@ -310,8 +311,8 @@ func Test_LoginPolicyPrepares(t *testing.T) {
|
||||
prepare: prepareLoginPolicyMFAsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.login_policies.multi_factors`+
|
||||
` FROM zitadel.projections.login_policies`),
|
||||
regexp.QuoteMeta(`SELECT projections.login_policies.multi_factors`+
|
||||
` FROM projections.login_policies`),
|
||||
[]string{
|
||||
"multi_factors",
|
||||
},
|
||||
@@ -327,8 +328,8 @@ func Test_LoginPolicyPrepares(t *testing.T) {
|
||||
prepare: prepareLoginPolicyMFAsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.login_policies.multi_factors`+
|
||||
` FROM zitadel.projections.login_policies`),
|
||||
regexp.QuoteMeta(`SELECT projections.login_policies.multi_factors`+
|
||||
` FROM projections.login_policies`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
"time"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/query/projection"
|
||||
@@ -31,6 +33,10 @@ var (
|
||||
name: projection.MailTemplateAggregateIDCol,
|
||||
table: mailTemplateTable,
|
||||
}
|
||||
MailTemplateColInstanceID = Column{
|
||||
name: projection.MailTemplateInstanceIDCol,
|
||||
table: mailTemplateTable,
|
||||
}
|
||||
MailTemplateColSequence = Column{
|
||||
name: projection.MailTemplateSequenceCol,
|
||||
table: mailTemplateTable,
|
||||
@@ -60,12 +66,17 @@ var (
|
||||
func (q *Queries) MailTemplateByOrg(ctx context.Context, orgID string) (*MailTemplate, error) {
|
||||
stmt, scan := prepareMailTemplateQuery()
|
||||
query, args, err := stmt.Where(
|
||||
sq.Or{
|
||||
sq.And{
|
||||
sq.Eq{
|
||||
MailTemplateColAggregateID.identifier(): orgID,
|
||||
MailTemplateColInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
},
|
||||
sq.Eq{
|
||||
MailTemplateColAggregateID.identifier(): domain.IAMID,
|
||||
sq.Or{
|
||||
sq.Eq{
|
||||
MailTemplateColAggregateID.identifier(): orgID,
|
||||
},
|
||||
sq.Eq{
|
||||
MailTemplateColAggregateID.identifier(): domain.IAMID,
|
||||
},
|
||||
},
|
||||
}).
|
||||
OrderBy(MailTemplateColIsDefault.identifier()).
|
||||
@@ -82,6 +93,7 @@ func (q *Queries) DefaultMailTemplate(ctx context.Context) (*MailTemplate, error
|
||||
stmt, scan := prepareMailTemplateQuery()
|
||||
query, args, err := stmt.Where(sq.Eq{
|
||||
MailTemplateColAggregateID.identifier(): domain.IAMID,
|
||||
MailTemplateColInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).
|
||||
OrderBy(MailTemplateColIsDefault.identifier()).
|
||||
Limit(1).ToSql()
|
||||
|
||||
@@ -32,7 +32,7 @@ func (q *Queries) GetOrgMemberRoles(isGlobal bool) []string {
|
||||
}
|
||||
|
||||
func (q *Queries) GetProjectMemberRoles(ctx context.Context) ([]string, error) {
|
||||
iam, err := q.IAMByID(ctx, domain.IAMID)
|
||||
iam, err := q.IAM(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ import (
|
||||
"golang.org/x/text/language"
|
||||
"sigs.k8s.io/yaml"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/query/projection"
|
||||
@@ -57,6 +59,10 @@ var (
|
||||
name: projection.MessageTextAggregateIDCol,
|
||||
table: messageTextTable,
|
||||
}
|
||||
MessageTextColInstanceID = Column{
|
||||
name: projection.MessageTextInstanceIDCol,
|
||||
table: messageTextTable,
|
||||
}
|
||||
MessageTextColSequence = Column{
|
||||
name: projection.MessageTextSequenceCol,
|
||||
table: messageTextTable,
|
||||
@@ -114,12 +120,17 @@ var (
|
||||
func (q *Queries) MessageTextByOrg(ctx context.Context, orgID string) (*MessageText, error) {
|
||||
stmt, scan := prepareMessageTextQuery()
|
||||
query, args, err := stmt.Where(
|
||||
sq.Or{
|
||||
sq.And{
|
||||
sq.Eq{
|
||||
MessageTextColAggregateID.identifier(): orgID,
|
||||
MessageTextColInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
},
|
||||
sq.Eq{
|
||||
MessageTextColAggregateID.identifier(): domain.IAMID,
|
||||
sq.Or{
|
||||
sq.Eq{
|
||||
MessageTextColAggregateID.identifier(): orgID,
|
||||
},
|
||||
sq.Eq{
|
||||
MessageTextColAggregateID.identifier(): domain.IAMID,
|
||||
},
|
||||
},
|
||||
}).
|
||||
OrderBy(MessageTextColAggregateID.identifier()).
|
||||
@@ -136,6 +147,7 @@ func (q *Queries) DefaultMessageText(ctx context.Context) (*MessageText, error)
|
||||
stmt, scan := prepareMessageTextQuery()
|
||||
query, args, err := stmt.Where(sq.Eq{
|
||||
MessageTextColAggregateID.identifier(): domain.IAMID,
|
||||
MessageTextColInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).
|
||||
Limit(1).ToSql()
|
||||
if err != nil {
|
||||
@@ -161,16 +173,11 @@ func (q *Queries) DefaultMessageTextByTypeAndLanguageFromFileSystem(messageType,
|
||||
func (q *Queries) CustomMessageTextByTypeAndLanguage(ctx context.Context, aggregateID, messageType, language string) (*MessageText, error) {
|
||||
stmt, scan := prepareMessageTextQuery()
|
||||
query, args, err := stmt.Where(
|
||||
sq.And{
|
||||
sq.Eq{
|
||||
MessageTextColLanguage.identifier(): language,
|
||||
},
|
||||
sq.Eq{
|
||||
MessageTextColType.identifier(): messageType,
|
||||
},
|
||||
sq.Eq{
|
||||
MessageTextColAggregateID.identifier(): aggregateID,
|
||||
},
|
||||
sq.Eq{
|
||||
MessageTextColLanguage.identifier(): language,
|
||||
MessageTextColType.identifier(): messageType,
|
||||
MessageTextColAggregateID.identifier(): aggregateID,
|
||||
MessageTextColInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
},
|
||||
).
|
||||
OrderBy(MessageTextColAggregateID.identifier()).
|
||||
|
||||
@@ -8,9 +8,10 @@ import (
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/text/language"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
errs "github.com/caos/zitadel/internal/errors"
|
||||
"golang.org/x/text/language"
|
||||
)
|
||||
|
||||
func Test_MessageTextPrepares(t *testing.T) {
|
||||
@@ -29,21 +30,21 @@ func Test_MessageTextPrepares(t *testing.T) {
|
||||
prepare: prepareMessageTextQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.message_texts.aggregate_id,`+
|
||||
` zitadel.projections.message_texts.sequence,`+
|
||||
` zitadel.projections.message_texts.creation_date,`+
|
||||
` zitadel.projections.message_texts.change_date,`+
|
||||
` zitadel.projections.message_texts.state,`+
|
||||
` zitadel.projections.message_texts.type,`+
|
||||
` zitadel.projections.message_texts.language,`+
|
||||
` zitadel.projections.message_texts.title,`+
|
||||
` zitadel.projections.message_texts.pre_header,`+
|
||||
` zitadel.projections.message_texts.subject,`+
|
||||
` zitadel.projections.message_texts.greeting,`+
|
||||
` zitadel.projections.message_texts.text,`+
|
||||
` zitadel.projections.message_texts.button_text,`+
|
||||
` zitadel.projections.message_texts.footer_text`+
|
||||
` FROM zitadel.projections.message_texts`),
|
||||
regexp.QuoteMeta(`SELECT projections.message_texts.aggregate_id,`+
|
||||
` projections.message_texts.sequence,`+
|
||||
` projections.message_texts.creation_date,`+
|
||||
` projections.message_texts.change_date,`+
|
||||
` projections.message_texts.state,`+
|
||||
` projections.message_texts.type,`+
|
||||
` projections.message_texts.language,`+
|
||||
` projections.message_texts.title,`+
|
||||
` projections.message_texts.pre_header,`+
|
||||
` projections.message_texts.subject,`+
|
||||
` projections.message_texts.greeting,`+
|
||||
` projections.message_texts.text,`+
|
||||
` projections.message_texts.button_text,`+
|
||||
` projections.message_texts.footer_text`+
|
||||
` FROM projections.message_texts`),
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -61,21 +62,21 @@ func Test_MessageTextPrepares(t *testing.T) {
|
||||
prepare: prepareMessageTextQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.message_texts.aggregate_id,`+
|
||||
` zitadel.projections.message_texts.sequence,`+
|
||||
` zitadel.projections.message_texts.creation_date,`+
|
||||
` zitadel.projections.message_texts.change_date,`+
|
||||
` zitadel.projections.message_texts.state,`+
|
||||
` zitadel.projections.message_texts.type,`+
|
||||
` zitadel.projections.message_texts.language,`+
|
||||
` zitadel.projections.message_texts.title,`+
|
||||
` zitadel.projections.message_texts.pre_header,`+
|
||||
` zitadel.projections.message_texts.subject,`+
|
||||
` zitadel.projections.message_texts.greeting,`+
|
||||
` zitadel.projections.message_texts.text,`+
|
||||
` zitadel.projections.message_texts.button_text,`+
|
||||
` zitadel.projections.message_texts.footer_text`+
|
||||
` FROM zitadel.projections.message_texts`),
|
||||
regexp.QuoteMeta(`SELECT projections.message_texts.aggregate_id,`+
|
||||
` projections.message_texts.sequence,`+
|
||||
` projections.message_texts.creation_date,`+
|
||||
` projections.message_texts.change_date,`+
|
||||
` projections.message_texts.state,`+
|
||||
` projections.message_texts.type,`+
|
||||
` projections.message_texts.language,`+
|
||||
` projections.message_texts.title,`+
|
||||
` projections.message_texts.pre_header,`+
|
||||
` projections.message_texts.subject,`+
|
||||
` projections.message_texts.greeting,`+
|
||||
` projections.message_texts.text,`+
|
||||
` projections.message_texts.button_text,`+
|
||||
` projections.message_texts.footer_text`+
|
||||
` FROM projections.message_texts`),
|
||||
[]string{
|
||||
"aggregate_id",
|
||||
"sequence",
|
||||
@@ -132,21 +133,21 @@ func Test_MessageTextPrepares(t *testing.T) {
|
||||
prepare: prepareMessageTextQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.message_texts.aggregate_id,`+
|
||||
` zitadel.projections.message_texts.sequence,`+
|
||||
` zitadel.projections.message_texts.creation_date,`+
|
||||
` zitadel.projections.message_texts.change_date,`+
|
||||
` zitadel.projections.message_texts.state,`+
|
||||
` zitadel.projections.message_texts.type,`+
|
||||
` zitadel.projections.message_texts.language,`+
|
||||
` zitadel.projections.message_texts.title,`+
|
||||
` zitadel.projections.message_texts.pre_header,`+
|
||||
` zitadel.projections.message_texts.subject,`+
|
||||
` zitadel.projections.message_texts.greeting,`+
|
||||
` zitadel.projections.message_texts.text,`+
|
||||
` zitadel.projections.message_texts.button_text,`+
|
||||
` zitadel.projections.message_texts.footer_text`+
|
||||
` FROM zitadel.projections.message_texts`),
|
||||
regexp.QuoteMeta(`SELECT projections.message_texts.aggregate_id,`+
|
||||
` projections.message_texts.sequence,`+
|
||||
` projections.message_texts.creation_date,`+
|
||||
` projections.message_texts.change_date,`+
|
||||
` projections.message_texts.state,`+
|
||||
` projections.message_texts.type,`+
|
||||
` projections.message_texts.language,`+
|
||||
` projections.message_texts.title,`+
|
||||
` projections.message_texts.pre_header,`+
|
||||
` projections.message_texts.subject,`+
|
||||
` projections.message_texts.greeting,`+
|
||||
` projections.message_texts.text,`+
|
||||
` projections.message_texts.button_text,`+
|
||||
` projections.message_texts.footer_text`+
|
||||
` FROM projections.message_texts`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
|
||||
@@ -7,6 +7,9 @@ import (
|
||||
"time"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/query/projection"
|
||||
@@ -47,6 +50,10 @@ var (
|
||||
name: projection.DebugNotificationProviderResourceOwnerCol,
|
||||
table: notificationProviderTable,
|
||||
}
|
||||
NotificationProviderColumnInstanceID = Column{
|
||||
name: projection.DebugNotificationProviderInstanceIDCol,
|
||||
table: notificationProviderTable,
|
||||
}
|
||||
NotificationProviderColumnState = Column{
|
||||
name: projection.DebugNotificationProviderStateCol,
|
||||
table: notificationProviderTable,
|
||||
@@ -64,9 +71,15 @@ var (
|
||||
func (q *Queries) NotificationProviderByIDAndType(ctx context.Context, aggID string, providerType domain.NotificationProviderType) (*DebugNotificationProvider, error) {
|
||||
query, scan := prepareDebugNotificationProviderQuery()
|
||||
stmt, args, err := query.Where(
|
||||
sq.Or{
|
||||
sq.And{
|
||||
sq.Eq{
|
||||
LoginPolicyColumnOrgID.identifier(): aggID,
|
||||
NotificationProviderColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
},
|
||||
sq.Or{
|
||||
sq.Eq{
|
||||
NotificationProviderColumnAggID.identifier(): aggID,
|
||||
NotificationProviderColumnType.identifier(): providerType,
|
||||
},
|
||||
},
|
||||
}).
|
||||
Limit(1).ToSql()
|
||||
|
||||
@@ -28,15 +28,15 @@ func Test_NotificationProviderPrepares(t *testing.T) {
|
||||
prepare: prepareDebugNotificationProviderQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.notification_providers.aggregate_id,`+
|
||||
` zitadel.projections.notification_providers.creation_date,`+
|
||||
` zitadel.projections.notification_providers.change_date,`+
|
||||
` zitadel.projections.notification_providers.sequence,`+
|
||||
` zitadel.projections.notification_providers.resource_owner,`+
|
||||
` zitadel.projections.notification_providers.state,`+
|
||||
` zitadel.projections.notification_providers.provider_type,`+
|
||||
` zitadel.projections.notification_providers.compact`+
|
||||
` FROM zitadel.projections.notification_providers`),
|
||||
regexp.QuoteMeta(`SELECT projections.notification_providers.aggregate_id,`+
|
||||
` projections.notification_providers.creation_date,`+
|
||||
` projections.notification_providers.change_date,`+
|
||||
` projections.notification_providers.sequence,`+
|
||||
` projections.notification_providers.resource_owner,`+
|
||||
` projections.notification_providers.state,`+
|
||||
` projections.notification_providers.provider_type,`+
|
||||
` projections.notification_providers.compact`+
|
||||
` FROM projections.notification_providers`),
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -54,15 +54,15 @@ func Test_NotificationProviderPrepares(t *testing.T) {
|
||||
prepare: prepareDebugNotificationProviderQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.notification_providers.aggregate_id,`+
|
||||
` zitadel.projections.notification_providers.creation_date,`+
|
||||
` zitadel.projections.notification_providers.change_date,`+
|
||||
` zitadel.projections.notification_providers.sequence,`+
|
||||
` zitadel.projections.notification_providers.resource_owner,`+
|
||||
` zitadel.projections.notification_providers.state,`+
|
||||
` zitadel.projections.notification_providers.provider_type,`+
|
||||
` zitadel.projections.notification_providers.compact`+
|
||||
` FROM zitadel.projections.notification_providers`),
|
||||
regexp.QuoteMeta(`SELECT projections.notification_providers.aggregate_id,`+
|
||||
` projections.notification_providers.creation_date,`+
|
||||
` projections.notification_providers.change_date,`+
|
||||
` projections.notification_providers.sequence,`+
|
||||
` projections.notification_providers.resource_owner,`+
|
||||
` projections.notification_providers.state,`+
|
||||
` projections.notification_providers.provider_type,`+
|
||||
` projections.notification_providers.compact`+
|
||||
` FROM projections.notification_providers`),
|
||||
[]string{
|
||||
"aggregate_id",
|
||||
"creation_date",
|
||||
@@ -101,15 +101,15 @@ func Test_NotificationProviderPrepares(t *testing.T) {
|
||||
prepare: prepareDebugNotificationProviderQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.notification_providers.aggregate_id,`+
|
||||
` zitadel.projections.notification_providers.creation_date,`+
|
||||
` zitadel.projections.notification_providers.change_date,`+
|
||||
` zitadel.projections.notification_providers.sequence,`+
|
||||
` zitadel.projections.notification_providers.resource_owner,`+
|
||||
` zitadel.projections.notification_providers.state,`+
|
||||
` zitadel.projections.notification_providers.provider_type,`+
|
||||
` zitadel.projections.notification_providers.compact`+
|
||||
` FROM zitadel.projections.notification_providers`),
|
||||
regexp.QuoteMeta(`SELECT projections.notification_providers.aggregate_id,`+
|
||||
` projections.notification_providers.creation_date,`+
|
||||
` projections.notification_providers.change_date,`+
|
||||
` projections.notification_providers.sequence,`+
|
||||
` projections.notification_providers.resource_owner,`+
|
||||
` projections.notification_providers.state,`+
|
||||
` projections.notification_providers.provider_type,`+
|
||||
` projections.notification_providers.compact`+
|
||||
` FROM projections.notification_providers`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
"time"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/query/projection"
|
||||
)
|
||||
@@ -31,6 +33,10 @@ var (
|
||||
name: projection.OIDCSettingsColumnResourceOwner,
|
||||
table: oidcSettingsTable,
|
||||
}
|
||||
OIDCSettingsColumnInstanceID = Column{
|
||||
name: projection.OIDCSettingsColumnInstanceID,
|
||||
table: oidcSettingsTable,
|
||||
}
|
||||
OIDCSettingsColumnSequence = Column{
|
||||
name: projection.OIDCSettingsColumnSequence,
|
||||
table: oidcSettingsTable,
|
||||
@@ -70,6 +76,7 @@ func (q *Queries) OIDCSettingsByAggID(ctx context.Context, aggregateID string) (
|
||||
stmt, scan := prepareOIDCSettingsQuery()
|
||||
query, args, err := stmt.Where(sq.Eq{
|
||||
OIDCSettingsColumnAggregateID.identifier(): aggregateID,
|
||||
OIDCSettingsColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "QUERY-s9nle", "Errors.Query.SQLStatment")
|
||||
|
||||
@@ -28,16 +28,16 @@ func Test_OIDCConfigsPrepares(t *testing.T) {
|
||||
prepare: prepareOIDCSettingsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
`SELECT zitadel.projections.oidc_settings.aggregate_id,`+
|
||||
` zitadel.projections.oidc_settings.creation_date,`+
|
||||
` zitadel.projections.oidc_settings.change_date,`+
|
||||
` zitadel.projections.oidc_settings.resource_owner,`+
|
||||
` zitadel.projections.oidc_settings.sequence,`+
|
||||
` zitadel.projections.oidc_settings.access_token_lifetime,`+
|
||||
` zitadel.projections.oidc_settings.id_token_lifetime,`+
|
||||
` zitadel.projections.oidc_settings.refresh_token_idle_expiration,`+
|
||||
` zitadel.projections.oidc_settings.refresh_token_expiration`+
|
||||
` FROM zitadel.projections.oidc_settings`,
|
||||
`SELECT projections.oidc_settings.aggregate_id,`+
|
||||
` projections.oidc_settings.creation_date,`+
|
||||
` projections.oidc_settings.change_date,`+
|
||||
` projections.oidc_settings.resource_owner,`+
|
||||
` projections.oidc_settings.sequence,`+
|
||||
` projections.oidc_settings.access_token_lifetime,`+
|
||||
` projections.oidc_settings.id_token_lifetime,`+
|
||||
` projections.oidc_settings.refresh_token_idle_expiration,`+
|
||||
` projections.oidc_settings.refresh_token_expiration`+
|
||||
` FROM projections.oidc_settings`,
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -55,16 +55,16 @@ func Test_OIDCConfigsPrepares(t *testing.T) {
|
||||
prepare: prepareOIDCSettingsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.oidc_settings.aggregate_id,`+
|
||||
` zitadel.projections.oidc_settings.creation_date,`+
|
||||
` zitadel.projections.oidc_settings.change_date,`+
|
||||
` zitadel.projections.oidc_settings.resource_owner,`+
|
||||
` zitadel.projections.oidc_settings.sequence,`+
|
||||
` zitadel.projections.oidc_settings.access_token_lifetime,`+
|
||||
` zitadel.projections.oidc_settings.id_token_lifetime,`+
|
||||
` zitadel.projections.oidc_settings.refresh_token_idle_expiration,`+
|
||||
` zitadel.projections.oidc_settings.refresh_token_expiration`+
|
||||
` FROM zitadel.projections.oidc_settings`),
|
||||
regexp.QuoteMeta(`SELECT projections.oidc_settings.aggregate_id,`+
|
||||
` projections.oidc_settings.creation_date,`+
|
||||
` projections.oidc_settings.change_date,`+
|
||||
` projections.oidc_settings.resource_owner,`+
|
||||
` projections.oidc_settings.sequence,`+
|
||||
` projections.oidc_settings.access_token_lifetime,`+
|
||||
` projections.oidc_settings.id_token_lifetime,`+
|
||||
` projections.oidc_settings.refresh_token_idle_expiration,`+
|
||||
` projections.oidc_settings.refresh_token_expiration`+
|
||||
` FROM projections.oidc_settings`),
|
||||
[]string{
|
||||
"aggregate_id",
|
||||
"creation_date",
|
||||
@@ -106,16 +106,16 @@ func Test_OIDCConfigsPrepares(t *testing.T) {
|
||||
prepare: prepareOIDCSettingsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.oidc_settings.aggregate_id,`+
|
||||
` zitadel.projections.oidc_settings.creation_date,`+
|
||||
` zitadel.projections.oidc_settings.change_date,`+
|
||||
` zitadel.projections.oidc_settings.resource_owner,`+
|
||||
` zitadel.projections.oidc_settings.sequence,`+
|
||||
` zitadel.projections.oidc_settings.access_token_lifetime,`+
|
||||
` zitadel.projections.oidc_settings.id_token_lifetime,`+
|
||||
` zitadel.projections.oidc_settings.refresh_token_idle_expiration,`+
|
||||
` zitadel.projections.oidc_settings.refresh_token_expiration`+
|
||||
` FROM zitadel.projections.oidc_settings`),
|
||||
regexp.QuoteMeta(`SELECT projections.oidc_settings.aggregate_id,`+
|
||||
` projections.oidc_settings.creation_date,`+
|
||||
` projections.oidc_settings.change_date,`+
|
||||
` projections.oidc_settings.resource_owner,`+
|
||||
` projections.oidc_settings.sequence,`+
|
||||
` projections.oidc_settings.access_token_lifetime,`+
|
||||
` projections.oidc_settings.id_token_lifetime,`+
|
||||
` projections.oidc_settings.refresh_token_idle_expiration,`+
|
||||
` projections.oidc_settings.refresh_token_expiration`+
|
||||
` FROM projections.oidc_settings`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
|
||||
+23
-7
@@ -7,6 +7,8 @@ import (
|
||||
"time"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/query/projection"
|
||||
@@ -32,6 +34,10 @@ var (
|
||||
name: projection.OrgColumnResourceOwner,
|
||||
table: orgsTable,
|
||||
}
|
||||
OrgColumnInstanceID = Column{
|
||||
name: projection.OrgColumnInstanceID,
|
||||
table: orgsTable,
|
||||
}
|
||||
OrgColumnState = Column{
|
||||
name: projection.OrgColumnState,
|
||||
table: orgsTable,
|
||||
@@ -83,7 +89,8 @@ func (q *OrgSearchQueries) toQuery(query sq.SelectBuilder) sq.SelectBuilder {
|
||||
func (q *Queries) OrgByID(ctx context.Context, id string) (*Org, error) {
|
||||
stmt, scan := prepareOrgQuery()
|
||||
query, args, err := stmt.Where(sq.Eq{
|
||||
OrgColumnID.identifier(): id,
|
||||
OrgColumnID.identifier(): id,
|
||||
OrgColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "QUERY-AWx52", "Errors.Query.SQLStatement")
|
||||
@@ -96,7 +103,8 @@ func (q *Queries) OrgByID(ctx context.Context, id string) (*Org, error) {
|
||||
func (q *Queries) OrgByDomainGlobal(ctx context.Context, domain string) (*Org, error) {
|
||||
stmt, scan := prepareOrgQuery()
|
||||
query, args, err := stmt.Where(sq.Eq{
|
||||
OrgColumnDomain.identifier(): domain,
|
||||
OrgColumnDomain.identifier(): domain,
|
||||
OrgColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "QUERY-TYUCE", "Errors.Query.SQLStatement")
|
||||
@@ -109,12 +117,17 @@ func (q *Queries) OrgByDomainGlobal(ctx context.Context, domain string) (*Org, e
|
||||
func (q *Queries) IsOrgUnique(ctx context.Context, name, domain string) (isUnique bool, err error) {
|
||||
query, scan := prepareOrgUniqueQuery()
|
||||
stmt, args, err := query.Where(
|
||||
sq.Or{
|
||||
sq.And{
|
||||
sq.Eq{
|
||||
OrgColumnDomain.identifier(): domain,
|
||||
OrgColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
},
|
||||
sq.Eq{
|
||||
OrgColumnName.identifier(): name,
|
||||
sq.Or{
|
||||
sq.Eq{
|
||||
OrgColumnDomain.identifier(): domain,
|
||||
},
|
||||
sq.Eq{
|
||||
OrgColumnName.identifier(): name,
|
||||
},
|
||||
},
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
@@ -132,7 +145,10 @@ func (q *Queries) ExistsOrg(ctx context.Context, id string) (err error) {
|
||||
|
||||
func (q *Queries) SearchOrgs(ctx context.Context, queries *OrgSearchQueries) (orgs *Orgs, err error) {
|
||||
query, scan := prepareOrgsQuery()
|
||||
stmt, args, err := queries.toQuery(query).ToSql()
|
||||
stmt, args, err := queries.toQuery(query).
|
||||
Where(sq.Eq{
|
||||
OrgColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInvalidArgument(err, "QUERY-wQ3by", "Errors.Query.InvalidRequest")
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import (
|
||||
"time"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/query/projection"
|
||||
@@ -54,7 +56,10 @@ func NewOrgDomainVerifiedSearchQuery(verified bool) (SearchQuery, error) {
|
||||
|
||||
func (q *Queries) SearchOrgDomains(ctx context.Context, queries *OrgDomainSearchQueries) (domains *Domains, err error) {
|
||||
query, scan := prepareDomainsQuery()
|
||||
stmt, args, err := queries.toQuery(query).ToSql()
|
||||
stmt, args, err := queries.toQuery(query).
|
||||
Where(sq.Eq{
|
||||
OrgDomainInstanceIDCol.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInvalidArgument(err, "QUERY-ZRfj1", "Errors.Query.SQLStatement")
|
||||
}
|
||||
@@ -143,6 +148,10 @@ var (
|
||||
name: projection.OrgDomainOrgIDCol,
|
||||
table: orgDomainsTable,
|
||||
}
|
||||
OrgDomainInstanceIDCol = Column{
|
||||
name: projection.OrgDomainInstanceIDCol,
|
||||
table: orgDomainsTable,
|
||||
}
|
||||
OrgDomainIsVerifiedCol = Column{
|
||||
name: projection.OrgDomainIsVerifiedCol,
|
||||
table: orgDomainsTable,
|
||||
|
||||
@@ -27,16 +27,16 @@ func Test_OrgDomainPrepares(t *testing.T) {
|
||||
prepare: prepareDomainsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.org_domains.creation_date,`+
|
||||
` zitadel.projections.org_domains.change_date,`+
|
||||
` zitadel.projections.org_domains.sequence,`+
|
||||
` zitadel.projections.org_domains.domain,`+
|
||||
` zitadel.projections.org_domains.org_id,`+
|
||||
` zitadel.projections.org_domains.is_verified,`+
|
||||
` zitadel.projections.org_domains.is_primary,`+
|
||||
` zitadel.projections.org_domains.validation_type,`+
|
||||
regexp.QuoteMeta(`SELECT projections.org_domains.creation_date,`+
|
||||
` projections.org_domains.change_date,`+
|
||||
` projections.org_domains.sequence,`+
|
||||
` projections.org_domains.domain,`+
|
||||
` projections.org_domains.org_id,`+
|
||||
` projections.org_domains.is_verified,`+
|
||||
` projections.org_domains.is_primary,`+
|
||||
` projections.org_domains.validation_type,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.org_domains`),
|
||||
` FROM projections.org_domains`),
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -48,16 +48,16 @@ func Test_OrgDomainPrepares(t *testing.T) {
|
||||
prepare: prepareDomainsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.org_domains.creation_date,`+
|
||||
` zitadel.projections.org_domains.change_date,`+
|
||||
` zitadel.projections.org_domains.sequence,`+
|
||||
` zitadel.projections.org_domains.domain,`+
|
||||
` zitadel.projections.org_domains.org_id,`+
|
||||
` zitadel.projections.org_domains.is_verified,`+
|
||||
` zitadel.projections.org_domains.is_primary,`+
|
||||
` zitadel.projections.org_domains.validation_type,`+
|
||||
regexp.QuoteMeta(`SELECT projections.org_domains.creation_date,`+
|
||||
` projections.org_domains.change_date,`+
|
||||
` projections.org_domains.sequence,`+
|
||||
` projections.org_domains.domain,`+
|
||||
` projections.org_domains.org_id,`+
|
||||
` projections.org_domains.is_verified,`+
|
||||
` projections.org_domains.is_primary,`+
|
||||
` projections.org_domains.validation_type,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.org_domains`),
|
||||
` FROM projections.org_domains`),
|
||||
[]string{
|
||||
"id",
|
||||
"creation_date",
|
||||
@@ -106,16 +106,16 @@ func Test_OrgDomainPrepares(t *testing.T) {
|
||||
prepare: prepareDomainsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.org_domains.creation_date,`+
|
||||
` zitadel.projections.org_domains.change_date,`+
|
||||
` zitadel.projections.org_domains.sequence,`+
|
||||
` zitadel.projections.org_domains.domain,`+
|
||||
` zitadel.projections.org_domains.org_id,`+
|
||||
` zitadel.projections.org_domains.is_verified,`+
|
||||
` zitadel.projections.org_domains.is_primary,`+
|
||||
` zitadel.projections.org_domains.validation_type,`+
|
||||
regexp.QuoteMeta(`SELECT projections.org_domains.creation_date,`+
|
||||
` projections.org_domains.change_date,`+
|
||||
` projections.org_domains.sequence,`+
|
||||
` projections.org_domains.domain,`+
|
||||
` projections.org_domains.org_id,`+
|
||||
` projections.org_domains.is_verified,`+
|
||||
` projections.org_domains.is_primary,`+
|
||||
` projections.org_domains.validation_type,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.org_domains`),
|
||||
` FROM projections.org_domains`),
|
||||
[]string{
|
||||
"id",
|
||||
"creation_date",
|
||||
@@ -184,16 +184,16 @@ func Test_OrgDomainPrepares(t *testing.T) {
|
||||
prepare: prepareDomainsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.org_domains.creation_date,`+
|
||||
` zitadel.projections.org_domains.change_date,`+
|
||||
` zitadel.projections.org_domains.sequence,`+
|
||||
` zitadel.projections.org_domains.domain,`+
|
||||
` zitadel.projections.org_domains.org_id,`+
|
||||
` zitadel.projections.org_domains.is_verified,`+
|
||||
` zitadel.projections.org_domains.is_primary,`+
|
||||
` zitadel.projections.org_domains.validation_type,`+
|
||||
regexp.QuoteMeta(`SELECT projections.org_domains.creation_date,`+
|
||||
` projections.org_domains.change_date,`+
|
||||
` projections.org_domains.sequence,`+
|
||||
` projections.org_domains.domain,`+
|
||||
` projections.org_domains.org_id,`+
|
||||
` projections.org_domains.is_verified,`+
|
||||
` projections.org_domains.is_primary,`+
|
||||
` projections.org_domains.validation_type,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.org_domains`),
|
||||
` FROM projections.org_domains`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
|
||||
@@ -7,6 +7,9 @@ import (
|
||||
"time"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/query/projection"
|
||||
@@ -49,6 +52,10 @@ var (
|
||||
name: projection.OrgIAMPolicyResourceOwnerCol,
|
||||
table: orgIAMTable,
|
||||
}
|
||||
OrgIAMColInstanceID = Column{
|
||||
name: projection.OrgIAMPolicyInstanceIDCol,
|
||||
table: orgIAMTable,
|
||||
}
|
||||
OrgIAMColUserLoginMustBeDomain = Column{
|
||||
name: projection.OrgIAMPolicyUserLoginMustBeDomainCol,
|
||||
table: orgIAMTable,
|
||||
@@ -66,12 +73,17 @@ var (
|
||||
func (q *Queries) OrgIAMPolicyByOrg(ctx context.Context, orgID string) (*OrgIAMPolicy, error) {
|
||||
stmt, scan := prepareOrgIAMPolicyQuery()
|
||||
query, args, err := stmt.Where(
|
||||
sq.Or{
|
||||
sq.And{
|
||||
sq.Eq{
|
||||
OrgIAMColID.identifier(): orgID,
|
||||
OrgIAMColInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
},
|
||||
sq.Eq{
|
||||
OrgIAMColID.identifier(): domain.IAMID,
|
||||
sq.Or{
|
||||
sq.Eq{
|
||||
OrgIAMColID.identifier(): orgID,
|
||||
},
|
||||
sq.Eq{
|
||||
OrgIAMColID.identifier(): domain.IAMID,
|
||||
},
|
||||
},
|
||||
}).
|
||||
OrderBy(OrgIAMColIsDefault.identifier()).
|
||||
@@ -87,7 +99,8 @@ func (q *Queries) OrgIAMPolicyByOrg(ctx context.Context, orgID string) (*OrgIAMP
|
||||
func (q *Queries) DefaultOrgIAMPolicy(ctx context.Context) (*OrgIAMPolicy, error) {
|
||||
stmt, scan := prepareOrgIAMPolicyQuery()
|
||||
query, args, err := stmt.Where(sq.Eq{
|
||||
OrgIAMColID.identifier(): domain.IAMID,
|
||||
OrgIAMColID.identifier(): domain.IAMID,
|
||||
OrgIAMColInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).
|
||||
OrderBy(OrgIAMColIsDefault.identifier()).
|
||||
Limit(1).ToSql()
|
||||
|
||||
@@ -28,15 +28,15 @@ func Test_OrgIAMPolicyPrepares(t *testing.T) {
|
||||
prepare: prepareOrgIAMPolicyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.org_iam_policies.id,`+
|
||||
` zitadel.projections.org_iam_policies.sequence,`+
|
||||
` zitadel.projections.org_iam_policies.creation_date,`+
|
||||
` zitadel.projections.org_iam_policies.change_date,`+
|
||||
` zitadel.projections.org_iam_policies.resource_owner,`+
|
||||
` zitadel.projections.org_iam_policies.user_login_must_be_domain,`+
|
||||
` zitadel.projections.org_iam_policies.is_default,`+
|
||||
` zitadel.projections.org_iam_policies.state`+
|
||||
` FROM zitadel.projections.org_iam_policies`),
|
||||
regexp.QuoteMeta(`SELECT projections.org_iam_policies.id,`+
|
||||
` projections.org_iam_policies.sequence,`+
|
||||
` projections.org_iam_policies.creation_date,`+
|
||||
` projections.org_iam_policies.change_date,`+
|
||||
` projections.org_iam_policies.resource_owner,`+
|
||||
` projections.org_iam_policies.user_login_must_be_domain,`+
|
||||
` projections.org_iam_policies.is_default,`+
|
||||
` projections.org_iam_policies.state`+
|
||||
` FROM projections.org_iam_policies`),
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -54,15 +54,15 @@ func Test_OrgIAMPolicyPrepares(t *testing.T) {
|
||||
prepare: prepareOrgIAMPolicyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.org_iam_policies.id,`+
|
||||
` zitadel.projections.org_iam_policies.sequence,`+
|
||||
` zitadel.projections.org_iam_policies.creation_date,`+
|
||||
` zitadel.projections.org_iam_policies.change_date,`+
|
||||
` zitadel.projections.org_iam_policies.resource_owner,`+
|
||||
` zitadel.projections.org_iam_policies.user_login_must_be_domain,`+
|
||||
` zitadel.projections.org_iam_policies.is_default,`+
|
||||
` zitadel.projections.org_iam_policies.state`+
|
||||
` FROM zitadel.projections.org_iam_policies`),
|
||||
regexp.QuoteMeta(`SELECT projections.org_iam_policies.id,`+
|
||||
` projections.org_iam_policies.sequence,`+
|
||||
` projections.org_iam_policies.creation_date,`+
|
||||
` projections.org_iam_policies.change_date,`+
|
||||
` projections.org_iam_policies.resource_owner,`+
|
||||
` projections.org_iam_policies.user_login_must_be_domain,`+
|
||||
` projections.org_iam_policies.is_default,`+
|
||||
` projections.org_iam_policies.state`+
|
||||
` FROM projections.org_iam_policies`),
|
||||
[]string{
|
||||
"id",
|
||||
"sequence",
|
||||
@@ -101,15 +101,15 @@ func Test_OrgIAMPolicyPrepares(t *testing.T) {
|
||||
prepare: prepareOrgIAMPolicyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.org_iam_policies.id,`+
|
||||
` zitadel.projections.org_iam_policies.sequence,`+
|
||||
` zitadel.projections.org_iam_policies.creation_date,`+
|
||||
` zitadel.projections.org_iam_policies.change_date,`+
|
||||
` zitadel.projections.org_iam_policies.resource_owner,`+
|
||||
` zitadel.projections.org_iam_policies.user_login_must_be_domain,`+
|
||||
` zitadel.projections.org_iam_policies.is_default,`+
|
||||
` zitadel.projections.org_iam_policies.state`+
|
||||
` FROM zitadel.projections.org_iam_policies`),
|
||||
regexp.QuoteMeta(`SELECT projections.org_iam_policies.id,`+
|
||||
` projections.org_iam_policies.sequence,`+
|
||||
` projections.org_iam_policies.creation_date,`+
|
||||
` projections.org_iam_policies.change_date,`+
|
||||
` projections.org_iam_policies.resource_owner,`+
|
||||
` projections.org_iam_policies.user_login_must_be_domain,`+
|
||||
` projections.org_iam_policies.is_default,`+
|
||||
` projections.org_iam_policies.state`+
|
||||
` FROM projections.org_iam_policies`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/query/projection"
|
||||
|
||||
@@ -40,6 +41,10 @@ var (
|
||||
name: projection.MemberResourceOwner,
|
||||
table: orgMemberTable,
|
||||
}
|
||||
OrgMemberInstanceID = Column{
|
||||
name: projection.MemberInstanceID,
|
||||
table: orgMemberTable,
|
||||
}
|
||||
OrgMemberOrgID = Column{
|
||||
name: projection.OrgMemberOrgIDCol,
|
||||
table: orgMemberTable,
|
||||
@@ -59,7 +64,10 @@ func (q *OrgMembersQuery) toQuery(query sq.SelectBuilder) sq.SelectBuilder {
|
||||
|
||||
func (q *Queries) OrgMembers(ctx context.Context, queries *OrgMembersQuery) (*Members, error) {
|
||||
query, scan := prepareOrgMembersQuery()
|
||||
stmt, args, err := queries.toQuery(query).ToSql()
|
||||
stmt, args, err := queries.toQuery(query).
|
||||
Where(sq.Eq{
|
||||
OrgMemberInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInvalidArgument(err, "QUERY-PDAVB", "Errors.Query.InvalidRequest")
|
||||
}
|
||||
|
||||
@@ -19,22 +19,22 @@ var (
|
||||
", members.resource_owner" +
|
||||
", members.user_id" +
|
||||
", members.roles" +
|
||||
", zitadel.projections.login_names.login_name" +
|
||||
", zitadel.projections.users_humans.email" +
|
||||
", zitadel.projections.users_humans.first_name" +
|
||||
", zitadel.projections.users_humans.last_name" +
|
||||
", zitadel.projections.users_humans.display_name" +
|
||||
", zitadel.projections.users_machines.name" +
|
||||
", zitadel.projections.users_humans.avatar_key" +
|
||||
", projections.login_names.login_name" +
|
||||
", projections.users_humans.email" +
|
||||
", projections.users_humans.first_name" +
|
||||
", projections.users_humans.last_name" +
|
||||
", projections.users_humans.display_name" +
|
||||
", projections.users_machines.name" +
|
||||
", projections.users_humans.avatar_key" +
|
||||
", COUNT(*) OVER () " +
|
||||
"FROM zitadel.projections.org_members as members " +
|
||||
"LEFT JOIN zitadel.projections.users_humans " +
|
||||
"ON members.user_id = zitadel.projections.users_humans.user_id " +
|
||||
"LEFT JOIN zitadel.projections.users_machines " +
|
||||
"ON members.user_id = zitadel.projections.users_machines.user_id " +
|
||||
"LEFT JOIN zitadel.projections.login_names " +
|
||||
"ON members.user_id = zitadel.projections.login_names.user_id " +
|
||||
"WHERE zitadel.projections.login_names.is_primary = $1")
|
||||
"FROM projections.org_members as members " +
|
||||
"LEFT JOIN projections.users_humans " +
|
||||
"ON members.user_id = projections.users_humans.user_id " +
|
||||
"LEFT JOIN projections.users_machines " +
|
||||
"ON members.user_id = projections.users_machines.user_id " +
|
||||
"LEFT JOIN projections.login_names " +
|
||||
"ON members.user_id = projections.login_names.user_id " +
|
||||
"WHERE projections.login_names.is_primary = $1")
|
||||
orgMembersColumns = []string{
|
||||
"creation_date",
|
||||
"change_date",
|
||||
|
||||
+66
-66
@@ -28,16 +28,16 @@ func Test_OrgPrepares(t *testing.T) {
|
||||
prepare: prepareOrgsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.orgs.id,`+
|
||||
` zitadel.projections.orgs.creation_date,`+
|
||||
` zitadel.projections.orgs.change_date,`+
|
||||
` zitadel.projections.orgs.resource_owner,`+
|
||||
` zitadel.projections.orgs.org_state,`+
|
||||
` zitadel.projections.orgs.sequence,`+
|
||||
` zitadel.projections.orgs.name,`+
|
||||
` zitadel.projections.orgs.primary_domain,`+
|
||||
regexp.QuoteMeta(`SELECT projections.orgs.id,`+
|
||||
` projections.orgs.creation_date,`+
|
||||
` projections.orgs.change_date,`+
|
||||
` projections.orgs.resource_owner,`+
|
||||
` projections.orgs.org_state,`+
|
||||
` projections.orgs.sequence,`+
|
||||
` projections.orgs.name,`+
|
||||
` projections.orgs.primary_domain,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.orgs`),
|
||||
` FROM projections.orgs`),
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -49,16 +49,16 @@ func Test_OrgPrepares(t *testing.T) {
|
||||
prepare: prepareOrgsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.orgs.id,`+
|
||||
` zitadel.projections.orgs.creation_date,`+
|
||||
` zitadel.projections.orgs.change_date,`+
|
||||
` zitadel.projections.orgs.resource_owner,`+
|
||||
` zitadel.projections.orgs.org_state,`+
|
||||
` zitadel.projections.orgs.sequence,`+
|
||||
` zitadel.projections.orgs.name,`+
|
||||
` zitadel.projections.orgs.primary_domain,`+
|
||||
regexp.QuoteMeta(`SELECT projections.orgs.id,`+
|
||||
` projections.orgs.creation_date,`+
|
||||
` projections.orgs.change_date,`+
|
||||
` projections.orgs.resource_owner,`+
|
||||
` projections.orgs.org_state,`+
|
||||
` projections.orgs.sequence,`+
|
||||
` projections.orgs.name,`+
|
||||
` projections.orgs.primary_domain,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.orgs`),
|
||||
` FROM projections.orgs`),
|
||||
[]string{
|
||||
"id",
|
||||
"creation_date",
|
||||
@@ -107,16 +107,16 @@ func Test_OrgPrepares(t *testing.T) {
|
||||
prepare: prepareOrgsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.orgs.id,`+
|
||||
` zitadel.projections.orgs.creation_date,`+
|
||||
` zitadel.projections.orgs.change_date,`+
|
||||
` zitadel.projections.orgs.resource_owner,`+
|
||||
` zitadel.projections.orgs.org_state,`+
|
||||
` zitadel.projections.orgs.sequence,`+
|
||||
` zitadel.projections.orgs.name,`+
|
||||
` zitadel.projections.orgs.primary_domain,`+
|
||||
regexp.QuoteMeta(`SELECT projections.orgs.id,`+
|
||||
` projections.orgs.creation_date,`+
|
||||
` projections.orgs.change_date,`+
|
||||
` projections.orgs.resource_owner,`+
|
||||
` projections.orgs.org_state,`+
|
||||
` projections.orgs.sequence,`+
|
||||
` projections.orgs.name,`+
|
||||
` projections.orgs.primary_domain,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.orgs`),
|
||||
` FROM projections.orgs`),
|
||||
[]string{
|
||||
"id",
|
||||
"creation_date",
|
||||
@@ -185,16 +185,16 @@ func Test_OrgPrepares(t *testing.T) {
|
||||
prepare: prepareOrgsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.orgs.id,`+
|
||||
` zitadel.projections.orgs.creation_date,`+
|
||||
` zitadel.projections.orgs.change_date,`+
|
||||
` zitadel.projections.orgs.resource_owner,`+
|
||||
` zitadel.projections.orgs.org_state,`+
|
||||
` zitadel.projections.orgs.sequence,`+
|
||||
` zitadel.projections.orgs.name,`+
|
||||
` zitadel.projections.orgs.primary_domain,`+
|
||||
regexp.QuoteMeta(`SELECT projections.orgs.id,`+
|
||||
` projections.orgs.creation_date,`+
|
||||
` projections.orgs.change_date,`+
|
||||
` projections.orgs.resource_owner,`+
|
||||
` projections.orgs.org_state,`+
|
||||
` projections.orgs.sequence,`+
|
||||
` projections.orgs.name,`+
|
||||
` projections.orgs.primary_domain,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.orgs`),
|
||||
` FROM projections.orgs`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
@@ -211,15 +211,15 @@ func Test_OrgPrepares(t *testing.T) {
|
||||
prepare: prepareOrgQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.orgs.id,`+
|
||||
` zitadel.projections.orgs.creation_date,`+
|
||||
` zitadel.projections.orgs.change_date,`+
|
||||
` zitadel.projections.orgs.resource_owner,`+
|
||||
` zitadel.projections.orgs.org_state,`+
|
||||
` zitadel.projections.orgs.sequence,`+
|
||||
` zitadel.projections.orgs.name,`+
|
||||
` zitadel.projections.orgs.primary_domain`+
|
||||
` FROM zitadel.projections.orgs`),
|
||||
regexp.QuoteMeta(`SELECT projections.orgs.id,`+
|
||||
` projections.orgs.creation_date,`+
|
||||
` projections.orgs.change_date,`+
|
||||
` projections.orgs.resource_owner,`+
|
||||
` projections.orgs.org_state,`+
|
||||
` projections.orgs.sequence,`+
|
||||
` projections.orgs.name,`+
|
||||
` projections.orgs.primary_domain`+
|
||||
` FROM projections.orgs`),
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -237,15 +237,15 @@ func Test_OrgPrepares(t *testing.T) {
|
||||
prepare: prepareOrgQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.orgs.id,`+
|
||||
` zitadel.projections.orgs.creation_date,`+
|
||||
` zitadel.projections.orgs.change_date,`+
|
||||
` zitadel.projections.orgs.resource_owner,`+
|
||||
` zitadel.projections.orgs.org_state,`+
|
||||
` zitadel.projections.orgs.sequence,`+
|
||||
` zitadel.projections.orgs.name,`+
|
||||
` zitadel.projections.orgs.primary_domain`+
|
||||
` FROM zitadel.projections.orgs`),
|
||||
regexp.QuoteMeta(`SELECT projections.orgs.id,`+
|
||||
` projections.orgs.creation_date,`+
|
||||
` projections.orgs.change_date,`+
|
||||
` projections.orgs.resource_owner,`+
|
||||
` projections.orgs.org_state,`+
|
||||
` projections.orgs.sequence,`+
|
||||
` projections.orgs.name,`+
|
||||
` projections.orgs.primary_domain`+
|
||||
` FROM projections.orgs`),
|
||||
[]string{
|
||||
"id",
|
||||
"creation_date",
|
||||
@@ -284,15 +284,15 @@ func Test_OrgPrepares(t *testing.T) {
|
||||
prepare: prepareOrgQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.orgs.id,`+
|
||||
` zitadel.projections.orgs.creation_date,`+
|
||||
` zitadel.projections.orgs.change_date,`+
|
||||
` zitadel.projections.orgs.resource_owner,`+
|
||||
` zitadel.projections.orgs.org_state,`+
|
||||
` zitadel.projections.orgs.sequence,`+
|
||||
` zitadel.projections.orgs.name,`+
|
||||
` zitadel.projections.orgs.primary_domain`+
|
||||
` FROM zitadel.projections.orgs`),
|
||||
regexp.QuoteMeta(`SELECT projections.orgs.id,`+
|
||||
` projections.orgs.creation_date,`+
|
||||
` projections.orgs.change_date,`+
|
||||
` projections.orgs.resource_owner,`+
|
||||
` projections.orgs.org_state,`+
|
||||
` projections.orgs.sequence,`+
|
||||
` projections.orgs.name,`+
|
||||
` projections.orgs.primary_domain`+
|
||||
` FROM projections.orgs`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
@@ -310,7 +310,7 @@ func Test_OrgPrepares(t *testing.T) {
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT COUNT(*) = 0`+
|
||||
` FROM zitadel.projections.orgs`),
|
||||
` FROM projections.orgs`),
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -329,7 +329,7 @@ func Test_OrgPrepares(t *testing.T) {
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT COUNT(*) = 0`+
|
||||
` FROM zitadel.projections.orgs`),
|
||||
` FROM projections.orgs`),
|
||||
[]string{
|
||||
"count",
|
||||
},
|
||||
@@ -346,7 +346,7 @@ func Test_OrgPrepares(t *testing.T) {
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT COUNT(*) = 0`+
|
||||
` FROM zitadel.projections.orgs`),
|
||||
` FROM projections.orgs`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
"time"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/query/projection"
|
||||
@@ -50,6 +52,10 @@ var (
|
||||
name: projection.AgePolicyResourceOwnerCol,
|
||||
table: passwordAgeTable,
|
||||
}
|
||||
PasswordAgeColInstanceID = Column{
|
||||
name: projection.AgePolicyInstanceIDCol,
|
||||
table: passwordAgeTable,
|
||||
}
|
||||
PasswordAgeColWarnDays = Column{
|
||||
name: projection.AgePolicyExpireWarnDaysCol,
|
||||
table: passwordAgeTable,
|
||||
@@ -71,12 +77,17 @@ var (
|
||||
func (q *Queries) PasswordAgePolicyByOrg(ctx context.Context, orgID string) (*PasswordAgePolicy, error) {
|
||||
stmt, scan := preparePasswordAgePolicyQuery()
|
||||
query, args, err := stmt.Where(
|
||||
sq.Or{
|
||||
sq.And{
|
||||
sq.Eq{
|
||||
PasswordAgeColID.identifier(): orgID,
|
||||
PasswordAgeColInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
},
|
||||
sq.Eq{
|
||||
PasswordAgeColID.identifier(): domain.IAMID,
|
||||
sq.Or{
|
||||
sq.Eq{
|
||||
PasswordAgeColID.identifier(): orgID,
|
||||
},
|
||||
sq.Eq{
|
||||
PasswordAgeColID.identifier(): domain.IAMID,
|
||||
},
|
||||
},
|
||||
}).
|
||||
OrderBy(PasswordAgeColIsDefault.identifier()).
|
||||
|
||||
@@ -28,16 +28,16 @@ func Test_PasswordAgePolicyPrepares(t *testing.T) {
|
||||
prepare: preparePasswordAgePolicyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.password_age_policies.id,`+
|
||||
` zitadel.projections.password_age_policies.sequence,`+
|
||||
` zitadel.projections.password_age_policies.creation_date,`+
|
||||
` zitadel.projections.password_age_policies.change_date,`+
|
||||
` zitadel.projections.password_age_policies.resource_owner,`+
|
||||
` zitadel.projections.password_age_policies.expire_warn_days,`+
|
||||
` zitadel.projections.password_age_policies.max_age_days,`+
|
||||
` zitadel.projections.password_age_policies.is_default,`+
|
||||
` zitadel.projections.password_age_policies.state`+
|
||||
` FROM zitadel.projections.password_age_policies`),
|
||||
regexp.QuoteMeta(`SELECT projections.password_age_policies.id,`+
|
||||
` projections.password_age_policies.sequence,`+
|
||||
` projections.password_age_policies.creation_date,`+
|
||||
` projections.password_age_policies.change_date,`+
|
||||
` projections.password_age_policies.resource_owner,`+
|
||||
` projections.password_age_policies.expire_warn_days,`+
|
||||
` projections.password_age_policies.max_age_days,`+
|
||||
` projections.password_age_policies.is_default,`+
|
||||
` projections.password_age_policies.state`+
|
||||
` FROM projections.password_age_policies`),
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -55,16 +55,16 @@ func Test_PasswordAgePolicyPrepares(t *testing.T) {
|
||||
prepare: preparePasswordAgePolicyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.password_age_policies.id,`+
|
||||
` zitadel.projections.password_age_policies.sequence,`+
|
||||
` zitadel.projections.password_age_policies.creation_date,`+
|
||||
` zitadel.projections.password_age_policies.change_date,`+
|
||||
` zitadel.projections.password_age_policies.resource_owner,`+
|
||||
` zitadel.projections.password_age_policies.expire_warn_days,`+
|
||||
` zitadel.projections.password_age_policies.max_age_days,`+
|
||||
` zitadel.projections.password_age_policies.is_default,`+
|
||||
` zitadel.projections.password_age_policies.state`+
|
||||
` FROM zitadel.projections.password_age_policies`),
|
||||
regexp.QuoteMeta(`SELECT projections.password_age_policies.id,`+
|
||||
` projections.password_age_policies.sequence,`+
|
||||
` projections.password_age_policies.creation_date,`+
|
||||
` projections.password_age_policies.change_date,`+
|
||||
` projections.password_age_policies.resource_owner,`+
|
||||
` projections.password_age_policies.expire_warn_days,`+
|
||||
` projections.password_age_policies.max_age_days,`+
|
||||
` projections.password_age_policies.is_default,`+
|
||||
` projections.password_age_policies.state`+
|
||||
` FROM projections.password_age_policies`),
|
||||
[]string{
|
||||
"id",
|
||||
"sequence",
|
||||
@@ -106,16 +106,16 @@ func Test_PasswordAgePolicyPrepares(t *testing.T) {
|
||||
prepare: preparePasswordAgePolicyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.password_age_policies.id,`+
|
||||
` zitadel.projections.password_age_policies.sequence,`+
|
||||
` zitadel.projections.password_age_policies.creation_date,`+
|
||||
` zitadel.projections.password_age_policies.change_date,`+
|
||||
` zitadel.projections.password_age_policies.resource_owner,`+
|
||||
` zitadel.projections.password_age_policies.expire_warn_days,`+
|
||||
` zitadel.projections.password_age_policies.max_age_days,`+
|
||||
` zitadel.projections.password_age_policies.is_default,`+
|
||||
` zitadel.projections.password_age_policies.state`+
|
||||
` FROM zitadel.projections.password_age_policies`),
|
||||
regexp.QuoteMeta(`SELECT projections.password_age_policies.id,`+
|
||||
` projections.password_age_policies.sequence,`+
|
||||
` projections.password_age_policies.creation_date,`+
|
||||
` projections.password_age_policies.change_date,`+
|
||||
` projections.password_age_policies.resource_owner,`+
|
||||
` projections.password_age_policies.expire_warn_days,`+
|
||||
` projections.password_age_policies.max_age_days,`+
|
||||
` projections.password_age_policies.is_default,`+
|
||||
` projections.password_age_policies.state`+
|
||||
` FROM projections.password_age_policies`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
"time"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/query/projection"
|
||||
@@ -32,12 +34,17 @@ type PasswordComplexityPolicy struct {
|
||||
func (q *Queries) PasswordComplexityPolicyByOrg(ctx context.Context, orgID string) (*PasswordComplexityPolicy, error) {
|
||||
stmt, scan := preparePasswordComplexityPolicyQuery()
|
||||
query, args, err := stmt.Where(
|
||||
sq.Or{
|
||||
sq.And{
|
||||
sq.Eq{
|
||||
PasswordComplexityColID.identifier(): orgID,
|
||||
PasswordComplexityColInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
},
|
||||
sq.Eq{
|
||||
PasswordComplexityColID.identifier(): domain.IAMID,
|
||||
sq.Or{
|
||||
sq.Eq{
|
||||
PasswordComplexityColID.identifier(): orgID,
|
||||
},
|
||||
sq.Eq{
|
||||
PasswordComplexityColID.identifier(): domain.IAMID,
|
||||
},
|
||||
},
|
||||
}).
|
||||
OrderBy(PasswordComplexityColIsDefault.identifier()).
|
||||
@@ -53,7 +60,8 @@ func (q *Queries) PasswordComplexityPolicyByOrg(ctx context.Context, orgID strin
|
||||
func (q *Queries) DefaultPasswordComplexityPolicy(ctx context.Context) (*PasswordComplexityPolicy, error) {
|
||||
stmt, scan := preparePasswordComplexityPolicyQuery()
|
||||
query, args, err := stmt.Where(sq.Eq{
|
||||
PasswordComplexityColID.identifier(): domain.IAMID,
|
||||
PasswordComplexityColID.identifier(): domain.IAMID,
|
||||
PasswordComplexityColInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).
|
||||
OrderBy(PasswordComplexityColIsDefault.identifier()).
|
||||
Limit(1).ToSql()
|
||||
@@ -89,6 +97,10 @@ var (
|
||||
name: projection.ComplexityPolicyResourceOwnerCol,
|
||||
table: passwordComplexityTable,
|
||||
}
|
||||
PasswordComplexityColInstanceID = Column{
|
||||
name: projection.ComplexityPolicyInstanceIDCol,
|
||||
table: passwordComplexityTable,
|
||||
}
|
||||
PasswordComplexityColMinLength = Column{
|
||||
name: projection.ComplexityPolicyMinLengthCol,
|
||||
table: passwordComplexityTable,
|
||||
|
||||
@@ -28,19 +28,19 @@ func Test_PasswordComplexityPolicyPrepares(t *testing.T) {
|
||||
prepare: preparePasswordComplexityPolicyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.password_complexity_policies.id,`+
|
||||
` zitadel.projections.password_complexity_policies.sequence,`+
|
||||
` zitadel.projections.password_complexity_policies.creation_date,`+
|
||||
` zitadel.projections.password_complexity_policies.change_date,`+
|
||||
` zitadel.projections.password_complexity_policies.resource_owner,`+
|
||||
` zitadel.projections.password_complexity_policies.min_length,`+
|
||||
` zitadel.projections.password_complexity_policies.has_lowercase,`+
|
||||
` zitadel.projections.password_complexity_policies.has_uppercase,`+
|
||||
` zitadel.projections.password_complexity_policies.has_number,`+
|
||||
` zitadel.projections.password_complexity_policies.has_symbol,`+
|
||||
` zitadel.projections.password_complexity_policies.is_default,`+
|
||||
` zitadel.projections.password_complexity_policies.state`+
|
||||
` FROM zitadel.projections.password_complexity_policies`),
|
||||
regexp.QuoteMeta(`SELECT projections.password_complexity_policies.id,`+
|
||||
` projections.password_complexity_policies.sequence,`+
|
||||
` projections.password_complexity_policies.creation_date,`+
|
||||
` projections.password_complexity_policies.change_date,`+
|
||||
` projections.password_complexity_policies.resource_owner,`+
|
||||
` projections.password_complexity_policies.min_length,`+
|
||||
` projections.password_complexity_policies.has_lowercase,`+
|
||||
` projections.password_complexity_policies.has_uppercase,`+
|
||||
` projections.password_complexity_policies.has_number,`+
|
||||
` projections.password_complexity_policies.has_symbol,`+
|
||||
` projections.password_complexity_policies.is_default,`+
|
||||
` projections.password_complexity_policies.state`+
|
||||
` FROM projections.password_complexity_policies`),
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -58,19 +58,19 @@ func Test_PasswordComplexityPolicyPrepares(t *testing.T) {
|
||||
prepare: preparePasswordComplexityPolicyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.password_complexity_policies.id,`+
|
||||
` zitadel.projections.password_complexity_policies.sequence,`+
|
||||
` zitadel.projections.password_complexity_policies.creation_date,`+
|
||||
` zitadel.projections.password_complexity_policies.change_date,`+
|
||||
` zitadel.projections.password_complexity_policies.resource_owner,`+
|
||||
` zitadel.projections.password_complexity_policies.min_length,`+
|
||||
` zitadel.projections.password_complexity_policies.has_lowercase,`+
|
||||
` zitadel.projections.password_complexity_policies.has_uppercase,`+
|
||||
` zitadel.projections.password_complexity_policies.has_number,`+
|
||||
` zitadel.projections.password_complexity_policies.has_symbol,`+
|
||||
` zitadel.projections.password_complexity_policies.is_default,`+
|
||||
` zitadel.projections.password_complexity_policies.state`+
|
||||
` FROM zitadel.projections.password_complexity_policies`),
|
||||
regexp.QuoteMeta(`SELECT projections.password_complexity_policies.id,`+
|
||||
` projections.password_complexity_policies.sequence,`+
|
||||
` projections.password_complexity_policies.creation_date,`+
|
||||
` projections.password_complexity_policies.change_date,`+
|
||||
` projections.password_complexity_policies.resource_owner,`+
|
||||
` projections.password_complexity_policies.min_length,`+
|
||||
` projections.password_complexity_policies.has_lowercase,`+
|
||||
` projections.password_complexity_policies.has_uppercase,`+
|
||||
` projections.password_complexity_policies.has_number,`+
|
||||
` projections.password_complexity_policies.has_symbol,`+
|
||||
` projections.password_complexity_policies.is_default,`+
|
||||
` projections.password_complexity_policies.state`+
|
||||
` FROM projections.password_complexity_policies`),
|
||||
[]string{
|
||||
"id",
|
||||
"sequence",
|
||||
@@ -121,19 +121,19 @@ func Test_PasswordComplexityPolicyPrepares(t *testing.T) {
|
||||
prepare: preparePasswordComplexityPolicyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.password_complexity_policies.id,`+
|
||||
` zitadel.projections.password_complexity_policies.sequence,`+
|
||||
` zitadel.projections.password_complexity_policies.creation_date,`+
|
||||
` zitadel.projections.password_complexity_policies.change_date,`+
|
||||
` zitadel.projections.password_complexity_policies.resource_owner,`+
|
||||
` zitadel.projections.password_complexity_policies.min_length,`+
|
||||
` zitadel.projections.password_complexity_policies.has_lowercase,`+
|
||||
` zitadel.projections.password_complexity_policies.has_uppercase,`+
|
||||
` zitadel.projections.password_complexity_policies.has_number,`+
|
||||
` zitadel.projections.password_complexity_policies.has_symbol,`+
|
||||
` zitadel.projections.password_complexity_policies.is_default,`+
|
||||
` zitadel.projections.password_complexity_policies.state`+
|
||||
` FROM zitadel.projections.password_complexity_policies`),
|
||||
regexp.QuoteMeta(`SELECT projections.password_complexity_policies.id,`+
|
||||
` projections.password_complexity_policies.sequence,`+
|
||||
` projections.password_complexity_policies.creation_date,`+
|
||||
` projections.password_complexity_policies.change_date,`+
|
||||
` projections.password_complexity_policies.resource_owner,`+
|
||||
` projections.password_complexity_policies.min_length,`+
|
||||
` projections.password_complexity_policies.has_lowercase,`+
|
||||
` projections.password_complexity_policies.has_uppercase,`+
|
||||
` projections.password_complexity_policies.has_number,`+
|
||||
` projections.password_complexity_policies.has_symbol,`+
|
||||
` projections.password_complexity_policies.is_default,`+
|
||||
` projections.password_complexity_policies.state`+
|
||||
` FROM projections.password_complexity_policies`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
"time"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/query/projection"
|
||||
@@ -50,6 +52,10 @@ var (
|
||||
name: projection.PrivacyPolicyResourceOwnerCol,
|
||||
table: privacyTable,
|
||||
}
|
||||
PrivacyColInstanceID = Column{
|
||||
name: projection.PrivacyPolicyInstanceIDCol,
|
||||
table: privacyTable,
|
||||
}
|
||||
PrivacyColPrivacyLink = Column{
|
||||
name: projection.PrivacyPolicyPrivacyLinkCol,
|
||||
table: privacyTable,
|
||||
@@ -71,12 +77,17 @@ var (
|
||||
func (q *Queries) PrivacyPolicyByOrg(ctx context.Context, orgID string) (*PrivacyPolicy, error) {
|
||||
stmt, scan := preparePrivacyPolicyQuery()
|
||||
query, args, err := stmt.Where(
|
||||
sq.Or{
|
||||
sq.And{
|
||||
sq.Eq{
|
||||
PrivacyColID.identifier(): orgID,
|
||||
PrivacyColInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
},
|
||||
sq.Eq{
|
||||
PrivacyColID.identifier(): domain.IAMID,
|
||||
sq.Or{
|
||||
sq.Eq{
|
||||
PrivacyColID.identifier(): orgID,
|
||||
},
|
||||
sq.Eq{
|
||||
PrivacyColID.identifier(): domain.IAMID,
|
||||
},
|
||||
},
|
||||
}).
|
||||
OrderBy(PrivacyColIsDefault.identifier()).
|
||||
@@ -92,7 +103,8 @@ func (q *Queries) PrivacyPolicyByOrg(ctx context.Context, orgID string) (*Privac
|
||||
func (q *Queries) DefaultPrivacyPolicy(ctx context.Context) (*PrivacyPolicy, error) {
|
||||
stmt, scan := preparePrivacyPolicyQuery()
|
||||
query, args, err := stmt.Where(sq.Eq{
|
||||
PrivacyColID.identifier(): domain.IAMID,
|
||||
PrivacyColID.identifier(): domain.IAMID,
|
||||
PrivacyColInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).
|
||||
OrderBy(PrivacyColIsDefault.identifier()).
|
||||
Limit(1).ToSql()
|
||||
|
||||
@@ -28,16 +28,16 @@ func Test_PrivacyPolicyPrepares(t *testing.T) {
|
||||
prepare: preparePrivacyPolicyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.privacy_policies.id,`+
|
||||
` zitadel.projections.privacy_policies.sequence,`+
|
||||
` zitadel.projections.privacy_policies.creation_date,`+
|
||||
` zitadel.projections.privacy_policies.change_date,`+
|
||||
` zitadel.projections.privacy_policies.resource_owner,`+
|
||||
` zitadel.projections.privacy_policies.privacy_link,`+
|
||||
` zitadel.projections.privacy_policies.tos_link,`+
|
||||
` zitadel.projections.privacy_policies.is_default,`+
|
||||
` zitadel.projections.privacy_policies.state`+
|
||||
` FROM zitadel.projections.privacy_policies`),
|
||||
regexp.QuoteMeta(`SELECT projections.privacy_policies.id,`+
|
||||
` projections.privacy_policies.sequence,`+
|
||||
` projections.privacy_policies.creation_date,`+
|
||||
` projections.privacy_policies.change_date,`+
|
||||
` projections.privacy_policies.resource_owner,`+
|
||||
` projections.privacy_policies.privacy_link,`+
|
||||
` projections.privacy_policies.tos_link,`+
|
||||
` projections.privacy_policies.is_default,`+
|
||||
` projections.privacy_policies.state`+
|
||||
` FROM projections.privacy_policies`),
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -55,16 +55,16 @@ func Test_PrivacyPolicyPrepares(t *testing.T) {
|
||||
prepare: preparePrivacyPolicyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.privacy_policies.id,`+
|
||||
` zitadel.projections.privacy_policies.sequence,`+
|
||||
` zitadel.projections.privacy_policies.creation_date,`+
|
||||
` zitadel.projections.privacy_policies.change_date,`+
|
||||
` zitadel.projections.privacy_policies.resource_owner,`+
|
||||
` zitadel.projections.privacy_policies.privacy_link,`+
|
||||
` zitadel.projections.privacy_policies.tos_link,`+
|
||||
` zitadel.projections.privacy_policies.is_default,`+
|
||||
` zitadel.projections.privacy_policies.state`+
|
||||
` FROM zitadel.projections.privacy_policies`),
|
||||
regexp.QuoteMeta(`SELECT projections.privacy_policies.id,`+
|
||||
` projections.privacy_policies.sequence,`+
|
||||
` projections.privacy_policies.creation_date,`+
|
||||
` projections.privacy_policies.change_date,`+
|
||||
` projections.privacy_policies.resource_owner,`+
|
||||
` projections.privacy_policies.privacy_link,`+
|
||||
` projections.privacy_policies.tos_link,`+
|
||||
` projections.privacy_policies.is_default,`+
|
||||
` projections.privacy_policies.state`+
|
||||
` FROM projections.privacy_policies`),
|
||||
[]string{
|
||||
"id",
|
||||
"sequence",
|
||||
@@ -106,16 +106,16 @@ func Test_PrivacyPolicyPrepares(t *testing.T) {
|
||||
prepare: preparePrivacyPolicyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.privacy_policies.id,`+
|
||||
` zitadel.projections.privacy_policies.sequence,`+
|
||||
` zitadel.projections.privacy_policies.creation_date,`+
|
||||
` zitadel.projections.privacy_policies.change_date,`+
|
||||
` zitadel.projections.privacy_policies.resource_owner,`+
|
||||
` zitadel.projections.privacy_policies.privacy_link,`+
|
||||
` zitadel.projections.privacy_policies.tos_link,`+
|
||||
` zitadel.projections.privacy_policies.is_default,`+
|
||||
` zitadel.projections.privacy_policies.state`+
|
||||
` FROM zitadel.projections.privacy_policies`),
|
||||
regexp.QuoteMeta(`SELECT projections.privacy_policies.id,`+
|
||||
` projections.privacy_policies.sequence,`+
|
||||
` projections.privacy_policies.creation_date,`+
|
||||
` projections.privacy_policies.change_date,`+
|
||||
` projections.privacy_policies.resource_owner,`+
|
||||
` projections.privacy_policies.privacy_link,`+
|
||||
` projections.privacy_policies.tos_link,`+
|
||||
` projections.privacy_policies.is_default,`+
|
||||
` projections.privacy_policies.state`+
|
||||
` FROM projections.privacy_policies`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"time"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
"github.com/caos/zitadel/internal/query/projection"
|
||||
|
||||
@@ -54,6 +55,10 @@ var (
|
||||
name: projection.ProjectColumnResourceOwner,
|
||||
table: projectsTable,
|
||||
}
|
||||
ProjectColumnInstanceID = Column{
|
||||
name: projection.ProjectColumnInstanceID,
|
||||
table: projectsTable,
|
||||
}
|
||||
ProjectColumnCreator = Column{
|
||||
name: projection.ProjectColumnCreator,
|
||||
table: projectsTable,
|
||||
@@ -96,7 +101,8 @@ type ProjectSearchQueries struct {
|
||||
func (q *Queries) ProjectByID(ctx context.Context, id string) (*Project, error) {
|
||||
stmt, scan := prepareProjectQuery()
|
||||
query, args, err := stmt.Where(sq.Eq{
|
||||
ProjectColumnID.identifier(): id,
|
||||
ProjectColumnID.identifier(): id,
|
||||
ProjectColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "QUERY-2m00Q", "Errors.Query.SQLStatment")
|
||||
@@ -113,7 +119,10 @@ func (q *Queries) ExistsProject(ctx context.Context, id string) (err error) {
|
||||
|
||||
func (q *Queries) SearchProjects(ctx context.Context, queries *ProjectSearchQueries) (projects *Projects, err error) {
|
||||
query, scan := prepareProjectsQuery()
|
||||
stmt, args, err := queries.toQuery(query).ToSql()
|
||||
stmt, args, err := queries.toQuery(query).
|
||||
Where(sq.Eq{
|
||||
ProjectColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInvalidArgument(err, "QUERY-fn9ew", "Errors.Query.InvalidRequest")
|
||||
}
|
||||
|
||||
@@ -7,9 +7,10 @@ import (
|
||||
"time"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
"github.com/lib/pq"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
"github.com/caos/zitadel/internal/query/projection"
|
||||
"github.com/lib/pq"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
@@ -36,6 +37,10 @@ var (
|
||||
name: projection.ProjectGrantColumnResourceOwner,
|
||||
table: projectGrantsTable,
|
||||
}
|
||||
ProjectGrantColumnInstanceID = Column{
|
||||
name: projection.ProjectGrantColumnInstanceID,
|
||||
table: projectGrantsTable,
|
||||
}
|
||||
ProjectGrantColumnState = Column{
|
||||
name: projection.ProjectGrantColumnState,
|
||||
table: projectGrantsTable,
|
||||
@@ -103,7 +108,8 @@ type ProjectGrantSearchQueries struct {
|
||||
func (q *Queries) ProjectGrantByID(ctx context.Context, id string) (*ProjectGrant, error) {
|
||||
stmt, scan := prepareProjectGrantQuery()
|
||||
query, args, err := stmt.Where(sq.Eq{
|
||||
ProjectGrantColumnGrantID.identifier(): id,
|
||||
ProjectGrantColumnGrantID.identifier(): id,
|
||||
ProjectGrantColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "QUERY-Nf93d", "Errors.Query.SQLStatment")
|
||||
@@ -118,6 +124,7 @@ func (q *Queries) ProjectGrantByIDAndGrantedOrg(ctx context.Context, id, granted
|
||||
query, args, err := stmt.Where(sq.Eq{
|
||||
ProjectGrantColumnGrantID.identifier(): id,
|
||||
ProjectGrantColumnGrantedOrgID.identifier(): grantedOrg,
|
||||
ProjectGrantColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "QUERY-MO9fs", "Errors.Query.SQLStatment")
|
||||
@@ -134,7 +141,10 @@ func (q *Queries) ExistsProjectGrant(ctx context.Context, id string) (err error)
|
||||
|
||||
func (q *Queries) SearchProjectGrants(ctx context.Context, queries *ProjectGrantSearchQueries) (projects *ProjectGrants, err error) {
|
||||
query, scan := prepareProjectGrantsQuery()
|
||||
stmt, args, err := queries.toQuery(query).ToSql()
|
||||
stmt, args, err := queries.toQuery(query).
|
||||
Where(sq.Eq{
|
||||
ProjectGrantColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInvalidArgument(err, "QUERY-N9fsg", "Errors.Query.InvalidRequest")
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
"github.com/lib/pq"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/query/projection"
|
||||
)
|
||||
@@ -40,6 +42,10 @@ var (
|
||||
name: projection.MemberResourceOwner,
|
||||
table: projectGrantMemberTable,
|
||||
}
|
||||
ProjectGrantMemberInstanceID = Column{
|
||||
name: projection.MemberInstanceID,
|
||||
table: projectGrantMemberTable,
|
||||
}
|
||||
ProjectGrantMemberProjectID = Column{
|
||||
name: projection.ProjectGrantMemberProjectIDCol,
|
||||
table: projectGrantMemberTable,
|
||||
@@ -66,7 +72,10 @@ func (q *ProjectGrantMembersQuery) toQuery(query sq.SelectBuilder) sq.SelectBuil
|
||||
|
||||
func (q *Queries) ProjectGrantMembers(ctx context.Context, queries *ProjectGrantMembersQuery) (*Members, error) {
|
||||
query, scan := prepareProjectGrantMembersQuery()
|
||||
stmt, args, err := queries.toQuery(query).ToSql()
|
||||
stmt, args, err := queries.toQuery(query).
|
||||
Where(sq.Eq{
|
||||
ProjectGrantMemberInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInvalidArgument(err, "QUERY-USNwM", "Errors.Query.InvalidRequest")
|
||||
}
|
||||
|
||||
@@ -19,22 +19,22 @@ var (
|
||||
", members.resource_owner" +
|
||||
", members.user_id" +
|
||||
", members.roles" +
|
||||
", zitadel.projections.login_names.login_name" +
|
||||
", zitadel.projections.users_humans.email" +
|
||||
", zitadel.projections.users_humans.first_name" +
|
||||
", zitadel.projections.users_humans.last_name" +
|
||||
", zitadel.projections.users_humans.display_name" +
|
||||
", zitadel.projections.users_machines.name" +
|
||||
", zitadel.projections.users_humans.avatar_key" +
|
||||
", projections.login_names.login_name" +
|
||||
", projections.users_humans.email" +
|
||||
", projections.users_humans.first_name" +
|
||||
", projections.users_humans.last_name" +
|
||||
", projections.users_humans.display_name" +
|
||||
", projections.users_machines.name" +
|
||||
", projections.users_humans.avatar_key" +
|
||||
", COUNT(*) OVER () " +
|
||||
"FROM zitadel.projections.project_grant_members as members " +
|
||||
"LEFT JOIN zitadel.projections.users_humans " +
|
||||
"ON members.user_id = zitadel.projections.users_humans.user_id " +
|
||||
"LEFT JOIN zitadel.projections.users_machines " +
|
||||
"ON members.user_id = zitadel.projections.users_machines.user_id " +
|
||||
"LEFT JOIN zitadel.projections.login_names " +
|
||||
"ON members.user_id = zitadel.projections.login_names.user_id " +
|
||||
"WHERE zitadel.projections.login_names.is_primary = $1")
|
||||
"FROM projections.project_grant_members as members " +
|
||||
"LEFT JOIN projections.users_humans " +
|
||||
"ON members.user_id = projections.users_humans.user_id " +
|
||||
"LEFT JOIN projections.users_machines " +
|
||||
"ON members.user_id = projections.users_machines.user_id " +
|
||||
"LEFT JOIN projections.login_names " +
|
||||
"ON members.user_id = projections.login_names.user_id " +
|
||||
"WHERE projections.login_names.is_primary = $1")
|
||||
projectGrantMembersColumns = []string{
|
||||
"creation_date",
|
||||
"change_date",
|
||||
|
||||
@@ -8,9 +8,10 @@ import (
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"github.com/lib/pq"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/lib/pq"
|
||||
)
|
||||
|
||||
func Test_ProjectGrantPrepares(t *testing.T) {
|
||||
@@ -29,23 +30,23 @@ func Test_ProjectGrantPrepares(t *testing.T) {
|
||||
prepare: prepareProjectGrantsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(` SELECT zitadel.projections.project_grants.project_id,`+
|
||||
` zitadel.projections.project_grants.grant_id,`+
|
||||
` zitadel.projections.project_grants.creation_date,`+
|
||||
` zitadel.projections.project_grants.change_date,`+
|
||||
` zitadel.projections.project_grants.resource_owner,`+
|
||||
` zitadel.projections.project_grants.state,`+
|
||||
` zitadel.projections.project_grants.sequence,`+
|
||||
` zitadel.projections.projects.name,`+
|
||||
` zitadel.projections.project_grants.granted_org_id,`+
|
||||
regexp.QuoteMeta(` SELECT projections.project_grants.project_id,`+
|
||||
` projections.project_grants.grant_id,`+
|
||||
` projections.project_grants.creation_date,`+
|
||||
` projections.project_grants.change_date,`+
|
||||
` projections.project_grants.resource_owner,`+
|
||||
` projections.project_grants.state,`+
|
||||
` projections.project_grants.sequence,`+
|
||||
` projections.projects.name,`+
|
||||
` projections.project_grants.granted_org_id,`+
|
||||
` o.name,`+
|
||||
` zitadel.projections.project_grants.granted_role_keys,`+
|
||||
` projections.project_grants.granted_role_keys,`+
|
||||
` r.name,`+
|
||||
` COUNT(*) OVER () `+
|
||||
` FROM zitadel.projections.project_grants `+
|
||||
` LEFT JOIN zitadel.projections.projects ON zitadel.projections.project_grants.project_id = zitadel.projections.projects.id `+
|
||||
` LEFT JOIN zitadel.projections.orgs as r ON zitadel.projections.project_grants.resource_owner = r.id`+
|
||||
` LEFT JOIN zitadel.projections.orgs as o ON zitadel.projections.project_grants.granted_org_id = o.id`),
|
||||
` FROM projections.project_grants `+
|
||||
` LEFT JOIN projections.projects ON projections.project_grants.project_id = projections.projects.id `+
|
||||
` LEFT JOIN projections.orgs as r ON projections.project_grants.resource_owner = r.id`+
|
||||
` LEFT JOIN projections.orgs as o ON projections.project_grants.granted_org_id = o.id`),
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -57,23 +58,23 @@ func Test_ProjectGrantPrepares(t *testing.T) {
|
||||
prepare: prepareProjectGrantsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(` SELECT zitadel.projections.project_grants.project_id,`+
|
||||
` zitadel.projections.project_grants.grant_id,`+
|
||||
` zitadel.projections.project_grants.creation_date,`+
|
||||
` zitadel.projections.project_grants.change_date,`+
|
||||
` zitadel.projections.project_grants.resource_owner,`+
|
||||
` zitadel.projections.project_grants.state,`+
|
||||
` zitadel.projections.project_grants.sequence,`+
|
||||
` zitadel.projections.projects.name,`+
|
||||
` zitadel.projections.project_grants.granted_org_id,`+
|
||||
regexp.QuoteMeta(` SELECT projections.project_grants.project_id,`+
|
||||
` projections.project_grants.grant_id,`+
|
||||
` projections.project_grants.creation_date,`+
|
||||
` projections.project_grants.change_date,`+
|
||||
` projections.project_grants.resource_owner,`+
|
||||
` projections.project_grants.state,`+
|
||||
` projections.project_grants.sequence,`+
|
||||
` projections.projects.name,`+
|
||||
` projections.project_grants.granted_org_id,`+
|
||||
` o.name,`+
|
||||
` zitadel.projections.project_grants.granted_role_keys,`+
|
||||
` projections.project_grants.granted_role_keys,`+
|
||||
` r.name,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.project_grants`+
|
||||
` LEFT JOIN zitadel.projections.projects ON zitadel.projections.project_grants.project_id = zitadel.projections.projects.id`+
|
||||
` LEFT JOIN zitadel.projections.orgs as r ON zitadel.projections.project_grants.resource_owner = r.id`+
|
||||
` LEFT JOIN zitadel.projections.orgs as o ON zitadel.projections.project_grants.granted_org_id = o.id`),
|
||||
` FROM projections.project_grants`+
|
||||
` LEFT JOIN projections.projects ON projections.project_grants.project_id = projections.projects.id`+
|
||||
` LEFT JOIN projections.orgs as r ON projections.project_grants.resource_owner = r.id`+
|
||||
` LEFT JOIN projections.orgs as o ON projections.project_grants.granted_org_id = o.id`),
|
||||
[]string{
|
||||
"project_id",
|
||||
"grant_id",
|
||||
@@ -134,23 +135,23 @@ func Test_ProjectGrantPrepares(t *testing.T) {
|
||||
prepare: prepareProjectGrantsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(` SELECT zitadel.projections.project_grants.project_id,`+
|
||||
` zitadel.projections.project_grants.grant_id,`+
|
||||
` zitadel.projections.project_grants.creation_date,`+
|
||||
` zitadel.projections.project_grants.change_date,`+
|
||||
` zitadel.projections.project_grants.resource_owner,`+
|
||||
` zitadel.projections.project_grants.state,`+
|
||||
` zitadel.projections.project_grants.sequence,`+
|
||||
` zitadel.projections.projects.name,`+
|
||||
` zitadel.projections.project_grants.granted_org_id,`+
|
||||
regexp.QuoteMeta(` SELECT projections.project_grants.project_id,`+
|
||||
` projections.project_grants.grant_id,`+
|
||||
` projections.project_grants.creation_date,`+
|
||||
` projections.project_grants.change_date,`+
|
||||
` projections.project_grants.resource_owner,`+
|
||||
` projections.project_grants.state,`+
|
||||
` projections.project_grants.sequence,`+
|
||||
` projections.projects.name,`+
|
||||
` projections.project_grants.granted_org_id,`+
|
||||
` o.name,`+
|
||||
` zitadel.projections.project_grants.granted_role_keys,`+
|
||||
` projections.project_grants.granted_role_keys,`+
|
||||
` r.name,`+
|
||||
` COUNT(*) OVER () `+
|
||||
` FROM zitadel.projections.project_grants `+
|
||||
` LEFT JOIN zitadel.projections.projects ON zitadel.projections.project_grants.project_id = zitadel.projections.projects.id `+
|
||||
` LEFT JOIN zitadel.projections.orgs as r ON zitadel.projections.project_grants.resource_owner = r.id`+
|
||||
` LEFT JOIN zitadel.projections.orgs as o ON zitadel.projections.project_grants.granted_org_id = o.id`),
|
||||
` FROM projections.project_grants `+
|
||||
` LEFT JOIN projections.projects ON projections.project_grants.project_id = projections.projects.id `+
|
||||
` LEFT JOIN projections.orgs as r ON projections.project_grants.resource_owner = r.id`+
|
||||
` LEFT JOIN projections.orgs as o ON projections.project_grants.granted_org_id = o.id`),
|
||||
[]string{
|
||||
"project_id",
|
||||
"grant_id",
|
||||
@@ -211,23 +212,23 @@ func Test_ProjectGrantPrepares(t *testing.T) {
|
||||
prepare: prepareProjectGrantsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(` SELECT zitadel.projections.project_grants.project_id,`+
|
||||
` zitadel.projections.project_grants.grant_id,`+
|
||||
` zitadel.projections.project_grants.creation_date,`+
|
||||
` zitadel.projections.project_grants.change_date,`+
|
||||
` zitadel.projections.project_grants.resource_owner,`+
|
||||
` zitadel.projections.project_grants.state,`+
|
||||
` zitadel.projections.project_grants.sequence,`+
|
||||
` zitadel.projections.projects.name,`+
|
||||
` zitadel.projections.project_grants.granted_org_id,`+
|
||||
regexp.QuoteMeta(` SELECT projections.project_grants.project_id,`+
|
||||
` projections.project_grants.grant_id,`+
|
||||
` projections.project_grants.creation_date,`+
|
||||
` projections.project_grants.change_date,`+
|
||||
` projections.project_grants.resource_owner,`+
|
||||
` projections.project_grants.state,`+
|
||||
` projections.project_grants.sequence,`+
|
||||
` projections.projects.name,`+
|
||||
` projections.project_grants.granted_org_id,`+
|
||||
` o.name,`+
|
||||
` zitadel.projections.project_grants.granted_role_keys,`+
|
||||
` projections.project_grants.granted_role_keys,`+
|
||||
` r.name,`+
|
||||
` COUNT(*) OVER () `+
|
||||
` FROM zitadel.projections.project_grants `+
|
||||
` LEFT JOIN zitadel.projections.projects ON zitadel.projections.project_grants.project_id = zitadel.projections.projects.id `+
|
||||
` LEFT JOIN zitadel.projections.orgs as r ON zitadel.projections.project_grants.resource_owner = r.id`+
|
||||
` LEFT JOIN zitadel.projections.orgs as o ON zitadel.projections.project_grants.granted_org_id = o.id`),
|
||||
` FROM projections.project_grants `+
|
||||
` LEFT JOIN projections.projects ON projections.project_grants.project_id = projections.projects.id `+
|
||||
` LEFT JOIN projections.orgs as r ON projections.project_grants.resource_owner = r.id`+
|
||||
` LEFT JOIN projections.orgs as o ON projections.project_grants.granted_org_id = o.id`),
|
||||
[]string{
|
||||
"project_id",
|
||||
"grant_id",
|
||||
@@ -288,23 +289,23 @@ func Test_ProjectGrantPrepares(t *testing.T) {
|
||||
prepare: prepareProjectGrantsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(` SELECT zitadel.projections.project_grants.project_id,`+
|
||||
` zitadel.projections.project_grants.grant_id,`+
|
||||
` zitadel.projections.project_grants.creation_date,`+
|
||||
` zitadel.projections.project_grants.change_date,`+
|
||||
` zitadel.projections.project_grants.resource_owner,`+
|
||||
` zitadel.projections.project_grants.state,`+
|
||||
` zitadel.projections.project_grants.sequence,`+
|
||||
` zitadel.projections.projects.name,`+
|
||||
` zitadel.projections.project_grants.granted_org_id,`+
|
||||
regexp.QuoteMeta(` SELECT projections.project_grants.project_id,`+
|
||||
` projections.project_grants.grant_id,`+
|
||||
` projections.project_grants.creation_date,`+
|
||||
` projections.project_grants.change_date,`+
|
||||
` projections.project_grants.resource_owner,`+
|
||||
` projections.project_grants.state,`+
|
||||
` projections.project_grants.sequence,`+
|
||||
` projections.projects.name,`+
|
||||
` projections.project_grants.granted_org_id,`+
|
||||
` o.name,`+
|
||||
` zitadel.projections.project_grants.granted_role_keys,`+
|
||||
` projections.project_grants.granted_role_keys,`+
|
||||
` r.name,`+
|
||||
` COUNT(*) OVER () `+
|
||||
` FROM zitadel.projections.project_grants `+
|
||||
` LEFT JOIN zitadel.projections.projects ON zitadel.projections.project_grants.project_id = zitadel.projections.projects.id `+
|
||||
` LEFT JOIN zitadel.projections.orgs as r ON zitadel.projections.project_grants.resource_owner = r.id`+
|
||||
` LEFT JOIN zitadel.projections.orgs as o ON zitadel.projections.project_grants.granted_org_id = o.id`),
|
||||
` FROM projections.project_grants `+
|
||||
` LEFT JOIN projections.projects ON projections.project_grants.project_id = projections.projects.id `+
|
||||
` LEFT JOIN projections.orgs as r ON projections.project_grants.resource_owner = r.id`+
|
||||
` LEFT JOIN projections.orgs as o ON projections.project_grants.granted_org_id = o.id`),
|
||||
[]string{
|
||||
"project_id",
|
||||
"grant_id",
|
||||
@@ -365,23 +366,23 @@ func Test_ProjectGrantPrepares(t *testing.T) {
|
||||
prepare: prepareProjectGrantsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(` SELECT zitadel.projections.project_grants.project_id,`+
|
||||
` zitadel.projections.project_grants.grant_id,`+
|
||||
` zitadel.projections.project_grants.creation_date,`+
|
||||
` zitadel.projections.project_grants.change_date,`+
|
||||
` zitadel.projections.project_grants.resource_owner,`+
|
||||
` zitadel.projections.project_grants.state,`+
|
||||
` zitadel.projections.project_grants.sequence,`+
|
||||
` zitadel.projections.projects.name,`+
|
||||
` zitadel.projections.project_grants.granted_org_id,`+
|
||||
regexp.QuoteMeta(` SELECT projections.project_grants.project_id,`+
|
||||
` projections.project_grants.grant_id,`+
|
||||
` projections.project_grants.creation_date,`+
|
||||
` projections.project_grants.change_date,`+
|
||||
` projections.project_grants.resource_owner,`+
|
||||
` projections.project_grants.state,`+
|
||||
` projections.project_grants.sequence,`+
|
||||
` projections.projects.name,`+
|
||||
` projections.project_grants.granted_org_id,`+
|
||||
` o.name,`+
|
||||
` zitadel.projections.project_grants.granted_role_keys,`+
|
||||
` projections.project_grants.granted_role_keys,`+
|
||||
` r.name,`+
|
||||
` COUNT(*) OVER () `+
|
||||
` FROM zitadel.projections.project_grants `+
|
||||
` LEFT JOIN zitadel.projections.projects ON zitadel.projections.project_grants.project_id = zitadel.projections.projects.id `+
|
||||
` LEFT JOIN zitadel.projections.orgs as r ON zitadel.projections.project_grants.resource_owner = r.id`+
|
||||
` LEFT JOIN zitadel.projections.orgs as o ON zitadel.projections.project_grants.granted_org_id = o.id`),
|
||||
` FROM projections.project_grants `+
|
||||
` LEFT JOIN projections.projects ON projections.project_grants.project_id = projections.projects.id `+
|
||||
` LEFT JOIN projections.orgs as r ON projections.project_grants.resource_owner = r.id`+
|
||||
` LEFT JOIN projections.orgs as o ON projections.project_grants.granted_org_id = o.id`),
|
||||
[]string{
|
||||
"project_id",
|
||||
"grant_id",
|
||||
@@ -470,23 +471,23 @@ func Test_ProjectGrantPrepares(t *testing.T) {
|
||||
prepare: prepareProjectGrantsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(` SELECT zitadel.projections.project_grants.project_id,`+
|
||||
` zitadel.projections.project_grants.grant_id,`+
|
||||
` zitadel.projections.project_grants.creation_date,`+
|
||||
` zitadel.projections.project_grants.change_date,`+
|
||||
` zitadel.projections.project_grants.resource_owner,`+
|
||||
` zitadel.projections.project_grants.state,`+
|
||||
` zitadel.projections.project_grants.sequence,`+
|
||||
` zitadel.projections.projects.name,`+
|
||||
` zitadel.projections.project_grants.granted_org_id,`+
|
||||
regexp.QuoteMeta(` SELECT projections.project_grants.project_id,`+
|
||||
` projections.project_grants.grant_id,`+
|
||||
` projections.project_grants.creation_date,`+
|
||||
` projections.project_grants.change_date,`+
|
||||
` projections.project_grants.resource_owner,`+
|
||||
` projections.project_grants.state,`+
|
||||
` projections.project_grants.sequence,`+
|
||||
` projections.projects.name,`+
|
||||
` projections.project_grants.granted_org_id,`+
|
||||
` o.name,`+
|
||||
` zitadel.projections.project_grants.granted_role_keys,`+
|
||||
` projections.project_grants.granted_role_keys,`+
|
||||
` r.name,`+
|
||||
` COUNT(*) OVER () `+
|
||||
` FROM zitadel.projections.project_grants `+
|
||||
` LEFT JOIN zitadel.projections.projects ON zitadel.projections.project_grants.project_id = zitadel.projections.projects.id `+
|
||||
` LEFT JOIN zitadel.projections.orgs as r ON zitadel.projections.project_grants.resource_owner = r.id`+
|
||||
` LEFT JOIN zitadel.projections.orgs as o ON zitadel.projections.project_grants.granted_org_id = o.id`),
|
||||
` FROM projections.project_grants `+
|
||||
` LEFT JOIN projections.projects ON projections.project_grants.project_id = projections.projects.id `+
|
||||
` LEFT JOIN projections.orgs as r ON projections.project_grants.resource_owner = r.id`+
|
||||
` LEFT JOIN projections.orgs as o ON projections.project_grants.granted_org_id = o.id`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
@@ -503,22 +504,22 @@ func Test_ProjectGrantPrepares(t *testing.T) {
|
||||
prepare: prepareProjectGrantQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(` SELECT zitadel.projections.project_grants.project_id,`+
|
||||
` zitadel.projections.project_grants.grant_id,`+
|
||||
` zitadel.projections.project_grants.creation_date,`+
|
||||
` zitadel.projections.project_grants.change_date,`+
|
||||
` zitadel.projections.project_grants.resource_owner,`+
|
||||
` zitadel.projections.project_grants.state,`+
|
||||
` zitadel.projections.project_grants.sequence,`+
|
||||
` zitadel.projections.projects.name,`+
|
||||
` zitadel.projections.project_grants.granted_org_id,`+
|
||||
regexp.QuoteMeta(` SELECT projections.project_grants.project_id,`+
|
||||
` projections.project_grants.grant_id,`+
|
||||
` projections.project_grants.creation_date,`+
|
||||
` projections.project_grants.change_date,`+
|
||||
` projections.project_grants.resource_owner,`+
|
||||
` projections.project_grants.state,`+
|
||||
` projections.project_grants.sequence,`+
|
||||
` projections.projects.name,`+
|
||||
` projections.project_grants.granted_org_id,`+
|
||||
` o.name,`+
|
||||
` zitadel.projections.project_grants.granted_role_keys,`+
|
||||
` projections.project_grants.granted_role_keys,`+
|
||||
` r.name`+
|
||||
` FROM zitadel.projections.project_grants `+
|
||||
` LEFT JOIN zitadel.projections.projects ON zitadel.projections.project_grants.project_id = zitadel.projections.projects.id `+
|
||||
` LEFT JOIN zitadel.projections.orgs as r ON zitadel.projections.project_grants.resource_owner = r.id`+
|
||||
` LEFT JOIN zitadel.projections.orgs as o ON zitadel.projections.project_grants.granted_org_id = o.id`),
|
||||
` FROM projections.project_grants `+
|
||||
` LEFT JOIN projections.projects ON projections.project_grants.project_id = projections.projects.id `+
|
||||
` LEFT JOIN projections.orgs as r ON projections.project_grants.resource_owner = r.id`+
|
||||
` LEFT JOIN projections.orgs as o ON projections.project_grants.granted_org_id = o.id`),
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -536,22 +537,22 @@ func Test_ProjectGrantPrepares(t *testing.T) {
|
||||
prepare: prepareProjectGrantQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(` SELECT zitadel.projections.project_grants.project_id,`+
|
||||
` zitadel.projections.project_grants.grant_id,`+
|
||||
` zitadel.projections.project_grants.creation_date,`+
|
||||
` zitadel.projections.project_grants.change_date,`+
|
||||
` zitadel.projections.project_grants.resource_owner,`+
|
||||
` zitadel.projections.project_grants.state,`+
|
||||
` zitadel.projections.project_grants.sequence,`+
|
||||
` zitadel.projections.projects.name,`+
|
||||
` zitadel.projections.project_grants.granted_org_id,`+
|
||||
regexp.QuoteMeta(` SELECT projections.project_grants.project_id,`+
|
||||
` projections.project_grants.grant_id,`+
|
||||
` projections.project_grants.creation_date,`+
|
||||
` projections.project_grants.change_date,`+
|
||||
` projections.project_grants.resource_owner,`+
|
||||
` projections.project_grants.state,`+
|
||||
` projections.project_grants.sequence,`+
|
||||
` projections.projects.name,`+
|
||||
` projections.project_grants.granted_org_id,`+
|
||||
` o.name,`+
|
||||
` zitadel.projections.project_grants.granted_role_keys,`+
|
||||
` projections.project_grants.granted_role_keys,`+
|
||||
` r.name`+
|
||||
` FROM zitadel.projections.project_grants `+
|
||||
` LEFT JOIN zitadel.projections.projects ON zitadel.projections.project_grants.project_id = zitadel.projections.projects.id `+
|
||||
` LEFT JOIN zitadel.projections.orgs as r ON zitadel.projections.project_grants.resource_owner = r.id`+
|
||||
` LEFT JOIN zitadel.projections.orgs as o ON zitadel.projections.project_grants.granted_org_id = o.id`),
|
||||
` FROM projections.project_grants `+
|
||||
` LEFT JOIN projections.projects ON projections.project_grants.project_id = projections.projects.id `+
|
||||
` LEFT JOIN projections.orgs as r ON projections.project_grants.resource_owner = r.id`+
|
||||
` LEFT JOIN projections.orgs as o ON projections.project_grants.granted_org_id = o.id`),
|
||||
[]string{
|
||||
"project_id",
|
||||
"grant_id",
|
||||
@@ -602,22 +603,22 @@ func Test_ProjectGrantPrepares(t *testing.T) {
|
||||
prepare: prepareProjectGrantQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(` SELECT zitadel.projections.project_grants.project_id,`+
|
||||
` zitadel.projections.project_grants.grant_id,`+
|
||||
` zitadel.projections.project_grants.creation_date,`+
|
||||
` zitadel.projections.project_grants.change_date,`+
|
||||
` zitadel.projections.project_grants.resource_owner,`+
|
||||
` zitadel.projections.project_grants.state,`+
|
||||
` zitadel.projections.project_grants.sequence,`+
|
||||
` zitadel.projections.projects.name,`+
|
||||
` zitadel.projections.project_grants.granted_org_id,`+
|
||||
regexp.QuoteMeta(` SELECT projections.project_grants.project_id,`+
|
||||
` projections.project_grants.grant_id,`+
|
||||
` projections.project_grants.creation_date,`+
|
||||
` projections.project_grants.change_date,`+
|
||||
` projections.project_grants.resource_owner,`+
|
||||
` projections.project_grants.state,`+
|
||||
` projections.project_grants.sequence,`+
|
||||
` projections.projects.name,`+
|
||||
` projections.project_grants.granted_org_id,`+
|
||||
` o.name,`+
|
||||
` zitadel.projections.project_grants.granted_role_keys,`+
|
||||
` projections.project_grants.granted_role_keys,`+
|
||||
` r.name`+
|
||||
` FROM zitadel.projections.project_grants `+
|
||||
` LEFT JOIN zitadel.projections.projects ON zitadel.projections.project_grants.project_id = zitadel.projections.projects.id `+
|
||||
` LEFT JOIN zitadel.projections.orgs as r ON zitadel.projections.project_grants.resource_owner = r.id`+
|
||||
` LEFT JOIN zitadel.projections.orgs as o ON zitadel.projections.project_grants.granted_org_id = o.id`),
|
||||
` FROM projections.project_grants `+
|
||||
` LEFT JOIN projections.projects ON projections.project_grants.project_id = projections.projects.id `+
|
||||
` LEFT JOIN projections.orgs as r ON projections.project_grants.resource_owner = r.id`+
|
||||
` LEFT JOIN projections.orgs as o ON projections.project_grants.granted_org_id = o.id`),
|
||||
[]string{
|
||||
"project_id",
|
||||
"grant_id",
|
||||
@@ -668,22 +669,22 @@ func Test_ProjectGrantPrepares(t *testing.T) {
|
||||
prepare: prepareProjectGrantQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(` SELECT zitadel.projections.project_grants.project_id,`+
|
||||
` zitadel.projections.project_grants.grant_id,`+
|
||||
` zitadel.projections.project_grants.creation_date,`+
|
||||
` zitadel.projections.project_grants.change_date,`+
|
||||
` zitadel.projections.project_grants.resource_owner,`+
|
||||
` zitadel.projections.project_grants.state,`+
|
||||
` zitadel.projections.project_grants.sequence,`+
|
||||
` zitadel.projections.projects.name,`+
|
||||
` zitadel.projections.project_grants.granted_org_id,`+
|
||||
regexp.QuoteMeta(` SELECT projections.project_grants.project_id,`+
|
||||
` projections.project_grants.grant_id,`+
|
||||
` projections.project_grants.creation_date,`+
|
||||
` projections.project_grants.change_date,`+
|
||||
` projections.project_grants.resource_owner,`+
|
||||
` projections.project_grants.state,`+
|
||||
` projections.project_grants.sequence,`+
|
||||
` projections.projects.name,`+
|
||||
` projections.project_grants.granted_org_id,`+
|
||||
` o.name,`+
|
||||
` zitadel.projections.project_grants.granted_role_keys,`+
|
||||
` projections.project_grants.granted_role_keys,`+
|
||||
` r.name`+
|
||||
` FROM zitadel.projections.project_grants `+
|
||||
` LEFT JOIN zitadel.projections.projects ON zitadel.projections.project_grants.project_id = zitadel.projections.projects.id `+
|
||||
` LEFT JOIN zitadel.projections.orgs as r ON zitadel.projections.project_grants.resource_owner = r.id`+
|
||||
` LEFT JOIN zitadel.projections.orgs as o ON zitadel.projections.project_grants.granted_org_id = o.id`),
|
||||
` FROM projections.project_grants `+
|
||||
` LEFT JOIN projections.projects ON projections.project_grants.project_id = projections.projects.id `+
|
||||
` LEFT JOIN projections.orgs as r ON projections.project_grants.resource_owner = r.id`+
|
||||
` LEFT JOIN projections.orgs as o ON projections.project_grants.granted_org_id = o.id`),
|
||||
[]string{
|
||||
"project_id",
|
||||
"grant_id",
|
||||
@@ -734,22 +735,22 @@ func Test_ProjectGrantPrepares(t *testing.T) {
|
||||
prepare: prepareProjectGrantQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(` SELECT zitadel.projections.project_grants.project_id,`+
|
||||
` zitadel.projections.project_grants.grant_id,`+
|
||||
` zitadel.projections.project_grants.creation_date,`+
|
||||
` zitadel.projections.project_grants.change_date,`+
|
||||
` zitadel.projections.project_grants.resource_owner,`+
|
||||
` zitadel.projections.project_grants.state,`+
|
||||
` zitadel.projections.project_grants.sequence,`+
|
||||
` zitadel.projections.projects.name,`+
|
||||
` zitadel.projections.project_grants.granted_org_id,`+
|
||||
regexp.QuoteMeta(` SELECT projections.project_grants.project_id,`+
|
||||
` projections.project_grants.grant_id,`+
|
||||
` projections.project_grants.creation_date,`+
|
||||
` projections.project_grants.change_date,`+
|
||||
` projections.project_grants.resource_owner,`+
|
||||
` projections.project_grants.state,`+
|
||||
` projections.project_grants.sequence,`+
|
||||
` projections.projects.name,`+
|
||||
` projections.project_grants.granted_org_id,`+
|
||||
` o.name,`+
|
||||
` zitadel.projections.project_grants.granted_role_keys,`+
|
||||
` projections.project_grants.granted_role_keys,`+
|
||||
` r.name`+
|
||||
` FROM zitadel.projections.project_grants `+
|
||||
` LEFT JOIN zitadel.projections.projects ON zitadel.projections.project_grants.project_id = zitadel.projections.projects.id `+
|
||||
` LEFT JOIN zitadel.projections.orgs as r ON zitadel.projections.project_grants.resource_owner = r.id`+
|
||||
` LEFT JOIN zitadel.projections.orgs as o ON zitadel.projections.project_grants.granted_org_id = o.id`),
|
||||
` FROM projections.project_grants `+
|
||||
` LEFT JOIN projections.projects ON projections.project_grants.project_id = projections.projects.id `+
|
||||
` LEFT JOIN projections.orgs as r ON projections.project_grants.resource_owner = r.id`+
|
||||
` LEFT JOIN projections.orgs as o ON projections.project_grants.granted_org_id = o.id`),
|
||||
[]string{
|
||||
"project_id",
|
||||
"grant_id",
|
||||
@@ -800,22 +801,22 @@ func Test_ProjectGrantPrepares(t *testing.T) {
|
||||
prepare: prepareProjectGrantQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(` SELECT zitadel.projections.project_grants.project_id,`+
|
||||
` zitadel.projections.project_grants.grant_id,`+
|
||||
` zitadel.projections.project_grants.creation_date,`+
|
||||
` zitadel.projections.project_grants.change_date,`+
|
||||
` zitadel.projections.project_grants.resource_owner,`+
|
||||
` zitadel.projections.project_grants.state,`+
|
||||
` zitadel.projections.project_grants.sequence,`+
|
||||
` zitadel.projections.projects.name,`+
|
||||
` zitadel.projections.project_grants.granted_org_id,`+
|
||||
regexp.QuoteMeta(` SELECT projections.project_grants.project_id,`+
|
||||
` projections.project_grants.grant_id,`+
|
||||
` projections.project_grants.creation_date,`+
|
||||
` projections.project_grants.change_date,`+
|
||||
` projections.project_grants.resource_owner,`+
|
||||
` projections.project_grants.state,`+
|
||||
` projections.project_grants.sequence,`+
|
||||
` projections.projects.name,`+
|
||||
` projections.project_grants.granted_org_id,`+
|
||||
` o.name,`+
|
||||
` zitadel.projections.project_grants.granted_role_keys,`+
|
||||
` projections.project_grants.granted_role_keys,`+
|
||||
` r.name`+
|
||||
` FROM zitadel.projections.project_grants `+
|
||||
` LEFT JOIN zitadel.projections.projects ON zitadel.projections.project_grants.project_id = zitadel.projections.projects.id `+
|
||||
` LEFT JOIN zitadel.projections.orgs as r ON zitadel.projections.project_grants.resource_owner = r.id`+
|
||||
` LEFT JOIN zitadel.projections.orgs as o ON zitadel.projections.project_grants.granted_org_id = o.id`),
|
||||
` FROM projections.project_grants `+
|
||||
` LEFT JOIN projections.projects ON projections.project_grants.project_id = projections.projects.id `+
|
||||
` LEFT JOIN projections.orgs as r ON projections.project_grants.resource_owner = r.id`+
|
||||
` LEFT JOIN projections.orgs as o ON projections.project_grants.granted_org_id = o.id`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
"github.com/lib/pq"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/query/projection"
|
||||
)
|
||||
@@ -40,6 +42,10 @@ var (
|
||||
name: projection.MemberResourceOwner,
|
||||
table: projectMemberTable,
|
||||
}
|
||||
ProjectMemberInstanceID = Column{
|
||||
name: projection.MemberInstanceID,
|
||||
table: projectMemberTable,
|
||||
}
|
||||
ProjectMemberProjectID = Column{
|
||||
name: projection.ProjectMemberProjectIDCol,
|
||||
table: projectMemberTable,
|
||||
@@ -59,7 +65,10 @@ func (q *ProjectMembersQuery) toQuery(query sq.SelectBuilder) sq.SelectBuilder {
|
||||
|
||||
func (q *Queries) ProjectMembers(ctx context.Context, queries *ProjectMembersQuery) (*Members, error) {
|
||||
query, scan := prepareProjectMembersQuery()
|
||||
stmt, args, err := queries.toQuery(query).ToSql()
|
||||
stmt, args, err := queries.toQuery(query).
|
||||
Where(sq.Eq{
|
||||
ProjectMemberInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInvalidArgument(err, "QUERY-T8CuT", "Errors.Query.InvalidRequest")
|
||||
}
|
||||
|
||||
@@ -19,22 +19,22 @@ var (
|
||||
", members.resource_owner" +
|
||||
", members.user_id" +
|
||||
", members.roles" +
|
||||
", zitadel.projections.login_names.login_name" +
|
||||
", zitadel.projections.users_humans.email" +
|
||||
", zitadel.projections.users_humans.first_name" +
|
||||
", zitadel.projections.users_humans.last_name" +
|
||||
", zitadel.projections.users_humans.display_name" +
|
||||
", zitadel.projections.users_machines.name" +
|
||||
", zitadel.projections.users_humans.avatar_key" +
|
||||
", projections.login_names.login_name" +
|
||||
", projections.users_humans.email" +
|
||||
", projections.users_humans.first_name" +
|
||||
", projections.users_humans.last_name" +
|
||||
", projections.users_humans.display_name" +
|
||||
", projections.users_machines.name" +
|
||||
", projections.users_humans.avatar_key" +
|
||||
", COUNT(*) OVER () " +
|
||||
"FROM zitadel.projections.project_members as members " +
|
||||
"LEFT JOIN zitadel.projections.users_humans " +
|
||||
"ON members.user_id = zitadel.projections.users_humans.user_id " +
|
||||
"LEFT JOIN zitadel.projections.users_machines " +
|
||||
"ON members.user_id = zitadel.projections.users_machines.user_id " +
|
||||
"LEFT JOIN zitadel.projections.login_names " +
|
||||
"ON members.user_id = zitadel.projections.login_names.user_id " +
|
||||
"WHERE zitadel.projections.login_names.is_primary = $1")
|
||||
"FROM projections.project_members as members " +
|
||||
"LEFT JOIN projections.users_humans " +
|
||||
"ON members.user_id = projections.users_humans.user_id " +
|
||||
"LEFT JOIN projections.users_machines " +
|
||||
"ON members.user_id = projections.users_machines.user_id " +
|
||||
"LEFT JOIN projections.login_names " +
|
||||
"ON members.user_id = projections.login_names.user_id " +
|
||||
"WHERE projections.login_names.is_primary = $1")
|
||||
projectMembersColumns = []string{
|
||||
"creation_date",
|
||||
"change_date",
|
||||
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
"time"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/query/projection"
|
||||
)
|
||||
@@ -27,6 +29,10 @@ var (
|
||||
name: projection.ProjectRoleColumnResourceOwner,
|
||||
table: projectRolesTable,
|
||||
}
|
||||
ProjectRoleColumnInstanceID = Column{
|
||||
name: projection.ProjectRoleColumnInstanceID,
|
||||
table: projectRolesTable,
|
||||
}
|
||||
ProjectRoleColumnSequence = Column{
|
||||
name: projection.ProjectRoleColumnSequence,
|
||||
table: projectRolesTable,
|
||||
@@ -79,8 +85,9 @@ func (q *Queries) ProjectRoleByID(ctx context.Context, projectID, key string) (*
|
||||
stmt, scan := prepareProjectRoleQuery()
|
||||
query, args, err := stmt.
|
||||
Where(sq.Eq{
|
||||
ProjectRoleColumnProjectID.identifier(): projectID,
|
||||
ProjectRoleColumnKey.identifier(): key,
|
||||
ProjectRoleColumnProjectID.identifier(): projectID,
|
||||
ProjectRoleColumnKey.identifier(): key,
|
||||
ProjectRoleColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "QUERY-2N0fs", "Errors.Query.SQLStatment")
|
||||
@@ -97,7 +104,10 @@ func (q *Queries) ExistsProjectRole(ctx context.Context, projectID, key string)
|
||||
|
||||
func (q *Queries) SearchProjectRoles(ctx context.Context, queries *ProjectRoleSearchQueries) (projects *ProjectRoles, err error) {
|
||||
query, scan := prepareProjectRolesQuery()
|
||||
stmt, args, err := queries.toQuery(query).ToSql()
|
||||
stmt, args, err := queries.toQuery(query).
|
||||
Where(sq.Eq{
|
||||
ProjectRoleColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInvalidArgument(err, "QUERY-3N9ff", "Errors.Query.InvalidRequest")
|
||||
}
|
||||
@@ -124,7 +134,10 @@ func (q *Queries) SearchGrantedProjectRoles(ctx context.Context, grantID, grante
|
||||
return nil, err
|
||||
}
|
||||
query, scan := prepareProjectRolesQuery()
|
||||
stmt, args, err := queries.toQuery(query).ToSql()
|
||||
stmt, args, err := queries.toQuery(query).
|
||||
Where(sq.Eq{
|
||||
ProjectRoleColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInvalidArgument(err, "QUERY-3N9ff", "Errors.Query.InvalidRequest")
|
||||
}
|
||||
|
||||
@@ -27,16 +27,16 @@ func Test_ProjectRolePrepares(t *testing.T) {
|
||||
prepare: prepareProjectRolesQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.project_roles.project_id,`+
|
||||
` zitadel.projections.project_roles.creation_date,`+
|
||||
` zitadel.projections.project_roles.change_date,`+
|
||||
` zitadel.projections.project_roles.resource_owner,`+
|
||||
` zitadel.projections.project_roles.sequence,`+
|
||||
` zitadel.projections.project_roles.role_key,`+
|
||||
` zitadel.projections.project_roles.display_name,`+
|
||||
` zitadel.projections.project_roles.group_name,`+
|
||||
regexp.QuoteMeta(`SELECT projections.project_roles.project_id,`+
|
||||
` projections.project_roles.creation_date,`+
|
||||
` projections.project_roles.change_date,`+
|
||||
` projections.project_roles.resource_owner,`+
|
||||
` projections.project_roles.sequence,`+
|
||||
` projections.project_roles.role_key,`+
|
||||
` projections.project_roles.display_name,`+
|
||||
` projections.project_roles.group_name,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.project_roles`),
|
||||
` FROM projections.project_roles`),
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -48,16 +48,16 @@ func Test_ProjectRolePrepares(t *testing.T) {
|
||||
prepare: prepareProjectRolesQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.project_roles.project_id,`+
|
||||
` zitadel.projections.project_roles.creation_date,`+
|
||||
` zitadel.projections.project_roles.change_date,`+
|
||||
` zitadel.projections.project_roles.resource_owner,`+
|
||||
` zitadel.projections.project_roles.sequence,`+
|
||||
` zitadel.projections.project_roles.role_key,`+
|
||||
` zitadel.projections.project_roles.display_name,`+
|
||||
` zitadel.projections.project_roles.group_name,`+
|
||||
regexp.QuoteMeta(`SELECT projections.project_roles.project_id,`+
|
||||
` projections.project_roles.creation_date,`+
|
||||
` projections.project_roles.change_date,`+
|
||||
` projections.project_roles.resource_owner,`+
|
||||
` projections.project_roles.sequence,`+
|
||||
` projections.project_roles.role_key,`+
|
||||
` projections.project_roles.display_name,`+
|
||||
` projections.project_roles.group_name,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.project_roles`),
|
||||
` FROM projections.project_roles`),
|
||||
[]string{
|
||||
"project_id",
|
||||
"creation_date",
|
||||
@@ -106,16 +106,16 @@ func Test_ProjectRolePrepares(t *testing.T) {
|
||||
prepare: prepareProjectRolesQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.project_roles.project_id,`+
|
||||
` zitadel.projections.project_roles.creation_date,`+
|
||||
` zitadel.projections.project_roles.change_date,`+
|
||||
` zitadel.projections.project_roles.resource_owner,`+
|
||||
` zitadel.projections.project_roles.sequence,`+
|
||||
` zitadel.projections.project_roles.role_key,`+
|
||||
` zitadel.projections.project_roles.display_name,`+
|
||||
` zitadel.projections.project_roles.group_name,`+
|
||||
regexp.QuoteMeta(`SELECT projections.project_roles.project_id,`+
|
||||
` projections.project_roles.creation_date,`+
|
||||
` projections.project_roles.change_date,`+
|
||||
` projections.project_roles.resource_owner,`+
|
||||
` projections.project_roles.sequence,`+
|
||||
` projections.project_roles.role_key,`+
|
||||
` projections.project_roles.display_name,`+
|
||||
` projections.project_roles.group_name,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.project_roles`),
|
||||
` FROM projections.project_roles`),
|
||||
[]string{
|
||||
"project_id",
|
||||
"creation_date",
|
||||
@@ -184,16 +184,16 @@ func Test_ProjectRolePrepares(t *testing.T) {
|
||||
prepare: prepareProjectRolesQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.project_roles.project_id,`+
|
||||
` zitadel.projections.project_roles.creation_date,`+
|
||||
` zitadel.projections.project_roles.change_date,`+
|
||||
` zitadel.projections.project_roles.resource_owner,`+
|
||||
` zitadel.projections.project_roles.sequence,`+
|
||||
` zitadel.projections.project_roles.role_key,`+
|
||||
` zitadel.projections.project_roles.display_name,`+
|
||||
` zitadel.projections.project_roles.group_name,`+
|
||||
regexp.QuoteMeta(`SELECT projections.project_roles.project_id,`+
|
||||
` projections.project_roles.creation_date,`+
|
||||
` projections.project_roles.change_date,`+
|
||||
` projections.project_roles.resource_owner,`+
|
||||
` projections.project_roles.sequence,`+
|
||||
` projections.project_roles.role_key,`+
|
||||
` projections.project_roles.display_name,`+
|
||||
` projections.project_roles.group_name,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.project_roles`),
|
||||
` FROM projections.project_roles`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
@@ -210,15 +210,15 @@ func Test_ProjectRolePrepares(t *testing.T) {
|
||||
prepare: prepareProjectRoleQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.project_roles.project_id,`+
|
||||
` zitadel.projections.project_roles.creation_date,`+
|
||||
` zitadel.projections.project_roles.change_date,`+
|
||||
` zitadel.projections.project_roles.resource_owner,`+
|
||||
` zitadel.projections.project_roles.sequence,`+
|
||||
` zitadel.projections.project_roles.role_key,`+
|
||||
` zitadel.projections.project_roles.display_name,`+
|
||||
` zitadel.projections.project_roles.group_name`+
|
||||
` FROM zitadel.projections.project_roles`),
|
||||
regexp.QuoteMeta(`SELECT projections.project_roles.project_id,`+
|
||||
` projections.project_roles.creation_date,`+
|
||||
` projections.project_roles.change_date,`+
|
||||
` projections.project_roles.resource_owner,`+
|
||||
` projections.project_roles.sequence,`+
|
||||
` projections.project_roles.role_key,`+
|
||||
` projections.project_roles.display_name,`+
|
||||
` projections.project_roles.group_name`+
|
||||
` FROM projections.project_roles`),
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -236,15 +236,15 @@ func Test_ProjectRolePrepares(t *testing.T) {
|
||||
prepare: prepareProjectRoleQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.project_roles.project_id,`+
|
||||
` zitadel.projections.project_roles.creation_date,`+
|
||||
` zitadel.projections.project_roles.change_date,`+
|
||||
` zitadel.projections.project_roles.resource_owner,`+
|
||||
` zitadel.projections.project_roles.sequence,`+
|
||||
` zitadel.projections.project_roles.role_key,`+
|
||||
` zitadel.projections.project_roles.display_name,`+
|
||||
` zitadel.projections.project_roles.group_name`+
|
||||
` FROM zitadel.projections.project_roles`),
|
||||
regexp.QuoteMeta(`SELECT projections.project_roles.project_id,`+
|
||||
` projections.project_roles.creation_date,`+
|
||||
` projections.project_roles.change_date,`+
|
||||
` projections.project_roles.resource_owner,`+
|
||||
` projections.project_roles.sequence,`+
|
||||
` projections.project_roles.role_key,`+
|
||||
` projections.project_roles.display_name,`+
|
||||
` projections.project_roles.group_name`+
|
||||
` FROM projections.project_roles`),
|
||||
[]string{
|
||||
"project_id",
|
||||
"creation_date",
|
||||
@@ -283,15 +283,15 @@ func Test_ProjectRolePrepares(t *testing.T) {
|
||||
prepare: prepareProjectRoleQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.project_roles.project_id,`+
|
||||
` zitadel.projections.project_roles.creation_date,`+
|
||||
` zitadel.projections.project_roles.change_date,`+
|
||||
` zitadel.projections.project_roles.resource_owner,`+
|
||||
` zitadel.projections.project_roles.sequence,`+
|
||||
` zitadel.projections.project_roles.role_key,`+
|
||||
` zitadel.projections.project_roles.display_name,`+
|
||||
` zitadel.projections.project_roles.group_name`+
|
||||
` FROM zitadel.projections.project_roles`),
|
||||
regexp.QuoteMeta(`SELECT projections.project_roles.project_id,`+
|
||||
` projections.project_roles.creation_date,`+
|
||||
` projections.project_roles.change_date,`+
|
||||
` projections.project_roles.resource_owner,`+
|
||||
` projections.project_roles.sequence,`+
|
||||
` projections.project_roles.role_key,`+
|
||||
` projections.project_roles.display_name,`+
|
||||
` projections.project_roles.group_name`+
|
||||
` FROM projections.project_roles`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
|
||||
@@ -44,19 +44,19 @@ func Test_ProjectPrepares(t *testing.T) {
|
||||
prepare: prepareProjectsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.projects.id,`+
|
||||
` zitadel.projections.projects.creation_date,`+
|
||||
` zitadel.projections.projects.change_date,`+
|
||||
` zitadel.projections.projects.resource_owner,`+
|
||||
` zitadel.projections.projects.state,`+
|
||||
` zitadel.projections.projects.sequence,`+
|
||||
` zitadel.projections.projects.name,`+
|
||||
` zitadel.projections.projects.project_role_assertion,`+
|
||||
` zitadel.projections.projects.project_role_check,`+
|
||||
` zitadel.projections.projects.has_project_check,`+
|
||||
` zitadel.projections.projects.private_labeling_setting,`+
|
||||
regexp.QuoteMeta(`SELECT projections.projects.id,`+
|
||||
` projections.projects.creation_date,`+
|
||||
` projections.projects.change_date,`+
|
||||
` projections.projects.resource_owner,`+
|
||||
` projections.projects.state,`+
|
||||
` projections.projects.sequence,`+
|
||||
` projections.projects.name,`+
|
||||
` projections.projects.project_role_assertion,`+
|
||||
` projections.projects.project_role_check,`+
|
||||
` projections.projects.has_project_check,`+
|
||||
` projections.projects.private_labeling_setting,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.projects`),
|
||||
` FROM projections.projects`),
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -68,19 +68,19 @@ func Test_ProjectPrepares(t *testing.T) {
|
||||
prepare: prepareProjectsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.projects.id,`+
|
||||
` zitadel.projections.projects.creation_date,`+
|
||||
` zitadel.projections.projects.change_date,`+
|
||||
` zitadel.projections.projects.resource_owner,`+
|
||||
` zitadel.projections.projects.state,`+
|
||||
` zitadel.projections.projects.sequence,`+
|
||||
` zitadel.projections.projects.name,`+
|
||||
` zitadel.projections.projects.project_role_assertion,`+
|
||||
` zitadel.projections.projects.project_role_check,`+
|
||||
` zitadel.projections.projects.has_project_check,`+
|
||||
` zitadel.projections.projects.private_labeling_setting,`+
|
||||
regexp.QuoteMeta(`SELECT projections.projects.id,`+
|
||||
` projections.projects.creation_date,`+
|
||||
` projections.projects.change_date,`+
|
||||
` projections.projects.resource_owner,`+
|
||||
` projections.projects.state,`+
|
||||
` projections.projects.sequence,`+
|
||||
` projections.projects.name,`+
|
||||
` projections.projects.project_role_assertion,`+
|
||||
` projections.projects.project_role_check,`+
|
||||
` projections.projects.has_project_check,`+
|
||||
` projections.projects.private_labeling_setting,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.projects`),
|
||||
` FROM projections.projects`),
|
||||
[]string{
|
||||
"id",
|
||||
"creation_date",
|
||||
@@ -138,19 +138,19 @@ func Test_ProjectPrepares(t *testing.T) {
|
||||
prepare: prepareProjectsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.projects.id,`+
|
||||
` zitadel.projections.projects.creation_date,`+
|
||||
` zitadel.projections.projects.change_date,`+
|
||||
` zitadel.projections.projects.resource_owner,`+
|
||||
` zitadel.projections.projects.state,`+
|
||||
` zitadel.projections.projects.sequence,`+
|
||||
` zitadel.projections.projects.name,`+
|
||||
` zitadel.projections.projects.project_role_assertion,`+
|
||||
` zitadel.projections.projects.project_role_check,`+
|
||||
` zitadel.projections.projects.has_project_check,`+
|
||||
` zitadel.projections.projects.private_labeling_setting,`+
|
||||
regexp.QuoteMeta(`SELECT projections.projects.id,`+
|
||||
` projections.projects.creation_date,`+
|
||||
` projections.projects.change_date,`+
|
||||
` projections.projects.resource_owner,`+
|
||||
` projections.projects.state,`+
|
||||
` projections.projects.sequence,`+
|
||||
` projections.projects.name,`+
|
||||
` projections.projects.project_role_assertion,`+
|
||||
` projections.projects.project_role_check,`+
|
||||
` projections.projects.has_project_check,`+
|
||||
` projections.projects.private_labeling_setting,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.projects`),
|
||||
` FROM projections.projects`),
|
||||
[]string{
|
||||
"id",
|
||||
"creation_date",
|
||||
@@ -234,19 +234,19 @@ func Test_ProjectPrepares(t *testing.T) {
|
||||
prepare: prepareProjectsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.projects.id,`+
|
||||
` zitadel.projections.projects.creation_date,`+
|
||||
` zitadel.projections.projects.change_date,`+
|
||||
` zitadel.projections.projects.resource_owner,`+
|
||||
` zitadel.projections.projects.state,`+
|
||||
` zitadel.projections.projects.sequence,`+
|
||||
` zitadel.projections.projects.name,`+
|
||||
` zitadel.projections.projects.project_role_assertion,`+
|
||||
` zitadel.projections.projects.project_role_check,`+
|
||||
` zitadel.projections.projects.has_project_check,`+
|
||||
` zitadel.projections.projects.private_labeling_setting,`+
|
||||
regexp.QuoteMeta(`SELECT projections.projects.id,`+
|
||||
` projections.projects.creation_date,`+
|
||||
` projections.projects.change_date,`+
|
||||
` projections.projects.resource_owner,`+
|
||||
` projections.projects.state,`+
|
||||
` projections.projects.sequence,`+
|
||||
` projections.projects.name,`+
|
||||
` projections.projects.project_role_assertion,`+
|
||||
` projections.projects.project_role_check,`+
|
||||
` projections.projects.has_project_check,`+
|
||||
` projections.projects.private_labeling_setting,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM zitadel.projections.projects`),
|
||||
` FROM projections.projects`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
@@ -263,18 +263,18 @@ func Test_ProjectPrepares(t *testing.T) {
|
||||
prepare: prepareProjectQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
`SELECT zitadel.projections.projects.id,`+
|
||||
` zitadel.projections.projects.creation_date,`+
|
||||
` zitadel.projections.projects.change_date,`+
|
||||
` zitadel.projections.projects.resource_owner,`+
|
||||
` zitadel.projections.projects.state,`+
|
||||
` zitadel.projections.projects.sequence,`+
|
||||
` zitadel.projections.projects.name,`+
|
||||
` zitadel.projections.projects.project_role_assertion,`+
|
||||
` zitadel.projections.projects.project_role_check,`+
|
||||
` zitadel.projections.projects.has_project_check,`+
|
||||
` zitadel.projections.projects.private_labeling_setting`+
|
||||
` FROM zitadel.projections.projects`,
|
||||
`SELECT projections.projects.id,`+
|
||||
` projections.projects.creation_date,`+
|
||||
` projections.projects.change_date,`+
|
||||
` projections.projects.resource_owner,`+
|
||||
` projections.projects.state,`+
|
||||
` projections.projects.sequence,`+
|
||||
` projections.projects.name,`+
|
||||
` projections.projects.project_role_assertion,`+
|
||||
` projections.projects.project_role_check,`+
|
||||
` projections.projects.has_project_check,`+
|
||||
` projections.projects.private_labeling_setting`+
|
||||
` FROM projections.projects`,
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -292,18 +292,18 @@ func Test_ProjectPrepares(t *testing.T) {
|
||||
prepare: prepareProjectQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.projects.id,`+
|
||||
` zitadel.projections.projects.creation_date,`+
|
||||
` zitadel.projections.projects.change_date,`+
|
||||
` zitadel.projections.projects.resource_owner,`+
|
||||
` zitadel.projections.projects.state,`+
|
||||
` zitadel.projections.projects.sequence,`+
|
||||
` zitadel.projections.projects.name,`+
|
||||
` zitadel.projections.projects.project_role_assertion,`+
|
||||
` zitadel.projections.projects.project_role_check,`+
|
||||
` zitadel.projections.projects.has_project_check,`+
|
||||
` zitadel.projections.projects.private_labeling_setting`+
|
||||
` FROM zitadel.projections.projects`),
|
||||
regexp.QuoteMeta(`SELECT projections.projects.id,`+
|
||||
` projections.projects.creation_date,`+
|
||||
` projections.projects.change_date,`+
|
||||
` projections.projects.resource_owner,`+
|
||||
` projections.projects.state,`+
|
||||
` projections.projects.sequence,`+
|
||||
` projections.projects.name,`+
|
||||
` projections.projects.project_role_assertion,`+
|
||||
` projections.projects.project_role_check,`+
|
||||
` projections.projects.has_project_check,`+
|
||||
` projections.projects.private_labeling_setting`+
|
||||
` FROM projections.projects`),
|
||||
[]string{
|
||||
"id",
|
||||
"creation_date",
|
||||
@@ -351,18 +351,18 @@ func Test_ProjectPrepares(t *testing.T) {
|
||||
prepare: prepareProjectQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.projects.id,`+
|
||||
` zitadel.projections.projects.creation_date,`+
|
||||
` zitadel.projections.projects.change_date,`+
|
||||
` zitadel.projections.projects.resource_owner,`+
|
||||
` zitadel.projections.projects.state,`+
|
||||
` zitadel.projections.projects.sequence,`+
|
||||
` zitadel.projections.projects.name,`+
|
||||
` zitadel.projections.projects.project_role_assertion,`+
|
||||
` zitadel.projections.projects.project_role_check,`+
|
||||
` zitadel.projections.projects.has_project_check,`+
|
||||
` zitadel.projections.projects.private_labeling_setting`+
|
||||
` FROM zitadel.projections.projects`),
|
||||
regexp.QuoteMeta(`SELECT projections.projects.id,`+
|
||||
` projections.projects.creation_date,`+
|
||||
` projections.projects.change_date,`+
|
||||
` projections.projects.resource_owner,`+
|
||||
` projections.projects.state,`+
|
||||
` projections.projects.sequence,`+
|
||||
` projections.projects.name,`+
|
||||
` projections.projects.project_role_assertion,`+
|
||||
` projections.projects.project_role_check,`+
|
||||
` projections.projects.has_project_check,`+
|
||||
` projections.projects.private_labeling_setting`+
|
||||
` FROM projections.projects`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
|
||||
@@ -3,8 +3,6 @@ package projection
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/logging"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
@@ -14,11 +12,12 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
ActionTable = "zitadel.projections.actions"
|
||||
ActionTable = "projections.actions"
|
||||
ActionIDCol = "id"
|
||||
ActionCreationDateCol = "creation_date"
|
||||
ActionChangeDateCol = "change_date"
|
||||
ActionResourceOwnerCol = "resource_owner"
|
||||
ActionInstanceIDCol = "instance_id"
|
||||
ActionStateCol = "action_state"
|
||||
ActionSequenceCol = "sequence"
|
||||
ActionNameCol = "name"
|
||||
@@ -35,6 +34,24 @@ func NewActionProjection(ctx context.Context, config crdb.StatementHandlerConfig
|
||||
p := new(ActionProjection)
|
||||
config.ProjectionName = ActionTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(ActionIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(ActionCreationDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(ActionChangeDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(ActionResourceOwnerCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(ActionInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(ActionStateCol, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(ActionSequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(ActionNameCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(ActionScriptCol, crdb.ColumnTypeText, crdb.Default("")),
|
||||
crdb.NewColumn(ActionTimeoutCol, crdb.ColumnTypeInt64, crdb.Default(0)),
|
||||
crdb.NewColumn(ActionAllowedToFailCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
},
|
||||
crdb.NewPrimaryKey(ActionInstanceIDCol, ActionIDCol),
|
||||
crdb.NewIndex("ro_idx", []string{ActionResourceOwnerCol}),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
@@ -72,8 +89,7 @@ func (p *ActionProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *ActionProjection) reduceActionAdded(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*action.AddedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-Sgg31", "seq", event.Sequence, "expectedType", action.AddedEventType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-Dff21", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-Dff21", "reduce.wrong.event.type% s", action.AddedEventType)
|
||||
}
|
||||
return crdb.NewCreateStatement(
|
||||
e,
|
||||
@@ -82,6 +98,7 @@ func (p *ActionProjection) reduceActionAdded(event eventstore.Event) (*handler.S
|
||||
handler.NewCol(ActionCreationDateCol, e.CreationDate()),
|
||||
handler.NewCol(ActionChangeDateCol, e.CreationDate()),
|
||||
handler.NewCol(ActionResourceOwnerCol, e.Aggregate().ResourceOwner),
|
||||
handler.NewCol(ActionInstanceIDCol, e.Aggregate().InstanceID),
|
||||
handler.NewCol(ActionSequenceCol, e.Sequence()),
|
||||
handler.NewCol(ActionNameCol, e.Name),
|
||||
handler.NewCol(ActionScriptCol, e.Script),
|
||||
@@ -95,8 +112,7 @@ func (p *ActionProjection) reduceActionAdded(event eventstore.Event) (*handler.S
|
||||
func (p *ActionProjection) reduceActionChanged(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*action.ChangedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-Dg2th", "seq", event.Sequence, "expected", action.ChangedEventType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-Gg43d", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-Gg43d", "reduce.wrong.event.type %s", action.ChangedEventType)
|
||||
}
|
||||
values := []handler.Column{
|
||||
handler.NewCol(ActionChangeDateCol, e.CreationDate()),
|
||||
@@ -126,8 +142,7 @@ func (p *ActionProjection) reduceActionChanged(event eventstore.Event) (*handler
|
||||
func (p *ActionProjection) reduceActionDeactivated(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*action.DeactivatedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-Fhhjd", "seq", event.Sequence, "expectedType", action.DeactivatedEventType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-Fgh32", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-Fgh32", "reduce.wrong.event.type %s", action.DeactivatedEventType)
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
e,
|
||||
@@ -145,8 +160,7 @@ func (p *ActionProjection) reduceActionDeactivated(event eventstore.Event) (*han
|
||||
func (p *ActionProjection) reduceActionReactivated(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*action.ReactivatedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-Fg4r3", "seq", event.Sequence, "expectedType", action.ReactivatedEventType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-hwdqa", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-hwdqa", "reduce.wrong.event.type% s", action.ReactivatedEventType)
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
e,
|
||||
@@ -164,8 +178,7 @@ func (p *ActionProjection) reduceActionReactivated(event eventstore.Event) (*han
|
||||
func (p *ActionProjection) reduceActionRemoved(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*action.RemovedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-Dgwh2", "seq", event.Sequence, "expectedType", action.RemovedEventType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-Dgh2d", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-Dgh2d", "reduce.wrong.event.type% s", action.RemovedEventType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
e,
|
||||
|
||||
@@ -40,12 +40,13 @@ func TestActionProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO zitadel.projections.actions (id, creation_date, change_date, resource_owner, sequence, name, script, timeout, allowed_to_fail, action_state) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)",
|
||||
expectedStmt: "INSERT INTO projections.actions (id, creation_date, change_date, resource_owner, instance_id, sequence, name, script, timeout, allowed_to_fail, action_state) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
anyArg{},
|
||||
anyArg{},
|
||||
"ro-id",
|
||||
"instance-id",
|
||||
uint64(15),
|
||||
"name",
|
||||
"name(){}",
|
||||
@@ -76,7 +77,7 @@ func TestActionProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.actions SET (change_date, sequence, name, script) = ($1, $2, $3, $4) WHERE (id = $5)",
|
||||
expectedStmt: "UPDATE projections.actions SET (change_date, sequence, name, script) = ($1, $2, $3, $4) WHERE (id = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -107,7 +108,7 @@ func TestActionProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.actions SET (change_date, sequence, action_state) = ($1, $2, $3) WHERE (id = $4)",
|
||||
expectedStmt: "UPDATE projections.actions SET (change_date, sequence, action_state) = ($1, $2, $3) WHERE (id = $4)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -137,7 +138,7 @@ func TestActionProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.actions SET (change_date, sequence, action_state) = ($1, $2, $3) WHERE (id = $4)",
|
||||
expectedStmt: "UPDATE projections.actions SET (change_date, sequence, action_state) = ($1, $2, $3) WHERE (id = $4)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -167,7 +168,7 @@ func TestActionProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.actions WHERE (id = $1)",
|
||||
expectedStmt: "DELETE FROM projections.actions WHERE (id = $1)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
},
|
||||
|
||||
@@ -3,7 +3,6 @@ package projection
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/logging"
|
||||
"github.com/lib/pq"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
@@ -14,20 +13,104 @@ import (
|
||||
"github.com/caos/zitadel/internal/repository/project"
|
||||
)
|
||||
|
||||
const (
|
||||
AppProjectionTable = "projections.apps"
|
||||
AppAPITable = AppProjectionTable + "_" + appAPITableSuffix
|
||||
AppOIDCTable = AppProjectionTable + "_" + appOIDCTableSuffix
|
||||
|
||||
AppColumnID = "id"
|
||||
AppColumnName = "name"
|
||||
AppColumnProjectID = "project_id"
|
||||
AppColumnCreationDate = "creation_date"
|
||||
AppColumnChangeDate = "change_date"
|
||||
AppColumnResourceOwner = "resource_owner"
|
||||
AppColumnInstanceID = "instance_id"
|
||||
AppColumnState = "state"
|
||||
AppColumnSequence = "sequence"
|
||||
|
||||
appAPITableSuffix = "api_configs"
|
||||
AppAPIConfigColumnAppID = "app_id"
|
||||
AppAPIConfigColumnClientID = "client_id"
|
||||
AppAPIConfigColumnClientSecret = "client_secret"
|
||||
AppAPIConfigColumnAuthMethod = "auth_method"
|
||||
|
||||
appOIDCTableSuffix = "oidc_configs"
|
||||
AppOIDCConfigColumnAppID = "app_id"
|
||||
AppOIDCConfigColumnVersion = "version"
|
||||
AppOIDCConfigColumnClientID = "client_id"
|
||||
AppOIDCConfigColumnClientSecret = "client_secret"
|
||||
AppOIDCConfigColumnRedirectUris = "redirect_uris"
|
||||
AppOIDCConfigColumnResponseTypes = "response_types"
|
||||
AppOIDCConfigColumnGrantTypes = "grant_types"
|
||||
AppOIDCConfigColumnApplicationType = "application_type"
|
||||
AppOIDCConfigColumnAuthMethodType = "auth_method_type"
|
||||
AppOIDCConfigColumnPostLogoutRedirectUris = "post_logout_redirect_uris"
|
||||
AppOIDCConfigColumnDevMode = "is_dev_mode"
|
||||
AppOIDCConfigColumnAccessTokenType = "access_token_type"
|
||||
AppOIDCConfigColumnAccessTokenRoleAssertion = "access_token_role_assertion"
|
||||
AppOIDCConfigColumnIDTokenRoleAssertion = "id_token_role_assertion"
|
||||
AppOIDCConfigColumnIDTokenUserinfoAssertion = "id_token_userinfo_assertion"
|
||||
AppOIDCConfigColumnClockSkew = "clock_skew"
|
||||
AppOIDCConfigColumnAdditionalOrigins = "additional_origins"
|
||||
)
|
||||
|
||||
type AppProjection struct {
|
||||
crdb.StatementHandler
|
||||
}
|
||||
|
||||
const (
|
||||
AppProjectionTable = "zitadel.projections.apps"
|
||||
AppAPITable = AppProjectionTable + "_" + appAPITableSuffix
|
||||
AppOIDCTable = AppProjectionTable + "_" + appOIDCTableSuffix
|
||||
)
|
||||
|
||||
func NewAppProjection(ctx context.Context, config crdb.StatementHandlerConfig) *AppProjection {
|
||||
p := new(AppProjection)
|
||||
config.ProjectionName = AppProjectionTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewMultiTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(AppColumnID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AppColumnName, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AppColumnProjectID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AppColumnCreationDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(AppColumnChangeDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(AppColumnResourceOwner, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AppColumnInstanceID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AppColumnState, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(AppColumnSequence, crdb.ColumnTypeInt64),
|
||||
},
|
||||
crdb.NewPrimaryKey(AppColumnInstanceID, ActionIDCol),
|
||||
crdb.NewIndex("project_id_idx", []string{AppColumnProjectID}),
|
||||
),
|
||||
crdb.NewSuffixedTable([]*crdb.Column{
|
||||
crdb.NewColumn(AppAPIConfigColumnAppID, crdb.ColumnTypeText, crdb.DeleteCascade(AppColumnID)),
|
||||
crdb.NewColumn(AppAPIConfigColumnClientID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AppAPIConfigColumnClientSecret, crdb.ColumnTypeJSONB, crdb.Nullable()),
|
||||
crdb.NewColumn(AppAPIConfigColumnAuthMethod, crdb.ColumnTypeEnum),
|
||||
},
|
||||
crdb.NewPrimaryKey(AppAPIConfigColumnAppID),
|
||||
appAPITableSuffix,
|
||||
crdb.NewIndex("client_id_idx", []string{AppAPIConfigColumnClientID}),
|
||||
),
|
||||
crdb.NewSuffixedTable([]*crdb.Column{
|
||||
crdb.NewColumn(AppOIDCConfigColumnAppID, crdb.ColumnTypeText, crdb.DeleteCascade(AppColumnID)),
|
||||
crdb.NewColumn(AppOIDCConfigColumnVersion, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AppOIDCConfigColumnClientID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AppOIDCConfigColumnClientSecret, crdb.ColumnTypeJSONB, crdb.Nullable()),
|
||||
crdb.NewColumn(AppOIDCConfigColumnRedirectUris, crdb.ColumnTypeTextArray, crdb.Nullable()),
|
||||
crdb.NewColumn(AppOIDCConfigColumnResponseTypes, crdb.ColumnTypeEnumArray, crdb.Nullable()), //TODO: null?
|
||||
crdb.NewColumn(AppOIDCConfigColumnGrantTypes, crdb.ColumnTypeEnumArray, crdb.Nullable()), //TODO: null?
|
||||
crdb.NewColumn(AppOIDCConfigColumnApplicationType, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(AppOIDCConfigColumnAuthMethodType, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(AppOIDCConfigColumnPostLogoutRedirectUris, crdb.ColumnTypeTextArray, crdb.Nullable()),
|
||||
crdb.NewColumn(AppOIDCConfigColumnDevMode, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(AppOIDCConfigColumnAccessTokenType, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(AppOIDCConfigColumnAccessTokenRoleAssertion, crdb.ColumnTypeBool, crdb.Nullable()), //TODO: null?
|
||||
crdb.NewColumn(AppOIDCConfigColumnIDTokenRoleAssertion, crdb.ColumnTypeBool, crdb.Nullable()), //TODO: null?
|
||||
crdb.NewColumn(AppOIDCConfigColumnIDTokenUserinfoAssertion, crdb.ColumnTypeBool, crdb.Nullable()), //TODO: null?
|
||||
crdb.NewColumn(AppOIDCConfigColumnClockSkew, crdb.ColumnTypeInt64, crdb.Nullable()), //TODO: null?
|
||||
crdb.NewColumn(AppOIDCConfigColumnAdditionalOrigins, crdb.ColumnTypeTextArray, crdb.Nullable()),
|
||||
},
|
||||
crdb.NewPrimaryKey(AppOIDCConfigColumnAppID),
|
||||
appOIDCTableSuffix,
|
||||
crdb.NewIndex("client_id_idx", []string{AppOIDCConfigColumnClientID}),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
@@ -90,47 +173,10 @@ func (p *AppProjection) reducers() []handler.AggregateReducer {
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
AppColumnID = "id"
|
||||
AppColumnName = "name"
|
||||
AppColumnProjectID = "project_id"
|
||||
AppColumnCreationDate = "creation_date"
|
||||
AppColumnChangeDate = "change_date"
|
||||
AppColumnResourceOwner = "resource_owner"
|
||||
AppColumnState = "state"
|
||||
AppColumnSequence = "sequence"
|
||||
|
||||
appAPITableSuffix = "api_configs"
|
||||
AppAPIConfigColumnAppID = "app_id"
|
||||
AppAPIConfigColumnClientID = "client_id"
|
||||
AppAPIConfigColumnClientSecret = "client_secret"
|
||||
AppAPIConfigColumnAuthMethod = "auth_method"
|
||||
|
||||
appOIDCTableSuffix = "oidc_configs"
|
||||
AppOIDCConfigColumnAppID = "app_id"
|
||||
AppOIDCConfigColumnVersion = "version"
|
||||
AppOIDCConfigColumnClientID = "client_id"
|
||||
AppOIDCConfigColumnClientSecret = "client_secret"
|
||||
AppOIDCConfigColumnRedirectUris = "redirect_uris"
|
||||
AppOIDCConfigColumnResponseTypes = "response_types"
|
||||
AppOIDCConfigColumnGrantTypes = "grant_types"
|
||||
AppOIDCConfigColumnApplicationType = "application_type"
|
||||
AppOIDCConfigColumnAuthMethodType = "auth_method_type"
|
||||
AppOIDCConfigColumnPostLogoutRedirectUris = "post_logout_redirect_uris"
|
||||
AppOIDCConfigColumnDevMode = "is_dev_mode"
|
||||
AppOIDCConfigColumnAccessTokenType = "access_token_type"
|
||||
AppOIDCConfigColumnAccessTokenRoleAssertion = "access_token_role_assertion"
|
||||
AppOIDCConfigColumnIDTokenRoleAssertion = "id_token_role_assertion"
|
||||
AppOIDCConfigColumnIDTokenUserinfoAssertion = "id_token_userinfo_assertion"
|
||||
AppOIDCConfigColumnClockSkew = "clock_skew"
|
||||
AppOIDCConfigColumnAdditionalOrigins = "additional_origins"
|
||||
)
|
||||
|
||||
func (p *AppProjection) reduceAppAdded(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*project.ApplicationAddedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-OzK4m", "seq", event.Sequence(), "expectedType", project.ApplicationAddedType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-1xYE6", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-1xYE6", "reduce.wrong.event.type %s", project.ApplicationAddedType)
|
||||
}
|
||||
return crdb.NewCreateStatement(
|
||||
e,
|
||||
@@ -141,6 +187,7 @@ func (p *AppProjection) reduceAppAdded(event eventstore.Event) (*handler.Stateme
|
||||
handler.NewCol(AppColumnCreationDate, e.CreationDate()),
|
||||
handler.NewCol(AppColumnChangeDate, e.CreationDate()),
|
||||
handler.NewCol(AppColumnResourceOwner, e.Aggregate().ResourceOwner),
|
||||
handler.NewCol(AppColumnInstanceID, e.Aggregate().InstanceID),
|
||||
handler.NewCol(AppColumnState, domain.AppStateActive),
|
||||
handler.NewCol(AppColumnSequence, e.Sequence()),
|
||||
},
|
||||
@@ -150,8 +197,7 @@ func (p *AppProjection) reduceAppAdded(event eventstore.Event) (*handler.Stateme
|
||||
func (p *AppProjection) reduceAppChanged(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*project.ApplicationChangedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-4Fjh2", "seq", event.Sequence(), "expectedType", project.ApplicationChangedType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-ZJ8JA", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-ZJ8JA", "reduce.wrong.event.type %s", project.ApplicationChangedType)
|
||||
}
|
||||
if e.Name == "" {
|
||||
return crdb.NewNoOpStatement(event), nil
|
||||
@@ -172,8 +218,7 @@ func (p *AppProjection) reduceAppChanged(event eventstore.Event) (*handler.State
|
||||
func (p *AppProjection) reduceAppDeactivated(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*project.ApplicationDeactivatedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-hZ9to", "seq", event.Sequence(), "expectedType", project.ApplicationDeactivatedType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-MVWxZ", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-MVWxZ", "reduce.wrong.event.type %s", project.ApplicationDeactivatedType)
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
e,
|
||||
@@ -191,8 +236,7 @@ func (p *AppProjection) reduceAppDeactivated(event eventstore.Event) (*handler.S
|
||||
func (p *AppProjection) reduceAppReactivated(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*project.ApplicationReactivatedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-AbK3B", "seq", event.Sequence(), "expectedType", project.ApplicationReactivatedType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-D0HZO", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-D0HZO", "reduce.wrong.event.type %s", project.ApplicationReactivatedType)
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
e,
|
||||
@@ -210,8 +254,7 @@ func (p *AppProjection) reduceAppReactivated(event eventstore.Event) (*handler.S
|
||||
func (p *AppProjection) reduceAppRemoved(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*project.ApplicationRemovedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-tdRId", "seq", event.Sequence(), "expectedType", project.ApplicationRemovedType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-Y99aq", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-Y99aq", "reduce.wrong.event.type %s", project.ApplicationRemovedType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
e,
|
||||
@@ -224,8 +267,7 @@ func (p *AppProjection) reduceAppRemoved(event eventstore.Event) (*handler.State
|
||||
func (p *AppProjection) reduceProjectRemoved(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*project.ProjectRemovedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-ZxQnj", "seq", event.Sequence(), "expectedType", project.ProjectRemovedType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-DlUlO", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-DlUlO", "reduce.wrong.event.type %s", project.ProjectRemovedType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
e,
|
||||
@@ -238,8 +280,7 @@ func (p *AppProjection) reduceProjectRemoved(event eventstore.Event) (*handler.S
|
||||
func (p *AppProjection) reduceAPIConfigAdded(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*project.APIConfigAddedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-tdRId", "seq", event.Sequence(), "expectedType", project.APIConfigAddedType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-Y99aq", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-Y99aq", "reduce.wrong.event.type %s", project.APIConfigAddedType)
|
||||
}
|
||||
return crdb.NewMultiStatement(
|
||||
e,
|
||||
@@ -267,8 +308,7 @@ func (p *AppProjection) reduceAPIConfigAdded(event eventstore.Event) (*handler.S
|
||||
func (p *AppProjection) reduceAPIConfigChanged(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*project.APIConfigChangedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-C6b4f", "seq", event.Sequence(), "expectedType", project.APIConfigChangedType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-vnZKi", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-vnZKi", "reduce.wrong.event.type %s", project.APIConfigChangedType)
|
||||
}
|
||||
cols := make([]handler.Column, 0, 2)
|
||||
if e.ClientSecret != nil {
|
||||
@@ -304,8 +344,7 @@ func (p *AppProjection) reduceAPIConfigChanged(event eventstore.Event) (*handler
|
||||
func (p *AppProjection) reduceAPIConfigSecretChanged(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*project.APIConfigSecretChangedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-dssSI", "seq", event.Sequence(), "expectedType", project.APIConfigSecretChangedType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-ttb0I", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-ttb0I", "reduce.wrong.event.type %s", project.APIConfigSecretChangedType)
|
||||
}
|
||||
return crdb.NewMultiStatement(
|
||||
e,
|
||||
@@ -333,8 +372,7 @@ func (p *AppProjection) reduceAPIConfigSecretChanged(event eventstore.Event) (*h
|
||||
func (p *AppProjection) reduceOIDCConfigAdded(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*project.OIDCConfigAddedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-nlDQv", "seq", event.Sequence(), "expectedType", project.OIDCConfigAddedType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-GNHU1", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-GNHU1", "reduce.wrong.event.type %s", project.OIDCConfigAddedType)
|
||||
}
|
||||
return crdb.NewMultiStatement(
|
||||
e,
|
||||
@@ -375,8 +413,7 @@ func (p *AppProjection) reduceOIDCConfigAdded(event eventstore.Event) (*handler.
|
||||
func (p *AppProjection) reduceOIDCConfigChanged(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*project.OIDCConfigChangedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-nlDQv", "seq", event.Sequence(), "expectedType", project.OIDCConfigChangedType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-GNHU1", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-GNHU1", "reduce.wrong.event.type %s", project.OIDCConfigChangedType)
|
||||
}
|
||||
|
||||
cols := make([]handler.Column, 0, 15)
|
||||
@@ -451,8 +488,7 @@ func (p *AppProjection) reduceOIDCConfigChanged(event eventstore.Event) (*handle
|
||||
func (p *AppProjection) reduceOIDCConfigSecretChanged(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*project.OIDCConfigSecretChangedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-nlDQv", "seq", event.Sequence(), "expectedType", project.OIDCConfigSecretChangedType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-GNHU1", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-GNHU1", "reduce.wrong.event.type %s", project.OIDCConfigSecretChangedType)
|
||||
}
|
||||
return crdb.NewMultiStatement(
|
||||
e,
|
||||
|
||||
@@ -4,13 +4,14 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/lib/pq"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/eventstore/handler"
|
||||
"github.com/caos/zitadel/internal/eventstore/repository"
|
||||
"github.com/caos/zitadel/internal/repository/project"
|
||||
"github.com/lib/pq"
|
||||
)
|
||||
|
||||
func TestAppProjection_reduces(t *testing.T) {
|
||||
@@ -44,7 +45,7 @@ func TestAppProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO zitadel.projections.apps (id, name, project_id, creation_date, change_date, resource_owner, state, sequence) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)",
|
||||
expectedStmt: "INSERT INTO projections.apps (id, name, project_id, creation_date, change_date, resource_owner, instance_id, state, sequence) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
||||
expectedArgs: []interface{}{
|
||||
"app-id",
|
||||
"my-app",
|
||||
@@ -52,6 +53,7 @@ func TestAppProjection_reduces(t *testing.T) {
|
||||
anyArg{},
|
||||
anyArg{},
|
||||
"ro-id",
|
||||
"instance-id",
|
||||
domain.AppStateActive,
|
||||
uint64(15),
|
||||
},
|
||||
@@ -81,7 +83,7 @@ func TestAppProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.apps SET (name, change_date, sequence) = ($1, $2, $3) WHERE (id = $4)",
|
||||
expectedStmt: "UPDATE projections.apps SET (name, change_date, sequence) = ($1, $2, $3) WHERE (id = $4)",
|
||||
expectedArgs: []interface{}{
|
||||
"my-app",
|
||||
anyArg{},
|
||||
@@ -113,7 +115,7 @@ func TestAppProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.apps SET (state, change_date, sequence) = ($1, $2, $3) WHERE (id = $4)",
|
||||
expectedStmt: "UPDATE projections.apps SET (state, change_date, sequence) = ($1, $2, $3) WHERE (id = $4)",
|
||||
expectedArgs: []interface{}{
|
||||
domain.AppStateInactive,
|
||||
anyArg{},
|
||||
@@ -145,7 +147,7 @@ func TestAppProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.apps SET (state, change_date, sequence) = ($1, $2, $3) WHERE (id = $4)",
|
||||
expectedStmt: "UPDATE projections.apps SET (state, change_date, sequence) = ($1, $2, $3) WHERE (id = $4)",
|
||||
expectedArgs: []interface{}{
|
||||
domain.AppStateActive,
|
||||
anyArg{},
|
||||
@@ -177,7 +179,7 @@ func TestAppProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.apps WHERE (id = $1)",
|
||||
expectedStmt: "DELETE FROM projections.apps WHERE (id = $1)",
|
||||
expectedArgs: []interface{}{
|
||||
"app-id",
|
||||
},
|
||||
@@ -204,7 +206,7 @@ func TestAppProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.apps WHERE (project_id = $1)",
|
||||
expectedStmt: "DELETE FROM projections.apps WHERE (project_id = $1)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
},
|
||||
@@ -236,7 +238,7 @@ func TestAppProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO zitadel.projections.apps_api_configs (app_id, client_id, client_secret, auth_method) VALUES ($1, $2, $3, $4)",
|
||||
expectedStmt: "INSERT INTO projections.apps_api_configs (app_id, client_id, client_secret, auth_method) VALUES ($1, $2, $3, $4)",
|
||||
expectedArgs: []interface{}{
|
||||
"app-id",
|
||||
"client-id",
|
||||
@@ -245,7 +247,7 @@ func TestAppProjection_reduces(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.apps SET (change_date, sequence) = ($1, $2) WHERE (id = $3)",
|
||||
expectedStmt: "UPDATE projections.apps SET (change_date, sequence) = ($1, $2) WHERE (id = $3)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -279,7 +281,7 @@ func TestAppProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.apps_api_configs SET (client_secret, auth_method) = ($1, $2) WHERE (app_id = $3)",
|
||||
expectedStmt: "UPDATE projections.apps_api_configs SET (client_secret, auth_method) = ($1, $2) WHERE (app_id = $3)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
domain.APIAuthMethodTypePrivateKeyJWT,
|
||||
@@ -287,7 +289,7 @@ func TestAppProjection_reduces(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.apps SET (change_date, sequence) = ($1, $2) WHERE (id = $3)",
|
||||
expectedStmt: "UPDATE projections.apps SET (change_date, sequence) = ($1, $2) WHERE (id = $3)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -341,14 +343,14 @@ func TestAppProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.apps_api_configs SET (client_secret) = ($1) WHERE (app_id = $2)",
|
||||
expectedStmt: "UPDATE projections.apps_api_configs SET (client_secret) = ($1) WHERE (app_id = $2)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
"app-id",
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.apps SET (change_date, sequence) = ($1, $2) WHERE (id = $3)",
|
||||
expectedStmt: "UPDATE projections.apps SET (change_date, sequence) = ($1, $2) WHERE (id = $3)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -395,7 +397,7 @@ func TestAppProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO zitadel.projections.apps_oidc_configs (app_id, version, client_id, client_secret, redirect_uris, response_types, grant_types, application_type, auth_method_type, post_logout_redirect_uris, is_dev_mode, access_token_type, access_token_role_assertion, id_token_role_assertion, id_token_userinfo_assertion, clock_skew, additional_origins) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17)",
|
||||
expectedStmt: "INSERT INTO projections.apps_oidc_configs (app_id, version, client_id, client_secret, redirect_uris, response_types, grant_types, application_type, auth_method_type, post_logout_redirect_uris, is_dev_mode, access_token_type, access_token_role_assertion, id_token_role_assertion, id_token_userinfo_assertion, clock_skew, additional_origins) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17)",
|
||||
expectedArgs: []interface{}{
|
||||
"app-id",
|
||||
domain.OIDCVersionV1,
|
||||
@@ -417,7 +419,7 @@ func TestAppProjection_reduces(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.apps SET (change_date, sequence) = ($1, $2) WHERE (id = $3)",
|
||||
expectedStmt: "UPDATE projections.apps SET (change_date, sequence) = ($1, $2) WHERE (id = $3)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -462,7 +464,7 @@ func TestAppProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.apps_oidc_configs SET (version, redirect_uris, response_types, grant_types, application_type, auth_method_type, post_logout_redirect_uris, is_dev_mode, access_token_type, access_token_role_assertion, id_token_role_assertion, id_token_userinfo_assertion, clock_skew, additional_origins) = ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14) WHERE (app_id = $15)",
|
||||
expectedStmt: "UPDATE projections.apps_oidc_configs SET (version, redirect_uris, response_types, grant_types, application_type, auth_method_type, post_logout_redirect_uris, is_dev_mode, access_token_type, access_token_role_assertion, id_token_role_assertion, id_token_userinfo_assertion, clock_skew, additional_origins) = ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14) WHERE (app_id = $15)",
|
||||
expectedArgs: []interface{}{
|
||||
domain.OIDCVersionV1,
|
||||
pq.StringArray{"redirect.one.ch", "redirect.two.ch"},
|
||||
@@ -482,7 +484,7 @@ func TestAppProjection_reduces(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.apps SET (change_date, sequence) = ($1, $2) WHERE (id = $3)",
|
||||
expectedStmt: "UPDATE projections.apps SET (change_date, sequence) = ($1, $2) WHERE (id = $3)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -536,14 +538,14 @@ func TestAppProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.apps_oidc_configs SET (client_secret) = ($1) WHERE (app_id = $2)",
|
||||
expectedStmt: "UPDATE projections.apps_oidc_configs SET (client_secret) = ($1) WHERE (app_id = $2)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
"app-id",
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.apps SET (change_date, sequence) = ($1, $2) WHERE (id = $3)",
|
||||
expectedStmt: "UPDATE projections.apps SET (change_date, sequence) = ($1, $2) WHERE (id = $3)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
|
||||
@@ -4,8 +4,6 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/caos/logging"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
@@ -16,10 +14,11 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
AuthNKeyTable = "zitadel.projections.authn_keys"
|
||||
AuthNKeyTable = "projections.authn_keys"
|
||||
AuthNKeyIDCol = "id"
|
||||
AuthNKeyCreationDateCol = "creation_date"
|
||||
AuthNKeyResourceOwnerCol = "resource_owner"
|
||||
AuthNKeyInstanceIDCol = "instance_id"
|
||||
AuthNKeyAggregateIDCol = "aggregate_id"
|
||||
AuthNKeySequenceCol = "sequence"
|
||||
AuthNKeyObjectIDCol = "object_id"
|
||||
@@ -38,6 +37,26 @@ func NewAuthNKeyProjection(ctx context.Context, config crdb.StatementHandlerConf
|
||||
p := new(AuthNKeyProjection)
|
||||
config.ProjectionName = AuthNKeyTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(AuthNKeyIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AuthNKeyCreationDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(AuthNKeyResourceOwnerCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AuthNKeyInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AuthNKeyAggregateIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AuthNKeySequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(AuthNKeyObjectIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AuthNKeyExpirationCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(AuthNKeyIdentifierCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AuthNKeyPublicKeyCol, crdb.ColumnTypeBytes),
|
||||
crdb.NewColumn(AuthNKeyEnabledCol, crdb.ColumnTypeBool, crdb.Default(true)),
|
||||
crdb.NewColumn(AuthNKeyTypeCol, crdb.ColumnTypeEnum, crdb.Default(0)),
|
||||
},
|
||||
crdb.NewPrimaryKey(AuthNKeyInstanceIDCol, AuthNKeyIDCol),
|
||||
crdb.NewIndex("enabled_idx", []string{AuthNKeyEnabledCol}),
|
||||
crdb.NewIndex("identifier_idx", []string{AuthNKeyIdentifierCol}),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
@@ -121,8 +140,7 @@ func (p *AuthNKeyProjection) reduceAuthNKeyAdded(event eventstore.Event) (*handl
|
||||
authNKeyEvent.publicKey = e.PublicKey
|
||||
authNKeyEvent.keyType = e.KeyType
|
||||
default:
|
||||
logging.LogWithFields("PROJE-Dbr3g", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{project.ApplicationKeyAddedEventType, user.MachineKeyAddedEventType}).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "PROJE-Dgb32", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-Dgb32", "reduce.wrong.event.type %v", []eventstore.EventType{project.ApplicationKeyAddedEventType, user.MachineKeyAddedEventType})
|
||||
}
|
||||
return crdb.NewMultiStatement(
|
||||
&authNKeyEvent,
|
||||
@@ -131,6 +149,7 @@ func (p *AuthNKeyProjection) reduceAuthNKeyAdded(event eventstore.Event) (*handl
|
||||
handler.NewCol(AuthNKeyIDCol, authNKeyEvent.keyID),
|
||||
handler.NewCol(AuthNKeyCreationDateCol, authNKeyEvent.CreationDate()),
|
||||
handler.NewCol(AuthNKeyResourceOwnerCol, authNKeyEvent.Aggregate().ResourceOwner),
|
||||
handler.NewCol(AuthNKeyInstanceIDCol, authNKeyEvent.Aggregate().InstanceID),
|
||||
handler.NewCol(AuthNKeyAggregateIDCol, authNKeyEvent.Aggregate().ID),
|
||||
handler.NewCol(AuthNKeySequenceCol, authNKeyEvent.Sequence()),
|
||||
handler.NewCol(AuthNKeyObjectIDCol, authNKeyEvent.objectID),
|
||||
@@ -160,8 +179,7 @@ func (p *AuthNKeyProjection) reduceAuthNKeyEnabledChanged(event eventstore.Event
|
||||
appID = e.AppID
|
||||
enabled = *e.AuthMethodType == domain.OIDCAuthMethodTypePrivateKeyJWT
|
||||
default:
|
||||
logging.LogWithFields("PROJE-Db5u3", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{project.APIConfigChangedType, project.OIDCConfigChangedType}).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "PROJE-Dbrt1", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-Dbrt1", "reduce.wrong.event.type %v", []eventstore.EventType{project.APIConfigChangedType, project.OIDCConfigChangedType})
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
event,
|
||||
@@ -184,9 +202,7 @@ func (p *AuthNKeyProjection) reduceAuthNKeyRemoved(event eventstore.Event) (*han
|
||||
case *user.UserRemovedEvent:
|
||||
condition = handler.NewCond(AuthNKeyAggregateIDCol, e.Aggregate().ID)
|
||||
default:
|
||||
logging.LogWithFields("PROJE-Sfdg3", "seq", event.Sequence(), "expectedTypes",
|
||||
[]eventstore.EventType{project.ApplicationKeyRemovedEventType, project.ApplicationRemovedType, project.ProjectRemovedType, user.MachineKeyRemovedEventType, user.UserRemovedType}).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "PROJE-BGge42", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-BGge42", "reduce.wrong.event.type %v", []eventstore.EventType{project.ApplicationKeyRemovedEventType, project.ApplicationRemovedType, project.ProjectRemovedType, user.MachineKeyRemovedEventType, user.UserRemovedType})
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
event,
|
||||
|
||||
@@ -40,11 +40,12 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO zitadel.projections.authn_keys (id, creation_date, resource_owner, aggregate_id, sequence, object_id, expiration, identifier, public_key, type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)",
|
||||
expectedStmt: "INSERT INTO projections.authn_keys (id, creation_date, resource_owner, instance_id, aggregate_id, sequence, object_id, expiration, identifier, public_key, type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)",
|
||||
expectedArgs: []interface{}{
|
||||
"keyId",
|
||||
anyArg{},
|
||||
"ro-id",
|
||||
"instance-id",
|
||||
"agg-id",
|
||||
uint64(15),
|
||||
"appId",
|
||||
@@ -76,11 +77,12 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO zitadel.projections.authn_keys (id, creation_date, resource_owner, aggregate_id, sequence, object_id, expiration, identifier, public_key, type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)",
|
||||
expectedStmt: "INSERT INTO projections.authn_keys (id, creation_date, resource_owner, instance_id, aggregate_id, sequence, object_id, expiration, identifier, public_key, type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)",
|
||||
expectedArgs: []interface{}{
|
||||
"keyId",
|
||||
anyArg{},
|
||||
"ro-id",
|
||||
"instance-id",
|
||||
"agg-id",
|
||||
uint64(15),
|
||||
"agg-id",
|
||||
@@ -112,7 +114,7 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.authn_keys WHERE (id = $1)",
|
||||
expectedStmt: "DELETE FROM projections.authn_keys WHERE (id = $1)",
|
||||
expectedArgs: []interface{}{
|
||||
"keyId",
|
||||
},
|
||||
@@ -159,7 +161,7 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.authn_keys SET (enabled) = ($1) WHERE (object_id = $2)",
|
||||
expectedStmt: "UPDATE projections.authn_keys SET (enabled) = ($1) WHERE (object_id = $2)",
|
||||
expectedArgs: []interface{}{
|
||||
false,
|
||||
"appId",
|
||||
@@ -187,7 +189,7 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.authn_keys SET (enabled) = ($1) WHERE (object_id = $2)",
|
||||
expectedStmt: "UPDATE projections.authn_keys SET (enabled) = ($1) WHERE (object_id = $2)",
|
||||
expectedArgs: []interface{}{
|
||||
true,
|
||||
"appId",
|
||||
@@ -215,7 +217,7 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.authn_keys WHERE (id = $1)",
|
||||
expectedStmt: "DELETE FROM projections.authn_keys WHERE (id = $1)",
|
||||
expectedArgs: []interface{}{
|
||||
"keyId",
|
||||
},
|
||||
@@ -262,7 +264,7 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.authn_keys SET (enabled) = ($1) WHERE (object_id = $2)",
|
||||
expectedStmt: "UPDATE projections.authn_keys SET (enabled) = ($1) WHERE (object_id = $2)",
|
||||
expectedArgs: []interface{}{
|
||||
false,
|
||||
"appId",
|
||||
@@ -290,7 +292,7 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.authn_keys SET (enabled) = ($1) WHERE (object_id = $2)",
|
||||
expectedStmt: "UPDATE projections.authn_keys SET (enabled) = ($1) WHERE (object_id = $2)",
|
||||
expectedArgs: []interface{}{
|
||||
true,
|
||||
"appId",
|
||||
@@ -318,7 +320,7 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.authn_keys WHERE (id = $1)",
|
||||
expectedStmt: "DELETE FROM projections.authn_keys WHERE (id = $1)",
|
||||
expectedArgs: []interface{}{
|
||||
"keyId",
|
||||
},
|
||||
@@ -345,7 +347,7 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.authn_keys WHERE (object_id = $1)",
|
||||
expectedStmt: "DELETE FROM projections.authn_keys WHERE (object_id = $1)",
|
||||
expectedArgs: []interface{}{
|
||||
"appId",
|
||||
},
|
||||
@@ -372,7 +374,7 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.authn_keys WHERE (aggregate_id = $1)",
|
||||
expectedStmt: "DELETE FROM projections.authn_keys WHERE (aggregate_id = $1)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
},
|
||||
@@ -399,7 +401,7 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.authn_keys WHERE (id = $1)",
|
||||
expectedStmt: "DELETE FROM projections.authn_keys WHERE (id = $1)",
|
||||
expectedArgs: []interface{}{
|
||||
"keyId",
|
||||
},
|
||||
@@ -426,7 +428,7 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.authn_keys WHERE (aggregate_id = $1)",
|
||||
expectedStmt: "DELETE FROM projections.authn_keys WHERE (aggregate_id = $1)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
},
|
||||
|
||||
@@ -3,8 +3,6 @@ package projection
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/logging"
|
||||
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/eventstore/handler"
|
||||
@@ -14,14 +12,11 @@ import (
|
||||
"github.com/caos/zitadel/internal/repository/policy"
|
||||
)
|
||||
|
||||
type CustomTextProjection struct {
|
||||
crdb.StatementHandler
|
||||
}
|
||||
|
||||
const (
|
||||
CustomTextTable = "zitadel.projections.custom_texts"
|
||||
CustomTextTable = "projections.custom_texts"
|
||||
|
||||
CustomTextAggregateIDCol = "aggregate_id"
|
||||
CustomTextInstanceIDCol = "instance_id"
|
||||
CustomTextCreationDateCol = "creation_date"
|
||||
CustomTextChangeDateCol = "change_date"
|
||||
CustomTextSequenceCol = "sequence"
|
||||
@@ -32,10 +27,30 @@ const (
|
||||
CustomTextTextCol = "text"
|
||||
)
|
||||
|
||||
type CustomTextProjection struct {
|
||||
crdb.StatementHandler
|
||||
}
|
||||
|
||||
func NewCustomTextProjection(ctx context.Context, config crdb.StatementHandlerConfig) *CustomTextProjection {
|
||||
p := new(CustomTextProjection)
|
||||
config.ProjectionName = CustomTextTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(CustomTextAggregateIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(CustomTextInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(CustomTextCreationDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(CustomTextChangeDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(CustomTextSequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(CustomTextIsDefaultCol, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(CustomTextTemplateCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(CustomTextLanguageCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(CustomTextKeyCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(CustomTextTextCol, crdb.ColumnTypeText),
|
||||
},
|
||||
crdb.NewPrimaryKey(CustomTextInstanceIDCol, CustomTextAggregateIDCol, CustomTextTemplateCol, CustomTextKeyCol, CustomTextLanguageCol),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
@@ -90,13 +105,13 @@ func (p *CustomTextProjection) reduceSet(event eventstore.Event) (*handler.State
|
||||
customTextEvent = e.CustomTextSetEvent
|
||||
isDefault = true
|
||||
default:
|
||||
logging.LogWithFields("PROJE-g0Jfs", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.CustomTextSetEventType, iam.CustomTextSetEventType}).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "PROJE-KKfw4", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-KKfw4", "reduce.wrong.event.type %v", []eventstore.EventType{org.CustomTextSetEventType, iam.CustomTextSetEventType})
|
||||
}
|
||||
return crdb.NewUpsertStatement(
|
||||
&customTextEvent,
|
||||
[]handler.Column{
|
||||
handler.NewCol(CustomTextAggregateIDCol, customTextEvent.Aggregate().ID),
|
||||
handler.NewCol(CustomTextInstanceIDCol, customTextEvent.Aggregate().InstanceID),
|
||||
handler.NewCol(CustomTextCreationDateCol, customTextEvent.CreationDate()),
|
||||
handler.NewCol(CustomTextChangeDateCol, customTextEvent.CreationDate()),
|
||||
handler.NewCol(CustomTextSequenceCol, customTextEvent.Sequence()),
|
||||
@@ -116,8 +131,7 @@ func (p *CustomTextProjection) reduceRemoved(event eventstore.Event) (*handler.S
|
||||
case *iam.CustomTextRemovedEvent:
|
||||
customTextEvent = e.CustomTextRemovedEvent
|
||||
default:
|
||||
logging.LogWithFields("PROJE-2Nigw", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.CustomTextRemovedEventType, iam.CustomTextRemovedEventType}).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "PROJE-n9wJg", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-n9wJg", "reduce.wrong.event.type %v", []eventstore.EventType{org.CustomTextRemovedEventType, iam.CustomTextRemovedEventType})
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
&customTextEvent,
|
||||
@@ -137,8 +151,7 @@ func (p *CustomTextProjection) reduceTemplateRemoved(event eventstore.Event) (*h
|
||||
case *iam.CustomTextTemplateRemovedEvent:
|
||||
customTextEvent = e.CustomTextTemplateRemovedEvent
|
||||
default:
|
||||
logging.LogWithFields("PROJE-J9wfg", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.CustomTextTemplateRemovedEventType, iam.CustomTextTemplateRemovedEventType}).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "PROJE-29iPf", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-29iPf", "reduce.wrong.event.type %v", []eventstore.EventType{org.CustomTextTemplateRemovedEventType, iam.CustomTextTemplateRemovedEventType})
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
&customTextEvent,
|
||||
|
||||
@@ -44,9 +44,10 @@ func TestCustomTextProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPSERT INTO zitadel.projections.custom_texts (aggregate_id, creation_date, change_date, sequence, is_default, template, language, key, text) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
||||
expectedStmt: "UPSERT INTO projections.custom_texts (aggregate_id, instance_id, creation_date, change_date, sequence, is_default, template, language, key, text) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
"instance-id",
|
||||
anyArg{},
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -83,7 +84,7 @@ func TestCustomTextProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.custom_texts WHERE (aggregate_id = $1) AND (template = $2) AND (key = $3) AND (language = $4)",
|
||||
expectedStmt: "DELETE FROM projections.custom_texts WHERE (aggregate_id = $1) AND (template = $2) AND (key = $3) AND (language = $4)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
"InitCode",
|
||||
@@ -117,7 +118,7 @@ func TestCustomTextProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.custom_texts WHERE (aggregate_id = $1) AND (template = $2) AND (language = $3)",
|
||||
expectedStmt: "DELETE FROM projections.custom_texts WHERE (aggregate_id = $1) AND (template = $2) AND (language = $3)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
"InitCode",
|
||||
@@ -151,9 +152,10 @@ func TestCustomTextProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPSERT INTO zitadel.projections.custom_texts (aggregate_id, creation_date, change_date, sequence, is_default, template, language, key, text) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
||||
expectedStmt: "UPSERT INTO projections.custom_texts (aggregate_id, instance_id, creation_date, change_date, sequence, is_default, template, language, key, text) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
"instance-id",
|
||||
anyArg{},
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -190,7 +192,7 @@ func TestCustomTextProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.custom_texts WHERE (aggregate_id = $1) AND (template = $2) AND (key = $3) AND (language = $4)",
|
||||
expectedStmt: "DELETE FROM projections.custom_texts WHERE (aggregate_id = $1) AND (template = $2) AND (key = $3) AND (language = $4)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
"InitCode",
|
||||
@@ -224,7 +226,7 @@ func TestCustomTextProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.custom_texts WHERE (aggregate_id = $1) AND (template = $2) AND (language = $3)",
|
||||
expectedStmt: "DELETE FROM projections.custom_texts WHERE (aggregate_id = $1) AND (template = $2) AND (language = $3)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
"InitCode",
|
||||
|
||||
@@ -3,7 +3,6 @@ package projection
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/logging"
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/repository/settings"
|
||||
|
||||
@@ -14,18 +13,43 @@ import (
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
)
|
||||
|
||||
const (
|
||||
DebugNotificationProviderTable = "projections.notification_providers"
|
||||
|
||||
DebugNotificationProviderAggIDCol = "aggregate_id"
|
||||
DebugNotificationProviderCreationDateCol = "creation_date"
|
||||
DebugNotificationProviderChangeDateCol = "change_date"
|
||||
DebugNotificationProviderSequenceCol = "sequence"
|
||||
DebugNotificationProviderResourceOwnerCol = "resource_owner"
|
||||
DebugNotificationProviderInstanceIDCol = "instance_id"
|
||||
DebugNotificationProviderStateCol = "state"
|
||||
DebugNotificationProviderTypeCol = "provider_type"
|
||||
DebugNotificationProviderCompactCol = "compact"
|
||||
)
|
||||
|
||||
type DebugNotificationProviderProjection struct {
|
||||
crdb.StatementHandler
|
||||
}
|
||||
|
||||
const (
|
||||
DebugNotificationProviderTable = "zitadel.projections.notification_providers"
|
||||
)
|
||||
|
||||
func NewDebugNotificationProviderProjection(ctx context.Context, config crdb.StatementHandlerConfig) *DebugNotificationProviderProjection {
|
||||
p := &DebugNotificationProviderProjection{}
|
||||
config.ProjectionName = DebugNotificationProviderTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(DebugNotificationProviderAggIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(DebugNotificationProviderCreationDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(DebugNotificationProviderChangeDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(DebugNotificationProviderSequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(DebugNotificationProviderResourceOwnerCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(DebugNotificationProviderInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(DebugNotificationProviderStateCol, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(DebugNotificationProviderTypeCol, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(DebugNotificationProviderCompactCol, crdb.ColumnTypeBool),
|
||||
},
|
||||
crdb.NewPrimaryKey(DebugNotificationProviderInstanceIDCol, DebugNotificationProviderAggIDCol, DebugNotificationProviderTypeCol),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
@@ -64,17 +88,6 @@ func (p *DebugNotificationProviderProjection) reducers() []handler.AggregateRedu
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
DebugNotificationProviderAggIDCol = "aggregate_id"
|
||||
DebugNotificationProviderCreationDateCol = "creation_date"
|
||||
DebugNotificationProviderChangeDateCol = "change_date"
|
||||
DebugNotificationProviderSequenceCol = "sequence"
|
||||
DebugNotificationProviderResourceOwnerCol = "resource_owner"
|
||||
DebugNotificationProviderStateCol = "state"
|
||||
DebugNotificationProviderTypeCol = "provider_type"
|
||||
DebugNotificationProviderCompactCol = "compact"
|
||||
)
|
||||
|
||||
func (p *DebugNotificationProviderProjection) reduceDebugNotificationProviderAdded(event eventstore.Event) (*handler.Statement, error) {
|
||||
var providerEvent settings.DebugNotificationProviderAddedEvent
|
||||
var providerType domain.NotificationProviderType
|
||||
@@ -86,8 +99,7 @@ func (p *DebugNotificationProviderProjection) reduceDebugNotificationProviderAdd
|
||||
providerEvent = e.DebugNotificationProviderAddedEvent
|
||||
providerType = domain.NotificationProviderTypeLog
|
||||
default:
|
||||
logging.WithFields("seq", event.Sequence(), "expectedTypes", []eventstore.EventType{iam.DebugNotificationProviderFileAddedEventType, iam.DebugNotificationProviderLogAddedEventType}).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-pYPxS", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-pYPxS", "reduce.wrong.event.type %v", []eventstore.EventType{iam.DebugNotificationProviderFileAddedEventType, iam.DebugNotificationProviderLogAddedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewCreateStatement(&providerEvent, []handler.Column{
|
||||
@@ -96,6 +108,7 @@ func (p *DebugNotificationProviderProjection) reduceDebugNotificationProviderAdd
|
||||
handler.NewCol(DebugNotificationProviderChangeDateCol, providerEvent.CreationDate()),
|
||||
handler.NewCol(DebugNotificationProviderSequenceCol, providerEvent.Sequence()),
|
||||
handler.NewCol(DebugNotificationProviderResourceOwnerCol, providerEvent.Aggregate().ResourceOwner),
|
||||
handler.NewCol(DebugNotificationProviderInstanceIDCol, providerEvent.Aggregate().InstanceID),
|
||||
handler.NewCol(DebugNotificationProviderStateCol, domain.NotificationProviderStateActive),
|
||||
handler.NewCol(DebugNotificationProviderTypeCol, providerType),
|
||||
handler.NewCol(DebugNotificationProviderCompactCol, providerEvent.Compact),
|
||||
@@ -113,8 +126,7 @@ func (p *DebugNotificationProviderProjection) reduceDebugNotificationProviderCha
|
||||
providerEvent = e.DebugNotificationProviderChangedEvent
|
||||
providerType = domain.NotificationProviderTypeLog
|
||||
default:
|
||||
logging.WithFields("seq", event.Sequence(), "expectedTypes", []eventstore.EventType{iam.DebugNotificationProviderFileChangedEventType, iam.DebugNotificationProviderLogChangedEventType}).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-pYPxS", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-pYPxS", "reduce.wrong.event.type %v", []eventstore.EventType{iam.DebugNotificationProviderFileChangedEventType, iam.DebugNotificationProviderLogChangedEventType})
|
||||
}
|
||||
|
||||
cols := []handler.Column{
|
||||
@@ -146,8 +158,7 @@ func (p *DebugNotificationProviderProjection) reduceDebugNotificationProviderRem
|
||||
providerEvent = e.DebugNotificationProviderRemovedEvent
|
||||
providerType = domain.NotificationProviderTypeLog
|
||||
default:
|
||||
logging.WithFields("seq", event.Sequence(), "expectedTypes", []eventstore.EventType{iam.DebugNotificationProviderFileRemovedEventType, iam.DebugNotificationProviderLogRemovedEventType}).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-dow9f", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-dow9f", "reduce.wrong.event.type %v", []eventstore.EventType{iam.DebugNotificationProviderFileRemovedEventType, iam.DebugNotificationProviderLogRemovedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
|
||||
@@ -41,13 +41,14 @@ func TestDebugNotificationProviderProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO zitadel.projections.notification_providers (aggregate_id, creation_date, change_date, sequence, resource_owner, state, provider_type, compact) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)",
|
||||
expectedStmt: "INSERT INTO projections.notification_providers (aggregate_id, creation_date, change_date, sequence, resource_owner, instance_id, state, provider_type, compact) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
anyArg{},
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
"ro-id",
|
||||
"instance-id",
|
||||
domain.NotificationProviderStateActive,
|
||||
domain.NotificationProviderTypeFile,
|
||||
true,
|
||||
@@ -77,7 +78,7 @@ func TestDebugNotificationProviderProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.notification_providers SET (change_date, sequence, compact) = ($1, $2, $3) WHERE (aggregate_id = $4) AND (provider_type = $5)",
|
||||
expectedStmt: "UPDATE projections.notification_providers SET (change_date, sequence, compact) = ($1, $2, $3) WHERE (aggregate_id = $4) AND (provider_type = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -108,7 +109,7 @@ func TestDebugNotificationProviderProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.notification_providers WHERE (aggregate_id = $1) AND (provider_type = $2)",
|
||||
expectedStmt: "DELETE FROM projections.notification_providers WHERE (aggregate_id = $1) AND (provider_type = $2)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
domain.NotificationProviderTypeFile,
|
||||
@@ -138,13 +139,14 @@ func TestDebugNotificationProviderProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO zitadel.projections.notification_providers (aggregate_id, creation_date, change_date, sequence, resource_owner, state, provider_type, compact) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)",
|
||||
expectedStmt: "INSERT INTO projections.notification_providers (aggregate_id, creation_date, change_date, sequence, resource_owner, instance_id, state, provider_type, compact) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
anyArg{},
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
"ro-id",
|
||||
"instance-id",
|
||||
domain.NotificationProviderStateActive,
|
||||
domain.NotificationProviderTypeLog,
|
||||
true,
|
||||
@@ -174,7 +176,7 @@ func TestDebugNotificationProviderProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.notification_providers SET (change_date, sequence, compact) = ($1, $2, $3) WHERE (aggregate_id = $4) AND (provider_type = $5)",
|
||||
expectedStmt: "UPDATE projections.notification_providers SET (change_date, sequence, compact) = ($1, $2, $3) WHERE (aggregate_id = $4) AND (provider_type = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -205,7 +207,7 @@ func TestDebugNotificationProviderProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.notification_providers WHERE (aggregate_id = $1) AND (provider_type = $2)",
|
||||
expectedStmt: "DELETE FROM projections.notification_providers WHERE (aggregate_id = $1) AND (provider_type = $2)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
domain.NotificationProviderTypeLog,
|
||||
|
||||
@@ -26,6 +26,7 @@ func testEvent(
|
||||
Version: "v1",
|
||||
AggregateID: "agg-id",
|
||||
ResourceOwner: sql.NullString{String: "ro-id", Valid: true},
|
||||
InstanceID: sql.NullString{String: "instance-id", Valid: true},
|
||||
ID: "event-id",
|
||||
EditorService: "editor-svc",
|
||||
EditorUser: "editor-user",
|
||||
|
||||
@@ -3,8 +3,6 @@ package projection
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/logging"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
@@ -16,18 +14,79 @@ import (
|
||||
"github.com/caos/zitadel/internal/repository/org"
|
||||
)
|
||||
|
||||
const (
|
||||
FeatureTable = "projections.features"
|
||||
|
||||
FeatureAggregateIDCol = "aggregate_id"
|
||||
FeatureInstanceIDCol = "instance_id"
|
||||
FeatureChangeDateCol = "change_date"
|
||||
FeatureSequenceCol = "sequence"
|
||||
FeatureIsDefaultCol = "is_default"
|
||||
FeatureTierNameCol = "tier_name"
|
||||
FeatureTierDescriptionCol = "tier_description"
|
||||
FeatureStateCol = "state"
|
||||
FeatureStateDescriptionCol = "state_description"
|
||||
FeatureAuditLogRetentionCol = "audit_log_retention"
|
||||
FeatureLoginPolicyFactorsCol = "login_policy_factors"
|
||||
FeatureLoginPolicyIDPCol = "login_policy_idp"
|
||||
FeatureLoginPolicyPasswordlessCol = "login_policy_passwordless"
|
||||
FeatureLoginPolicyRegistrationCol = "login_policy_registration"
|
||||
FeatureLoginPolicyUsernameLoginCol = "login_policy_username_login"
|
||||
FeatureLoginPolicyPasswordResetCol = "login_policy_password_reset"
|
||||
FeaturePasswordComplexityPolicyCol = "password_complexity_policy"
|
||||
FeatureLabelPolicyPrivateLabelCol = "label_policy_private_label"
|
||||
FeatureLabelPolicyWatermarkCol = "label_policy_watermark"
|
||||
FeatureCustomDomainCol = "custom_domain"
|
||||
FeaturePrivacyPolicyCol = "privacy_policy"
|
||||
FeatureMetadataUserCol = "metadata_user"
|
||||
FeatureCustomTextMessageCol = "custom_text_message"
|
||||
FeatureCustomTextLoginCol = "custom_text_login"
|
||||
FeatureLockoutPolicyCol = "lockout_policy"
|
||||
FeatureActionsAllowedCol = "actions_allowed"
|
||||
FeatureMaxActionsCol = "max_actions"
|
||||
)
|
||||
|
||||
type FeatureProjection struct {
|
||||
crdb.StatementHandler
|
||||
}
|
||||
|
||||
const (
|
||||
FeatureTable = "zitadel.projections.features"
|
||||
)
|
||||
|
||||
func NewFeatureProjection(ctx context.Context, config crdb.StatementHandlerConfig) *FeatureProjection {
|
||||
p := new(FeatureProjection)
|
||||
config.ProjectionName = FeatureTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(FeatureAggregateIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(FeatureInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(FeatureChangeDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(FeatureSequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(FeatureIsDefaultCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(FeatureTierNameCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(FeatureTierDescriptionCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(FeatureStateCol, crdb.ColumnTypeEnum, crdb.Default(0)),
|
||||
crdb.NewColumn(FeatureStateDescriptionCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(FeatureAuditLogRetentionCol, crdb.ColumnTypeInt64, crdb.Default(0)),
|
||||
crdb.NewColumn(FeatureLoginPolicyFactorsCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(FeatureLoginPolicyIDPCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(FeatureLoginPolicyPasswordlessCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(FeatureLoginPolicyRegistrationCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(FeatureLoginPolicyUsernameLoginCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(FeatureLoginPolicyPasswordResetCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(FeaturePasswordComplexityPolicyCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(FeatureLabelPolicyPrivateLabelCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(FeatureLabelPolicyWatermarkCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(FeatureCustomDomainCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(FeaturePrivacyPolicyCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(FeatureMetadataUserCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(FeatureCustomTextMessageCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(FeatureCustomTextLoginCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(FeatureLockoutPolicyCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(FeatureActionsAllowedCol, crdb.ColumnTypeEnum, crdb.Default(0)),
|
||||
crdb.NewColumn(FeatureMaxActionsCol, crdb.ColumnTypeInt64, crdb.Default(0)),
|
||||
},
|
||||
crdb.NewPrimaryKey(FeatureInstanceIDCol, FeatureAggregateIDCol),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
@@ -59,35 +118,6 @@ func (p *FeatureProjection) reducers() []handler.AggregateReducer {
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
FeatureAggregateIDCol = "aggregate_id"
|
||||
FeatureChangeDateCol = "change_date"
|
||||
FeatureSequenceCol = "sequence"
|
||||
FeatureIsDefaultCol = "is_default"
|
||||
FeatureTierNameCol = "tier_name"
|
||||
FeatureTierDescriptionCol = "tier_description"
|
||||
FeatureStateCol = "state"
|
||||
FeatureStateDescriptionCol = "state_description"
|
||||
FeatureAuditLogRetentionCol = "audit_log_retention"
|
||||
FeatureLoginPolicyFactorsCol = "login_policy_factors"
|
||||
FeatureLoginPolicyIDPCol = "login_policy_idp"
|
||||
FeatureLoginPolicyPasswordlessCol = "login_policy_passwordless"
|
||||
FeatureLoginPolicyRegistrationCol = "login_policy_registration"
|
||||
FeatureLoginPolicyUsernameLoginCol = "login_policy_username_login"
|
||||
FeatureLoginPolicyPasswordResetCol = "login_policy_password_reset"
|
||||
FeaturePasswordComplexityPolicyCol = "password_complexity_policy"
|
||||
FeatureLabelPolicyPrivateLabelCol = "label_policy_private_label"
|
||||
FeatureLabelPolicyWatermarkCol = "label_policy_watermark"
|
||||
FeatureCustomDomainCol = "custom_domain"
|
||||
FeaturePrivacyPolicyCol = "privacy_policy"
|
||||
FeatureMetadataUserCol = "metadata_user"
|
||||
FeatureCustomTextMessageCol = "custom_text_message"
|
||||
FeatureCustomTextLoginCol = "custom_text_login"
|
||||
FeatureLockoutPolicyCol = "lockout_policy"
|
||||
FeatureActionsAllowedCol = "actions_allowed"
|
||||
FeatureMaxActionsCol = "max_actions"
|
||||
)
|
||||
|
||||
func (p *FeatureProjection) reduceFeatureSet(event eventstore.Event) (*handler.Statement, error) {
|
||||
var featureEvent features.FeaturesSetEvent
|
||||
var isDefault bool
|
||||
@@ -99,12 +129,12 @@ func (p *FeatureProjection) reduceFeatureSet(event eventstore.Event) (*handler.S
|
||||
featureEvent = e.FeaturesSetEvent
|
||||
isDefault = false
|
||||
default:
|
||||
logging.LogWithFields("HANDL-M9ets", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.FeaturesSetEventType, iam.FeaturesSetEventType}).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-K0erf", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-K0erf", "reduce.wrong.event.type %v", []eventstore.EventType{org.FeaturesSetEventType, iam.FeaturesSetEventType})
|
||||
}
|
||||
|
||||
cols := []handler.Column{
|
||||
handler.NewCol(FeatureAggregateIDCol, featureEvent.Aggregate().ID),
|
||||
handler.NewCol(FeatureInstanceIDCol, featureEvent.Aggregate().InstanceID),
|
||||
handler.NewCol(FeatureChangeDateCol, featureEvent.CreationDate()),
|
||||
handler.NewCol(FeatureSequenceCol, featureEvent.Sequence()),
|
||||
handler.NewCol(FeatureIsDefaultCol, isDefault),
|
||||
@@ -196,8 +226,7 @@ func (p *FeatureProjection) reduceFeatureSet(event eventstore.Event) (*handler.S
|
||||
func (p *FeatureProjection) reduceFeatureRemoved(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*org.FeaturesRemovedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-fN903", "seq", event.Sequence(), "expectedType", org.FeaturesRemovedEventType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-0p4rf", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-0p4rf", "reduce.wrong.event.type %s", org.FeaturesRemovedEventType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
e,
|
||||
|
||||
@@ -64,9 +64,10 @@ func TestFeatureProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPSERT INTO zitadel.projections.features (aggregate_id, change_date, sequence, is_default, tier_name, tier_description, state, state_description, audit_log_retention, login_policy_factors, login_policy_idp, login_policy_passwordless, login_policy_registration, login_policy_username_login, login_policy_password_reset, password_complexity_policy, label_policy_private_label, label_policy_watermark, custom_domain, privacy_policy, metadata_user, custom_text_message, custom_text_login, lockout_policy, actions_allowed, max_actions) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26)",
|
||||
expectedStmt: "UPSERT INTO projections.features (aggregate_id, instance_id, change_date, sequence, is_default, tier_name, tier_description, state, state_description, audit_log_retention, login_policy_factors, login_policy_idp, login_policy_passwordless, login_policy_registration, login_policy_username_login, login_policy_password_reset, password_complexity_policy, label_policy_private_label, label_policy_watermark, custom_domain, privacy_policy, metadata_user, custom_text_message, custom_text_login, lockout_policy, actions_allowed, max_actions) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
"instance-id",
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
false,
|
||||
@@ -138,9 +139,10 @@ func TestFeatureProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPSERT INTO zitadel.projections.features (aggregate_id, change_date, sequence, is_default, tier_name, tier_description, state, state_description, audit_log_retention, login_policy_factors, login_policy_idp, login_policy_passwordless, login_policy_registration, login_policy_username_login, login_policy_password_reset, password_complexity_policy, label_policy_private_label, label_policy_watermark, custom_domain, privacy_policy, metadata_user, custom_text_message, custom_text_login, lockout_policy, actions_allowed) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25)",
|
||||
expectedStmt: "UPSERT INTO projections.features (aggregate_id, instance_id, change_date, sequence, is_default, tier_name, tier_description, state, state_description, audit_log_retention, login_policy_factors, login_policy_idp, login_policy_passwordless, login_policy_registration, login_policy_username_login, login_policy_password_reset, password_complexity_policy, label_policy_private_label, label_policy_watermark, custom_domain, privacy_policy, metadata_user, custom_text_message, custom_text_login, lockout_policy, actions_allowed) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
"instance-id",
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
false,
|
||||
@@ -189,9 +191,10 @@ func TestFeatureProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPSERT INTO zitadel.projections.features (aggregate_id, change_date, sequence, is_default) VALUES ($1, $2, $3, $4)",
|
||||
expectedStmt: "UPSERT INTO projections.features (aggregate_id, instance_id, change_date, sequence, is_default) VALUES ($1, $2, $3, $4, $5)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
"instance-id",
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
false,
|
||||
@@ -219,7 +222,7 @@ func TestFeatureProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.features WHERE (aggregate_id = $1)",
|
||||
expectedStmt: "DELETE FROM projections.features WHERE (aggregate_id = $1)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
},
|
||||
@@ -268,9 +271,10 @@ func TestFeatureProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPSERT INTO zitadel.projections.features (aggregate_id, change_date, sequence, is_default, tier_name, tier_description, state, state_description, audit_log_retention, login_policy_factors, login_policy_idp, login_policy_passwordless, login_policy_registration, login_policy_username_login, login_policy_password_reset, password_complexity_policy, label_policy_private_label, label_policy_watermark, custom_domain, privacy_policy, metadata_user, custom_text_message, custom_text_login, lockout_policy, actions_allowed) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25)",
|
||||
expectedStmt: "UPSERT INTO projections.features (aggregate_id, instance_id, change_date, sequence, is_default, tier_name, tier_description, state, state_description, audit_log_retention, login_policy_factors, login_policy_idp, login_policy_passwordless, login_policy_registration, login_policy_username_login, login_policy_password_reset, password_complexity_policy, label_policy_private_label, label_policy_watermark, custom_domain, privacy_policy, metadata_user, custom_text_message, custom_text_login, lockout_policy, actions_allowed) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
"instance-id",
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
true,
|
||||
@@ -342,9 +346,10 @@ func TestFeatureProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPSERT INTO zitadel.projections.features (aggregate_id, change_date, sequence, is_default, tier_name, tier_description, state, state_description, audit_log_retention, login_policy_factors, login_policy_idp, login_policy_passwordless, login_policy_registration, login_policy_username_login, login_policy_password_reset, password_complexity_policy, label_policy_private_label, label_policy_watermark, custom_domain, privacy_policy, metadata_user, custom_text_message, custom_text_login, lockout_policy, actions_allowed, max_actions) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26)",
|
||||
expectedStmt: "UPSERT INTO projections.features (aggregate_id, instance_id, change_date, sequence, is_default, tier_name, tier_description, state, state_description, audit_log_retention, login_policy_factors, login_policy_idp, login_policy_passwordless, login_policy_registration, login_policy_username_login, login_policy_password_reset, password_complexity_policy, label_policy_private_label, label_policy_watermark, custom_domain, privacy_policy, metadata_user, custom_text_message, custom_text_login, lockout_policy, actions_allowed, max_actions) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
"instance-id",
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
true,
|
||||
|
||||
@@ -3,8 +3,6 @@ package projection
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/logging"
|
||||
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/eventstore/handler"
|
||||
@@ -13,10 +11,13 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
FlowTriggerTable = "zitadel.projections.flows_triggers"
|
||||
FlowTriggerTable = "projections.flows_triggers"
|
||||
FlowTypeCol = "flow_type"
|
||||
FlowChangeDateCol = "change_date"
|
||||
FlowSequenceCol = "sequence"
|
||||
FlowTriggerTypeCol = "trigger_type"
|
||||
FlowResourceOwnerCol = "resource_owner"
|
||||
FlowInstanceIDCol = "instance_id"
|
||||
FlowActionTriggerSequenceCol = "trigger_sequence"
|
||||
FlowActionIDCol = "action_id"
|
||||
)
|
||||
@@ -29,6 +30,20 @@ func NewFlowProjection(ctx context.Context, config crdb.StatementHandlerConfig)
|
||||
p := new(FlowProjection)
|
||||
config.ProjectionName = FlowTriggerTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(FlowTypeCol, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(FlowChangeDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(FlowSequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(FlowTriggerTypeCol, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(FlowResourceOwnerCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(FlowInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(FlowActionTriggerSequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(FlowActionIDCol, crdb.ColumnTypeText),
|
||||
},
|
||||
crdb.NewPrimaryKey(FlowInstanceIDCol, FlowTypeCol, FlowTriggerTypeCol, FlowResourceOwnerCol, FlowActionIDCol),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
@@ -54,8 +69,7 @@ func (p *FlowProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *FlowProjection) reduceTriggerActionsSetEventType(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*org.TriggerActionsSetEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-zWCk3", "seq", event.Sequence, "expectedType", org.TriggerActionsSetEventType).Error("was not an trigger actions set event")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-uYq4r", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-uYq4r", "reduce.wrong.event.type %s", org.TriggerActionsSetEventType)
|
||||
}
|
||||
stmts := make([]func(reader eventstore.Event) crdb.Exec, len(e.ActionIDs)+1)
|
||||
stmts[0] = crdb.AddDeleteStatement(
|
||||
@@ -68,7 +82,10 @@ func (p *FlowProjection) reduceTriggerActionsSetEventType(event eventstore.Event
|
||||
stmts[i+1] = crdb.AddCreateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(FlowResourceOwnerCol, e.Aggregate().ResourceOwner),
|
||||
handler.NewCol(FlowInstanceIDCol, e.Aggregate().InstanceID),
|
||||
handler.NewCol(FlowTypeCol, e.FlowType),
|
||||
handler.NewCol(FlowChangeDateCol, e.CreationDate()),
|
||||
handler.NewCol(FlowSequenceCol, e.Sequence()),
|
||||
handler.NewCol(FlowTriggerTypeCol, e.TriggerType),
|
||||
handler.NewCol(FlowActionIDCol, id),
|
||||
handler.NewCol(FlowActionTriggerSequenceCol, i),
|
||||
@@ -81,8 +98,7 @@ func (p *FlowProjection) reduceTriggerActionsSetEventType(event eventstore.Event
|
||||
func (p *FlowProjection) reduceFlowClearedEventType(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*org.FlowClearedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-zWCk3", "seq", event.Sequence, "expectedType", org.FlowClearedEventType).Error("was not a flow cleared event")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-uYq4r", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-uYq4r", "reduce.wrong.event.type %s", org.FlowClearedEventType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
e,
|
||||
|
||||
@@ -1,184 +0,0 @@
|
||||
package flow
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/logging"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/eventstore/handler"
|
||||
"github.com/caos/zitadel/internal/eventstore/handler/crdb"
|
||||
"github.com/caos/zitadel/internal/repository/action"
|
||||
"github.com/caos/zitadel/internal/repository/org"
|
||||
)
|
||||
|
||||
type FlowProjection struct {
|
||||
crdb.StatementHandler
|
||||
}
|
||||
|
||||
func NewFlowProjection(ctx context.Context, config crdb.StatementHandlerConfig) *FlowProjection {
|
||||
p := &FlowProjection{}
|
||||
config.ProjectionName = "projections.flows"
|
||||
config.Reducers = p.reducers()
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *FlowProjection) reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: org.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
{
|
||||
Event: org.TriggerActionsSetEventType,
|
||||
Reduce: p.reduceTriggerActionsSetEventType,
|
||||
},
|
||||
{
|
||||
Event: org.FlowClearedEventType,
|
||||
Reduce: p.reduceFlowClearedEventType,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Aggregate: action.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
{
|
||||
Event: action.AddedEventType,
|
||||
Reduce: p.reduceFlowActionAdded,
|
||||
},
|
||||
{
|
||||
Event: action.ChangedEventType,
|
||||
Reduce: p.reduceFlowActionChanged,
|
||||
},
|
||||
{
|
||||
Event: action.RemovedEventType,
|
||||
Reduce: p.reduceFlowActionRemoved,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
triggerTableSuffix = "triggers"
|
||||
flowTypeCol = "flow_type"
|
||||
flowTriggerTypeCol = "trigger_type"
|
||||
flowResourceOwnerCol = "resource_owner"
|
||||
flowActionTriggerSequenceCol = "trigger_sequence"
|
||||
flowActionIDCol = "action_id"
|
||||
|
||||
actionTableSuffix = "actions"
|
||||
actionIDCol = "id"
|
||||
actionCreationDateCol = "creation_date"
|
||||
actionChangeDateCol = "change_date"
|
||||
actionResourceOwnerCol = "resource_owner"
|
||||
actionSequenceCol = "sequence"
|
||||
actionNameCol = "name"
|
||||
actionScriptCol = "script"
|
||||
)
|
||||
|
||||
func (p *FlowProjection) reduceTriggerActionsSetEventType(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*org.TriggerActionsSetEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-zWCk3", "seq", event.Sequence, "expectedType", action.AddedEventType).Error("was not an trigger actions set event")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-uYq4r", "reduce.wrong.event.type")
|
||||
}
|
||||
stmts := make([]func(reader eventstore.Event) crdb.Exec, len(e.ActionIDs)+1)
|
||||
stmts[0] = crdb.AddDeleteStatement(
|
||||
[]handler.Condition{
|
||||
handler.NewCond(flowTypeCol, e.FlowType),
|
||||
handler.NewCond(flowTriggerTypeCol, e.TriggerType),
|
||||
},
|
||||
crdb.WithTableSuffix(triggerTableSuffix),
|
||||
)
|
||||
for i, id := range e.ActionIDs {
|
||||
stmts[i+1] = crdb.AddCreateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(flowResourceOwnerCol, e.Aggregate().ResourceOwner),
|
||||
handler.NewCol(flowTypeCol, e.FlowType),
|
||||
handler.NewCol(flowTriggerTypeCol, e.TriggerType),
|
||||
handler.NewCol(flowActionIDCol, id),
|
||||
handler.NewCol(flowActionTriggerSequenceCol, i),
|
||||
},
|
||||
crdb.WithTableSuffix(triggerTableSuffix),
|
||||
)
|
||||
}
|
||||
return crdb.NewMultiStatement(e, stmts...), nil
|
||||
}
|
||||
|
||||
func (p *FlowProjection) reduceFlowClearedEventType(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*org.FlowClearedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-zWCk3", "seq", event.Sequence, "expectedType", action.AddedEventType).Error("was not an trigger actions set event")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-uYq4r", "reduce.wrong.event.type")
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(flowTypeCol, e.FlowType),
|
||||
},
|
||||
crdb.WithTableSuffix(triggerTableSuffix),
|
||||
), nil
|
||||
}
|
||||
|
||||
func (p *FlowProjection) reduceFlowActionAdded(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*action.AddedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-zWCk3", "seq", event.Sequence, "expectedType", action.AddedEventType).Error("was not an flow action added event")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-uYq4r", "reduce.wrong.event.type")
|
||||
}
|
||||
return crdb.NewCreateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(actionIDCol, e.Aggregate().ID),
|
||||
handler.NewCol(actionCreationDateCol, e.CreationDate()),
|
||||
handler.NewCol(actionChangeDateCol, e.CreationDate()),
|
||||
handler.NewCol(actionResourceOwnerCol, e.Aggregate().ResourceOwner),
|
||||
handler.NewCol(actionSequenceCol, e.Sequence()),
|
||||
handler.NewCol(actionNameCol, e.Name),
|
||||
handler.NewCol(actionScriptCol, e.Script),
|
||||
},
|
||||
crdb.WithTableSuffix(actionTableSuffix),
|
||||
), nil
|
||||
}
|
||||
|
||||
func (p *FlowProjection) reduceFlowActionChanged(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*action.ChangedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-q4oq8", "seq", event.Sequence, "expected", action.ChangedEventType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-Bg8oM", "reduce.wrong.event.type")
|
||||
}
|
||||
values := []handler.Column{
|
||||
handler.NewCol(actionChangeDateCol, e.CreationDate()),
|
||||
handler.NewCol(actionSequenceCol, e.Sequence()),
|
||||
}
|
||||
if e.Name != nil {
|
||||
values = append(values, handler.NewCol(actionNameCol, *e.Name))
|
||||
}
|
||||
if e.Script != nil {
|
||||
values = append(values, handler.NewCol(actionScriptCol, *e.Script))
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
e,
|
||||
values,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(actionIDCol, e.Aggregate().ID),
|
||||
},
|
||||
crdb.WithTableSuffix(actionTableSuffix),
|
||||
), nil
|
||||
}
|
||||
|
||||
func (p *FlowProjection) reduceFlowActionRemoved(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*action.RemovedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-79OhB", "seq", event.Sequence, "expectedType", action.RemovedEventType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-4TbKT", "reduce.wrong.event.type")
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(actionIDCol, e.Aggregate().ID),
|
||||
},
|
||||
crdb.WithTableSuffix(actionTableSuffix),
|
||||
), nil
|
||||
}
|
||||
@@ -39,27 +39,33 @@ func TestFlowProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.flows_triggers WHERE (flow_type = $1) AND (trigger_type = $2)",
|
||||
expectedStmt: "DELETE FROM projections.flows_triggers WHERE (flow_type = $1) AND (trigger_type = $2)",
|
||||
expectedArgs: []interface{}{
|
||||
domain.FlowTypeExternalAuthentication,
|
||||
domain.TriggerTypePostAuthentication,
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "INSERT INTO zitadel.projections.flows_triggers (resource_owner, flow_type, trigger_type, action_id, trigger_sequence) VALUES ($1, $2, $3, $4, $5)",
|
||||
expectedStmt: "INSERT INTO projections.flows_triggers (resource_owner, instance_id, flow_type, change_date, sequence, trigger_type, action_id, trigger_sequence) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)",
|
||||
expectedArgs: []interface{}{
|
||||
"ro-id",
|
||||
"instance-id",
|
||||
domain.FlowTypeExternalAuthentication,
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
domain.TriggerTypePostAuthentication,
|
||||
"id1",
|
||||
0,
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "INSERT INTO zitadel.projections.flows_triggers (resource_owner, flow_type, trigger_type, action_id, trigger_sequence) VALUES ($1, $2, $3, $4, $5)",
|
||||
expectedStmt: "INSERT INTO projections.flows_triggers (resource_owner, instance_id, flow_type, change_date, sequence, trigger_type, action_id, trigger_sequence) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)",
|
||||
expectedArgs: []interface{}{
|
||||
"ro-id",
|
||||
"instance-id",
|
||||
domain.FlowTypeExternalAuthentication,
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
domain.TriggerTypePostAuthentication,
|
||||
"id2",
|
||||
1,
|
||||
@@ -87,7 +93,7 @@ func TestFlowProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.flows_triggers WHERE (flow_type = $1)",
|
||||
expectedStmt: "DELETE FROM projections.flows_triggers WHERE (flow_type = $1)",
|
||||
expectedArgs: []interface{}{
|
||||
domain.FlowTypeExternalAuthentication,
|
||||
},
|
||||
|
||||
@@ -3,7 +3,6 @@ package projection
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/logging"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/eventstore/handler"
|
||||
@@ -11,18 +10,41 @@ import (
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
)
|
||||
|
||||
const (
|
||||
IAMProjectionTable = "projections.iam"
|
||||
|
||||
IAMColumnID = "id"
|
||||
IAMColumnChangeDate = "change_date"
|
||||
IAMColumnGlobalOrgID = "global_org_id"
|
||||
IAMColumnProjectID = "iam_project_id"
|
||||
IAMColumnSequence = "sequence"
|
||||
IAMColumnSetUpStarted = "setup_started"
|
||||
IAMColumnSetUpDone = "setup_done"
|
||||
IAMColumnDefaultLanguage = "default_language"
|
||||
)
|
||||
|
||||
type IAMProjection struct {
|
||||
crdb.StatementHandler
|
||||
}
|
||||
|
||||
const (
|
||||
IAMProjectionTable = "zitadel.projections.iam"
|
||||
)
|
||||
|
||||
func NewIAMProjection(ctx context.Context, config crdb.StatementHandlerConfig) *IAMProjection {
|
||||
p := new(IAMProjection)
|
||||
config.ProjectionName = IAMProjectionTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(IAMColumnID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(IAMColumnChangeDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(IAMColumnGlobalOrgID, crdb.ColumnTypeText, crdb.Default("")),
|
||||
crdb.NewColumn(IAMColumnProjectID, crdb.ColumnTypeText, crdb.Default("")),
|
||||
crdb.NewColumn(IAMColumnSequence, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(IAMColumnSetUpStarted, crdb.ColumnTypeInt64, crdb.Default(0)),
|
||||
crdb.NewColumn(IAMColumnSetUpDone, crdb.ColumnTypeInt64, crdb.Default(0)),
|
||||
crdb.NewColumn(IAMColumnDefaultLanguage, crdb.ColumnTypeText, crdb.Default("")),
|
||||
},
|
||||
crdb.NewPrimaryKey(IAMColumnID),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
@@ -57,29 +79,15 @@ func (p *IAMProjection) reducers() []handler.AggregateReducer {
|
||||
}
|
||||
}
|
||||
|
||||
type IAMColumn string
|
||||
|
||||
const (
|
||||
IAMColumnID = "id"
|
||||
IAMColumnChangeDate = "change_date"
|
||||
IAMColumnGlobalOrgID = "global_org_id"
|
||||
IAMColumnProjectID = "iam_project_id"
|
||||
IAMColumnSequence = "sequence"
|
||||
IAMColumnSetUpStarted = "setup_started"
|
||||
IAMColumnSetUpDone = "setup_done"
|
||||
IAMColumnDefaultLanguage = "default_language"
|
||||
)
|
||||
|
||||
func (p *IAMProjection) reduceGlobalOrgSet(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*iam.GlobalOrgSetEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-3n89fs", "seq", event.Sequence(), "expectedType", iam.GlobalOrgSetEventType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-2n9f2", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-2n9f2", "reduce.wrong.event.type %s", iam.GlobalOrgSetEventType)
|
||||
}
|
||||
return crdb.NewUpsertStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(IAMColumnID, e.Aggregate().ID),
|
||||
handler.NewCol(IAMColumnID, e.Aggregate().InstanceID),
|
||||
handler.NewCol(IAMColumnChangeDate, e.CreationDate()),
|
||||
handler.NewCol(IAMColumnSequence, e.Sequence()),
|
||||
handler.NewCol(IAMColumnGlobalOrgID, e.OrgID),
|
||||
@@ -90,13 +98,12 @@ func (p *IAMProjection) reduceGlobalOrgSet(event eventstore.Event) (*handler.Sta
|
||||
func (p *IAMProjection) reduceIAMProjectSet(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*iam.ProjectSetEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-2j9fw", "seq", event.Sequence(), "expectedType", iam.ProjectSetEventType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-30o0e", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-30o0e", "reduce.wrong.event.type %s", iam.ProjectSetEventType)
|
||||
}
|
||||
return crdb.NewUpsertStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(IAMColumnID, e.Aggregate().ID),
|
||||
handler.NewCol(IAMColumnID, e.Aggregate().InstanceID),
|
||||
handler.NewCol(IAMColumnChangeDate, e.CreationDate()),
|
||||
handler.NewCol(IAMColumnSequence, e.Sequence()),
|
||||
handler.NewCol(IAMColumnProjectID, e.ProjectID),
|
||||
@@ -107,13 +114,12 @@ func (p *IAMProjection) reduceIAMProjectSet(event eventstore.Event) (*handler.St
|
||||
func (p *IAMProjection) reduceDefaultLanguageSet(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*iam.DefaultLanguageSetEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-3n9le", "seq", event.Sequence(), "expectedType", iam.DefaultLanguageSetEventType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-30o0e", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-30o0e", "reduce.wrong.event.type %s", iam.DefaultLanguageSetEventType)
|
||||
}
|
||||
return crdb.NewUpsertStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(IAMColumnID, e.Aggregate().ID),
|
||||
handler.NewCol(IAMColumnID, e.Aggregate().InstanceID),
|
||||
handler.NewCol(IAMColumnChangeDate, e.CreationDate()),
|
||||
handler.NewCol(IAMColumnSequence, e.Sequence()),
|
||||
handler.NewCol(IAMColumnDefaultLanguage, e.Language.String()),
|
||||
@@ -124,11 +130,10 @@ func (p *IAMProjection) reduceDefaultLanguageSet(event eventstore.Event) (*handl
|
||||
func (p *IAMProjection) reduceSetupEvent(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*iam.SetupStepEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-39fjw", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{iam.SetupDoneEventType, iam.SetupStartedEventType}).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-d9nfw", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-d9nfw", "reduce.wrong.event.type %v", []eventstore.EventType{iam.SetupDoneEventType, iam.SetupStartedEventType})
|
||||
}
|
||||
columns := []handler.Column{
|
||||
handler.NewCol(IAMColumnID, e.Aggregate().ID),
|
||||
handler.NewCol(IAMColumnID, e.Aggregate().InstanceID),
|
||||
handler.NewCol(IAMColumnChangeDate, e.CreationDate()),
|
||||
handler.NewCol(IAMColumnSequence, e.Sequence()),
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ package projection
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/logging"
|
||||
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/eventstore/handler"
|
||||
@@ -13,18 +11,28 @@ import (
|
||||
"github.com/caos/zitadel/internal/repository/user"
|
||||
)
|
||||
|
||||
const (
|
||||
IAMMemberProjectionTable = "projections.iam_members"
|
||||
|
||||
IAMMemberIAMIDCol = "iam_id"
|
||||
)
|
||||
|
||||
type IAMMemberProjection struct {
|
||||
crdb.StatementHandler
|
||||
}
|
||||
|
||||
const (
|
||||
IAMMemberProjectionTable = "zitadel.projections.iam_members"
|
||||
)
|
||||
|
||||
func NewIAMMemberProjection(ctx context.Context, config crdb.StatementHandlerConfig) *IAMMemberProjection {
|
||||
p := new(IAMMemberProjection)
|
||||
config.ProjectionName = IAMMemberProjectionTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable(
|
||||
append(memberColumns, crdb.NewColumn(IAMColumnID, crdb.ColumnTypeText)),
|
||||
crdb.NewPrimaryKey(MemberInstanceID, IAMColumnID, MemberUserIDCol),
|
||||
crdb.NewIndex("user_idx", []string{MemberUserIDCol}),
|
||||
),
|
||||
)
|
||||
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
@@ -64,17 +72,10 @@ func (p *IAMMemberProjection) reducers() []handler.AggregateReducer {
|
||||
}
|
||||
}
|
||||
|
||||
type IAMMemberColumn string
|
||||
|
||||
const (
|
||||
IAMMemberIAMIDCol = "iam_id"
|
||||
)
|
||||
|
||||
func (p *IAMMemberProjection) reduceAdded(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*iam.MemberAddedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-c8SBb", "seq", event.Sequence(), "expectedType", iam.MemberAddedEventType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-pGNCu", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-pGNCu", "reduce.wrong.event.type %s", iam.MemberAddedEventType)
|
||||
}
|
||||
return reduceMemberAdded(e.MemberAddedEvent, withMemberCol(IAMMemberIAMIDCol, e.Aggregate().ID))
|
||||
}
|
||||
@@ -82,8 +83,7 @@ func (p *IAMMemberProjection) reduceAdded(event eventstore.Event) (*handler.Stat
|
||||
func (p *IAMMemberProjection) reduceChanged(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*iam.MemberChangedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-QsjwO", "seq", event.Sequence(), "expected", iam.MemberChangedEventType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-5WQcZ", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-5WQcZ", "reduce.wrong.event.type %s", iam.MemberChangedEventType)
|
||||
}
|
||||
return reduceMemberChanged(e.MemberChangedEvent)
|
||||
}
|
||||
@@ -91,8 +91,7 @@ func (p *IAMMemberProjection) reduceChanged(event eventstore.Event) (*handler.St
|
||||
func (p *IAMMemberProjection) reduceCascadeRemoved(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*iam.MemberCascadeRemovedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-mOncs", "seq", event.Sequence(), "expected", iam.MemberCascadeRemovedEventType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-Dmdf2", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-Dmdf2", "reduce.wrong.event.type %s", iam.MemberCascadeRemovedEventType)
|
||||
}
|
||||
return reduceMemberCascadeRemoved(e.MemberCascadeRemovedEvent)
|
||||
}
|
||||
@@ -100,8 +99,7 @@ func (p *IAMMemberProjection) reduceCascadeRemoved(event eventstore.Event) (*han
|
||||
func (p *IAMMemberProjection) reduceRemoved(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*iam.MemberRemovedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-lW1Zv", "seq", event.Sequence(), "expected", iam.MemberRemovedEventType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-exVqy", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-exVqy", "reduce.wrong.event.type %s", iam.MemberRemovedEventType)
|
||||
}
|
||||
return reduceMemberRemoved(e, withMemberCond(MemberUserIDCol, e.UserID))
|
||||
}
|
||||
@@ -109,8 +107,7 @@ func (p *IAMMemberProjection) reduceRemoved(event eventstore.Event) (*handler.St
|
||||
func (p *IAMMemberProjection) reduceUserRemoved(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*user.UserRemovedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-rBuvT", "seq", event.Sequence(), "expected", user.UserRemovedType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-mkDHF", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-mkDHF", "reduce.wrong.event.type %s", user.UserRemovedType)
|
||||
}
|
||||
return reduceMemberRemoved(e, withMemberCond(MemberUserIDCol, e.Aggregate().ID))
|
||||
}
|
||||
|
||||
@@ -3,13 +3,14 @@ package projection
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/lib/pq"
|
||||
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/eventstore/handler"
|
||||
"github.com/caos/zitadel/internal/eventstore/repository"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/user"
|
||||
"github.com/lib/pq"
|
||||
)
|
||||
|
||||
func TestIAMMemberProjection_reduces(t *testing.T) {
|
||||
@@ -43,7 +44,7 @@ func TestIAMMemberProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO zitadel.projections.iam_members (user_id, roles, creation_date, change_date, sequence, resource_owner, iam_id) VALUES ($1, $2, $3, $4, $5, $6, $7)",
|
||||
expectedStmt: "INSERT INTO projections.iam_members (user_id, roles, creation_date, change_date, sequence, resource_owner, instance_id, iam_id) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)",
|
||||
expectedArgs: []interface{}{
|
||||
"user-id",
|
||||
pq.StringArray{"role"},
|
||||
@@ -51,6 +52,7 @@ func TestIAMMemberProjection_reduces(t *testing.T) {
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
"ro-id",
|
||||
"instance-id",
|
||||
"agg-id",
|
||||
},
|
||||
},
|
||||
@@ -79,7 +81,7 @@ func TestIAMMemberProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.iam_members SET (roles, change_date, sequence) = ($1, $2, $3) WHERE (user_id = $4)",
|
||||
expectedStmt: "UPDATE projections.iam_members SET (roles, change_date, sequence) = ($1, $2, $3) WHERE (user_id = $4)",
|
||||
expectedArgs: []interface{}{
|
||||
pq.StringArray{"role", "changed"},
|
||||
anyArg{},
|
||||
@@ -111,7 +113,7 @@ func TestIAMMemberProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.iam_members WHERE (user_id = $1)",
|
||||
expectedStmt: "DELETE FROM projections.iam_members WHERE (user_id = $1)",
|
||||
expectedArgs: []interface{}{
|
||||
"user-id",
|
||||
},
|
||||
@@ -140,7 +142,7 @@ func TestIAMMemberProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.iam_members WHERE (user_id = $1)",
|
||||
expectedStmt: "DELETE FROM projections.iam_members WHERE (user_id = $1)",
|
||||
expectedArgs: []interface{}{
|
||||
"user-id",
|
||||
},
|
||||
@@ -167,7 +169,7 @@ func TestIAMMemberProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.iam_members WHERE (user_id = $1)",
|
||||
expectedStmt: "DELETE FROM projections.iam_members WHERE (user_id = $1)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
},
|
||||
|
||||
@@ -39,9 +39,9 @@ func TestIAMProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPSERT INTO zitadel.projections.iam (id, change_date, sequence, global_org_id) VALUES ($1, $2, $3, $4)",
|
||||
expectedStmt: "UPSERT INTO projections.iam (id, change_date, sequence, global_org_id) VALUES ($1, $2, $3, $4)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
"instance-id",
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
"orgid",
|
||||
@@ -69,9 +69,9 @@ func TestIAMProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPSERT INTO zitadel.projections.iam (id, change_date, sequence, iam_project_id) VALUES ($1, $2, $3, $4)",
|
||||
expectedStmt: "UPSERT INTO projections.iam (id, change_date, sequence, iam_project_id) VALUES ($1, $2, $3, $4)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
"instance-id",
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
"project-id",
|
||||
@@ -99,9 +99,9 @@ func TestIAMProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPSERT INTO zitadel.projections.iam (id, change_date, sequence, default_language) VALUES ($1, $2, $3, $4)",
|
||||
expectedStmt: "UPSERT INTO projections.iam (id, change_date, sequence, default_language) VALUES ($1, $2, $3, $4)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
"instance-id",
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
"en",
|
||||
@@ -129,9 +129,9 @@ func TestIAMProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPSERT INTO zitadel.projections.iam (id, change_date, sequence, setup_started) VALUES ($1, $2, $3, $4)",
|
||||
expectedStmt: "UPSERT INTO projections.iam (id, change_date, sequence, setup_started) VALUES ($1, $2, $3, $4)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
"instance-id",
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
domain.Step1,
|
||||
@@ -159,9 +159,9 @@ func TestIAMProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPSERT INTO zitadel.projections.iam (id, change_date, sequence, setup_done) VALUES ($1, $2, $3, $4)",
|
||||
expectedStmt: "UPSERT INTO projections.iam (id, change_date, sequence, setup_done) VALUES ($1, $2, $3, $4)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
"instance-id",
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
domain.Step1,
|
||||
|
||||
@@ -3,7 +3,8 @@ package projection
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/logging"
|
||||
"github.com/lib/pq"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
@@ -12,23 +13,97 @@ import (
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/idpconfig"
|
||||
"github.com/caos/zitadel/internal/repository/org"
|
||||
"github.com/lib/pq"
|
||||
)
|
||||
|
||||
const (
|
||||
IDPTable = "projections.idps"
|
||||
IDPOIDCTable = IDPTable + "_" + IDPOIDCSuffix
|
||||
IDPJWTTable = IDPTable + "_" + IDPJWTSuffix
|
||||
|
||||
IDPOIDCSuffix = "oidc_config"
|
||||
IDPJWTSuffix = "jwt_config"
|
||||
|
||||
IDPIDCol = "id"
|
||||
IDPCreationDateCol = "creation_date"
|
||||
IDPChangeDateCol = "change_date"
|
||||
IDPSequenceCol = "sequence"
|
||||
IDPResourceOwnerCol = "resource_owner"
|
||||
IDPInstanceIDCol = "instance_id"
|
||||
IDPStateCol = "state"
|
||||
IDPNameCol = "name"
|
||||
IDPStylingTypeCol = "styling_type"
|
||||
IDPOwnerTypeCol = "owner_type"
|
||||
IDPAutoRegisterCol = "auto_register"
|
||||
IDPTypeCol = "type"
|
||||
|
||||
OIDCConfigIDPIDCol = "idp_id"
|
||||
OIDCConfigClientIDCol = "client_id"
|
||||
OIDCConfigClientSecretCol = "client_secret"
|
||||
OIDCConfigIssuerCol = "issuer"
|
||||
OIDCConfigScopesCol = "scopes"
|
||||
OIDCConfigDisplayNameMappingCol = "display_name_mapping"
|
||||
OIDCConfigUsernameMappingCol = "username_mapping"
|
||||
OIDCConfigAuthorizationEndpointCol = "authorization_endpoint"
|
||||
OIDCConfigTokenEndpointCol = "token_endpoint"
|
||||
|
||||
JWTConfigIDPIDCol = "idp_id"
|
||||
JWTConfigIssuerCol = "issuer"
|
||||
JWTConfigKeysEndpointCol = "keys_endpoint"
|
||||
JWTConfigHeaderNameCol = "header_name"
|
||||
JWTConfigEndpointCol = "endpoint"
|
||||
)
|
||||
|
||||
type IDPProjection struct {
|
||||
crdb.StatementHandler
|
||||
}
|
||||
|
||||
const (
|
||||
IDPTable = "zitadel.projections.idps"
|
||||
IDPOIDCTable = IDPTable + "_" + IDPOIDCSuffix
|
||||
IDPJWTTable = IDPTable + "_" + IDPJWTSuffix
|
||||
)
|
||||
|
||||
func NewIDPProjection(ctx context.Context, config crdb.StatementHandlerConfig) *IDPProjection {
|
||||
p := new(IDPProjection)
|
||||
config.ProjectionName = IDPTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewMultiTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(IDPIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(IDPCreationDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(IDPChangeDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(IDPSequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(IDPResourceOwnerCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(IDPInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(IDPStateCol, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(IDPNameCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(IDPStylingTypeCol, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(IDPOwnerTypeCol, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(IDPAutoRegisterCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(IDPTypeCol, crdb.ColumnTypeEnum),
|
||||
},
|
||||
crdb.NewPrimaryKey(IDPInstanceIDCol, IDPIDCol),
|
||||
crdb.NewIndex("ro_idx", []string{IDPResourceOwnerCol}),
|
||||
),
|
||||
crdb.NewSuffixedTable([]*crdb.Column{
|
||||
crdb.NewColumn(OIDCConfigIDPIDCol, crdb.ColumnTypeText, crdb.DeleteCascade(IDPIDCol)),
|
||||
crdb.NewColumn(OIDCConfigClientIDCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(OIDCConfigClientSecretCol, crdb.ColumnTypeJSONB, crdb.Nullable()),
|
||||
crdb.NewColumn(OIDCConfigIssuerCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(OIDCConfigScopesCol, crdb.ColumnTypeTextArray, crdb.Nullable()),
|
||||
crdb.NewColumn(OIDCConfigDisplayNameMappingCol, crdb.ColumnTypeEnum, crdb.Nullable()),
|
||||
crdb.NewColumn(OIDCConfigUsernameMappingCol, crdb.ColumnTypeEnum, crdb.Nullable()),
|
||||
crdb.NewColumn(OIDCConfigAuthorizationEndpointCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(OIDCConfigTokenEndpointCol, crdb.ColumnTypeEnum, crdb.Nullable()),
|
||||
},
|
||||
crdb.NewPrimaryKey(OIDCConfigIDPIDCol),
|
||||
IDPOIDCSuffix,
|
||||
),
|
||||
crdb.NewSuffixedTable([]*crdb.Column{
|
||||
crdb.NewColumn(JWTConfigIDPIDCol, crdb.ColumnTypeText, crdb.DeleteCascade(IDPIDCol)),
|
||||
crdb.NewColumn(JWTConfigIssuerCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(JWTConfigKeysEndpointCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(JWTConfigHeaderNameCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(JWTConfigEndpointCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
},
|
||||
crdb.NewPrimaryKey(JWTConfigIDPIDCol),
|
||||
IDPJWTSuffix,
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
@@ -120,39 +195,6 @@ func (p *IDPProjection) reducers() []handler.AggregateReducer {
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
IDPOIDCSuffix = "oidc_config"
|
||||
IDPJWTSuffix = "jwt_config"
|
||||
|
||||
IDPIDCol = "id"
|
||||
IDPCreationDateCol = "creation_date"
|
||||
IDPChangeDateCol = "change_date"
|
||||
IDPSequenceCol = "sequence"
|
||||
IDPResourceOwnerCol = "resource_owner"
|
||||
IDPStateCol = "state"
|
||||
IDPNameCol = "name"
|
||||
IDPStylingTypeCol = "styling_type"
|
||||
IDPOwnerTypeCol = "owner_type"
|
||||
IDPAutoRegisterCol = "auto_register"
|
||||
IDPTypeCol = "type"
|
||||
|
||||
OIDCConfigIDPIDCol = "idp_id"
|
||||
OIDCConfigClientIDCol = "client_id"
|
||||
OIDCConfigClientSecretCol = "client_secret"
|
||||
OIDCConfigIssuerCol = "issuer"
|
||||
OIDCConfigScopesCol = "scopes"
|
||||
OIDCConfigDisplayNameMappingCol = "display_name_mapping"
|
||||
OIDCConfigUsernameMappingCol = "username_mapping"
|
||||
OIDCConfigAuthorizationEndpointCol = "authorization_endpoint"
|
||||
OIDCConfigTokenEndpointCol = "token_endpoint"
|
||||
|
||||
JWTConfigIDPIDCol = "idp_id"
|
||||
JWTConfigIssuerCol = "issuer"
|
||||
JWTConfigKeysEndpointCol = "keys_endpoint"
|
||||
JWTConfigHeaderNameCol = "header_name"
|
||||
JWTConfigEndpointCol = "endpoint"
|
||||
)
|
||||
|
||||
func (p *IDPProjection) reduceIDPAdded(event eventstore.Event) (*handler.Statement, error) {
|
||||
var idpEvent idpconfig.IDPConfigAddedEvent
|
||||
var idpOwnerType domain.IdentityProviderType
|
||||
@@ -164,8 +206,7 @@ func (p *IDPProjection) reduceIDPAdded(event eventstore.Event) (*handler.Stateme
|
||||
idpEvent = e.IDPConfigAddedEvent
|
||||
idpOwnerType = domain.IdentityProviderTypeSystem
|
||||
default:
|
||||
logging.LogWithFields("HANDL-hBriG", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.IDPConfigAddedEventType, iam.IDPConfigAddedEventType}).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-fcUdQ", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-fcUdQ", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPConfigAddedEventType, iam.IDPConfigAddedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewCreateStatement(
|
||||
@@ -176,6 +217,7 @@ func (p *IDPProjection) reduceIDPAdded(event eventstore.Event) (*handler.Stateme
|
||||
handler.NewCol(IDPChangeDateCol, idpEvent.CreationDate()),
|
||||
handler.NewCol(IDPSequenceCol, idpEvent.Sequence()),
|
||||
handler.NewCol(IDPResourceOwnerCol, idpEvent.Aggregate().ResourceOwner),
|
||||
handler.NewCol(IDPInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
||||
handler.NewCol(IDPStateCol, domain.IDPConfigStateActive),
|
||||
handler.NewCol(IDPNameCol, idpEvent.Name),
|
||||
handler.NewCol(IDPStylingTypeCol, idpEvent.StylingType),
|
||||
@@ -193,8 +235,7 @@ func (p *IDPProjection) reduceIDPChanged(event eventstore.Event) (*handler.State
|
||||
case *iam.IDPConfigChangedEvent:
|
||||
idpEvent = e.IDPConfigChangedEvent
|
||||
default:
|
||||
logging.LogWithFields("HANDL-FFrph", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.IDPConfigChangedEventType, iam.IDPConfigChangedEventType}).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-NVvJD", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-NVvJD", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPConfigChangedEventType, iam.IDPConfigChangedEventType})
|
||||
}
|
||||
|
||||
cols := make([]handler.Column, 0, 5)
|
||||
@@ -233,8 +274,7 @@ func (p *IDPProjection) reduceIDPDeactivated(event eventstore.Event) (*handler.S
|
||||
case *iam.IDPConfigDeactivatedEvent:
|
||||
idpEvent = e.IDPConfigDeactivatedEvent
|
||||
default:
|
||||
logging.LogWithFields("HANDL-1s33a", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.IDPConfigDeactivatedEventType, iam.IDPConfigDeactivatedEventType}).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-94O5l", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-94O5l", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPConfigDeactivatedEventType, iam.IDPConfigDeactivatedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
@@ -258,8 +298,7 @@ func (p *IDPProjection) reduceIDPReactivated(event eventstore.Event) (*handler.S
|
||||
case *iam.IDPConfigReactivatedEvent:
|
||||
idpEvent = e.IDPConfigReactivatedEvent
|
||||
default:
|
||||
logging.LogWithFields("HANDL-Zgzpt", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.IDPConfigReactivatedEventType, iam.IDPConfigReactivatedEventType}).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-I8QyS", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-I8QyS", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPConfigReactivatedEventType, iam.IDPConfigReactivatedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
@@ -283,8 +322,7 @@ func (p *IDPProjection) reduceIDPRemoved(event eventstore.Event) (*handler.State
|
||||
case *iam.IDPConfigRemovedEvent:
|
||||
idpEvent = e.IDPConfigRemovedEvent
|
||||
default:
|
||||
logging.LogWithFields("HANDL-JJasT", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.IDPConfigRemovedEventType, iam.IDPConfigRemovedEventType}).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-B4zy8", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-B4zy8", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPConfigRemovedEventType, iam.IDPConfigRemovedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
@@ -303,8 +341,7 @@ func (p *IDPProjection) reduceOIDCConfigAdded(event eventstore.Event) (*handler.
|
||||
case *iam.IDPOIDCConfigAddedEvent:
|
||||
idpEvent = e.OIDCConfigAddedEvent
|
||||
default:
|
||||
logging.LogWithFields("HANDL-DCmeB", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.IDPOIDCConfigAddedEventType, iam.IDPOIDCConfigAddedEventType}).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-2FuAA", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-2FuAA", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPOIDCConfigAddedEventType, iam.IDPOIDCConfigAddedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewMultiStatement(&idpEvent,
|
||||
@@ -343,8 +380,7 @@ func (p *IDPProjection) reduceOIDCConfigChanged(event eventstore.Event) (*handle
|
||||
case *iam.IDPOIDCConfigChangedEvent:
|
||||
idpEvent = e.OIDCConfigChangedEvent
|
||||
default:
|
||||
logging.LogWithFields("HANDL-VyBm2", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.IDPOIDCConfigChangedEventType, iam.IDPOIDCConfigChangedEventType}).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-x2IVI", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-x2IVI", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPOIDCConfigChangedEventType, iam.IDPOIDCConfigChangedEventType})
|
||||
}
|
||||
|
||||
cols := make([]handler.Column, 0, 8)
|
||||
@@ -406,8 +442,7 @@ func (p *IDPProjection) reduceJWTConfigAdded(event eventstore.Event) (*handler.S
|
||||
case *iam.IDPJWTConfigAddedEvent:
|
||||
idpEvent = e.JWTConfigAddedEvent
|
||||
default:
|
||||
logging.LogWithFields("HANDL-228q7", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.IDPJWTConfigAddedEventType, iam.IDPJWTConfigAddedEventType}).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-qvPdb", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-qvPdb", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPJWTConfigAddedEventType, iam.IDPJWTConfigAddedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewMultiStatement(&idpEvent,
|
||||
@@ -443,8 +478,7 @@ func (p *IDPProjection) reduceJWTConfigChanged(event eventstore.Event) (*handler
|
||||
case *iam.IDPJWTConfigChangedEvent:
|
||||
idpEvent = e.JWTConfigChangedEvent
|
||||
default:
|
||||
logging.LogWithFields("HANDL-VyBm2", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.IDPJWTConfigChangedEventType, iam.IDPJWTConfigChangedEventType}).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-x2IVI", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-x2IVI", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPJWTConfigChangedEventType, iam.IDPJWTConfigChangedEventType})
|
||||
}
|
||||
|
||||
cols := make([]handler.Column, 0, 4)
|
||||
|
||||
@@ -3,7 +3,6 @@ package projection
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/logging"
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
@@ -14,18 +13,41 @@ import (
|
||||
"github.com/caos/zitadel/internal/repository/policy"
|
||||
)
|
||||
|
||||
const (
|
||||
IDPLoginPolicyLinkTable = "projections.idp_login_policy_links"
|
||||
|
||||
IDPLoginPolicyLinkIDPIDCol = "idp_id"
|
||||
IDPLoginPolicyLinkAggregateIDCol = "aggregate_id"
|
||||
IDPLoginPolicyLinkCreationDateCol = "creation_date"
|
||||
IDPLoginPolicyLinkChangeDateCol = "change_date"
|
||||
IDPLoginPolicyLinkSequenceCol = "sequence"
|
||||
IDPLoginPolicyLinkResourceOwnerCol = "resource_owner"
|
||||
IDPLoginPolicyLinkInstanceIDCol = "instance_id"
|
||||
IDPLoginPolicyLinkProviderTypeCol = "provider_type"
|
||||
)
|
||||
|
||||
type IDPLoginPolicyLinkProjection struct {
|
||||
crdb.StatementHandler
|
||||
}
|
||||
|
||||
const (
|
||||
IDPLoginPolicyLinkTable = "zitadel.projections.idp_login_policy_links"
|
||||
)
|
||||
|
||||
func NewIDPLoginPolicyLinkProjection(ctx context.Context, config crdb.StatementHandlerConfig) *IDPLoginPolicyLinkProjection {
|
||||
p := new(IDPLoginPolicyLinkProjection)
|
||||
config.ProjectionName = IDPLoginPolicyLinkTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(IDPLoginPolicyLinkIDPIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(IDPLoginPolicyLinkAggregateIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(IDPLoginPolicyLinkCreationDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(IDPLoginPolicyLinkChangeDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(IDPLoginPolicyLinkSequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(IDPLoginPolicyLinkResourceOwnerCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(IDPLoginPolicyLinkInstanceIDCol, crdb.ColumnTypeText),
|
||||
},
|
||||
crdb.NewPrimaryKey(IDPLoginPolicyLinkInstanceIDCol, IDPLoginPolicyLinkAggregateIDCol, IDPLoginPolicyLinkIDPIDCol),
|
||||
crdb.NewIndex("ro_idx", []string{IDPLoginPolicyLinkResourceOwnerCol}),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
@@ -81,16 +103,6 @@ func (p *IDPLoginPolicyLinkProjection) reducers() []handler.AggregateReducer {
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
IDPLoginPolicyLinkIDPIDCol = "idp_id"
|
||||
IDPLoginPolicyLinkAggregateIDCol = "aggregate_id"
|
||||
IDPLoginPolicyLinkCreationDateCol = "creation_date"
|
||||
IDPLoginPolicyLinkChangeDateCol = "change_date"
|
||||
IDPLoginPolicyLinkSequenceCol = "sequence"
|
||||
IDPLoginPolicyLinkResourceOwnerCol = "resource_owner"
|
||||
IDPLoginPolicyLinkProviderTypeCol = "provider_type"
|
||||
)
|
||||
|
||||
func (p *IDPLoginPolicyLinkProjection) reduceAdded(event eventstore.Event) (*handler.Statement, error) {
|
||||
var (
|
||||
idp policy.IdentityProviderAddedEvent
|
||||
@@ -105,8 +117,7 @@ func (p *IDPLoginPolicyLinkProjection) reduceAdded(event eventstore.Event) (*han
|
||||
idp = e.IdentityProviderAddedEvent
|
||||
providerType = domain.IdentityProviderTypeSystem
|
||||
default:
|
||||
logging.LogWithFields("HANDL-oce92", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.LoginPolicyIDPProviderAddedEventType, iam.LoginPolicyIDPProviderAddedEventType}).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-Nlp55", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-Nlp55", "reduce.wrong.event.type %v", []eventstore.EventType{org.LoginPolicyIDPProviderAddedEventType, iam.LoginPolicyIDPProviderAddedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewCreateStatement(&idp,
|
||||
@@ -117,6 +128,7 @@ func (p *IDPLoginPolicyLinkProjection) reduceAdded(event eventstore.Event) (*han
|
||||
handler.NewCol(IDPLoginPolicyLinkChangeDateCol, idp.CreationDate()),
|
||||
handler.NewCol(IDPLoginPolicyLinkSequenceCol, idp.Sequence()),
|
||||
handler.NewCol(IDPLoginPolicyLinkResourceOwnerCol, idp.Aggregate().ResourceOwner),
|
||||
handler.NewCol(IDPLoginPolicyLinkInstanceIDCol, idp.Aggregate().InstanceID),
|
||||
handler.NewCol(IDPLoginPolicyLinkProviderTypeCol, providerType),
|
||||
},
|
||||
), nil
|
||||
@@ -131,8 +143,7 @@ func (p *IDPLoginPolicyLinkProjection) reduceRemoved(event eventstore.Event) (*h
|
||||
case *iam.IdentityProviderRemovedEvent:
|
||||
idp = e.IdentityProviderRemovedEvent
|
||||
default:
|
||||
logging.LogWithFields("HANDL-vAH3I", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.LoginPolicyIDPProviderRemovedEventType, iam.LoginPolicyIDPProviderRemovedEventType}).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-tUMYY", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-tUMYY", "reduce.wrong.event.type %v", []eventstore.EventType{org.LoginPolicyIDPProviderRemovedEventType, iam.LoginPolicyIDPProviderRemovedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(&idp,
|
||||
@@ -152,8 +163,7 @@ func (p *IDPLoginPolicyLinkProjection) reduceCascadeRemoved(event eventstore.Eve
|
||||
case *iam.IdentityProviderCascadeRemovedEvent:
|
||||
idp = e.IdentityProviderCascadeRemovedEvent
|
||||
default:
|
||||
logging.LogWithFields("HANDL-7lZaf", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.LoginPolicyIDPProviderCascadeRemovedEventType, iam.LoginPolicyIDPProviderCascadeRemovedEventType}).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-iCKSj", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-iCKSj", "reduce.wrong.event.type %v", []eventstore.EventType{org.LoginPolicyIDPProviderCascadeRemovedEventType, iam.LoginPolicyIDPProviderCascadeRemovedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(&idp,
|
||||
@@ -173,8 +183,7 @@ func (p *IDPLoginPolicyLinkProjection) reduceIDPConfigRemoved(event eventstore.E
|
||||
case *iam.IDPConfigRemovedEvent:
|
||||
idpID = e.ConfigID
|
||||
default:
|
||||
logging.LogWithFields("HANDL-aJvob", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.IDPConfigRemovedEventType, iam.IDPConfigRemovedEventType}).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-u6tze", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-u6tze", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPConfigRemovedEventType, iam.IDPConfigRemovedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(event,
|
||||
@@ -188,8 +197,7 @@ func (p *IDPLoginPolicyLinkProjection) reduceIDPConfigRemoved(event eventstore.E
|
||||
func (p *IDPLoginPolicyLinkProjection) reduceOrgRemoved(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*org.OrgRemovedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-WTYC1", "seq", event.Sequence(), "expectedType", org.OrgRemovedEventType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-QSoSe", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-QSoSe", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(e,
|
||||
[]handler.Condition{
|
||||
|
||||
@@ -43,7 +43,7 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO zitadel.projections.idp_login_policy_links (idp_id, aggregate_id, creation_date, change_date, sequence, resource_owner, provider_type) VALUES ($1, $2, $3, $4, $5, $6, $7)",
|
||||
expectedStmt: "INSERT INTO projections.idp_login_policy_links (idp_id, aggregate_id, creation_date, change_date, sequence, resource_owner, instance_id, provider_type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-config-id",
|
||||
"agg-id",
|
||||
@@ -51,6 +51,7 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) {
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
"ro-id",
|
||||
"instance-id",
|
||||
domain.IdentityProviderTypeSystem,
|
||||
},
|
||||
},
|
||||
@@ -79,7 +80,7 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.idp_login_policy_links WHERE (idp_id = $1) AND (aggregate_id = $2)",
|
||||
expectedStmt: "DELETE FROM projections.idp_login_policy_links WHERE (idp_id = $1) AND (aggregate_id = $2)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-config-id",
|
||||
"agg-id",
|
||||
@@ -110,7 +111,7 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.idp_login_policy_links WHERE (idp_id = $1) AND (aggregate_id = $2)",
|
||||
expectedStmt: "DELETE FROM projections.idp_login_policy_links WHERE (idp_id = $1) AND (aggregate_id = $2)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-config-id",
|
||||
"agg-id",
|
||||
@@ -141,7 +142,7 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO zitadel.projections.idp_login_policy_links (idp_id, aggregate_id, creation_date, change_date, sequence, resource_owner, provider_type) VALUES ($1, $2, $3, $4, $5, $6, $7)",
|
||||
expectedStmt: "INSERT INTO projections.idp_login_policy_links (idp_id, aggregate_id, creation_date, change_date, sequence, resource_owner, instance_id, provider_type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-config-id",
|
||||
"agg-id",
|
||||
@@ -149,6 +150,7 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) {
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
"ro-id",
|
||||
"instance-id",
|
||||
domain.IdentityProviderTypeOrg,
|
||||
},
|
||||
},
|
||||
@@ -177,7 +179,7 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.idp_login_policy_links WHERE (idp_id = $1) AND (aggregate_id = $2)",
|
||||
expectedStmt: "DELETE FROM projections.idp_login_policy_links WHERE (idp_id = $1) AND (aggregate_id = $2)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-config-id",
|
||||
"agg-id",
|
||||
@@ -208,7 +210,7 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.idp_login_policy_links WHERE (idp_id = $1) AND (aggregate_id = $2)",
|
||||
expectedStmt: "DELETE FROM projections.idp_login_policy_links WHERE (idp_id = $1) AND (aggregate_id = $2)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-config-id",
|
||||
"agg-id",
|
||||
@@ -236,7 +238,7 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.idp_login_policy_links WHERE (resource_owner = $1)",
|
||||
expectedStmt: "DELETE FROM projections.idp_login_policy_links WHERE (resource_owner = $1)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
},
|
||||
@@ -265,7 +267,7 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.idp_login_policy_links WHERE (idp_id = $1) AND (resource_owner = $2)",
|
||||
expectedStmt: "DELETE FROM projections.idp_login_policy_links WHERE (idp_id = $1) AND (resource_owner = $2)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-config-id",
|
||||
"ro-id",
|
||||
@@ -295,7 +297,7 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.idp_login_policy_links WHERE (idp_id = $1) AND (resource_owner = $2)",
|
||||
expectedStmt: "DELETE FROM projections.idp_login_policy_links WHERE (idp_id = $1) AND (resource_owner = $2)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-config-id",
|
||||
"ro-id",
|
||||
|
||||
@@ -3,6 +3,8 @@ package projection
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/lib/pq"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
@@ -10,7 +12,6 @@ import (
|
||||
"github.com/caos/zitadel/internal/eventstore/repository"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/org"
|
||||
"github.com/lib/pq"
|
||||
)
|
||||
|
||||
func TestIDPProjection_reduces(t *testing.T) {
|
||||
@@ -47,13 +48,14 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO zitadel.projections.idps (id, creation_date, change_date, sequence, resource_owner, state, name, styling_type, auto_register, owner_type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)",
|
||||
expectedStmt: "INSERT INTO projections.idps (id, creation_date, change_date, sequence, resource_owner, instance_id, state, name, styling_type, auto_register, owner_type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-config-id",
|
||||
anyArg{},
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
"ro-id",
|
||||
"instance-id",
|
||||
domain.IDPConfigStateActive,
|
||||
"custom-zitadel-instance",
|
||||
domain.IDPConfigStylingTypeUnspecified,
|
||||
@@ -88,7 +90,7 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.idps SET (name, styling_type, auto_register, change_date, sequence) = ($1, $2, $3, $4, $5) WHERE (id = $6)",
|
||||
expectedStmt: "UPDATE projections.idps SET (name, styling_type, auto_register, change_date, sequence) = ($1, $2, $3, $4, $5) WHERE (id = $6)",
|
||||
expectedArgs: []interface{}{
|
||||
"custom-zitadel-instance",
|
||||
domain.IDPConfigStylingTypeGoogle,
|
||||
@@ -122,7 +124,7 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.idps SET (state, change_date, sequence) = ($1, $2, $3) WHERE (id = $4)",
|
||||
expectedStmt: "UPDATE projections.idps SET (state, change_date, sequence) = ($1, $2, $3) WHERE (id = $4)",
|
||||
expectedArgs: []interface{}{
|
||||
domain.IDPConfigStateInactive,
|
||||
anyArg{},
|
||||
@@ -154,7 +156,7 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.idps SET (state, change_date, sequence) = ($1, $2, $3) WHERE (id = $4)",
|
||||
expectedStmt: "UPDATE projections.idps SET (state, change_date, sequence) = ($1, $2, $3) WHERE (id = $4)",
|
||||
expectedArgs: []interface{}{
|
||||
domain.IDPConfigStateActive,
|
||||
anyArg{},
|
||||
@@ -186,7 +188,7 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.idps WHERE (id = $1)",
|
||||
expectedStmt: "DELETE FROM projections.idps WHERE (id = $1)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-config-id",
|
||||
},
|
||||
@@ -227,7 +229,7 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.idps SET (change_date, sequence, type) = ($1, $2, $3) WHERE (id = $4)",
|
||||
expectedStmt: "UPDATE projections.idps SET (change_date, sequence, type) = ($1, $2, $3) WHERE (id = $4)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -236,7 +238,7 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "INSERT INTO zitadel.projections.idps_oidc_config (idp_id, client_id, client_secret, issuer, scopes, display_name_mapping, username_mapping, authorization_endpoint, token_endpoint) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
||||
expectedStmt: "INSERT INTO projections.idps_oidc_config (idp_id, client_id, client_secret, issuer, scopes, display_name_mapping, username_mapping, authorization_endpoint, token_endpoint) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-config-id",
|
||||
"client-id",
|
||||
@@ -285,7 +287,7 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.idps SET (change_date, sequence) = ($1, $2) WHERE (id = $3)",
|
||||
expectedStmt: "UPDATE projections.idps SET (change_date, sequence) = ($1, $2) WHERE (id = $3)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -293,7 +295,7 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.idps_oidc_config SET (client_id, client_secret, issuer, authorization_endpoint, token_endpoint, scopes, display_name_mapping, username_mapping) = ($1, $2, $3, $4, $5, $6, $7, $8) WHERE (idp_id = $9)",
|
||||
expectedStmt: "UPDATE projections.idps_oidc_config SET (client_id, client_secret, issuer, authorization_endpoint, token_endpoint, scopes, display_name_mapping, username_mapping) = ($1, $2, $3, $4, $5, $6, $7, $8) WHERE (idp_id = $9)",
|
||||
expectedArgs: []interface{}{
|
||||
"client-id",
|
||||
anyArg{},
|
||||
@@ -354,7 +356,7 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.idps SET (change_date, sequence, type) = ($1, $2, $3) WHERE (id = $4)",
|
||||
expectedStmt: "UPDATE projections.idps SET (change_date, sequence, type) = ($1, $2, $3) WHERE (id = $4)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -363,7 +365,7 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "INSERT INTO zitadel.projections.idps_jwt_config (idp_id, endpoint, issuer, keys_endpoint, header_name) VALUES ($1, $2, $3, $4, $5)",
|
||||
expectedStmt: "INSERT INTO projections.idps_jwt_config (idp_id, endpoint, issuer, keys_endpoint, header_name) VALUES ($1, $2, $3, $4, $5)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-config-id",
|
||||
"https://api.zitadel.ch/jwt",
|
||||
@@ -400,7 +402,7 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.idps SET (change_date, sequence) = ($1, $2) WHERE (id = $3)",
|
||||
expectedStmt: "UPDATE projections.idps SET (change_date, sequence) = ($1, $2) WHERE (id = $3)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -408,7 +410,7 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.idps_jwt_config SET (endpoint, issuer, keys_endpoint, header_name) = ($1, $2, $3, $4) WHERE (idp_id = $5)",
|
||||
expectedStmt: "UPDATE projections.idps_jwt_config SET (endpoint, issuer, keys_endpoint, header_name) = ($1, $2, $3, $4) WHERE (idp_id = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
"https://api.zitadel.ch/jwt",
|
||||
"issuer",
|
||||
@@ -465,13 +467,14 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO zitadel.projections.idps (id, creation_date, change_date, sequence, resource_owner, state, name, styling_type, auto_register, owner_type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)",
|
||||
expectedStmt: "INSERT INTO projections.idps (id, creation_date, change_date, sequence, resource_owner, instance_id, state, name, styling_type, auto_register, owner_type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-config-id",
|
||||
anyArg{},
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
"ro-id",
|
||||
"instance-id",
|
||||
domain.IDPConfigStateActive,
|
||||
"custom-zitadel-instance",
|
||||
domain.IDPConfigStylingTypeUnspecified,
|
||||
@@ -506,7 +509,7 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.idps SET (name, styling_type, auto_register, change_date, sequence) = ($1, $2, $3, $4, $5) WHERE (id = $6)",
|
||||
expectedStmt: "UPDATE projections.idps SET (name, styling_type, auto_register, change_date, sequence) = ($1, $2, $3, $4, $5) WHERE (id = $6)",
|
||||
expectedArgs: []interface{}{
|
||||
"custom-zitadel-instance",
|
||||
domain.IDPConfigStylingTypeGoogle,
|
||||
@@ -540,7 +543,7 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.idps SET (state, change_date, sequence) = ($1, $2, $3) WHERE (id = $4)",
|
||||
expectedStmt: "UPDATE projections.idps SET (state, change_date, sequence) = ($1, $2, $3) WHERE (id = $4)",
|
||||
expectedArgs: []interface{}{
|
||||
domain.IDPConfigStateInactive,
|
||||
anyArg{},
|
||||
@@ -572,7 +575,7 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.idps SET (state, change_date, sequence) = ($1, $2, $3) WHERE (id = $4)",
|
||||
expectedStmt: "UPDATE projections.idps SET (state, change_date, sequence) = ($1, $2, $3) WHERE (id = $4)",
|
||||
expectedArgs: []interface{}{
|
||||
domain.IDPConfigStateActive,
|
||||
anyArg{},
|
||||
@@ -604,7 +607,7 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.idps WHERE (id = $1)",
|
||||
expectedStmt: "DELETE FROM projections.idps WHERE (id = $1)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-config-id",
|
||||
},
|
||||
@@ -645,7 +648,7 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.idps SET (change_date, sequence, type) = ($1, $2, $3) WHERE (id = $4)",
|
||||
expectedStmt: "UPDATE projections.idps SET (change_date, sequence, type) = ($1, $2, $3) WHERE (id = $4)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -654,7 +657,7 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "INSERT INTO zitadel.projections.idps_oidc_config (idp_id, client_id, client_secret, issuer, scopes, display_name_mapping, username_mapping, authorization_endpoint, token_endpoint) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
||||
expectedStmt: "INSERT INTO projections.idps_oidc_config (idp_id, client_id, client_secret, issuer, scopes, display_name_mapping, username_mapping, authorization_endpoint, token_endpoint) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-config-id",
|
||||
"client-id",
|
||||
@@ -703,7 +706,7 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.idps SET (change_date, sequence) = ($1, $2) WHERE (id = $3)",
|
||||
expectedStmt: "UPDATE projections.idps SET (change_date, sequence) = ($1, $2) WHERE (id = $3)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -711,7 +714,7 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.idps_oidc_config SET (client_id, client_secret, issuer, authorization_endpoint, token_endpoint, scopes, display_name_mapping, username_mapping) = ($1, $2, $3, $4, $5, $6, $7, $8) WHERE (idp_id = $9)",
|
||||
expectedStmt: "UPDATE projections.idps_oidc_config SET (client_id, client_secret, issuer, authorization_endpoint, token_endpoint, scopes, display_name_mapping, username_mapping) = ($1, $2, $3, $4, $5, $6, $7, $8) WHERE (idp_id = $9)",
|
||||
expectedArgs: []interface{}{
|
||||
"client-id",
|
||||
anyArg{},
|
||||
@@ -772,7 +775,7 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.idps SET (change_date, sequence, type) = ($1, $2, $3) WHERE (id = $4)",
|
||||
expectedStmt: "UPDATE projections.idps SET (change_date, sequence, type) = ($1, $2, $3) WHERE (id = $4)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -781,7 +784,7 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "INSERT INTO zitadel.projections.idps_jwt_config (idp_id, endpoint, issuer, keys_endpoint, header_name) VALUES ($1, $2, $3, $4, $5)",
|
||||
expectedStmt: "INSERT INTO projections.idps_jwt_config (idp_id, endpoint, issuer, keys_endpoint, header_name) VALUES ($1, $2, $3, $4, $5)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-config-id",
|
||||
"https://api.zitadel.ch/jwt",
|
||||
@@ -818,7 +821,7 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.idps SET (change_date, sequence) = ($1, $2) WHERE (id = $3)",
|
||||
expectedStmt: "UPDATE projections.idps SET (change_date, sequence) = ($1, $2) WHERE (id = $3)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -826,7 +829,7 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.idps_jwt_config SET (endpoint, issuer, keys_endpoint, header_name) = ($1, $2, $3, $4) WHERE (idp_id = $5)",
|
||||
expectedStmt: "UPDATE projections.idps_jwt_config SET (endpoint, issuer, keys_endpoint, header_name) = ($1, $2, $3, $4) WHERE (idp_id = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
"https://api.zitadel.ch/jwt",
|
||||
"issuer",
|
||||
|
||||
@@ -3,7 +3,6 @@ package projection
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/logging"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/eventstore/handler"
|
||||
@@ -13,6 +12,19 @@ import (
|
||||
"github.com/caos/zitadel/internal/repository/user"
|
||||
)
|
||||
|
||||
const (
|
||||
IDPUserLinkTable = "projections.idp_user_links"
|
||||
IDPUserLinkIDPIDCol = "idp_id"
|
||||
IDPUserLinkUserIDCol = "user_id"
|
||||
IDPUserLinkExternalUserIDCol = "external_user_id"
|
||||
IDPUserLinkCreationDateCol = "creation_date"
|
||||
IDPUserLinkChangeDateCol = "change_date"
|
||||
IDPUserLinkSequenceCol = "sequence"
|
||||
IDPUserLinkResourceOwnerCol = "resource_owner"
|
||||
IDPUserLinkInstanceIDCol = "instance_id"
|
||||
IDPUserLinkDisplayNameCol = "display_name"
|
||||
)
|
||||
|
||||
type IDPUserLinkProjection struct {
|
||||
crdb.StatementHandler
|
||||
}
|
||||
@@ -21,6 +33,22 @@ func NewIDPUserLinkProjection(ctx context.Context, config crdb.StatementHandlerC
|
||||
p := new(IDPUserLinkProjection)
|
||||
config.ProjectionName = IDPUserLinkTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(IDPUserLinkIDPIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(IDPUserLinkUserIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(IDPUserLinkExternalUserIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(IDPUserLinkCreationDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(IDPUserLinkChangeDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(IDPUserLinkSequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(IDPUserLinkResourceOwnerCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(IDPUserLinkInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(IDPUserLinkDisplayNameCol, crdb.ColumnTypeText),
|
||||
},
|
||||
crdb.NewPrimaryKey(IDPUserLinkInstanceIDCol, IDPUserLinkIDPIDCol, IDPUserLinkExternalUserIDCol),
|
||||
crdb.NewIndex("user_idx", []string{IDPUserLinkUserIDCol}),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
@@ -73,23 +101,10 @@ func (p *IDPUserLinkProjection) reducers() []handler.AggregateReducer {
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
IDPUserLinkTable = "zitadel.projections.idp_user_links"
|
||||
IDPUserLinkIDPIDCol = "idp_id"
|
||||
IDPUserLinkUserIDCol = "user_id"
|
||||
IDPUserLinkExternalUserIDCol = "external_user_id"
|
||||
IDPUserLinkCreationDateCol = "creation_date"
|
||||
IDPUserLinkChangeDateCol = "change_date"
|
||||
IDPUserLinkSequenceCol = "sequence"
|
||||
IDPUserLinkResourceOwnerCol = "resource_owner"
|
||||
IDPUserLinkDisplayNameCol = "display_name"
|
||||
)
|
||||
|
||||
func (p *IDPUserLinkProjection) reduceAdded(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*user.UserIDPLinkAddedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-v2qC3", "seq", event.Sequence(), "expectedType", user.UserIDPLinkAddedType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-DpmXq", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-DpmXq", "reduce.wrong.event.type %s", user.UserIDPLinkAddedType)
|
||||
}
|
||||
|
||||
return crdb.NewCreateStatement(e,
|
||||
@@ -101,6 +116,7 @@ func (p *IDPUserLinkProjection) reduceAdded(event eventstore.Event) (*handler.St
|
||||
handler.NewCol(IDPUserLinkChangeDateCol, e.CreationDate()),
|
||||
handler.NewCol(IDPUserLinkSequenceCol, e.Sequence()),
|
||||
handler.NewCol(IDPUserLinkResourceOwnerCol, e.Aggregate().ResourceOwner),
|
||||
handler.NewCol(IDPUserLinkInstanceIDCol, e.Aggregate().InstanceID),
|
||||
handler.NewCol(IDPUserLinkDisplayNameCol, e.DisplayName),
|
||||
},
|
||||
), nil
|
||||
@@ -109,8 +125,7 @@ func (p *IDPUserLinkProjection) reduceAdded(event eventstore.Event) (*handler.St
|
||||
func (p *IDPUserLinkProjection) reduceRemoved(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*user.UserIDPLinkRemovedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-zX5m9", "seq", event.Sequence(), "expectedType", user.UserIDPLinkRemovedType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-AZmfJ", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-AZmfJ", "reduce.wrong.event.type %s", user.UserIDPLinkRemovedType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(e,
|
||||
@@ -125,8 +140,7 @@ func (p *IDPUserLinkProjection) reduceRemoved(event eventstore.Event) (*handler.
|
||||
func (p *IDPUserLinkProjection) reduceCascadeRemoved(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*user.UserIDPLinkCascadeRemovedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-I0s2H", "seq", event.Sequence(), "expectedType", user.UserIDPLinkCascadeRemovedType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-jQpv9", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-jQpv9", "reduce.wrong.event.type %s", user.UserIDPLinkCascadeRemovedType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(e,
|
||||
@@ -141,8 +155,7 @@ func (p *IDPUserLinkProjection) reduceCascadeRemoved(event eventstore.Event) (*h
|
||||
func (p *IDPUserLinkProjection) reduceOrgRemoved(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*org.OrgRemovedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-zX5m9", "seq", event.Sequence(), "expectedType", org.OrgRemovedEventType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-AZmfJ", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-AZmfJ", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(e,
|
||||
@@ -155,8 +168,7 @@ func (p *IDPUserLinkProjection) reduceOrgRemoved(event eventstore.Event) (*handl
|
||||
func (p *IDPUserLinkProjection) reduceUserRemoved(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*user.UserRemovedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-yM6u6", "seq", event.Sequence(), "expectedType", user.UserRemovedType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-uwlWE", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-uwlWE", "reduce.wrong.event.type %s", user.UserRemovedType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(e,
|
||||
@@ -175,8 +187,7 @@ func (p *IDPUserLinkProjection) reduceIDPConfigRemoved(event eventstore.Event) (
|
||||
case *iam.IDPConfigRemovedEvent:
|
||||
idpID = e.ConfigID
|
||||
default:
|
||||
logging.LogWithFields("HANDL-7lZaf", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.IDPConfigRemovedEventType, iam.IDPConfigRemovedEventType}).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-iCKSj", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-iCKSj", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPConfigRemovedEventType, iam.IDPConfigRemovedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(event,
|
||||
|
||||
@@ -44,7 +44,7 @@ func TestIDPUserLinkProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO zitadel.projections.idp_user_links (idp_id, user_id, external_user_id, creation_date, change_date, sequence, resource_owner, display_name) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)",
|
||||
expectedStmt: "INSERT INTO projections.idp_user_links (idp_id, user_id, external_user_id, creation_date, change_date, sequence, resource_owner, instance_id, display_name) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-config-id",
|
||||
"agg-id",
|
||||
@@ -53,6 +53,7 @@ func TestIDPUserLinkProjection_reduces(t *testing.T) {
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
"ro-id",
|
||||
"instance-id",
|
||||
"[email protected]",
|
||||
},
|
||||
},
|
||||
@@ -81,7 +82,7 @@ func TestIDPUserLinkProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.idp_user_links WHERE (idp_id = $1) AND (user_id = $2) AND (external_user_id = $3)",
|
||||
expectedStmt: "DELETE FROM projections.idp_user_links WHERE (idp_id = $1) AND (user_id = $2) AND (external_user_id = $3)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-config-id",
|
||||
"agg-id",
|
||||
@@ -113,7 +114,7 @@ func TestIDPUserLinkProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.idp_user_links WHERE (idp_id = $1) AND (user_id = $2) AND (external_user_id = $3)",
|
||||
expectedStmt: "DELETE FROM projections.idp_user_links WHERE (idp_id = $1) AND (user_id = $2) AND (external_user_id = $3)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-config-id",
|
||||
"agg-id",
|
||||
@@ -142,7 +143,7 @@ func TestIDPUserLinkProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.idp_user_links WHERE (resource_owner = $1)",
|
||||
expectedStmt: "DELETE FROM projections.idp_user_links WHERE (resource_owner = $1)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
},
|
||||
@@ -169,7 +170,7 @@ func TestIDPUserLinkProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.idp_user_links WHERE (user_id = $1)",
|
||||
expectedStmt: "DELETE FROM projections.idp_user_links WHERE (user_id = $1)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
},
|
||||
@@ -198,7 +199,7 @@ func TestIDPUserLinkProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.idp_user_links WHERE (idp_id = $1) AND (resource_owner = $2)",
|
||||
expectedStmt: "DELETE FROM projections.idp_user_links WHERE (idp_id = $1) AND (resource_owner = $2)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-config-id",
|
||||
"ro-id",
|
||||
@@ -228,7 +229,7 @@ func TestIDPUserLinkProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.idp_user_links WHERE (idp_id = $1) AND (resource_owner = $2)",
|
||||
expectedStmt: "DELETE FROM projections.idp_user_links WHERE (idp_id = $1) AND (resource_owner = $2)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-config-id",
|
||||
"ro-id",
|
||||
|
||||
@@ -4,8 +4,6 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/caos/logging"
|
||||
|
||||
"github.com/caos/zitadel/internal/crypto"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
@@ -14,22 +12,71 @@ import (
|
||||
"github.com/caos/zitadel/internal/repository/keypair"
|
||||
)
|
||||
|
||||
const (
|
||||
KeyProjectionTable = "projections.keys"
|
||||
KeyPrivateTable = KeyProjectionTable + "_" + privateKeyTableSuffix
|
||||
KeyPublicTable = KeyProjectionTable + "_" + publicKeyTableSuffix
|
||||
|
||||
KeyColumnID = "id"
|
||||
KeyColumnCreationDate = "creation_date"
|
||||
KeyColumnChangeDate = "change_date"
|
||||
KeyColumnResourceOwner = "resource_owner"
|
||||
KeyColumnInstanceID = "instance_id"
|
||||
KeyColumnSequence = "sequence"
|
||||
KeyColumnAlgorithm = "algorithm"
|
||||
KeyColumnUse = "use"
|
||||
|
||||
privateKeyTableSuffix = "private"
|
||||
KeyPrivateColumnID = "id"
|
||||
KeyPrivateColumnExpiry = "expiry"
|
||||
KeyPrivateColumnKey = "key"
|
||||
|
||||
publicKeyTableSuffix = "public"
|
||||
KeyPublicColumnID = "id"
|
||||
KeyPublicColumnExpiry = "expiry"
|
||||
KeyPublicColumnKey = "key"
|
||||
)
|
||||
|
||||
type KeyProjection struct {
|
||||
crdb.StatementHandler
|
||||
encryptionAlgorithm crypto.EncryptionAlgorithm
|
||||
keyChan chan<- interface{}
|
||||
}
|
||||
|
||||
const (
|
||||
KeyProjectionTable = "zitadel.projections.keys"
|
||||
KeyPrivateTable = KeyProjectionTable + "_" + privateKeyTableSuffix
|
||||
KeyPublicTable = KeyProjectionTable + "_" + publicKeyTableSuffix
|
||||
)
|
||||
|
||||
func NewKeyProjection(ctx context.Context, config crdb.StatementHandlerConfig, keyEncryptionAlgorithm crypto.EncryptionAlgorithm, keyChan chan<- interface{}) *KeyProjection {
|
||||
p := new(KeyProjection)
|
||||
config.ProjectionName = KeyProjectionTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewMultiTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(KeyColumnID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(KeyColumnCreationDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(KeyColumnChangeDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(KeyColumnResourceOwner, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(KeyColumnInstanceID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(KeyColumnSequence, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(KeyColumnAlgorithm, crdb.ColumnTypeText, crdb.Default("")),
|
||||
crdb.NewColumn(KeyColumnUse, crdb.ColumnTypeText, crdb.Default("")),
|
||||
},
|
||||
crdb.NewPrimaryKey(KeyColumnInstanceID, KeyColumnID),
|
||||
),
|
||||
crdb.NewSuffixedTable([]*crdb.Column{
|
||||
crdb.NewColumn(KeyPrivateColumnID, crdb.ColumnTypeText, crdb.DeleteCascade(KeyColumnID)),
|
||||
crdb.NewColumn(KeyPrivateColumnExpiry, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(KeyPrivateColumnKey, crdb.ColumnTypeJSONB),
|
||||
},
|
||||
crdb.NewPrimaryKey(KeyPrivateColumnID),
|
||||
privateKeyTableSuffix,
|
||||
),
|
||||
crdb.NewSuffixedTable([]*crdb.Column{
|
||||
crdb.NewColumn(KeyPublicColumnID, crdb.ColumnTypeText, crdb.DeleteCascade(KeyColumnID)),
|
||||
crdb.NewColumn(KeyPublicColumnExpiry, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(KeyPublicColumnKey, crdb.ColumnTypeBytes),
|
||||
},
|
||||
crdb.NewPrimaryKey(KeyPublicColumnID),
|
||||
publicKeyTableSuffix,
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
p.keyChan = keyChan
|
||||
p.encryptionAlgorithm = keyEncryptionAlgorithm
|
||||
@@ -51,31 +98,10 @@ func (p *KeyProjection) reducers() []handler.AggregateReducer {
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
KeyColumnID = "id"
|
||||
KeyColumnCreationDate = "creation_date"
|
||||
KeyColumnChangeDate = "change_date"
|
||||
KeyColumnResourceOwner = "resource_owner"
|
||||
KeyColumnSequence = "sequence"
|
||||
KeyColumnAlgorithm = "algorithm"
|
||||
KeyColumnUse = "use"
|
||||
|
||||
privateKeyTableSuffix = "private"
|
||||
KeyPrivateColumnID = "id"
|
||||
KeyPrivateColumnExpiry = "expiry"
|
||||
KeyPrivateColumnKey = "key"
|
||||
|
||||
publicKeyTableSuffix = "public"
|
||||
KeyPublicColumnID = "id"
|
||||
KeyPublicColumnExpiry = "expiry"
|
||||
KeyPublicColumnKey = "key"
|
||||
)
|
||||
|
||||
func (p *KeyProjection) reduceKeyPairAdded(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*keypair.AddedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-GEdg3", "seq", event.Sequence(), "expectedType", keypair.AddedEventType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-SAbr2", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-SAbr2", "reduce.wrong.event.type %s", keypair.AddedEventType)
|
||||
}
|
||||
if e.PrivateKey.Expiry.Before(time.Now()) && e.PublicKey.Expiry.Before(time.Now()) {
|
||||
return crdb.NewNoOpStatement(e), nil
|
||||
@@ -87,6 +113,7 @@ func (p *KeyProjection) reduceKeyPairAdded(event eventstore.Event) (*handler.Sta
|
||||
handler.NewCol(KeyColumnCreationDate, e.CreationDate()),
|
||||
handler.NewCol(KeyColumnChangeDate, e.CreationDate()),
|
||||
handler.NewCol(KeyColumnResourceOwner, e.Aggregate().ResourceOwner),
|
||||
handler.NewCol(KeyColumnInstanceID, e.Aggregate().InstanceID),
|
||||
handler.NewCol(KeyColumnSequence, e.Sequence()),
|
||||
handler.NewCol(KeyColumnAlgorithm, e.Algorithm),
|
||||
handler.NewCol(KeyColumnUse, e.Usage),
|
||||
@@ -109,7 +136,6 @@ func (p *KeyProjection) reduceKeyPairAdded(event eventstore.Event) (*handler.Sta
|
||||
if e.PublicKey.Expiry.After(time.Now()) {
|
||||
publicKey, err := crypto.Decrypt(e.PublicKey.Key, p.encryptionAlgorithm)
|
||||
if err != nil {
|
||||
logging.LogWithFields("HANDL-SDfw2", "seq", event.Sequence()).Error("cannot decrypt public key")
|
||||
return nil, errors.ThrowInternal(err, "HANDL-DAg2f", "cannot decrypt public key")
|
||||
}
|
||||
creates = append(creates, crdb.AddCreateStatement(
|
||||
|
||||
@@ -43,19 +43,20 @@ func TestKeyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO zitadel.projections.keys (id, creation_date, change_date, resource_owner, sequence, algorithm, use) VALUES ($1, $2, $3, $4, $5, $6, $7)",
|
||||
expectedStmt: "INSERT INTO projections.keys (id, creation_date, change_date, resource_owner, instance_id, sequence, algorithm, use) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
anyArg{},
|
||||
anyArg{},
|
||||
"ro-id",
|
||||
"instance-id",
|
||||
uint64(15),
|
||||
"algorithm",
|
||||
domain.KeyUsageSigning,
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "INSERT INTO zitadel.projections.keys_private (id, expiry, key) VALUES ($1, $2, $3)",
|
||||
expectedStmt: "INSERT INTO projections.keys_private (id, expiry, key) VALUES ($1, $2, $3)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
anyArg{},
|
||||
@@ -68,7 +69,7 @@ func TestKeyProjection_reduces(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "INSERT INTO zitadel.projections.keys_public (id, expiry, key) VALUES ($1, $2, $3)",
|
||||
expectedStmt: "INSERT INTO projections.keys_public (id, expiry, key) VALUES ($1, $2, $3)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
anyArg{},
|
||||
|
||||
@@ -3,7 +3,6 @@ package projection
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/logging"
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
@@ -14,18 +13,75 @@ import (
|
||||
"github.com/caos/zitadel/internal/repository/policy"
|
||||
)
|
||||
|
||||
const (
|
||||
LabelPolicyTable = "projections.label_policies"
|
||||
|
||||
LabelPolicyIDCol = "id"
|
||||
LabelPolicyCreationDateCol = "creation_date"
|
||||
LabelPolicyChangeDateCol = "change_date"
|
||||
LabelPolicySequenceCol = "sequence"
|
||||
LabelPolicyStateCol = "state"
|
||||
LabelPolicyIsDefaultCol = "is_default"
|
||||
LabelPolicyResourceOwnerCol = "resource_owner"
|
||||
LabelPolicyInstanceIDCol = "instance_id"
|
||||
LabelPolicyHideLoginNameSuffixCol = "hide_login_name_suffix"
|
||||
LabelPolicyWatermarkDisabledCol = "watermark_disabled"
|
||||
LabelPolicyShouldErrorPopupCol = "should_error_popup"
|
||||
LabelPolicyFontURLCol = "font_url"
|
||||
|
||||
LabelPolicyLightPrimaryColorCol = "light_primary_color"
|
||||
LabelPolicyLightWarnColorCol = "light_warn_color"
|
||||
LabelPolicyLightBackgroundColorCol = "light_background_color"
|
||||
LabelPolicyLightFontColorCol = "light_font_color"
|
||||
LabelPolicyLightLogoURLCol = "light_logo_url"
|
||||
LabelPolicyLightIconURLCol = "light_icon_url"
|
||||
|
||||
LabelPolicyDarkPrimaryColorCol = "dark_primary_color"
|
||||
LabelPolicyDarkWarnColorCol = "dark_warn_color"
|
||||
LabelPolicyDarkBackgroundColorCol = "dark_background_color"
|
||||
LabelPolicyDarkFontColorCol = "dark_font_color"
|
||||
LabelPolicyDarkLogoURLCol = "dark_logo_url"
|
||||
LabelPolicyDarkIconURLCol = "dark_icon_url"
|
||||
)
|
||||
|
||||
type LabelPolicyProjection struct {
|
||||
crdb.StatementHandler
|
||||
}
|
||||
|
||||
const (
|
||||
LabelPolicyTable = "zitadel.projections.label_policies"
|
||||
)
|
||||
|
||||
func NewLabelPolicyProjection(ctx context.Context, config crdb.StatementHandlerConfig) *LabelPolicyProjection {
|
||||
p := new(LabelPolicyProjection)
|
||||
config.ProjectionName = LabelPolicyTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(LabelPolicyIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(LabelPolicyCreationDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(LabelPolicyChangeDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(LabelPolicySequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(LabelPolicyStateCol, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(LabelPolicyIsDefaultCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(LabelPolicyResourceOwnerCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(LabelPolicyInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(LabelPolicyHideLoginNameSuffixCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(LabelPolicyWatermarkDisabledCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(LabelPolicyShouldErrorPopupCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(LabelPolicyFontURLCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(LabelPolicyLightPrimaryColorCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(LabelPolicyLightWarnColorCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(LabelPolicyLightBackgroundColorCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(LabelPolicyLightFontColorCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(LabelPolicyLightLogoURLCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(LabelPolicyLightIconURLCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(LabelPolicyDarkPrimaryColorCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(LabelPolicyDarkWarnColorCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(LabelPolicyDarkBackgroundColorCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(LabelPolicyDarkFontColorCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(LabelPolicyDarkLogoURLCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(LabelPolicyDarkIconURLCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
},
|
||||
crdb.NewPrimaryKey(LabelPolicyInstanceIDCol, LabelPolicyIDCol, LabelPolicyStateCol),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
@@ -172,8 +228,7 @@ func (p *LabelPolicyProjection) reduceAdded(event eventstore.Event) (*handler.St
|
||||
policyEvent = e.LabelPolicyAddedEvent
|
||||
isDefault = true
|
||||
default:
|
||||
logging.LogWithFields("PROJE-zR6h0", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.LabelPolicyAddedEventType, iam.LabelPolicyAddedEventType}).Error("was not an event")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "PROJE-CSE7A", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-CSE7A", "reduce.wrong.event.type %v", []eventstore.EventType{org.LabelPolicyAddedEventType, iam.LabelPolicyAddedEventType})
|
||||
}
|
||||
return crdb.NewCreateStatement(
|
||||
&policyEvent,
|
||||
@@ -185,6 +240,7 @@ func (p *LabelPolicyProjection) reduceAdded(event eventstore.Event) (*handler.St
|
||||
handler.NewCol(LabelPolicyStateCol, domain.LabelPolicyStatePreview),
|
||||
handler.NewCol(LabelPolicyIsDefaultCol, isDefault),
|
||||
handler.NewCol(LabelPolicyResourceOwnerCol, policyEvent.Aggregate().ResourceOwner),
|
||||
handler.NewCol(LabelPolicyInstanceIDCol, policyEvent.Aggregate().InstanceID),
|
||||
handler.NewCol(LabelPolicyLightPrimaryColorCol, policyEvent.PrimaryColor),
|
||||
handler.NewCol(LabelPolicyLightBackgroundColorCol, policyEvent.BackgroundColor),
|
||||
handler.NewCol(LabelPolicyLightWarnColorCol, policyEvent.WarnColor),
|
||||
@@ -207,8 +263,7 @@ func (p *LabelPolicyProjection) reduceChanged(event eventstore.Event) (*handler.
|
||||
case *iam.LabelPolicyChangedEvent:
|
||||
policyEvent = e.LabelPolicyChangedEvent
|
||||
default:
|
||||
logging.LogWithFields("PROJE-2VrlG", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.LabelPolicyChangedEventType, iam.LabelPolicyChangedEventType}).Error("was not an event")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "PROJE-qgVug", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-qgVug", "reduce.wrong.event.type %v", []eventstore.EventType{org.LabelPolicyChangedEventType, iam.LabelPolicyChangedEventType})
|
||||
}
|
||||
cols := []handler.Column{
|
||||
handler.NewCol(LabelPolicyChangeDateCol, policyEvent.CreationDate()),
|
||||
@@ -259,8 +314,7 @@ func (p *LabelPolicyProjection) reduceChanged(event eventstore.Event) (*handler.
|
||||
func (p *LabelPolicyProjection) reduceRemoved(event eventstore.Event) (*handler.Statement, error) {
|
||||
policyEvent, ok := event.(*org.LabelPolicyRemovedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("PROJE-izDbs", "seq", event.Sequence(), "expectedType", org.LabelPolicyRemovedEventType).Error("was not an event")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "PROJE-ATMBz", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-ATMBz", "reduce.wrong.event.type %s", org.LabelPolicyRemovedEventType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
policyEvent,
|
||||
@@ -274,8 +328,7 @@ func (p *LabelPolicyProjection) reduceActivated(event eventstore.Event) (*handle
|
||||
case *org.LabelPolicyActivatedEvent, *iam.LabelPolicyActivatedEvent:
|
||||
// everything ok
|
||||
default:
|
||||
logging.LogWithFields("PROJE-ZQO7J", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.LabelPolicyActivatedEventType, iam.LabelPolicyActivatedEventType}).Error("was not an event")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "PROJE-dldEU", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-dldEU", "reduce.wrong.event.type %v", []eventstore.EventType{org.LabelPolicyActivatedEventType, iam.LabelPolicyActivatedEventType})
|
||||
}
|
||||
return crdb.NewCopyStatement(
|
||||
event,
|
||||
@@ -322,8 +375,7 @@ func (p *LabelPolicyProjection) reduceLogoAdded(event eventstore.Event) (*handle
|
||||
case *iam.LabelPolicyLogoDarkAddedEvent:
|
||||
storeKey = handler.NewCol(LabelPolicyDarkLogoURLCol, e.StoreKey)
|
||||
default:
|
||||
logging.LogWithFields("PROJE-NHrbi", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.LabelPolicyLogoAddedEventType, iam.LabelPolicyLogoAddedEventType, org.LabelPolicyLogoDarkAddedEventType, iam.LabelPolicyLogoDarkAddedEventType}).Error("was not an event")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "PROJE-4wbOI", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-4wbOI", "reduce.wrong.event.type %v", []eventstore.EventType{org.LabelPolicyLogoAddedEventType, iam.LabelPolicyLogoAddedEventType, org.LabelPolicyLogoDarkAddedEventType, iam.LabelPolicyLogoDarkAddedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
@@ -351,8 +403,7 @@ func (p *LabelPolicyProjection) reduceLogoRemoved(event eventstore.Event) (*hand
|
||||
case *iam.LabelPolicyLogoDarkRemovedEvent:
|
||||
col = LabelPolicyDarkLogoURLCol
|
||||
default:
|
||||
logging.LogWithFields("PROJE-oUmnS", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.LabelPolicyLogoRemovedEventType, iam.LabelPolicyLogoRemovedEventType, org.LabelPolicyLogoDarkRemovedEventType, iam.LabelPolicyLogoDarkRemovedEventType}).Error("was not an event")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "PROJE-kg8H4", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-kg8H4", "reduce.wrong.event.type %v", []eventstore.EventType{org.LabelPolicyLogoRemovedEventType, iam.LabelPolicyLogoRemovedEventType, org.LabelPolicyLogoDarkRemovedEventType, iam.LabelPolicyLogoDarkRemovedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
@@ -380,8 +431,7 @@ func (p *LabelPolicyProjection) reduceIconAdded(event eventstore.Event) (*handle
|
||||
case *iam.LabelPolicyIconDarkAddedEvent:
|
||||
storeKey = handler.NewCol(LabelPolicyDarkIconURLCol, e.StoreKey)
|
||||
default:
|
||||
logging.LogWithFields("PROJE-6efFw", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.LabelPolicyIconAddedEventType, iam.LabelPolicyIconAddedEventType, org.LabelPolicyIconDarkAddedEventType, iam.LabelPolicyIconDarkAddedEventType}).Error("was not an event")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "PROJE-e2JFz", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-e2JFz", "reduce.wrong.event.type %v", []eventstore.EventType{org.LabelPolicyIconAddedEventType, iam.LabelPolicyIconAddedEventType, org.LabelPolicyIconDarkAddedEventType, iam.LabelPolicyIconDarkAddedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
@@ -409,8 +459,7 @@ func (p *LabelPolicyProjection) reduceIconRemoved(event eventstore.Event) (*hand
|
||||
case *iam.LabelPolicyIconDarkRemovedEvent:
|
||||
col = LabelPolicyDarkIconURLCol
|
||||
default:
|
||||
logging.LogWithFields("PROJE-0BiAZ", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.LabelPolicyIconRemovedEventType, iam.LabelPolicyIconRemovedEventType, org.LabelPolicyIconDarkRemovedEventType, iam.LabelPolicyIconDarkRemovedEventType}).Error("was not an event")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "PROJE-gfgbY", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-gfgbY", "reduce.wrong.event.type %v", []eventstore.EventType{org.LabelPolicyIconRemovedEventType, iam.LabelPolicyIconRemovedEventType, org.LabelPolicyIconDarkRemovedEventType, iam.LabelPolicyIconDarkRemovedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
@@ -434,8 +483,7 @@ func (p *LabelPolicyProjection) reduceFontAdded(event eventstore.Event) (*handle
|
||||
case *iam.LabelPolicyFontAddedEvent:
|
||||
storeKey = handler.NewCol(LabelPolicyFontURLCol, e.StoreKey)
|
||||
default:
|
||||
logging.LogWithFields("PROJE-DCzfX", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.LabelPolicyFontAddedEventType, iam.LabelPolicyFontAddedEventType}).Error("was not an event")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "PROJE-65i9W", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-65i9W", "reduce.wrong.event.type %v", []eventstore.EventType{org.LabelPolicyFontAddedEventType, iam.LabelPolicyFontAddedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
@@ -459,8 +507,7 @@ func (p *LabelPolicyProjection) reduceFontRemoved(event eventstore.Event) (*hand
|
||||
case *iam.LabelPolicyFontRemovedEvent:
|
||||
col = LabelPolicyFontURLCol
|
||||
default:
|
||||
logging.LogWithFields("PROJE-YKwG4", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.LabelPolicyFontRemovedEventType, iam.LabelPolicyFontRemovedEventType}).Error("was not an event")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "PROJE-xf32J", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-xf32J", "reduce.wrong.event.type %v", []eventstore.EventType{org.LabelPolicyFontRemovedEventType, iam.LabelPolicyFontRemovedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
@@ -481,8 +528,7 @@ func (p *LabelPolicyProjection) reduceAssetsRemoved(event eventstore.Event) (*ha
|
||||
case *org.LabelPolicyAssetsRemovedEvent, *iam.LabelPolicyAssetsRemovedEvent:
|
||||
//ok
|
||||
default:
|
||||
logging.LogWithFields("PROJE-YKwG4", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.LabelPolicyAssetsRemovedEventType, iam.LabelPolicyAssetsRemovedEventType}).Error("was not an event")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "PROJE-qi39A", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-qi39A", "reduce.wrong.event.type %v", []eventstore.EventType{org.LabelPolicyAssetsRemovedEventType, iam.LabelPolicyAssetsRemovedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
@@ -501,31 +547,3 @@ func (p *LabelPolicyProjection) reduceAssetsRemoved(event eventstore.Event) (*ha
|
||||
handler.NewCond(LabelPolicyStateCol, domain.LabelPolicyStatePreview),
|
||||
}), nil
|
||||
}
|
||||
|
||||
const (
|
||||
LabelPolicyCreationDateCol = "creation_date"
|
||||
LabelPolicyChangeDateCol = "change_date"
|
||||
LabelPolicySequenceCol = "sequence"
|
||||
LabelPolicyIDCol = "id"
|
||||
LabelPolicyStateCol = "state"
|
||||
LabelPolicyIsDefaultCol = "is_default"
|
||||
LabelPolicyResourceOwnerCol = "resource_owner"
|
||||
LabelPolicyHideLoginNameSuffixCol = "hide_login_name_suffix"
|
||||
LabelPolicyFontURLCol = "font_url"
|
||||
LabelPolicyWatermarkDisabledCol = "watermark_disabled"
|
||||
LabelPolicyShouldErrorPopupCol = "should_error_popup"
|
||||
|
||||
LabelPolicyLightPrimaryColorCol = "light_primary_color"
|
||||
LabelPolicyLightWarnColorCol = "light_warn_color"
|
||||
LabelPolicyLightBackgroundColorCol = "light_background_color"
|
||||
LabelPolicyLightFontColorCol = "light_font_color"
|
||||
LabelPolicyLightLogoURLCol = "light_logo_url"
|
||||
LabelPolicyLightIconURLCol = "light_icon_url"
|
||||
|
||||
LabelPolicyDarkPrimaryColorCol = "dark_primary_color"
|
||||
LabelPolicyDarkWarnColorCol = "dark_warn_color"
|
||||
LabelPolicyDarkBackgroundColorCol = "dark_background_color"
|
||||
LabelPolicyDarkFontColorCol = "dark_font_color"
|
||||
LabelPolicyDarkLogoURLCol = "dark_logo_url"
|
||||
LabelPolicyDarkIconURLCol = "dark_icon_url"
|
||||
)
|
||||
|
||||
@@ -40,7 +40,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO zitadel.projections.label_policies (creation_date, change_date, sequence, id, state, is_default, resource_owner, light_primary_color, light_background_color, light_warn_color, light_font_color, dark_primary_color, dark_background_color, dark_warn_color, dark_font_color, hide_login_name_suffix, should_error_popup, watermark_disabled) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18)",
|
||||
expectedStmt: "INSERT INTO projections.label_policies (creation_date, change_date, sequence, id, state, is_default, resource_owner, instance_id, light_primary_color, light_background_color, light_warn_color, light_font_color, dark_primary_color, dark_background_color, dark_warn_color, dark_font_color, hide_login_name_suffix, should_error_popup, watermark_disabled) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
anyArg{},
|
||||
@@ -49,6 +49,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
domain.LabelPolicyStatePreview,
|
||||
false,
|
||||
"ro-id",
|
||||
"instance-id",
|
||||
"#5282c1",
|
||||
"#141735",
|
||||
"#ff3b5b",
|
||||
@@ -84,7 +85,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.label_policies SET (change_date, sequence, light_primary_color, light_background_color, light_warn_color, light_font_color) = ($1, $2, $3, $4, $5, $6) WHERE (id = $7) AND (state = $8)",
|
||||
expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, light_primary_color, light_background_color, light_warn_color, light_font_color) = ($1, $2, $3, $4, $5, $6) WHERE (id = $7) AND (state = $8)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -118,7 +119,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.label_policies WHERE (id = $1)",
|
||||
expectedStmt: "DELETE FROM projections.label_policies WHERE (id = $1)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
},
|
||||
@@ -145,7 +146,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPSERT INTO zitadel.projections.label_policies (change_date, sequence, state, creation_date, resource_owner, id, is_default, hide_login_name_suffix, font_url, watermark_disabled, should_error_popup, light_primary_color, light_warn_color, light_background_color, light_font_color, light_logo_url, light_icon_url, dark_primary_color, dark_warn_color, dark_background_color, dark_font_color, dark_logo_url, dark_icon_url) SELECT $1, $2, $3, creation_date, resource_owner, id, is_default, hide_login_name_suffix, font_url, watermark_disabled, should_error_popup, light_primary_color, light_warn_color, light_background_color, light_font_color, light_logo_url, light_icon_url, dark_primary_color, dark_warn_color, dark_background_color, dark_font_color, dark_logo_url, dark_icon_url FROM zitadel.projections.label_policies AS copy_table WHERE copy_table.id = $4 AND copy_table.state = $5",
|
||||
expectedStmt: "UPSERT INTO projections.label_policies (change_date, sequence, state, creation_date, resource_owner, id, is_default, hide_login_name_suffix, font_url, watermark_disabled, should_error_popup, light_primary_color, light_warn_color, light_background_color, light_font_color, light_logo_url, light_icon_url, dark_primary_color, dark_warn_color, dark_background_color, dark_font_color, dark_logo_url, dark_icon_url) SELECT $1, $2, $3, creation_date, resource_owner, id, is_default, hide_login_name_suffix, font_url, watermark_disabled, should_error_popup, light_primary_color, light_warn_color, light_background_color, light_font_color, light_logo_url, light_icon_url, dark_primary_color, dark_warn_color, dark_background_color, dark_font_color, dark_logo_url, dark_icon_url FROM projections.label_policies AS copy_table WHERE copy_table.id = $4 AND copy_table.state = $5",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -176,7 +177,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.label_policies SET (change_date, sequence, light_logo_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, light_logo_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -207,7 +208,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.label_policies SET (change_date, sequence, dark_logo_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, dark_logo_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -238,7 +239,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.label_policies SET (change_date, sequence, light_icon_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, light_icon_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -269,7 +270,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.label_policies SET (change_date, sequence, dark_icon_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, dark_icon_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -300,7 +301,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.label_policies SET (change_date, sequence, light_logo_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, light_logo_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -331,7 +332,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.label_policies SET (change_date, sequence, dark_logo_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, dark_logo_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -362,7 +363,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.label_policies SET (change_date, sequence, light_icon_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, light_icon_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -393,7 +394,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.label_policies SET (change_date, sequence, dark_icon_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, dark_icon_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -424,7 +425,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.label_policies SET (change_date, sequence, font_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, font_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -455,7 +456,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.label_policies SET (change_date, sequence, font_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, font_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -486,7 +487,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.label_policies SET (change_date, sequence, light_logo_url, light_icon_url, dark_logo_url, dark_icon_url, font_url) = ($1, $2, $3, $4, $5, $6, $7) WHERE (id = $8) AND (state = $9)",
|
||||
expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, light_logo_url, light_icon_url, dark_logo_url, dark_icon_url, font_url) = ($1, $2, $3, $4, $5, $6, $7) WHERE (id = $8) AND (state = $9)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -521,7 +522,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO zitadel.projections.label_policies (creation_date, change_date, sequence, id, state, is_default, resource_owner, light_primary_color, light_background_color, light_warn_color, light_font_color, dark_primary_color, dark_background_color, dark_warn_color, dark_font_color, hide_login_name_suffix, should_error_popup, watermark_disabled) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18)",
|
||||
expectedStmt: "INSERT INTO projections.label_policies (creation_date, change_date, sequence, id, state, is_default, resource_owner, instance_id, light_primary_color, light_background_color, light_warn_color, light_font_color, dark_primary_color, dark_background_color, dark_warn_color, dark_font_color, hide_login_name_suffix, should_error_popup, watermark_disabled) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
anyArg{},
|
||||
@@ -530,6 +531,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
domain.LabelPolicyStatePreview,
|
||||
true,
|
||||
"ro-id",
|
||||
"instance-id",
|
||||
"#5282c1",
|
||||
"#141735",
|
||||
"#ff3b5b",
|
||||
@@ -565,7 +567,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.label_policies SET (change_date, sequence, light_primary_color, light_background_color, light_warn_color, light_font_color, dark_primary_color, dark_background_color, dark_warn_color, dark_font_color, hide_login_name_suffix, should_error_popup, watermark_disabled) = ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13) WHERE (id = $14) AND (state = $15)",
|
||||
expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, light_primary_color, light_background_color, light_warn_color, light_font_color, dark_primary_color, dark_background_color, dark_warn_color, dark_font_color, hide_login_name_suffix, should_error_popup, watermark_disabled) = ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13) WHERE (id = $14) AND (state = $15)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -606,7 +608,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPSERT INTO zitadel.projections.label_policies (change_date, sequence, state, creation_date, resource_owner, id, is_default, hide_login_name_suffix, font_url, watermark_disabled, should_error_popup, light_primary_color, light_warn_color, light_background_color, light_font_color, light_logo_url, light_icon_url, dark_primary_color, dark_warn_color, dark_background_color, dark_font_color, dark_logo_url, dark_icon_url) SELECT $1, $2, $3, creation_date, resource_owner, id, is_default, hide_login_name_suffix, font_url, watermark_disabled, should_error_popup, light_primary_color, light_warn_color, light_background_color, light_font_color, light_logo_url, light_icon_url, dark_primary_color, dark_warn_color, dark_background_color, dark_font_color, dark_logo_url, dark_icon_url FROM zitadel.projections.label_policies AS copy_table WHERE copy_table.id = $4 AND copy_table.state = $5",
|
||||
expectedStmt: "UPSERT INTO projections.label_policies (change_date, sequence, state, creation_date, resource_owner, id, is_default, hide_login_name_suffix, font_url, watermark_disabled, should_error_popup, light_primary_color, light_warn_color, light_background_color, light_font_color, light_logo_url, light_icon_url, dark_primary_color, dark_warn_color, dark_background_color, dark_font_color, dark_logo_url, dark_icon_url) SELECT $1, $2, $3, creation_date, resource_owner, id, is_default, hide_login_name_suffix, font_url, watermark_disabled, should_error_popup, light_primary_color, light_warn_color, light_background_color, light_font_color, light_logo_url, light_icon_url, dark_primary_color, dark_warn_color, dark_background_color, dark_font_color, dark_logo_url, dark_icon_url FROM projections.label_policies AS copy_table WHERE copy_table.id = $4 AND copy_table.state = $5",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -637,7 +639,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.label_policies SET (change_date, sequence, light_logo_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, light_logo_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -668,7 +670,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.label_policies SET (change_date, sequence, dark_logo_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, dark_logo_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -699,7 +701,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.label_policies SET (change_date, sequence, light_icon_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, light_icon_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -730,7 +732,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.label_policies SET (change_date, sequence, dark_icon_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, dark_icon_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -761,7 +763,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.label_policies SET (change_date, sequence, light_logo_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, light_logo_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -792,7 +794,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.label_policies SET (change_date, sequence, dark_logo_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, dark_logo_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -823,7 +825,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.label_policies SET (change_date, sequence, light_icon_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, light_icon_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -854,7 +856,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.label_policies SET (change_date, sequence, dark_icon_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, dark_icon_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -885,7 +887,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.label_policies SET (change_date, sequence, font_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, font_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -916,7 +918,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.label_policies SET (change_date, sequence, font_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, font_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -947,7 +949,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.label_policies SET (change_date, sequence, light_logo_url, light_icon_url, dark_logo_url, dark_icon_url, font_url) = ($1, $2, $3, $4, $5, $6, $7) WHERE (id = $8) AND (state = $9)",
|
||||
expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, light_logo_url, light_icon_url, dark_logo_url, dark_icon_url, font_url) = ($1, $2, $3, $4, $5, $6, $7) WHERE (id = $8) AND (state = $9)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
|
||||
@@ -3,7 +3,6 @@ package projection
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/logging"
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
@@ -14,28 +13,45 @@ import (
|
||||
"github.com/caos/zitadel/internal/repository/policy"
|
||||
)
|
||||
|
||||
type LockoutPolicyProjection struct {
|
||||
crdb.StatementHandler
|
||||
}
|
||||
|
||||
const (
|
||||
LockoutPolicyTable = "zitadel.projections.lockout_policies"
|
||||
LockoutPolicyTable = "projections.lockout_policies"
|
||||
|
||||
LockoutPolicyIDCol = "id"
|
||||
LockoutPolicyCreationDateCol = "creation_date"
|
||||
LockoutPolicyChangeDateCol = "change_date"
|
||||
LockoutPolicySequenceCol = "sequence"
|
||||
LockoutPolicyIDCol = "id"
|
||||
LockoutPolicyStateCol = "state"
|
||||
LockoutPolicyMaxPasswordAttemptsCol = "max_password_attempts"
|
||||
LockoutPolicyShowLockOutFailuresCol = "show_failure"
|
||||
LockoutPolicyIsDefaultCol = "is_default"
|
||||
LockoutPolicyResourceOwnerCol = "resource_owner"
|
||||
LockoutPolicyInstanceIDCol = "instance_id"
|
||||
LockoutPolicyMaxPasswordAttemptsCol = "max_password_attempts"
|
||||
LockoutPolicyShowLockOutFailuresCol = "show_failure"
|
||||
)
|
||||
|
||||
type LockoutPolicyProjection struct {
|
||||
crdb.StatementHandler
|
||||
}
|
||||
|
||||
func NewLockoutPolicyProjection(ctx context.Context, config crdb.StatementHandlerConfig) *LockoutPolicyProjection {
|
||||
p := new(LockoutPolicyProjection)
|
||||
config.ProjectionName = LockoutPolicyTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(LockoutPolicyIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(LockoutPolicyCreationDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(LockoutPolicyChangeDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(LockoutPolicySequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(LockoutPolicyStateCol, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(LockoutPolicyIsDefaultCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(LockoutPolicyResourceOwnerCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(LockoutPolicyInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(LockoutPolicyMaxPasswordAttemptsCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(LockoutPolicyShowLockOutFailuresCol, crdb.ColumnTypeBool),
|
||||
},
|
||||
crdb.NewPrimaryKey(LockoutPolicyInstanceIDCol, LockoutPolicyIDCol),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
@@ -86,8 +102,7 @@ func (p *LockoutPolicyProjection) reduceAdded(event eventstore.Event) (*handler.
|
||||
policyEvent = e.LockoutPolicyAddedEvent
|
||||
isDefault = true
|
||||
default:
|
||||
logging.LogWithFields("PROJE-uFqFM", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.LockoutPolicyAddedEventType, iam.LockoutPolicyAddedEventType}).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "PROJE-d8mZO", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-d8mZO", "reduce.wrong.event.type, %v", []eventstore.EventType{org.LockoutPolicyAddedEventType, iam.LockoutPolicyAddedEventType})
|
||||
}
|
||||
return crdb.NewCreateStatement(
|
||||
&policyEvent,
|
||||
@@ -101,6 +116,7 @@ func (p *LockoutPolicyProjection) reduceAdded(event eventstore.Event) (*handler.
|
||||
handler.NewCol(LockoutPolicyShowLockOutFailuresCol, policyEvent.ShowLockOutFailures),
|
||||
handler.NewCol(LockoutPolicyIsDefaultCol, isDefault),
|
||||
handler.NewCol(LockoutPolicyResourceOwnerCol, policyEvent.Aggregate().ResourceOwner),
|
||||
handler.NewCol(LockoutPolicyInstanceIDCol, policyEvent.Aggregate().InstanceID),
|
||||
}), nil
|
||||
}
|
||||
|
||||
@@ -112,8 +128,7 @@ func (p *LockoutPolicyProjection) reduceChanged(event eventstore.Event) (*handle
|
||||
case *iam.LockoutPolicyChangedEvent:
|
||||
policyEvent = e.LockoutPolicyChangedEvent
|
||||
default:
|
||||
logging.LogWithFields("PROJE-iIkej", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.LockoutPolicyChangedEventType, iam.LockoutPolicyChangedEventType}).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "PROJE-pT3mQ", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-pT3mQ", "reduce.wrong.event.type, %v", []eventstore.EventType{org.LockoutPolicyChangedEventType, iam.LockoutPolicyChangedEventType})
|
||||
}
|
||||
cols := []handler.Column{
|
||||
handler.NewCol(LockoutPolicyChangeDateCol, policyEvent.CreationDate()),
|
||||
@@ -136,8 +151,7 @@ func (p *LockoutPolicyProjection) reduceChanged(event eventstore.Event) (*handle
|
||||
func (p *LockoutPolicyProjection) reduceRemoved(event eventstore.Event) (*handler.Statement, error) {
|
||||
policyEvent, ok := event.(*org.LockoutPolicyRemovedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("PROJE-U5cys", "seq", event.Sequence(), "expectedType", org.LockoutPolicyRemovedEventType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "PROJE-Bqut9", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-Bqut9", "reduce.wrong.event.type %s", org.LockoutPolicyRemovedEventType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
policyEvent,
|
||||
|
||||
@@ -43,7 +43,7 @@ func TestLockoutPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO zitadel.projections.lockout_policies (creation_date, change_date, sequence, id, state, max_password_attempts, show_failure, is_default, resource_owner) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
||||
expectedStmt: "INSERT INTO projections.lockout_policies (creation_date, change_date, sequence, id, state, max_password_attempts, show_failure, is_default, resource_owner, instance_id) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
anyArg{},
|
||||
@@ -54,6 +54,7 @@ func TestLockoutPolicyProjection_reduces(t *testing.T) {
|
||||
true,
|
||||
false,
|
||||
"ro-id",
|
||||
"instance-id",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -81,7 +82,7 @@ func TestLockoutPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.lockout_policies SET (change_date, sequence, max_password_attempts, show_failure) = ($1, $2, $3, $4) WHERE (id = $5)",
|
||||
expectedStmt: "UPDATE projections.lockout_policies SET (change_date, sequence, max_password_attempts, show_failure) = ($1, $2, $3, $4) WHERE (id = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -112,7 +113,7 @@ func TestLockoutPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.lockout_policies WHERE (id = $1)",
|
||||
expectedStmt: "DELETE FROM projections.lockout_policies WHERE (id = $1)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
},
|
||||
@@ -142,7 +143,7 @@ func TestLockoutPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO zitadel.projections.lockout_policies (creation_date, change_date, sequence, id, state, max_password_attempts, show_failure, is_default, resource_owner) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
||||
expectedStmt: "INSERT INTO projections.lockout_policies (creation_date, change_date, sequence, id, state, max_password_attempts, show_failure, is_default, resource_owner, instance_id) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
anyArg{},
|
||||
@@ -153,6 +154,7 @@ func TestLockoutPolicyProjection_reduces(t *testing.T) {
|
||||
true,
|
||||
true,
|
||||
"ro-id",
|
||||
"instance-id",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -180,7 +182,7 @@ func TestLockoutPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.lockout_policies SET (change_date, sequence, max_password_attempts, show_failure) = ($1, $2, $3, $4) WHERE (id = $5)",
|
||||
expectedStmt: "UPDATE projections.lockout_policies SET (change_date, sequence, max_password_attempts, show_failure) = ($1, $2, $3, $4) WHERE (id = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
|
||||
@@ -2,8 +2,8 @@ package projection
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/caos/logging"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/eventstore/handler"
|
||||
@@ -14,21 +14,117 @@ import (
|
||||
"github.com/caos/zitadel/internal/repository/user"
|
||||
)
|
||||
|
||||
type LoginNameProjection struct {
|
||||
crdb.StatementHandler
|
||||
}
|
||||
|
||||
const (
|
||||
LoginNameProjectionTable = "zitadel.projections.login_names"
|
||||
LoginNameProjectionTable = "projections.login_names"
|
||||
LoginNameUserProjectionTable = LoginNameProjectionTable + "_" + loginNameUserSuffix
|
||||
LoginNamePolicyProjectionTable = LoginNameProjectionTable + "_" + loginNamePolicySuffix
|
||||
LoginNameDomainProjectionTable = LoginNameProjectionTable + "_" + loginNameDomainSuffix
|
||||
|
||||
LoginNameCol = "login_name"
|
||||
|
||||
loginNameUserSuffix = "users"
|
||||
LoginNameUserIDCol = "id"
|
||||
LoginNameUserUserNameCol = "user_name"
|
||||
LoginNameUserResourceOwnerCol = "resource_owner"
|
||||
LoginNameUserInstanceIDCol = "instance_id"
|
||||
|
||||
loginNameDomainSuffix = "domains"
|
||||
LoginNameDomainNameCol = "name"
|
||||
LoginNameDomainIsPrimaryCol = "is_primary"
|
||||
LoginNameDomainResourceOwnerCol = "resource_owner"
|
||||
LoginNameDomainInstanceIDCol = "instance_id"
|
||||
|
||||
loginNamePolicySuffix = "policies"
|
||||
LoginNamePoliciesMustBeDomainCol = "must_be_domain"
|
||||
LoginNamePoliciesIsDefaultCol = "is_default"
|
||||
LoginNamePoliciesResourceOwnerCol = "resource_owner"
|
||||
LoginNamePoliciesInstanceIDCol = "instance_id"
|
||||
)
|
||||
|
||||
var (
|
||||
viewStmt = fmt.Sprintf("SELECT"+
|
||||
" user_id"+
|
||||
" , IF(%[1]s, CONCAT(%[2]s, '@', domain), %[2]s) AS login_name"+
|
||||
" , IFNULL(%[3]s, true) AS %[3]s"+
|
||||
" , %[4]s"+
|
||||
" FROM ("+
|
||||
" SELECT"+
|
||||
" policy_users.user_id"+
|
||||
" , policy_users.%[2]s"+
|
||||
" , policy_users.%[5]s"+
|
||||
" , policy_users.%[4]s"+
|
||||
" , policy_users.%[1]s"+
|
||||
" , domains.%[6]s AS domain"+
|
||||
" , domains.%[3]s"+
|
||||
" FROM ("+
|
||||
" SELECT"+
|
||||
" users.id as user_id"+
|
||||
" , users.%[2]s"+
|
||||
" , users.%[4]s"+
|
||||
" , users.%[5]s"+
|
||||
" , IFNULL(policy_custom.%[1]s, policy_default.%[1]s) AS %[1]s"+
|
||||
" FROM %[7]s users"+
|
||||
" LEFT JOIN %[8]s policy_custom on policy_custom.%[9]s = users.%[5]s AND policy_custom.%[10]s = users.%[4]s"+
|
||||
" LEFT JOIN %[8]s policy_default on policy_default.%[11]s = true) policy_users"+
|
||||
" LEFT JOIN %[12]s domains ON policy_users.%[1]s AND policy_users.%[5]s = domains.%[13]s AND policy_users.%[10]s = domains.%[14]s"+
|
||||
");",
|
||||
LoginNamePoliciesMustBeDomainCol,
|
||||
LoginNameUserUserNameCol,
|
||||
LoginNameDomainIsPrimaryCol,
|
||||
LoginNameUserInstanceIDCol,
|
||||
LoginNameUserResourceOwnerCol,
|
||||
LoginNameDomainNameCol,
|
||||
LoginNameUserProjectionTable,
|
||||
LoginNamePolicyProjectionTable,
|
||||
LoginNamePoliciesResourceOwnerCol,
|
||||
LoginNamePoliciesInstanceIDCol,
|
||||
LoginNamePoliciesIsDefaultCol,
|
||||
LoginNameDomainProjectionTable,
|
||||
LoginNameDomainResourceOwnerCol,
|
||||
LoginNameDomainInstanceIDCol,
|
||||
)
|
||||
)
|
||||
|
||||
type LoginNameProjection struct {
|
||||
crdb.StatementHandler
|
||||
}
|
||||
|
||||
func NewLoginNameProjection(ctx context.Context, config crdb.StatementHandlerConfig) *LoginNameProjection {
|
||||
p := new(LoginNameProjection)
|
||||
config.ProjectionName = LoginNameProjectionTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewViewCheck(
|
||||
viewStmt,
|
||||
crdb.NewSuffixedTable([]*crdb.Column{
|
||||
crdb.NewColumn(LoginNameUserIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(LoginNameUserUserNameCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(LoginNameUserResourceOwnerCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(LoginNameUserInstanceIDCol, crdb.ColumnTypeText),
|
||||
},
|
||||
crdb.NewPrimaryKey(LoginNameUserInstanceIDCol, LoginNameUserIDCol),
|
||||
loginNameUserSuffix,
|
||||
crdb.NewIndex("ro_idx", []string{LoginNameUserResourceOwnerCol}),
|
||||
),
|
||||
crdb.NewSuffixedTable([]*crdb.Column{
|
||||
crdb.NewColumn(LoginNameDomainNameCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(LoginNameDomainIsPrimaryCol, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(LoginNameDomainResourceOwnerCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(LoginNameDomainInstanceIDCol, crdb.ColumnTypeText),
|
||||
},
|
||||
crdb.NewPrimaryKey(LoginNameDomainInstanceIDCol, LoginNameDomainResourceOwnerCol, LoginNameDomainNameCol),
|
||||
loginNameDomainSuffix,
|
||||
),
|
||||
crdb.NewSuffixedTable([]*crdb.Column{
|
||||
crdb.NewColumn(LoginNamePoliciesMustBeDomainCol, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(LoginNamePoliciesIsDefaultCol, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(LoginNamePoliciesResourceOwnerCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(LoginNamePoliciesInstanceIDCol, crdb.ColumnTypeText),
|
||||
},
|
||||
crdb.NewPrimaryKey(LoginNamePoliciesInstanceIDCol, LoginNamePoliciesResourceOwnerCol),
|
||||
loginNamePolicySuffix,
|
||||
crdb.NewIndex("is_default_idx", []string{LoginNamePoliciesResourceOwnerCol, LoginNamePoliciesIsDefaultCol}),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
@@ -120,25 +216,6 @@ func (p *LoginNameProjection) reducers() []handler.AggregateReducer {
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
LoginNameCol = "login_name"
|
||||
|
||||
loginNameUserSuffix = "users"
|
||||
LoginNameUserIDCol = "id"
|
||||
LoginNameUserUserNameCol = "user_name"
|
||||
LoginNameUserResourceOwnerCol = "resource_owner"
|
||||
|
||||
loginNameDomainSuffix = "domains"
|
||||
LoginNameDomainNameCol = "name"
|
||||
LoginNameDomainIsPrimaryCol = "is_primary"
|
||||
LoginNameDomainResourceOwnerCol = "resource_owner"
|
||||
|
||||
loginNamePolicySuffix = "policies"
|
||||
LoginNamePoliciesMustBeDomainCol = "must_be_domain"
|
||||
LoginNamePoliciesIsDefaultCol = "is_default"
|
||||
LoginNamePoliciesResourceOwnerCol = "resource_owner"
|
||||
)
|
||||
|
||||
func (p *LoginNameProjection) reduceUserCreated(event eventstore.Event) (*handler.Statement, error) {
|
||||
var userName string
|
||||
|
||||
@@ -150,8 +227,7 @@ func (p *LoginNameProjection) reduceUserCreated(event eventstore.Event) (*handle
|
||||
case *user.MachineAddedEvent:
|
||||
userName = e.UserName
|
||||
default:
|
||||
logging.LogWithFields("HANDL-tDUx3", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{user.UserV1AddedType, user.HumanAddedType, user.UserV1RegisteredType, user.HumanRegisteredType, user.MachineAddedEventType}).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-ayo69", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-ayo69", "reduce.wrong.event.type %v", []eventstore.EventType{user.UserV1AddedType, user.HumanAddedType, user.UserV1RegisteredType, user.HumanRegisteredType, user.MachineAddedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewCreateStatement(
|
||||
@@ -160,6 +236,7 @@ func (p *LoginNameProjection) reduceUserCreated(event eventstore.Event) (*handle
|
||||
handler.NewCol(LoginNameUserIDCol, event.Aggregate().ID),
|
||||
handler.NewCol(LoginNameUserUserNameCol, userName),
|
||||
handler.NewCol(LoginNameUserResourceOwnerCol, event.Aggregate().ResourceOwner),
|
||||
handler.NewCol(LoginNameUserInstanceIDCol, event.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(loginNameUserSuffix),
|
||||
), nil
|
||||
@@ -168,8 +245,7 @@ func (p *LoginNameProjection) reduceUserCreated(event eventstore.Event) (*handle
|
||||
func (p *LoginNameProjection) reduceUserRemoved(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*user.UserRemovedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-8XEdC", "seq", event.Sequence(), "expectedType", user.UserRemovedType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-QIe3C", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-QIe3C", "reduce.wrong.event.type %s", user.UserRemovedType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
@@ -184,8 +260,7 @@ func (p *LoginNameProjection) reduceUserRemoved(event eventstore.Event) (*handle
|
||||
func (p *LoginNameProjection) reduceUserNameChanged(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*user.UsernameChangedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-UGo7U", "seq", event.Sequence(), "expectedType", user.UserUserNameChangedType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-QlwjC", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-QlwjC", "reduce.wrong.event.type %s", user.UserUserNameChangedType)
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
@@ -203,8 +278,7 @@ func (p *LoginNameProjection) reduceUserNameChanged(event eventstore.Event) (*ha
|
||||
func (p *LoginNameProjection) reduceUserDomainClaimed(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*user.DomainClaimedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-zIbyU", "seq", event.Sequence(), "expectedType", user.UserDomainClaimedType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-AQMBY", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-AQMBY", "reduce.wrong.event.type %s", user.UserDomainClaimedType)
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
@@ -233,8 +307,7 @@ func (p *LoginNameProjection) reduceOrgIAMPolicyAdded(event eventstore.Event) (*
|
||||
policyEvent = &e.OrgIAMPolicyAddedEvent
|
||||
isDefault = true
|
||||
default:
|
||||
logging.LogWithFields("HANDL-PQluH", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.OrgIAMPolicyAddedEventType, iam.OrgIAMPolicyAddedEventType}).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-yCV6S", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-yCV6S", "reduce.wrong.event.type %v", []eventstore.EventType{org.OrgIAMPolicyAddedEventType, iam.OrgIAMPolicyAddedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewCreateStatement(
|
||||
@@ -243,6 +316,7 @@ func (p *LoginNameProjection) reduceOrgIAMPolicyAdded(event eventstore.Event) (*
|
||||
handler.NewCol(LoginNamePoliciesMustBeDomainCol, policyEvent.UserLoginMustBeDomain),
|
||||
handler.NewCol(LoginNamePoliciesIsDefaultCol, isDefault),
|
||||
handler.NewCol(LoginNamePoliciesResourceOwnerCol, policyEvent.Aggregate().ResourceOwner),
|
||||
handler.NewCol(LoginNamePoliciesInstanceIDCol, policyEvent.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(loginNamePolicySuffix),
|
||||
), nil
|
||||
@@ -257,8 +331,7 @@ func (p *LoginNameProjection) reduceOrgIAMPolicyChanged(event eventstore.Event)
|
||||
case *iam.OrgIAMPolicyChangedEvent:
|
||||
policyEvent = &e.OrgIAMPolicyChangedEvent
|
||||
default:
|
||||
logging.LogWithFields("HANDL-Z27QN", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.OrgIAMPolicyChangedEventType, iam.OrgIAMPolicyChangedEventType}).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-ArFDd", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-ArFDd", "reduce.wrong.event.type %v", []eventstore.EventType{org.OrgIAMPolicyChangedEventType, iam.OrgIAMPolicyChangedEventType})
|
||||
}
|
||||
|
||||
if policyEvent.UserLoginMustBeDomain == nil {
|
||||
@@ -280,8 +353,7 @@ func (p *LoginNameProjection) reduceOrgIAMPolicyChanged(event eventstore.Event)
|
||||
func (p *LoginNameProjection) reduceOrgIAMPolicyRemoved(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*org.OrgIAMPolicyRemovedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-1ZFHL", "seq", event.Sequence(), "expectedType", org.OrgIAMPolicyRemovedEventType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-ysEeB", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-ysEeB", "reduce.wrong.event.type %s", org.OrgIAMPolicyRemovedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
@@ -296,8 +368,7 @@ func (p *LoginNameProjection) reduceOrgIAMPolicyRemoved(event eventstore.Event)
|
||||
func (p *LoginNameProjection) reduceDomainVerified(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*org.DomainVerifiedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-Rr7Tq", "seq", event.Sequence(), "expectedType", org.OrgDomainVerifiedEventType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-weGAh", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-weGAh", "reduce.wrong.event.type %s", org.OrgDomainVerifiedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewCreateStatement(
|
||||
@@ -305,6 +376,7 @@ func (p *LoginNameProjection) reduceDomainVerified(event eventstore.Event) (*han
|
||||
[]handler.Column{
|
||||
handler.NewCol(LoginNameDomainNameCol, e.Domain),
|
||||
handler.NewCol(LoginNameDomainResourceOwnerCol, e.Aggregate().ResourceOwner),
|
||||
handler.NewCol(LoginNameDomainInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(loginNameDomainSuffix),
|
||||
), nil
|
||||
@@ -313,8 +385,7 @@ func (p *LoginNameProjection) reduceDomainVerified(event eventstore.Event) (*han
|
||||
func (p *LoginNameProjection) reducePrimaryDomainSet(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*org.DomainPrimarySetEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-0L5tW", "seq", event.Sequence(), "expectedType", org.OrgDomainPrimarySetEventType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-eOXPN", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-eOXPN", "reduce.wrong.event.type %s", org.OrgDomainPrimarySetEventType)
|
||||
}
|
||||
|
||||
return crdb.NewMultiStatement(
|
||||
@@ -345,8 +416,7 @@ func (p *LoginNameProjection) reducePrimaryDomainSet(event eventstore.Event) (*h
|
||||
func (p *LoginNameProjection) reduceDomainRemoved(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*org.DomainRemovedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-reP2u", "seq", event.Sequence(), "expectedType", org.OrgDomainRemovedEventType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-4RHYq", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-4RHYq", "reduce.wrong.event.type %s", org.OrgDomainRemovedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
|
||||
@@ -42,11 +42,12 @@ func TestLoginNameProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO zitadel.projections.login_names_users (id, user_name, resource_owner) VALUES ($1, $2, $3)",
|
||||
expectedStmt: "INSERT INTO projections.login_names_users (id, user_name, resource_owner, instance_id) VALUES ($1, $2, $3, $4)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
"human-added",
|
||||
"ro-id",
|
||||
"instance-id",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -73,11 +74,12 @@ func TestLoginNameProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO zitadel.projections.login_names_users (id, user_name, resource_owner) VALUES ($1, $2, $3)",
|
||||
expectedStmt: "INSERT INTO projections.login_names_users (id, user_name, resource_owner, instance_id) VALUES ($1, $2, $3, $4)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
"human-registered",
|
||||
"ro-id",
|
||||
"instance-id",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -104,11 +106,12 @@ func TestLoginNameProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO zitadel.projections.login_names_users (id, user_name, resource_owner) VALUES ($1, $2, $3)",
|
||||
expectedStmt: "INSERT INTO projections.login_names_users (id, user_name, resource_owner, instance_id) VALUES ($1, $2, $3, $4)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
"machine-added",
|
||||
"ro-id",
|
||||
"instance-id",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -133,7 +136,7 @@ func TestLoginNameProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.login_names_users WHERE (id = $1)",
|
||||
expectedStmt: "DELETE FROM projections.login_names_users WHERE (id = $1)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
},
|
||||
@@ -162,7 +165,7 @@ func TestLoginNameProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.login_names_users SET (user_name) = ($1) WHERE (id = $2)",
|
||||
expectedStmt: "UPDATE projections.login_names_users SET (user_name) = ($1) WHERE (id = $2)",
|
||||
expectedArgs: []interface{}{
|
||||
"changed",
|
||||
"agg-id",
|
||||
@@ -192,7 +195,7 @@ func TestLoginNameProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.login_names_users SET (user_name) = ($1) WHERE (id = $2)",
|
||||
expectedStmt: "UPDATE projections.login_names_users SET (user_name) = ($1) WHERE (id = $2)",
|
||||
expectedArgs: []interface{}{
|
||||
"claimed",
|
||||
"agg-id",
|
||||
@@ -222,11 +225,12 @@ func TestLoginNameProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO zitadel.projections.login_names_policies (must_be_domain, is_default, resource_owner) VALUES ($1, $2, $3)",
|
||||
expectedStmt: "INSERT INTO projections.login_names_policies (must_be_domain, is_default, resource_owner, instance_id) VALUES ($1, $2, $3, $4)",
|
||||
expectedArgs: []interface{}{
|
||||
true,
|
||||
false,
|
||||
"ro-id",
|
||||
"instance-id",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -253,7 +257,7 @@ func TestLoginNameProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.login_names_policies SET (must_be_domain) = ($1) WHERE (resource_owner = $2)",
|
||||
expectedStmt: "UPDATE projections.login_names_policies SET (must_be_domain) = ($1) WHERE (resource_owner = $2)",
|
||||
expectedArgs: []interface{}{
|
||||
false,
|
||||
"ro-id",
|
||||
@@ -301,7 +305,7 @@ func TestLoginNameProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.login_names_policies WHERE (resource_owner = $1)",
|
||||
expectedStmt: "DELETE FROM projections.login_names_policies WHERE (resource_owner = $1)",
|
||||
expectedArgs: []interface{}{
|
||||
"ro-id",
|
||||
},
|
||||
@@ -330,10 +334,11 @@ func TestLoginNameProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO zitadel.projections.login_names_domains (name, resource_owner) VALUES ($1, $2)",
|
||||
expectedStmt: "INSERT INTO projections.login_names_domains (name, resource_owner, instance_id) VALUES ($1, $2, $3)",
|
||||
expectedArgs: []interface{}{
|
||||
"verified",
|
||||
"ro-id",
|
||||
"instance-id",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -360,7 +365,7 @@ func TestLoginNameProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.login_names_domains WHERE (name = $1) AND (resource_owner = $2)",
|
||||
expectedStmt: "DELETE FROM projections.login_names_domains WHERE (name = $1) AND (resource_owner = $2)",
|
||||
expectedArgs: []interface{}{
|
||||
"remove",
|
||||
"ro-id",
|
||||
@@ -390,7 +395,7 @@ func TestLoginNameProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.login_names_domains SET (is_primary) = ($1) WHERE (resource_owner = $2) AND (is_primary = $3)",
|
||||
expectedStmt: "UPDATE projections.login_names_domains SET (is_primary) = ($1) WHERE (resource_owner = $2) AND (is_primary = $3)",
|
||||
expectedArgs: []interface{}{
|
||||
false,
|
||||
"ro-id",
|
||||
@@ -398,7 +403,7 @@ func TestLoginNameProjection_reduces(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.login_names_domains SET (is_primary) = ($1) WHERE (name = $2) AND (resource_owner = $3)",
|
||||
expectedStmt: "UPDATE projections.login_names_domains SET (is_primary) = ($1) WHERE (name = $2) AND (resource_owner = $3)",
|
||||
expectedArgs: []interface{}{
|
||||
true,
|
||||
"primary",
|
||||
@@ -429,11 +434,12 @@ func TestLoginNameProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO zitadel.projections.login_names_policies (must_be_domain, is_default, resource_owner) VALUES ($1, $2, $3)",
|
||||
expectedStmt: "INSERT INTO projections.login_names_policies (must_be_domain, is_default, resource_owner, instance_id) VALUES ($1, $2, $3, $4)",
|
||||
expectedArgs: []interface{}{
|
||||
true,
|
||||
true,
|
||||
"ro-id",
|
||||
"instance-id",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -460,7 +466,7 @@ func TestLoginNameProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.login_names_policies SET (must_be_domain) = ($1) WHERE (resource_owner = $2)",
|
||||
expectedStmt: "UPDATE projections.login_names_policies SET (must_be_domain) = ($1) WHERE (resource_owner = $2)",
|
||||
expectedArgs: []interface{}{
|
||||
false,
|
||||
"ro-id",
|
||||
|
||||
@@ -3,8 +3,6 @@ package projection
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/logging"
|
||||
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/eventstore/handler"
|
||||
@@ -14,18 +12,63 @@ import (
|
||||
"github.com/caos/zitadel/internal/repository/policy"
|
||||
)
|
||||
|
||||
const (
|
||||
LoginPolicyTable = "projections.login_policies"
|
||||
|
||||
LoginPolicyIDCol = "aggregate_id"
|
||||
LoginPolicyInstanceIDCol = "instance_id"
|
||||
LoginPolicyCreationDateCol = "creation_date"
|
||||
LoginPolicyChangeDateCol = "change_date"
|
||||
LoginPolicySequenceCol = "sequence"
|
||||
LoginPolicyIsDefaultCol = "is_default"
|
||||
LoginPolicyAllowRegisterCol = "allow_register"
|
||||
LoginPolicyAllowUsernamePasswordCol = "allow_username_password"
|
||||
LoginPolicyAllowExternalIDPsCol = "allow_external_idps"
|
||||
LoginPolicyForceMFACol = "force_mfa"
|
||||
LoginPolicy2FAsCol = "second_factors"
|
||||
LoginPolicyMFAsCol = "multi_factors"
|
||||
LoginPolicyPasswordlessTypeCol = "passwordless_type"
|
||||
LoginPolicyHidePWResetCol = "hide_password_reset"
|
||||
PasswordCheckLifetimeCol = "password_check_lifetime"
|
||||
ExternalLoginCheckLifetimeCol = "external_login_check_lifetime"
|
||||
MFAInitSkipLifetimeCol = "mfa_init_skip_lifetime"
|
||||
SecondFactorCheckLifetimeCol = "second_factor_check_lifetime"
|
||||
MultiFactorCheckLifetimeCol = "multi_factor_check_lifetime"
|
||||
)
|
||||
|
||||
type LoginPolicyProjection struct {
|
||||
crdb.StatementHandler
|
||||
}
|
||||
|
||||
const (
|
||||
LoginPolicyTable = "zitadel.projections.login_policies"
|
||||
)
|
||||
|
||||
func NewLoginPolicyProjection(ctx context.Context, config crdb.StatementHandlerConfig) *LoginPolicyProjection {
|
||||
p := new(LoginPolicyProjection)
|
||||
config.ProjectionName = LoginPolicyTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(LoginPolicyIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(LoginPolicyInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(LoginPolicyCreationDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(LoginPolicyChangeDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(LoginPolicySequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(LoginPolicyIsDefaultCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(LoginPolicyAllowRegisterCol, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(LoginPolicyAllowUsernamePasswordCol, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(LoginPolicyAllowExternalIDPsCol, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(LoginPolicyForceMFACol, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(LoginPolicy2FAsCol, crdb.ColumnTypeEnumArray),
|
||||
crdb.NewColumn(LoginPolicyMFAsCol, crdb.ColumnTypeEnumArray),
|
||||
crdb.NewColumn(LoginPolicyPasswordlessTypeCol, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(LoginPolicyHidePWResetCol, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(PasswordCheckLifetimeCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(ExternalLoginCheckLifetimeCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(MFAInitSkipLifetimeCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(SecondFactorCheckLifetimeCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(MultiFactorCheckLifetimeCol, crdb.ColumnTypeInt64),
|
||||
},
|
||||
crdb.NewPrimaryKey(LoginPolicyInstanceIDCol, LoginPolicyIDCol),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
@@ -97,27 +140,6 @@ func (p *LoginPolicyProjection) reducers() []handler.AggregateReducer {
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
LoginPolicyIDCol = "aggregate_id"
|
||||
LoginPolicyCreationDateCol = "creation_date"
|
||||
LoginPolicyChangeDateCol = "change_date"
|
||||
LoginPolicySequenceCol = "sequence"
|
||||
LoginPolicyAllowRegisterCol = "allow_register"
|
||||
LoginPolicyAllowUsernamePasswordCol = "allow_username_password"
|
||||
LoginPolicyAllowExternalIDPsCol = "allow_external_idps"
|
||||
LoginPolicyForceMFACol = "force_mfa"
|
||||
LoginPolicy2FAsCol = "second_factors"
|
||||
LoginPolicyMFAsCol = "multi_factors"
|
||||
LoginPolicyPasswordlessTypeCol = "passwordless_type"
|
||||
LoginPolicyIsDefaultCol = "is_default"
|
||||
LoginPolicyHidePWResetCol = "hide_password_reset"
|
||||
PasswordCheckLifetimeCol = "password_check_lifetime"
|
||||
ExternalLoginCheckLifetimeCol = "external_login_check_lifetime"
|
||||
MFAInitSkipLifetimeCol = "mfa_init_skip_lifetime"
|
||||
SecondFactorCheckLifetimeCol = "second_factor_check_lifetime"
|
||||
MultiFactorCheckLifetimeCol = "multi_factor_check_lifetime"
|
||||
)
|
||||
|
||||
func (p *LoginPolicyProjection) reduceLoginPolicyAdded(event eventstore.Event) (*handler.Statement, error) {
|
||||
var policyEvent policy.LoginPolicyAddedEvent
|
||||
var isDefault bool
|
||||
@@ -129,12 +151,12 @@ func (p *LoginPolicyProjection) reduceLoginPolicyAdded(event eventstore.Event) (
|
||||
policyEvent = e.LoginPolicyAddedEvent
|
||||
isDefault = false
|
||||
default:
|
||||
logging.LogWithFields("HANDL-IW6So", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.LoginPolicyAddedEventType, iam.LoginPolicyAddedEventType}).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-pYPxS", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-pYPxS", "reduce.wrong.event.type %v", []eventstore.EventType{org.LoginPolicyAddedEventType, iam.LoginPolicyAddedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewCreateStatement(&policyEvent, []handler.Column{
|
||||
handler.NewCol(LoginPolicyIDCol, policyEvent.Aggregate().ID),
|
||||
handler.NewCol(LoginPolicyInstanceIDCol, policyEvent.Aggregate().InstanceID),
|
||||
handler.NewCol(LoginPolicyCreationDateCol, policyEvent.CreationDate()),
|
||||
handler.NewCol(LoginPolicyChangeDateCol, policyEvent.CreationDate()),
|
||||
handler.NewCol(LoginPolicySequenceCol, policyEvent.Sequence()),
|
||||
@@ -161,8 +183,7 @@ func (p *LoginPolicyProjection) reduceLoginPolicyChanged(event eventstore.Event)
|
||||
case *org.LoginPolicyChangedEvent:
|
||||
policyEvent = e.LoginPolicyChangedEvent
|
||||
default:
|
||||
logging.LogWithFields("HANDL-NIvFo", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.LoginPolicyChangedEventType, iam.LoginPolicyChangedEventType}).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-BpaO6", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-BpaO6", "reduce.wrong.event.type %v", []eventstore.EventType{org.LoginPolicyChangedEventType, iam.LoginPolicyChangedEventType})
|
||||
}
|
||||
|
||||
cols := []handler.Column{
|
||||
@@ -220,8 +241,7 @@ func (p *LoginPolicyProjection) reduceMFAAdded(event eventstore.Event) (*handler
|
||||
case *org.LoginPolicyMultiFactorAddedEvent:
|
||||
policyEvent = e.MultiFactorAddedEvent
|
||||
default:
|
||||
logging.LogWithFields("HANDL-fYAHO", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.LoginPolicyMultiFactorAddedEventType, iam.LoginPolicyMultiFactorAddedEventType}).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-WMhAV", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-WMhAV", "reduce.wrong.event.type %v", []eventstore.EventType{org.LoginPolicyMultiFactorAddedEventType, iam.LoginPolicyMultiFactorAddedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
@@ -245,8 +265,7 @@ func (p *LoginPolicyProjection) reduceMFARemoved(event eventstore.Event) (*handl
|
||||
case *org.LoginPolicyMultiFactorRemovedEvent:
|
||||
policyEvent = e.MultiFactorRemovedEvent
|
||||
default:
|
||||
logging.LogWithFields("HANDL-vtC31", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.LoginPolicyMultiFactorRemovedEventType, iam.LoginPolicyMultiFactorRemovedEventType}).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-czU7n", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-czU7n", "reduce.wrong.event.type %v", []eventstore.EventType{org.LoginPolicyMultiFactorRemovedEventType, iam.LoginPolicyMultiFactorRemovedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
@@ -265,8 +284,7 @@ func (p *LoginPolicyProjection) reduceMFARemoved(event eventstore.Event) (*handl
|
||||
func (p *LoginPolicyProjection) reduceLoginPolicyRemoved(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*org.LoginPolicyRemovedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-gF5q6", "seq", event.Sequence(), "expectedType", org.LoginPolicyRemovedEventType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-oRSvD", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-oRSvD", "reduce.wrong.event.type %s", org.LoginPolicyRemovedEventType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
e,
|
||||
@@ -284,8 +302,7 @@ func (p *LoginPolicyProjection) reduce2FAAdded(event eventstore.Event) (*handler
|
||||
case *org.LoginPolicySecondFactorAddedEvent:
|
||||
policyEvent = e.SecondFactorAddedEvent
|
||||
default:
|
||||
logging.LogWithFields("HANDL-dwadQ", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.LoginPolicySecondFactorAddedEventType, iam.LoginPolicySecondFactorAddedEventType}).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-agB2E", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-agB2E", "reduce.wrong.event.type %v", []eventstore.EventType{org.LoginPolicySecondFactorAddedEventType, iam.LoginPolicySecondFactorAddedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
@@ -309,8 +326,7 @@ func (p *LoginPolicyProjection) reduce2FARemoved(event eventstore.Event) (*handl
|
||||
case *org.LoginPolicySecondFactorRemovedEvent:
|
||||
policyEvent = e.SecondFactorRemovedEvent
|
||||
default:
|
||||
logging.LogWithFields("HANDL-2IE8Y", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.LoginPolicySecondFactorRemovedEventType, iam.LoginPolicySecondFactorRemovedEventType}).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-KYJvA", "reduce.wrong.event.type")
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-KYJvA", "reduce.wrong.event.type %v", []eventstore.EventType{org.LoginPolicySecondFactorRemovedEventType, iam.LoginPolicySecondFactorRemovedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
|
||||
@@ -53,9 +53,10 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO zitadel.projections.login_policies (aggregate_id, creation_date, change_date, sequence, allow_register, allow_username_password, allow_external_idps, force_mfa, passwordless_type, is_default, hide_password_reset, password_check_lifetime, external_login_check_lifetime, mfa_init_skip_lifetime, second_factor_check_lifetime, multi_factor_check_lifetime) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16)",
|
||||
expectedStmt: "INSERT INTO projections.login_policies (aggregate_id, instance_id, creation_date, change_date, sequence, allow_register, allow_username_password, allow_external_idps, force_mfa, passwordless_type, is_default, hide_password_reset, password_check_lifetime, external_login_check_lifetime, mfa_init_skip_lifetime, second_factor_check_lifetime, multi_factor_check_lifetime) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
"instance-id",
|
||||
anyArg{},
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -107,7 +108,7 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.login_policies SET (change_date, sequence, allow_register, allow_username_password, allow_external_idps, force_mfa, passwordless_type, hide_password_reset, password_check_lifetime, external_login_check_lifetime, mfa_init_skip_lifetime, second_factor_check_lifetime, multi_factor_check_lifetime) = ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13) WHERE (aggregate_id = $14)",
|
||||
expectedStmt: "UPDATE projections.login_policies SET (change_date, sequence, allow_register, allow_username_password, allow_external_idps, force_mfa, passwordless_type, hide_password_reset, password_check_lifetime, external_login_check_lifetime, mfa_init_skip_lifetime, second_factor_check_lifetime, multi_factor_check_lifetime) = ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13) WHERE (aggregate_id = $14)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -149,7 +150,7 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.login_policies SET (change_date, sequence, multi_factors) = ($1, $2, array_append(multi_factors, $3)) WHERE (aggregate_id = $4)",
|
||||
expectedStmt: "UPDATE projections.login_policies SET (change_date, sequence, multi_factors) = ($1, $2, array_append(multi_factors, $3)) WHERE (aggregate_id = $4)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -181,7 +182,7 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.login_policies SET (change_date, sequence, multi_factors) = ($1, $2, array_remove(multi_factors, $3)) WHERE (aggregate_id = $4)",
|
||||
expectedStmt: "UPDATE projections.login_policies SET (change_date, sequence, multi_factors) = ($1, $2, array_remove(multi_factors, $3)) WHERE (aggregate_id = $4)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -211,7 +212,7 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.login_policies WHERE (aggregate_id = $1)",
|
||||
expectedStmt: "DELETE FROM projections.login_policies WHERE (aggregate_id = $1)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
},
|
||||
@@ -240,7 +241,7 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.login_policies SET (change_date, sequence, second_factors) = ($1, $2, array_append(second_factors, $3)) WHERE (aggregate_id = $4)",
|
||||
expectedStmt: "UPDATE projections.login_policies SET (change_date, sequence, second_factors) = ($1, $2, array_append(second_factors, $3)) WHERE (aggregate_id = $4)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -272,7 +273,7 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.login_policies SET (change_date, sequence, second_factors) = ($1, $2, array_remove(second_factors, $3)) WHERE (aggregate_id = $4)",
|
||||
expectedStmt: "UPDATE projections.login_policies SET (change_date, sequence, second_factors) = ($1, $2, array_remove(second_factors, $3)) WHERE (aggregate_id = $4)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -314,9 +315,10 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO zitadel.projections.login_policies (aggregate_id, creation_date, change_date, sequence, allow_register, allow_username_password, allow_external_idps, force_mfa, passwordless_type, is_default, hide_password_reset, password_check_lifetime, external_login_check_lifetime, mfa_init_skip_lifetime, second_factor_check_lifetime, multi_factor_check_lifetime) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16)",
|
||||
expectedStmt: "INSERT INTO projections.login_policies (aggregate_id, instance_id, creation_date, change_date, sequence, allow_register, allow_username_password, allow_external_idps, force_mfa, passwordless_type, is_default, hide_password_reset, password_check_lifetime, external_login_check_lifetime, mfa_init_skip_lifetime, second_factor_check_lifetime, multi_factor_check_lifetime) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
"instance-id",
|
||||
anyArg{},
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -363,7 +365,7 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.login_policies SET (change_date, sequence, allow_register, allow_username_password, allow_external_idps, force_mfa, passwordless_type, hide_password_reset) = ($1, $2, $3, $4, $5, $6, $7, $8) WHERE (aggregate_id = $9)",
|
||||
expectedStmt: "UPDATE projections.login_policies SET (change_date, sequence, allow_register, allow_username_password, allow_external_idps, force_mfa, passwordless_type, hide_password_reset) = ($1, $2, $3, $4, $5, $6, $7, $8) WHERE (aggregate_id = $9)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -400,7 +402,7 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.login_policies SET (change_date, sequence, multi_factors) = ($1, $2, array_append(multi_factors, $3)) WHERE (aggregate_id = $4)",
|
||||
expectedStmt: "UPDATE projections.login_policies SET (change_date, sequence, multi_factors) = ($1, $2, array_append(multi_factors, $3)) WHERE (aggregate_id = $4)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -432,7 +434,7 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.login_policies SET (change_date, sequence, multi_factors) = ($1, $2, array_remove(multi_factors, $3)) WHERE (aggregate_id = $4)",
|
||||
expectedStmt: "UPDATE projections.login_policies SET (change_date, sequence, multi_factors) = ($1, $2, array_remove(multi_factors, $3)) WHERE (aggregate_id = $4)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -464,7 +466,7 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.login_policies SET (change_date, sequence, second_factors) = ($1, $2, array_append(second_factors, $3)) WHERE (aggregate_id = $4)",
|
||||
expectedStmt: "UPDATE projections.login_policies SET (change_date, sequence, second_factors) = ($1, $2, array_append(second_factors, $3)) WHERE (aggregate_id = $4)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -496,7 +498,7 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.login_policies SET (change_date, sequence, second_factors) = ($1, $2, array_remove(second_factors, $3)) WHERE (aggregate_id = $4)",
|
||||
expectedStmt: "UPDATE projections.login_policies SET (change_date, sequence, second_factors) = ($1, $2, array_remove(second_factors, $3)) WHERE (aggregate_id = $4)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user