add graph

This commit is contained in:
A.Unger
2021-11-04 13:50:42 +01:00
parent b61887aca1
commit cfe1ac30af
7 changed files with 389 additions and 241 deletions

View File

@@ -3,16 +3,13 @@ package command
import (
"context"
"os"
"strings"
"github.com/owncloud/ocis/ocis-pkg/sync"
"github.com/thejerf/suture/v4"
"github.com/owncloud/ocis/graph/pkg/config"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/log"
"github.com/owncloud/ocis/ocis-pkg/version"
"github.com/spf13/viper"
"github.com/urfave/cli/v2"
)
@@ -31,8 +28,6 @@ func Execute(cfg *config.Config) error {
},
},
//Flags: flagset.RootWithConfig(cfg),
Before: func(c *cli.Context) error {
cfg.Server.Version = version.String
return ParseConfig(c, cfg)
@@ -68,46 +63,18 @@ func NewLogger(cfg *config.Config) log.Logger {
)
}
// ParseConfig reads graph configuration from fs.
// ParseConfig loads proxy configuration from known paths.
func ParseConfig(c *cli.Context, cfg *config.Config) error {
sync.ParsingViperConfig.Lock()
defer sync.ParsingViperConfig.Unlock()
logger := NewLogger(cfg)
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.SetEnvPrefix("GRAPH")
viper.AutomaticEnv()
if c.IsSet("config-file") {
viper.SetConfigFile(c.String("config-file"))
} else {
viper.SetConfigName("graph")
viper.AddConfigPath("/etc/ocis")
viper.AddConfigPath("$HOME/.ocis")
viper.AddConfigPath("./config")
conf, err := ociscfg.BindSourcesToStructs("graph", cfg)
if err != nil {
return err
}
if err := viper.ReadInConfig(); err != nil {
switch err.(type) {
case viper.ConfigFileNotFoundError:
//logger.Info().
// Msg("Continue without config")
case viper.UnsupportedConfigError:
logger.Fatal().
Err(err).
Msg("Unsupported config type")
default:
logger.Fatal().
Err(err).
Msg("Failed to read config")
}
}
// load all env variables relevant to the config in the current context.
conf.LoadOSEnv(config.GetEnv(), false)
if err := viper.Unmarshal(&cfg); err != nil {
logger.Fatal().
Err(err).
Msg("Failed to parse config")
if err = cfg.UnmapEnv(conf); err != nil {
return err
}
return nil

View File

@@ -29,9 +29,7 @@ func Server(cfg *config.Config) *cli.Command {
// When running on single binary mode the before hook from the root command won't get called. We manually
// call this before hook from ocis command, so the configuration can be loaded.
if !cfg.Supervised {
return ParseConfig(ctx, cfg)
}
return ParseConfig(ctx, cfg)
logger.Debug().Str("service", "graph").Msg("ignoring config file parsing when running supervised")
return nil
},