Files
zitadel/internal/query/projection/idp_template_relational.go

2867 lines
103 KiB
Go
Raw Normal View History

2025-07-25 17:06:18 +01:00
package projection
import (
"context"
"encoding/json"
"fmt"
2025-07-25 17:06:18 +01:00
"github.com/zitadel/zitadel/backend/v3/domain"
2025-07-25 17:06:18 +01:00
"github.com/zitadel/zitadel/backend/v3/storage/database/dialect/postgres"
"github.com/zitadel/zitadel/backend/v3/storage/database/repository"
db_domain "github.com/zitadel/zitadel/backend/v3/domain"
"github.com/zitadel/zitadel/internal/eventstore"
2025-07-25 17:06:18 +01:00
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
"github.com/zitadel/zitadel/internal/repository/idp"
2025-07-25 17:06:18 +01:00
"github.com/zitadel/zitadel/internal/repository/instance"
"github.com/zitadel/zitadel/internal/repository/org"
"github.com/zitadel/zitadel/internal/zerrors"
)
const (
IDPRelationalOrgId = "org_id"
IDPRelationalAllowCreationCol = "allow_creation"
IDPRelationalAllowLinkingCol = "allow_linking"
IDPRelationalAllowAutoCreationCol = "allow_auto_creation"
IDPRelationalAllowAutoUpdateCol = "allow_auto_update"
IDPRelationalAllowAutoLinkingCol = "allow_auto_linking"
2025-07-25 17:06:18 +01:00
)
type idpTemplateRelationalProjection struct {
idpRepo db_domain.IDProviderRepository
2025-07-25 17:06:18 +01:00
}
func newIDPTemplateRelationalProjection(ctx context.Context, config handler.Config) *handler.Handler {
client := postgres.PGxPool(config.Client.Pool)
idpRepo := repository.IDProviderRepository(client)
return handler.NewHandler(ctx, &config, &idpTemplateRelationalProjection{
idpRepo: idpRepo,
})
}
func (*idpTemplateRelationalProjection) Name() string {
return IDPRelationalTable
}
func (p *idpTemplateRelationalProjection) Reducers() []handler.AggregateReducer {
return []handler.AggregateReducer{
{
Aggregate: instance.AggregateType,
EventReducers: []handler.EventReducer{
// TODO
// {
// Event: instance.IDPConfigAddedEventType,
// Reduce: p.reduceOldConfigAdded,
// },
// TODO
// {
// Event: instance.IDPConfigChangedEventType,
// Reduce: p.reduceOldConfigChanged,
// },
// TODO
// {
// Event: instance.IDPOIDCConfigAddedEventType,
// Reduce: p.reduceOldOIDCConfigAdded,
// },
// TODO
// {
// Event: instance.IDPOIDCConfigChangedEventType,
// Reduce: p.reduceOldOIDCConfigChanged,
// },
// TODO
// {
// Event: instance.IDPJWTConfigAddedEventType,
// Reduce: p.reduceOldJWTConfigAdded,
// },
// TODO
// {
// Event: instance.IDPJWTConfigChangedEventType,
// Reduce: p.reduceOldJWTConfigChanged,
// },
2025-07-25 17:06:18 +01:00
{
Event: instance.OAuthIDPAddedEventType,
Reduce: p.reduceOAuthIDPRelationalAdded,
},
{
Event: instance.OAuthIDPChangedEventType,
Reduce: p.reduceOAuthIDPRelationalChanged,
},
{
Event: instance.OIDCIDPAddedEventType,
Reduce: p.reduceOIDCIDPRelationalAdded,
},
{
Event: instance.OIDCIDPChangedEventType,
Reduce: p.reduceOIDCIDPRelationalChanged,
2025-07-25 17:06:18 +01:00
},
{
Event: instance.OIDCIDPMigratedAzureADEventType,
Reduce: p.reduceOIDCIDPRelationalMigratedAzureAD,
},
{
Event: instance.OIDCIDPMigratedGoogleEventType,
Reduce: p.reduceOIDCIDPRelationalMigratedGoogle,
},
{
Event: instance.JWTIDPAddedEventType,
Reduce: p.reduceJWTIDPRelationalAdded,
},
{
Event: instance.JWTIDPChangedEventType,
Reduce: p.reduceJWTIDPRelationalChanged,
},
{
Event: instance.AzureADIDPAddedEventType,
Reduce: p.reduceAzureADIDPRelationalAdded,
},
{
Event: instance.AzureADIDPChangedEventType,
Reduce: p.reduceAzureADIDPRelationalChanged,
},
{
Event: instance.GitHubIDPAddedEventType,
Reduce: p.reduceGitHubIDPRelationalAdded,
},
{
Event: instance.GitHubIDPChangedEventType,
Reduce: p.reduceGitHubIDPRelationalChanged,
},
{
Event: instance.GitHubEnterpriseIDPAddedEventType,
Reduce: p.reduceGitHubEnterpriseIDPRelationalAdded,
},
{
Event: instance.GitHubEnterpriseIDPChangedEventType,
Reduce: p.reduceGitHubEnterpriseIDPRelationalChanged,
},
{
Event: instance.GitLabIDPAddedEventType,
Reduce: p.reduceGitLabIDPRelationalAdded,
},
{
Event: instance.GitLabIDPChangedEventType,
Reduce: p.reduceGitLabIDPRelationalChanged,
},
{
Event: instance.GitLabSelfHostedIDPAddedEventType,
Reduce: p.reduceGitLabSelfHostedIDPRelationalAdded,
},
{
Event: instance.GitLabSelfHostedIDPChangedEventType,
Reduce: p.reduceGitLabSelfHostedIDPRelationalChanged,
},
{
Event: instance.GoogleIDPAddedEventType,
Reduce: p.reduceGoogleIDPRelationalAdded,
},
{
Event: instance.GoogleIDPChangedEventType,
Reduce: p.reduceGoogleIDPRelationalChanged,
},
{
Event: instance.LDAPIDPAddedEventType,
Reduce: p.reduceLDAPIDPAdded,
},
{
Event: instance.LDAPIDPChangedEventType,
Reduce: p.reduceLDAPIDPChanged,
},
{
Event: instance.AppleIDPAddedEventType,
Reduce: p.reduceAppleIDPAdded,
},
{
Event: instance.AppleIDPChangedEventType,
Reduce: p.reduceAppleIDPChanged,
},
{
Event: instance.SAMLIDPAddedEventType,
Reduce: p.reduceSAMLIDPAdded,
},
{
Event: instance.SAMLIDPChangedEventType,
Reduce: p.reduceSAMLIDPChanged,
},
2025-07-25 17:06:18 +01:00
// {
// Event: instance.IDPConfigRemovedEventType,
// Reduce: p.reduceIDPConfigRemoved,
// },
{
Event: instance.IDPRemovedEventType,
Reduce: p.reduceIDPRemoved,
},
2025-07-25 17:06:18 +01:00
// {
// Event: instance.InstanceRemovedEventType,
// Reduce: reduceInstanceRemovedHelper(IDPTemplateInstanceIDCol),
// },
},
},
{
Aggregate: org.AggregateType,
EventReducers: []handler.EventReducer{
{
Event: org.OAuthIDPAddedEventType,
Reduce: p.reduceOAuthIDPRelationalAdded,
},
{
Event: org.OAuthIDPChangedEventType,
Reduce: p.reduceOAuthIDPRelationalChanged,
},
{
Event: org.OIDCIDPAddedEventType,
Reduce: p.reduceOIDCIDPRelationalAdded,
},
{
Event: org.OIDCIDPChangedEventType,
Reduce: p.reduceOIDCIDPRelationalChanged,
},
{
Event: org.OIDCIDPMigratedAzureADEventType,
Reduce: p.reduceOIDCIDPRelationalMigratedAzureAD,
},
{
Event: org.OIDCIDPMigratedGoogleEventType,
Reduce: p.reduceOIDCIDPRelationalMigratedGoogle,
},
{
Event: org.JWTIDPAddedEventType,
Reduce: p.reduceJWTIDPRelationalAdded,
},
{
Event: org.JWTIDPChangedEventType,
Reduce: p.reduceJWTIDPRelationalChanged,
},
// {
// Event: org.IDPConfigAddedEventType,
// Reduce: p.reduceOldConfigAdded,
2025-07-25 17:06:18 +01:00
// },
// {
// Event: org.IDPConfigChangedEventType,
// Reduce: p.reduceOldConfigChanged,
// },
2025-07-25 17:06:18 +01:00
// {
// Event: org.IDPOIDCConfigAddedEventType,
// Reduce: p.reduceOldOIDCConfigAdded,
// },
// {
// Event: org.IDPOIDCConfigChangedEventType,
// Reduce: p.reduceOldOIDCConfigChanged,
// },
// {
// Event: org.IDPJWTConfigAddedEventType,
// Reduce: p.reduceOldJWTConfigAdded,
// },
// {
// Event: org.IDPJWTConfigChangedEventType,
// Reduce: p.reduceOldJWTConfigChanged,
// },
{
Event: org.AzureADIDPAddedEventType,
Reduce: p.reduceAzureADIDPRelationalAdded,
},
{
Event: org.AzureADIDPChangedEventType,
Reduce: p.reduceAzureADIDPRelationalChanged,
},
{
Event: org.GitHubIDPAddedEventType,
Reduce: p.reduceGitHubIDPRelationalAdded,
},
{
Event: org.GitHubIDPChangedEventType,
Reduce: p.reduceGitHubIDPRelationalChanged,
},
{
Event: org.GitHubEnterpriseIDPAddedEventType,
Reduce: p.reduceGitHubEnterpriseIDPRelationalAdded,
},
{
Event: org.GitHubEnterpriseIDPChangedEventType,
Reduce: p.reduceGitHubEnterpriseIDPRelationalChanged,
},
{
Event: org.GitLabIDPAddedEventType,
Reduce: p.reduceGitLabIDPRelationalAdded,
},
{
Event: org.GitLabIDPChangedEventType,
Reduce: p.reduceGitLabIDPRelationalChanged,
},
{
Event: org.GitLabSelfHostedIDPAddedEventType,
Reduce: p.reduceGitLabSelfHostedIDPRelationalAdded,
},
{
Event: org.GitLabSelfHostedIDPChangedEventType,
Reduce: p.reduceGitLabSelfHostedIDPRelationalChanged,
},
{
Event: org.GoogleIDPAddedEventType,
Reduce: p.reduceGoogleIDPRelationalAdded,
},
{
Event: org.GoogleIDPChangedEventType,
Reduce: p.reduceGoogleIDPRelationalChanged,
},
{
Event: org.LDAPIDPAddedEventType,
Reduce: p.reduceLDAPIDPAdded,
},
{
Event: org.LDAPIDPChangedEventType,
Reduce: p.reduceLDAPIDPChanged,
},
{
Event: org.AppleIDPAddedEventType,
Reduce: p.reduceAppleIDPAdded,
},
{
Event: org.AppleIDPChangedEventType,
Reduce: p.reduceAppleIDPChanged,
},
{
Event: org.SAMLIDPAddedEventType,
Reduce: p.reduceSAMLIDPAdded,
},
{
Event: org.SAMLIDPChangedEventType,
Reduce: p.reduceSAMLIDPChanged,
},
2025-07-25 17:06:18 +01:00
// {
// Event: org.IDPConfigRemovedEventType,
// Reduce: p.reduceIDPConfigRemoved,
// },
{
Event: org.IDPRemovedEventType,
Reduce: p.reduceIDPRemoved,
},
2025-07-25 17:06:18 +01:00
// {
// Event: org.OrgRemovedEventType,
// Reduce: p.reduceOwnerRemoved,
// },
},
},
}
}
func (p *idpTemplateRelationalProjection) reduceOAuthIDPRelationalAdded(event eventstore.Event) (*handler.Statement, error) {
var idpEvent idp.OAuthIDPAddedEvent
switch e := event.(type) {
case *org.OAuthIDPAddedEvent:
idpEvent = e.OAuthIDPAddedEvent
case *instance.OAuthIDPAddedEvent:
idpEvent = e.OAuthIDPAddedEvent
default:
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-Yap9ihb", "reduce.wrong.event.type %v", []eventstore.EventType{org.OAuthIDPAddedEventType, instance.OAuthIDPAddedEventType})
}
oauth := db_domain.OAuth{
ClientID: idpEvent.ClientID,
ClientSecret: idpEvent.ClientSecret,
AuthorizationEndpoint: idpEvent.AuthorizationEndpoint,
TokenEndpoint: idpEvent.TokenEndpoint,
UserEndpoint: idpEvent.UserEndpoint,
Scopes: idpEvent.Scopes,
IDAttribute: idpEvent.IDAttribute,
UsePKCE: idpEvent.UsePKCE,
}
2025-07-25 17:06:18 +01:00
payload, err := json.Marshal(oauth)
if err != nil {
return nil, err
}
2025-07-25 17:06:18 +01:00
var orgId *string
if idpEvent.Aggregate().ResourceOwner != idpEvent.Agg.InstanceID {
orgId = &idpEvent.Aggregate().ResourceOwner
}
return handler.NewMultiStatement(
&idpEvent,
handler.AddCreateStatement(
[]handler.Column{
handler.NewCol(IDPTemplateIDCol, idpEvent.ID),
handler.NewCol(IDPRelationalOrgId, orgId),
handler.NewCol(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
handler.NewCol(IDPTemplateStateCol, db_domain.IDPStateActive.String()),
handler.NewCol(IDPTemplateNameCol, idpEvent.Name),
handler.NewCol(IDPTemplateTypeCol, db_domain.IDPTypeOAuth.String()),
handler.NewCol(IDPRelationalAllowCreationCol, idpEvent.IsCreationAllowed),
handler.NewCol(IDPRelationalAllowLinkingCol, idpEvent.IsLinkingAllowed),
handler.NewCol(IDPRelationalAllowAutoCreationCol, idpEvent.IsAutoCreation),
handler.NewCol(IDPRelationalAllowAutoUpdateCol, idpEvent.IsAutoUpdate),
handler.NewCol(IDPRelationalAllowAutoLinkingCol, db_domain.IDPAutoLinkingOption(idpEvent.AutoLinkingOption).String()),
handler.NewCol(IDPRelationalPayloadCol, payload),
handler.NewCol(CreatedAt, idpEvent.CreationDate()),
},
),
), nil
}
2025-07-25 17:06:18 +01:00
func (p *idpTemplateRelationalProjection) reduceOAuthIDPRelationalChanged(event eventstore.Event) (*handler.Statement, error) {
var idpEvent idp.OAuthIDPChangedEvent
switch e := event.(type) {
case *org.OAuthIDPChangedEvent:
idpEvent = e.OAuthIDPChangedEvent
case *instance.OAuthIDPChangedEvent:
idpEvent = e.OAuthIDPChangedEvent
default:
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-Y1582ks", "reduce.wrong.event.type %v", []eventstore.EventType{org.OAuthIDPChangedEventType, instance.OAuthIDPChangedEventType})
}
2025-07-25 17:06:18 +01:00
var orgId *string
if idpEvent.Aggregate().ResourceOwner != idpEvent.Agg.InstanceID {
orgId = &idpEvent.Aggregate().ResourceOwner
}
oauth, err := p.idpRepo.GetOAuth(context.Background(), p.idpRepo.IDCondition(idpEvent.ID), idpEvent.Agg.InstanceID, orgId)
if err != nil {
return nil, err
}
2025-07-25 17:06:18 +01:00
columns := make([]handler.Column, 0, 7)
reduceIDPRelationalChangedTemplateColumns(idpEvent.Name, idpEvent.OptionChanges, &columns)
payload := &oauth.OAuth
payloadChanged := reduceOAuthIDPRelationalChangedColumns(payload, &idpEvent)
if payloadChanged {
payload, err := json.Marshal(payload)
if err != nil {
return nil, err
}
columns = append(columns, handler.NewCol(IDPRelationalPayloadCol, payload))
}
2025-07-25 17:06:18 +01:00
return handler.NewMultiStatement(
&idpEvent,
handler.AddUpdateStatement(
columns,
[]handler.Condition{
handler.NewCond(IDPTemplateIDCol, idpEvent.ID),
handler.NewCond(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
handler.NewCond(IDPRelationalOrgId, orgId),
},
),
), nil
}
2025-07-25 17:06:18 +01:00
func (p *idpTemplateRelationalProjection) reduceOIDCIDPRelationalAdded(event eventstore.Event) (*handler.Statement, error) {
var idpEvent idp.OIDCIDPAddedEvent
switch e := event.(type) {
case *org.OIDCIDPAddedEvent:
idpEvent = e.OIDCIDPAddedEvent
case *instance.OIDCIDPAddedEvent:
idpEvent = e.OIDCIDPAddedEvent
default:
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-Ys02m1", "reduce.wrong.event.type %v", []eventstore.EventType{org.OIDCIDPAddedEventType, instance.OIDCIDPAddedEventType})
}
// idpEvent, ok := event.(*instance.OIDCIDPAddedEvent)
// if !ok {
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-9s02m1", "reduce.wrong.event.type %v", []eventstore.EventType{org.OIDCIDPAddedEventType, instance.OIDCIDPAddedEventType})
// }
payload, err := json.Marshal(idpEvent)
if err != nil {
return nil, err
}
var orgId *string
if idpEvent.Aggregate().ResourceOwner != idpEvent.Agg.InstanceID {
orgId = &idpEvent.Aggregate().ResourceOwner
}
return handler.NewMultiStatement(
&idpEvent,
handler.AddCreateStatement(
[]handler.Column{
handler.NewCol(IDPTemplateIDCol, idpEvent.ID),
handler.NewCol(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
handler.NewCol(IDPRelationalOrgId, orgId),
handler.NewCol(IDPTemplateStateCol, db_domain.IDPStateActive),
handler.NewCol(IDPTemplateNameCol, idpEvent.Name),
handler.NewCol(IDPTemplateTypeCol, db_domain.IDPTypeOIDC.String()),
handler.NewCol(IDPRelationalAllowCreationCol, idpEvent.IsCreationAllowed),
handler.NewCol(IDPRelationalAllowLinkingCol, idpEvent.IsLinkingAllowed),
handler.NewCol(IDPRelationalAllowAutoCreationCol, idpEvent.IsAutoCreation),
handler.NewCol(IDPRelationalAllowAutoUpdateCol, idpEvent.IsAutoUpdate),
handler.NewCol(IDPRelationalAllowAutoLinkingCol, db_domain.IDPAutoLinkingOption(idpEvent.AutoLinkingOption).String()),
handler.NewCol(IDPRelationalPayloadCol, payload),
handler.NewCol(CreatedAt, idpEvent.CreationDate()),
},
),
), nil
}
func (p *idpTemplateRelationalProjection) reduceOIDCIDPRelationalChanged(event eventstore.Event) (*handler.Statement, error) {
var idpEvent idp.OIDCIDPChangedEvent
switch e := event.(type) {
case *org.OIDCIDPChangedEvent:
idpEvent = e.OIDCIDPChangedEvent
case *instance.OIDCIDPChangedEvent:
idpEvent = e.OIDCIDPChangedEvent
default:
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-Y1582ks", "reduce.wrong.event.type %v", []eventstore.EventType{org.OIDCIDPChangedEventType, instance.OIDCIDPChangedEventType})
}
// idpEvent, ok := event.(*instance.OIDCIDPChangedEvent)
// if !ok {
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-p1582ks", "reduce.wrong.event.type %v", []eventstore.EventType{org.OIDCIDPChangedEventType, instance.OIDCIDPChangedEventType})
// }
var orgId *string
if idpEvent.Aggregate().ResourceOwner != idpEvent.Agg.InstanceID {
orgId = &idpEvent.Aggregate().ResourceOwner
}
oidc, err := p.idpRepo.GetOIDC(context.Background(), p.idpRepo.IDCondition(idpEvent.ID), idpEvent.Agg.InstanceID, orgId)
if err != nil {
return nil, err
}
columns := make([]handler.Column, 0, 7)
reduceIDPRelationalChangedTemplateColumns(idpEvent.Name, idpEvent.OptionChanges, &columns)
payload := &oidc.OIDC
payloadChanged := reduceOIDCIDPRelationalChangedColumns(payload, &idpEvent)
if payloadChanged {
payload, err := json.Marshal(payload)
if err != nil {
return nil, err
}
columns = append(columns, handler.NewCol(IDPRelationalPayloadCol, payload))
}
return handler.NewMultiStatement(
&idpEvent,
handler.AddUpdateStatement(
columns,
[]handler.Condition{
handler.NewCond(IDPTemplateIDCol, idpEvent.ID),
handler.NewCond(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
handler.NewCond(IDPRelationalOrgId, orgId),
},
),
), nil
}
2025-07-25 17:06:18 +01:00
func (p *idpTemplateRelationalProjection) reduceOIDCIDPRelationalMigratedAzureAD(event eventstore.Event) (*handler.Statement, error) {
var idpEvent idp.OIDCIDPMigratedAzureADEvent
switch e := event.(type) {
case *org.OIDCIDPMigratedAzureADEvent:
idpEvent = e.OIDCIDPMigratedAzureADEvent
case *instance.OIDCIDPMigratedAzureADEvent:
idpEvent = e.OIDCIDPMigratedAzureADEvent
default:
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-Y1582ks", "reduce.wrong.event.type %v", []eventstore.EventType{org.OIDCIDPMigratedAzureADEventType, instance.OIDCIDPMigratedAzureADEventType})
}
// idpEvent, ok := event.(*instance.OIDCIDPMigratedAzureADEvent)
// if !ok {
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-p1582ks", "reduce.wrong.event.type %v", []eventstore.EventType{org.OIDCIDPMigratedAzureADEventType, instance.OIDCIDPMigratedAzureADEventType})
// }
2025-07-25 17:06:18 +01:00
azure := db_domain.Azure{
ClientID: idpEvent.ClientID,
ClientSecret: idpEvent.ClientSecret,
Scopes: idpEvent.Scopes,
Tenant: idpEvent.Tenant,
IsEmailVerified: idpEvent.IsEmailVerified,
}
payload, err := json.Marshal(azure)
if err != nil {
return nil, err
}
var orgId *string
if idpEvent.Aggregate().ResourceOwner != idpEvent.Agg.InstanceID {
orgId = &idpEvent.Aggregate().ResourceOwner
}
return handler.NewMultiStatement(
&idpEvent,
handler.AddUpdateStatement(
[]handler.Column{
handler.NewCol(IDPTemplateNameCol, idpEvent.Name),
handler.NewCol(IDPTemplateTypeCol, db_domain.IDPTypeAzure.String()),
handler.NewCol(IDPRelationalAllowCreationCol, idpEvent.IsCreationAllowed),
handler.NewCol(IDPRelationalAllowLinkingCol, idpEvent.IsLinkingAllowed),
handler.NewCol(IDPRelationalAllowAutoCreationCol, idpEvent.IsAutoCreation),
handler.NewCol(IDPRelationalAllowAutoUpdateCol, idpEvent.IsAutoUpdate),
handler.NewCol(IDPRelationalAllowAutoLinkingCol, db_domain.IDPAutoLinkingOption(idpEvent.AutoLinkingOption).String()),
handler.NewCol(IDPRelationalPayloadCol, payload),
},
[]handler.Condition{
handler.NewCond(IDPTemplateIDCol, idpEvent.ID),
handler.NewCond(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
handler.NewCond(IDPRelationalOrgId, orgId),
},
),
), nil
}
func (p *idpTemplateRelationalProjection) reduceOIDCIDPRelationalMigratedGoogle(event eventstore.Event) (*handler.Statement, error) {
var idpEvent idp.OIDCIDPMigratedGoogleEvent
switch e := event.(type) {
case *org.OIDCIDPMigratedGoogleEvent:
idpEvent = e.OIDCIDPMigratedGoogleEvent
case *instance.OIDCIDPMigratedGoogleEvent:
idpEvent = e.OIDCIDPMigratedGoogleEvent
default:
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-Y1582ks", "reduce.wrong.event.type %v", []eventstore.EventType{org.OIDCIDPMigratedGoogleEventType, instance.OIDCIDPMigratedGoogleEventType})
}
// idpEvent, ok := event.(*instance.OIDCIDPMigratedGoogleEvent)
// if !ok {
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-p1582ks", "reduce.wrong.event.type %v", []eventstore.EventType{org.OIDCIDPMigratedGoogleEventType, instance.OIDCIDPMigratedGoogleEventType})
// }
google := db_domain.Google{
ClientID: idpEvent.ClientID,
ClientSecret: idpEvent.ClientSecret,
Scopes: idpEvent.Scopes,
}
payload, err := json.Marshal(google)
if err != nil {
return nil, err
}
var orgId *string
if idpEvent.Aggregate().ResourceOwner != idpEvent.Agg.InstanceID {
orgId = &idpEvent.Aggregate().ResourceOwner
}
return handler.NewMultiStatement(
&idpEvent,
handler.AddUpdateStatement(
[]handler.Column{
handler.NewCol(IDPTemplateNameCol, idpEvent.Name),
handler.NewCol(IDPTemplateTypeCol, db_domain.IDPTypeGoogle.String()),
handler.NewCol(IDPRelationalAllowCreationCol, idpEvent.IsCreationAllowed),
handler.NewCol(IDPRelationalAllowLinkingCol, idpEvent.IsLinkingAllowed),
handler.NewCol(IDPRelationalAllowAutoCreationCol, idpEvent.IsAutoCreation),
handler.NewCol(IDPRelationalAllowAutoUpdateCol, idpEvent.IsAutoUpdate),
handler.NewCol(IDPRelationalAllowAutoLinkingCol, db_domain.IDPAutoLinkingOption(idpEvent.AutoLinkingOption).String()),
handler.NewCol(IDPRelationalPayloadCol, payload),
},
[]handler.Condition{
handler.NewCond(IDPTemplateIDCol, idpEvent.ID),
handler.NewCond(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
handler.NewCond(IDPRelationalOrgId, orgId),
},
),
), nil
}
2025-07-25 17:06:18 +01:00
func (p *idpTemplateRelationalProjection) reduceJWTIDPRelationalAdded(event eventstore.Event) (*handler.Statement, error) {
var idpEvent idp.JWTIDPAddedEvent
switch e := event.(type) {
case *org.JWTIDPAddedEvent:
idpEvent = e.JWTIDPAddedEvent
case *instance.JWTIDPAddedEvent:
idpEvent = e.JWTIDPAddedEvent
default:
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-Yopi2s", "reduce.wrong.event.type %v", []eventstore.EventType{org.JWTIDPAddedEventType, instance.JWTIDPAddedEventType})
}
// idpEvent, ok := event.(*instance.JWTIDPAddedEvent)
// if !ok {
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-xopi2s", "reduce.wrong.event.type %v", []eventstore.EventType{org.JWTIDPAddedEventType, instance.JWTIDPAddedEventType})
// }
jwt := db_domain.JWT{
JWTEndpoint: idpEvent.JWTEndpoint,
Issuer: idpEvent.Issuer,
KeysEndpoint: idpEvent.KeysEndpoint,
HeaderName: idpEvent.HeaderName,
}
payload, err := json.Marshal(jwt)
if err != nil {
return nil, err
}
var orgId *string
if idpEvent.Aggregate().ResourceOwner != idpEvent.Agg.InstanceID {
orgId = &idpEvent.Aggregate().ResourceOwner
}
return handler.NewMultiStatement(
&idpEvent,
handler.AddCreateStatement(
[]handler.Column{
handler.NewCol(IDPTemplateIDCol, idpEvent.ID),
handler.NewCol(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
handler.NewCol(IDPRelationalOrgId, orgId),
handler.NewCol(IDPTemplateNameCol, idpEvent.Name),
handler.NewCol(IDPTemplateStateCol, db_domain.IDPStateActive.String()),
handler.NewCol(IDPTemplateTypeCol, db_domain.IDPTypeJWT.String()),
handler.NewCol(IDPRelationalAllowCreationCol, idpEvent.IsCreationAllowed),
handler.NewCol(IDPRelationalAllowLinkingCol, idpEvent.IsLinkingAllowed),
handler.NewCol(IDPRelationalAllowAutoCreationCol, idpEvent.IsAutoCreation),
handler.NewCol(IDPRelationalAllowAutoUpdateCol, idpEvent.IsAutoUpdate),
handler.NewCol(IDPRelationalAllowAutoLinkingCol, db_domain.IDPAutoLinkingOption(idpEvent.AutoLinkingOption).String()),
handler.NewCol(IDPRelationalPayloadCol, payload),
handler.NewCol(CreatedAt, idpEvent.CreationDate()),
},
),
), nil
}
2025-07-25 17:06:18 +01:00
func (p *idpTemplateRelationalProjection) reduceJWTIDPRelationalChanged(event eventstore.Event) (*handler.Statement, error) {
var idpEvent idp.JWTIDPChangedEvent
switch e := event.(type) {
case *org.JWTIDPChangedEvent:
idpEvent = e.JWTIDPChangedEvent
case *instance.JWTIDPChangedEvent:
idpEvent = e.JWTIDPChangedEvent
default:
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-Y1582ks", "reduce.wrong.event.type %v", []eventstore.EventType{org.JWTIDPChangedEventType, instance.JWTIDPChangedEventType})
}
// idpEvent, ok := event.(*instance.JWTIDPChangedEvent)
// if !ok {
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-p1582ks", "reduce.wrong.event.type %v", []eventstore.EventType{org.JWTIDPChangedEventType, instance.JWTIDPChangedEventType})
// }
var orgId *string
if idpEvent.Aggregate().ResourceOwner != idpEvent.Agg.InstanceID {
orgId = &idpEvent.Aggregate().ResourceOwner
}
2025-07-25 17:06:18 +01:00
jwt, err := p.idpRepo.GetJWT(context.Background(), p.idpRepo.IDCondition(idpEvent.ID), idpEvent.Agg.InstanceID, orgId)
if err != nil {
return nil, err
}
columns := make([]handler.Column, 0, 7)
reduceIDPRelationalChangedTemplateColumns(idpEvent.Name, idpEvent.OptionChanges, &columns)
payload := &jwt.JWT
payloadChanged := reduceJWTIDPRelationalChangedColumns(payload, &idpEvent)
if payloadChanged {
payload, err := json.Marshal(payload)
if err != nil {
return nil, err
}
columns = append(columns, handler.NewCol(IDPRelationalPayloadCol, payload))
}
2025-07-25 17:06:18 +01:00
return handler.NewMultiStatement(
&idpEvent,
handler.AddUpdateStatement(
columns,
[]handler.Condition{
handler.NewCond(IDPTemplateIDCol, idpEvent.ID),
handler.NewCond(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
handler.NewCond(IDPRelationalOrgId, orgId),
},
),
), nil
}
// func (p *idpTemplateRelationalProjection) reduceOldConfigAdded(event eventstore.Event) (*handler.Statement, error) {
2025-07-25 17:06:18 +01:00
// var idpEvent idpconfig.IDPConfigAddedEvent
// var idpOwnerType domain.IdentityProviderType
// switch e := event.(type) {
// case *org.IDPConfigAddedEvent:
// idpEvent = e.IDPConfigAddedEvent
// idpOwnerType = domain.IdentityProviderTypeOrg
// case *instance.IDPConfigAddedEvent:
// idpEvent = e.IDPConfigAddedEvent
// idpOwnerType = domain.IdentityProviderTypeSystem
// default:
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-ADfeg", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPConfigAddedEventType, instance.IDPConfigAddedEventType})
// }
// return handler.NewCreateStatement(
// event,
// []handler.Column{
// handler.NewCol(IDPTemplateIDCol, idpEvent.ConfigID),
// handler.NewCol(IDPTemplateCreationDateCol, idpEvent.CreationDate()),
// handler.NewCol(IDPTemplateChangeDateCol, idpEvent.CreationDate()),
// handler.NewCol(IDPTemplateSequenceCol, idpEvent.Sequence()),
// handler.NewCol(IDPTemplateResourceOwnerCol, idpEvent.Aggregate().ResourceOwner),
// handler.NewCol(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
// handler.NewCol(IDPTemplateStateCol, domain.IDPStateActive),
// handler.NewCol(IDPTemplateNameCol, idpEvent.Name),
// handler.NewCol(IDPTemplateOwnerTypeCol, idpOwnerType),
// handler.NewCol(IDPTemplateTypeCol, domain.IDPTypeUnspecified),
// handler.NewCol(IDPTemplateIsCreationAllowedCol, true),
// handler.NewCol(IDPTemplateIsLinkingAllowedCol, true),
// handler.NewCol(IDPTemplateIsAutoCreationCol, idpEvent.AutoRegister),
// handler.NewCol(IDPTemplateIsAutoUpdateCol, false),
// handler.NewCol(IDPTemplateAutoLinkingCol, domain.AutoLinkingOptionUnspecified),
// },
// ), nil
// }
// func (p *idpTemplateProjection) reduceOldConfigChanged(event eventstore.Event) (*handler.Statement, error) {
// var idpEvent idpconfig.IDPConfigChangedEvent
// switch e := event.(type) {
// case *org.IDPConfigChangedEvent:
// idpEvent = e.IDPConfigChangedEvent
// case *instance.IDPConfigChangedEvent:
// idpEvent = e.IDPConfigChangedEvent
// default:
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-SAfg2", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPConfigChangedEventType, instance.IDPConfigChangedEventType})
// }
// cols := make([]handler.Column, 0, 4)
// if idpEvent.Name != nil {
// cols = append(cols, handler.NewCol(IDPTemplateNameCol, *idpEvent.Name))
// }
// if idpEvent.AutoRegister != nil {
// cols = append(cols, handler.NewCol(IDPTemplateIsAutoCreationCol, *idpEvent.AutoRegister))
// }
// cols = append(cols,
// handler.NewCol(IDPTemplateChangeDateCol, idpEvent.CreationDate()),
// handler.NewCol(IDPTemplateSequenceCol, idpEvent.Sequence()),
// )
// return handler.NewUpdateStatement(
// event,
// cols,
// []handler.Condition{
// handler.NewCond(IDPTemplateIDCol, idpEvent.ConfigID),
// handler.NewCond(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
// },
// ), nil
// }
// func (p *idpTemplateProjection) reduceOldOIDCConfigAdded(event eventstore.Event) (*handler.Statement, error) {
// var idpEvent idpconfig.OIDCConfigAddedEvent
// switch e := event.(type) {
// case *org.IDPOIDCConfigAddedEvent:
// idpEvent = e.OIDCConfigAddedEvent
// case *instance.IDPOIDCConfigAddedEvent:
// idpEvent = e.OIDCConfigAddedEvent
// default:
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-ASFdq2", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPOIDCConfigAddedEventType, instance.IDPOIDCConfigAddedEventType})
// }
// return handler.NewMultiStatement(
// &idpEvent,
// handler.AddUpdateStatement(
// []handler.Column{
// handler.NewCol(IDPTemplateChangeDateCol, idpEvent.CreationDate()),
// handler.NewCol(IDPTemplateSequenceCol, idpEvent.Sequence()),
// handler.NewCol(IDPTemplateTypeCol, domain.IDPTypeOIDC),
// },
// []handler.Condition{
// handler.NewCond(IDPTemplateIDCol, idpEvent.IDPConfigID),
// handler.NewCond(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
// },
// ),
// handler.AddCreateStatement(
// []handler.Column{
// handler.NewCol(OIDCIDCol, idpEvent.IDPConfigID),
// handler.NewCol(OIDCInstanceIDCol, idpEvent.Aggregate().InstanceID),
// handler.NewCol(OIDCIssuerCol, idpEvent.Issuer),
// handler.NewCol(OIDCClientIDCol, idpEvent.ClientID),
// handler.NewCol(OIDCClientSecretCol, idpEvent.ClientSecret),
// handler.NewCol(OIDCScopesCol, database.TextArray[string](idpEvent.Scopes)),
// handler.NewCol(OIDCIDTokenMappingCol, true),
// handler.NewCol(OIDCUsePKCECol, false),
// },
// handler.WithTableSuffix(IDPTemplateOIDCSuffix),
// ),
// ), nil
// }
// func (p *idpTemplateProjection) reduceOldOIDCConfigChanged(event eventstore.Event) (*handler.Statement, error) {
// var idpEvent idpconfig.OIDCConfigChangedEvent
// switch e := event.(type) {
// case *org.IDPOIDCConfigChangedEvent:
// idpEvent = e.OIDCConfigChangedEvent
// case *instance.IDPOIDCConfigChangedEvent:
// idpEvent = e.OIDCConfigChangedEvent
// default:
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-p1582ks", "reduce.wrong.event.type %v", []eventstore.EventType{org.OIDCIDPChangedEventType, instance.OIDCIDPChangedEventType})
// }
// ops := make([]func(eventstore.Event) handler.Exec, 0, 2)
// ops = append(ops,
// handler.AddUpdateStatement(
// []handler.Column{
// handler.NewCol(IDPTemplateChangeDateCol, idpEvent.CreationDate()),
// handler.NewCol(IDPTemplateSequenceCol, idpEvent.Sequence()),
// },
// []handler.Condition{
// handler.NewCond(IDPTemplateIDCol, idpEvent.IDPConfigID),
// handler.NewCond(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
// },
// ),
// )
// oidcCols := make([]handler.Column, 0, 4)
// if idpEvent.ClientID != nil {
// oidcCols = append(oidcCols, handler.NewCol(OIDCClientIDCol, *idpEvent.ClientID))
// }
// if idpEvent.ClientSecret != nil {
// oidcCols = append(oidcCols, handler.NewCol(OIDCClientSecretCol, *idpEvent.ClientSecret))
// }
// if idpEvent.Issuer != nil {
// oidcCols = append(oidcCols, handler.NewCol(OIDCIssuerCol, *idpEvent.Issuer))
// }
// if idpEvent.Scopes != nil {
// oidcCols = append(oidcCols, handler.NewCol(OIDCScopesCol, database.TextArray[string](idpEvent.Scopes)))
// }
// if len(oidcCols) > 0 {
// ops = append(ops,
// handler.AddUpdateStatement(
// oidcCols,
// []handler.Condition{
// handler.NewCond(OIDCIDCol, idpEvent.IDPConfigID),
// handler.NewCond(OIDCInstanceIDCol, idpEvent.Aggregate().InstanceID),
// },
// handler.WithTableSuffix(IDPTemplateOIDCSuffix),
// ),
// )
// }
// return handler.NewMultiStatement(
// &idpEvent,
// ops...,
// ), nil
// }
// func (p *idpTemplateProjection) reduceOldJWTConfigAdded(event eventstore.Event) (*handler.Statement, error) {
// var idpEvent idpconfig.JWTConfigAddedEvent
// switch e := event.(type) {
// case *org.IDPJWTConfigAddedEvent:
// idpEvent = e.JWTConfigAddedEvent
// case *instance.IDPJWTConfigAddedEvent:
// idpEvent = e.JWTConfigAddedEvent
// default:
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-ASFdq2", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPJWTConfigAddedEventType, instance.IDPJWTConfigAddedEventType})
// }
// return handler.NewMultiStatement(
// &idpEvent,
// handler.AddUpdateStatement(
// []handler.Column{
// handler.NewCol(IDPTemplateChangeDateCol, idpEvent.CreationDate()),
// handler.NewCol(IDPTemplateSequenceCol, idpEvent.Sequence()),
// handler.NewCol(IDPTemplateTypeCol, domain.IDPTypeJWT),
// },
// []handler.Condition{
// handler.NewCond(IDPTemplateIDCol, idpEvent.IDPConfigID),
// handler.NewCond(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
// },
// ),
// handler.AddCreateStatement(
// []handler.Column{
// handler.NewCol(JWTIDCol, idpEvent.IDPConfigID),
// handler.NewCol(JWTInstanceIDCol, idpEvent.Aggregate().InstanceID),
// handler.NewCol(JWTIssuerCol, idpEvent.Issuer),
// handler.NewCol(JWTEndpointCol, idpEvent.JWTEndpoint),
// handler.NewCol(JWTKeysEndpointCol, idpEvent.KeysEndpoint),
// handler.NewCol(JWTHeaderNameCol, idpEvent.HeaderName),
// },
// handler.WithTableSuffix(IDPTemplateJWTSuffix),
// ),
// ), nil
// }
// func (p *idpTemplateProjection) reduceOldJWTConfigChanged(event eventstore.Event) (*handler.Statement, error) {
// var idpEvent idpconfig.JWTConfigChangedEvent
// switch e := event.(type) {
// case *org.IDPJWTConfigChangedEvent:
// idpEvent = e.JWTConfigChangedEvent
// case *instance.IDPJWTConfigChangedEvent:
// idpEvent = e.JWTConfigChangedEvent
// default:
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-p1582ks", "reduce.wrong.event.type %v", []eventstore.EventType{org.JWTIDPChangedEventType, instance.JWTIDPChangedEventType})
// }
// ops := make([]func(eventstore.Event) handler.Exec, 0, 2)
// ops = append(ops,
// handler.AddUpdateStatement(
// []handler.Column{
// handler.NewCol(IDPTemplateChangeDateCol, idpEvent.CreationDate()),
// handler.NewCol(IDPTemplateSequenceCol, idpEvent.Sequence()),
// },
// []handler.Condition{
// handler.NewCond(IDPTemplateIDCol, idpEvent.IDPConfigID),
// handler.NewCond(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
// },
// ),
// )
// jwtCols := make([]handler.Column, 0, 4)
// if idpEvent.JWTEndpoint != nil {
// jwtCols = append(jwtCols, handler.NewCol(JWTEndpointCol, *idpEvent.JWTEndpoint))
// }
// if idpEvent.KeysEndpoint != nil {
// jwtCols = append(jwtCols, handler.NewCol(JWTKeysEndpointCol, *idpEvent.KeysEndpoint))
// }
// if idpEvent.HeaderName != nil {
// jwtCols = append(jwtCols, handler.NewCol(JWTHeaderNameCol, *idpEvent.HeaderName))
// }
// if idpEvent.Issuer != nil {
// jwtCols = append(jwtCols, handler.NewCol(JWTIssuerCol, *idpEvent.Issuer))
// }
// if len(jwtCols) > 0 {
// ops = append(ops,
// handler.AddUpdateStatement(
// jwtCols,
// []handler.Condition{
// handler.NewCond(JWTIDCol, idpEvent.IDPConfigID),
// handler.NewCond(JWTInstanceIDCol, idpEvent.Aggregate().InstanceID),
// },
// handler.WithTableSuffix(IDPTemplateJWTSuffix),
// ),
// )
// }
// return handler.NewMultiStatement(
// &idpEvent,
// ops...,
// ), nil
// }
func (p *idpTemplateRelationalProjection) reduceAzureADIDPRelationalAdded(event eventstore.Event) (*handler.Statement, error) {
var idpEvent idp.AzureADIDPAddedEvent
switch e := event.(type) {
case *org.AzureADIDPAddedEvent:
idpEvent = e.AzureADIDPAddedEvent
case *instance.AzureADIDPAddedEvent:
idpEvent = e.AzureADIDPAddedEvent
default:
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-Y9a022b", "reduce.wrong.event.type %v", []eventstore.EventType{org.AzureADIDPAddedEventType, instance.AzureADIDPAddedEventType})
}
// idpEvent, ok := event.(*instance.AzureADIDPAddedEvent)
// if !ok {
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-x9a022b", "reduce.wrong.event.type %v", []eventstore.EventType{org.AzureADIDPAddedEventType, instance.AzureADIDPAddedEventType})
// }
2025-07-25 17:06:18 +01:00
azure := db_domain.Azure{
ClientID: idpEvent.ClientID,
ClientSecret: idpEvent.ClientSecret,
Scopes: idpEvent.Scopes,
Tenant: idpEvent.Tenant,
IsEmailVerified: idpEvent.IsEmailVerified,
}
2025-07-25 17:06:18 +01:00
payload, err := json.Marshal(azure)
if err != nil {
return nil, err
}
2025-07-25 17:06:18 +01:00
var orgId *string
if idpEvent.Aggregate().ResourceOwner != idpEvent.Agg.InstanceID {
orgId = &idpEvent.Aggregate().ResourceOwner
}
return handler.NewMultiStatement(
&idpEvent,
handler.AddCreateStatement(
[]handler.Column{
handler.NewCol(IDPTemplateIDCol, idpEvent.ID),
handler.NewCol(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
handler.NewCol(IDPRelationalOrgId, orgId),
handler.NewCol(IDPTemplateNameCol, idpEvent.Name),
handler.NewCol(IDPTemplateTypeCol, db_domain.IDPTypeAzure.String()),
handler.NewCol(IDPTemplateStateCol, db_domain.IDPStateActive.String()),
handler.NewCol(IDPRelationalAllowCreationCol, idpEvent.IsCreationAllowed),
handler.NewCol(IDPRelationalAllowLinkingCol, idpEvent.IsLinkingAllowed),
handler.NewCol(IDPRelationalAllowAutoCreationCol, idpEvent.IsAutoCreation),
handler.NewCol(IDPRelationalAllowAutoUpdateCol, idpEvent.IsAutoUpdate),
handler.NewCol(IDPRelationalAllowAutoLinkingCol, db_domain.IDPAutoLinkingOption(idpEvent.AutoLinkingOption).String()),
handler.NewCol(CreatedAt, idpEvent.CreationDate()),
handler.NewCol(IDPRelationalPayloadCol, payload),
},
),
), nil
}
func (p *idpTemplateRelationalProjection) reduceAzureADIDPRelationalChanged(event eventstore.Event) (*handler.Statement, error) {
var idpEvent idp.AzureADIDPChangedEvent
switch e := event.(type) {
case *org.AzureADIDPChangedEvent:
idpEvent = e.AzureADIDPChangedEvent
case *instance.AzureADIDPChangedEvent:
idpEvent = e.AzureADIDPChangedEvent
default:
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-Y1582ks", "reduce.wrong.event.type %v", []eventstore.EventType{org.AzureADIDPChangedEventType, instance.AzureADIDPChangedEventType})
}
// idpEvent, ok := event.(*instance.AzureADIDPChangedEvent)
// if !ok {
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-p1582ks", "reduce.wrong.event.type %v", []eventstore.EventType{org.AzureADIDPChangedEventType, instance.AzureADIDPChangedEventType})
// }
var orgId *string
if idpEvent.Aggregate().ResourceOwner != idpEvent.Agg.InstanceID {
orgId = &idpEvent.Aggregate().ResourceOwner
}
oauth, err := p.idpRepo.GetOAzureAD(context.Background(), p.idpRepo.IDCondition(idpEvent.ID), idpEvent.Agg.InstanceID, orgId)
if err != nil {
return nil, err
}
columns := make([]handler.Column, 0, 7)
reduceIDPRelationalChangedTemplateColumns(idpEvent.Name, idpEvent.OptionChanges, &columns)
payload := &oauth.Azure
payloadChanged := reduceAzureADIDPRelationalChangedColumns(payload, &idpEvent)
if payloadChanged {
payload, err := json.Marshal(payload)
if err != nil {
return nil, err
}
columns = append(columns, handler.NewCol(IDPRelationalPayloadCol, payload))
}
return handler.NewMultiStatement(
&idpEvent,
handler.AddUpdateStatement(
columns,
[]handler.Condition{
handler.NewCond(IDPTemplateIDCol, idpEvent.ID),
handler.NewCond(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
handler.NewCond(IDPRelationalOrgId, orgId),
},
),
), nil
}
func (p *idpTemplateRelationalProjection) reduceGitHubIDPRelationalAdded(event eventstore.Event) (*handler.Statement, error) {
var idpEvent idp.GitHubIDPAddedEvent
switch e := event.(type) {
case *org.GitHubIDPAddedEvent:
idpEvent = e.GitHubIDPAddedEvent
case *instance.GitHubIDPAddedEvent:
idpEvent = e.GitHubIDPAddedEvent
default:
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-x9a022b", "reduce.wrong.event.type %v", []eventstore.EventType{org.GitHubIDPAddedEventType, instance.GitHubIDPAddedEventType})
}
// idpEvent, ok := event.(*instance.GitHubIDPAddedEvent)
// if !ok {
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-x9a022b", "reduce.wrong.event.type %v", []eventstore.EventType{org.GitHubIDPAddedEventType, instance.GitHubIDPAddedEventType})
// }
github := db_domain.Github{
ClientID: idpEvent.ClientID,
ClientSecret: idpEvent.ClientSecret,
Scopes: idpEvent.Scopes,
}
payload, err := json.Marshal(github)
if err != nil {
return nil, err
}
var orgId *string
if idpEvent.Aggregate().ResourceOwner != idpEvent.Agg.InstanceID {
orgId = &idpEvent.Aggregate().ResourceOwner
}
return handler.NewMultiStatement(
&idpEvent,
handler.AddCreateStatement(
[]handler.Column{
handler.NewCol(IDPTemplateIDCol, idpEvent.ID),
handler.NewCol(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
handler.NewCol(IDPRelationalOrgId, orgId),
handler.NewCol(IDPTemplateNameCol, idpEvent.Name),
handler.NewCol(IDPTemplateTypeCol, db_domain.IDPTypeGitHub.String()),
handler.NewCol(IDPTemplateStateCol, db_domain.IDPStateActive.String()),
handler.NewCol(IDPRelationalAllowCreationCol, idpEvent.IsCreationAllowed),
handler.NewCol(IDPRelationalAllowLinkingCol, idpEvent.IsLinkingAllowed),
handler.NewCol(IDPRelationalAllowAutoCreationCol, idpEvent.IsAutoCreation),
handler.NewCol(IDPRelationalAllowAutoUpdateCol, idpEvent.IsAutoUpdate),
handler.NewCol(IDPRelationalAllowAutoLinkingCol, db_domain.IDPAutoLinkingOption(idpEvent.AutoLinkingOption).String()),
handler.NewCol(CreatedAt, idpEvent.CreationDate()),
handler.NewCol(IDPRelationalPayloadCol, payload),
},
),
), nil
// return handler.NewMultiStatement(
// &idpEvent,
// handler.AddCreateStatement(
// []handler.Column{
// handler.NewCol(IDPTemplateIDCol, idpEvent.ID),
// handler.NewCol(IDPTemplateCreationDateCol, idpEvent.CreationDate()),
// handler.NewCol(IDPTemplateChangeDateCol, idpEvent.CreationDate()),
// handler.NewCol(IDPTemplateSequenceCol, idpEvent.Sequence()),
// handler.NewCol(IDPTemplateResourceOwnerCol, idpEvent.Aggregate().ResourceOwner),
// handler.NewCol(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
// handler.NewCol(IDPTemplateStateCol, domain.IDPStateActive),
// handler.NewCol(IDPTemplateNameCol, idpEvent.Name),
// handler.NewCol(IDPTemplateOwnerTypeCol, idpOwnerType),
// handler.NewCol(IDPTemplateTypeCol, domain.IDPTypeGithub),
// handler.NewCol(IDPTemplateIsCreationAllowedCol, idpEvent.IsCreationAllowed),
// handler.NewCol(IDPTemplateIsLinkingAllowedCol, idpEvent.IsLinkingAllowed),
// handler.NewCol(IDPTemplateIsAutoCreationCol, idpEvent.IsAutoCreation),
// handler.NewCol(IDPTemplateIsAutoUpdateCol, idpEvent.IsAutoUpdate),
// handler.NewCol(IDPTemplateAutoLinkingCol, idpEvent.AutoLinkingOption),
// },
// ),
// handler.AddCreateStatement(
// []handler.Column{
// handler.NewCol(GitHubIDCol, idpEvent.ID),
// handler.NewCol(GitHubInstanceIDCol, idpEvent.Aggregate().InstanceID),
// handler.NewCol(GitHubClientIDCol, idpEvent.ClientID),
// handler.NewCol(GitHubClientSecretCol, idpEvent.ClientSecret),
// handler.NewCol(GitHubScopesCol, database.TextArray[string](idpEvent.Scopes)),
// },
// handler.WithTableSuffix(IDPTemplateGitHubSuffix),
// ),
// ), nil
}
2025-07-25 17:06:18 +01:00
func (p *idpTemplateRelationalProjection) reduceGitHubIDPRelationalChanged(event eventstore.Event) (*handler.Statement, error) {
var idpEvent idp.GitHubIDPChangedEvent
switch e := event.(type) {
case *org.GitHubIDPChangedEvent:
idpEvent = e.GitHubIDPChangedEvent
case *instance.GitHubIDPChangedEvent:
idpEvent = e.GitHubIDPChangedEvent
default:
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-Y1582ks", "reduce.wrong.event.type %v", []eventstore.EventType{org.GitHubIDPChangedEventType, instance.GitHubIDPChangedEventType})
}
// idpEvent, ok := event.(*instance.GitHubIDPChangedEvent)
// if !ok {
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-p1582ks", "reduce.wrong.event.type %v", []eventstore.EventType{org.GitHubIDPChangedEventType, instance.GitHubIDPChangedEventType})
// }
var orgId *string
if idpEvent.Aggregate().ResourceOwner != idpEvent.Agg.InstanceID {
orgId = &idpEvent.Aggregate().ResourceOwner
}
2025-07-25 17:06:18 +01:00
github, err := p.idpRepo.GetGithub(context.Background(), p.idpRepo.IDCondition(idpEvent.ID), idpEvent.Agg.InstanceID, orgId)
if err != nil {
return nil, err
}
columns := make([]handler.Column, 0, 7)
reduceIDPRelationalChangedTemplateColumns(idpEvent.Name, idpEvent.OptionChanges, &columns)
payload := &github.Github
payloadChanged := reduceGitHubIDPRelationalChangedColumns(payload, &idpEvent)
if payloadChanged {
payload, err := json.Marshal(payload)
if err != nil {
return nil, err
}
columns = append(columns, handler.NewCol(IDPRelationalPayloadCol, payload))
}
return handler.NewMultiStatement(
&idpEvent,
handler.AddUpdateStatement(
columns,
[]handler.Condition{
handler.NewCond(IDPTemplateIDCol, idpEvent.ID),
handler.NewCond(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
handler.NewCond(IDPRelationalOrgId, orgId),
},
),
), nil
}
func (p *idpTemplateRelationalProjection) reduceGitHubEnterpriseIDPRelationalAdded(event eventstore.Event) (*handler.Statement, error) {
var idpEvent idp.GitHubEnterpriseIDPAddedEvent
switch e := event.(type) {
case *org.GitHubEnterpriseIDPAddedEvent:
idpEvent = e.GitHubEnterpriseIDPAddedEvent
case *instance.GitHubEnterpriseIDPAddedEvent:
idpEvent = e.GitHubEnterpriseIDPAddedEvent
default:
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-Yf3g2a", "reduce.wrong.event.type %v", []eventstore.EventType{org.GitHubEnterpriseIDPAddedEventType, instance.GitHubEnterpriseIDPAddedEventType})
}
// idpEvent, ok := event.(*instance.GitHubEnterpriseIDPAddedEvent)
// if !ok {
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-Sf3g2a", "reduce.wrong.event.type %v", []eventstore.EventType{org.GitHubEnterpriseIDPAddedEventType, instance.GitHubEnterpriseIDPAddedEventType})
// }
githubEnterprise := db_domain.GithubEnterprise{
ClientID: idpEvent.ClientID,
ClientSecret: idpEvent.ClientSecret,
AuthorizationEndpoint: idpEvent.AuthorizationEndpoint,
TokenEndpoint: idpEvent.TokenEndpoint,
UserEndpoint: idpEvent.UserEndpoint,
Scopes: idpEvent.Scopes,
}
payload, err := json.Marshal(githubEnterprise)
if err != nil {
return nil, err
}
var orgId *string
if idpEvent.Aggregate().ResourceOwner != idpEvent.Agg.InstanceID {
orgId = &idpEvent.Aggregate().ResourceOwner
}
return handler.NewMultiStatement(
&idpEvent,
handler.AddCreateStatement(
[]handler.Column{
handler.NewCol(IDPTemplateIDCol, idpEvent.ID),
handler.NewCol(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
handler.NewCol(IDPRelationalOrgId, orgId),
handler.NewCol(IDPTemplateStateCol, db_domain.IDPStateActive.String()),
handler.NewCol(IDPTemplateNameCol, idpEvent.Name),
handler.NewCol(IDPTemplateTypeCol, db_domain.IDPTypeGitHubEnterprise.String()),
handler.NewCol(IDPRelationalAllowCreationCol, idpEvent.IsCreationAllowed),
handler.NewCol(IDPRelationalAllowLinkingCol, idpEvent.IsLinkingAllowed),
handler.NewCol(IDPRelationalAllowAutoCreationCol, idpEvent.IsAutoCreation),
handler.NewCol(IDPRelationalAllowAutoUpdateCol, idpEvent.IsAutoUpdate),
handler.NewCol(IDPRelationalAllowAutoLinkingCol, db_domain.IDPAutoLinkingOption(idpEvent.AutoLinkingOption).String()),
handler.NewCol(IDPRelationalPayloadCol, payload),
handler.NewCol(CreatedAt, idpEvent.CreationDate()),
},
),
), nil
}
func (p *idpTemplateRelationalProjection) reduceGitHubEnterpriseIDPRelationalChanged(event eventstore.Event) (*handler.Statement, error) {
var idpEvent idp.GitHubEnterpriseIDPChangedEvent
switch e := event.(type) {
case *org.GitHubEnterpriseIDPChangedEvent:
idpEvent = e.GitHubEnterpriseIDPChangedEvent
case *instance.GitHubEnterpriseIDPChangedEvent:
idpEvent = e.GitHubEnterpriseIDPChangedEvent
default:
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-YDg3g", "reduce.wrong.event.type %v", []eventstore.EventType{org.GitHubEnterpriseIDPChangedEventType, instance.GitHubEnterpriseIDPChangedEventType})
}
// idpEvent, ok := event.(*instance.GitHubEnterpriseIDPChangedEvent)
// if !ok {
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-SDg3g", "reduce.wrong.event.type %v", []eventstore.EventType{org.GitHubEnterpriseIDPChangedEventType, instance.GitHubEnterpriseIDPChangedEventType})
// }
var orgId *string
if idpEvent.Aggregate().ResourceOwner != idpEvent.Agg.InstanceID {
orgId = &idpEvent.Aggregate().ResourceOwner
}
githubEnterprise, err := p.idpRepo.GetGithubEnterprise(context.Background(), p.idpRepo.IDCondition(idpEvent.ID), idpEvent.Agg.InstanceID, orgId)
if err != nil {
return nil, err
}
columns := make([]handler.Column, 0, 7)
reduceIDPRelationalChangedTemplateColumns(idpEvent.Name, idpEvent.OptionChanges, &columns)
payload := &githubEnterprise.GithubEnterprise
payloadChanged := reduceGitHubEnterpriseIDPRelationalChangedColumns(payload, &idpEvent)
if payloadChanged {
payload, err := json.Marshal(payload)
if err != nil {
return nil, err
}
columns = append(columns, handler.NewCol(IDPRelationalPayloadCol, payload))
}
return handler.NewMultiStatement(
&idpEvent,
handler.AddUpdateStatement(
columns,
[]handler.Condition{
handler.NewCond(IDPTemplateIDCol, idpEvent.ID),
handler.NewCond(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
handler.NewCond(IDPRelationalOrgId, orgId),
},
),
), nil
}
func (p *idpTemplateRelationalProjection) reduceGitLabIDPRelationalAdded(event eventstore.Event) (*handler.Statement, error) {
var idpEvent idp.GitLabIDPAddedEvent
switch e := event.(type) {
case *org.GitLabIDPAddedEvent:
idpEvent = e.GitLabIDPAddedEvent
case *instance.GitLabIDPAddedEvent:
idpEvent = e.GitLabIDPAddedEvent
default:
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-Y9a022b", "reduce.wrong.event.type %v", []eventstore.EventType{org.GitLabIDPAddedEventType, instance.GitLabIDPAddedEventType})
}
// idpEvent, ok := event.(*instance.GitLabIDPAddedEvent)
// if !ok {
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-x9a022b", "reduce.wrong.event.type %v", []eventstore.EventType{org.GitLabIDPAddedEventType, instance.GitLabIDPAddedEventType})
// }
gitlab := db_domain.Gitlab{
ClientID: idpEvent.ClientID,
ClientSecret: idpEvent.ClientSecret,
Scopes: idpEvent.Scopes,
}
payload, err := json.Marshal(gitlab)
if err != nil {
return nil, err
}
var orgId *string
if idpEvent.Aggregate().ResourceOwner != idpEvent.Agg.InstanceID {
orgId = &idpEvent.Aggregate().ResourceOwner
}
return handler.NewMultiStatement(
&idpEvent,
handler.AddCreateStatement(
[]handler.Column{
handler.NewCol(IDPTemplateIDCol, idpEvent.ID),
handler.NewCol(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
handler.NewCol(IDPRelationalOrgId, orgId),
handler.NewCol(IDPTemplateNameCol, idpEvent.Name),
handler.NewCol(IDPTemplateTypeCol, db_domain.IDPTypeGitLab.String()),
handler.NewCol(IDPTemplateStateCol, db_domain.IDPStateActive.String()),
handler.NewCol(IDPRelationalAllowCreationCol, idpEvent.IsCreationAllowed),
handler.NewCol(IDPRelationalAllowLinkingCol, idpEvent.IsLinkingAllowed),
handler.NewCol(IDPRelationalAllowAutoCreationCol, idpEvent.IsAutoCreation),
handler.NewCol(IDPRelationalAllowAutoUpdateCol, idpEvent.IsAutoUpdate),
handler.NewCol(IDPRelationalAllowAutoLinkingCol, db_domain.IDPAutoLinkingOption(idpEvent.AutoLinkingOption).String()),
handler.NewCol(CreatedAt, idpEvent.CreationDate()),
handler.NewCol(IDPRelationalPayloadCol, payload),
},
),
), nil
}
func (p *idpTemplateRelationalProjection) reduceGitLabIDPRelationalChanged(event eventstore.Event) (*handler.Statement, error) {
var idpEvent idp.GitLabIDPChangedEvent
switch e := event.(type) {
case *org.GitLabIDPChangedEvent:
idpEvent = e.GitLabIDPChangedEvent
case *instance.GitLabIDPChangedEvent:
idpEvent = e.GitLabIDPChangedEvent
default:
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-Y1582ks", "reduce.wrong.event.type %v", []eventstore.EventType{org.GitLabIDPChangedEventType, instance.GitLabIDPChangedEventType})
}
// idpEvent, ok := event.(*instance.GitLabIDPChangedEvent)
// if !ok {
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-p1582ks", "reduce.wrong.event.type %v", []eventstore.EventType{org.GitLabIDPChangedEventType, instance.GitLabIDPChangedEventType})
// }
var orgId *string
if idpEvent.Aggregate().ResourceOwner != idpEvent.Agg.InstanceID {
orgId = &idpEvent.Aggregate().ResourceOwner
}
oauth, err := p.idpRepo.GetGitlab(context.Background(), p.idpRepo.IDCondition(idpEvent.ID), idpEvent.Agg.InstanceID, orgId)
if err != nil {
return nil, err
}
columns := make([]handler.Column, 0, 7)
reduceIDPRelationalChangedTemplateColumns(idpEvent.Name, idpEvent.OptionChanges, &columns)
payload := &oauth.Gitlab
payloadChanged := reduceGitLabIDPRelationalChangedColumns(payload, &idpEvent)
if payloadChanged {
payload, err := json.Marshal(payload)
if err != nil {
return nil, err
}
columns = append(columns, handler.NewCol(IDPRelationalPayloadCol, payload))
}
return handler.NewMultiStatement(
&idpEvent,
handler.AddUpdateStatement(
columns,
[]handler.Condition{
handler.NewCond(IDPTemplateIDCol, idpEvent.ID),
handler.NewCond(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
handler.NewCond(IDPRelationalOrgId, orgId),
},
),
), nil
}
func (p *idpTemplateRelationalProjection) reduceGitLabSelfHostedIDPRelationalAdded(event eventstore.Event) (*handler.Statement, error) {
var idpEvent idp.GitLabSelfHostedIDPAddedEvent
switch e := event.(type) {
case *org.GitLabSelfHostedIDPAddedEvent:
idpEvent = e.GitLabSelfHostedIDPAddedEvent
case *instance.GitLabSelfHostedIDPAddedEvent:
idpEvent = e.GitLabSelfHostedIDPAddedEvent
default:
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-YAF3gw", "reduce.wrong.event.type %v", []eventstore.EventType{org.GitLabSelfHostedIDPAddedEventType, instance.GitLabSelfHostedIDPAddedEventType})
}
// idpEvent, ok := event.(*instance.GitLabSelfHostedIDPAddedEvent)
// if !ok {
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-SAF3gw", "reduce.wrong.event.type %v", []eventstore.EventType{org.GitLabSelfHostedIDPAddedEventType, instance.GitLabSelfHostedIDPAddedEventType})
// }
gitlabSelfHosting := db_domain.GitlabSelfHosting{
Issuer: idpEvent.Issuer,
ClientID: idpEvent.ClientID,
ClientSecret: idpEvent.ClientSecret,
Scopes: idpEvent.Scopes,
}
payload, err := json.Marshal(gitlabSelfHosting)
if err != nil {
return nil, err
}
var orgId *string
if idpEvent.Aggregate().ResourceOwner != idpEvent.Agg.InstanceID {
orgId = &idpEvent.Aggregate().ResourceOwner
}
return handler.NewMultiStatement(
&idpEvent,
handler.AddCreateStatement(
[]handler.Column{
handler.NewCol(IDPTemplateIDCol, idpEvent.ID),
handler.NewCol(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
handler.NewCol(IDPRelationalOrgId, orgId),
handler.NewCol(IDPTemplateNameCol, idpEvent.Name),
handler.NewCol(IDPTemplateTypeCol, db_domain.IDPTypeGitLabSelfHosted.String()),
handler.NewCol(IDPTemplateStateCol, db_domain.IDPStateActive.String()),
handler.NewCol(IDPRelationalAllowCreationCol, idpEvent.IsCreationAllowed),
handler.NewCol(IDPRelationalAllowLinkingCol, idpEvent.IsLinkingAllowed),
handler.NewCol(IDPRelationalAllowAutoCreationCol, idpEvent.IsAutoCreation),
handler.NewCol(IDPRelationalAllowAutoUpdateCol, idpEvent.IsAutoUpdate),
handler.NewCol(IDPRelationalAllowAutoLinkingCol, db_domain.IDPAutoLinkingOption(idpEvent.AutoLinkingOption).String()),
handler.NewCol(CreatedAt, idpEvent.CreationDate()),
handler.NewCol(IDPRelationalPayloadCol, payload),
},
),
), nil
}
func (p *idpTemplateRelationalProjection) reduceGitLabSelfHostedIDPRelationalChanged(event eventstore.Event) (*handler.Statement, error) {
var idpEvent idp.GitLabSelfHostedIDPChangedEvent
switch e := event.(type) {
case *org.GitLabSelfHostedIDPChangedEvent:
idpEvent = e.GitLabSelfHostedIDPChangedEvent
case *instance.GitLabSelfHostedIDPChangedEvent:
idpEvent = e.GitLabSelfHostedIDPChangedEvent
default:
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-YAf3g2", "reduce.wrong.event.type %v", []eventstore.EventType{org.GitLabSelfHostedIDPChangedEventType, instance.GitLabSelfHostedIDPChangedEventType})
}
// idpEvent, ok := event.(*instance.GitLabSelfHostedIDPChangedEvent)
// if !ok {
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-SAf3g2", "reduce.wrong.event.type %v", []eventstore.EventType{org.GitLabSelfHostedIDPChangedEventType, instance.GitLabSelfHostedIDPChangedEventType})
// }
var orgId *string
if idpEvent.Aggregate().ResourceOwner != idpEvent.Agg.InstanceID {
orgId = &idpEvent.Aggregate().ResourceOwner
}
gitlabSelfHosted, err := p.idpRepo.GetGitlabSelfHosting(context.Background(), p.idpRepo.IDCondition(idpEvent.ID), idpEvent.Agg.InstanceID, orgId)
if err != nil {
return nil, err
}
columns := make([]handler.Column, 0, 7)
reduceIDPRelationalChangedTemplateColumns(idpEvent.Name, idpEvent.OptionChanges, &columns)
payload := &gitlabSelfHosted.GitlabSelfHosting
payloadChanged := reduceGitLabSelfHostedIDPRelationalChangedColumns(payload, &idpEvent)
if payloadChanged {
payload, err := json.Marshal(payload)
if err != nil {
return nil, err
}
columns = append(columns, handler.NewCol(IDPRelationalPayloadCol, payload))
}
return handler.NewMultiStatement(
&idpEvent,
handler.AddUpdateStatement(
columns,
[]handler.Condition{
handler.NewCond(IDPTemplateIDCol, idpEvent.ID),
handler.NewCond(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
handler.NewCond(IDPRelationalOrgId, orgId),
},
),
), nil
// ops := make([]func(eventstore.Event) handler.Exec, 0, 2)
// ops = append(ops,
// handler.AddUpdateStatement(
// reduceIDPChangedTemplateColumns(idpEvent.Name, idpEvent.CreationDate(), idpEvent.Sequence(), idpEvent.OptionChanges),
// []handler.Condition{
// handler.NewCond(IDPTemplateIDCol, idpEvent.ID),
// handler.NewCond(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
// },
// ),
// )
// gitlabCols := reduceGitLabSelfHostedIDPRelationalChangedColumns(idpEvent)
// if len(gitlabCols) > 0 {
// ops = append(ops,
// handler.AddUpdateStatement(
// gitlabCols,
// []handler.Condition{
// handler.NewCond(GitLabSelfHostedIDCol, idpEvent.ID),
// handler.NewCond(GitLabSelfHostedInstanceIDCol, idpEvent.Aggregate().InstanceID),
// },
// handler.WithTableSuffix(IDPTemplateGitLabSelfHostedSuffix),
// ),
// )
// }
// return handler.NewMultiStatement(
// &idpEvent,
// ops...,
// ), nil
}
2025-07-25 17:06:18 +01:00
func (p *idpTemplateRelationalProjection) reduceGoogleIDPRelationalAdded(event eventstore.Event) (*handler.Statement, error) {
var idpEvent idp.GoogleIDPAddedEvent
switch e := event.(type) {
case *org.GoogleIDPAddedEvent:
idpEvent = e.GoogleIDPAddedEvent
case *instance.GoogleIDPAddedEvent:
idpEvent = e.GoogleIDPAddedEvent
default:
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-Yp9ihb", "reduce.wrong.event.type %v", []eventstore.EventType{org.GoogleIDPAddedEventType, instance.GoogleIDPAddedEventType})
}
// idpEvent, ok := event.(*instance.GoogleIDPAddedEvent)
// if !ok {
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-ap9ihb", "reduce.wrong.event.type %v", []eventstore.EventType{org.GoogleIDPAddedEventType, instance.GoogleIDPAddedEventType})
// }
2025-07-25 17:06:18 +01:00
google := db_domain.Google{
ClientID: idpEvent.ClientID,
ClientSecret: idpEvent.ClientSecret,
Scopes: idpEvent.Scopes,
}
2025-07-25 17:06:18 +01:00
payload, err := json.Marshal(google)
if err != nil {
return nil, err
}
2025-07-25 17:06:18 +01:00
var orgId *string
if idpEvent.Aggregate().ResourceOwner != idpEvent.Agg.InstanceID {
orgId = &idpEvent.Aggregate().ResourceOwner
}
return handler.NewMultiStatement(
&idpEvent,
handler.AddCreateStatement(
[]handler.Column{
handler.NewCol(IDPTemplateIDCol, idpEvent.ID),
handler.NewCol(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
handler.NewCol(IDPRelationalOrgId, orgId),
handler.NewCol(IDPTemplateNameCol, idpEvent.Name),
handler.NewCol(IDPTemplateTypeCol, db_domain.IDPTypeGoogle.String()),
handler.NewCol(IDPTemplateStateCol, db_domain.IDPStateActive.String()),
handler.NewCol(IDPRelationalAllowCreationCol, idpEvent.IsCreationAllowed),
handler.NewCol(IDPRelationalAllowLinkingCol, idpEvent.IsLinkingAllowed),
handler.NewCol(IDPRelationalAllowAutoCreationCol, idpEvent.IsAutoCreation),
handler.NewCol(IDPRelationalAllowAutoUpdateCol, idpEvent.IsAutoUpdate),
handler.NewCol(IDPRelationalAllowAutoLinkingCol, db_domain.IDPAutoLinkingOption(idpEvent.AutoLinkingOption).String()),
handler.NewCol(CreatedAt, idpEvent.CreationDate()),
handler.NewCol(IDPRelationalPayloadCol, payload),
},
),
), nil
}
2025-07-25 17:06:18 +01:00
func (p *idpTemplateRelationalProjection) reduceGoogleIDPRelationalChanged(event eventstore.Event) (*handler.Statement, error) {
var idpEvent idp.GoogleIDPChangedEvent
switch e := event.(type) {
case *org.GoogleIDPChangedEvent:
idpEvent = e.GoogleIDPChangedEvent
case *instance.GoogleIDPChangedEvent:
idpEvent = e.GoogleIDPChangedEvent
default:
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-Y1582ks", "reduce.wrong.event.type %v", []eventstore.EventType{org.GoogleIDPChangedEventType, instance.GoogleIDPChangedEventType})
}
// idpEvent, ok := event.(*instance.GoogleIDPChangedEvent)
// if !ok {
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-p1582ks", "reduce.wrong.event.type %v", []eventstore.EventType{org.GoogleIDPChangedEventType, instance.GoogleIDPChangedEventType})
// }
var orgId *string
if idpEvent.Aggregate().ResourceOwner != idpEvent.Agg.InstanceID {
orgId = &idpEvent.Aggregate().ResourceOwner
}
2025-07-25 17:06:18 +01:00
oauth, err := p.idpRepo.GetGoogle(context.Background(), p.idpRepo.IDCondition(idpEvent.ID), idpEvent.Agg.InstanceID, orgId)
if err != nil {
return nil, err
}
2025-07-25 17:06:18 +01:00
columns := make([]handler.Column, 0, 7)
reduceIDPRelationalChangedTemplateColumns(idpEvent.Name, idpEvent.OptionChanges, &columns)
2025-07-25 17:06:18 +01:00
payload := &oauth.Google
payloadChanged := reduceGoogleIDPRelationalChangedColumns(payload, &idpEvent)
if payloadChanged {
payload, err := json.Marshal(payload)
if err != nil {
return nil, err
}
columns = append(columns, handler.NewCol(IDPRelationalPayloadCol, payload))
}
return handler.NewMultiStatement(
&idpEvent,
handler.AddUpdateStatement(
columns,
[]handler.Condition{
handler.NewCond(IDPTemplateIDCol, idpEvent.ID),
handler.NewCond(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
handler.NewCond(IDPRelationalOrgId, orgId),
},
),
), nil
}
func (p *idpTemplateRelationalProjection) reduceLDAPIDPAdded(event eventstore.Event) (*handler.Statement, error) {
var idpEvent idp.LDAPIDPAddedEvent
switch e := event.(type) {
case *org.LDAPIDPAddedEvent:
idpEvent = e.LDAPIDPAddedEvent
case *instance.LDAPIDPAddedEvent:
idpEvent = e.LDAPIDPAddedEvent
default:
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-9s02m1", "reduce.wrong.event.type %v", []eventstore.EventType{org.LDAPIDPAddedEventType, instance.LDAPIDPAddedEventType})
}
ldap := db_domain.LDAP{
Servers: idpEvent.Servers,
StartTLS: idpEvent.StartTLS,
BaseDN: idpEvent.BaseDN,
BindDN: idpEvent.BindDN,
BindPassword: idpEvent.BindPassword,
UserBase: idpEvent.UserBase,
UserObjectClasses: idpEvent.UserObjectClasses,
UserFilters: idpEvent.UserFilters,
Timeout: idpEvent.Timeout,
LDAPAttributes: db_domain.LDAPAttributes{
IDAttribute: idpEvent.IDAttribute,
FirstNameAttribute: idpEvent.FirstNameAttribute,
LastNameAttribute: idpEvent.LastNameAttribute,
DisplayNameAttribute: idpEvent.DisplayNameAttribute,
NickNameAttribute: idpEvent.NickNameAttribute,
PreferredUsernameAttribute: idpEvent.PreferredUsernameAttribute,
EmailAttribute: idpEvent.EmailAttribute,
EmailVerifiedAttribute: idpEvent.EmailVerifiedAttribute,
PhoneAttribute: idpEvent.PhoneAttribute,
PhoneVerifiedAttribute: idpEvent.PhoneVerifiedAttribute,
PreferredLanguageAttribute: idpEvent.PreferredLanguageAttribute,
AvatarURLAttribute: idpEvent.AvatarURLAttribute,
ProfileAttribute: idpEvent.ProfileAttribute,
},
}
payload, err := json.Marshal(ldap)
if err != nil {
return nil, err
}
var orgId *string
if idpEvent.Aggregate().ResourceOwner != idpEvent.Agg.InstanceID {
orgId = &idpEvent.Aggregate().ResourceOwner
}
return handler.NewMultiStatement(
&idpEvent,
handler.AddCreateStatement(
[]handler.Column{
handler.NewCol(IDPTemplateIDCol, idpEvent.ID),
handler.NewCol(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
handler.NewCol(IDPRelationalOrgId, orgId),
handler.NewCol(IDPTemplateNameCol, idpEvent.Name),
handler.NewCol(IDPTemplateTypeCol, db_domain.IDPTypeLDAP.String()),
handler.NewCol(IDPTemplateStateCol, db_domain.IDPStateActive.String()),
handler.NewCol(IDPRelationalAllowCreationCol, idpEvent.IsCreationAllowed),
handler.NewCol(IDPRelationalAllowLinkingCol, idpEvent.IsLinkingAllowed),
handler.NewCol(IDPRelationalAllowAutoCreationCol, idpEvent.IsAutoCreation),
handler.NewCol(IDPRelationalAllowAutoUpdateCol, idpEvent.IsAutoUpdate),
handler.NewCol(IDPRelationalAllowAutoLinkingCol, db_domain.IDPAutoLinkingOption(idpEvent.AutoLinkingOption).String()),
handler.NewCol(CreatedAt, idpEvent.CreationDate()),
handler.NewCol(IDPRelationalPayloadCol, payload),
},
),
), nil
}
func (p *idpTemplateRelationalProjection) reduceLDAPIDPChanged(event eventstore.Event) (*handler.Statement, error) {
var idpEvent idp.LDAPIDPChangedEvent
switch e := event.(type) {
case *org.LDAPIDPChangedEvent:
idpEvent = e.LDAPIDPChangedEvent
case *instance.LDAPIDPChangedEvent:
idpEvent = e.LDAPIDPChangedEvent
default:
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-p1582ks", "reduce.wrong.event.type %v", []eventstore.EventType{org.LDAPIDPChangedEventType, instance.LDAPIDPChangedEventType})
}
var orgId *string
if idpEvent.Aggregate().ResourceOwner != idpEvent.Agg.InstanceID {
orgId = &idpEvent.Aggregate().ResourceOwner
}
oauth, err := p.idpRepo.GetLDAP(context.Background(), p.idpRepo.IDCondition(idpEvent.ID), idpEvent.Agg.InstanceID, orgId)
if err != nil {
return nil, err
}
columns := make([]handler.Column, 0, 7)
reduceIDPRelationalChangedTemplateColumns(idpEvent.Name, idpEvent.OptionChanges, &columns)
payload := &oauth.LDAP
payloadChanged := reduceLDAPIDPRelationalChangedColumns(payload, &idpEvent)
if payloadChanged {
payload, err := json.Marshal(payload)
if err != nil {
return nil, err
}
columns = append(columns, handler.NewCol(IDPRelationalPayloadCol, payload))
}
return handler.NewMultiStatement(
&idpEvent,
handler.AddUpdateStatement(
columns,
[]handler.Condition{
handler.NewCond(IDPTemplateIDCol, idpEvent.ID),
handler.NewCond(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
handler.NewCond(IDPRelationalOrgId, orgId),
},
),
), nil
// ops := make([]func(eventstore.Event) handler.Exec, 0, 2)
// ops = append(ops,
// handler.AddUpdateStatement(
// reduceIDPChangedTemplateColumns(idpEvent.Name, idpEvent.CreationDate(), idpEvent.Sequence(), idpEvent.OptionChanges),
// []handler.Condition{
// handler.NewCond(IDPTemplateIDCol, idpEvent.ID),
// handler.NewCond(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
// },
// ),
// )
// ldapCols := reduceLDAPIDPChangedColumns(idpEvent)
// if len(ldapCols) > 0 {
// ops = append(ops,
// handler.AddUpdateStatement(
// ldapCols,
// []handler.Condition{
// handler.NewCond(LDAPIDCol, idpEvent.ID),
// handler.NewCond(LDAPInstanceIDCol, idpEvent.Aggregate().InstanceID),
// },
// handler.WithTableSuffix(IDPTemplateLDAPSuffix),
// ),
// )
// }
// return handler.NewMultiStatement(
// &idpEvent,
// ops...,
// ), nil
}
2025-07-25 17:06:18 +01:00
func (p *idpTemplateRelationalProjection) reduceAppleIDPAdded(event eventstore.Event) (*handler.Statement, error) {
var idpEvent idp.AppleIDPAddedEvent
switch e := event.(type) {
case *org.AppleIDPAddedEvent:
idpEvent = e.AppleIDPAddedEvent
case *instance.AppleIDPAddedEvent:
idpEvent = e.AppleIDPAddedEvent
default:
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-YFvg3", "reduce.wrong.event.type %v", []eventstore.EventType{org.AppleIDPAddedEventType /*, instance.AppleIDPAddedEventType*/})
}
2025-07-25 17:06:18 +01:00
apple := db_domain.Apple{
ClientID: idpEvent.ClientID,
TeamID: idpEvent.TeamID,
KeyID: idpEvent.KeyID,
PrivateKey: idpEvent.PrivateKey,
Scopes: idpEvent.Scopes,
}
2025-07-25 17:06:18 +01:00
payload, err := json.Marshal(apple)
if err != nil {
return nil, err
}
2025-07-25 17:06:18 +01:00
var orgId *string
if idpEvent.Aggregate().ResourceOwner != idpEvent.Agg.InstanceID {
orgId = &idpEvent.Aggregate().ResourceOwner
}
2025-07-25 17:06:18 +01:00
return handler.NewMultiStatement(
&idpEvent,
handler.AddCreateStatement(
[]handler.Column{
handler.NewCol(IDPTemplateIDCol, idpEvent.ID),
handler.NewCol(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
handler.NewCol(IDPRelationalOrgId, orgId),
handler.NewCol(IDPTemplateNameCol, idpEvent.Name),
handler.NewCol(IDPTemplateTypeCol, db_domain.IDPTypeApple.String()),
handler.NewCol(IDPTemplateStateCol, db_domain.IDPStateActive.String()),
handler.NewCol(IDPRelationalAllowCreationCol, idpEvent.IsCreationAllowed),
handler.NewCol(IDPRelationalAllowLinkingCol, idpEvent.IsLinkingAllowed),
handler.NewCol(IDPRelationalAllowAutoCreationCol, idpEvent.IsAutoCreation),
handler.NewCol(IDPRelationalAllowAutoUpdateCol, idpEvent.IsAutoUpdate),
handler.NewCol(IDPRelationalAllowAutoLinkingCol, db_domain.IDPAutoLinkingOption(idpEvent.AutoLinkingOption).String()),
handler.NewCol(CreatedAt, idpEvent.CreationDate()),
handler.NewCol(IDPRelationalPayloadCol, payload),
},
),
), nil
}
2025-07-25 17:06:18 +01:00
func (p *idpTemplateRelationalProjection) reduceAppleIDPChanged(event eventstore.Event) (*handler.Statement, error) {
var idpEvent idp.AppleIDPChangedEvent
switch e := event.(type) {
case *org.AppleIDPChangedEvent:
idpEvent = e.AppleIDPChangedEvent
case *instance.AppleIDPChangedEvent:
idpEvent = e.AppleIDPChangedEvent
default:
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-YBez3", "reduce.wrong.event.type %v", []eventstore.EventType{org.AppleIDPChangedEventType /*, instance.AppleIDPChangedEventType*/})
}
2025-07-25 17:06:18 +01:00
var orgId *string
if idpEvent.Aggregate().ResourceOwner != idpEvent.Agg.InstanceID {
orgId = &idpEvent.Aggregate().ResourceOwner
}
2025-07-25 17:06:18 +01:00
apple, err := p.idpRepo.GetApple(context.Background(), p.idpRepo.IDCondition(idpEvent.ID), idpEvent.Agg.InstanceID, orgId)
if err != nil {
return nil, err
}
2025-07-25 17:06:18 +01:00
columns := make([]handler.Column, 0, 7)
reduceIDPRelationalChangedTemplateColumns(idpEvent.Name, idpEvent.OptionChanges, &columns)
2025-07-25 17:06:18 +01:00
payload := &apple.Apple
payloadChanged := reduceAppleIDPRelationalChangedColumns(payload, &idpEvent)
if payloadChanged {
payload, err := json.Marshal(payload)
if err != nil {
return nil, err
}
columns = append(columns, handler.NewCol(IDPRelationalPayloadCol, payload))
}
2025-07-25 17:06:18 +01:00
return handler.NewMultiStatement(
&idpEvent,
handler.AddUpdateStatement(
columns,
[]handler.Condition{
handler.NewCond(IDPTemplateIDCol, idpEvent.ID),
handler.NewCond(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
handler.NewCond(IDPRelationalOrgId, orgId),
},
),
), nil
}
2025-07-25 17:06:18 +01:00
func (p *idpTemplateRelationalProjection) reduceSAMLIDPAdded(event eventstore.Event) (*handler.Statement, error) {
var idpEvent idp.SAMLIDPAddedEvent
switch e := event.(type) {
case *org.SAMLIDPAddedEvent:
idpEvent = e.SAMLIDPAddedEvent
case *instance.SAMLIDPAddedEvent:
idpEvent = e.SAMLIDPAddedEvent
default:
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-Ys02m1", "reduce.wrong.event.type %v", []eventstore.EventType{org.SAMLIDPAddedEventType, instance.SAMLIDPAddedEventType})
}
fmt.Printf("@@ >>>>>>>>>>>>>>>>>>>>>>>>>>>> idpEvent.NameIDFormat = %+v\n", idpEvent.NameIDFormat)
saml := db_domain.SAML{
Metadata: idpEvent.Metadata,
Key: idpEvent.Key,
Certificate: idpEvent.Certificate,
Binding: idpEvent.Binding,
WithSignedRequest: idpEvent.WithSignedRequest,
NameIDFormat: idpEvent.NameIDFormat,
TransientMappingAttributeName: idpEvent.TransientMappingAttributeName,
FederatedLogoutEnabled: idpEvent.FederatedLogoutEnabled,
}
payload, err := json.Marshal(saml)
if err != nil {
return nil, err
}
var orgId *string
if idpEvent.Aggregate().ResourceOwner != idpEvent.Agg.InstanceID {
orgId = &idpEvent.Aggregate().ResourceOwner
}
return handler.NewMultiStatement(
&idpEvent,
handler.AddCreateStatement(
[]handler.Column{
handler.NewCol(IDPTemplateIDCol, idpEvent.ID),
handler.NewCol(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
handler.NewCol(IDPRelationalOrgId, orgId),
handler.NewCol(IDPTemplateNameCol, idpEvent.Name),
handler.NewCol(IDPTemplateTypeCol, db_domain.IDPTypeSAML.String()),
handler.NewCol(IDPTemplateStateCol, db_domain.IDPStateActive.String()),
handler.NewCol(IDPRelationalAllowCreationCol, idpEvent.IsCreationAllowed),
handler.NewCol(IDPRelationalAllowLinkingCol, idpEvent.IsLinkingAllowed),
handler.NewCol(IDPRelationalAllowAutoCreationCol, idpEvent.IsAutoCreation),
handler.NewCol(IDPRelationalAllowAutoUpdateCol, idpEvent.IsAutoUpdate),
handler.NewCol(IDPRelationalAllowAutoLinkingCol, db_domain.IDPAutoLinkingOption(idpEvent.AutoLinkingOption).String()),
handler.NewCol(CreatedAt, idpEvent.CreationDate()),
handler.NewCol(IDPRelationalPayloadCol, payload),
},
),
), nil
}
func (p *idpTemplateRelationalProjection) reduceSAMLIDPChanged(event eventstore.Event) (*handler.Statement, error) {
var idpEvent idp.SAMLIDPChangedEvent
switch e := event.(type) {
case *org.SAMLIDPChangedEvent:
idpEvent = e.SAMLIDPChangedEvent
case *instance.SAMLIDPChangedEvent:
idpEvent = e.SAMLIDPChangedEvent
default:
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-Y7c0fii4ad", "reduce.wrong.event.type %v", []eventstore.EventType{org.SAMLIDPChangedEventType, instance.SAMLIDPChangedEventType})
}
var orgId *string
if idpEvent.Aggregate().ResourceOwner != idpEvent.Agg.InstanceID {
orgId = &idpEvent.Aggregate().ResourceOwner
}
saml, err := p.idpRepo.GetSAML(context.Background(), p.idpRepo.IDCondition(idpEvent.ID), idpEvent.Agg.InstanceID, orgId)
if err != nil {
return nil, err
}
columns := make([]handler.Column, 0, 7)
reduceIDPRelationalChangedTemplateColumns(idpEvent.Name, idpEvent.OptionChanges, &columns)
payload := &saml.SAML
payloadChanged := reduceSAMLIDPRelationalChangedColumns(payload, &idpEvent)
if payloadChanged {
payload, err := json.Marshal(payload)
if err != nil {
return nil, err
}
columns = append(columns, handler.NewCol(IDPRelationalPayloadCol, payload))
}
return handler.NewMultiStatement(
&idpEvent,
handler.AddUpdateStatement(
columns,
[]handler.Condition{
handler.NewCond(IDPTemplateIDCol, idpEvent.ID),
handler.NewCond(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
handler.NewCond(IDPRelationalOrgId, orgId),
},
),
), nil
// ops := make([]func(eventstore.Event) handler.Exec, 0, 2)
// ops = append(ops,
// handler.AddUpdateStatement(
// reduceIDPChangedTemplateColumns(idpEvent.Name, idpEvent.CreationDate(), idpEvent.Sequence(), idpEvent.OptionChanges),
// []handler.Condition{
// handler.NewCond(IDPTemplateIDCol, idpEvent.ID),
// handler.NewCond(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
// },
// ),
// )
// if len(SAMLCols) > 0 {
// ops = append(ops,
// handler.AddUpdateStatement(
// SAMLCols,
// []handler.Condition{
// handler.NewCond(SAMLIDCol, idpEvent.ID),
// handler.NewCond(SAMLInstanceIDCol, idpEvent.Aggregate().InstanceID),
// },
// handler.WithTableSuffix(IDPTemplateSAMLSuffix),
// ),
// )
// }
// return handler.NewMultiStatement(
// &idpEvent,
// ops...,
// ), nil
}
2025-07-25 17:06:18 +01:00
// func (p *idpTemplateProjection) reduceIDPConfigRemoved(event eventstore.Event) (*handler.Statement, error) {
// var idpEvent idpconfig.IDPConfigRemovedEvent
// switch e := event.(type) {
// case *org.IDPConfigRemovedEvent:
// idpEvent = e.IDPConfigRemovedEvent
// case *instance.IDPConfigRemovedEvent:
// idpEvent = e.IDPConfigRemovedEvent
// default:
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-SAFet", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPConfigRemovedEventType, instance.IDPConfigRemovedEventType})
// }
// return handler.NewDeleteStatement(
// &idpEvent,
// []handler.Condition{
// handler.NewCond(IDPTemplateIDCol, idpEvent.ConfigID),
// handler.NewCond(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
// },
// ), nil
// }
func (p *idpTemplateRelationalProjection) reduceIDPRemoved(event eventstore.Event) (*handler.Statement, error) {
var idpEvent idp.RemovedEvent
switch e := event.(type) {
case *org.IDPRemovedEvent:
idpEvent = e.RemovedEvent
case *instance.IDPRemovedEvent:
idpEvent = e.RemovedEvent
default:
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-xbcvwin2", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPRemovedEventType, instance.IDPRemovedEventType})
}
2025-07-25 17:06:18 +01:00
return handler.NewDeleteStatement(
&idpEvent,
[]handler.Condition{
handler.NewCond(IDPTemplateIDCol, idpEvent.ID),
handler.NewCond(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
},
), nil
}
2025-07-25 17:06:18 +01:00
// func (p *idpTemplateProjection) reduceOwnerRemoved(event eventstore.Event) (*handler.Statement, error) {
// e, ok := event.(*org.OrgRemovedEvent)
// if !ok {
// return nil, zerrors.ThrowInvalidArgumentf(nil, "PROJE-Jp0D2K", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
// }
// return handler.NewDeleteStatement(
// e,
// []handler.Condition{
// handler.NewCond(IDPTemplateInstanceIDCol, e.Aggregate().InstanceID),
// handler.NewCond(IDPTemplateResourceOwnerCol, e.Aggregate().ID),
// },
// ), nil
// }
// func reduceIDPChangedTemplateColumns(name *string, creationDate time.Time, sequence uint64, optionChanges idp.OptionChanges) []handler.Column {
// cols := make([]handler.Column, 0, 7)
// if name != nil {
// cols = append(cols, handler.NewCol(IDPTemplateNameCol, *name))
// }
// if optionChanges.IsCreationAllowed != nil {
// cols = append(cols, handler.NewCol(IDPTemplateIsCreationAllowedCol, *optionChanges.IsCreationAllowed))
// }
// if optionChanges.IsLinkingAllowed != nil {
// cols = append(cols, handler.NewCol(IDPTemplateIsLinkingAllowedCol, *optionChanges.IsLinkingAllowed))
// }
// if optionChanges.IsAutoCreation != nil {
// cols = append(cols, handler.NewCol(IDPTemplateIsAutoCreationCol, *optionChanges.IsAutoCreation))
// }
// if optionChanges.IsAutoUpdate != nil {
// cols = append(cols, handler.NewCol(IDPTemplateIsAutoUpdateCol, *optionChanges.IsAutoUpdate))
// }
// if optionChanges.AutoLinkingOption != nil {
// cols = append(cols, handler.NewCol(IDPTemplateAutoLinkingCol, *optionChanges.AutoLinkingOption))
// }
// return append(cols,
// handler.NewCol(IDPTemplateChangeDateCol, creationDate),
// handler.NewCol(IDPTemplateSequenceCol, sequence),
// )
// }
// func reduceOAuthIDPChangedColumns(idpEvent idp.OAuthIDPChangedEvent) []handler.Column {
// oauthCols := make([]handler.Column, 0, 7)
// if idpEvent.ClientID != nil {
// oauthCols = append(oauthCols, handler.NewCol(OAuthClientIDCol, *idpEvent.ClientID))
// }
// if idpEvent.ClientSecret != nil {
// oauthCols = append(oauthCols, handler.NewCol(OAuthClientSecretCol, *idpEvent.ClientSecret))
// }
// if idpEvent.AuthorizationEndpoint != nil {
// oauthCols = append(oauthCols, handler.NewCol(OAuthAuthorizationEndpointCol, *idpEvent.AuthorizationEndpoint))
// }
// if idpEvent.TokenEndpoint != nil {
// oauthCols = append(oauthCols, handler.NewCol(OAuthTokenEndpointCol, *idpEvent.TokenEndpoint))
// }
// if idpEvent.UserEndpoint != nil {
// oauthCols = append(oauthCols, handler.NewCol(OAuthUserEndpointCol, *idpEvent.UserEndpoint))
// }
// if idpEvent.Scopes != nil {
// oauthCols = append(oauthCols, handler.NewCol(OAuthScopesCol, database.TextArray[string](idpEvent.Scopes)))
// }
// if idpEvent.IDAttribute != nil {
// oauthCols = append(oauthCols, handler.NewCol(OAuthIDAttributeCol, *idpEvent.IDAttribute))
// }
// if idpEvent.UsePKCE != nil {
// oauthCols = append(oauthCols, handler.NewCol(OAuthUsePKCECol, *idpEvent.UsePKCE))
// }
// return oauthCols
// }
// func reduceOIDCIDPChangedColumns(idpEvent idp.OIDCIDPChangedEvent) []handler.Column {
// oidcCols := make([]handler.Column, 0, 5)
// if idpEvent.ClientID != nil {
// oidcCols = append(oidcCols, handler.NewCol(OIDCClientIDCol, *idpEvent.ClientID))
// }
// if idpEvent.ClientSecret != nil {
// oidcCols = append(oidcCols, handler.NewCol(OIDCClientSecretCol, *idpEvent.ClientSecret))
// }
// if idpEvent.Issuer != nil {
// oidcCols = append(oidcCols, handler.NewCol(OIDCIssuerCol, *idpEvent.Issuer))
// }
// if idpEvent.Scopes != nil {
// oidcCols = append(oidcCols, handler.NewCol(OIDCScopesCol, database.TextArray[string](idpEvent.Scopes)))
// }
// if idpEvent.IsIDTokenMapping != nil {
// oidcCols = append(oidcCols, handler.NewCol(OIDCIDTokenMappingCol, *idpEvent.IsIDTokenMapping))
// }
// if idpEvent.UsePKCE != nil {
// oidcCols = append(oidcCols, handler.NewCol(OIDCUsePKCECol, *idpEvent.UsePKCE))
// }
// return oidcCols
// }
// func reduceJWTIDPChangedColumns(idpEvent idp.JWTIDPChangedEvent) []handler.Column {
// jwtCols := make([]handler.Column, 0, 4)
// if idpEvent.JWTEndpoint != nil {
// jwtCols = append(jwtCols, handler.NewCol(JWTEndpointCol, *idpEvent.JWTEndpoint))
// }
// if idpEvent.KeysEndpoint != nil {
// jwtCols = append(jwtCols, handler.NewCol(JWTKeysEndpointCol, *idpEvent.KeysEndpoint))
// }
// if idpEvent.HeaderName != nil {
// jwtCols = append(jwtCols, handler.NewCol(JWTHeaderNameCol, *idpEvent.HeaderName))
// }
// if idpEvent.Issuer != nil {
// jwtCols = append(jwtCols, handler.NewCol(JWTIssuerCol, *idpEvent.Issuer))
// }
// return jwtCols
// }
// func reduceAzureADIDPChangedColumns(idpEvent idp.AzureADIDPChangedEvent) []handler.Column {
// azureADCols := make([]handler.Column, 0, 5)
// if idpEvent.ClientID != nil {
// azureADCols = append(azureADCols, handler.NewCol(AzureADClientIDCol, *idpEvent.ClientID))
// }
// if idpEvent.ClientSecret != nil {
// azureADCols = append(azureADCols, handler.NewCol(AzureADClientSecretCol, *idpEvent.ClientSecret))
// }
// if idpEvent.Scopes != nil {
// azureADCols = append(azureADCols, handler.NewCol(AzureADScopesCol, database.TextArray[string](idpEvent.Scopes)))
// }
// if idpEvent.Tenant != nil {
// azureADCols = append(azureADCols, handler.NewCol(AzureADTenantCol, *idpEvent.Tenant))
// }
// if idpEvent.IsEmailVerified != nil {
// azureADCols = append(azureADCols, handler.NewCol(AzureADIsEmailVerified, *idpEvent.IsEmailVerified))
// }
// return azureADCols
// }
// func reduceGitHubIDPChangedColumns(idpEvent idp.GitHubIDPChangedEvent) []handler.Column {
// oauthCols := make([]handler.Column, 0, 3)
// if idpEvent.ClientID != nil {
// oauthCols = append(oauthCols, handler.NewCol(GitHubClientIDCol, *idpEvent.ClientID))
// }
// if idpEvent.ClientSecret != nil {
// oauthCols = append(oauthCols, handler.NewCol(GitHubClientSecretCol, *idpEvent.ClientSecret))
// }
// if idpEvent.Scopes != nil {
// oauthCols = append(oauthCols, handler.NewCol(GitHubScopesCol, database.TextArray[string](idpEvent.Scopes)))
// }
// return oauthCols
// }
// func reduceGitHubEnterpriseIDPChangedColumns(idpEvent idp.GitHubEnterpriseIDPChangedEvent) []handler.Column {
// oauthCols := make([]handler.Column, 0, 6)
// if idpEvent.ClientID != nil {
// oauthCols = append(oauthCols, handler.NewCol(GitHubEnterpriseClientIDCol, *idpEvent.ClientID))
// }
// if idpEvent.ClientSecret != nil {
// oauthCols = append(oauthCols, handler.NewCol(GitHubEnterpriseClientSecretCol, *idpEvent.ClientSecret))
// }
// if idpEvent.AuthorizationEndpoint != nil {
// oauthCols = append(oauthCols, handler.NewCol(GitHubEnterpriseAuthorizationEndpointCol, *idpEvent.AuthorizationEndpoint))
// }
// if idpEvent.TokenEndpoint != nil {
// oauthCols = append(oauthCols, handler.NewCol(GitHubEnterpriseTokenEndpointCol, *idpEvent.TokenEndpoint))
// }
// if idpEvent.UserEndpoint != nil {
// oauthCols = append(oauthCols, handler.NewCol(GitHubEnterpriseUserEndpointCol, *idpEvent.UserEndpoint))
// }
// if idpEvent.Scopes != nil {
// oauthCols = append(oauthCols, handler.NewCol(GitHubEnterpriseScopesCol, database.TextArray[string](idpEvent.Scopes)))
// }
// return oauthCols
// }
// func reduceGitLabIDPChangedColumns(idpEvent idp.GitLabIDPChangedEvent) []handler.Column {
// gitlabCols := make([]handler.Column, 0, 3)
// if idpEvent.ClientID != nil {
// gitlabCols = append(gitlabCols, handler.NewCol(GitLabClientIDCol, *idpEvent.ClientID))
// }
// if idpEvent.ClientSecret != nil {
// gitlabCols = append(gitlabCols, handler.NewCol(GitLabClientSecretCol, *idpEvent.ClientSecret))
// }
// if idpEvent.Scopes != nil {
// gitlabCols = append(gitlabCols, handler.NewCol(GitLabScopesCol, database.TextArray[string](idpEvent.Scopes)))
// }
// return gitlabCols
// }
// func reduceGitLabSelfHostedIDPChangedColumns(idpEvent idp.GitLabSelfHostedIDPChangedEvent) []handler.Column {
// gitlabCols := make([]handler.Column, 0, 4)
// if idpEvent.Issuer != nil {
// gitlabCols = append(gitlabCols, handler.NewCol(GitLabSelfHostedIssuerCol, *idpEvent.Issuer))
// }
// if idpEvent.ClientID != nil {
// gitlabCols = append(gitlabCols, handler.NewCol(GitLabSelfHostedClientIDCol, *idpEvent.ClientID))
// }
// if idpEvent.ClientSecret != nil {
// gitlabCols = append(gitlabCols, handler.NewCol(GitLabSelfHostedClientSecretCol, *idpEvent.ClientSecret))
// }
// if idpEvent.Scopes != nil {
// gitlabCols = append(gitlabCols, handler.NewCol(GitLabSelfHostedScopesCol, database.TextArray[string](idpEvent.Scopes)))
// }
// return gitlabCols
// }
// func reduceGoogleIDPChangedColumns(idpEvent idp.GoogleIDPChangedEvent) []handler.Column {
// googleCols := make([]handler.Column, 0, 3)
// if idpEvent.ClientID != nil {
// googleCols = append(googleCols, handler.NewCol(GoogleClientIDCol, *idpEvent.ClientID))
// }
// if idpEvent.ClientSecret != nil {
// googleCols = append(googleCols, handler.NewCol(GoogleClientSecretCol, *idpEvent.ClientSecret))
// }
// if idpEvent.Scopes != nil {
// googleCols = append(googleCols, handler.NewCol(GoogleScopesCol, database.TextArray[string](idpEvent.Scopes)))
// }
// return googleCols
// }
// func reduceLDAPIDPChangedColumns(idpEvent idp.LDAPIDPChangedEvent) []handler.Column {
// ldapCols := make([]handler.Column, 0, 22)
// if idpEvent.Servers != nil {
// ldapCols = append(ldapCols, handler.NewCol(LDAPServersCol, database.TextArray[string](idpEvent.Servers)))
// }
// if idpEvent.StartTLS != nil {
// ldapCols = append(ldapCols, handler.NewCol(LDAPStartTLSCol, *idpEvent.StartTLS))
// }
// if idpEvent.BaseDN != nil {
// ldapCols = append(ldapCols, handler.NewCol(LDAPBaseDNCol, *idpEvent.BaseDN))
// }
// if idpEvent.BindDN != nil {
// ldapCols = append(ldapCols, handler.NewCol(LDAPBindDNCol, *idpEvent.BindDN))
// }
// if idpEvent.BindPassword != nil {
// ldapCols = append(ldapCols, handler.NewCol(LDAPBindPasswordCol, idpEvent.BindPassword))
// }
// if idpEvent.UserBase != nil {
// ldapCols = append(ldapCols, handler.NewCol(LDAPUserBaseCol, *idpEvent.UserBase))
// }
// if idpEvent.UserObjectClasses != nil {
// ldapCols = append(ldapCols, handler.NewCol(LDAPUserObjectClassesCol, database.TextArray[string](idpEvent.UserObjectClasses)))
// }
// if idpEvent.UserFilters != nil {
// ldapCols = append(ldapCols, handler.NewCol(LDAPUserFiltersCol, database.TextArray[string](idpEvent.UserFilters)))
// }
// if idpEvent.Timeout != nil {
// ldapCols = append(ldapCols, handler.NewCol(LDAPTimeoutCol, *idpEvent.Timeout))
// }
// if idpEvent.RootCA != nil {
// ldapCols = append(ldapCols, handler.NewCol(LDAPRootCACol, idpEvent.RootCA))
// }
// if idpEvent.IDAttribute != nil {
// ldapCols = append(ldapCols, handler.NewCol(LDAPIDAttributeCol, *idpEvent.IDAttribute))
// }
// if idpEvent.FirstNameAttribute != nil {
// ldapCols = append(ldapCols, handler.NewCol(LDAPFirstNameAttributeCol, *idpEvent.FirstNameAttribute))
// }
// if idpEvent.LastNameAttribute != nil {
// ldapCols = append(ldapCols, handler.NewCol(LDAPLastNameAttributeCol, *idpEvent.LastNameAttribute))
// }
// if idpEvent.DisplayNameAttribute != nil {
// ldapCols = append(ldapCols, handler.NewCol(LDAPDisplayNameAttributeCol, *idpEvent.DisplayNameAttribute))
// }
// if idpEvent.NickNameAttribute != nil {
// ldapCols = append(ldapCols, handler.NewCol(LDAPNickNameAttributeCol, *idpEvent.NickNameAttribute))
// }
// if idpEvent.PreferredUsernameAttribute != nil {
// ldapCols = append(ldapCols, handler.NewCol(LDAPPreferredUsernameAttributeCol, *idpEvent.PreferredUsernameAttribute))
// }
// if idpEvent.EmailAttribute != nil {
// ldapCols = append(ldapCols, handler.NewCol(LDAPEmailAttributeCol, *idpEvent.EmailAttribute))
// }
// if idpEvent.EmailVerifiedAttribute != nil {
// ldapCols = append(ldapCols, handler.NewCol(LDAPEmailVerifiedAttributeCol, *idpEvent.EmailVerifiedAttribute))
// }
// if idpEvent.PhoneAttribute != nil {
// ldapCols = append(ldapCols, handler.NewCol(LDAPPhoneAttributeCol, *idpEvent.PhoneAttribute))
// }
// if idpEvent.PhoneVerifiedAttribute != nil {
// ldapCols = append(ldapCols, handler.NewCol(LDAPPhoneVerifiedAttributeCol, *idpEvent.PhoneVerifiedAttribute))
// }
// if idpEvent.PreferredLanguageAttribute != nil {
// ldapCols = append(ldapCols, handler.NewCol(LDAPPreferredLanguageAttributeCol, *idpEvent.PreferredLanguageAttribute))
// }
// if idpEvent.AvatarURLAttribute != nil {
// ldapCols = append(ldapCols, handler.NewCol(LDAPAvatarURLAttributeCol, *idpEvent.AvatarURLAttribute))
// }
// if idpEvent.ProfileAttribute != nil {
// ldapCols = append(ldapCols, handler.NewCol(LDAPProfileAttributeCol, *idpEvent.ProfileAttribute))
// }
// return ldapCols
// }
// func reduceAppleIDPChangedColumns(idpEvent idp.AppleIDPChangedEvent) []handler.Column {
// appleCols := make([]handler.Column, 0, 5)
// if idpEvent.ClientID != nil {
// appleCols = append(appleCols, handler.NewCol(AppleClientIDCol, *idpEvent.ClientID))
// }
// if idpEvent.TeamID != nil {
// appleCols = append(appleCols, handler.NewCol(AppleTeamIDCol, *idpEvent.TeamID))
// }
// if idpEvent.KeyID != nil {
// appleCols = append(appleCols, handler.NewCol(AppleKeyIDCol, *idpEvent.KeyID))
// }
// if idpEvent.PrivateKey != nil {
// appleCols = append(appleCols, handler.NewCol(ApplePrivateKeyCol, *idpEvent.PrivateKey))
// }
// if idpEvent.Scopes != nil {
// appleCols = append(appleCols, handler.NewCol(AppleScopesCol, database.TextArray[string](idpEvent.Scopes)))
// }
// return appleCols
// }
// func reduceSAMLIDPChangedColumns(idpEvent idp.SAMLIDPChangedEvent) []handler.Column {
// SAMLCols := make([]handler.Column, 0, 5)
// if idpEvent.Metadata != nil {
// SAMLCols = append(SAMLCols, handler.NewCol(SAMLMetadataCol, idpEvent.Metadata))
// }
// if idpEvent.Key != nil {
// SAMLCols = append(SAMLCols, handler.NewCol(SAMLKeyCol, idpEvent.Key))
// }
// if idpEvent.Certificate != nil {
// SAMLCols = append(SAMLCols, handler.NewCol(SAMLCertificateCol, idpEvent.Certificate))
// }
// if idpEvent.Binding != nil {
// SAMLCols = append(SAMLCols, handler.NewCol(SAMLBindingCol, *idpEvent.Binding))
// }
// if idpEvent.WithSignedRequest != nil {
// SAMLCols = append(SAMLCols, handler.NewCol(SAMLWithSignedRequestCol, *idpEvent.WithSignedRequest))
// }
// if idpEvent.NameIDFormat != nil {
// SAMLCols = append(SAMLCols, handler.NewCol(SAMLNameIDFormatCol, *idpEvent.NameIDFormat))
// }
// if idpEvent.TransientMappingAttributeName != nil {
// SAMLCols = append(SAMLCols, handler.NewCol(SAMLTransientMappingAttributeName, *idpEvent.TransientMappingAttributeName))
// }
// if idpEvent.FederatedLogoutEnabled != nil {
// SAMLCols = append(SAMLCols, handler.NewCol(SAMLFederatedLogoutEnabled, *idpEvent.FederatedLogoutEnabled))
// }
// return SAMLCols
// }
func reduceIDPRelationalChangedTemplateColumns(name *string, optionChanges idp.OptionChanges, cols *[]handler.Column) {
if name != nil {
*cols = append(*cols, handler.NewCol(IDPTemplateNameCol, *name))
}
if optionChanges.IsCreationAllowed != nil {
*cols = append(*cols, handler.NewCol(IDPRelationalAllowCreationCol, *optionChanges.IsCreationAllowed))
}
if optionChanges.IsLinkingAllowed != nil {
*cols = append(*cols, handler.NewCol(IDPRelationalAllowLinkingCol, *optionChanges.IsLinkingAllowed))
}
if optionChanges.IsAutoCreation != nil {
*cols = append(*cols, handler.NewCol(IDPRelationalAllowAutoCreationCol, *optionChanges.IsAutoCreation))
}
if optionChanges.IsAutoUpdate != nil {
*cols = append(*cols, handler.NewCol(IDPRelationalAllowAutoUpdateCol, *optionChanges.IsAutoUpdate))
}
if optionChanges.AutoLinkingOption != nil {
*cols = append(*cols, handler.NewCol(IDPRelationalAllowAutoLinkingCol, db_domain.IDPAutoLinkingOption(*optionChanges.AutoLinkingOption).String()))
}
}
func reduceOAuthIDPRelationalChangedColumns(payload *db_domain.OAuth, idpEvent *idp.OAuthIDPChangedEvent) bool {
payloadChange := false
if idpEvent.ClientID != nil {
payloadChange = true
payload.ClientID = *idpEvent.ClientID
}
if idpEvent.ClientSecret != nil {
payloadChange = true
payload.ClientSecret = idpEvent.ClientSecret
}
if idpEvent.AuthorizationEndpoint != nil {
payloadChange = true
payload.AuthorizationEndpoint = *idpEvent.AuthorizationEndpoint
}
if idpEvent.TokenEndpoint != nil {
payloadChange = true
payload.TokenEndpoint = *idpEvent.TokenEndpoint
}
if idpEvent.UserEndpoint != nil {
payloadChange = true
payload.UserEndpoint = *idpEvent.UserEndpoint
}
if idpEvent.Scopes != nil {
payloadChange = true
payload.Scopes = idpEvent.Scopes
}
if idpEvent.IDAttribute != nil {
payloadChange = true
payload.IDAttribute = *idpEvent.IDAttribute
}
if idpEvent.UsePKCE != nil {
payloadChange = true
payload.UsePKCE = *idpEvent.UsePKCE
}
return payloadChange
}
func reduceOIDCIDPRelationalChangedColumns(payload *db_domain.OIDC, idpEvent *idp.OIDCIDPChangedEvent) bool {
payloadChange := false
if idpEvent.ClientID != nil {
payloadChange = true
payload.ClientID = *idpEvent.ClientID
}
if idpEvent.ClientSecret != nil {
payloadChange = true
payload.ClientSecret = *idpEvent.ClientSecret
}
if idpEvent.Issuer != nil {
payloadChange = true
payload.Issuer = *idpEvent.Issuer
}
if idpEvent.Scopes != nil {
payloadChange = true
payload.Scopes = idpEvent.Scopes
}
if idpEvent.IsIDTokenMapping != nil {
payloadChange = true
payload.IsIDTokenMapping = *idpEvent.IsIDTokenMapping
}
if idpEvent.UsePKCE != nil {
payloadChange = true
payload.UsePKCE = *idpEvent.UsePKCE
}
return payloadChange
}
func reduceJWTIDPRelationalChangedColumns(payload *db_domain.JWT, idpEvent *idp.JWTIDPChangedEvent) bool {
payloadChange := false
if idpEvent.JWTEndpoint != nil {
payloadChange = true
payload.JWTEndpoint = *idpEvent.JWTEndpoint
}
if idpEvent.KeysEndpoint != nil {
payloadChange = true
payload.KeysEndpoint = *idpEvent.KeysEndpoint
}
if idpEvent.HeaderName != nil {
payloadChange = true
payload.HeaderName = *idpEvent.HeaderName
}
if idpEvent.Issuer != nil {
payloadChange = true
payload.Issuer = *idpEvent.Issuer
}
return payloadChange
}
func reduceAzureADIDPRelationalChangedColumns(payload *db_domain.Azure, idpEvent *idp.AzureADIDPChangedEvent) bool {
payloadChange := false
if idpEvent.ClientID != nil {
payloadChange = true
payload.ClientID = *idpEvent.ClientID
}
if idpEvent.ClientSecret != nil {
payloadChange = true
payload.ClientSecret = idpEvent.ClientSecret
}
if idpEvent.Scopes != nil {
payloadChange = true
payload.Scopes = idpEvent.Scopes
}
if idpEvent.Tenant != nil {
payloadChange = true
payload.Tenant = *idpEvent.Tenant
}
if idpEvent.IsEmailVerified != nil {
payloadChange = true
payload.IsEmailVerified = *idpEvent.IsEmailVerified
}
return payloadChange
}
func reduceGitHubIDPRelationalChangedColumns(payload *db_domain.Github, idpEvent *idp.GitHubIDPChangedEvent) bool {
payloadChange := false
if idpEvent.ClientID != nil {
payloadChange = true
payload.ClientID = *idpEvent.ClientID
}
if idpEvent.ClientSecret != nil {
payloadChange = true
payload.ClientSecret = idpEvent.ClientSecret
}
if idpEvent.Scopes != nil {
payloadChange = true
payload.Scopes = idpEvent.Scopes
}
return payloadChange
}
func reduceGitHubEnterpriseIDPRelationalChangedColumns(payload *db_domain.GithubEnterprise, idpEvent *idp.GitHubEnterpriseIDPChangedEvent) bool {
payloadChange := false
if idpEvent.ClientID != nil {
payloadChange = true
payload.ClientID = *idpEvent.ClientID
}
if idpEvent.ClientSecret != nil {
payloadChange = true
payload.ClientSecret = idpEvent.ClientSecret
}
if idpEvent.AuthorizationEndpoint != nil {
payloadChange = true
payload.AuthorizationEndpoint = *idpEvent.AuthorizationEndpoint
}
if idpEvent.TokenEndpoint != nil {
payloadChange = true
payload.TokenEndpoint = *idpEvent.TokenEndpoint
}
if idpEvent.UserEndpoint != nil {
payloadChange = true
payload.UserEndpoint = *idpEvent.UserEndpoint
}
if idpEvent.Scopes != nil {
payloadChange = true
payload.Scopes = idpEvent.Scopes
}
return payloadChange
}
func reduceGitLabIDPRelationalChangedColumns(payload *db_domain.Gitlab, idpEvent *idp.GitLabIDPChangedEvent) bool {
payloadChange := false
if idpEvent.ClientID != nil {
payloadChange = true
payload.ClientID = *idpEvent.ClientID
}
if idpEvent.ClientSecret != nil {
payloadChange = true
payload.ClientSecret = idpEvent.ClientSecret
}
if idpEvent.Scopes != nil {
payloadChange = true
payload.Scopes = idpEvent.Scopes
}
return payloadChange
}
func reduceGitLabSelfHostedIDPRelationalChangedColumns(payload *db_domain.GitlabSelfHosting, idpEvent *idp.GitLabSelfHostedIDPChangedEvent) bool {
payloadChange := false
if idpEvent.ClientID != nil {
payloadChange = true
payload.ClientID = *idpEvent.ClientID
}
if idpEvent.ClientSecret != nil {
payloadChange = true
payload.ClientSecret = idpEvent.ClientSecret
}
if idpEvent.Issuer != nil {
payloadChange = true
payload.Issuer = *idpEvent.Issuer
}
if idpEvent.Scopes != nil {
payloadChange = true
payload.Scopes = idpEvent.Scopes
}
return payloadChange
}
func reduceGoogleIDPRelationalChangedColumns(payload *db_domain.Google, idpEvent *idp.GoogleIDPChangedEvent) bool {
payloadChange := false
if idpEvent.ClientID != nil {
payloadChange = true
payload.ClientID = *idpEvent.ClientID
}
if idpEvent.ClientSecret != nil {
payloadChange = true
payload.ClientSecret = idpEvent.ClientSecret
}
if idpEvent.Scopes != nil {
payloadChange = true
payload.Scopes = idpEvent.Scopes
}
return payloadChange
}
func reduceLDAPIDPRelationalChangedColumns(payload *db_domain.LDAP, idpEvent *idp.LDAPIDPChangedEvent) bool {
payloadChange := false
if idpEvent.Servers != nil {
payloadChange = true
payload.Servers = idpEvent.Servers
}
if idpEvent.StartTLS != nil {
payloadChange = true
payload.StartTLS = *idpEvent.StartTLS
}
if idpEvent.BaseDN != nil {
payloadChange = true
payload.BaseDN = *idpEvent.BaseDN
}
if idpEvent.BindDN != nil {
payloadChange = true
payload.BindDN = *idpEvent.BindDN
}
if idpEvent.BindPassword != nil {
payloadChange = true
payload.BindPassword = idpEvent.BindPassword
}
if idpEvent.UserBase != nil {
payloadChange = true
payload.UserBase = *idpEvent.UserBase
}
if idpEvent.UserObjectClasses != nil {
payloadChange = true
payload.UserObjectClasses = idpEvent.UserObjectClasses
}
if idpEvent.UserFilters != nil {
payloadChange = true
payload.UserFilters = idpEvent.UserFilters
}
if idpEvent.Timeout != nil {
payloadChange = true
payload.Timeout = *idpEvent.Timeout
}
if idpEvent.RootCA != nil {
payloadChange = true
payload.RootCA = idpEvent.RootCA
}
if idpEvent.IDAttribute != nil {
payloadChange = true
payload.IDAttribute = *idpEvent.IDAttribute
}
if idpEvent.FirstNameAttribute != nil {
payloadChange = true
payload.FirstNameAttribute = *idpEvent.FirstNameAttribute
}
if idpEvent.LastNameAttribute != nil {
payloadChange = true
payload.LastNameAttribute = *idpEvent.LastNameAttribute
}
if idpEvent.DisplayNameAttribute != nil {
payloadChange = true
payload.DisplayNameAttribute = *idpEvent.DisplayNameAttribute
}
if idpEvent.NickNameAttribute != nil {
payloadChange = true
payload.NickNameAttribute = *idpEvent.NickNameAttribute
}
if idpEvent.PreferredUsernameAttribute != nil {
payloadChange = true
payload.PreferredUsernameAttribute = *idpEvent.PreferredUsernameAttribute
}
if idpEvent.EmailAttribute != nil {
payloadChange = true
payload.EmailAttribute = *idpEvent.EmailAttribute
}
if idpEvent.EmailVerifiedAttribute != nil {
payloadChange = true
payload.EmailVerifiedAttribute = *idpEvent.EmailVerifiedAttribute
}
if idpEvent.PhoneAttribute != nil {
payloadChange = true
payload.PhoneAttribute = *idpEvent.PhoneAttribute
}
if idpEvent.PhoneVerifiedAttribute != nil {
payloadChange = true
payload.PhoneVerifiedAttribute = *idpEvent.PhoneVerifiedAttribute
}
if idpEvent.PreferredLanguageAttribute != nil {
payloadChange = true
payload.PreferredLanguageAttribute = *idpEvent.PreferredLanguageAttribute
}
if idpEvent.AvatarURLAttribute != nil {
payloadChange = true
payload.AvatarURLAttribute = *idpEvent.AvatarURLAttribute
}
if idpEvent.ProfileAttribute != nil {
payloadChange = true
payload.ProfileAttribute = *idpEvent.ProfileAttribute
}
return payloadChange
}
func reduceAppleIDPRelationalChangedColumns(payload *domain.Apple, idpEvent *idp.AppleIDPChangedEvent) bool {
payloadChange := false
if idpEvent.ClientID != nil {
payloadChange = true
payload.ClientID = *idpEvent.ClientID
}
if idpEvent.TeamID != nil {
payloadChange = true
payload.TeamID = *idpEvent.TeamID
}
if idpEvent.KeyID != nil {
payloadChange = true
payload.KeyID = *idpEvent.KeyID
}
if idpEvent.PrivateKey != nil {
payloadChange = true
payload.PrivateKey = idpEvent.PrivateKey
}
if idpEvent.Scopes != nil {
payloadChange = true
payload.Scopes = idpEvent.Scopes
}
return payloadChange
}
func reduceSAMLIDPRelationalChangedColumns(payload *domain.SAML, idpEvent *idp.SAMLIDPChangedEvent) bool {
payloadChange := false
if idpEvent.Metadata != nil {
payloadChange = true
payload.Metadata = idpEvent.Metadata
fmt.Println("@@ >>>>>>>>>>>>>>>>>>>>>>>>>>>> METTTADATA")
}
if idpEvent.Key != nil {
payloadChange = true
payload.Key = idpEvent.Key
fmt.Println("@@ >>>>>>>>>>>>>>>>>>>>>>>>>>>> KEEEEEEEEEEEEEEY")
}
if idpEvent.Certificate != nil {
payloadChange = true
payload.Certificate = idpEvent.Certificate
}
if idpEvent.Binding != nil {
payloadChange = true
payload.Binding = *idpEvent.Binding
fmt.Println("@@ >>>>>>>>>>>>>>>>>>>>>>>>>>>> BINDING")
}
if idpEvent.WithSignedRequest != nil {
payloadChange = true
payload.WithSignedRequest = *idpEvent.WithSignedRequest
}
if idpEvent.NameIDFormat != nil {
payloadChange = true
payload.NameIDFormat = idpEvent.NameIDFormat
}
if idpEvent.TransientMappingAttributeName != nil {
payloadChange = true
payload.TransientMappingAttributeName = *idpEvent.TransientMappingAttributeName
}
if idpEvent.FederatedLogoutEnabled != nil {
payloadChange = true
payload.FederatedLogoutEnabled = *idpEvent.FederatedLogoutEnabled
}
return payloadChange
}