From ff11cdba40704f1ac3c5af2a2068a82876c9c0da Mon Sep 17 00:00:00 2001 From: Fabi <38692350+fgerschwiler@users.noreply.github.com> Date: Thu, 23 Apr 2020 10:43:39 +0200 Subject: [PATCH] add system config (#71) --- cmd/zitadel/main.go | 12 +++++++----- cmd/zitadel/startup.yaml | 7 ------- cmd/zitadel/system-defaults.yaml | 8 ++++++++ internal/config/systemdefaults/system_defaults.go | 12 ++++++++++++ .../repository/eventsourcing/repository.go | 14 +++++--------- .../project/repository/eventsourcing/eventstore.go | 11 +++++------ pkg/auth/auth.go | 3 ++- pkg/management/management.go | 5 +++-- 8 files changed, 42 insertions(+), 30 deletions(-) create mode 100644 cmd/zitadel/system-defaults.yaml create mode 100644 internal/config/systemdefaults/system_defaults.go diff --git a/cmd/zitadel/main.go b/cmd/zitadel/main.go index 17c108d930..5d63c2ebc0 100644 --- a/cmd/zitadel/main.go +++ b/cmd/zitadel/main.go @@ -3,6 +3,7 @@ package main import ( "context" "flag" + sd "github.com/caos/zitadel/internal/config/systemdefaults" "github.com/caos/logging" @@ -23,9 +24,10 @@ type Config struct { Admin admin.Config Console console.Config - Log logging.Config - Tracing tracing.TracingConfig - AuthZ authz.Config + Log logging.Config + Tracing tracing.TracingConfig + AuthZ authz.Config + SystemDefaults sd.SystemDefaults } func main() { @@ -44,10 +46,10 @@ func main() { ctx := context.Background() if *managementEnabled { - management.Start(ctx, conf.Mgmt, conf.AuthZ) + management.Start(ctx, conf.Mgmt, conf.AuthZ, conf.SystemDefaults) } if *authEnabled { - auth.Start(ctx, conf.Auth, conf.AuthZ) + auth.Start(ctx, conf.Auth, conf.AuthZ, conf.SystemDefaults) } if *loginEnabled { err = login.Start(ctx, conf.Login) diff --git a/cmd/zitadel/startup.yaml b/cmd/zitadel/startup.yaml index 31cae0bbed..173e7095d0 100644 --- a/cmd/zitadel/startup.yaml +++ b/cmd/zitadel/startup.yaml @@ -31,13 +31,6 @@ Mgmt: Type: 'fastcache' Config: MaxCacheSizeInByte: 10485760 #10mb - PasswordSaltCost: 14 - ClientSecretGenerator: - Length: 64 - IncludeLowerLetters: true - IncludeUpperLetters: true - IncludeDigits: true - IncludeSymbols: true Auth: diff --git a/cmd/zitadel/system-defaults.yaml b/cmd/zitadel/system-defaults.yaml new file mode 100644 index 0000000000..33d9bbf5d2 --- /dev/null +++ b/cmd/zitadel/system-defaults.yaml @@ -0,0 +1,8 @@ +SecretGenerators: + PasswordSaltCost: 14 + ClientSecretGenerator: + Length: 64 + IncludeLowerLetters: true + IncludeUpperLetters: true + IncludeDigits: true + IncludeSymbols: true \ No newline at end of file diff --git a/internal/config/systemdefaults/system_defaults.go b/internal/config/systemdefaults/system_defaults.go new file mode 100644 index 0000000000..8d400a711f --- /dev/null +++ b/internal/config/systemdefaults/system_defaults.go @@ -0,0 +1,12 @@ +package systemdefaults + +import "github.com/caos/zitadel/internal/crypto" + +type SystemDefaults struct { + SecretGenerator SecretGenerator +} + +type SecretGenerator struct { + PasswordSaltCost int + ClientSecretGenerator crypto.GeneratorConfig +} diff --git a/internal/management/repository/eventsourcing/repository.go b/internal/management/repository/eventsourcing/repository.go index a141f749f5..2cc65b3d89 100644 --- a/internal/management/repository/eventsourcing/repository.go +++ b/internal/management/repository/eventsourcing/repository.go @@ -2,8 +2,8 @@ package eventsourcing import ( "context" + sd "github.com/caos/zitadel/internal/config/systemdefaults" - "github.com/caos/zitadel/internal/crypto" es_int "github.com/caos/zitadel/internal/eventstore" es_proj "github.com/caos/zitadel/internal/project/repository/eventsourcing" ) @@ -12,8 +12,6 @@ type Config struct { Eventstore es_int.Config //View view.ViewConfig //Spooler spooler.SpoolerConfig - PasswordSaltCost int - ClientSecretGenerator crypto.GeneratorConfig } type EsRepository struct { @@ -21,7 +19,7 @@ type EsRepository struct { ProjectRepo } -func Start(conf Config) (*EsRepository, error) { +func Start(conf Config, systemDefaults sd.SystemDefaults) (*EsRepository, error) { es, err := es_int.Start(conf.Eventstore) if err != nil { return nil, err @@ -38,11 +36,9 @@ func Start(conf Config) (*EsRepository, error) { //spool := spooler.StartSpooler(conf.Spooler) project, err := es_proj.StartProject(es_proj.ProjectConfig{ - Eventstore: es, - Cache: conf.Eventstore.Cache, - PasswordSaltCost: conf.PasswordSaltCost, - ClientSecretGenerator: conf.ClientSecretGenerator, - }) + Eventstore: es, + Cache: conf.Eventstore.Cache, + }, systemDefaults) if err != nil { return nil, err } diff --git a/internal/project/repository/eventsourcing/eventstore.go b/internal/project/repository/eventsourcing/eventstore.go index 97fb3713cc..66eb1a55a6 100644 --- a/internal/project/repository/eventsourcing/eventstore.go +++ b/internal/project/repository/eventsourcing/eventstore.go @@ -2,6 +2,7 @@ package eventsourcing import ( "context" + sd "github.com/caos/zitadel/internal/config/systemdefaults" "github.com/caos/zitadel/internal/project/repository/eventsourcing/model" "strconv" @@ -24,18 +25,16 @@ type ProjectEventstore struct { type ProjectConfig struct { es_int.Eventstore - Cache *config.CacheConfig - PasswordSaltCost int - ClientSecretGenerator crypto.GeneratorConfig + Cache *config.CacheConfig } -func StartProject(conf ProjectConfig) (*ProjectEventstore, error) { +func StartProject(conf ProjectConfig, systemDefaults sd.SystemDefaults) (*ProjectEventstore, error) { projectCache, err := StartCache(conf.Cache) if err != nil { return nil, err } - passwordAlg := crypto.NewBCrypt(conf.PasswordSaltCost) - pwGenerator := crypto.NewHashGenerator(conf.ClientSecretGenerator, passwordAlg) + passwordAlg := crypto.NewBCrypt(systemDefaults.SecretGenerator.PasswordSaltCost) + pwGenerator := crypto.NewHashGenerator(systemDefaults.SecretGenerator.ClientSecretGenerator, passwordAlg) idGenerator := sonyflake.NewSonyflake(sonyflake.Settings{}) return &ProjectEventstore{ Eventstore: conf.Eventstore, diff --git a/pkg/auth/auth.go b/pkg/auth/auth.go index 5fca24a0d0..42d98871e0 100644 --- a/pkg/auth/auth.go +++ b/pkg/auth/auth.go @@ -4,6 +4,7 @@ import ( "context" "github.com/caos/zitadel/internal/api/auth" app "github.com/caos/zitadel/internal/auth" + sd "github.com/caos/zitadel/internal/config/systemdefaults" "github.com/caos/zitadel/pkg/auth/api" ) @@ -12,6 +13,6 @@ type Config struct { API api.Config } -func Start(ctx context.Context, config Config, authZ auth.Config) { +func Start(ctx context.Context, config Config, authZ auth.Config, systemDefaults sd.SystemDefaults) { api.Start(ctx, config.API) } diff --git a/pkg/management/management.go b/pkg/management/management.go index 3339aaa098..2c8dce65af 100644 --- a/pkg/management/management.go +++ b/pkg/management/management.go @@ -4,6 +4,7 @@ import ( "context" "github.com/caos/logging" "github.com/caos/zitadel/internal/api/auth" + sd "github.com/caos/zitadel/internal/config/systemdefaults" "github.com/caos/zitadel/internal/management/repository/eventsourcing" "github.com/caos/zitadel/pkg/management/api" ) @@ -13,8 +14,8 @@ type Config struct { API api.Config } -func Start(ctx context.Context, config Config, authZ auth.Config) { - repo, err := eventsourcing.Start(config.Repository) +func Start(ctx context.Context, config Config, authZ auth.Config, systemDefaults sd.SystemDefaults) { + repo, err := eventsourcing.Start(config.Repository, systemDefaults) logging.Log("MAIN-9uBxp").OnError(err).Panic("unable to start app") api.Start(ctx, config.API, authZ, repo)