use global id generator (#142)

* use global id generator

* remove duplicate `UserRemoved`

Co-authored-by: Livio Amstutz <[email protected]>
This commit is contained in:
Fabi
2020-05-28 13:28:36 +02:00
committed by GitHub
co-authored by Livio Amstutz
parent 2758bf30b1
commit e3f9e9c05e
18 changed files with 69 additions and 76 deletions
@@ -4,15 +4,14 @@ import (
"github.com/caos/zitadel/internal/cache/config"
sd "github.com/caos/zitadel/internal/config/systemdefaults"
es_int "github.com/caos/zitadel/internal/eventstore"
"github.com/caos/zitadel/internal/id"
"github.com/caos/zitadel/internal/policy"
"github.com/sony/sonyflake"
)
var idGenerator = sonyflake.NewSonyflake(sonyflake.Settings{})
type PolicyEventstore struct {
es_int.Eventstore
policyCache *PolicyCache
idGenerator id.Generator
passwordAgePolicyDefault policy.PasswordAgePolicyDefault
passwordComplexityPolicyDefault policy.PasswordComplexityPolicyDefault
passwordLockoutPolicyDefault policy.PasswordLockoutPolicyDefault
@@ -31,6 +30,7 @@ func StartPolicy(conf PolicyConfig, systemDefaults sd.SystemDefaults) (*PolicyEv
return &PolicyEventstore{
Eventstore: conf.Eventstore,
policyCache: policyCache,
idGenerator: id.SonyFlakeGenerator,
passwordAgePolicyDefault: systemDefaults.DefaultPolicies.Age,
passwordComplexityPolicyDefault: systemDefaults.DefaultPolicies.Complexity,
passwordLockoutPolicyDefault: systemDefaults.DefaultPolicies.Lockout,
@@ -2,8 +2,6 @@ package eventsourcing
import (
"context"
"strconv"
"github.com/caos/zitadel/internal/api/auth"
caos_errs "github.com/caos/zitadel/internal/errors"
es_sdk "github.com/caos/zitadel/internal/eventstore/sdk"
@@ -39,11 +37,11 @@ func (es *PolicyEventstore) CreatePasswordAgePolicy(ctx context.Context, policy
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-yDJ5I", "Policy allready exists")
}
id, err := idGenerator.NextID()
id, err := es.idGenerator.Next()
if err != nil {
return nil, err
}
policy.AggregateID = strconv.FormatUint(id, 10)
policy.AggregateID = id
repoPolicy := PasswordAgePolicyFromModel(policy)
@@ -2,6 +2,7 @@ package eventsourcing
import (
"encoding/json"
"github.com/caos/zitadel/internal/id"
mock_cache "github.com/caos/zitadel/internal/cache/mock"
"github.com/caos/zitadel/internal/eventstore/mock"
@@ -14,6 +15,7 @@ func GetMockedEventstoreAge(ctrl *gomock.Controller, mockEs *mock.MockEventstore
return &PolicyEventstore{
Eventstore: mockEs,
policyCache: GetMockCacheAge(ctrl),
idGenerator: GetSonyFlacke(),
}
}
@@ -24,6 +26,10 @@ func GetMockCacheAge(ctrl *gomock.Controller) *PolicyCache {
return &PolicyCache{policyCache: mockCache}
}
func GetSonyFlacke() id.Generator {
return id.SonyFlakeGenerator
}
func GetMockGetPasswordAgePolicyOK(ctrl *gomock.Controller) *PolicyEventstore {
data, _ := json.Marshal(model.PasswordAgePolicy{Description: "Name"})
events := []*es_models.Event{
@@ -2,8 +2,6 @@ package eventsourcing
import (
"context"
"strconv"
"github.com/caos/zitadel/internal/api/auth"
caos_errs "github.com/caos/zitadel/internal/errors"
es_sdk "github.com/caos/zitadel/internal/eventstore/sdk"
@@ -42,11 +40,11 @@ func (es *PolicyEventstore) CreatePasswordComplexityPolicy(ctx context.Context,
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-yDJ5I", "Policy allready exists")
}
id, err := idGenerator.NextID()
id, err := es.idGenerator.Next()
if err != nil {
return nil, err
}
policy.AggregateID = strconv.FormatUint(id, 10)
policy.AggregateID = id
repoPolicy := PasswordComplexityPolicyFromModel(policy)
@@ -14,6 +14,7 @@ func GetMockedEventstoreComplexity(ctrl *gomock.Controller, mockEs *mock.MockEve
return &PolicyEventstore{
Eventstore: mockEs,
policyCache: GetMockCacheComplexity(ctrl),
idGenerator: GetSonyFlacke(),
}
}
@@ -2,8 +2,6 @@ package eventsourcing
import (
"context"
"strconv"
"github.com/caos/zitadel/internal/api/auth"
caos_errs "github.com/caos/zitadel/internal/errors"
es_sdk "github.com/caos/zitadel/internal/eventstore/sdk"
@@ -39,11 +37,11 @@ func (es *PolicyEventstore) CreatePasswordLockoutPolicy(ctx context.Context, pol
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-yDJ5I", "Policy allready exists")
}
id, err := idGenerator.NextID()
id, err := es.idGenerator.Next()
if err != nil {
return nil, err
}
policy.AggregateID = strconv.FormatUint(id, 10)
policy.AggregateID = id
repoPolicy := PasswordLockoutPolicyFromModel(policy)
@@ -14,6 +14,7 @@ func GetMockedEventstoreLockout(ctrl *gomock.Controller, mockEs *mock.MockEvents
return &PolicyEventstore{
Eventstore: mockEs,
policyCache: GetMockCacheLockout(ctrl),
idGenerator: GetSonyFlacke(),
}
}