new config framework in thumbnails
This commit is contained in:
@@ -5,16 +5,16 @@ package command
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/owncloud/ocis/ocis-pkg/config"
|
"github.com/owncloud/ocis/ocis-pkg/config"
|
||||||
"github.com/owncloud/ocis/ocis-pkg/version"
|
"github.com/owncloud/ocis/ocis-pkg/shared"
|
||||||
"github.com/owncloud/ocis/ocis/pkg/register"
|
"github.com/owncloud/ocis/ocis/pkg/register"
|
||||||
"github.com/owncloud/ocis/thumbnails/pkg/command"
|
"github.com/owncloud/ocis/thumbnails/pkg/command"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
|
|
||||||
svcconfig "github.com/owncloud/ocis/thumbnails/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ThumbnailsCommand is the entrypoint for the thumbnails command.
|
// ThumbnailsCommand is the entrypoint for the thumbnails command.
|
||||||
func ThumbnailsCommand(cfg *config.Config) *cli.Command {
|
func ThumbnailsCommand(cfg *config.Config) *cli.Command {
|
||||||
|
var globalLog shared.Log
|
||||||
|
|
||||||
return &cli.Command{
|
return &cli.Command{
|
||||||
Name: "thumbnails",
|
Name: "thumbnails",
|
||||||
Usage: "Start thumbnails server",
|
Usage: "Start thumbnails server",
|
||||||
@@ -23,31 +23,26 @@ func ThumbnailsCommand(cfg *config.Config) *cli.Command {
|
|||||||
command.PrintVersion(cfg.Thumbnails),
|
command.PrintVersion(cfg.Thumbnails),
|
||||||
},
|
},
|
||||||
Before: func(ctx *cli.Context) error {
|
Before: func(ctx *cli.Context) error {
|
||||||
return ParseConfig(ctx, cfg)
|
if err := ParseConfig(ctx, cfg); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
globalLog = cfg.Log
|
||||||
|
|
||||||
|
return nil
|
||||||
},
|
},
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
origCmd := command.Server(configureThumbnails(cfg))
|
// if thumbnails logging is empty in ocis.yaml
|
||||||
|
if (cfg.Thumbnails.Log == shared.Log{}) && (globalLog != shared.Log{}) {
|
||||||
|
// we can safely inherit the global logging values.
|
||||||
|
cfg.Thumbnails.Log = globalLog
|
||||||
|
}
|
||||||
|
origCmd := command.Server(cfg.Thumbnails)
|
||||||
return handleOriginalAction(c, origCmd)
|
return handleOriginalAction(c, origCmd)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func configureThumbnails(cfg *config.Config) *svcconfig.Config {
|
|
||||||
cfg.Thumbnails.Log.Level = cfg.Log.Level
|
|
||||||
cfg.Thumbnails.Log.Pretty = cfg.Log.Pretty
|
|
||||||
cfg.Thumbnails.Log.Color = cfg.Log.Color
|
|
||||||
cfg.Thumbnails.Server.Version = version.String
|
|
||||||
|
|
||||||
if cfg.Tracing.Enabled {
|
|
||||||
cfg.Thumbnails.Tracing.Enabled = cfg.Tracing.Enabled
|
|
||||||
cfg.Thumbnails.Tracing.Type = cfg.Tracing.Type
|
|
||||||
cfg.Thumbnails.Tracing.Endpoint = cfg.Tracing.Endpoint
|
|
||||||
cfg.Thumbnails.Tracing.Collector = cfg.Tracing.Collector
|
|
||||||
}
|
|
||||||
|
|
||||||
return cfg.Thumbnails
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
register.AddCommand(ThumbnailsCommand)
|
register.AddCommand(ThumbnailsCommand)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/ocis-pkg/shared"
|
||||||
|
|
||||||
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
|
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
|
||||||
"github.com/owncloud/ocis/ocis-pkg/log"
|
"github.com/owncloud/ocis/ocis-pkg/log"
|
||||||
"github.com/owncloud/ocis/ocis-pkg/version"
|
"github.com/owncloud/ocis/ocis-pkg/version"
|
||||||
@@ -82,7 +84,9 @@ type SutureService struct {
|
|||||||
|
|
||||||
// NewSutureService creates a new thumbnails.SutureService
|
// NewSutureService creates a new thumbnails.SutureService
|
||||||
func NewSutureService(cfg *ociscfg.Config) suture.Service {
|
func NewSutureService(cfg *ociscfg.Config) suture.Service {
|
||||||
cfg.Thumbnails.Log = cfg.Log
|
if (cfg.Thumbnails.Log == shared.Log{}) {
|
||||||
|
cfg.Thumbnails.Log = cfg.Log
|
||||||
|
}
|
||||||
return SutureService{
|
return SutureService{
|
||||||
cfg: cfg.Thumbnails,
|
cfg: cfg.Thumbnails,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,10 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
gofig "github.com/gookit/config/v2"
|
||||||
|
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
|
||||||
|
"github.com/owncloud/ocis/ocis-pkg/shared"
|
||||||
|
|
||||||
"github.com/oklog/run"
|
"github.com/oklog/run"
|
||||||
"github.com/owncloud/ocis/ocis-pkg/sync"
|
"github.com/owncloud/ocis/ocis-pkg/sync"
|
||||||
"github.com/owncloud/ocis/thumbnails/pkg/config"
|
"github.com/owncloud/ocis/thumbnails/pkg/config"
|
||||||
@@ -20,7 +24,27 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
Name: "server",
|
Name: "server",
|
||||||
Usage: "Start integrated server",
|
Usage: "Start integrated server",
|
||||||
Before: func(ctx *cli.Context) error {
|
Before: func(ctx *cli.Context) error {
|
||||||
return ParseConfig(ctx, cfg)
|
// 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
},
|
},
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
logger := NewLogger(cfg)
|
logger := NewLogger(cfg)
|
||||||
|
|||||||
Reference in New Issue
Block a user