add ocis-pkg/config default config + fix logging inheritance

This commit is contained in:
A.Unger
2021-11-08 11:14:26 +01:00
parent 835928b29b
commit 74dae6dad9
11 changed files with 152 additions and 249 deletions
+1 -24
View File
@@ -5,10 +5,8 @@ package command
import (
"github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/version"
"github.com/owncloud/ocis/ocis/pkg/register"
"github.com/owncloud/ocis/proxy/pkg/command"
svcconfig "github.com/owncloud/ocis/proxy/pkg/config"
"github.com/urfave/cli/v2"
)
@@ -25,33 +23,12 @@ func ProxyCommand(cfg *config.Config) *cli.Command {
return ParseConfig(ctx, cfg)
},
Action: func(c *cli.Context) error {
origCmd := command.Server(configureProxy(cfg))
origCmd := command.Server(cfg.Proxy)
return handleOriginalAction(c, origCmd)
},
}
}
func configureProxy(cfg *config.Config) *svcconfig.Config {
cfg.Proxy.OcisURL = cfg.OcisURL
cfg.Proxy.Log.Level = cfg.Log.Level
cfg.Proxy.Log.Pretty = cfg.Log.Pretty
cfg.Proxy.Log.Color = cfg.Log.Color
cfg.Proxy.Service.Version = version.String
if cfg.Tracing.Enabled {
cfg.Proxy.Tracing.Enabled = cfg.Tracing.Enabled
cfg.Proxy.Tracing.Type = cfg.Tracing.Type
cfg.Proxy.Tracing.Endpoint = cfg.Tracing.Endpoint
cfg.Proxy.Tracing.Collector = cfg.Tracing.Collector
}
if cfg.TokenManager.JWTSecret != "" {
cfg.Proxy.TokenManager.JWTSecret = cfg.TokenManager.JWTSecret
}
return cfg.Proxy
}
func init() {
register.AddCommand(ProxyCommand)
}
+1 -4
View File
@@ -3,8 +3,6 @@ package command
import (
"os"
"github.com/owncloud/ocis/ocis/pkg/flagset"
"github.com/owncloud/ocis/ocis-pkg/config"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/log"
@@ -15,14 +13,13 @@ import (
// Execute is the entry point for the ocis command.
func Execute() error {
cfg := config.New()
cfg := config.DefaultConfig()
app := &cli.App{
Name: "ocis",
Version: version.String,
Usage: "ownCloud Infinite Scale Stack",
Compiled: version.Compiled(),
Flags: flagset.RootWithConfig(cfg),
Before: func(c *cli.Context) error {
return ParseConfig(c, cfg)
},
+1 -3
View File
@@ -7,7 +7,6 @@ import (
"strings"
"github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis/pkg/flagset"
"github.com/owncloud/ocis/ocis/pkg/register"
"github.com/owncloud/ocis/ocis/pkg/runtime"
"github.com/urfave/cli/v2"
@@ -19,13 +18,12 @@ func Server(cfg *config.Config) *cli.Command {
Name: "server",
Usage: "Start fullstack server",
Category: "Fullstack",
Flags: flagset.ServerWithConfig(cfg),
Before: func(c *cli.Context) error {
if cfg.HTTP.Root != "/" {
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
}
return nil
return ParseConfig(c, cfg)
},
Action: func(c *cli.Context) error {
r := runtime.New(cfg)
-1
View File
@@ -1 +0,0 @@
package config
+1 -163
View File
@@ -5,109 +5,7 @@ import (
"github.com/urfave/cli/v2"
)
// RootWithConfig applies cfg to the root flagset
func RootWithConfig(cfg *config.Config) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
// this is just a dummy config flag do document the existence
// of this environment variable
// the environment variable itself is used in `ocis-pkg/config/defaults/paths.go`
Name: "ocis-base-data-path",
Usage: "Set the base path where oCIS stores data",
EnvVars: []string{"OCIS_BASE_DATA_PATH"},
},
&cli.StringFlag{
Name: "config-file",
Usage: "Load config file from a non standard location.",
EnvVars: []string{"OCIS_CONFIG_FILE"},
Destination: &cfg.File,
},
&cli.StringFlag{
Name: "ocis-log-level",
Value: "info",
Usage: "Set logging level",
EnvVars: []string{"OCIS_LOG_LEVEL"},
Destination: &cfg.Log.Level,
},
&cli.BoolFlag{
Value: false,
Name: "ocis-log-pretty",
Usage: "Enable pretty logging",
EnvVars: []string{"OCIS_LOG_PRETTY"},
Destination: &cfg.Log.Pretty,
},
&cli.BoolFlag{
Value: true,
Name: "ocis-log-color",
Usage: "Enable colored logging",
EnvVars: []string{"OCIS_LOG_COLOR"},
Destination: &cfg.Log.Color,
},
&cli.StringFlag{
Name: "ocis-log-file",
Usage: "Enable log to file",
EnvVars: []string{"OCIS_LOG_FILE"},
Destination: &cfg.Log.File,
},
&cli.BoolFlag{
Name: "tracing-enabled",
Usage: "Enable sending traces",
EnvVars: []string{"OCIS_TRACING_ENABLED"},
Destination: &cfg.Tracing.Enabled,
},
&cli.StringFlag{
Name: "tracing-type",
Value: "jaeger",
Usage: "Tracing backend type",
EnvVars: []string{"OCIS_TRACING_TYPE"},
Destination: &cfg.Tracing.Type,
},
&cli.StringFlag{
Name: "tracing-endpoint",
Value: "",
Usage: "Endpoint for the agent",
EnvVars: []string{"OCIS_TRACING_ENDPOINT"},
Destination: &cfg.Tracing.Endpoint,
},
&cli.StringFlag{
Name: "tracing-collector",
Value: "",
Usage: "Endpoint for the collector",
EnvVars: []string{"OCIS_TRACING_COLLECTOR"},
Destination: &cfg.Tracing.Collector,
},
&cli.StringFlag{
Name: "tracing-service",
Value: "ocis",
Usage: "Service name for tracing",
EnvVars: []string{"OCIS_TRACING_SERVICE"},
Destination: &cfg.Tracing.Service,
},
&cli.StringFlag{
Name: "jwt-secret",
Value: "Pive-Fumkiu4",
Usage: "Used to dismantle the access token, should equal reva's jwt-secret",
EnvVars: []string{"OCIS_JWT_SECRET"},
Destination: &cfg.TokenManager.JWTSecret,
},
&cli.StringFlag{
Name: "runtime-port",
Value: "9250",
Usage: "Configures which port the runtime starts",
EnvVars: []string{"OCIS_RUNTIME_PORT"},
Destination: &cfg.Runtime.Port,
},
&cli.StringFlag{
Name: "runtime-host",
Value: "localhost",
Usage: "Configures the host where the runtime process is running",
EnvVars: []string{"OCIS_RUNTIME_HOST"},
Destination: &cfg.Runtime.Host,
},
}
}
// HealthWithConfig applies cfg to the root flagset
// HealthWithConfig applies cfg to the root flag-set.
func HealthWithConfig(cfg *config.Config) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
@@ -119,63 +17,3 @@ func HealthWithConfig(cfg *config.Config) []cli.Flag {
},
}
}
// ServerWithConfig applies cfg to the root flagset
func ServerWithConfig(cfg *config.Config) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "debug-addr",
Value: "127.0.0.1:9010",
Usage: "Address to bind debug server",
EnvVars: []string{"OCIS_DEBUG_ADDR"},
Destination: &cfg.Debug.Addr,
},
&cli.StringFlag{
Name: "debug-token",
Value: "",
Usage: "Token to grant metrics access",
EnvVars: []string{"OCIS_DEBUG_TOKEN"},
Destination: &cfg.Debug.Token,
},
&cli.BoolFlag{
Name: "debug-pprof",
Usage: "Enable pprof debugging",
EnvVars: []string{"OCIS_DEBUG_PPROF"},
Destination: &cfg.Debug.Pprof,
},
&cli.BoolFlag{
Name: "debug-zpages",
Usage: "Enable zpages debugging",
EnvVars: []string{"OCIS_DEBUG_ZPAGES"},
Destination: &cfg.Debug.Zpages,
},
&cli.StringFlag{
Name: "http-addr",
Value: "127.0.0.1:9000",
Usage: "Address to bind http server",
EnvVars: []string{"OCIS_HTTP_ADDR"},
Destination: &cfg.HTTP.Addr,
},
&cli.StringFlag{
Name: "http-root",
Value: "/",
Usage: "Root path of http server",
EnvVars: []string{"OCIS_HTTP_ROOT"},
Destination: &cfg.HTTP.Root,
},
&cli.StringFlag{
Name: "grpc-addr",
Value: "127.0.0.1:9001",
Usage: "Address to bind grpc server",
EnvVars: []string{"OCIS_GRPC_ADDR"},
Destination: &cfg.GRPC.Addr,
},
&cli.StringFlag{
Name: "extensions",
Aliases: []string{"e"},
Usage: "Run specific extensions during supervised mode",
EnvVars: []string{"OCIS_RUN_EXTENSIONS"},
Destination: &cfg.Runtime.Extensions,
},
}
}