add system config (#71)

This commit is contained in:
Fabi 2020-04-23 10:43:39 +02:00 committed by GitHub
parent 8464cfa4fe
commit ff11cdba40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 42 additions and 30 deletions

View File

@ -3,6 +3,7 @@ package main
import ( import (
"context" "context"
"flag" "flag"
sd "github.com/caos/zitadel/internal/config/systemdefaults"
"github.com/caos/logging" "github.com/caos/logging"
@ -26,6 +27,7 @@ type Config struct {
Log logging.Config Log logging.Config
Tracing tracing.TracingConfig Tracing tracing.TracingConfig
AuthZ authz.Config AuthZ authz.Config
SystemDefaults sd.SystemDefaults
} }
func main() { func main() {
@ -44,10 +46,10 @@ func main() {
ctx := context.Background() ctx := context.Background()
if *managementEnabled { if *managementEnabled {
management.Start(ctx, conf.Mgmt, conf.AuthZ) management.Start(ctx, conf.Mgmt, conf.AuthZ, conf.SystemDefaults)
} }
if *authEnabled { if *authEnabled {
auth.Start(ctx, conf.Auth, conf.AuthZ) auth.Start(ctx, conf.Auth, conf.AuthZ, conf.SystemDefaults)
} }
if *loginEnabled { if *loginEnabled {
err = login.Start(ctx, conf.Login) err = login.Start(ctx, conf.Login)

View File

@ -31,13 +31,6 @@ Mgmt:
Type: 'fastcache' Type: 'fastcache'
Config: Config:
MaxCacheSizeInByte: 10485760 #10mb MaxCacheSizeInByte: 10485760 #10mb
PasswordSaltCost: 14
ClientSecretGenerator:
Length: 64
IncludeLowerLetters: true
IncludeUpperLetters: true
IncludeDigits: true
IncludeSymbols: true
Auth: Auth:

View File

@ -0,0 +1,8 @@
SecretGenerators:
PasswordSaltCost: 14
ClientSecretGenerator:
Length: 64
IncludeLowerLetters: true
IncludeUpperLetters: true
IncludeDigits: true
IncludeSymbols: true

View File

@ -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
}

View File

@ -2,8 +2,8 @@ package eventsourcing
import ( import (
"context" "context"
sd "github.com/caos/zitadel/internal/config/systemdefaults"
"github.com/caos/zitadel/internal/crypto"
es_int "github.com/caos/zitadel/internal/eventstore" es_int "github.com/caos/zitadel/internal/eventstore"
es_proj "github.com/caos/zitadel/internal/project/repository/eventsourcing" es_proj "github.com/caos/zitadel/internal/project/repository/eventsourcing"
) )
@ -12,8 +12,6 @@ type Config struct {
Eventstore es_int.Config Eventstore es_int.Config
//View view.ViewConfig //View view.ViewConfig
//Spooler spooler.SpoolerConfig //Spooler spooler.SpoolerConfig
PasswordSaltCost int
ClientSecretGenerator crypto.GeneratorConfig
} }
type EsRepository struct { type EsRepository struct {
@ -21,7 +19,7 @@ type EsRepository struct {
ProjectRepo ProjectRepo
} }
func Start(conf Config) (*EsRepository, error) { func Start(conf Config, systemDefaults sd.SystemDefaults) (*EsRepository, error) {
es, err := es_int.Start(conf.Eventstore) es, err := es_int.Start(conf.Eventstore)
if err != nil { if err != nil {
return nil, err return nil, err
@ -40,9 +38,7 @@ func Start(conf Config) (*EsRepository, error) {
project, err := es_proj.StartProject(es_proj.ProjectConfig{ project, err := es_proj.StartProject(es_proj.ProjectConfig{
Eventstore: es, Eventstore: es,
Cache: conf.Eventstore.Cache, Cache: conf.Eventstore.Cache,
PasswordSaltCost: conf.PasswordSaltCost, }, systemDefaults)
ClientSecretGenerator: conf.ClientSecretGenerator,
})
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -2,6 +2,7 @@ package eventsourcing
import ( import (
"context" "context"
sd "github.com/caos/zitadel/internal/config/systemdefaults"
"github.com/caos/zitadel/internal/project/repository/eventsourcing/model" "github.com/caos/zitadel/internal/project/repository/eventsourcing/model"
"strconv" "strconv"
@ -25,17 +26,15 @@ type ProjectEventstore struct {
type ProjectConfig struct { type ProjectConfig struct {
es_int.Eventstore es_int.Eventstore
Cache *config.CacheConfig Cache *config.CacheConfig
PasswordSaltCost int
ClientSecretGenerator crypto.GeneratorConfig
} }
func StartProject(conf ProjectConfig) (*ProjectEventstore, error) { func StartProject(conf ProjectConfig, systemDefaults sd.SystemDefaults) (*ProjectEventstore, error) {
projectCache, err := StartCache(conf.Cache) projectCache, err := StartCache(conf.Cache)
if err != nil { if err != nil {
return nil, err return nil, err
} }
passwordAlg := crypto.NewBCrypt(conf.PasswordSaltCost) passwordAlg := crypto.NewBCrypt(systemDefaults.SecretGenerator.PasswordSaltCost)
pwGenerator := crypto.NewHashGenerator(conf.ClientSecretGenerator, passwordAlg) pwGenerator := crypto.NewHashGenerator(systemDefaults.SecretGenerator.ClientSecretGenerator, passwordAlg)
idGenerator := sonyflake.NewSonyflake(sonyflake.Settings{}) idGenerator := sonyflake.NewSonyflake(sonyflake.Settings{})
return &ProjectEventstore{ return &ProjectEventstore{
Eventstore: conf.Eventstore, Eventstore: conf.Eventstore,

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"github.com/caos/zitadel/internal/api/auth" "github.com/caos/zitadel/internal/api/auth"
app "github.com/caos/zitadel/internal/auth" app "github.com/caos/zitadel/internal/auth"
sd "github.com/caos/zitadel/internal/config/systemdefaults"
"github.com/caos/zitadel/pkg/auth/api" "github.com/caos/zitadel/pkg/auth/api"
) )
@ -12,6 +13,6 @@ type Config struct {
API api.Config 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) api.Start(ctx, config.API)
} }

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"github.com/caos/logging" "github.com/caos/logging"
"github.com/caos/zitadel/internal/api/auth" "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/internal/management/repository/eventsourcing"
"github.com/caos/zitadel/pkg/management/api" "github.com/caos/zitadel/pkg/management/api"
) )
@ -13,8 +14,8 @@ type Config struct {
API api.Config 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) {
repo, err := eventsourcing.Start(config.Repository) repo, err := eventsourcing.Start(config.Repository, systemDefaults)
logging.Log("MAIN-9uBxp").OnError(err).Panic("unable to start app") logging.Log("MAIN-9uBxp").OnError(err).Panic("unable to start app")
api.Start(ctx, config.API, authZ, repo) api.Start(ctx, config.API, authZ, repo)