2021-11-02 07:26:34 +00:00
|
|
|
package projection
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2022-08-31 07:52:43 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/database"
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
|
|
"github.com/zitadel/zitadel/internal/errors"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
2022-10-20 12:36:52 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/repository/instance"
|
2022-11-30 16:01:17 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/repository/org"
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/repository/project"
|
2021-11-02 07:26:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2022-11-30 16:01:17 +00:00
|
|
|
AppProjectionTable = "projections.apps4"
|
2021-11-02 07:26:34 +00:00
|
|
|
AppAPITable = AppProjectionTable + "_" + appAPITableSuffix
|
|
|
|
AppOIDCTable = AppProjectionTable + "_" + appOIDCTableSuffix
|
2022-09-12 16:18:08 +00:00
|
|
|
AppSAMLTable = AppProjectionTable + "_" + appSAMLTableSuffix
|
2022-03-23 08:02:39 +00:00
|
|
|
|
|
|
|
AppColumnID = "id"
|
|
|
|
AppColumnName = "name"
|
|
|
|
AppColumnProjectID = "project_id"
|
|
|
|
AppColumnCreationDate = "creation_date"
|
|
|
|
AppColumnChangeDate = "change_date"
|
|
|
|
AppColumnResourceOwner = "resource_owner"
|
|
|
|
AppColumnInstanceID = "instance_id"
|
|
|
|
AppColumnState = "state"
|
|
|
|
AppColumnSequence = "sequence"
|
2022-11-30 16:01:17 +00:00
|
|
|
AppColumnOwnerRemoved = "owner_removed"
|
2022-03-23 08:02:39 +00:00
|
|
|
|
|
|
|
appAPITableSuffix = "api_configs"
|
|
|
|
AppAPIConfigColumnAppID = "app_id"
|
2022-05-25 12:15:13 +00:00
|
|
|
AppAPIConfigColumnInstanceID = "instance_id"
|
2022-03-23 08:02:39 +00:00
|
|
|
AppAPIConfigColumnClientID = "client_id"
|
|
|
|
AppAPIConfigColumnClientSecret = "client_secret"
|
|
|
|
AppAPIConfigColumnAuthMethod = "auth_method"
|
|
|
|
|
|
|
|
appOIDCTableSuffix = "oidc_configs"
|
|
|
|
AppOIDCConfigColumnAppID = "app_id"
|
2022-05-25 12:15:13 +00:00
|
|
|
AppOIDCConfigColumnInstanceID = "instance_id"
|
2022-03-23 08:02:39 +00:00
|
|
|
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"
|
2022-09-12 16:18:08 +00:00
|
|
|
|
|
|
|
appSAMLTableSuffix = "saml_configs"
|
|
|
|
AppSAMLConfigColumnAppID = "app_id"
|
|
|
|
AppSAMLConfigColumnInstanceID = "instance_id"
|
|
|
|
AppSAMLConfigColumnEntityID = "entity_id"
|
|
|
|
AppSAMLConfigColumnMetadata = "metadata"
|
|
|
|
AppSAMLConfigColumnMetadataURL = "metadata_url"
|
2021-11-02 07:26:34 +00:00
|
|
|
)
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
type appProjection struct {
|
2022-03-23 08:02:39 +00:00
|
|
|
crdb.StatementHandler
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
func newAppProjection(ctx context.Context, config crdb.StatementHandlerConfig) *appProjection {
|
|
|
|
p := new(appProjection)
|
2021-11-02 07:26:34 +00:00
|
|
|
config.ProjectionName = AppProjectionTable
|
|
|
|
config.Reducers = p.reducers()
|
2022-03-23 08:02:39 +00:00
|
|
|
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),
|
2022-11-30 16:01:17 +00:00
|
|
|
crdb.NewColumn(AppColumnOwnerRemoved, crdb.ColumnTypeBool, crdb.Default(false)),
|
2022-03-23 08:02:39 +00:00
|
|
|
},
|
2022-08-31 07:52:43 +00:00
|
|
|
crdb.NewPrimaryKey(AppColumnInstanceID, AppColumnID),
|
2022-11-30 16:01:17 +00:00
|
|
|
crdb.WithIndex(crdb.NewIndex("project_id", []string{AppColumnProjectID})),
|
|
|
|
crdb.WithIndex(crdb.NewIndex("owner_removed", []string{AppColumnOwnerRemoved})),
|
2022-03-23 08:02:39 +00:00
|
|
|
),
|
|
|
|
crdb.NewSuffixedTable([]*crdb.Column{
|
2022-05-25 12:15:13 +00:00
|
|
|
crdb.NewColumn(AppAPIConfigColumnAppID, crdb.ColumnTypeText),
|
|
|
|
crdb.NewColumn(AppAPIConfigColumnInstanceID, crdb.ColumnTypeText),
|
2022-03-23 08:02:39 +00:00
|
|
|
crdb.NewColumn(AppAPIConfigColumnClientID, crdb.ColumnTypeText),
|
|
|
|
crdb.NewColumn(AppAPIConfigColumnClientSecret, crdb.ColumnTypeJSONB, crdb.Nullable()),
|
|
|
|
crdb.NewColumn(AppAPIConfigColumnAuthMethod, crdb.ColumnTypeEnum),
|
|
|
|
},
|
2022-08-31 07:52:43 +00:00
|
|
|
crdb.NewPrimaryKey(AppAPIConfigColumnInstanceID, AppAPIConfigColumnAppID),
|
2022-03-23 08:02:39 +00:00
|
|
|
appAPITableSuffix,
|
2022-11-30 16:01:17 +00:00
|
|
|
crdb.WithForeignKey(crdb.NewForeignKeyOfPublicKeys()),
|
|
|
|
crdb.WithIndex(crdb.NewIndex("client_id", []string{AppAPIConfigColumnClientID})),
|
2022-03-23 08:02:39 +00:00
|
|
|
),
|
|
|
|
crdb.NewSuffixedTable([]*crdb.Column{
|
2022-05-25 12:15:13 +00:00
|
|
|
crdb.NewColumn(AppOIDCConfigColumnAppID, crdb.ColumnTypeText),
|
|
|
|
crdb.NewColumn(AppOIDCConfigColumnInstanceID, crdb.ColumnTypeText),
|
2022-08-31 07:52:43 +00:00
|
|
|
crdb.NewColumn(AppOIDCConfigColumnVersion, crdb.ColumnTypeEnum),
|
2022-03-23 08:02:39 +00:00
|
|
|
crdb.NewColumn(AppOIDCConfigColumnClientID, crdb.ColumnTypeText),
|
|
|
|
crdb.NewColumn(AppOIDCConfigColumnClientSecret, crdb.ColumnTypeJSONB, crdb.Nullable()),
|
|
|
|
crdb.NewColumn(AppOIDCConfigColumnRedirectUris, crdb.ColumnTypeTextArray, crdb.Nullable()),
|
2022-05-16 14:35:49 +00:00
|
|
|
crdb.NewColumn(AppOIDCConfigColumnResponseTypes, crdb.ColumnTypeEnumArray, crdb.Nullable()),
|
|
|
|
crdb.NewColumn(AppOIDCConfigColumnGrantTypes, crdb.ColumnTypeEnumArray, crdb.Nullable()),
|
2022-03-23 08:02:39 +00:00
|
|
|
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),
|
2022-05-16 14:35:49 +00:00
|
|
|
crdb.NewColumn(AppOIDCConfigColumnAccessTokenRoleAssertion, crdb.ColumnTypeBool, crdb.Default(false)),
|
|
|
|
crdb.NewColumn(AppOIDCConfigColumnIDTokenRoleAssertion, crdb.ColumnTypeBool, crdb.Default(false)),
|
|
|
|
crdb.NewColumn(AppOIDCConfigColumnIDTokenUserinfoAssertion, crdb.ColumnTypeBool, crdb.Default(false)),
|
|
|
|
crdb.NewColumn(AppOIDCConfigColumnClockSkew, crdb.ColumnTypeInt64, crdb.Default(0)),
|
2022-03-23 08:02:39 +00:00
|
|
|
crdb.NewColumn(AppOIDCConfigColumnAdditionalOrigins, crdb.ColumnTypeTextArray, crdb.Nullable()),
|
|
|
|
},
|
2022-08-31 07:52:43 +00:00
|
|
|
crdb.NewPrimaryKey(AppOIDCConfigColumnInstanceID, AppOIDCConfigColumnAppID),
|
2022-03-23 08:02:39 +00:00
|
|
|
appOIDCTableSuffix,
|
2022-11-30 16:01:17 +00:00
|
|
|
crdb.WithForeignKey(crdb.NewForeignKeyOfPublicKeys()),
|
|
|
|
crdb.WithIndex(crdb.NewIndex("client_id", []string{AppOIDCConfigColumnClientID})),
|
2022-03-23 08:02:39 +00:00
|
|
|
),
|
2022-09-12 16:18:08 +00:00
|
|
|
crdb.NewSuffixedTable([]*crdb.Column{
|
|
|
|
crdb.NewColumn(AppSAMLConfigColumnAppID, crdb.ColumnTypeText),
|
|
|
|
crdb.NewColumn(AppSAMLConfigColumnInstanceID, crdb.ColumnTypeText),
|
|
|
|
crdb.NewColumn(AppSAMLConfigColumnEntityID, crdb.ColumnTypeText),
|
|
|
|
crdb.NewColumn(AppSAMLConfigColumnMetadata, crdb.ColumnTypeBytes),
|
|
|
|
crdb.NewColumn(AppSAMLConfigColumnMetadataURL, crdb.ColumnTypeText),
|
|
|
|
},
|
|
|
|
crdb.NewPrimaryKey(AppSAMLConfigColumnInstanceID, AppSAMLConfigColumnAppID),
|
|
|
|
appSAMLTableSuffix,
|
2022-11-30 16:01:17 +00:00
|
|
|
crdb.WithForeignKey(crdb.NewForeignKeyOfPublicKeys()),
|
|
|
|
crdb.WithIndex(crdb.NewIndex("entity_id", []string{AppSAMLConfigColumnEntityID})),
|
2022-09-12 16:18:08 +00:00
|
|
|
),
|
2022-03-23 08:02:39 +00:00
|
|
|
)
|
2021-11-02 07:26:34 +00:00
|
|
|
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
func (p *appProjection) reducers() []handler.AggregateReducer {
|
2021-11-02 07:26:34 +00:00
|
|
|
return []handler.AggregateReducer{
|
|
|
|
{
|
|
|
|
Aggregate: project.AggregateType,
|
|
|
|
EventRedusers: []handler.EventReducer{
|
|
|
|
{
|
|
|
|
Event: project.ApplicationAddedType,
|
|
|
|
Reduce: p.reduceAppAdded,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: project.ApplicationChangedType,
|
|
|
|
Reduce: p.reduceAppChanged,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: project.ApplicationDeactivatedType,
|
|
|
|
Reduce: p.reduceAppDeactivated,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: project.ApplicationReactivatedType,
|
|
|
|
Reduce: p.reduceAppReactivated,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: project.ApplicationRemovedType,
|
|
|
|
Reduce: p.reduceAppRemoved,
|
|
|
|
},
|
2021-12-02 14:07:45 +00:00
|
|
|
{
|
|
|
|
Event: project.ProjectRemovedType,
|
|
|
|
Reduce: p.reduceProjectRemoved,
|
|
|
|
},
|
2021-11-02 07:26:34 +00:00
|
|
|
{
|
|
|
|
Event: project.APIConfigAddedType,
|
|
|
|
Reduce: p.reduceAPIConfigAdded,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: project.APIConfigChangedType,
|
|
|
|
Reduce: p.reduceAPIConfigChanged,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: project.APIConfigSecretChangedType,
|
|
|
|
Reduce: p.reduceAPIConfigSecretChanged,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: project.OIDCConfigAddedType,
|
|
|
|
Reduce: p.reduceOIDCConfigAdded,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: project.OIDCConfigChangedType,
|
|
|
|
Reduce: p.reduceOIDCConfigChanged,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: project.OIDCConfigSecretChangedType,
|
|
|
|
Reduce: p.reduceOIDCConfigSecretChanged,
|
|
|
|
},
|
2022-09-12 16:18:08 +00:00
|
|
|
{
|
|
|
|
Event: project.SAMLConfigAddedType,
|
|
|
|
Reduce: p.reduceSAMLConfigAdded,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: project.SAMLConfigChangedType,
|
|
|
|
Reduce: p.reduceSAMLConfigChanged,
|
|
|
|
},
|
2021-11-02 07:26:34 +00:00
|
|
|
},
|
|
|
|
},
|
2022-11-30 16:01:17 +00:00
|
|
|
{
|
|
|
|
Aggregate: org.AggregateType,
|
|
|
|
EventRedusers: []handler.EventReducer{
|
|
|
|
{
|
|
|
|
Event: org.OrgRemovedEventType,
|
|
|
|
Reduce: p.reduceOwnerRemoved,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-10-20 12:36:52 +00:00
|
|
|
{
|
|
|
|
Aggregate: instance.AggregateType,
|
|
|
|
EventRedusers: []handler.EventReducer{
|
|
|
|
{
|
|
|
|
Event: instance.InstanceRemovedEventType,
|
|
|
|
Reduce: reduceInstanceRemovedHelper(AppColumnInstanceID),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-11-02 07:26:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
func (p *appProjection) reduceAppAdded(event eventstore.Event) (*handler.Statement, error) {
|
2021-11-02 07:26:34 +00:00
|
|
|
e, ok := event.(*project.ApplicationAddedEvent)
|
|
|
|
if !ok {
|
2022-03-23 08:02:39 +00:00
|
|
|
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-1xYE6", "reduce.wrong.event.type %s", project.ApplicationAddedType)
|
2021-11-02 07:26:34 +00:00
|
|
|
}
|
|
|
|
return crdb.NewCreateStatement(
|
|
|
|
e,
|
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(AppColumnID, e.AppID),
|
|
|
|
handler.NewCol(AppColumnName, e.Name),
|
|
|
|
handler.NewCol(AppColumnProjectID, e.Aggregate().ID),
|
|
|
|
handler.NewCol(AppColumnCreationDate, e.CreationDate()),
|
|
|
|
handler.NewCol(AppColumnChangeDate, e.CreationDate()),
|
|
|
|
handler.NewCol(AppColumnResourceOwner, e.Aggregate().ResourceOwner),
|
2022-03-23 08:02:39 +00:00
|
|
|
handler.NewCol(AppColumnInstanceID, e.Aggregate().InstanceID),
|
2021-11-02 07:26:34 +00:00
|
|
|
handler.NewCol(AppColumnState, domain.AppStateActive),
|
|
|
|
handler.NewCol(AppColumnSequence, e.Sequence()),
|
|
|
|
},
|
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
func (p *appProjection) reduceAppChanged(event eventstore.Event) (*handler.Statement, error) {
|
2021-11-02 07:26:34 +00:00
|
|
|
e, ok := event.(*project.ApplicationChangedEvent)
|
|
|
|
if !ok {
|
2022-03-23 08:02:39 +00:00
|
|
|
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-ZJ8JA", "reduce.wrong.event.type %s", project.ApplicationChangedType)
|
2021-11-02 07:26:34 +00:00
|
|
|
}
|
2021-12-03 13:24:29 +00:00
|
|
|
if e.Name == "" {
|
|
|
|
return crdb.NewNoOpStatement(event), nil
|
|
|
|
}
|
2021-11-02 07:26:34 +00:00
|
|
|
return crdb.NewUpdateStatement(
|
|
|
|
e,
|
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(AppColumnName, e.Name),
|
|
|
|
handler.NewCol(AppColumnChangeDate, e.CreationDate()),
|
|
|
|
handler.NewCol(AppColumnSequence, e.Sequence()),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(AppColumnID, e.AppID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(AppColumnInstanceID, e.Aggregate().InstanceID),
|
2021-11-02 07:26:34 +00:00
|
|
|
},
|
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
func (p *appProjection) reduceAppDeactivated(event eventstore.Event) (*handler.Statement, error) {
|
2021-11-02 07:26:34 +00:00
|
|
|
e, ok := event.(*project.ApplicationDeactivatedEvent)
|
|
|
|
if !ok {
|
2022-03-23 08:02:39 +00:00
|
|
|
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-MVWxZ", "reduce.wrong.event.type %s", project.ApplicationDeactivatedType)
|
2021-11-02 07:26:34 +00:00
|
|
|
}
|
|
|
|
return crdb.NewUpdateStatement(
|
|
|
|
e,
|
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(AppColumnState, domain.AppStateInactive),
|
|
|
|
handler.NewCol(AppColumnChangeDate, e.CreationDate()),
|
|
|
|
handler.NewCol(AppColumnSequence, e.Sequence()),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(AppColumnID, e.AppID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(AppColumnInstanceID, e.Aggregate().InstanceID),
|
2021-11-02 07:26:34 +00:00
|
|
|
},
|
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
func (p *appProjection) reduceAppReactivated(event eventstore.Event) (*handler.Statement, error) {
|
2021-11-02 07:26:34 +00:00
|
|
|
e, ok := event.(*project.ApplicationReactivatedEvent)
|
|
|
|
if !ok {
|
2022-03-23 08:02:39 +00:00
|
|
|
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-D0HZO", "reduce.wrong.event.type %s", project.ApplicationReactivatedType)
|
2021-11-02 07:26:34 +00:00
|
|
|
}
|
|
|
|
return crdb.NewUpdateStatement(
|
|
|
|
e,
|
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(AppColumnState, domain.AppStateActive),
|
|
|
|
handler.NewCol(AppColumnChangeDate, e.CreationDate()),
|
|
|
|
handler.NewCol(AppColumnSequence, e.Sequence()),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(AppColumnID, e.AppID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(AppColumnInstanceID, e.Aggregate().InstanceID),
|
2021-11-02 07:26:34 +00:00
|
|
|
},
|
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
func (p *appProjection) reduceAppRemoved(event eventstore.Event) (*handler.Statement, error) {
|
2021-11-02 07:26:34 +00:00
|
|
|
e, ok := event.(*project.ApplicationRemovedEvent)
|
|
|
|
if !ok {
|
2022-03-23 08:02:39 +00:00
|
|
|
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-Y99aq", "reduce.wrong.event.type %s", project.ApplicationRemovedType)
|
2021-11-02 07:26:34 +00:00
|
|
|
}
|
|
|
|
return crdb.NewDeleteStatement(
|
|
|
|
e,
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(AppColumnID, e.AppID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(AppColumnInstanceID, e.Aggregate().InstanceID),
|
2021-11-02 07:26:34 +00:00
|
|
|
},
|
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
func (p *appProjection) reduceProjectRemoved(event eventstore.Event) (*handler.Statement, error) {
|
2021-12-02 14:07:45 +00:00
|
|
|
e, ok := event.(*project.ProjectRemovedEvent)
|
|
|
|
if !ok {
|
2022-03-23 08:02:39 +00:00
|
|
|
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-DlUlO", "reduce.wrong.event.type %s", project.ProjectRemovedType)
|
2021-12-02 14:07:45 +00:00
|
|
|
}
|
|
|
|
return crdb.NewDeleteStatement(
|
|
|
|
e,
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(AppColumnProjectID, e.Aggregate().ID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(AppColumnInstanceID, e.Aggregate().InstanceID),
|
2021-12-02 14:07:45 +00:00
|
|
|
},
|
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
func (p *appProjection) reduceAPIConfigAdded(event eventstore.Event) (*handler.Statement, error) {
|
2021-11-02 07:26:34 +00:00
|
|
|
e, ok := event.(*project.APIConfigAddedEvent)
|
|
|
|
if !ok {
|
2022-03-23 08:02:39 +00:00
|
|
|
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-Y99aq", "reduce.wrong.event.type %s", project.APIConfigAddedType)
|
2021-11-02 07:26:34 +00:00
|
|
|
}
|
|
|
|
return crdb.NewMultiStatement(
|
|
|
|
e,
|
|
|
|
crdb.AddCreateStatement(
|
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(AppAPIConfigColumnAppID, e.AppID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCol(AppAPIConfigColumnInstanceID, e.Aggregate().InstanceID),
|
2021-11-02 07:26:34 +00:00
|
|
|
handler.NewCol(AppAPIConfigColumnClientID, e.ClientID),
|
|
|
|
handler.NewCol(AppAPIConfigColumnClientSecret, e.ClientSecret),
|
|
|
|
handler.NewCol(AppAPIConfigColumnAuthMethod, e.AuthMethodType),
|
|
|
|
},
|
|
|
|
crdb.WithTableSuffix(appAPITableSuffix),
|
|
|
|
),
|
|
|
|
crdb.AddUpdateStatement(
|
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(AppColumnChangeDate, e.CreationDate()),
|
|
|
|
handler.NewCol(AppColumnSequence, e.Sequence()),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(AppColumnID, e.AppID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(AppColumnInstanceID, e.Aggregate().InstanceID),
|
2021-11-02 07:26:34 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
func (p *appProjection) reduceAPIConfigChanged(event eventstore.Event) (*handler.Statement, error) {
|
2021-11-02 07:26:34 +00:00
|
|
|
e, ok := event.(*project.APIConfigChangedEvent)
|
|
|
|
if !ok {
|
2022-03-23 08:02:39 +00:00
|
|
|
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-vnZKi", "reduce.wrong.event.type %s", project.APIConfigChangedType)
|
2021-11-02 07:26:34 +00:00
|
|
|
}
|
|
|
|
cols := make([]handler.Column, 0, 2)
|
|
|
|
if e.ClientSecret != nil {
|
|
|
|
cols = append(cols, handler.NewCol(AppAPIConfigColumnClientSecret, e.ClientSecret))
|
|
|
|
}
|
|
|
|
if e.AuthMethodType != nil {
|
|
|
|
cols = append(cols, handler.NewCol(AppAPIConfigColumnAuthMethod, *e.AuthMethodType))
|
|
|
|
}
|
|
|
|
if len(cols) == 0 {
|
|
|
|
return crdb.NewNoOpStatement(e), nil
|
|
|
|
}
|
|
|
|
return crdb.NewMultiStatement(
|
|
|
|
e,
|
|
|
|
crdb.AddUpdateStatement(
|
|
|
|
cols,
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(AppAPIConfigColumnAppID, e.AppID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(AppAPIConfigColumnInstanceID, e.Aggregate().InstanceID),
|
2021-11-02 07:26:34 +00:00
|
|
|
},
|
|
|
|
crdb.WithTableSuffix(appAPITableSuffix),
|
|
|
|
),
|
|
|
|
crdb.AddUpdateStatement(
|
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(AppColumnChangeDate, e.CreationDate()),
|
|
|
|
handler.NewCol(AppColumnSequence, e.Sequence()),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(AppColumnID, e.AppID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(AppColumnInstanceID, e.Aggregate().InstanceID),
|
2021-11-02 07:26:34 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
func (p *appProjection) reduceAPIConfigSecretChanged(event eventstore.Event) (*handler.Statement, error) {
|
2021-11-02 07:26:34 +00:00
|
|
|
e, ok := event.(*project.APIConfigSecretChangedEvent)
|
|
|
|
if !ok {
|
2022-03-23 08:02:39 +00:00
|
|
|
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-ttb0I", "reduce.wrong.event.type %s", project.APIConfigSecretChangedType)
|
2021-11-02 07:26:34 +00:00
|
|
|
}
|
|
|
|
return crdb.NewMultiStatement(
|
|
|
|
e,
|
|
|
|
crdb.AddUpdateStatement(
|
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(AppAPIConfigColumnClientSecret, e.ClientSecret),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(AppAPIConfigColumnAppID, e.AppID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(AppAPIConfigColumnInstanceID, e.Aggregate().InstanceID),
|
2021-11-02 07:26:34 +00:00
|
|
|
},
|
|
|
|
crdb.WithTableSuffix(appAPITableSuffix),
|
|
|
|
),
|
|
|
|
crdb.AddUpdateStatement(
|
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(AppColumnChangeDate, e.CreationDate()),
|
|
|
|
handler.NewCol(AppColumnSequence, e.Sequence()),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(AppColumnID, e.AppID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(AppColumnInstanceID, e.Aggregate().InstanceID),
|
2021-11-02 07:26:34 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
func (p *appProjection) reduceOIDCConfigAdded(event eventstore.Event) (*handler.Statement, error) {
|
2021-11-02 07:26:34 +00:00
|
|
|
e, ok := event.(*project.OIDCConfigAddedEvent)
|
|
|
|
if !ok {
|
2022-03-23 08:02:39 +00:00
|
|
|
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-GNHU1", "reduce.wrong.event.type %s", project.OIDCConfigAddedType)
|
2021-11-02 07:26:34 +00:00
|
|
|
}
|
|
|
|
return crdb.NewMultiStatement(
|
|
|
|
e,
|
|
|
|
crdb.AddCreateStatement(
|
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(AppOIDCConfigColumnAppID, e.AppID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCol(AppOIDCConfigColumnInstanceID, e.Aggregate().InstanceID),
|
2021-11-02 07:26:34 +00:00
|
|
|
handler.NewCol(AppOIDCConfigColumnVersion, e.Version),
|
|
|
|
handler.NewCol(AppOIDCConfigColumnClientID, e.ClientID),
|
|
|
|
handler.NewCol(AppOIDCConfigColumnClientSecret, e.ClientSecret),
|
2022-08-31 07:52:43 +00:00
|
|
|
handler.NewCol(AppOIDCConfigColumnRedirectUris, database.StringArray(e.RedirectUris)),
|
|
|
|
handler.NewCol(AppOIDCConfigColumnResponseTypes, database.EnumArray[domain.OIDCResponseType](e.ResponseTypes)),
|
|
|
|
handler.NewCol(AppOIDCConfigColumnGrantTypes, database.EnumArray[domain.OIDCGrantType](e.GrantTypes)),
|
2021-11-02 07:26:34 +00:00
|
|
|
handler.NewCol(AppOIDCConfigColumnApplicationType, e.ApplicationType),
|
|
|
|
handler.NewCol(AppOIDCConfigColumnAuthMethodType, e.AuthMethodType),
|
2022-08-31 07:52:43 +00:00
|
|
|
handler.NewCol(AppOIDCConfigColumnPostLogoutRedirectUris, database.StringArray(e.PostLogoutRedirectUris)),
|
2021-11-02 07:26:34 +00:00
|
|
|
handler.NewCol(AppOIDCConfigColumnDevMode, e.DevMode),
|
|
|
|
handler.NewCol(AppOIDCConfigColumnAccessTokenType, e.AccessTokenType),
|
|
|
|
handler.NewCol(AppOIDCConfigColumnAccessTokenRoleAssertion, e.AccessTokenRoleAssertion),
|
|
|
|
handler.NewCol(AppOIDCConfigColumnIDTokenRoleAssertion, e.IDTokenRoleAssertion),
|
|
|
|
handler.NewCol(AppOIDCConfigColumnIDTokenUserinfoAssertion, e.IDTokenUserinfoAssertion),
|
|
|
|
handler.NewCol(AppOIDCConfigColumnClockSkew, e.ClockSkew),
|
2022-08-31 07:52:43 +00:00
|
|
|
handler.NewCol(AppOIDCConfigColumnAdditionalOrigins, database.StringArray(e.AdditionalOrigins)),
|
2021-11-02 07:26:34 +00:00
|
|
|
},
|
|
|
|
crdb.WithTableSuffix(appOIDCTableSuffix),
|
|
|
|
),
|
|
|
|
crdb.AddUpdateStatement(
|
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(AppColumnChangeDate, e.CreationDate()),
|
|
|
|
handler.NewCol(AppColumnSequence, e.Sequence()),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(AppColumnID, e.AppID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(AppColumnInstanceID, e.Aggregate().InstanceID),
|
2021-11-02 07:26:34 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
func (p *appProjection) reduceOIDCConfigChanged(event eventstore.Event) (*handler.Statement, error) {
|
2021-11-02 07:26:34 +00:00
|
|
|
e, ok := event.(*project.OIDCConfigChangedEvent)
|
|
|
|
if !ok {
|
2022-03-23 08:02:39 +00:00
|
|
|
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-GNHU1", "reduce.wrong.event.type %s", project.OIDCConfigChangedType)
|
2021-11-02 07:26:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cols := make([]handler.Column, 0, 15)
|
|
|
|
if e.Version != nil {
|
|
|
|
cols = append(cols, handler.NewCol(AppOIDCConfigColumnVersion, *e.Version))
|
|
|
|
}
|
|
|
|
if e.RedirectUris != nil {
|
2022-08-31 07:52:43 +00:00
|
|
|
cols = append(cols, handler.NewCol(AppOIDCConfigColumnRedirectUris, database.StringArray(*e.RedirectUris)))
|
2021-11-02 07:26:34 +00:00
|
|
|
}
|
|
|
|
if e.ResponseTypes != nil {
|
2022-08-31 07:52:43 +00:00
|
|
|
cols = append(cols, handler.NewCol(AppOIDCConfigColumnResponseTypes, database.EnumArray[domain.OIDCResponseType](*e.ResponseTypes)))
|
2021-11-02 07:26:34 +00:00
|
|
|
}
|
|
|
|
if e.GrantTypes != nil {
|
2022-08-31 07:52:43 +00:00
|
|
|
cols = append(cols, handler.NewCol(AppOIDCConfigColumnGrantTypes, database.EnumArray[domain.OIDCGrantType](*e.GrantTypes)))
|
2021-11-02 07:26:34 +00:00
|
|
|
}
|
|
|
|
if e.ApplicationType != nil {
|
|
|
|
cols = append(cols, handler.NewCol(AppOIDCConfigColumnApplicationType, *e.ApplicationType))
|
|
|
|
}
|
|
|
|
if e.AuthMethodType != nil {
|
|
|
|
cols = append(cols, handler.NewCol(AppOIDCConfigColumnAuthMethodType, *e.AuthMethodType))
|
|
|
|
}
|
|
|
|
if e.PostLogoutRedirectUris != nil {
|
2022-08-31 07:52:43 +00:00
|
|
|
cols = append(cols, handler.NewCol(AppOIDCConfigColumnPostLogoutRedirectUris, database.StringArray(*e.PostLogoutRedirectUris)))
|
2021-11-02 07:26:34 +00:00
|
|
|
}
|
|
|
|
if e.DevMode != nil {
|
|
|
|
cols = append(cols, handler.NewCol(AppOIDCConfigColumnDevMode, *e.DevMode))
|
|
|
|
}
|
|
|
|
if e.AccessTokenType != nil {
|
|
|
|
cols = append(cols, handler.NewCol(AppOIDCConfigColumnAccessTokenType, *e.AccessTokenType))
|
|
|
|
}
|
|
|
|
if e.AccessTokenRoleAssertion != nil {
|
|
|
|
cols = append(cols, handler.NewCol(AppOIDCConfigColumnAccessTokenRoleAssertion, *e.AccessTokenRoleAssertion))
|
|
|
|
}
|
|
|
|
if e.IDTokenRoleAssertion != nil {
|
|
|
|
cols = append(cols, handler.NewCol(AppOIDCConfigColumnIDTokenRoleAssertion, *e.IDTokenRoleAssertion))
|
|
|
|
}
|
|
|
|
if e.IDTokenUserinfoAssertion != nil {
|
|
|
|
cols = append(cols, handler.NewCol(AppOIDCConfigColumnIDTokenUserinfoAssertion, *e.IDTokenUserinfoAssertion))
|
|
|
|
}
|
|
|
|
if e.ClockSkew != nil {
|
|
|
|
cols = append(cols, handler.NewCol(AppOIDCConfigColumnClockSkew, *e.ClockSkew))
|
|
|
|
}
|
|
|
|
if e.AdditionalOrigins != nil {
|
2022-08-31 07:52:43 +00:00
|
|
|
cols = append(cols, handler.NewCol(AppOIDCConfigColumnAdditionalOrigins, database.StringArray(*e.AdditionalOrigins)))
|
2021-11-02 07:26:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(cols) == 0 {
|
|
|
|
return crdb.NewNoOpStatement(e), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return crdb.NewMultiStatement(
|
|
|
|
e,
|
|
|
|
crdb.AddUpdateStatement(
|
|
|
|
cols,
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(AppOIDCConfigColumnAppID, e.AppID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(AppOIDCConfigColumnInstanceID, e.Aggregate().InstanceID),
|
2021-11-02 07:26:34 +00:00
|
|
|
},
|
|
|
|
crdb.WithTableSuffix(appOIDCTableSuffix),
|
|
|
|
),
|
|
|
|
crdb.AddUpdateStatement(
|
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(AppColumnChangeDate, e.CreationDate()),
|
|
|
|
handler.NewCol(AppColumnSequence, e.Sequence()),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(AppColumnID, e.AppID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(AppColumnInstanceID, e.Aggregate().InstanceID),
|
2021-11-02 07:26:34 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
func (p *appProjection) reduceOIDCConfigSecretChanged(event eventstore.Event) (*handler.Statement, error) {
|
2021-11-02 07:26:34 +00:00
|
|
|
e, ok := event.(*project.OIDCConfigSecretChangedEvent)
|
|
|
|
if !ok {
|
2022-03-23 08:02:39 +00:00
|
|
|
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-GNHU1", "reduce.wrong.event.type %s", project.OIDCConfigSecretChangedType)
|
2021-11-02 07:26:34 +00:00
|
|
|
}
|
|
|
|
return crdb.NewMultiStatement(
|
|
|
|
e,
|
|
|
|
crdb.AddUpdateStatement(
|
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(AppOIDCConfigColumnClientSecret, e.ClientSecret),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(AppOIDCConfigColumnAppID, e.AppID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(AppOIDCConfigColumnInstanceID, e.Aggregate().InstanceID),
|
2021-11-02 07:26:34 +00:00
|
|
|
},
|
|
|
|
crdb.WithTableSuffix(appOIDCTableSuffix),
|
|
|
|
),
|
|
|
|
crdb.AddUpdateStatement(
|
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(AppColumnChangeDate, e.CreationDate()),
|
|
|
|
handler.NewCol(AppColumnSequence, e.Sequence()),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(AppColumnID, e.AppID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(AppColumnInstanceID, e.Aggregate().InstanceID),
|
2021-11-02 07:26:34 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
), nil
|
|
|
|
}
|
2022-09-12 16:18:08 +00:00
|
|
|
|
2022-11-30 16:01:17 +00:00
|
|
|
func (p *appProjection) reduceOwnerRemoved(event eventstore.Event) (*handler.Statement, error) {
|
|
|
|
e, ok := event.(*org.OrgRemovedEvent)
|
|
|
|
if !ok {
|
|
|
|
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-Hyd1f", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
|
|
|
}
|
|
|
|
|
|
|
|
return crdb.NewUpdateStatement(
|
|
|
|
e,
|
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(AppColumnChangeDate, e.CreationDate()),
|
|
|
|
handler.NewCol(AppColumnSequence, e.Sequence()),
|
|
|
|
handler.NewCol(AppColumnOwnerRemoved, true),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(AppColumnInstanceID, e.Aggregate().InstanceID),
|
|
|
|
handler.NewCond(AppColumnResourceOwner, e.Aggregate().ID),
|
|
|
|
},
|
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2022-09-12 16:18:08 +00:00
|
|
|
func (p *appProjection) reduceSAMLConfigAdded(event eventstore.Event) (*handler.Statement, error) {
|
|
|
|
e, ok := event.(*project.SAMLConfigAddedEvent)
|
|
|
|
if !ok {
|
|
|
|
return nil, errors.ThrowInvalidArgument(nil, "HANDL-GMHU1", "reduce.wrong.event.type")
|
|
|
|
}
|
|
|
|
return crdb.NewMultiStatement(
|
|
|
|
e,
|
|
|
|
crdb.AddCreateStatement(
|
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(AppSAMLConfigColumnAppID, e.AppID),
|
|
|
|
handler.NewCol(AppSAMLConfigColumnInstanceID, e.Aggregate().InstanceID),
|
|
|
|
handler.NewCol(AppSAMLConfigColumnEntityID, e.EntityID),
|
|
|
|
handler.NewCol(AppSAMLConfigColumnMetadata, e.Metadata),
|
|
|
|
handler.NewCol(AppSAMLConfigColumnMetadataURL, e.MetadataURL),
|
|
|
|
},
|
|
|
|
crdb.WithTableSuffix(appSAMLTableSuffix),
|
|
|
|
),
|
|
|
|
crdb.AddUpdateStatement(
|
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(AppColumnChangeDate, e.CreationDate()),
|
|
|
|
handler.NewCol(AppColumnSequence, e.Sequence()),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(AppColumnID, e.AppID),
|
|
|
|
handler.NewCond(AppColumnInstanceID, e.Aggregate().InstanceID),
|
|
|
|
},
|
|
|
|
),
|
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *appProjection) reduceSAMLConfigChanged(event eventstore.Event) (*handler.Statement, error) {
|
|
|
|
e, ok := event.(*project.SAMLConfigChangedEvent)
|
|
|
|
if !ok {
|
|
|
|
return nil, errors.ThrowInvalidArgument(nil, "HANDL-GMHU2", "reduce.wrong.event.type")
|
|
|
|
}
|
|
|
|
|
|
|
|
cols := make([]handler.Column, 0, 3)
|
|
|
|
if e.Metadata != nil {
|
|
|
|
cols = append(cols, handler.NewCol(AppSAMLConfigColumnMetadata, e.Metadata))
|
|
|
|
}
|
|
|
|
if e.MetadataURL != nil {
|
|
|
|
cols = append(cols, handler.NewCol(AppSAMLConfigColumnMetadataURL, *e.MetadataURL))
|
|
|
|
}
|
|
|
|
if e.EntityID != "" {
|
|
|
|
cols = append(cols, handler.NewCol(AppSAMLConfigColumnEntityID, e.EntityID))
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(cols) == 0 {
|
|
|
|
return crdb.NewNoOpStatement(e), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return crdb.NewMultiStatement(
|
|
|
|
e,
|
|
|
|
crdb.AddUpdateStatement(
|
|
|
|
cols,
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(AppSAMLConfigColumnAppID, e.AppID),
|
|
|
|
handler.NewCond(AppSAMLConfigColumnInstanceID, e.Aggregate().InstanceID),
|
|
|
|
},
|
|
|
|
crdb.WithTableSuffix(appSAMLTableSuffix),
|
|
|
|
),
|
|
|
|
crdb.AddUpdateStatement(
|
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(AppColumnChangeDate, e.CreationDate()),
|
|
|
|
handler.NewCol(AppColumnSequence, e.Sequence()),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(AppColumnID, e.AppID),
|
|
|
|
handler.NewCond(AppColumnInstanceID, e.Aggregate().InstanceID),
|
|
|
|
},
|
|
|
|
),
|
|
|
|
), nil
|
|
|
|
}
|