mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-07-19 20:14:17 -04:00
migrate web to the new config scheme
This commit is contained in:
@@ -3,15 +3,11 @@ package command
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/owncloud/ocis/ocis-pkg/sync"
|
||||
|
||||
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
|
||||
"github.com/owncloud/ocis/ocis-pkg/log"
|
||||
"github.com/owncloud/ocis/ocis-pkg/version"
|
||||
"github.com/owncloud/ocis/web/pkg/config"
|
||||
"github.com/spf13/viper"
|
||||
"github.com/thejerf/suture/v4"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
@@ -59,46 +55,18 @@ func NewLogger(cfg *config.Config) log.Logger {
|
||||
)
|
||||
}
|
||||
|
||||
// ParseConfig loads proxy configuration from Viper known paths.
|
||||
// ParseConfig loads graph 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("WEB")
|
||||
viper.AutomaticEnv()
|
||||
|
||||
if c.IsSet("config-file") {
|
||||
viper.SetConfigFile(c.String("config-file"))
|
||||
} else {
|
||||
viper.SetConfigName("web")
|
||||
|
||||
viper.AddConfigPath("/etc/ocis")
|
||||
viper.AddConfigPath("$HOME/.ocis")
|
||||
viper.AddConfigPath("./config")
|
||||
conf, err := ociscfg.BindSourcesToStructs("web", cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
switch err.(type) {
|
||||
case viper.ConfigFileNotFoundError:
|
||||
logger.Debug().
|
||||
Msg("no config found on preconfigured location")
|
||||
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
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"github.com/oklog/run"
|
||||
"github.com/owncloud/ocis/ocis-pkg/sync"
|
||||
"github.com/owncloud/ocis/web/pkg/config"
|
||||
"github.com/owncloud/ocis/web/pkg/flagset"
|
||||
"github.com/owncloud/ocis/web/pkg/metrics"
|
||||
"github.com/owncloud/ocis/web/pkg/server/debug"
|
||||
"github.com/owncloud/ocis/web/pkg/server/http"
|
||||
@@ -22,24 +21,16 @@ func Server(cfg *config.Config) *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "server",
|
||||
Usage: "Start integrated server",
|
||||
Flags: flagset.ServerWithConfig(cfg),
|
||||
Before: func(ctx *cli.Context) error {
|
||||
logger := NewLogger(cfg)
|
||||
if cfg.HTTP.Root != "/" {
|
||||
cfg.HTTP.Root = strings.TrimRight(cfg.HTTP.Root, "/")
|
||||
}
|
||||
|
||||
// StringSliceFlag doesn't support Destination
|
||||
// UPDATE Destination on string flags supported. Wait for https://github.com/urfave/cli/pull/1078 to get to micro/cli
|
||||
if len(ctx.StringSlice("web-config-app")) > 0 {
|
||||
cfg.Web.Config.Apps = ctx.StringSlice("web-config-app")
|
||||
if err := ParseConfig(ctx, cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !cfg.Supervised {
|
||||
if err := ParseConfig(ctx, cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
logger := NewLogger(cfg)
|
||||
logger.Debug().Str("service", "web").Msg("ignoring config file parsing when running supervised")
|
||||
|
||||
// build well known openid-configuration endpoint if it is not set
|
||||
|
||||
Reference in New Issue
Block a user