normalize graph
This commit is contained in:
@@ -2,11 +2,6 @@ package config
|
|||||||
|
|
||||||
import "github.com/owncloud/ocis/ocis-pkg/shared"
|
import "github.com/owncloud/ocis/ocis-pkg/shared"
|
||||||
|
|
||||||
type mapping struct {
|
|
||||||
EnvVars []string // name of the EnvVars var.
|
|
||||||
Destination interface{} // memory address of the original config value to modify.
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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.
|
||||||
|
|||||||
@@ -20,30 +20,25 @@ func Execute(cfg *config.Config) error {
|
|||||||
Version: version.String,
|
Version: version.String,
|
||||||
Usage: "Serve Graph API for oCIS",
|
Usage: "Serve Graph API for oCIS",
|
||||||
Compiled: version.Compiled(),
|
Compiled: version.Compiled(),
|
||||||
|
|
||||||
Authors: []*cli.Author{
|
Authors: []*cli.Author{
|
||||||
{
|
{
|
||||||
Name: "ownCloud GmbH",
|
Name: "ownCloud GmbH",
|
||||||
Email: "support@owncloud.com",
|
Email: "support@owncloud.com",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
Before: func(c *cli.Context) error {
|
Before: func(c *cli.Context) error {
|
||||||
cfg.Server.Version = version.String
|
cfg.Server.Version = version.String
|
||||||
return ParseConfig(c, cfg)
|
return ParseConfig(c, cfg)
|
||||||
},
|
},
|
||||||
|
|
||||||
Commands: []*cli.Command{
|
Commands: []*cli.Command{
|
||||||
Server(cfg),
|
Server(cfg),
|
||||||
Health(cfg),
|
Health(cfg),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
cli.HelpFlag = &cli.BoolFlag{
|
cli.HelpFlag = &cli.BoolFlag{
|
||||||
Name: "help,h",
|
Name: "help,h",
|
||||||
Usage: "Show the help",
|
Usage: "Show the help",
|
||||||
}
|
}
|
||||||
|
|
||||||
cli.VersionFlag = &cli.BoolFlag{
|
cli.VersionFlag = &cli.BoolFlag{
|
||||||
Name: "version,v",
|
Name: "version,v",
|
||||||
Usage: "Print the version",
|
Usage: "Print the version",
|
||||||
@@ -73,9 +68,8 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error {
|
|||||||
// load all env variables relevant to the config in the current context.
|
// load all env variables relevant to the config in the current context.
|
||||||
conf.LoadOSEnv(config.GetEnv(), false)
|
conf.LoadOSEnv(config.GetEnv(), false)
|
||||||
|
|
||||||
if err = cfg.UnmapEnv(conf); err != nil {
|
bindings := config.StructMappings(cfg)
|
||||||
return err
|
return ociscfg.BindEnv(conf, bindings)
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -87,10 +81,7 @@ type SutureService struct {
|
|||||||
|
|
||||||
// NewSutureService creates a new graph.SutureService
|
// NewSutureService creates a new graph.SutureService
|
||||||
func NewSutureService(cfg *ociscfg.Config) suture.Service {
|
func NewSutureService(cfg *ociscfg.Config) suture.Service {
|
||||||
if cfg.Mode == 0 {
|
cfg.Graph.Log = cfg.Log
|
||||||
cfg.Graph.Supervised = true
|
|
||||||
}
|
|
||||||
cfg.Graph.Log.File = cfg.Log.File
|
|
||||||
return SutureService{
|
return SutureService{
|
||||||
cfg: cfg.Graph,
|
cfg: cfg.Graph,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,10 +24,7 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
|
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ParseConfig(ctx, cfg); err != nil {
|
return ParseConfig(ctx, cfg)
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
},
|
},
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
logger := NewLogger(cfg)
|
logger := NewLogger(cfg)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
gofig "github.com/gookit/config/v2"
|
gofig "github.com/gookit/config/v2"
|
||||||
|
"github.com/owncloud/ocis/ocis-pkg/shared"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Log defines the available logging configuration.
|
// Log defines the available logging configuration.
|
||||||
@@ -65,7 +66,7 @@ type Spaces struct {
|
|||||||
// Config combines all available configuration parts.
|
// Config combines all available configuration parts.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
File string `mapstructure:"file"`
|
File string `mapstructure:"file"`
|
||||||
Log Log `mapstructure:"log"`
|
Log shared.Log `mapstructure:"log"`
|
||||||
Debug Debug `mapstructure:"debug"`
|
Debug Debug `mapstructure:"debug"`
|
||||||
HTTP HTTP `mapstructure:"http"`
|
HTTP HTTP `mapstructure:"http"`
|
||||||
Server Server `mapstructure:"server"`
|
Server Server `mapstructure:"server"`
|
||||||
@@ -85,7 +86,7 @@ func New() *Config {
|
|||||||
|
|
||||||
func DefaultConfig() *Config {
|
func DefaultConfig() *Config {
|
||||||
return &Config{
|
return &Config{
|
||||||
Log: Log{},
|
Log: shared.Log{},
|
||||||
Debug: Debug{
|
Debug: Debug{
|
||||||
Addr: "127.0.0.1:9124",
|
Addr: "127.0.0.1:9124",
|
||||||
Token: "",
|
Token: "",
|
||||||
|
|||||||
@@ -1,13 +1,17 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
type mapping struct {
|
import "github.com/owncloud/ocis/ocis-pkg/shared"
|
||||||
EnvVars []string // name of the EnvVars var.
|
|
||||||
Destination interface{} // memory address of the original config value to modify.
|
// 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
|
||||||
|
// us propagate changes easier.
|
||||||
|
func StructMappings(cfg *Config) []shared.EnvBinding {
|
||||||
|
return structMappings(cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// structMappings binds a set of environment variables to a destination on cfg.
|
// structMappings binds a set of environment variables to a destination on cfg.
|
||||||
func structMappings(cfg *Config) []mapping {
|
func structMappings(cfg *Config) []shared.EnvBinding {
|
||||||
return []mapping{
|
return []shared.EnvBinding{
|
||||||
{
|
{
|
||||||
EnvVars: []string{"GRAPH_CONFIG_FILE"},
|
EnvVars: []string{"GRAPH_CONFIG_FILE"},
|
||||||
Destination: &cfg.File,
|
Destination: &cfg.File,
|
||||||
Reference in New Issue
Block a user