normalize graph

This commit is contained in:
A.Unger
2021-11-08 12:04:30 +01:00
parent e8b9186ba3
commit 4c9e4713cf
5 changed files with 16 additions and 28 deletions

View File

@@ -2,11 +2,6 @@ package config
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
// 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.

View File

@@ -20,30 +20,25 @@ func Execute(cfg *config.Config) error {
Version: version.String,
Usage: "Serve Graph API for oCIS",
Compiled: version.Compiled(),
Authors: []*cli.Author{
{
Name: "ownCloud GmbH",
Email: "support@owncloud.com",
},
},
Before: func(c *cli.Context) error {
cfg.Server.Version = version.String
return ParseConfig(c, cfg)
},
Commands: []*cli.Command{
Server(cfg),
Health(cfg),
},
}
cli.HelpFlag = &cli.BoolFlag{
Name: "help,h",
Usage: "Show the help",
}
cli.VersionFlag = &cli.BoolFlag{
Name: "version,v",
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.
conf.LoadOSEnv(config.GetEnv(), false)
if err = cfg.UnmapEnv(conf); err != nil {
return err
}
bindings := config.StructMappings(cfg)
return ociscfg.BindEnv(conf, bindings)
return nil
}
@@ -87,10 +81,7 @@ type SutureService struct {
// NewSutureService creates a new graph.SutureService
func NewSutureService(cfg *ociscfg.Config) suture.Service {
if cfg.Mode == 0 {
cfg.Graph.Supervised = true
}
cfg.Graph.Log.File = cfg.Log.File
cfg.Graph.Log = cfg.Log
return SutureService{
cfg: cfg.Graph,
}

View File

@@ -24,10 +24,7 @@ func Server(cfg *config.Config) *cli.Command {
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
}
if err := ParseConfig(ctx, cfg); err != nil {
return err
}
return nil
return ParseConfig(ctx, cfg)
},
Action: func(c *cli.Context) error {
logger := NewLogger(cfg)

View File

@@ -6,6 +6,7 @@ import (
"reflect"
gofig "github.com/gookit/config/v2"
"github.com/owncloud/ocis/ocis-pkg/shared"
)
// Log defines the available logging configuration.
@@ -65,7 +66,7 @@ type Spaces struct {
// Config combines all available configuration parts.
type Config struct {
File string `mapstructure:"file"`
Log Log `mapstructure:"log"`
Log shared.Log `mapstructure:"log"`
Debug Debug `mapstructure:"debug"`
HTTP HTTP `mapstructure:"http"`
Server Server `mapstructure:"server"`
@@ -85,7 +86,7 @@ func New() *Config {
func DefaultConfig() *Config {
return &Config{
Log: Log{},
Log: shared.Log{},
Debug: Debug{
Addr: "127.0.0.1:9124",
Token: "",

View File

@@ -1,13 +1,17 @@
package config
type mapping struct {
EnvVars []string // name of the EnvVars var.
Destination interface{} // memory address of the original config value to modify.
import "github.com/owncloud/ocis/ocis-pkg/shared"
// 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.
func structMappings(cfg *Config) []mapping {
return []mapping{
func structMappings(cfg *Config) []shared.EnvBinding {
return []shared.EnvBinding{
{
EnvVars: []string{"GRAPH_CONFIG_FILE"},
Destination: &cfg.File,