From 4b1e79604a8f251aa06a58e44c8f522f7d9bf4e4 Mon Sep 17 00:00:00 2001 From: adlerhurst Date: Thu, 12 Nov 2020 23:15:01 +0100 Subject: [PATCH] new iam repo in all services --- .../eventsourcing/eventstore/iam.go | 10 ++++--- .../repository/eventsourcing/repository.go | 27 +++++++++++++++++-- .../eventsourcing/eventstore/iam.go | 6 ++++- .../repository/eventsourcing/repository.go | 25 +++++++++++++++++ .../eventsourcing/eventstore/iam.go | 8 +----- .../repository/eventsourcing/repository.go | 3 +-- internal/v2/repository/idp/config.go | 1 + 7 files changed, 64 insertions(+), 16 deletions(-) create mode 100644 internal/v2/repository/idp/config.go diff --git a/internal/auth/repository/eventsourcing/eventstore/iam.go b/internal/auth/repository/eventsourcing/eventstore/iam.go index f281310dc4..00b3c8c615 100644 --- a/internal/auth/repository/eventsourcing/eventstore/iam.go +++ b/internal/auth/repository/eventsourcing/eventstore/iam.go @@ -2,15 +2,17 @@ package eventstore import ( "context" + "github.com/caos/zitadel/internal/iam/model" - iam_event "github.com/caos/zitadel/internal/iam/repository/eventsourcing" + iam_business "github.com/caos/zitadel/internal/v2/business/iam" ) type IAMRepository struct { - IAMID string - IAMEvents *iam_event.IAMEventstore + IAMID string + + IAMV2 *iam_business.Repository } func (repo *IAMRepository) GetIAM(ctx context.Context) (*model.IAM, error) { - return repo.IAMEvents.IAMByID(ctx, repo.IAMID) + return repo.IAMV2.IAMByID(ctx, repo.IAMID) } diff --git a/internal/auth/repository/eventsourcing/repository.go b/internal/auth/repository/eventsourcing/repository.go index cb83e00705..09020da708 100644 --- a/internal/auth/repository/eventsourcing/repository.go +++ b/internal/auth/repository/eventsourcing/repository.go @@ -21,6 +21,10 @@ import ( es_org "github.com/caos/zitadel/internal/org/repository/eventsourcing" es_proj "github.com/caos/zitadel/internal/project/repository/eventsourcing" es_user "github.com/caos/zitadel/internal/user/repository/eventsourcing" + iam_business "github.com/caos/zitadel/internal/v2/business/iam" + "github.com/caos/zitadel/internal/v2/repository/iam" + "github.com/caos/zitadel/internal/v2/repository/member" + "github.com/caos/zitadel/internal/v2/repository/policy" ) type Config struct { @@ -51,6 +55,25 @@ func Start(conf Config, authZ authz.Config, systemDefaults sd.SystemDefaults, au if err != nil { return nil, err } + esV2 := es.V2() + esV2.RegisterFilterEventMapper(iam.SetupStartedEventType, iam.SetupStepMapper). + RegisterFilterEventMapper(iam.SetupDoneEventType, iam.SetupStepMapper). + RegisterFilterEventMapper(iam.GlobalOrgSetEventType, iam.GlobalOrgSetMapper). + RegisterFilterEventMapper(iam.ProjectSetEventType, iam.ProjectSetMapper). + RegisterFilterEventMapper(iam.LabelPolicyAddedEventType, policy.LabelPolicyAddedEventMapper). + RegisterFilterEventMapper(iam.LabelPolicyChangedEventType, policy.LabelPolicyChangedEventMapper). + RegisterFilterEventMapper(iam.LoginPolicyAddedEventType, policy.LoginPolicyAddedEventMapper). + RegisterFilterEventMapper(iam.LoginPolicyChangedEventType, policy.LoginPolicyChangedEventMapper). + RegisterFilterEventMapper(iam.OrgIAMPolicyAddedEventType, policy.OrgIAMPolicyAddedEventMapper). + RegisterFilterEventMapper(iam.PasswordAgePolicyAddedEventType, policy.PasswordAgePolicyAddedEventMapper). + RegisterFilterEventMapper(iam.PasswordAgePolicyChangedEventType, policy.PasswordAgePolicyChangedEventMapper). + RegisterFilterEventMapper(iam.PasswordComplexityPolicyAddedEventType, policy.PasswordComplexityPolicyAddedEventMapper). + RegisterFilterEventMapper(iam.PasswordComplexityPolicyChangedEventType, policy.PasswordComplexityPolicyChangedEventMapper). + RegisterFilterEventMapper(iam.PasswordLockoutPolicyAddedEventType, policy.PasswordLockoutPolicyAddedEventMapper). + RegisterFilterEventMapper(iam.PasswordLockoutPolicyChangedEventType, policy.PasswordLockoutPolicyChangedEventMapper). + RegisterFilterEventMapper(iam.MemberAddedEventType, member.AddedEventMapper). + RegisterFilterEventMapper(iam.MemberChangedEventType, member.ChangedEventMapper). + RegisterFilterEventMapper(iam.MemberRemovedEventType, member.RemovedEventMapper) sqlClient, err := conf.View.Start() if err != nil { @@ -176,8 +199,8 @@ func Start(conf Config, authZ authz.Config, systemDefaults sd.SystemDefaults, au SystemDefaults: systemDefaults, }, eventstore.IAMRepository{ - IAMEvents: iam, - IAMID: systemDefaults.IamID, + IAMID: systemDefaults.IamID, + IAMV2: iam_business.StartRepository(&iam_business.Config{Eventstore: esV2}), }, }, nil } diff --git a/internal/authz/repository/eventsourcing/eventstore/iam.go b/internal/authz/repository/eventsourcing/eventstore/iam.go index 48c532e60a..8d2ceabb79 100644 --- a/internal/authz/repository/eventsourcing/eventstore/iam.go +++ b/internal/authz/repository/eventsourcing/eventstore/iam.go @@ -2,13 +2,17 @@ package eventstore import ( "context" + "github.com/caos/zitadel/internal/iam/model" iam_event "github.com/caos/zitadel/internal/iam/repository/eventsourcing" + iam_business "github.com/caos/zitadel/internal/v2/business/iam" ) type IamRepo struct { IAMID string IAMEvents *iam_event.IAMEventstore + + IAMV2 *iam_business.Repository } func (repo *IamRepo) Health(ctx context.Context) error { @@ -16,5 +20,5 @@ func (repo *IamRepo) Health(ctx context.Context) error { } func (repo *IamRepo) IamByID(ctx context.Context) (*model.IAM, error) { - return repo.IAMEvents.IAMByID(ctx, repo.IAMID) + return repo.IAMV2.IAMByID(ctx, repo.IAMID) } diff --git a/internal/authz/repository/eventsourcing/repository.go b/internal/authz/repository/eventsourcing/repository.go index b39ad5e2e8..9b471abe8a 100644 --- a/internal/authz/repository/eventsourcing/repository.go +++ b/internal/authz/repository/eventsourcing/repository.go @@ -2,7 +2,11 @@ package eventsourcing import ( "context" + es_user "github.com/caos/zitadel/internal/user/repository/eventsourcing" + "github.com/caos/zitadel/internal/v2/repository/iam" + "github.com/caos/zitadel/internal/v2/repository/member" + "github.com/caos/zitadel/internal/v2/repository/policy" "github.com/caos/zitadel/internal/api/authz" "github.com/caos/zitadel/internal/auth_request/repository/cache" @@ -18,6 +22,7 @@ import ( "github.com/caos/zitadel/internal/id" es_key "github.com/caos/zitadel/internal/key/repository/eventsourcing" es_proj "github.com/caos/zitadel/internal/project/repository/eventsourcing" + iam_business "github.com/caos/zitadel/internal/v2/business/iam" ) type Config struct { @@ -40,6 +45,25 @@ func Start(conf Config, authZ authz.Config, systemDefaults sd.SystemDefaults) (* if err != nil { return nil, err } + esV2 := es.V2() + esV2.RegisterFilterEventMapper(iam.SetupStartedEventType, iam.SetupStepMapper). + RegisterFilterEventMapper(iam.SetupDoneEventType, iam.SetupStepMapper). + RegisterFilterEventMapper(iam.GlobalOrgSetEventType, iam.GlobalOrgSetMapper). + RegisterFilterEventMapper(iam.ProjectSetEventType, iam.ProjectSetMapper). + RegisterFilterEventMapper(iam.LabelPolicyAddedEventType, policy.LabelPolicyAddedEventMapper). + RegisterFilterEventMapper(iam.LabelPolicyChangedEventType, policy.LabelPolicyChangedEventMapper). + RegisterFilterEventMapper(iam.LoginPolicyAddedEventType, policy.LoginPolicyAddedEventMapper). + RegisterFilterEventMapper(iam.LoginPolicyChangedEventType, policy.LoginPolicyChangedEventMapper). + RegisterFilterEventMapper(iam.OrgIAMPolicyAddedEventType, policy.OrgIAMPolicyAddedEventMapper). + RegisterFilterEventMapper(iam.PasswordAgePolicyAddedEventType, policy.PasswordAgePolicyAddedEventMapper). + RegisterFilterEventMapper(iam.PasswordAgePolicyChangedEventType, policy.PasswordAgePolicyChangedEventMapper). + RegisterFilterEventMapper(iam.PasswordComplexityPolicyAddedEventType, policy.PasswordComplexityPolicyAddedEventMapper). + RegisterFilterEventMapper(iam.PasswordComplexityPolicyChangedEventType, policy.PasswordComplexityPolicyChangedEventMapper). + RegisterFilterEventMapper(iam.PasswordLockoutPolicyAddedEventType, policy.PasswordLockoutPolicyAddedEventMapper). + RegisterFilterEventMapper(iam.PasswordLockoutPolicyChangedEventType, policy.PasswordLockoutPolicyChangedEventMapper). + RegisterFilterEventMapper(iam.MemberAddedEventType, member.AddedEventMapper). + RegisterFilterEventMapper(iam.MemberChangedEventType, member.ChangedEventMapper). + RegisterFilterEventMapper(iam.MemberRemovedEventType, member.RemovedEventMapper) sqlClient, err := conf.View.Start() if err != nil { @@ -90,6 +114,7 @@ func Start(conf Config, authZ authz.Config, systemDefaults sd.SystemDefaults) (* eventstore.IamRepo{ IAMID: systemDefaults.IamID, IAMEvents: iam, + IAMV2: iam_business.StartRepository(&iam_business.Config{Eventstore: esV2}), }, eventstore.TokenVerifierRepo{ //TODO: Add Token Verification Key diff --git a/internal/management/repository/eventsourcing/eventstore/iam.go b/internal/management/repository/eventsourcing/eventstore/iam.go index 0ab06ce403..1dc62fd8a4 100644 --- a/internal/management/repository/eventsourcing/eventstore/iam.go +++ b/internal/management/repository/eventsourcing/eventstore/iam.go @@ -4,19 +4,13 @@ import ( "context" iam_model "github.com/caos/zitadel/internal/iam/model" - "github.com/caos/zitadel/internal/iam/repository/eventsourcing" iam_business "github.com/caos/zitadel/internal/v2/business/iam" ) type IAMRepository struct { - IAMEvents *eventsourcing.IAMEventstore - IAMV2 *iam_business.Repository } func (repo *IAMRepository) IAMByID(ctx context.Context, id string) (*iam_model.IAM, error) { - if repo.IAMV2 != nil { - return repo.IAMV2.IAMByID(ctx, id) - } - return repo.IAMEvents.IAMByID(ctx, id) + return repo.IAMV2.IAMByID(ctx, id) } diff --git a/internal/management/repository/eventsourcing/repository.go b/internal/management/repository/eventsourcing/repository.go index 78b1da3530..73dc2de2cb 100644 --- a/internal/management/repository/eventsourcing/repository.go +++ b/internal/management/repository/eventsourcing/repository.go @@ -115,8 +115,7 @@ func Start(conf Config, systemDefaults sd.SystemDefaults, roles []string) (*EsRe UserRepo: eventstore.UserRepo{es, conf.SearchLimit, user, org, usergrant, view, systemDefaults}, UserGrantRepo: eventstore.UserGrantRepo{conf.SearchLimit, usergrant, view}, IAMRepository: eventstore.IAMRepository{ - IAMEvents: iam, - IAMV2: iam_business.StartRepository(&iam_business.Config{Eventstore: esV2}), + IAMV2: iam_business.StartRepository(&iam_business.Config{Eventstore: esV2}), }, }, nil } diff --git a/internal/v2/repository/idp/config.go b/internal/v2/repository/idp/config.go new file mode 100644 index 0000000000..dbd5a4b201 --- /dev/null +++ b/internal/v2/repository/idp/config.go @@ -0,0 +1 @@ +package idp