sane common configurations

This commit is contained in:
A.Unger
2021-11-11 12:51:57 +01:00
parent 04d8ec86ab
commit aa67106e04
11 changed files with 72 additions and 97 deletions
+14 -4
View File
@@ -63,8 +63,20 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error {
return err
}
// provide with defaults for shared logging, since we need a valid destination address for BindEnv.
if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil {
cfg.Log = &shared.Log{
Level: cfg.Commons.Log.Level,
Pretty: cfg.Commons.Log.Pretty,
Color: cfg.Commons.Log.Color,
File: cfg.Commons.Log.File,
}
} else if cfg.Log == nil && cfg.Commons == nil {
cfg.Log = &shared.Log{}
}
// load all env variables relevant to the config in the current context.
conf.LoadOSEnv(config.GetEnv(), false)
conf.LoadOSEnv(config.GetEnv(cfg), false)
bindings := config.StructMappings(cfg)
return ociscfg.BindEnv(conf, bindings)
@@ -77,9 +89,7 @@ type SutureService struct {
// NewSutureService creates a new accounts.SutureService
func NewSutureService(cfg *ociscfg.Config) suture.Service {
if (cfg.Accounts.Log == shared.Log{}) {
cfg.Accounts.Log = cfg.Log
}
cfg.Accounts.Commons = cfg.Commons
return SutureService{
cfg: cfg.Accounts,
}
+1 -20
View File
@@ -6,10 +6,6 @@ import (
"github.com/owncloud/ocis/ocis-pkg/log"
gofig "github.com/gookit/config/v2"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/shared"
"github.com/owncloud/ocis/ocis-pkg/sync"
"github.com/oklog/run"
@@ -29,8 +25,6 @@ func Server(cfg *config.Config) *cli.Command {
Usage: "Start ocis accounts service",
Description: "uses an LDAP server as the storage backend",
Before: func(ctx *cli.Context) error {
// remember shared logging info to prevent empty overwrites
inLog := cfg.Log
if cfg.HTTP.Root != "/" {
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
}
@@ -41,23 +35,10 @@ func Server(cfg *config.Config) *cli.Command {
return err
}
if (cfg.Log == shared.Log{}) && (inLog != shared.Log{}) {
// set the default to the parent config
cfg.Log = inLog
// and parse the environment
conf := &gofig.Config{}
conf.LoadOSEnv(config.GetEnv(), false)
bindings := config.StructMappings(cfg)
if err := ociscfg.BindEnv(conf, bindings); err != nil {
return err
}
}
return nil
},
Action: func(c *cli.Context) error {
logger := log.LoggerFromConfig("accounts", cfg.Log)
logger := log.LoggerFromConfig("accounts", *cfg.Log)
err := tracing.Configure(cfg)
if err != nil {
return err
+7 -6
View File
@@ -125,12 +125,14 @@ type Tracing struct {
// Config merges all Account config parameters.
type Config struct {
*shared.Commons
LDAP LDAP `mapstructure:"ldap"`
HTTP HTTP `mapstructure:"http"`
GRPC GRPC `mapstructure:"grpc"`
Server Server `mapstructure:"server"`
Asset Asset `mapstructure:"asset"`
Log shared.Log `mapstructure:"log"`
Log *shared.Log `mapstructure:"log"`
TokenManager TokenManager `mapstructure:"token_manager"`
Repo Repo `mapstructure:"repo"`
Index Index `mapstructure:"index"`
@@ -171,7 +173,6 @@ func DefaultConfig() *Config {
DemoUsersAndGroups: true,
},
Asset: Asset{},
Log: shared.Log{},
TokenManager: TokenManager{
JWTSecret: "Pive-Fumkiu4",
},
@@ -212,10 +213,10 @@ func DefaultConfig() *Config {
// GetEnv fetches a list of known env variables for this extension. It is to be used by gookit, as it provides a list
// with all the environment variables an extension supports.
func GetEnv() []string {
var r = make([]string, len(structMappings(&Config{})))
for i := range structMappings(&Config{}) {
r = append(r, structMappings(&Config{})[i].EnvVars...)
func GetEnv(cfg *Config) []string {
var r = make([]string, len(structMappings(cfg)))
for i := range structMappings(cfg) {
r = append(r, structMappings(cfg)[i].EnvVars...)
}
return r