mirror of
https://github.com/zitadel/zitadel.git
synced 2025-06-09 09:58:40 +00:00
ignore client ids
This commit is contained in:
parent
3a338cdb44
commit
d5d365d154
@ -45,12 +45,11 @@ Console:
|
|||||||
InstanceManagementURL: "https://example.com/instances/{{.InstanceID}}"
|
InstanceManagementURL: "https://example.com/instances/{{.InstanceID}}"
|
||||||
|
|
||||||
Projections:
|
Projections:
|
||||||
RequeueEvery: 60s
|
|
||||||
Customizations:
|
Customizations:
|
||||||
NotificationsQuotas:
|
NotificationsQuotas:
|
||||||
# RequeueEvery: 1s
|
RequeueEvery: 1s
|
||||||
Telemetry:
|
Telemetry:
|
||||||
RequeueEvery: 20s
|
RequeueEvery: 30s
|
||||||
|
|
||||||
DefaultInstance:
|
DefaultInstance:
|
||||||
LoginPolicy:
|
LoginPolicy:
|
||||||
|
@ -128,16 +128,18 @@ func (h *StatementHandler) SearchQuery(ctx context.Context, instanceIDs []string
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if h.reduceScheduledPseudoEvent {
|
||||||
|
queryBuilder.
|
||||||
|
AddQuery().
|
||||||
|
SequenceGreater(seq).
|
||||||
|
InstanceID(instanceID)
|
||||||
|
continue
|
||||||
|
}
|
||||||
queryBuilder.
|
queryBuilder.
|
||||||
AddQuery().
|
AddQuery().
|
||||||
SequenceGreater(seq).
|
SequenceGreater(seq).
|
||||||
InstanceID(instanceID)
|
InstanceID(instanceID).
|
||||||
|
AggregateTypes(aggregateType)
|
||||||
if !h.reduceScheduledPseudoEvent {
|
|
||||||
queryBuilder.
|
|
||||||
AddQuery().
|
|
||||||
AggregateTypes(aggregateType)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -315,6 +315,16 @@ func NewLessThanCond(column string, value interface{}) handler.Condition {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewContainsCond(column string, value interface{}) handler.Condition {
|
||||||
|
return handler.Condition{
|
||||||
|
Name: column,
|
||||||
|
Value: value,
|
||||||
|
ParameterOpt: func(placeholder string) string {
|
||||||
|
return fmt.Sprintf(" @> ARRAY[%s]", placeholder)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// NewCopyStatement creates a new upsert statement which updates a column from an existing row
|
// NewCopyStatement creates a new upsert statement which updates a column from an existing row
|
||||||
// cols represent the columns which are objective to change.
|
// cols represent the columns which are objective to change.
|
||||||
// if the value of a col is empty the data will be copied from the selected row
|
// if the value of a col is empty the data will be copied from the selected row
|
||||||
|
@ -100,13 +100,13 @@ func NewProjectionHandler(
|
|||||||
reduceScheduledPseudoEvent: reduceScheduledPseudoEvent,
|
reduceScheduledPseudoEvent: reduceScheduledPseudoEvent,
|
||||||
}
|
}
|
||||||
|
|
||||||
go func(subscribe bool) {
|
go func() {
|
||||||
<-initialized
|
<-initialized
|
||||||
if subscribe {
|
if !h.reduceScheduledPseudoEvent {
|
||||||
go h.subscribe(ctx)
|
go h.subscribe(ctx)
|
||||||
}
|
}
|
||||||
go h.schedule(ctx)
|
go h.schedule(ctx)
|
||||||
}(!h.reduceScheduledPseudoEvent)
|
}()
|
||||||
|
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
@ -342,6 +342,7 @@ func TestProjectionHandler_Process(t *testing.T) {
|
|||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
|
|
||||||
index, err := h.Process(tt.args.ctx, tt.args.events...)
|
index, err := h.Process(tt.args.ctx, tt.args.events...)
|
||||||
|
@ -2,9 +2,6 @@ package projection
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/zitadel/zitadel/internal/repository/milestone"
|
"github.com/zitadel/zitadel/internal/repository/milestone"
|
||||||
|
|
||||||
@ -20,12 +17,12 @@ import (
|
|||||||
const (
|
const (
|
||||||
MilestonesProjectionTable = "projections.milestones"
|
MilestonesProjectionTable = "projections.milestones"
|
||||||
|
|
||||||
MilestoneColumnInstanceID = "instance_id"
|
MilestoneColumnInstanceID = "instance_id"
|
||||||
MilestoneColumnType = "type"
|
MilestoneColumnType = "type"
|
||||||
MilestoneColumnPrimaryDomain = "primary_domain"
|
MilestoneColumnPrimaryDomain = "primary_domain"
|
||||||
MilestoneColumnReachedDate = "reached_date"
|
MilestoneColumnReachedDate = "reached_date"
|
||||||
MilestoneColumnPushedDate = "last_pushed_date"
|
MilestoneColumnPushedDate = "last_pushed_date"
|
||||||
MilestoneColumnIgnoredProject = "ignore_project"
|
MilestoneColumnIgnoreClientIDs = "ignore_client_ids"
|
||||||
)
|
)
|
||||||
|
|
||||||
type milestoneProjection struct {
|
type milestoneProjection struct {
|
||||||
@ -43,7 +40,7 @@ func newMilestoneProjection(ctx context.Context, config crdb.StatementHandlerCon
|
|||||||
crdb.NewColumn(MilestoneColumnReachedDate, crdb.ColumnTypeTimestamp, crdb.Nullable()),
|
crdb.NewColumn(MilestoneColumnReachedDate, crdb.ColumnTypeTimestamp, crdb.Nullable()),
|
||||||
crdb.NewColumn(MilestoneColumnPushedDate, crdb.ColumnTypeTimestamp, crdb.Nullable()),
|
crdb.NewColumn(MilestoneColumnPushedDate, crdb.ColumnTypeTimestamp, crdb.Nullable()),
|
||||||
crdb.NewColumn(MilestoneColumnPrimaryDomain, crdb.ColumnTypeText, crdb.Nullable()),
|
crdb.NewColumn(MilestoneColumnPrimaryDomain, crdb.ColumnTypeText, crdb.Nullable()),
|
||||||
crdb.NewColumn(MilestoneColumnIgnoredProject, crdb.ColumnTypeText, crdb.Nullable()),
|
crdb.NewColumn(MilestoneColumnIgnoreClientIDs, crdb.ColumnTypeTextArray, crdb.Nullable()),
|
||||||
},
|
},
|
||||||
crdb.NewPrimaryKey(MilestoneColumnInstanceID, MilestoneColumnType),
|
crdb.NewPrimaryKey(MilestoneColumnInstanceID, MilestoneColumnType),
|
||||||
),
|
),
|
||||||
@ -67,7 +64,7 @@ func (p *milestoneProjection) reducers() []handler.AggregateReducer {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Event: instance.InstanceRemovedEventType,
|
Event: instance.InstanceRemovedEventType,
|
||||||
Reduce: p.milestoneReached(milestone.InstanceDeleted),
|
Reduce: p.reduceReachedFunc(milestone.InstanceDeleted),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -76,11 +73,19 @@ func (p *milestoneProjection) reducers() []handler.AggregateReducer {
|
|||||||
EventRedusers: []handler.EventReducer{
|
EventRedusers: []handler.EventReducer{
|
||||||
{
|
{
|
||||||
Event: project.ProjectAddedType,
|
Event: project.ProjectAddedType,
|
||||||
Reduce: p.reduceProjectAdded,
|
Reduce: p.reduceReachedIfUserEventFunc(milestone.ProjectCreated),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Event: project.ApplicationAddedType,
|
Event: project.ApplicationAddedType,
|
||||||
Reduce: p.milestoneReached(milestone.ApplicationCreated),
|
Reduce: p.reduceReachedIfUserEventFunc(milestone.ApplicationCreated),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Event: project.OIDCConfigAddedType,
|
||||||
|
Reduce: p.reduceOIDCConfigAdded,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Event: project.APIConfigAddedType,
|
||||||
|
Reduce: p.reduceAPIConfigAdded,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -88,6 +93,8 @@ func (p *milestoneProjection) reducers() []handler.AggregateReducer {
|
|||||||
Aggregate: user.AggregateType,
|
Aggregate: user.AggregateType,
|
||||||
EventRedusers: []handler.EventReducer{
|
EventRedusers: []handler.EventReducer{
|
||||||
{
|
{
|
||||||
|
// user.UserTokenAddedType is not emitted on creation of personal access tokens
|
||||||
|
// PATs have no effect on milestone.AuthenticationSucceededOnApplication or milestone.AuthenticationSucceededOnInstance
|
||||||
Event: user.UserTokenAddedType,
|
Event: user.UserTokenAddedType,
|
||||||
Reduce: p.reduceUserTokenAdded,
|
Reduce: p.reduceUserTokenAdded,
|
||||||
},
|
},
|
||||||
@ -105,12 +112,17 @@ func (p *milestoneProjection) reducers() []handler.AggregateReducer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *milestoneProjection) milestoneReached(msType milestone.Type) func(event eventstore.Event) (*handler.Statement, error) {
|
func (p *milestoneProjection) reduceReachedIfUserEventFunc(msType milestone.Type) func(event eventstore.Event) (*handler.Statement, error) {
|
||||||
return func(event eventstore.Event) (*handler.Statement, error) {
|
return func(event eventstore.Event) (*handler.Statement, error) {
|
||||||
printEvent(event)
|
if p.isSystemEvent(event) {
|
||||||
if isSystemEvent(event) {
|
|
||||||
return crdb.NewNoOpStatement(event), nil
|
return crdb.NewNoOpStatement(event), nil
|
||||||
}
|
}
|
||||||
|
return p.reduceReachedFunc(msType)(event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *milestoneProjection) reduceReachedFunc(msType milestone.Type) func(event eventstore.Event) (*handler.Statement, error) {
|
||||||
|
return func(event eventstore.Event) (*handler.Statement, error) {
|
||||||
return crdb.NewUpdateStatement(event, []handler.Column{
|
return crdb.NewUpdateStatement(event, []handler.Column{
|
||||||
handler.NewCol(MilestoneColumnReachedDate, event.CreationDate()),
|
handler.NewCol(MilestoneColumnReachedDate, event.CreationDate()),
|
||||||
},
|
},
|
||||||
@ -123,7 +135,6 @@ func (p *milestoneProjection) milestoneReached(msType milestone.Type) func(event
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *milestoneProjection) reducePushed(event eventstore.Event) (*handler.Statement, error) {
|
func (p *milestoneProjection) reducePushed(event eventstore.Event) (*handler.Statement, error) {
|
||||||
printEvent(event)
|
|
||||||
e, ok := event.(*milestone.PushedEvent)
|
e, ok := event.(*milestone.PushedEvent)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-XJGXK", "reduce.wrong.event.type %s", milestone.PushedEventType)
|
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-XJGXK", "reduce.wrong.event.type %s", milestone.PushedEventType)
|
||||||
@ -185,14 +196,30 @@ func (p *milestoneProjection) reduceInstanceDomainPrimarySet(event eventstore.Ev
|
|||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *milestoneProjection) reduceProjectAdded(event eventstore.Event) (*handler.Statement, error) {
|
func (p *milestoneProjection) reduceOIDCConfigAdded(event eventstore.Event) (*handler.Statement, error) {
|
||||||
if !isSystemEvent(event) {
|
e, ok := event.(*project.OIDCConfigAddedEvent)
|
||||||
return p.milestoneReached(milestone.ProjectCreated)(event)
|
if !ok {
|
||||||
|
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-Rw7Cv", "reduce.wrong.event.type %s", project.OIDCConfigAddedType)
|
||||||
|
}
|
||||||
|
return p.reduceAppConfigAdded(e, e.ClientID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *milestoneProjection) reduceAPIConfigAdded(event eventstore.Event) (*handler.Statement, error) {
|
||||||
|
e, ok := event.(*project.APIConfigAddedEvent)
|
||||||
|
if !ok {
|
||||||
|
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-QudD2", "reduce.wrong.event.type %s", project.APIConfigAddedType)
|
||||||
|
}
|
||||||
|
return p.reduceAppConfigAdded(e, e.ClientID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *milestoneProjection) reduceAppConfigAdded(event eventstore.Event, clientID string) (*handler.Statement, error) {
|
||||||
|
if !p.isSystemEvent(event) {
|
||||||
|
return crdb.NewNoOpStatement(event), nil
|
||||||
}
|
}
|
||||||
return crdb.NewUpdateStatement(
|
return crdb.NewUpdateStatement(
|
||||||
event,
|
event,
|
||||||
[]handler.Column{
|
[]handler.Column{
|
||||||
handler.NewCol(MilestoneColumnIgnoredProject, event.Aggregate().ID),
|
crdb.NewArrayAppendCol(MilestoneColumnIgnoreClientIDs, clientID),
|
||||||
},
|
},
|
||||||
[]handler.Condition{
|
[]handler.Condition{
|
||||||
handler.NewCond(MilestoneColumnInstanceID, event.Aggregate().InstanceID),
|
handler.NewCond(MilestoneColumnInstanceID, event.Aggregate().InstanceID),
|
||||||
@ -207,8 +234,7 @@ func (p *milestoneProjection) reduceUserTokenAdded(event eventstore.Event) (*han
|
|||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-3xhJ7", "reduce.wrong.event.type %s", user.UserTokenAddedType)
|
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-3xhJ7", "reduce.wrong.event.type %s", user.UserTokenAddedType)
|
||||||
}
|
}
|
||||||
return crdb.NewMultiStatement(
|
statements := []func(eventstore.Event) crdb.Exec{
|
||||||
e,
|
|
||||||
crdb.AddUpdateStatement(
|
crdb.AddUpdateStatement(
|
||||||
[]handler.Column{
|
[]handler.Column{
|
||||||
handler.NewCol(MilestoneColumnReachedDate, event.CreationDate()),
|
handler.NewCol(MilestoneColumnReachedDate, event.CreationDate()),
|
||||||
@ -219,6 +245,9 @@ func (p *milestoneProjection) reduceUserTokenAdded(event eventstore.Event) (*han
|
|||||||
crdb.NewIsNullCond(MilestoneColumnReachedDate),
|
crdb.NewIsNullCond(MilestoneColumnReachedDate),
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
}
|
||||||
|
// We ignore authentications without app, for example JWT profile or PAT
|
||||||
|
if e.ApplicationID != "" {
|
||||||
crdb.AddUpdateStatement(
|
crdb.AddUpdateStatement(
|
||||||
[]handler.Column{
|
[]handler.Column{
|
||||||
handler.NewCol(MilestoneColumnReachedDate, event.CreationDate()),
|
handler.NewCol(MilestoneColumnReachedDate, event.CreationDate()),
|
||||||
@ -226,22 +255,14 @@ func (p *milestoneProjection) reduceUserTokenAdded(event eventstore.Event) (*han
|
|||||||
[]handler.Condition{
|
[]handler.Condition{
|
||||||
handler.NewCond(MilestoneColumnInstanceID, event.Aggregate().InstanceID),
|
handler.NewCond(MilestoneColumnInstanceID, event.Aggregate().InstanceID),
|
||||||
handler.NewCond(MilestoneColumnType, milestone.AuthenticationSucceededOnApplication),
|
handler.NewCond(MilestoneColumnType, milestone.AuthenticationSucceededOnApplication),
|
||||||
crdb.NewNotEqualCond(MilestoneColumnIgnoredProject, strings.Split(e.ApplicationID, "@")[0]),
|
crdb.NewContainsCond(MilestoneColumnIgnoreClientIDs, e.ApplicationID),
|
||||||
crdb.NewIsNullCond(MilestoneColumnReachedDate),
|
crdb.NewIsNullCond(MilestoneColumnReachedDate),
|
||||||
},
|
},
|
||||||
),
|
)
|
||||||
), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func isSystemEvent(event eventstore.Event) bool {
|
|
||||||
return event.EditorUser() == "" || event.EditorService() == ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Remove
|
|
||||||
func printEvent(event eventstore.Event) {
|
|
||||||
bytes, err := json.MarshalIndent(event, "", " ")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
}
|
||||||
fmt.Println(event.Type(), string(bytes))
|
return crdb.NewMultiStatement(e, statements...), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *milestoneProjection) isSystemEvent(event eventstore.Event) bool {
|
||||||
|
return event.EditorUser() == "" || event.EditorService() == "" || event.EditorService() == "SYSTEM"
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user