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
+117 -9
View File
@@ -82,10 +82,7 @@ type Runtime struct {
// Config combines all available configuration parts.
type Config struct {
// Mode is mostly used whenever we need to run an extension. The technical debt this introduces is in regard of
// what it does. Supervised (0) loads configuration from a unified config file because of known limitations of Viper; whereas
// Unsupervised (1) MUST parse config from all known sources.
Mode Mode
Mode Mode // DEPRECATED
File string
OcisURL string `mapstructure:"ocis_url"`
@@ -132,6 +129,54 @@ func New() *Config {
}
}
func DefaultConfig() *Config {
return &Config{
Log: Log{
Level: "info",
},
Debug: Debug{
Addr: "127.0.0.1:9010",
Token: "",
Pprof: false,
Zpages: false,
},
HTTP: HTTP{
Addr: "127.0.0.1:9000",
Root: "/",
},
GRPC: GRPC{
Addr: "127.0.0.1:9001",
},
Tracing: Tracing{
Enabled: false,
Type: "jaeger",
Endpoint: "",
Collector: "",
Service: "ocis",
},
TokenManager: TokenManager{
JWTSecret: "Pive-Fumkiu4",
},
Runtime: Runtime{
Port: "9250",
Host: "localhost",
},
Accounts: accounts.DefaultConfig(),
GLAuth: glauth.DefaultConfig(),
Graph: graph.DefaultConfig(),
IDP: idp.DefaultConfig(),
Proxy: proxy.DefaultConfig(),
GraphExplorer: graphExplorer.DefaultConfig(),
OCS: ocs.DefaultConfig(),
Settings: settings.DefaultConfig(),
Web: web.DefaultConfig(),
Store: store.DefaultConfig(),
Thumbnails: thumbnails.DefaultConfig(),
WebDAV: webdav.DefaultConfig(),
Storage: storage.New(),
}
}
// GetEnv fetches a list of known env variables for this extension. It is to be used by gookit, as it provides a list
// with all the environment variables an extension supports.
func GetEnv() []string {
@@ -178,13 +223,8 @@ func (c *Config) UnmapEnv(gooconf *gofig.Config) error {
return nil
}
// structMappings binds a set of environment variables to a destination on cfg.
func structMappings(cfg *Config) []shared.EnvBinding {
return []shared.EnvBinding{
{
EnvVars: []string{"OCIS_LOG_FILE"},
Destination: &cfg.Log.Level,
},
{
EnvVars: []string{"OCIS_LOG_LEVEL"},
Destination: &cfg.Log.Level,
@@ -197,5 +237,73 @@ func structMappings(cfg *Config) []shared.EnvBinding {
EnvVars: []string{"OCIS_LOG_PRETTY"},
Destination: &cfg.Log.Pretty,
},
{
EnvVars: []string{"OCIS_LOG_FILE"},
Destination: &cfg.Log.File,
},
{
EnvVars: []string{"OCIS_TRACING_ENABLED"},
Destination: &cfg.Tracing.Enabled,
},
{
EnvVars: []string{"OCIS_TRACING_TYPE"},
Destination: &cfg.Tracing.Type,
},
{
EnvVars: []string{"OCIS_TRACING_ENDPOINT"},
Destination: &cfg.Tracing.Endpoint,
},
{
EnvVars: []string{"OCIS_TRACING_COLLECTOR"},
Destination: &cfg.Tracing.Collector,
},
{
EnvVars: []string{"OCIS_TRACING_SERVICE"},
Destination: &cfg.Tracing.Service,
},
{
EnvVars: []string{"OCIS_JWT_SECRET"},
Destination: &cfg.TokenManager.JWTSecret,
},
{
EnvVars: []string{"OCIS_RUNTIME_PORT"},
Destination: &cfg.Runtime.Port,
},
{
EnvVars: []string{"OCIS_RUNTIME_HOST"},
Destination: &cfg.Runtime.Host,
},
{
EnvVars: []string{"OCIS_DEBUG_ADDR"},
Destination: &cfg.Debug.Addr,
},
{
EnvVars: []string{"OCIS_DEBUG_TOKEN"},
Destination: &cfg.Debug.Token,
},
{
EnvVars: []string{"OCIS_DEBUG_PPROF"},
Destination: &cfg.Debug.Pprof,
},
{
EnvVars: []string{"OCIS_DEBUG_ZPAGES"},
Destination: &cfg.Debug.Zpages,
},
{
EnvVars: []string{"OCIS_HTTP_ADDR"},
Destination: &cfg.HTTP.Addr,
},
{
EnvVars: []string{"OCIS_HTTP_ROOT"},
Destination: &cfg.HTTP.Root,
},
{
EnvVars: []string{"OCIS_GRPC_ADDR"},
Destination: &cfg.GRPC.Addr,
},
{
EnvVars: []string{"OCIS_RUN_EXTENSIONS"},
Destination: &cfg.Runtime.Extensions,
},
}
}
+5 -6
View File
@@ -4,17 +4,16 @@ import (
"fmt"
"reflect"
"github.com/owncloud/ocis/ocis-pkg/shared"
gofig "github.com/gookit/config/v2"
"github.com/owncloud/ocis/ocis-pkg/shared"
)
// UnbindEnv takes a config `c` and a EnvBinding
func UnbindEnv(c *gofig.Config, bindings []shared.EnvBinding) error {
return unbindEnv(c, bindings)
// BindEnv takes a config `c` and a EnvBinding and binds the values from the environment to the address location in cfg.
func BindEnv(c *gofig.Config, bindings []shared.EnvBinding) error {
return bindEnv(c, bindings)
}
func unbindEnv(c *gofig.Config, bindings []shared.EnvBinding) error {
func bindEnv(c *gofig.Config, bindings []shared.EnvBinding) error {
for i := range bindings {
for j := range bindings[i].EnvVars {
// we need to guard against v != "" because this is the condition that checks that the value is set from the environment.