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

View File

@@ -4,10 +4,9 @@ import (
"context"
"os"
"github.com/owncloud/ocis/ocis-pkg/shared"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/log"
"github.com/owncloud/ocis/ocis-pkg/shared"
"github.com/owncloud/ocis/ocis-pkg/version"
"github.com/owncloud/ocis/proxy/pkg/config"
"github.com/thejerf/suture/v4"
@@ -51,17 +50,6 @@ func Execute(cfg *config.Config) error {
return app.Run(os.Args)
}
// NewLogger initializes a service-specific logger instance.
func NewLogger(cfg *config.Config) log.Logger {
return log.NewLogger(
log.Name("proxy"),
log.Level(cfg.Log.Level),
log.Pretty(cfg.Log.Pretty),
log.Color(cfg.Log.Color),
log.File(cfg.Log.File),
)
}
// ParseConfig loads proxy configuration. Loading will first attempt to parse config files in the expected locations
// and then parses environment variables. In the context of oCIS env variables will always overwrite values set
// in a config file.
@@ -75,7 +63,20 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error {
return err
}
conf.LoadOSEnv(config.GetEnv(), false)
// 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{}
}
conf.LoadOSEnv(config.GetEnv(cfg), false)
bindings := config.StructMappings(cfg)
return ociscfg.BindEnv(conf, bindings)
}
@@ -87,9 +88,8 @@ type SutureService struct {
// NewSutureService creates a new proxy.SutureService
func NewSutureService(cfg *ociscfg.Config) suture.Service {
if (cfg.Proxy.Log == shared.Log{}) {
cfg.Proxy.Log = cfg.Log
}
// inherit common configuration from ocis config parsing.
cfg.Proxy.Commons = cfg.Commons
return SutureService{
cfg: cfg.Proxy,
}
@@ -103,3 +103,14 @@ func (s SutureService) Serve(ctx context.Context) error {
return nil
}
// NewLogger initializes a service-specific logger instance.
func NewLogger(cfg *config.Config) log.Logger {
return log.NewLogger(
log.Name("proxy"),
log.Level(cfg.Log.Level),
log.Pretty(cfg.Log.Pretty),
log.Color(cfg.Log.Color),
log.File(cfg.Log.File),
)
}

View File

@@ -8,11 +8,6 @@ import (
"strings"
"time"
gofig "github.com/gookit/config/v2"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/shared"
"github.com/coreos/go-oidc/v3/oidc"
"github.com/cs3org/reva/pkg/token/manager/jwt"
chimiddleware "github.com/go-chi/chi/v5/middleware"
@@ -45,26 +40,10 @@ func Server(cfg *config.Config) *cli.Command {
Name: "server",
Usage: "Start integrated server",
Before: func(ctx *cli.Context) error {
// remember shared logging info to prevent empty overwrites
inLog := cfg.Log
if err := ParseConfig(ctx, cfg); err != nil {
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
}
}
if cfg.HTTP.Root != "/" {
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
}
@@ -73,14 +52,6 @@ func Server(cfg *config.Config) *cli.Command {
cfg.PreSignedURL.AllowedHTTPMethods = ctx.StringSlice("presignedurl-allow-method")
}
// we need a starting point to compare the default config values to determine if the outcome of ParseConfig
// modified a value that should be shared just because it is present in the ocis.yaml file.
defaultConfig := config.DefaultConfig()
if cfg.OcisURL != "" && cfg.OIDC.Issuer == defaultConfig.OIDC.Issuer {
cfg.OIDC.Issuer = cfg.OcisURL
}
if err := loadUserAgent(ctx, cfg); err != nil {
return err
}