addded web to the new inheritance strategy
This commit is contained in:
@@ -2,7 +2,6 @@ package command
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/owncloud/ocis/ocis-pkg/config"
|
"github.com/owncloud/ocis/ocis-pkg/config"
|
||||||
"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/web/pkg/command"
|
"github.com/owncloud/ocis/web/pkg/command"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
@@ -10,8 +9,6 @@ import (
|
|||||||
|
|
||||||
// WebCommand is the entrypoint for the web command.
|
// WebCommand is the entrypoint for the web command.
|
||||||
func WebCommand(cfg *config.Config) *cli.Command {
|
func WebCommand(cfg *config.Config) *cli.Command {
|
||||||
var globalLog shared.Log
|
|
||||||
|
|
||||||
return &cli.Command{
|
return &cli.Command{
|
||||||
Name: "web",
|
Name: "web",
|
||||||
Usage: "Start web server",
|
Usage: "Start web server",
|
||||||
@@ -21,16 +18,13 @@ func WebCommand(cfg *config.Config) *cli.Command {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
globalLog = cfg.Log
|
if cfg.Commons != nil {
|
||||||
|
cfg.Web.Commons = cfg.Commons
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
// if accounts logging is empty in ocis.yaml
|
|
||||||
if (cfg.Web.Log == shared.Log{}) && (globalLog != shared.Log{}) {
|
|
||||||
// we can safely inherit the global logging values.
|
|
||||||
cfg.Web.Log = globalLog
|
|
||||||
}
|
|
||||||
origCmd := command.Server(cfg.Web)
|
origCmd := command.Server(cfg.Web)
|
||||||
return handleOriginalAction(c, origCmd)
|
return handleOriginalAction(c, origCmd)
|
||||||
},
|
},
|
||||||
|
|||||||
+14
-4
@@ -64,7 +64,19 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error {
|
|||||||
return err
|
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)
|
bindings := config.StructMappings(cfg)
|
||||||
return ociscfg.BindEnv(conf, bindings)
|
return ociscfg.BindEnv(conf, bindings)
|
||||||
}
|
}
|
||||||
@@ -76,9 +88,7 @@ type SutureService struct {
|
|||||||
|
|
||||||
// NewSutureService creates a new web.SutureService
|
// NewSutureService creates a new web.SutureService
|
||||||
func NewSutureService(cfg *ociscfg.Config) suture.Service {
|
func NewSutureService(cfg *ociscfg.Config) suture.Service {
|
||||||
if (cfg.Web.Log == shared.Log{}) {
|
cfg.Web.Commons = cfg.Commons
|
||||||
cfg.Web.Log = cfg.Log
|
|
||||||
}
|
|
||||||
return SutureService{
|
return SutureService{
|
||||||
cfg: cfg.Web,
|
cfg: cfg.Web,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,6 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
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/web/pkg/config"
|
"github.com/owncloud/ocis/web/pkg/config"
|
||||||
@@ -26,9 +22,6 @@ 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 {
|
||||||
// remember shared logging info to prevent empty overwrites
|
|
||||||
inLog := cfg.Log
|
|
||||||
|
|
||||||
if cfg.HTTP.Root != "/" {
|
if cfg.HTTP.Root != "/" {
|
||||||
cfg.HTTP.Root = strings.TrimRight(cfg.HTTP.Root, "/")
|
cfg.HTTP.Root = strings.TrimRight(cfg.HTTP.Root, "/")
|
||||||
}
|
}
|
||||||
@@ -42,19 +35,6 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
cfg.Web.Config.OpenIDConnect.MetadataURL = strings.TrimRight(cfg.Web.Config.OpenIDConnect.Authority, "/") + "/.well-known/openid-configuration"
|
cfg.Web.Config.OpenIDConnect.MetadataURL = strings.TrimRight(cfg.Web.Config.OpenIDConnect.Authority, "/") + "/.well-known/openid-configuration"
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
return nil
|
||||||
},
|
},
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
@@ -71,7 +51,7 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
logger.Err(err).Msg("error opening config file")
|
logger.Err(err).Msg("error opening config file")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := json.Unmarshal(contents, &cfg.Web.Config); err != nil {
|
if err = json.Unmarshal(contents, &cfg.Web.Config); err != nil {
|
||||||
logger.Fatal().Err(err).Msg("error unmarshalling config file")
|
logger.Fatal().Err(err).Msg("error unmarshalling config file")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,13 +88,15 @@ type Web struct {
|
|||||||
|
|
||||||
// Config combines all available configuration parts.
|
// Config combines all available configuration parts.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
File string `mapstructure:"file"`
|
*shared.Commons
|
||||||
Log shared.Log `mapstructure:"log"`
|
|
||||||
Debug Debug `mapstructure:"debug"`
|
File string `mapstructure:"file"`
|
||||||
HTTP HTTP `mapstructure:"http"`
|
Log *shared.Log `mapstructure:"log"`
|
||||||
Tracing Tracing `mapstructure:"tracing"`
|
Debug Debug `mapstructure:"debug"`
|
||||||
Asset Asset `mapstructure:"asset"`
|
HTTP HTTP `mapstructure:"http"`
|
||||||
Web Web `mapstructure:"web"`
|
Tracing Tracing `mapstructure:"tracing"`
|
||||||
|
Asset Asset `mapstructure:"asset"`
|
||||||
|
Web Web `mapstructure:"web"`
|
||||||
|
|
||||||
Context context.Context
|
Context context.Context
|
||||||
Supervised bool
|
Supervised bool
|
||||||
@@ -107,7 +109,6 @@ func New() *Config {
|
|||||||
|
|
||||||
func DefaultConfig() *Config {
|
func DefaultConfig() *Config {
|
||||||
return &Config{
|
return &Config{
|
||||||
Log: shared.Log{},
|
|
||||||
Debug: Debug{
|
Debug: Debug{
|
||||||
Addr: "127.0.0.1:9104",
|
Addr: "127.0.0.1:9104",
|
||||||
Token: "",
|
Token: "",
|
||||||
@@ -150,14 +151,3 @@ 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...)
|
|
||||||
}
|
|
||||||
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,6 +2,17 @@ package config
|
|||||||
|
|
||||||
import "github.com/owncloud/ocis/ocis-pkg/shared"
|
import "github.com/owncloud/ocis/ocis-pkg/shared"
|
||||||
|
|
||||||
|
// 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(cfg *Config) []string {
|
||||||
|
var r = make([]string, len(structMappings(cfg)))
|
||||||
|
for i := range structMappings(cfg) {
|
||||||
|
r = append(r, structMappings(cfg)[i].EnvVars...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
// StructMappings binds a set of environment variables to a destination on cfg. Iterating over this set and editing the
|
// StructMappings binds a set of environment variables to a destination on cfg. Iterating over this set and editing the
|
||||||
// Destination value of a binding will alter the original value, as it is a pointer to its memory address. This lets
|
// Destination value of a binding will alter the original value, as it is a pointer to its memory address. This lets
|
||||||
// us propagate changes easier.
|
// us propagate changes easier.
|
||||||
|
|||||||
Reference in New Issue
Block a user