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 (
"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)

View File

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

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 (
"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
}

View File

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

View File

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

View File

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