mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-02-22 21:49:07 -06:00
switch all other services to struct tag based env config
This commit is contained in:
committed by
Jörn Friedrich Dreyer
parent
288d6c469e
commit
6990e7d660
@@ -26,6 +26,7 @@ func Execute(cfg *config.Config) error {
|
||||
Email: "support@owncloud.com",
|
||||
},
|
||||
},
|
||||
|
||||
Before: func(c *cli.Context) error {
|
||||
cfg.Service.Version = version.String
|
||||
return ParseConfig(c, cfg)
|
||||
|
||||
@@ -26,12 +26,12 @@ func Server(cfg *config.Config) *cli.Command {
|
||||
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
|
||||
}
|
||||
|
||||
cfg.Repo.Backend = strings.ToLower(cfg.Repo.Backend)
|
||||
|
||||
if err := ParseConfig(ctx, cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cfg.Repo.Backend = strings.ToLower(cfg.Repo.Backend)
|
||||
|
||||
return nil
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
|
||||
@@ -8,6 +8,15 @@ import (
|
||||
"github.com/owncloud/ocis/ocis-pkg/config/defaults"
|
||||
)
|
||||
|
||||
//TODO: use debug config
|
||||
// Debug defines the available debug configuration.
|
||||
type Debug struct {
|
||||
Addr string `ocisConfig:"addr" env:"ACCOUNTS_DEBUG_ADDR"`
|
||||
Token string `ocisConfig:"token" env:"ACCOUNTS_DEBUG_TOKEN"`
|
||||
Pprof bool `ocisConfig:"pprof" env:"ACCOUNTS_DEBUG_PPROF"`
|
||||
Zpages bool `ocisConfig:"zpages" env:"ACCOUNTS_DEBUG_ZPAGES"`
|
||||
}
|
||||
|
||||
// CORS defines the available cors configuration.
|
||||
type CORS struct {
|
||||
AllowedOrigins []string `ocisConfig:"allowed_origins"`
|
||||
@@ -112,28 +121,28 @@ type Log struct {
|
||||
type Config struct {
|
||||
//*shared.Commons
|
||||
|
||||
HTTP HTTP `ocisConfig:"http"`
|
||||
GRPC GRPC `ocisConfig:"grpc"`
|
||||
Service Service `ocisConfig:"service"`
|
||||
Asset Asset `ocisConfig:"asset"`
|
||||
Log Log `ocisConfig:"log"`
|
||||
TokenManager TokenManager `ocisConfig:"token_manager"`
|
||||
Repo Repo `ocisConfig:"repo"`
|
||||
Index Index `ocisConfig:"index"`
|
||||
ServiceUser ServiceUser `ocisConfig:"service_user"`
|
||||
HashDifficulty int `ocisConfig:"hash_difficulty" env:"ACCOUNTS_HASH_DIFFICULTY"`
|
||||
DemoUsersAndGroups bool `ocisConfig:"demo_users_and_groups" env:"ACCOUNTS_DEMO_USERS_AND_GROUPS"`
|
||||
Tracing Tracing `ocisConfig:"tracing"`
|
||||
Service Service `ocisConfig:"service"`
|
||||
|
||||
Tracing Tracing `ocisConfig:"tracing"`
|
||||
Log Log `ocisConfig:"log"`
|
||||
Debug Debug `ocisConfig:"debug"`
|
||||
|
||||
HTTP HTTP `ocisConfig:"http"`
|
||||
GRPC GRPC `ocisConfig:"grpc"`
|
||||
|
||||
TokenManager TokenManager `ocisConfig:"token_manager"`
|
||||
|
||||
Asset Asset `ocisConfig:"asset"`
|
||||
Repo Repo `ocisConfig:"repo"`
|
||||
Index Index `ocisConfig:"index"`
|
||||
ServiceUser ServiceUser `ocisConfig:"service_user"`
|
||||
HashDifficulty int `ocisConfig:"hash_difficulty" env:"ACCOUNTS_HASH_DIFFICULTY"`
|
||||
DemoUsersAndGroups bool `ocisConfig:"demo_users_and_groups" env:"ACCOUNTS_DEMO_USERS_AND_GROUPS"`
|
||||
|
||||
Context context.Context
|
||||
Supervised bool
|
||||
}
|
||||
|
||||
// New returns a new config.
|
||||
func New() *Config {
|
||||
return &Config{}
|
||||
}
|
||||
|
||||
func DefaultConfig() *Config {
|
||||
return &Config{
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ func init() {
|
||||
grpc.Address("localhost:9180"),
|
||||
)
|
||||
|
||||
cfg := config.New()
|
||||
cfg := config.DefaultConfig()
|
||||
cfg.Repo.Backend = "disk"
|
||||
cfg.Repo.Disk.Path = dataPath
|
||||
cfg.DemoUsersAndGroups = true
|
||||
|
||||
@@ -31,8 +31,7 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
cfg := config.New()
|
||||
cfg.Service.Name = "accounts"
|
||||
cfg := config.DefaultConfig()
|
||||
cfg.Repo.Backend = "disk"
|
||||
cfg.Repo.Disk.Path = dataPath
|
||||
logger := olog.NewLogger(olog.Color(true), olog.Pretty(true))
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := command.Execute(config.New()); err != nil {
|
||||
if err := command.Execute(config.DefaultConfig()); err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,10 +26,12 @@ func Execute(cfg *config.Config) error {
|
||||
Email: "support@owncloud.com",
|
||||
},
|
||||
},
|
||||
|
||||
Before: func(c *cli.Context) error {
|
||||
cfg.Service.Version = version.String
|
||||
return nil
|
||||
return ParseConfig(c, cfg)
|
||||
},
|
||||
|
||||
Commands: []*cli.Command{
|
||||
Server(cfg),
|
||||
Health(cfg),
|
||||
@@ -89,7 +91,7 @@ type SutureService struct {
|
||||
|
||||
// NewSutureService creates a new glauth.SutureService
|
||||
func NewSutureService(cfg *ociscfg.Config) suture.Service {
|
||||
cfg.GLAuth.Commons = cfg.Commons
|
||||
//cfg.GLAuth.Commons = cfg.Commons
|
||||
return SutureService{
|
||||
cfg: cfg.GLAuth,
|
||||
}
|
||||
|
||||
@@ -84,25 +84,24 @@ type FallbackBackend struct {
|
||||
type Config struct {
|
||||
*shared.Commons
|
||||
|
||||
Log Log `ocisConfig:"log"`
|
||||
Debug Debug `ocisConfig:"debug"`
|
||||
Service Service `ocisConfig:"service"`
|
||||
Tracing Tracing `ocisConfig:"tracing"`
|
||||
Ldap Ldap `ocisConfig:"ldap"`
|
||||
Ldaps Ldaps `ocisConfig:"ldaps"`
|
||||
Backend Backend `ocisConfig:"backend"`
|
||||
Fallback FallbackBackend `ocisConfig:"fallback"`
|
||||
RoleBundleUUID string `ocisConfig:"role_bundle_uuid" env:"GLAUTH_ROLE_BUNDLE_ID"`
|
||||
Service Service `ocisConfig:"service"`
|
||||
|
||||
Tracing Tracing `ocisConfig:"tracing"`
|
||||
Log Log `ocisConfig:"log"`
|
||||
Debug Debug `ocisConfig:"debug"`
|
||||
|
||||
Ldap Ldap `ocisConfig:"ldap"`
|
||||
Ldaps Ldaps `ocisConfig:"ldaps"`
|
||||
|
||||
Backend Backend `ocisConfig:"backend"`
|
||||
Fallback FallbackBackend `ocisConfig:"fallback"`
|
||||
|
||||
RoleBundleUUID string `ocisConfig:"role_bundle_uuid" env:"GLAUTH_ROLE_BUNDLE_ID"`
|
||||
|
||||
Context context.Context
|
||||
Supervised bool
|
||||
}
|
||||
|
||||
// New initializes a new configuration with or without defaults.
|
||||
func New() *Config {
|
||||
return &Config{}
|
||||
}
|
||||
|
||||
func DefaultConfig() *Config {
|
||||
return &Config{
|
||||
Debug: Debug{
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/owncloud/ocis/graph-explorer/pkg/config"
|
||||
"github.com/owncloud/ocis/graph-explorer/pkg/logging"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
@@ -17,7 +18,7 @@ func Health(cfg *config.Config) *cli.Command {
|
||||
return ParseConfig(c, cfg)
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
logger := NewLogger(cfg)
|
||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||
|
||||
resp, err := http.Get(
|
||||
fmt.Sprintf(
|
||||
|
||||
@@ -4,12 +4,13 @@ import (
|
||||
"context"
|
||||
"os"
|
||||
|
||||
"github.com/imdario/mergo"
|
||||
"github.com/owncloud/ocis/graph-explorer/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/thejerf/suture/v4"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/wkloucek/envdecode"
|
||||
)
|
||||
|
||||
// Execute is the entry point for the graph-explorer command.
|
||||
@@ -25,10 +26,12 @@ func Execute(cfg *config.Config) error {
|
||||
Email: "support@owncloud.com",
|
||||
},
|
||||
},
|
||||
|
||||
Before: func(c *cli.Context) error {
|
||||
cfg.Service.Version = version.String
|
||||
return ParseConfig(c, cfg)
|
||||
},
|
||||
|
||||
Commands: []*cli.Command{
|
||||
Server(cfg),
|
||||
Health(cfg),
|
||||
@@ -46,27 +49,37 @@ func Execute(cfg *config.Config) error {
|
||||
return app.Run(os.Args)
|
||||
}
|
||||
|
||||
// NewLogger initializes a service-specific logger instance.
|
||||
func NewLogger(cfg *config.Config) log.Logger {
|
||||
return log.NewLogger(
|
||||
log.Name("graph-explorer"),
|
||||
log.Level(cfg.Log.Level),
|
||||
log.Pretty(cfg.Log.Pretty),
|
||||
log.Color(cfg.Log.Color),
|
||||
log.File(cfg.Log.File),
|
||||
)
|
||||
}
|
||||
|
||||
// ParseConfig loads graph configuration from known paths.
|
||||
func ParseConfig(c *cli.Context, cfg *config.Config) error {
|
||||
conf, err := ociscfg.BindSourcesToStructs("graph-explorer", cfg)
|
||||
_, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
conf.LoadOSEnv(config.GetEnv(), false)
|
||||
bindings := config.StructMappings(cfg)
|
||||
return ociscfg.BindEnv(conf, bindings)
|
||||
// provide with defaults for shared logging, since we need a valid destination address for BindEnv.
|
||||
//if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil {
|
||||
// cfg.Log = &shared.Log{
|
||||
// Level: cfg.Commons.Log.Level,
|
||||
// Pretty: cfg.Commons.Log.Pretty,
|
||||
// Color: cfg.Commons.Log.Color,
|
||||
// File: cfg.Commons.Log.File,
|
||||
// }
|
||||
//} else if cfg.Log == nil && cfg.Commons == nil {
|
||||
// cfg.Log = &shared.Log{}
|
||||
//}
|
||||
|
||||
// load all env variables relevant to the config in the current context.
|
||||
envCfg := config.Config{}
|
||||
if err := envdecode.Decode(&envCfg); err != nil && err.Error() != "none of the target fields were set from environment variables" {
|
||||
return err
|
||||
}
|
||||
|
||||
// merge environment variable config on top of the current config
|
||||
if err := mergo.Merge(cfg, envCfg, mergo.WithOverride); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SutureService allows for the graph-explorer command to be embedded and supervised by a suture supervisor tree.
|
||||
@@ -76,7 +89,7 @@ type SutureService struct {
|
||||
|
||||
// NewSutureService creates a new graph-explorer.SutureService
|
||||
func NewSutureService(cfg *ociscfg.Config) suture.Service {
|
||||
cfg.GraphExplorer.Log = cfg.Log
|
||||
//cfg.GraphExplorer.Log = cfg.Log
|
||||
return SutureService{
|
||||
cfg: cfg.GraphExplorer,
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/oklog/run"
|
||||
"github.com/owncloud/ocis/graph-explorer/pkg/config"
|
||||
"github.com/owncloud/ocis/graph-explorer/pkg/logging"
|
||||
"github.com/owncloud/ocis/graph-explorer/pkg/metrics"
|
||||
"github.com/owncloud/ocis/graph-explorer/pkg/server/debug"
|
||||
"github.com/owncloud/ocis/graph-explorer/pkg/server/http"
|
||||
@@ -26,9 +27,11 @@ func Server(cfg *config.Config) *cli.Command {
|
||||
return ParseConfig(ctx, cfg)
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
logger := NewLogger(cfg)
|
||||
tracing.Configure(cfg)
|
||||
|
||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||
err := tracing.Configure(cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var (
|
||||
gr = run.Group{}
|
||||
ctx, cancel = func() (context.Context, context.CancelFunc) {
|
||||
|
||||
@@ -2,70 +2,73 @@ package config
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/owncloud/ocis/ocis-pkg/shared"
|
||||
)
|
||||
|
||||
// Debug defines the available debug configuration.
|
||||
type Debug struct {
|
||||
Addr string `ocisConfig:"addr"`
|
||||
Token string `ocisConfig:"token"`
|
||||
Pprof bool `ocisConfig:"pprof"`
|
||||
Zpages bool `ocisConfig:"zpages"`
|
||||
Addr string `ocisConfig:"addr" env:"GRAPH_EXPLORER_DEBUG_ADDR"`
|
||||
Token string `ocisConfig:"token" env:"GRAPH_EXPLORER_DEBUG_TOKEN"`
|
||||
Pprof bool `ocisConfig:"pprof" env:"GRAPH_EXPLORER_DEBUG_PPROF"`
|
||||
Zpages bool `ocisConfig:"zpages" env:"GRAPH_EXPLORER_DEBUG_ZPAGES"`
|
||||
}
|
||||
|
||||
// HTTP defines the available http configuration.
|
||||
type HTTP struct {
|
||||
Addr string `ocisConfig:"addr"`
|
||||
Root string `ocisConfig:"root"`
|
||||
Addr string `ocisConfig:"addr" env:"GRAPH_EXPLORER_HTTP_ADDR"`
|
||||
Root string `ocisConfig:"root" env:"GRAPH_EXPLORER_HTTP_ROOT"`
|
||||
Namespace string
|
||||
}
|
||||
|
||||
// Service defines the available service configuration.
|
||||
type Service struct {
|
||||
Name string `ocisConfig:"name"`
|
||||
Version string `ocisConfig:"version"`
|
||||
Name string
|
||||
Version string
|
||||
}
|
||||
|
||||
// Tracing defines the available tracing configuration.
|
||||
type Tracing struct {
|
||||
Enabled bool `ocisConfig:"enabled"`
|
||||
Type string `ocisConfig:"type"`
|
||||
Endpoint string `ocisConfig:"endpoint"`
|
||||
Collector string `ocisConfig:"collector"`
|
||||
Service string `ocisConfig:"service"`
|
||||
Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;GRAPH_EXPLORER_TRACING_ENABLED"`
|
||||
Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;GRAPH_EXPLORER_TRACING_TYPE"`
|
||||
Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;GRAPH_EXPLORER_TRACING_ENDPOINT"`
|
||||
Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;GRAPH_EXPLORER_TRACING_COLLECTOR"`
|
||||
Service string `ocisConfig:"service" env:"GRAPH_EXPLORER_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name?
|
||||
}
|
||||
|
||||
// Log defines the available log configuration.
|
||||
type Log struct {
|
||||
Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;GRAPH_EXPLORER_LOG_LEVEL"`
|
||||
Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;GRAPH_EXPLORER_LOG_PRETTY"`
|
||||
Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;GRAPH_EXPLORER_LOG_COLOR"`
|
||||
File string `mapstructure:"file" env:"OCIS_LOG_FILE;GRAPH_EXPLORER_LOG_FILE"`
|
||||
}
|
||||
|
||||
// GraphExplorer defines the available graph-explorer configuration.
|
||||
type GraphExplorer struct {
|
||||
ClientID string `ocisConfig:"client_id"`
|
||||
Issuer string `ocisConfig:"issuer"`
|
||||
GraphURLBase string `ocisConfig:"graph_url_base"`
|
||||
GraphURLPath string `ocisConfig:"graph_url_path"`
|
||||
ClientID string `ocisConfig:"client_id" env:"GRAPH_EXPLORER_CLIENT_ID"`
|
||||
Issuer string `ocisConfig:"issuer" env:"OCIS_URL;GRAPH_EXPLORER_ISSUER"`
|
||||
GraphURLBase string `ocisConfig:"graph_url_base" env:"OCIS_URL;GRAPH_EXPLORER_GRAPH_URL_BASE"`
|
||||
GraphURLPath string `ocisConfig:"graph_url_path" env:"GRAPH_EXPLORER_GRAPH_URL_PATH"`
|
||||
}
|
||||
|
||||
// Config combines all available configuration parts.
|
||||
type Config struct {
|
||||
Log shared.Log `ocisConfig:"log"`
|
||||
Debug Debug `ocisConfig:"debug"`
|
||||
HTTP HTTP `ocisConfig:"http"`
|
||||
Service Service `ocisConfig:"service"`
|
||||
Tracing Tracing `ocisConfig:"tracing"`
|
||||
Service Service `ocisConfig:"service"`
|
||||
|
||||
Tracing Tracing `ocisConfig:"tracing"`
|
||||
Log Log `ocisConfig:"log"`
|
||||
Debug Debug `ocisConfig:"debug"`
|
||||
|
||||
HTTP HTTP `ocisConfig:"http"`
|
||||
|
||||
GraphExplorer GraphExplorer `ocisConfig:"graph_explorer"`
|
||||
|
||||
Context context.Context
|
||||
Supervised bool
|
||||
}
|
||||
|
||||
// New initializes a new configuration with or without defaults.
|
||||
func New() *Config {
|
||||
return &Config{}
|
||||
}
|
||||
|
||||
// DefaultConfig provides with a working version of a config.
|
||||
func DefaultConfig() *Config {
|
||||
return &Config{
|
||||
Log: shared.Log{},
|
||||
Debug: Debug{
|
||||
Addr: "127.0.0.1:9136",
|
||||
Token: "",
|
||||
@@ -78,7 +81,7 @@ func DefaultConfig() *Config {
|
||||
Namespace: "com.owncloud.web",
|
||||
},
|
||||
Service: Service{
|
||||
Name: "graph",
|
||||
Name: "graph-explorer",
|
||||
},
|
||||
Tracing: Tracing{
|
||||
Type: "jaeger",
|
||||
@@ -94,14 +97,3 @@ func DefaultConfig() *Config {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// 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 {
|
||||
var r = make([]string, len(structMappings(&Config{})))
|
||||
for i := range structMappings(&Config{}) {
|
||||
r = append(r, structMappings(&Config{})[i].EnvVars...)
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
@@ -1,96 +0,0 @@
|
||||
package config
|
||||
|
||||
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) []shared.EnvBinding {
|
||||
return []shared.EnvBinding{
|
||||
{
|
||||
EnvVars: []string{"OCIS_LOG_LEVEL", "GRAPH_EXPLORER_LOG_LEVEL"},
|
||||
Destination: &cfg.Log.Level,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_LOG_PRETTY", "GRAPH_EXPLORER_LOG_PRETTY"},
|
||||
Destination: &cfg.Log.Pretty,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_LOG_COLOR", "GRAPH_EXPLORER_LOG_COLOR"},
|
||||
Destination: &cfg.Log.Color,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_LOG_FILE", "GRAPH_EXPLORER_LOG_FILE"},
|
||||
Destination: &cfg.Log.File,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_TRACING_ENABLED", "GRAPH_EXPLORER_TRACING_ENABLED"},
|
||||
Destination: &cfg.Tracing.Enabled,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_TRACING_TYPE", "GRAPH_EXPLORER_TRACING_TYPE"},
|
||||
Destination: &cfg.Tracing.Type,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_TRACING_ENDPOINT", "GRAPH_EXPLORER_TRACING_ENDPOINT"},
|
||||
Destination: &cfg.Tracing.Endpoint,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_TRACING_COLLECTOR", "GRAPH_EXPLORER_TRACING_COLLECTOR"},
|
||||
Destination: &cfg.Tracing.Collector,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"GRAPH_EXPLORER_TRACING_SERVICE"},
|
||||
Destination: &cfg.Tracing.Service,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"GRAPH_EXPLORER_DEBUG_ADDR"},
|
||||
Destination: &cfg.Debug.Addr,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"GRAPH_EXPLORER_DEBUG_TOKEN"},
|
||||
Destination: &cfg.Debug.Token,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"GRAPH_EXPLORER_DEBUG_PPROF"},
|
||||
Destination: &cfg.Debug.Pprof,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"GRAPH_EXPLORER_DEBUG_ZPAGES"},
|
||||
Destination: &cfg.Debug.Zpages,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"GRAPH_EXPLORER_HTTP_ADDR"},
|
||||
Destination: &cfg.HTTP.Addr,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"GRAPH_EXPLORER_HTTP_ROOT"},
|
||||
Destination: &cfg.HTTP.Root,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"GRAPH_EXPLORER_NAMESPACE"},
|
||||
Destination: &cfg.HTTP.Namespace,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_URL", "GRAPH_EXPLORER_ISSUER"},
|
||||
Destination: &cfg.GraphExplorer.Issuer,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"GRAPH_EXPLORER_CLIENT_ID"},
|
||||
Destination: &cfg.GraphExplorer.ClientID,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_URL", "GRAPH_EXPLORER_GRAPH_URL_BASE"},
|
||||
Destination: &cfg.GraphExplorer.GraphURLBase,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"GRAPH_EXPLORER_GRAPH_URL_PATH"},
|
||||
Destination: &cfg.GraphExplorer.GraphURLPath,
|
||||
},
|
||||
}
|
||||
}
|
||||
17
graph-explorer/pkg/logging/logging.go
Normal file
17
graph-explorer/pkg/logging/logging.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package logging
|
||||
|
||||
import (
|
||||
"github.com/owncloud/ocis/graph-explorer/pkg/config"
|
||||
"github.com/owncloud/ocis/ocis-pkg/log"
|
||||
)
|
||||
|
||||
// LoggerFromConfig initializes a service-specific logger instance.
|
||||
func Configure(name string, cfg config.Log) log.Logger {
|
||||
return log.NewLogger(
|
||||
log.Name(name),
|
||||
log.Level(cfg.Level),
|
||||
log.Pretty(cfg.Pretty),
|
||||
log.Color(cfg.Color),
|
||||
log.File(cfg.File),
|
||||
)
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := command.Execute(config.New()); err != nil {
|
||||
if err := command.Execute(config.DefaultConfig()); err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/owncloud/ocis/graph/pkg/config"
|
||||
"github.com/owncloud/ocis/graph/pkg/logging"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
@@ -17,7 +18,7 @@ func Health(cfg *config.Config) *cli.Command {
|
||||
return ParseConfig(c, cfg)
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
logger := NewLogger(cfg)
|
||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||
|
||||
resp, err := http.Get(
|
||||
fmt.Sprintf(
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
|
||||
"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/urfave/cli/v2"
|
||||
)
|
||||
@@ -28,10 +27,12 @@ func Execute(cfg *config.Config) error {
|
||||
Email: "support@owncloud.com",
|
||||
},
|
||||
},
|
||||
|
||||
Before: func(c *cli.Context) error {
|
||||
cfg.Service.Version = version.String
|
||||
return ParseConfig(c, cfg)
|
||||
},
|
||||
|
||||
Commands: []*cli.Command{
|
||||
Server(cfg),
|
||||
Health(cfg),
|
||||
@@ -49,17 +50,6 @@ func Execute(cfg *config.Config) error {
|
||||
return app.Run(os.Args)
|
||||
}
|
||||
|
||||
// NewLogger initializes a service-specific logger instance.
|
||||
func NewLogger(cfg *config.Config) log.Logger {
|
||||
return log.NewLogger(
|
||||
log.Name("graph"),
|
||||
log.Level(cfg.Log.Level),
|
||||
log.Pretty(cfg.Log.Pretty),
|
||||
log.Color(cfg.Log.Color),
|
||||
log.File(cfg.Log.File),
|
||||
)
|
||||
}
|
||||
|
||||
// ParseConfig loads graph configuration from known paths.
|
||||
func ParseConfig(c *cli.Context, cfg *config.Config) error {
|
||||
_, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg)
|
||||
@@ -100,7 +90,7 @@ type SutureService struct {
|
||||
|
||||
// NewSutureService creates a new graph.SutureService
|
||||
func NewSutureService(cfg *ociscfg.Config) suture.Service {
|
||||
cfg.Graph.Commons = cfg.Commons
|
||||
//cfg.Graph.Commons = cfg.Commons
|
||||
return SutureService{
|
||||
cfg: cfg.Graph,
|
||||
}
|
||||
|
||||
@@ -90,25 +90,24 @@ type Identity struct {
|
||||
type Config struct {
|
||||
*shared.Commons
|
||||
|
||||
Log Log `ocisConfig:"log"`
|
||||
Debug Debug `ocisConfig:"debug"`
|
||||
HTTP HTTP `ocisConfig:"http"`
|
||||
Service Service `ocisConfig:"service"`
|
||||
Tracing Tracing `ocisConfig:"tracing"`
|
||||
Service Service `ocisConfig:"service"`
|
||||
|
||||
Tracing Tracing `ocisConfig:"tracing"`
|
||||
Log Log `ocisConfig:"log"`
|
||||
Debug Debug `ocisConfig:"debug"`
|
||||
|
||||
HTTP HTTP `ocisConfig:"http"`
|
||||
|
||||
Reva Reva `ocisConfig:"reva"`
|
||||
TokenManager TokenManager `ocisConfig:"token_manager"`
|
||||
Spaces Spaces `ocisConfig:"spaces"`
|
||||
Identity Identity `ocisConfig:"identity"`
|
||||
|
||||
Spaces Spaces `ocisConfig:"spaces"`
|
||||
Identity Identity `ocisConfig:"identity"`
|
||||
|
||||
Context context.Context
|
||||
Supervised bool
|
||||
}
|
||||
|
||||
// New initializes a new configuration with or without defaults.
|
||||
func New() *Config {
|
||||
return &Config{}
|
||||
}
|
||||
|
||||
func DefaultConfig() *Config {
|
||||
return &Config{
|
||||
Debug: Debug{
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/owncloud/ocis/idp/pkg/config"
|
||||
"github.com/owncloud/ocis/idp/pkg/logging"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
@@ -17,7 +18,7 @@ func Health(cfg *config.Config) *cli.Command {
|
||||
return ParseConfig(c, cfg)
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
logger := NewLogger(cfg)
|
||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||
|
||||
resp, err := http.Get(
|
||||
fmt.Sprintf(
|
||||
|
||||
@@ -4,14 +4,13 @@ import (
|
||||
"context"
|
||||
"os"
|
||||
|
||||
"github.com/owncloud/ocis/ocis-pkg/shared"
|
||||
|
||||
"github.com/imdario/mergo"
|
||||
"github.com/owncloud/ocis/idp/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/thejerf/suture/v4"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/wkloucek/envdecode"
|
||||
)
|
||||
|
||||
// Execute is the entry point for the ocis-idp command.
|
||||
@@ -27,9 +26,10 @@ func Execute(cfg *config.Config) error {
|
||||
Email: "support@owncloud.com",
|
||||
},
|
||||
},
|
||||
|
||||
Before: func(c *cli.Context) error {
|
||||
cfg.Service.Version = version.String
|
||||
return nil
|
||||
return ParseConfig(c, cfg)
|
||||
},
|
||||
|
||||
Commands: []*cli.Command{
|
||||
@@ -52,41 +52,37 @@ func Execute(cfg *config.Config) error {
|
||||
return app.Run(os.Args)
|
||||
}
|
||||
|
||||
// NewLogger initializes a service-specific logger instance.
|
||||
func NewLogger(cfg *config.Config) log.Logger {
|
||||
return log.NewLogger(
|
||||
log.Name("idp"),
|
||||
log.Level(cfg.Log.Level),
|
||||
log.Pretty(cfg.Log.Pretty),
|
||||
log.Color(cfg.Log.Color),
|
||||
log.File(cfg.Log.File),
|
||||
)
|
||||
}
|
||||
|
||||
// ParseConfig loads idp configuration from known paths.
|
||||
func ParseConfig(c *cli.Context, cfg *config.Config) error {
|
||||
conf, err := ociscfg.BindSourcesToStructs("idp", cfg)
|
||||
_, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// provide with defaults for shared logging, since we need a valid destination address for BindEnv.
|
||||
if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil {
|
||||
cfg.Log = &shared.Log{
|
||||
Level: cfg.Commons.Log.Level,
|
||||
Pretty: cfg.Commons.Log.Pretty,
|
||||
Color: cfg.Commons.Log.Color,
|
||||
File: cfg.Commons.Log.File,
|
||||
}
|
||||
} else if cfg.Log == nil && cfg.Commons == nil {
|
||||
cfg.Log = &shared.Log{}
|
||||
}
|
||||
//if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil {
|
||||
// cfg.Log = &shared.Log{
|
||||
// Level: cfg.Commons.Log.Level,
|
||||
// Pretty: cfg.Commons.Log.Pretty,
|
||||
// Color: cfg.Commons.Log.Color,
|
||||
// File: cfg.Commons.Log.File,
|
||||
// }
|
||||
//} else if cfg.Log == nil && cfg.Commons == nil {
|
||||
// cfg.Log = &shared.Log{}
|
||||
//}
|
||||
|
||||
// load all env variables relevant to the config in the current context.
|
||||
conf.LoadOSEnv(config.GetEnv(cfg), false)
|
||||
envCfg := config.Config{}
|
||||
if err := envdecode.Decode(&envCfg); err != nil && err.Error() != "none of the target fields were set from environment variables" {
|
||||
return err
|
||||
}
|
||||
|
||||
bindings := config.StructMappings(cfg)
|
||||
return ociscfg.BindEnv(conf, bindings)
|
||||
// merge environment variable config on top of the current config
|
||||
if err := mergo.Merge(cfg, envCfg, mergo.WithOverride); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SutureService allows for the idp command to be embedded and supervised by a suture supervisor tree.
|
||||
@@ -96,7 +92,7 @@ type SutureService struct {
|
||||
|
||||
// NewSutureService creates a new idp.SutureService
|
||||
func NewSutureService(cfg *ociscfg.Config) suture.Service {
|
||||
cfg.IDP.Commons = cfg.Commons
|
||||
//cfg.IDP.Commons = cfg.Commons
|
||||
return SutureService{
|
||||
cfg: cfg.IDP,
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/oklog/run"
|
||||
"github.com/owncloud/ocis/idp/pkg/config"
|
||||
"github.com/owncloud/ocis/idp/pkg/logging"
|
||||
"github.com/owncloud/ocis/idp/pkg/metrics"
|
||||
"github.com/owncloud/ocis/idp/pkg/server/debug"
|
||||
"github.com/owncloud/ocis/idp/pkg/server/http"
|
||||
@@ -30,10 +31,11 @@ func Server(cfg *config.Config) *cli.Command {
|
||||
return nil
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
logger := NewLogger(cfg)
|
||||
|
||||
tracing.Configure(cfg)
|
||||
|
||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||
err := tracing.Configure(cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var (
|
||||
gr = run.Group{}
|
||||
ctx, cancel = func() (context.Context, context.CancelFunc) {
|
||||
|
||||
@@ -11,113 +11,139 @@ import (
|
||||
|
||||
// Debug defines the available debug configuration.
|
||||
type Debug struct {
|
||||
Addr string `ocisConfig:"addr"`
|
||||
Token string `ocisConfig:"token"`
|
||||
Pprof bool `ocisConfig:"pprof"`
|
||||
Zpages bool `ocisConfig:"zpages"`
|
||||
Addr string `ocisConfig:"addr" env:"IDP_DEBUG_ADDR"`
|
||||
Token string `ocisConfig:"token" env:"IDP_DEBUG_TOKEN"`
|
||||
Pprof bool `ocisConfig:"pprof" env:"IDP_DEBUG_PPROF"`
|
||||
Zpages bool `ocisConfig:"zpages" env:"IDP_DEBUG_ZPAGES"`
|
||||
}
|
||||
|
||||
// HTTP defines the available http configuration.
|
||||
type HTTP struct {
|
||||
Addr string `ocisConfig:"addr"`
|
||||
Root string `ocisConfig:"root"`
|
||||
Namespace string `ocisConfig:"namespace"`
|
||||
TLSCert string `ocisConfig:"tls_cert"`
|
||||
TLSKey string `ocisConfig:"tls_key"`
|
||||
TLS bool `ocisConfig:"tls"`
|
||||
Addr string `ocisConfig:"addr" env:"IDP_HTTP_ADDR"`
|
||||
Root string `ocisConfig:"root" env:"IDP_HTTP_ROOT"`
|
||||
Namespace string
|
||||
TLSCert string `ocisConfig:"tls_cert" env:"IDP_TRANSPORT_TLS_CERT"`
|
||||
TLSKey string `ocisConfig:"tls_key" env:"IDP_TRANSPORT_TLS_KEY"`
|
||||
TLS bool `ocisConfig:"tls" env:"IDP_TLS"`
|
||||
}
|
||||
|
||||
// Service defines the available service configuration.
|
||||
type Service struct {
|
||||
Name string `ocisConfig:"name"`
|
||||
Version string `ocisConfig:"version"`
|
||||
Name string
|
||||
Version string
|
||||
}
|
||||
|
||||
// Ldap defines the available LDAP configuration.
|
||||
type Ldap struct {
|
||||
URI string `ocisConfig:"uri"`
|
||||
BindDN string `ocisConfig:"bind_dn"`
|
||||
BindPassword string `ocisConfig:"bind_password"`
|
||||
BaseDN string `ocisConfig:"base_dn"`
|
||||
Scope string `ocisConfig:"scope"`
|
||||
LoginAttribute string `ocisConfig:"login_attribute"`
|
||||
EmailAttribute string `ocisConfig:"email_attribute"`
|
||||
NameAttribute string `ocisConfig:"name_attribute"`
|
||||
UUIDAttribute string `ocisConfig:"uuid_attribute"`
|
||||
UUIDAttributeType string `ocisConfig:"uuid_attribute_type"`
|
||||
Filter string `ocisConfig:"filter"`
|
||||
URI string `ocisConfig:"uri" env:"IDP_LDAP_URI"`
|
||||
|
||||
BindDN string `ocisConfig:"bind_dn" env:"IDP_LDAP_BIND_DN"`
|
||||
BindPassword string `ocisConfig:"bind_password" env:"IDP_LDAP_BIND_PASSWORD"`
|
||||
|
||||
BaseDN string `ocisConfig:"base_dn" env:"IDP_LDAP_BASE_DN"`
|
||||
Scope string `ocisConfig:"scope" env:"IDP_LDAP_SCOPE"`
|
||||
|
||||
LoginAttribute string `ocisConfig:"login_attribute" env:"IDP_LDAP_LOGIN_ATTRIBUTE"`
|
||||
EmailAttribute string `ocisConfig:"email_attribute" env:"IDP_LDAP_EMAIL_ATTRIBUTE"`
|
||||
NameAttribute string `ocisConfig:"name_attribute" env:"IDP_LDAP_NAME_ATTRIBUTE"`
|
||||
UUIDAttribute string `ocisConfig:"uuid_attribute" env:"IDP_LDAP_UUID_ATTRIBUTE"`
|
||||
UUIDAttributeType string `ocisConfig:"uuid_attribute_type" env:"IDP_LDAP_UUID_ATTRIBUTE_TYPE"`
|
||||
|
||||
Filter string `ocisConfig:"filter" env:"IDP_LDAP_FILTER"`
|
||||
}
|
||||
|
||||
// Tracing defines the available tracing configuration.
|
||||
type Tracing struct {
|
||||
Enabled bool `ocisConfig:"enabled"`
|
||||
Type string `ocisConfig:"type"`
|
||||
Endpoint string `ocisConfig:"endpoint"`
|
||||
Collector string `ocisConfig:"collector"`
|
||||
Service string `ocisConfig:"service"`
|
||||
Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;IDP_TRACING_ENABLED"`
|
||||
Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;IDP_TRACING_TYPE"`
|
||||
Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;IDP_TRACING_ENDPOINT"`
|
||||
Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;IDP_TRACING_COLLECTOR"`
|
||||
Service string `ocisConfig:"service" env:"IDP_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name?
|
||||
}
|
||||
|
||||
// Log defines the available log configuration.
|
||||
type Log struct {
|
||||
Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;IDP_LOG_LEVEL"`
|
||||
Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;IDP_LOG_PRETTY"`
|
||||
Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;IDP_LOG_COLOR"`
|
||||
File string `mapstructure:"file" env:"OCIS_LOG_FILE;IDP_LOG_FILE"`
|
||||
}
|
||||
|
||||
// Asset defines the available asset configuration.
|
||||
type Asset struct {
|
||||
Path string `ocisConfig:"asset"`
|
||||
Path string `ocisConfig:"asset" env:"IDP_ASSET_PATH"`
|
||||
}
|
||||
|
||||
type Settings struct {
|
||||
Iss string `ocisConfig:"iss"`
|
||||
IdentityManager string `ocisConfig:"identity_manager"`
|
||||
URIBasePath string `ocisConfig:"uri_base_path"`
|
||||
SignInURI string `ocisConfig:"sign_in_uri"`
|
||||
SignedOutURI string `ocisConfig:"signed_out_uri"`
|
||||
AuthorizationEndpointURI string `ocisConfig:"authorization_endpoint_uri"`
|
||||
EndsessionEndpointURI string `ocisConfig:"end_session_endpoint_uri"`
|
||||
Insecure bool `ocisConfig:"insecure"`
|
||||
TrustedProxy []string `ocisConfig:"trusted_proxy"`
|
||||
AllowScope []string `ocisConfig:"allow_scope"`
|
||||
AllowClientGuests bool `ocisConfig:"allow_client_guests"`
|
||||
AllowDynamicClientRegistration bool `ocisConfig:"allow_dynamic_client_registration"`
|
||||
EncryptionSecretFile string `ocisConfig:"encrypt_secret_file"`
|
||||
Listen string `ocisConfig:"listen"`
|
||||
IdentifierClientDisabled bool `ocisConfig:"identifier_client_disabled"`
|
||||
IdentifierClientPath string `ocisConfig:"identifier_client_path"`
|
||||
IdentifierRegistrationConf string `ocisConfig:"identifier_registration_conf"`
|
||||
IdentifierScopesConf string `ocisConfig:"identifier_scopes_conf"`
|
||||
IdentifierDefaultBannerLogo string `ocisConfig:"identifier_default_banner_logo"`
|
||||
IdentifierDefaultSignInPageText string `ocisConfig:"identifier_default_sign_in_page_text"`
|
||||
IdentifierDefaultUsernameHintText string `ocisConfig:"identifier_default_username_hint_text"`
|
||||
SigningKid string `ocisConfig:"sign_in_kid"`
|
||||
SigningMethod string `ocisConfig:"sign_in_method"`
|
||||
SigningPrivateKeyFiles []string `ocisConfig:"sign_in_private_key_files"`
|
||||
ValidationKeysPath string `ocisConfig:"validation_keys_path"`
|
||||
CookieBackendURI string `ocisConfig:"cookie_backend_uri"`
|
||||
CookieNames []string `ocisConfig:"cookie_names"`
|
||||
AccessTokenDurationSeconds uint64 `ocisConfig:"access_token_duration_seconds"`
|
||||
IDTokenDurationSeconds uint64 `ocisConfig:"id_token_duration_seconds"`
|
||||
RefreshTokenDurationSeconds uint64 `ocisConfig:"refresh_token_duration_seconds"`
|
||||
DyamicClientSecretDurationSeconds uint64 `ocisConfig:"dynamic_client_secret_duration_seconds"`
|
||||
// don't change the order of elements in this struct
|
||||
// it needs to match github.com/libregraph/lico/bootstrap.Settings
|
||||
|
||||
Iss string `ocisConfig:"iss" env:"OCIS_URL;IDP_ISS"`
|
||||
|
||||
IdentityManager string `ocisConfig:"identity_manager" env:"IDP_IDENTITY_MANAGER"`
|
||||
|
||||
URIBasePath string `ocisConfig:"uri_base_path" env:"IDP_URI_BASE_PATH"`
|
||||
|
||||
SignInURI string `ocisConfig:"sign_in_uri" env:"IDP_SIGN_IN_URI"`
|
||||
SignedOutURI string `ocisConfig:"signed_out_uri" env:"IDP_SIGN_OUT_URI"`
|
||||
|
||||
AuthorizationEndpointURI string `ocisConfig:"authorization_endpoint_uri" env:"IDP_ENDPOINT_URI"`
|
||||
EndsessionEndpointURI string `ocisConfig:"end_session_endpoint_uri" env:"IDP_ENDSESSION_ENDPOINT_URI"`
|
||||
|
||||
Insecure bool `ocisConfig:"insecure" env:"IDP_INSECURE"`
|
||||
|
||||
TrustedProxy []string `ocisConfig:"trusted_proxy"` //TODO: how to configure this via env?
|
||||
|
||||
AllowScope []string `ocisConfig:"allow_scope"` // TODO: is this even needed?
|
||||
AllowClientGuests bool `ocisConfig:"allow_client_guests" env:"IDP_ALLOW_CLIENT_GUESTS"`
|
||||
AllowDynamicClientRegistration bool `ocisConfig:"allow_dynamic_client_registration" env:"IDP_ALLOW_DYNAMIC_CLIENT_REGISTRATION"`
|
||||
|
||||
EncryptionSecretFile string `ocisConfig:"encrypt_secret_file" env:"IDP_ENCRYPTION_SECRET"`
|
||||
|
||||
Listen string `ocisConfig:"listen"` //TODO: is this even needed?
|
||||
|
||||
IdentifierClientDisabled bool `ocisConfig:"identifier_client_disabled" env:"IDP_DISABLE_IDENTIFIER_WEBAPP"`
|
||||
IdentifierClientPath string `ocisConfig:"identifier_client_path" env:"IDP_IDENTIFIER_CLIENT_PATH"`
|
||||
IdentifierRegistrationConf string `ocisConfig:"identifier_registration_conf" env:"IDP_IDENTIFIER_REGISTRATION_CONF"`
|
||||
IdentifierScopesConf string `ocisConfig:"identifier_scopes_conf" env:"IDP_IDENTIFIER_SCOPES_CONF"`
|
||||
IdentifierDefaultBannerLogo string `ocisConfig:"identifier_default_banner_logo"` // TODO: is this even needed?
|
||||
IdentifierDefaultSignInPageText string `ocisConfig:"identifier_default_sign_in_page_text"` // TODO: is this even needed?
|
||||
IdentifierDefaultUsernameHintText string `ocisConfig:"identifier_default_username_hint_text"` // TODO: is this even needed?
|
||||
|
||||
SigningKid string `ocisConfig:"sign_in_kid" env:"IDP_SIGNING_KID"`
|
||||
SigningMethod string `ocisConfig:"sign_in_method" env:"IDP_SIGNING_METHOD"`
|
||||
SigningPrivateKeyFiles []string `ocisConfig:"sign_in_private_key_files"` // TODO: is this even needed?
|
||||
ValidationKeysPath string `ocisConfig:"validation_keys_path" env:"IDP_VALIDATION_KEYS_PATH"`
|
||||
|
||||
CookieBackendURI string `ocisConfig:"cookie_backend_uri"` // TODO: is this even needed?
|
||||
CookieNames []string `ocisConfig:"cookie_names"` // TODO: is this even needed?
|
||||
|
||||
AccessTokenDurationSeconds uint64 `ocisConfig:"access_token_duration_seconds" env:"IDP_ACCESS_TOKEN_EXPIRATION"`
|
||||
IDTokenDurationSeconds uint64 `ocisConfig:"id_token_duration_seconds" env:"IDP_ID_TOKEN_EXPIRATION"`
|
||||
RefreshTokenDurationSeconds uint64 `ocisConfig:"refresh_token_duration_seconds" env:"IDP_REFRESH_TOKEN_EXPIRATION"`
|
||||
DyamicClientSecretDurationSeconds uint64 `ocisConfig:"dynamic_client_secret_duration_seconds" env:""`
|
||||
}
|
||||
|
||||
// Config combines all available configuration parts.
|
||||
type Config struct {
|
||||
*shared.Commons
|
||||
|
||||
Log *shared.Log `ocisConfig:"log"`
|
||||
Debug Debug `ocisConfig:"debug"`
|
||||
HTTP HTTP `ocisConfig:"http"`
|
||||
Tracing Tracing `ocisConfig:"tracing"`
|
||||
Asset Asset `ocisConfig:"asset"`
|
||||
IDP Settings `ocisConfig:"idp"`
|
||||
Ldap Ldap `ocisConfig:"ldap"`
|
||||
Service Service `ocisConfig:"service"`
|
||||
Service Service `ocisConfig:"service"`
|
||||
|
||||
Tracing Tracing `ocisConfig:"tracing"`
|
||||
Log Log `ocisConfig:"log"`
|
||||
Debug Debug `ocisConfig:"debug"`
|
||||
|
||||
HTTP HTTP `ocisConfig:"http"`
|
||||
|
||||
Asset Asset `ocisConfig:"asset"`
|
||||
IDP Settings `ocisConfig:"idp"`
|
||||
Ldap Ldap `ocisConfig:"ldap"`
|
||||
|
||||
Context context.Context
|
||||
Supervised bool
|
||||
}
|
||||
|
||||
// New initializes a new configuration with or without defaults.
|
||||
func New() *Config {
|
||||
return &Config{}
|
||||
}
|
||||
|
||||
func DefaultConfig() *Config {
|
||||
return &Config{
|
||||
Debug: Debug{
|
||||
|
||||
@@ -1,239 +0,0 @@
|
||||
package config
|
||||
|
||||
import "github.com/owncloud/ocis/ocis-pkg/shared"
|
||||
|
||||
// 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(cfg *Config) []string {
|
||||
var r = make([]string, len(structMappings(cfg)))
|
||||
for i := range structMappings(cfg) {
|
||||
r = append(r, structMappings(cfg)[i].EnvVars...)
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
// 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) []shared.EnvBinding {
|
||||
return []shared.EnvBinding{
|
||||
{
|
||||
EnvVars: []string{"OCIS_LOG_LEVEL", "IDP_LOG_LEVEL"},
|
||||
Destination: &cfg.Log.Level,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_LOG_PRETTY", "IDP_LOG_PRETTY"},
|
||||
Destination: &cfg.Log.Pretty,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_LOG_COLOR", "IDP_LOG_COLOR"},
|
||||
Destination: &cfg.Log.Color,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_LOG_FILE", "IDP_LOG_FILE"},
|
||||
Destination: &cfg.Log.File,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_CONFIG_FILE"},
|
||||
Destination: &cfg.File,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_TRACING_ENABLED", "IDP_TRACING_ENABLED"},
|
||||
Destination: &cfg.Tracing.Enabled,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_TRACING_TYPE", "IDP_TRACING_TYPE"},
|
||||
Destination: &cfg.Tracing.Type,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_TRACING_ENDPOINT", "IDP_TRACING_ENDPOINT"},
|
||||
Destination: &cfg.Tracing.Endpoint,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_TRACING_COLLECTOR", "IDP_TRACING_COLLECTOR"},
|
||||
Destination: &cfg.Tracing.Collector,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_TRACING_SERVICE"},
|
||||
Destination: &cfg.Tracing.Service,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_DEBUG_ADDR"},
|
||||
Destination: &cfg.Debug.Addr,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_DEBUG_TOKEN"},
|
||||
Destination: &cfg.Debug.Token,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_DEBUG_PPROF"},
|
||||
Destination: &cfg.Debug.Pprof,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_DEBUG_ZPAGES"},
|
||||
Destination: &cfg.Debug.Zpages,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_HTTP_ADDR"},
|
||||
Destination: &cfg.HTTP.Addr,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_HTTP_ROOT"},
|
||||
Destination: &cfg.HTTP.Root,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_HTTP_NAMESPACE"},
|
||||
Destination: &cfg.HTTP.Namespace,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_IDENTITY_MANAGER"},
|
||||
Destination: &cfg.IDP.IdentityManager,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_LDAP_URI"},
|
||||
Destination: &cfg.Ldap.URI,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_LDAP_BIND_DN"},
|
||||
Destination: &cfg.Ldap.BindDN,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_LDAP_BIND_PASSWORD"},
|
||||
Destination: &cfg.Ldap.BindPassword,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_LDAP_BASE_DN"},
|
||||
Destination: &cfg.Ldap.BaseDN,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_LDAP_SCOPE"},
|
||||
Destination: &cfg.Ldap.Scope,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_LDAP_LOGIN_ATTRIBUTE"},
|
||||
Destination: &cfg.Ldap.LoginAttribute,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_LDAP_EMAIL_ATTRIBUTE"},
|
||||
Destination: &cfg.Ldap.EmailAttribute,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_LDAP_NAME_ATTRIBUTE"},
|
||||
Destination: &cfg.Ldap.NameAttribute,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_LDAP_UUID_ATTRIBUTE"},
|
||||
Destination: &cfg.Ldap.UUIDAttribute,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_LDAP_UUID_ATTRIBUTE_TYPE"},
|
||||
Destination: &cfg.Ldap.UUIDAttributeType,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_LDAP_FILTER"},
|
||||
Destination: &cfg.Ldap.Filter,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_TRANSPORT_TLS_CERT"},
|
||||
Destination: &cfg.HTTP.TLSCert,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_TRANSPORT_TLS_KEY"},
|
||||
Destination: &cfg.HTTP.TLSKey,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_URL", "IDP_ISS"}, // IDP_ISS takes precedence over OCIS_URL
|
||||
Destination: &cfg.IDP.Iss,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_SIGNING_KID"},
|
||||
Destination: &cfg.IDP.SigningKid,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_VALIDATION_KEYS_PATH"},
|
||||
Destination: &cfg.IDP.ValidationKeysPath,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_ENCRYPTION_SECRET"},
|
||||
Destination: &cfg.IDP.EncryptionSecretFile,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_SIGNING_METHOD"},
|
||||
Destination: &cfg.IDP.SigningMethod,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_URI_BASE_PATH"},
|
||||
Destination: &cfg.IDP.URIBasePath,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_SIGN_IN_URI"},
|
||||
Destination: &cfg.IDP.SignInURI,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_SIGN_OUT_URI"},
|
||||
Destination: &cfg.IDP.SignedOutURI,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_ENDPOINT_URI"},
|
||||
Destination: &cfg.IDP.AuthorizationEndpointURI,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_ENDSESSION_ENDPOINT_URI"},
|
||||
Destination: &cfg.IDP.EndsessionEndpointURI,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_ASSET_PATH"},
|
||||
Destination: &cfg.Asset.Path,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_IDENTIFIER_CLIENT_PATH"},
|
||||
Destination: &cfg.IDP.IdentifierClientPath,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_IDENTIFIER_REGISTRATION_CONF"},
|
||||
Destination: &cfg.IDP.IdentifierRegistrationConf,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_IDENTIFIER_SCOPES_CONF"},
|
||||
Destination: &cfg.IDP.IdentifierScopesConf,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_INSECURE"},
|
||||
Destination: &cfg.IDP.Insecure,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_TLS"},
|
||||
Destination: &cfg.HTTP.TLS,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_ALLOW_CLIENT_GUESTS"},
|
||||
Destination: &cfg.IDP.AllowClientGuests,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_ALLOW_DYNAMIC_CLIENT_REGISTRATION"},
|
||||
Destination: &cfg.IDP.AllowDynamicClientRegistration,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_DISABLE_IDENTIFIER_WEBAPP"},
|
||||
Destination: &cfg.IDP.IdentifierClientDisabled,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_ACCESS_TOKEN_EXPIRATION"},
|
||||
Destination: &cfg.IDP.AccessTokenDurationSeconds,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_ID_TOKEN_EXPIRATION"},
|
||||
Destination: &cfg.IDP.IDTokenDurationSeconds,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"IDP_REFRESH_TOKEN_EXPIRATION"},
|
||||
Destination: &cfg.IDP.RefreshTokenDurationSeconds,
|
||||
},
|
||||
}
|
||||
}
|
||||
17
idp/pkg/logging/logging.go
Normal file
17
idp/pkg/logging/logging.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package logging
|
||||
|
||||
import (
|
||||
"github.com/owncloud/ocis/idp/pkg/config"
|
||||
"github.com/owncloud/ocis/ocis-pkg/log"
|
||||
)
|
||||
|
||||
// LoggerFromConfig initializes a service-specific logger instance.
|
||||
func Configure(name string, cfg config.Log) log.Logger {
|
||||
return log.NewLogger(
|
||||
log.Name(name),
|
||||
log.Level(cfg.Level),
|
||||
log.Pretty(cfg.Pretty),
|
||||
log.Color(cfg.Color),
|
||||
log.File(cfg.File),
|
||||
)
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
package log
|
||||
package logging
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/sirupsen/logrus"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
type levelMap map[logrus.Level]zerolog.Level
|
||||
@@ -70,7 +70,7 @@ func Server(opts ...Option) (http.Service, error) {
|
||||
|
||||
{
|
||||
handle = svc.NewInstrument(handle, options.Metrics)
|
||||
handle = svc.NewLogging(handle, options.Logger)
|
||||
handle = svc.NewLoggingHandler(handle, options.Logger)
|
||||
}
|
||||
|
||||
if err := micro.RegisterHandler(service.Server(), handle); err != nil {
|
||||
|
||||
@@ -7,19 +7,19 @@ import (
|
||||
)
|
||||
|
||||
// NewLogging returns a service that logs messages.
|
||||
func NewLogging(next Service, logger log.Logger) Service {
|
||||
return logging{
|
||||
func NewLoggingHandler(next Service, logger log.Logger) Service {
|
||||
return loggingHandler{
|
||||
next: next,
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
|
||||
type logging struct {
|
||||
type loggingHandler struct {
|
||||
next Service
|
||||
logger log.Logger
|
||||
}
|
||||
|
||||
// ServeHTTP implements the Service interface.
|
||||
func (l logging) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
func (l loggingHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
l.next.ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
"github.com/libregraph/lico/server"
|
||||
"github.com/owncloud/ocis/idp/pkg/assets"
|
||||
"github.com/owncloud/ocis/idp/pkg/config"
|
||||
logw "github.com/owncloud/ocis/idp/pkg/log"
|
||||
"github.com/owncloud/ocis/idp/pkg/logging"
|
||||
"github.com/owncloud/ocis/idp/pkg/middleware"
|
||||
"github.com/owncloud/ocis/ocis-pkg/log"
|
||||
"stash.kopano.io/kgol/rndm"
|
||||
@@ -59,7 +59,7 @@ func NewService(opts ...Option) Service {
|
||||
idpSettings := bootstrap.Settings(options.Config.IDP)
|
||||
|
||||
bs, err := bootstrap.Boot(ctx, &idpSettings, &licoconfig.Config{
|
||||
Logger: logw.Wrap(logger),
|
||||
Logger: logging.Wrap(logger),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
||||
@@ -42,6 +42,28 @@ const (
|
||||
|
||||
type Mode int
|
||||
|
||||
// Service defines the available service configuration.
|
||||
type Service struct {
|
||||
Name string
|
||||
Version string
|
||||
}
|
||||
|
||||
// Debug defines the available debug configuration.
|
||||
type Debug struct {
|
||||
Addr string `ocisConfig:"addr" env:"ACCOUNTS_DEBUG_ADDR"`
|
||||
Token string `ocisConfig:"token" env:"ACCOUNTS_DEBUG_TOKEN"`
|
||||
Pprof bool `ocisConfig:"pprof" env:"ACCOUNTS_DEBUG_PPROF"`
|
||||
Zpages bool `ocisConfig:"zpages" env:"ACCOUNTS_DEBUG_ZPAGES"`
|
||||
}
|
||||
|
||||
// Log defines the available log configuration.
|
||||
type Log struct {
|
||||
Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL"`
|
||||
Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY"`
|
||||
Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR"`
|
||||
File string `mapstructure:"file" env:"OCIS_LOG_FILE"`
|
||||
}
|
||||
|
||||
// Runtime configures the oCIS runtime when running in supervised mode.
|
||||
type Runtime struct {
|
||||
Port string `ocisConfig:"port"`
|
||||
@@ -53,13 +75,17 @@ type Runtime struct {
|
||||
type Config struct {
|
||||
*shared.Commons `ocisConfig:"shared"`
|
||||
|
||||
Service Service `ocisConfig:"service"`
|
||||
|
||||
Tracing Tracing `ocisConfig:"tracing"`
|
||||
Log Log `ocisConfig:"log"`
|
||||
Debug Debug `ocisConfig:"debug"`
|
||||
|
||||
Mode Mode // DEPRECATED
|
||||
File string
|
||||
OcisURL string `ocisConfig:"ocis_url"`
|
||||
|
||||
Registry string `ocisConfig:"registry"`
|
||||
Log shared.Log `ocisConfig:"log"`
|
||||
Tracing Tracing `ocisConfig:"tracing"`
|
||||
TokenManager TokenManager `ocisConfig:"token_manager"`
|
||||
Runtime Runtime `ocisConfig:"runtime"`
|
||||
|
||||
@@ -78,25 +104,6 @@ type Config struct {
|
||||
WebDAV *webdav.Config `ocisConfig:"webdav"`
|
||||
}
|
||||
|
||||
// New initializes a new configuration with or without defaults.
|
||||
func New() *Config {
|
||||
return &Config{
|
||||
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.DefaultConfig(),
|
||||
}
|
||||
}
|
||||
|
||||
func DefaultConfig() *Config {
|
||||
return &Config{
|
||||
Tracing: Tracing{
|
||||
@@ -149,6 +156,7 @@ func StructMappings(cfg *Config) []shared.EnvBinding {
|
||||
|
||||
func structMappings(cfg *Config) []shared.EnvBinding {
|
||||
return []shared.EnvBinding{
|
||||
// TODO: transform this too
|
||||
{
|
||||
EnvVars: []string{"OCIS_LOG_LEVEL"},
|
||||
Destination: &cfg.Log.Level,
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
//go:build !simple
|
||||
// +build !simple
|
||||
|
||||
package command
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
//go:build !simple
|
||||
// +build !simple
|
||||
|
||||
package command
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
//go:build !simple
|
||||
// +build !simple
|
||||
|
||||
package command
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
//go:build !simple
|
||||
// +build !simple
|
||||
|
||||
package command
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
//go:build !simple
|
||||
// +build !simple
|
||||
|
||||
package command
|
||||
|
||||
import (
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
|
||||
"github.com/owncloud/ocis/ocis-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/owncloud/ocis/ocis/pkg/register"
|
||||
"github.com/urfave/cli/v2"
|
||||
@@ -20,9 +19,12 @@ func Execute() error {
|
||||
Version: version.String,
|
||||
Usage: "ownCloud Infinite Scale Stack",
|
||||
Compiled: version.Compiled(),
|
||||
|
||||
Before: func(c *cli.Context) error {
|
||||
//cfg.Service.Version = version.String
|
||||
return ParseConfig(c, cfg)
|
||||
},
|
||||
|
||||
Authors: []*cli.Author{
|
||||
{
|
||||
Name: "ownCloud GmbH",
|
||||
@@ -51,17 +53,6 @@ func Execute() error {
|
||||
return app.Run(os.Args)
|
||||
}
|
||||
|
||||
// NewLogger initializes a service-specific logger instance
|
||||
func NewLogger(cfg *config.Config) log.Logger {
|
||||
return log.NewLogger(
|
||||
log.Name("ocis"),
|
||||
log.Level(cfg.Log.Level),
|
||||
log.Pretty(cfg.Log.Pretty),
|
||||
log.Color(cfg.Log.Color),
|
||||
log.File(cfg.Log.File),
|
||||
)
|
||||
}
|
||||
|
||||
// ParseConfig loads ocis configuration.
|
||||
func ParseConfig(c *cli.Context, cfg *config.Config) error {
|
||||
conf, err := ociscfg.BindSourcesToStructs("ocis", cfg)
|
||||
@@ -69,6 +60,8 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// TODO: use envconfig here too
|
||||
|
||||
conf.LoadOSEnv(config.GetEnv(), false)
|
||||
|
||||
bindings := config.StructMappings(cfg)
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
//go:build !simple
|
||||
// +build !simple
|
||||
|
||||
package command
|
||||
|
||||
import (
|
||||
"github.com/owncloud/ocis/ocis-pkg/shared"
|
||||
|
||||
"github.com/owncloud/ocis/ocis-pkg/config"
|
||||
"github.com/owncloud/ocis/ocis/pkg/register"
|
||||
"github.com/owncloud/ocis/ocis/pkg/runtime"
|
||||
@@ -23,9 +18,9 @@ func Server(cfg *config.Config) *cli.Command {
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
|
||||
cfg.Commons = &shared.Commons{
|
||||
Log: &cfg.Log,
|
||||
}
|
||||
//cfg.Commons = &shared.Commons{
|
||||
// Log: &cfg.Log,
|
||||
//}
|
||||
|
||||
r := runtime.New(cfg)
|
||||
return r.Start()
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
//go:build !simple
|
||||
// +build !simple
|
||||
|
||||
package command
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
//go:build !simple
|
||||
// +build !simple
|
||||
|
||||
package command
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
//go:build !simple
|
||||
// +build !simple
|
||||
|
||||
package command
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
//go:build !simple
|
||||
// +build !simple
|
||||
|
||||
package command
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
//go:build !simple
|
||||
// +build !simple
|
||||
|
||||
package command
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
//go:build !simple
|
||||
// +build !simple
|
||||
|
||||
package command
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
//go:build !simple
|
||||
// +build !simple
|
||||
|
||||
package command
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
//go:build !simple
|
||||
// +build !simple
|
||||
|
||||
package command
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
//go:build !simple
|
||||
// +build !simple
|
||||
|
||||
package command
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
//go:build !simple
|
||||
// +build !simple
|
||||
|
||||
package command
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
//go:build !simple
|
||||
// +build !simple
|
||||
|
||||
package command
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
//go:build !simple
|
||||
// +build !simple
|
||||
|
||||
package command
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
//go:build !simple
|
||||
// +build !simple
|
||||
|
||||
package command
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
//go:build !simple
|
||||
// +build !simple
|
||||
|
||||
package command
|
||||
|
||||
import (
|
||||
"github.com/owncloud/ocis/ocis-pkg/config"
|
||||
"github.com/owncloud/ocis/ocis-pkg/shared"
|
||||
"github.com/owncloud/ocis/ocis/pkg/register"
|
||||
"github.com/owncloud/ocis/store/pkg/command"
|
||||
"github.com/urfave/cli/v2"
|
||||
@@ -13,7 +9,7 @@ import (
|
||||
|
||||
// StoreCommand is the entrypoint for the ocs command.
|
||||
func StoreCommand(cfg *config.Config) *cli.Command {
|
||||
var globalLog shared.Log
|
||||
//var globalLog shared.Log
|
||||
|
||||
return &cli.Command{
|
||||
Name: "store",
|
||||
@@ -27,16 +23,16 @@ func StoreCommand(cfg *config.Config) *cli.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
globalLog = cfg.Log
|
||||
//globalLog = cfg.Log
|
||||
|
||||
return nil
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
// if accounts logging is empty in ocis.yaml
|
||||
if (cfg.Store.Log == shared.Log{}) && (globalLog != shared.Log{}) {
|
||||
// we can safely inherit the global logging values.
|
||||
cfg.Store.Log = globalLog
|
||||
}
|
||||
//if (cfg.Store.Log == shared.Log{}) && (globalLog != shared.Log{}) {
|
||||
// // we can safely inherit the global logging values.
|
||||
// cfg.Store.Log = globalLog
|
||||
//}
|
||||
|
||||
origCmd := command.Server(cfg.Store)
|
||||
return handleOriginalAction(c, origCmd)
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
//go:build !simple
|
||||
// +build !simple
|
||||
|
||||
package command
|
||||
|
||||
import (
|
||||
@@ -24,9 +21,9 @@ func ThumbnailsCommand(cfg *config.Config) *cli.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
if cfg.Commons != nil {
|
||||
cfg.Thumbnails.Commons = cfg.Commons
|
||||
}
|
||||
//if cfg.Commons != nil {
|
||||
// cfg.Thumbnails.Commons = cfg.Commons
|
||||
//}
|
||||
|
||||
return nil
|
||||
},
|
||||
|
||||
@@ -2,7 +2,6 @@ package command
|
||||
|
||||
import (
|
||||
"github.com/owncloud/ocis/ocis-pkg/config"
|
||||
"github.com/owncloud/ocis/ocis-pkg/shared"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
@@ -11,16 +10,16 @@ func ParseStorageCommon(ctx *cli.Context, cfg *config.Config) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if cfg.Storage.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil {
|
||||
cfg.Storage.Log = &shared.Log{
|
||||
Level: cfg.Commons.Log.Level,
|
||||
Pretty: cfg.Commons.Log.Pretty,
|
||||
Color: cfg.Commons.Log.Color,
|
||||
File: cfg.Commons.Log.File,
|
||||
}
|
||||
} else if cfg.Storage.Log == nil && cfg.Commons == nil {
|
||||
cfg.Storage.Log = &shared.Log{}
|
||||
}
|
||||
//if cfg.Storage.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil {
|
||||
// cfg.Storage.Log = &shared.Log{
|
||||
// Level: cfg.Commons.Log.Level,
|
||||
// Pretty: cfg.Commons.Log.Pretty,
|
||||
// Color: cfg.Commons.Log.Color,
|
||||
// File: cfg.Commons.Log.File,
|
||||
// }
|
||||
//} else if cfg.Storage.Log == nil && cfg.Commons == nil {
|
||||
// cfg.Storage.Log = &shared.Log{}
|
||||
//}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -18,9 +18,9 @@ func WebCommand(cfg *config.Config) *cli.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
if cfg.Commons != nil {
|
||||
cfg.Web.Commons = cfg.Commons
|
||||
}
|
||||
//if cfg.Commons != nil {
|
||||
// cfg.Web.Commons = cfg.Commons
|
||||
//}
|
||||
|
||||
return nil
|
||||
},
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
//go:build !simple
|
||||
// +build !simple
|
||||
|
||||
package command
|
||||
|
||||
import (
|
||||
|
||||
@@ -164,9 +164,9 @@ func Start(o ...Option) error {
|
||||
}
|
||||
}
|
||||
|
||||
if s.cfg.Storage.Log == nil {
|
||||
s.cfg.Storage.Log = &shared.Log{}
|
||||
}
|
||||
//if s.cfg.Storage.Log == nil {
|
||||
// s.cfg.Storage.Log = &shared.Log{}
|
||||
//}
|
||||
|
||||
s.cfg.Storage.Log.Color = s.cfg.Commons.Color
|
||||
s.cfg.Storage.Log.Level = s.cfg.Commons.Level
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/owncloud/ocis/ocs/pkg/config"
|
||||
"github.com/owncloud/ocis/ocs/pkg/logging"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
@@ -17,7 +18,7 @@ func Health(cfg *config.Config) *cli.Command {
|
||||
return ParseConfig(c, cfg)
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
logger := NewLogger(cfg)
|
||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||
|
||||
resp, err := http.Get(
|
||||
fmt.Sprintf(
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
|
||||
"github.com/imdario/mergo"
|
||||
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/ocs/pkg/config"
|
||||
"github.com/thejerf/suture/v4"
|
||||
@@ -31,7 +30,7 @@ func Execute(cfg *config.Config) error {
|
||||
|
||||
Before: func(c *cli.Context) error {
|
||||
cfg.Service.Version = version.String
|
||||
return nil
|
||||
return ParseConfig(c, cfg)
|
||||
},
|
||||
|
||||
Commands: []*cli.Command{
|
||||
@@ -54,17 +53,6 @@ func Execute(cfg *config.Config) error {
|
||||
return app.Run(os.Args)
|
||||
}
|
||||
|
||||
// NewLogger initializes a service-specific logger instance.
|
||||
func NewLogger(cfg *config.Config) log.Logger {
|
||||
return log.NewLogger(
|
||||
log.Name("ocs"),
|
||||
log.Level(cfg.Log.Level),
|
||||
log.Pretty(cfg.Log.Pretty),
|
||||
log.Color(cfg.Log.Color),
|
||||
log.File(cfg.Log.File),
|
||||
)
|
||||
}
|
||||
|
||||
// ParseConfig loads idp configuration from known paths.
|
||||
func ParseConfig(c *cli.Context, cfg *config.Config) error {
|
||||
_, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg)
|
||||
@@ -105,7 +93,7 @@ type SutureService struct {
|
||||
|
||||
// NewSutureService creates a new ocs.SutureService
|
||||
func NewSutureService(cfg *ociscfg.Config) suture.Service {
|
||||
cfg.OCS.Commons = cfg.Commons
|
||||
//cfg.OCS.Commons = cfg.Commons
|
||||
return SutureService{
|
||||
cfg: cfg.OCS,
|
||||
}
|
||||
|
||||
@@ -74,27 +74,27 @@ type IdentityManagement struct {
|
||||
type Config struct {
|
||||
*shared.Commons
|
||||
|
||||
Log Log `ocisConfig:"log"`
|
||||
Debug Debug `ocisConfig:"debug"`
|
||||
HTTP HTTP `ocisConfig:"http"`
|
||||
Tracing Tracing `ocisConfig:"tracing"`
|
||||
TokenManager TokenManager `ocisConfig:"token_manager"`
|
||||
Service Service `ocisConfig:"service"`
|
||||
Reva Reva `ocisConfig:"reva"`
|
||||
Service Service `ocisConfig:"service"`
|
||||
|
||||
Tracing Tracing `ocisConfig:"tracing"`
|
||||
Log Log `ocisConfig:"log"`
|
||||
Debug Debug `ocisConfig:"debug"`
|
||||
|
||||
HTTP HTTP `ocisConfig:"http"`
|
||||
|
||||
TokenManager TokenManager `ocisConfig:"token_manager"`
|
||||
Reva Reva `ocisConfig:"reva"`
|
||||
|
||||
IdentityManagement IdentityManagement `ocisConfig:"identity_management"`
|
||||
AccountBackend string `ocisConfig:"account_backend" env:"OCS_ACCOUNT_BACKEND_TYPE"`
|
||||
StorageUsersDriver string `ocisConfig:"storage_users_driver" env:"STORAGE_USERS_DRIVER;OCS_STORAGE_USERS_DRIVER"`
|
||||
MachineAuthAPIKey string `ocisConfig:"machine_auth_api_key" env:"OCIS_MACHINE_AUTH_API_KEY;OCS_MACHINE_AUTH_API_KEY"`
|
||||
|
||||
AccountBackend string `ocisConfig:"account_backend" env:"OCS_ACCOUNT_BACKEND_TYPE"`
|
||||
StorageUsersDriver string `ocisConfig:"storage_users_driver" env:"STORAGE_USERS_DRIVER;OCS_STORAGE_USERS_DRIVER"`
|
||||
MachineAuthAPIKey string `ocisConfig:"machine_auth_api_key" env:"OCIS_MACHINE_AUTH_API_KEY;OCS_MACHINE_AUTH_API_KEY"`
|
||||
|
||||
Context context.Context
|
||||
Supervised bool
|
||||
}
|
||||
|
||||
// New initializes a new configuration with or without defaults.
|
||||
func New() *Config {
|
||||
return &Config{}
|
||||
}
|
||||
|
||||
// DefaultConfig provides default values for a config struct.
|
||||
func DefaultConfig() *Config {
|
||||
return &Config{
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/owncloud/ocis/proxy/pkg/config"
|
||||
"github.com/owncloud/ocis/proxy/pkg/logging"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
@@ -15,7 +16,7 @@ func Health(cfg *config.Config) *cli.Command {
|
||||
Usage: "Check health status",
|
||||
//Flags: flagset.HealthWithConfig(cfg),
|
||||
Action: func(c *cli.Context) error {
|
||||
logger := NewLogger(cfg)
|
||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||
|
||||
resp, err := http.Get(
|
||||
fmt.Sprintf(
|
||||
|
||||
@@ -4,13 +4,13 @@ import (
|
||||
"context"
|
||||
"os"
|
||||
|
||||
"github.com/imdario/mergo"
|
||||
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
|
||||
"github.com/owncloud/ocis/ocis-pkg/log"
|
||||
"github.com/owncloud/ocis/ocis-pkg/shared"
|
||||
"github.com/owncloud/ocis/ocis-pkg/version"
|
||||
"github.com/owncloud/ocis/proxy/pkg/config"
|
||||
"github.com/thejerf/suture/v4"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/wkloucek/envdecode"
|
||||
)
|
||||
|
||||
// Execute is the entry point for the ocis-proxy command.
|
||||
@@ -26,10 +26,12 @@ func Execute(cfg *config.Config) error {
|
||||
Email: "support@owncloud.com",
|
||||
},
|
||||
},
|
||||
|
||||
Before: func(c *cli.Context) error {
|
||||
cfg.Service.Version = version.String
|
||||
return nil
|
||||
return ParseConfig(c, cfg)
|
||||
},
|
||||
|
||||
Commands: []*cli.Command{
|
||||
Server(cfg),
|
||||
Health(cfg),
|
||||
@@ -50,35 +52,37 @@ func Execute(cfg *config.Config) error {
|
||||
return app.Run(os.Args)
|
||||
}
|
||||
|
||||
// ParseConfig loads proxy configuration. Loading will first attempt to parse config files in the expected locations
|
||||
// and then parses environment variables. In the context of oCIS env variables will always overwrite values set
|
||||
// in a config file.
|
||||
// If this extension is run as a subcommand (i.e: ocis proxy) then there are 2 levels of config parsing:
|
||||
// 1. ocis.yaml (if any)
|
||||
// 2. proxy.yaml (if any)
|
||||
// 3. environment variables.
|
||||
// ParseConfig loads accounts configuration from known paths.
|
||||
func ParseConfig(c *cli.Context, cfg *config.Config) error {
|
||||
conf, err := ociscfg.BindSourcesToStructs("proxy", cfg)
|
||||
_, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// provide with defaults for shared logging, since we need a valid destination address for BindEnv.
|
||||
if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil {
|
||||
cfg.Log = &shared.Log{
|
||||
Level: cfg.Commons.Log.Level,
|
||||
Pretty: cfg.Commons.Log.Pretty,
|
||||
Color: cfg.Commons.Log.Color,
|
||||
File: cfg.Commons.Log.File,
|
||||
}
|
||||
} else if cfg.Log == nil && cfg.Commons == nil {
|
||||
cfg.Log = &shared.Log{}
|
||||
//if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil {
|
||||
// cfg.Log = &shared.Log{
|
||||
// Level: cfg.Commons.Log.Level,
|
||||
// Pretty: cfg.Commons.Log.Pretty,
|
||||
// Color: cfg.Commons.Log.Color,
|
||||
// File: cfg.Commons.Log.File,
|
||||
// }
|
||||
//} else if cfg.Log == nil && cfg.Commons == nil {
|
||||
// cfg.Log = &shared.Log{}
|
||||
//}
|
||||
|
||||
// load all env variables relevant to the config in the current context.
|
||||
envCfg := config.Config{}
|
||||
if err := envdecode.Decode(&envCfg); err != nil && err.Error() != "none of the target fields were set from environment variables" {
|
||||
return err
|
||||
}
|
||||
|
||||
conf.LoadOSEnv(config.GetEnv(cfg), false)
|
||||
// merge environment variable config on top of the current config
|
||||
if err := mergo.Merge(cfg, envCfg, mergo.WithOverride); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
bindings := config.StructMappings(cfg)
|
||||
return ociscfg.BindEnv(conf, bindings)
|
||||
return nil
|
||||
}
|
||||
|
||||
// SutureService allows for the proxy command to be embedded and supervised by a suture supervisor tree.
|
||||
@@ -88,7 +92,7 @@ type SutureService struct {
|
||||
|
||||
// NewSutureService creates a new proxy.SutureService
|
||||
func NewSutureService(cfg *ociscfg.Config) suture.Service {
|
||||
cfg.Proxy.Commons = cfg.Commons
|
||||
//cfg.Proxy.Commons = cfg.Commons
|
||||
return SutureService{
|
||||
cfg: cfg.Proxy,
|
||||
}
|
||||
@@ -102,14 +106,3 @@ func (s SutureService) Serve(ctx context.Context) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewLogger initializes a service-specific logger instance.
|
||||
func NewLogger(cfg *config.Config) log.Logger {
|
||||
return log.NewLogger(
|
||||
log.Name("proxy"),
|
||||
log.Level(cfg.Log.Level),
|
||||
log.Pretty(cfg.Log.Pretty),
|
||||
log.Color(cfg.Log.Color),
|
||||
log.File(cfg.Log.File),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"github.com/owncloud/ocis/ocis-pkg/service/grpc"
|
||||
"github.com/owncloud/ocis/proxy/pkg/config"
|
||||
"github.com/owncloud/ocis/proxy/pkg/cs3"
|
||||
"github.com/owncloud/ocis/proxy/pkg/logging"
|
||||
"github.com/owncloud/ocis/proxy/pkg/metrics"
|
||||
"github.com/owncloud/ocis/proxy/pkg/middleware"
|
||||
"github.com/owncloud/ocis/proxy/pkg/proxy"
|
||||
@@ -62,9 +63,9 @@ func Server(cfg *config.Config) *cli.Command {
|
||||
return nil
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
logger := NewLogger(cfg)
|
||||
|
||||
if err := tracing.Configure(cfg); err != nil {
|
||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||
err := tracing.Configure(cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -8,45 +8,45 @@ import (
|
||||
"github.com/owncloud/ocis/ocis-pkg/shared"
|
||||
)
|
||||
|
||||
// Log defines the available logging configuration.
|
||||
// Log defines the available log configuration.
|
||||
type Log struct {
|
||||
Level string `ocisConfig:"level"`
|
||||
Pretty bool `ocisConfig:"pretty"`
|
||||
Color bool `ocisConfig:"color"`
|
||||
File string `ocisConfig:"file"`
|
||||
Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;PROXY_LOG_LEVEL"`
|
||||
Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;PROXY_LOG_PRETTY"`
|
||||
Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;PROXY_LOG_COLOR"`
|
||||
File string `mapstructure:"file" env:"OCIS_LOG_FILE;PROXY_LOG_FILE"`
|
||||
}
|
||||
|
||||
// Debug defines the available debug configuration.
|
||||
type Debug struct {
|
||||
Addr string `ocisConfig:"addr"`
|
||||
Token string `ocisConfig:"token"`
|
||||
Pprof bool `ocisConfig:"pprof"`
|
||||
Zpages bool `ocisConfig:"zpages"`
|
||||
Addr string `ocisConfig:"addr" env:"PROXY_DEBUG_ADDR"`
|
||||
Token string `ocisConfig:"token" env:"PROXY_DEBUG_TOKEN"`
|
||||
Pprof bool `ocisConfig:"pprof" env:"PROXY_DEBUG_PPROF"`
|
||||
Zpages bool `ocisConfig:"zpages" env:"PROXY_DEBUG_ZPAGES"`
|
||||
}
|
||||
|
||||
// HTTP defines the available http configuration.
|
||||
type HTTP struct {
|
||||
Addr string `ocisConfig:"addr"`
|
||||
Root string `ocisConfig:"root"`
|
||||
Addr string `ocisConfig:"addr" env:"PROXY_HTTP_ADDR"`
|
||||
Root string `ocisConfig:"root" env:"PROXY_HTTP_ROOT"`
|
||||
Namespace string
|
||||
TLSCert string `ocisConfig:"tls_cert"`
|
||||
TLSKey string `ocisConfig:"tls_key"`
|
||||
TLS bool `ocisConfig:"tls"`
|
||||
TLSCert string `ocisConfig:"tls_cert" env:"PROXY_TRANSPORT_TLS_CERT"`
|
||||
TLSKey string `ocisConfig:"tls_key" env:"PROXY_TRANSPORT_TLS_KEY"`
|
||||
TLS bool `ocisConfig:"tls" env:"PROXY_TLS"`
|
||||
}
|
||||
|
||||
// Service defines the available service configuration.
|
||||
type Service struct {
|
||||
Name string `ocisConfig:"name"`
|
||||
Version string `ocisConfig:"version"`
|
||||
Name string
|
||||
Version string
|
||||
}
|
||||
|
||||
// Tracing defines the available tracing configuration.
|
||||
type Tracing struct {
|
||||
Enabled bool `ocisConfig:"enabled"`
|
||||
Type string `ocisConfig:"type"`
|
||||
Endpoint string `ocisConfig:"endpoint"`
|
||||
Collector string `ocisConfig:"collector"`
|
||||
Service string `ocisConfig:"service"`
|
||||
Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;PROXY_TRACING_ENABLED"`
|
||||
Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;PROXY_TRACING_TYPE"`
|
||||
Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;PROXY_TRACING_ENDPOINT"`
|
||||
Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;PROXY_TRACING_COLLECTOR"`
|
||||
Service string `ocisConfig:"service" env:"PROXY_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name?
|
||||
}
|
||||
|
||||
// Policy enables us to use multiple directors.
|
||||
@@ -84,7 +84,7 @@ var (
|
||||
|
||||
// Reva defines all available REVA configuration.
|
||||
type Reva struct {
|
||||
Address string `ocisConfig:"address"`
|
||||
Address string `ocisConfig:"address" env:"REVA_GATEWAY"`
|
||||
Middleware Middleware `ocisConfig:"middleware"`
|
||||
}
|
||||
|
||||
@@ -98,34 +98,31 @@ type Auth struct {
|
||||
CredentialsByUserAgent map[string]string `ocisConfig:""`
|
||||
}
|
||||
|
||||
// Cache is a TTL cache configuration.
|
||||
type Cache struct {
|
||||
Size int `ocisConfig:"size"`
|
||||
TTL int `ocisConfig:"ttl"`
|
||||
}
|
||||
|
||||
// Config combines all available configuration parts.
|
||||
type Config struct {
|
||||
*shared.Commons
|
||||
|
||||
Log *shared.Log `ocisConfig:"log"`
|
||||
Debug Debug `ocisConfig:"debug"`
|
||||
HTTP HTTP `ocisConfig:"http"`
|
||||
Service Service `ocisConfig:"service"`
|
||||
Tracing Tracing `ocisConfig:"tracing"`
|
||||
Service Service `ocisConfig:"service"`
|
||||
|
||||
Tracing Tracing `ocisConfig:"tracing"`
|
||||
Log Log `ocisConfig:"log"`
|
||||
Debug Debug `ocisConfig:"debug"`
|
||||
|
||||
HTTP HTTP `ocisConfig:"http"`
|
||||
|
||||
Policies []Policy `ocisConfig:"policies"`
|
||||
OIDC OIDC `ocisConfig:"oidc"`
|
||||
TokenManager TokenManager `ocisConfig:"token_manager"`
|
||||
PolicySelector *PolicySelector `ocisConfig:"policy_selector"`
|
||||
Reva Reva `ocisConfig:"reva"`
|
||||
PreSignedURL PreSignedURL `ocisConfig:"pre_signed_url"`
|
||||
AccountBackend string `ocisConfig:"account_backend"`
|
||||
UserOIDCClaim string `ocisConfig:"user_oidc_claim"`
|
||||
UserCS3Claim string `ocisConfig:"user_cs3_claim"`
|
||||
MachineAuthAPIKey string `ocisConfig:"machine_auth_api_key"`
|
||||
AutoprovisionAccounts bool `ocisConfig:"auto_provision_accounts"`
|
||||
EnableBasicAuth bool `ocisConfig:"enable_basic_auth"`
|
||||
InsecureBackends bool `ocisConfig:"insecure_backends"`
|
||||
AccountBackend string `ocisConfig:"account_backend" env:"PROXY_ACCOUNT_BACKEND_TYPE"`
|
||||
UserOIDCClaim string `ocisConfig:"user_oidc_claim" env:"PROXY_USER_OIDC_CLAIM"`
|
||||
UserCS3Claim string `ocisConfig:"user_cs3_claim" env:"PROXY_USER_CS3_CLAIM"`
|
||||
MachineAuthAPIKey string `ocisConfig:"machine_auth_api_key" env:"OCIS_MACHINE_AUTH_API_KEY;PROXY_MACHINE_AUTH_API_KEY"`
|
||||
AutoprovisionAccounts bool `ocisConfig:"auto_provision_accounts" env:"PROXY_AUTOPROVISION_ACCOUNTS"`
|
||||
EnableBasicAuth bool `ocisConfig:"enable_basic_auth" env:"PROXY_ENABLE_BASIC_AUTH"`
|
||||
InsecureBackends bool `ocisConfig:"insecure_backends" env:"PROXY_INSECURE_BACKENDS"`
|
||||
|
||||
Context context.Context
|
||||
Supervised bool
|
||||
@@ -134,9 +131,15 @@ type Config struct {
|
||||
// OIDC is the config for the OpenID-Connect middleware. If set the proxy will try to authenticate every request
|
||||
// with the configured oidc-provider
|
||||
type OIDC struct {
|
||||
Issuer string `ocisConfig:"issuer"`
|
||||
Insecure bool `ocisConfig:"insecure"`
|
||||
UserinfoCache Cache `ocisConfig:"user_info_cache"`
|
||||
Issuer string `ocisConfig:"issuer" env:"OCIS_URL;PROXY_OIDC_ISSUER"`
|
||||
Insecure bool `ocisConfig:"insecure" env:"OCIS_INSECURE;PROXY_OIDC_INSECURE"`
|
||||
UserinfoCache UserinfoCache `ocisConfig:"user_info_cache"`
|
||||
}
|
||||
|
||||
// UserinfoCache is a TTL cache configuration.
|
||||
type UserinfoCache struct {
|
||||
Size int `ocisConfig:"size" env:"PROXY_OIDC_USERINFO_CACHE_SIZE"`
|
||||
TTL int `ocisConfig:"ttl" env:"PROXY_OIDC_USERINFO_CACHE_TTL"`
|
||||
}
|
||||
|
||||
// PolicySelector is the toplevel-configuration for different selectors
|
||||
@@ -154,13 +157,13 @@ type StaticSelectorConf struct {
|
||||
|
||||
// TokenManager is the config for using the reva token manager
|
||||
type TokenManager struct {
|
||||
JWTSecret string `ocisConfig:"jwt_secret"`
|
||||
JWTSecret string `ocisConfig:"jwt_secret" env:"OCIS_JWT_SECRET;PROXY_JWT_SECRET"`
|
||||
}
|
||||
|
||||
// PreSignedURL is the config for the presigned url middleware
|
||||
type PreSignedURL struct {
|
||||
AllowedHTTPMethods []string `ocisConfig:"allowed_http_methods"`
|
||||
Enabled bool `ocisConfig:"enabled"`
|
||||
Enabled bool `ocisConfig:"enabled" env:"PROXY_ENABLE_PRESIGNEDURLS"`
|
||||
}
|
||||
|
||||
// MigrationSelectorConf is the config for the migration-selector
|
||||
@@ -192,13 +195,6 @@ type RegexRuleConf struct {
|
||||
Policy string `ocisConfig:"policy"`
|
||||
}
|
||||
|
||||
// New initializes a new configuration
|
||||
func New() *Config {
|
||||
return &Config{
|
||||
HTTP: HTTP{},
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultConfig provides with a working local configuration for a proxy service.
|
||||
func DefaultConfig() *Config {
|
||||
return &Config{
|
||||
@@ -227,7 +223,7 @@ func DefaultConfig() *Config {
|
||||
Issuer: "https://localhost:9200",
|
||||
Insecure: true,
|
||||
//Insecure: true,
|
||||
UserinfoCache: Cache{
|
||||
UserinfoCache: UserinfoCache{
|
||||
Size: 1024,
|
||||
TTL: 10,
|
||||
},
|
||||
@@ -243,14 +239,14 @@ func DefaultConfig() *Config {
|
||||
AllowedHTTPMethods: []string{"GET"},
|
||||
Enabled: true,
|
||||
},
|
||||
AccountBackend: "accounts",
|
||||
UserOIDCClaim: "email",
|
||||
UserCS3Claim: "mail",
|
||||
MachineAuthAPIKey: "change-me-please",
|
||||
//AutoprovisionAccounts: false,
|
||||
//EnableBasicAuth: false,
|
||||
//InsecureBackends: false,
|
||||
Context: nil,
|
||||
AccountBackend: "accounts",
|
||||
UserOIDCClaim: "email",
|
||||
UserCS3Claim: "mail",
|
||||
MachineAuthAPIKey: "change-me-please",
|
||||
AutoprovisionAccounts: false,
|
||||
EnableBasicAuth: false,
|
||||
InsecureBackends: false,
|
||||
// TODO: enable
|
||||
//Policies: defaultPolicies(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,182 +0,0 @@
|
||||
package config
|
||||
|
||||
import "github.com/owncloud/ocis/ocis-pkg/shared"
|
||||
|
||||
// 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(cfg *Config) []string {
|
||||
var r = make([]string, len(structMappings(cfg)))
|
||||
for i := range structMappings(cfg) {
|
||||
r = append(r, structMappings(cfg)[i].EnvVars...)
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
func structMappings(cfg *Config) []shared.EnvBinding {
|
||||
return []shared.EnvBinding{
|
||||
// Logging
|
||||
{
|
||||
EnvVars: []string{"OCIS_LOG_LEVEL", "PROXY_LOG_LEVEL"},
|
||||
Destination: &cfg.Log.Level,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_LOG_COLOR", "PROXY_LOG_COLOR"},
|
||||
Destination: &cfg.Log.Color,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_LOG_PRETTY", "PROXY_LOG_PRETTY"},
|
||||
Destination: &cfg.Log.Pretty,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_LOG_FILE", "PROXY_LOG_FILE"},
|
||||
Destination: &cfg.Log.File,
|
||||
},
|
||||
|
||||
// Basic auth
|
||||
{
|
||||
EnvVars: []string{"PROXY_ENABLE_BASIC_AUTH"},
|
||||
Destination: &cfg.EnableBasicAuth,
|
||||
},
|
||||
|
||||
// Debug (health)
|
||||
{
|
||||
EnvVars: []string{"PROXY_DEBUG_ADDR"},
|
||||
Destination: &cfg.Debug.Addr,
|
||||
},
|
||||
|
||||
// Tracing
|
||||
{
|
||||
EnvVars: []string{"OCIS_TRACING_ENABLED", "PROXY_TRACING_ENABLED"},
|
||||
Destination: &cfg.Tracing.Enabled,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_TRACING_TYPE", "PROXY_TRACING_TYPE"},
|
||||
Destination: &cfg.Tracing.Type,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_TRACING_ENDPOINT", "PROXY_TRACING_ENDPOINT"},
|
||||
Destination: &cfg.Tracing.Endpoint,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_TRACING_COLLECTOR", "PROXY_TRACING_COLLECTOR"},
|
||||
Destination: &cfg.Tracing.Collector,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"PROXY_TRACING_SERVICE"},
|
||||
Destination: &cfg.Tracing.Service,
|
||||
},
|
||||
|
||||
// Debug
|
||||
{
|
||||
EnvVars: []string{"PROXY_DEBUG_ADDR"},
|
||||
Destination: &cfg.Debug.Addr,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"PROXY_DEBUG_TOKEN"},
|
||||
Destination: &cfg.Debug.Token,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"PROXY_DEBUG_PPROF"},
|
||||
Destination: &cfg.Debug.Pprof,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"PROXY_DEBUG_ZPAGES"},
|
||||
Destination: &cfg.Debug.Zpages,
|
||||
},
|
||||
|
||||
// HTTP
|
||||
{
|
||||
EnvVars: []string{"PROXY_HTTP_ADDR"},
|
||||
Destination: &cfg.HTTP.Addr,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"PROXY_HTTP_ROOT"},
|
||||
Destination: &cfg.HTTP.Root,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"PROXY_HTTP_NAMESPACE"},
|
||||
Destination: &cfg.HTTP.Namespace,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"PROXY_TRANSPORT_TLS_CERT"},
|
||||
Destination: &cfg.HTTP.TLSCert,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"PROXY_TRANSPORT_TLS_KEY"},
|
||||
Destination: &cfg.HTTP.TLSKey,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"PROXY_TLS"},
|
||||
Destination: &cfg.HTTP.TLS,
|
||||
},
|
||||
|
||||
// Other
|
||||
{
|
||||
EnvVars: []string{"OCIS_JWT_SECRET", "PROXY_JWT_SECRET"},
|
||||
Destination: &cfg.TokenManager.JWTSecret,
|
||||
},
|
||||
|
||||
{
|
||||
EnvVars: []string{"REVA_GATEWAY"},
|
||||
Destination: &cfg.Reva.Address,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"PROXY_INSECURE_BACKENDS"},
|
||||
Destination: &cfg.InsecureBackends,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_URL", "PROXY_OIDC_ISSUER"},
|
||||
Destination: &cfg.OIDC.Issuer,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_INSECURE", "PROXY_OIDC_INSECURE"},
|
||||
Destination: &cfg.OIDC.Insecure,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"PROXY_OIDC_USERINFO_CACHE_TTL"},
|
||||
Destination: &cfg.OIDC.UserinfoCache.TTL,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"PROXY_OIDC_USERINFO_CACHE_SIZE"},
|
||||
Destination: &cfg.OIDC.UserinfoCache.Size,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"PROXY_AUTOPROVISION_ACCOUNTS"},
|
||||
Destination: &cfg.AutoprovisionAccounts,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"PROXY_USER_OIDC_CLAIM"},
|
||||
Destination: &cfg.UserOIDCClaim,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"PROXY_USER_CS3_CLAIM"},
|
||||
Destination: &cfg.UserCS3Claim,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"PROXY_ENABLE_PRESIGNEDURLS"},
|
||||
Destination: &cfg.PreSignedURL.Enabled,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"PROXY_ACCOUNT_BACKEND_TYPE"},
|
||||
Destination: &cfg.AccountBackend,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_MACHINE_AUTH_API_KEY", "PROXY_MACHINE_AUTH_API_KEY"},
|
||||
Destination: &cfg.MachineAuthAPIKey,
|
||||
},
|
||||
// there are 2 missing bindings:
|
||||
// EnvVars: []string{"PROXY_MIDDLEWARE_AUTH_CREDENTIALS_BY_USER_AGENT"},
|
||||
// EnvVars: []string{"PRESIGNEDURL_ALLOWED_METHODS"},
|
||||
// since they both have no destination
|
||||
// see https://github.com/owncloud/ocis/blob/52e5effa4fa05a1626d46f7d4cb574dde3a54593/proxy/pkg/flagset/flagset.go#L256-L261
|
||||
// and https://github.com/owncloud/ocis/blob/52e5effa4fa05a1626d46f7d4cb574dde3a54593/proxy/pkg/flagset/flagset.go#L295-L300
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
func newConn(endpoint string) (*grpc.ClientConn, error) {
|
||||
conn, err := grpc.Dial(
|
||||
endpoint,
|
||||
grpc.WithInsecure(),
|
||||
grpc.WithInsecure(), //TODO: depreciated
|
||||
grpc.WithUnaryInterceptor(
|
||||
otelgrpc.UnaryClientInterceptor(
|
||||
otelgrpc.WithTracerProvider(
|
||||
@@ -28,6 +28,7 @@ func newConn(endpoint string) (*grpc.ClientConn, error) {
|
||||
|
||||
// GetGatewayServiceClient returns a new cs3 gateway client
|
||||
func GetGatewayServiceClient(endpoint string) (gateway.GatewayAPIClient, error) {
|
||||
// TODO: check connection pooling
|
||||
conn, err := newConn(endpoint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
17
proxy/pkg/logging/logging.go
Normal file
17
proxy/pkg/logging/logging.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package logging
|
||||
|
||||
import (
|
||||
"github.com/owncloud/ocis/ocis-pkg/log"
|
||||
"github.com/owncloud/ocis/proxy/pkg/config"
|
||||
)
|
||||
|
||||
// LoggerFromConfig initializes a service-specific logger instance.
|
||||
func Configure(name string, cfg config.Log) log.Logger {
|
||||
return log.NewLogger(
|
||||
log.Name(name),
|
||||
log.Level(cfg.Level),
|
||||
log.Pretty(cfg.Pretty),
|
||||
log.Color(cfg.Color),
|
||||
log.File(cfg.File),
|
||||
)
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/owncloud/ocis/settings/pkg/config"
|
||||
"github.com/owncloud/ocis/settings/pkg/logging"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
@@ -17,7 +18,7 @@ func Health(cfg *config.Config) *cli.Command {
|
||||
return ParseConfig(c, cfg)
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
logger := NewLogger(cfg)
|
||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||
|
||||
resp, err := http.Get(
|
||||
fmt.Sprintf(
|
||||
|
||||
@@ -4,14 +4,13 @@ import (
|
||||
"context"
|
||||
"os"
|
||||
|
||||
"github.com/owncloud/ocis/ocis-pkg/shared"
|
||||
|
||||
"github.com/imdario/mergo"
|
||||
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/settings/pkg/config"
|
||||
"github.com/thejerf/suture/v4"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/wkloucek/envdecode"
|
||||
)
|
||||
|
||||
// Execute is the entry point for the ocis-settings command.
|
||||
@@ -31,7 +30,7 @@ func Execute(cfg *config.Config) error {
|
||||
|
||||
Before: func(c *cli.Context) error {
|
||||
cfg.Service.Version = version.String
|
||||
return nil
|
||||
return ParseConfig(c, cfg)
|
||||
},
|
||||
|
||||
Commands: []*cli.Command{
|
||||
@@ -54,39 +53,37 @@ func Execute(cfg *config.Config) error {
|
||||
return app.Run(os.Args)
|
||||
}
|
||||
|
||||
// NewLogger initializes a service-specific logger instance.
|
||||
func NewLogger(cfg *config.Config) log.Logger {
|
||||
return log.NewLogger(
|
||||
log.Name("settings"),
|
||||
log.Level(cfg.Log.Level),
|
||||
log.Pretty(cfg.Log.Pretty),
|
||||
log.Color(cfg.Log.Color),
|
||||
log.File(cfg.Log.File),
|
||||
)
|
||||
}
|
||||
|
||||
// ParseConfig loads idp configuration from known paths.
|
||||
func ParseConfig(c *cli.Context, cfg *config.Config) error {
|
||||
conf, err := ociscfg.BindSourcesToStructs("settings", cfg)
|
||||
_, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// provide with defaults for shared logging, since we need a valid destination address for BindEnv.
|
||||
if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil {
|
||||
cfg.Log = &shared.Log{
|
||||
Level: cfg.Commons.Log.Level,
|
||||
Pretty: cfg.Commons.Log.Pretty,
|
||||
Color: cfg.Commons.Log.Color,
|
||||
File: cfg.Commons.Log.File,
|
||||
}
|
||||
} else if cfg.Log == nil && cfg.Commons == nil {
|
||||
cfg.Log = &shared.Log{}
|
||||
//if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil {
|
||||
// cfg.Log = &shared.Log{
|
||||
// Level: cfg.Commons.Log.Level,
|
||||
// Pretty: cfg.Commons.Log.Pretty,
|
||||
// Color: cfg.Commons.Log.Color,
|
||||
// File: cfg.Commons.Log.File,
|
||||
// }
|
||||
//} else if cfg.Log == nil && cfg.Commons == nil {
|
||||
// cfg.Log = &shared.Log{}
|
||||
//}
|
||||
|
||||
// load all env variables relevant to the config in the current context.
|
||||
envCfg := config.Config{}
|
||||
if err := envdecode.Decode(&envCfg); err != nil && err.Error() != "none of the target fields were set from environment variables" {
|
||||
return err
|
||||
}
|
||||
|
||||
conf.LoadOSEnv(config.GetEnv(cfg), false)
|
||||
bindings := config.StructMappings(cfg)
|
||||
return ociscfg.BindEnv(conf, bindings)
|
||||
// merge environment variable config on top of the current config
|
||||
if err := mergo.Merge(cfg, envCfg, mergo.WithOverride); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SutureService allows for the settings command to be embedded and supervised by a suture supervisor tree.
|
||||
@@ -96,7 +93,7 @@ type SutureService struct {
|
||||
|
||||
// NewSutureService creates a new settings.SutureService
|
||||
func NewSutureService(cfg *ociscfg.Config) suture.Service {
|
||||
cfg.Settings.Commons = cfg.Commons
|
||||
//cfg.Settings.Commons = cfg.Commons
|
||||
return SutureService{
|
||||
cfg: cfg.Settings,
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/oklog/run"
|
||||
"github.com/owncloud/ocis/settings/pkg/config"
|
||||
"github.com/owncloud/ocis/settings/pkg/logging"
|
||||
"github.com/owncloud/ocis/settings/pkg/metrics"
|
||||
"github.com/owncloud/ocis/settings/pkg/server/debug"
|
||||
"github.com/owncloud/ocis/settings/pkg/server/grpc"
|
||||
@@ -31,8 +32,7 @@ func Server(cfg *config.Config) *cli.Command {
|
||||
return nil
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
logger := NewLogger(cfg)
|
||||
|
||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||
err := tracing.Configure(cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -11,10 +11,10 @@ import (
|
||||
|
||||
// Debug defines the available debug configuration.
|
||||
type Debug struct {
|
||||
Addr string `ocisConfig:"addr"`
|
||||
Token string `ocisConfig:"token"`
|
||||
Pprof bool `ocisConfig:"pprof"`
|
||||
Zpages bool `ocisConfig:"zpages"`
|
||||
Addr string `ocisConfig:"addr" env:"SETTINGS_DEBUG_ADDR"`
|
||||
Token string `ocisConfig:"token" env:"SETTINGS_DEBUG_TOKEN"`
|
||||
Pprof bool `ocisConfig:"pprof" env:"SETTINGS_DEBUG_PPROF"`
|
||||
Zpages bool `ocisConfig:"zpages" env:"SETTINGS_DEBUG_ZPAGES"`
|
||||
}
|
||||
|
||||
// CORS defines the available cors configuration.
|
||||
@@ -27,55 +27,66 @@ type CORS struct {
|
||||
|
||||
// HTTP defines the available http configuration.
|
||||
type HTTP struct {
|
||||
Addr string `ocisConfig:"addr"`
|
||||
Addr string `ocisConfig:"addr" env:"SETTINGS_HTTP_ADDR"`
|
||||
Namespace string
|
||||
Root string `ocisConfig:"root"`
|
||||
CacheTTL int `ocisConfig:"cache_ttl"`
|
||||
Root string `ocisConfig:"root" env:"SETTINGS_HTTP_ROOT"`
|
||||
CacheTTL int `ocisConfig:"cache_ttl" env:"SETTINGS_CACHE_TTL"`
|
||||
CORS CORS `ocisConfig:"cors"`
|
||||
}
|
||||
|
||||
// GRPC defines the available grpc configuration.
|
||||
type GRPC struct {
|
||||
Addr string `ocisConfig:"addr"`
|
||||
Addr string `ocisConfig:"addr" env:"SETTINGS_GRPC_ADDR"`
|
||||
Namespace string
|
||||
}
|
||||
|
||||
// Service provides configuration options for the service
|
||||
// Service defines the available service configuration.
|
||||
type Service struct {
|
||||
Name string `ocisConfig:"name"`
|
||||
Version string `ocisConfig:"version"`
|
||||
DataPath string `ocisConfig:"data_path"`
|
||||
Name string
|
||||
Version string
|
||||
}
|
||||
|
||||
// Tracing defines the available tracing configuration.
|
||||
type Tracing struct {
|
||||
Enabled bool `ocisConfig:"enabled"`
|
||||
Type string `ocisConfig:"type"`
|
||||
Endpoint string `ocisConfig:"endpoint"`
|
||||
Collector string `ocisConfig:"collector"`
|
||||
Service string `ocisConfig:"service"`
|
||||
Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;SETTINGS_TRACING_ENABLED"`
|
||||
Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;SETTINGS_TRACING_TYPE"`
|
||||
Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;SETTINGS_TRACING_ENDPOINT"`
|
||||
Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;SETTINGS_TRACING_COLLECTOR"`
|
||||
Service string `ocisConfig:"service" env:"SETTINGS_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name?
|
||||
}
|
||||
|
||||
// Asset undocumented
|
||||
// Log defines the available log configuration.
|
||||
type Log struct {
|
||||
Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;SETTINGS_LOG_LEVEL"`
|
||||
Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;SETTINGS_LOG_PRETTY"`
|
||||
Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;SETTINGS_LOG_COLOR"`
|
||||
File string `mapstructure:"file" env:"OCIS_LOG_FILE;SETTINGS_LOG_FILE"`
|
||||
}
|
||||
|
||||
// Asset defines the available asset configuration.
|
||||
type Asset struct {
|
||||
Path string `ocisConfig:"asset"`
|
||||
Path string `ocisConfig:"path" env:"SETTINGS_ASSET_PATH"`
|
||||
}
|
||||
|
||||
// TokenManager is the config for using the reva token manager
|
||||
type TokenManager struct {
|
||||
JWTSecret string `ocisConfig:"jwt_secret"`
|
||||
JWTSecret string `ocisConfig:"jwt_secret" env:"OCIS_JWT_SECRET;SETTINGS_JWT_SECRET"`
|
||||
}
|
||||
|
||||
// Config combines all available configuration parts.
|
||||
type Config struct {
|
||||
*shared.Commons
|
||||
|
||||
Service Service `ocisConfig:"service"`
|
||||
Log *shared.Log `ocisConfig:"log"`
|
||||
Debug Debug `ocisConfig:"debug"`
|
||||
HTTP HTTP `ocisConfig:"http"`
|
||||
GRPC GRPC `ocisConfig:"grpc"`
|
||||
Tracing Tracing `ocisConfig:"tracing"`
|
||||
Service Service `ocisConfig:"service"`
|
||||
|
||||
Tracing Tracing `ocisConfig:"tracing"`
|
||||
Log Log `ocisConfig:"log"`
|
||||
Debug Debug `ocisConfig:"debug"`
|
||||
|
||||
HTTP HTTP `ocisConfig:"http"`
|
||||
GRPC GRPC `ocisConfig:"grpc"`
|
||||
|
||||
DataPath string `ocisConfig:"data_path" env:"SETTINGS_DATA_PATH"`
|
||||
Asset Asset `ocisConfig:"asset"`
|
||||
TokenManager TokenManager `ocisConfig:"token_manager"`
|
||||
|
||||
@@ -83,17 +94,11 @@ type Config struct {
|
||||
Supervised bool
|
||||
}
|
||||
|
||||
// New initializes a new configuration with or without defaults.
|
||||
func New() *Config {
|
||||
return &Config{}
|
||||
}
|
||||
|
||||
// DefaultConfig provides sane bootstrapping defaults.
|
||||
func DefaultConfig() *Config {
|
||||
return &Config{
|
||||
Service: Service{
|
||||
Name: "settings",
|
||||
DataPath: path.Join(defaults.BaseDataPath(), "settings"),
|
||||
Name: "settings",
|
||||
},
|
||||
Debug: Debug{
|
||||
Addr: "127.0.0.1:9194",
|
||||
@@ -124,6 +129,7 @@ func DefaultConfig() *Config {
|
||||
Collector: "",
|
||||
Service: "settings",
|
||||
},
|
||||
DataPath: path.Join(defaults.BaseDataPath(), "settings"),
|
||||
Asset: Asset{
|
||||
Path: "",
|
||||
},
|
||||
|
||||
@@ -1,115 +0,0 @@
|
||||
package config
|
||||
|
||||
import "github.com/owncloud/ocis/ocis-pkg/shared"
|
||||
|
||||
// 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(cfg *Config) []string {
|
||||
var r = make([]string, len(structMappings(cfg)))
|
||||
for i := range structMappings(cfg) {
|
||||
r = append(r, structMappings(cfg)[i].EnvVars...)
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
// 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) []shared.EnvBinding {
|
||||
return []shared.EnvBinding{
|
||||
{
|
||||
EnvVars: []string{"OCIS_LOG_LEVEL", "SETTINGS_LOG_LEVEL"},
|
||||
Destination: &cfg.Log.Level,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_LOG_PRETTY", "SETTINGS_LOG_PRETTY"},
|
||||
Destination: &cfg.Log.Pretty,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_LOG_COLOR", "SETTINGS_LOG_COLOR"},
|
||||
Destination: &cfg.Log.Color,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"SETTINGS_CONFIG_FILE"},
|
||||
Destination: &cfg.File,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_TRACING_ENABLED", "SETTINGS_TRACING_ENABLED"},
|
||||
Destination: &cfg.Tracing.Enabled,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_TRACING_TYPE", "SETTINGS_TRACING_TYPE"},
|
||||
Destination: &cfg.Tracing.Type,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_TRACING_ENDPOINT", "SETTINGS_TRACING_ENDPOINT"},
|
||||
Destination: &cfg.Tracing.Endpoint,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_TRACING_COLLECTOR", "SETTINGS_TRACING_COLLECTOR"},
|
||||
Destination: &cfg.Tracing.Collector,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"SETTINGS_TRACING_SERVICE"},
|
||||
Destination: &cfg.Tracing.Service,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"SETTINGS_DEBUG_ADDR"},
|
||||
Destination: &cfg.Debug.Addr,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"SETTINGS_DEBUG_TOKEN"},
|
||||
Destination: &cfg.Debug.Token,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"SETTINGS_DEBUG_PPROF"},
|
||||
Destination: &cfg.Debug.Pprof,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"SETTINGS_DEBUG_ZPAGES"},
|
||||
Destination: &cfg.Debug.Zpages,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"SETTINGS_HTTP_ADDR"},
|
||||
Destination: &cfg.HTTP.Addr,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"SETTINGS_HTTP_NAMESPACE"},
|
||||
Destination: &cfg.HTTP.Namespace,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"SETTINGS_HTTP_ROOT"},
|
||||
Destination: &cfg.HTTP.Root,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"SETTINGS_CACHE_TTL"},
|
||||
Destination: &cfg.HTTP.CacheTTL,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"SETTINGS_GRPC_ADDR"},
|
||||
Destination: &cfg.GRPC.Addr,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"SETTINGS_ASSET_PATH"},
|
||||
Destination: &cfg.Asset.Path,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"SETTINGS_GRPC_NAMESPACE"},
|
||||
Destination: &cfg.GRPC.Namespace,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"SETTINGS_DATA_PATH"},
|
||||
Destination: &cfg.Service.DataPath,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_JWT_SECRET", "SETTINGS_JWT_SECRET"},
|
||||
Destination: &cfg.TokenManager.JWTSecret,
|
||||
},
|
||||
}
|
||||
}
|
||||
17
settings/pkg/logging/logging.go
Normal file
17
settings/pkg/logging/logging.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package logging
|
||||
|
||||
import (
|
||||
"github.com/owncloud/ocis/ocis-pkg/log"
|
||||
"github.com/owncloud/ocis/settings/pkg/config"
|
||||
)
|
||||
|
||||
// LoggerFromConfig initializes a service-specific logger instance.
|
||||
func Configure(name string, cfg config.Log) log.Logger {
|
||||
return log.NewLogger(
|
||||
log.Name(name),
|
||||
log.Level(cfg.Level),
|
||||
log.Pretty(cfg.Pretty),
|
||||
log.Color(cfg.Color),
|
||||
log.File(cfg.File),
|
||||
)
|
||||
}
|
||||
@@ -176,8 +176,8 @@ func init() {
|
||||
grpc.Address("localhost:9992"),
|
||||
)
|
||||
|
||||
cfg := config.New()
|
||||
cfg.Service.DataPath = dataPath
|
||||
cfg := config.DefaultConfig()
|
||||
cfg.DataPath = dataPath
|
||||
handler = svc.NewService(cfg, ocislog.NewLogger(ocislog.Color(true), ocislog.Pretty(true)))
|
||||
err := proto.RegisterBundleServiceHandler(service.Server(), handler)
|
||||
if err != nil {
|
||||
|
||||
@@ -32,16 +32,16 @@ func New(cfg *config.Config) settings.Manager {
|
||||
//),
|
||||
}
|
||||
|
||||
if _, err := os.Stat(cfg.Service.DataPath); err != nil {
|
||||
s.Logger.Info().Msgf("creating container on %v", cfg.Service.DataPath)
|
||||
err = os.MkdirAll(cfg.Service.DataPath, 0700)
|
||||
if _, err := os.Stat(cfg.DataPath); err != nil {
|
||||
s.Logger.Info().Msgf("creating container on %v", cfg.DataPath)
|
||||
err = os.MkdirAll(cfg.DataPath, 0700)
|
||||
|
||||
if err != nil {
|
||||
s.Logger.Err(err).Msgf("providing container on %v", cfg.Service.DataPath)
|
||||
s.Logger.Err(err).Msgf("providing container on %v", cfg.DataPath)
|
||||
}
|
||||
}
|
||||
|
||||
s.dataPath = cfg.Service.DataPath
|
||||
s.dataPath = cfg.DataPath
|
||||
return &s
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
|
||||
"github.com/owncloud/ocis/ocis-pkg/sync"
|
||||
"github.com/owncloud/ocis/storage/pkg/config"
|
||||
"github.com/owncloud/ocis/storage/pkg/logging"
|
||||
"github.com/owncloud/ocis/storage/pkg/server/debug"
|
||||
"github.com/owncloud/ocis/storage/pkg/tracing"
|
||||
"github.com/thejerf/suture/v4"
|
||||
@@ -27,7 +28,7 @@ func AppProvider(cfg *config.Config) *cli.Command {
|
||||
return ParseConfig(c, cfg, "storage-app-provider")
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
logger := NewLogger(cfg)
|
||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||
tracing.Configure(cfg, logger)
|
||||
gr := run.Group{}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
|
||||
"github.com/owncloud/ocis/ocis-pkg/sync"
|
||||
"github.com/owncloud/ocis/storage/pkg/config"
|
||||
"github.com/owncloud/ocis/storage/pkg/logging"
|
||||
"github.com/owncloud/ocis/storage/pkg/server/debug"
|
||||
"github.com/owncloud/ocis/storage/pkg/tracing"
|
||||
"github.com/thejerf/suture/v4"
|
||||
@@ -28,7 +29,7 @@ func AuthBasic(cfg *config.Config) *cli.Command {
|
||||
return ParseConfig(c, cfg, "storage-auth-basic")
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
logger := NewLogger(cfg)
|
||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||
tracing.Configure(cfg, logger)
|
||||
gr := run.Group{}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
|
||||
"github.com/owncloud/ocis/ocis-pkg/sync"
|
||||
"github.com/owncloud/ocis/storage/pkg/config"
|
||||
"github.com/owncloud/ocis/storage/pkg/logging"
|
||||
"github.com/owncloud/ocis/storage/pkg/server/debug"
|
||||
"github.com/owncloud/ocis/storage/pkg/tracing"
|
||||
"github.com/thejerf/suture/v4"
|
||||
@@ -27,7 +28,7 @@ func AuthBearer(cfg *config.Config) *cli.Command {
|
||||
return ParseConfig(c, cfg, "storage-auth-bearer")
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
logger := NewLogger(cfg)
|
||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||
tracing.Configure(cfg, logger)
|
||||
gr := run.Group{}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
|
||||
"github.com/owncloud/ocis/ocis-pkg/sync"
|
||||
"github.com/owncloud/ocis/storage/pkg/config"
|
||||
"github.com/owncloud/ocis/storage/pkg/logging"
|
||||
"github.com/owncloud/ocis/storage/pkg/server/debug"
|
||||
"github.com/owncloud/ocis/storage/pkg/tracing"
|
||||
"github.com/thejerf/suture/v4"
|
||||
@@ -27,7 +28,7 @@ func AuthMachine(cfg *config.Config) *cli.Command {
|
||||
return ParseConfig(c, cfg, "storage-auth-machine")
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
logger := NewLogger(cfg)
|
||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||
tracing.Configure(cfg, logger)
|
||||
gr := run.Group{}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
"github.com/owncloud/ocis/ocis-pkg/conversions"
|
||||
"github.com/owncloud/ocis/ocis-pkg/sync"
|
||||
"github.com/owncloud/ocis/storage/pkg/config"
|
||||
"github.com/owncloud/ocis/storage/pkg/logging"
|
||||
"github.com/owncloud/ocis/storage/pkg/server/debug"
|
||||
"github.com/owncloud/ocis/storage/pkg/tracing"
|
||||
"github.com/thejerf/suture/v4"
|
||||
@@ -34,7 +35,7 @@ func Frontend(cfg *config.Config) *cli.Command {
|
||||
return ParseConfig(c, cfg, "storage-frontend")
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
logger := NewLogger(cfg)
|
||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||
|
||||
tracing.Configure(cfg, logger)
|
||||
|
||||
|
||||
@@ -15,10 +15,10 @@ import (
|
||||
"github.com/oklog/run"
|
||||
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
|
||||
"github.com/owncloud/ocis/ocis-pkg/log"
|
||||
"github.com/owncloud/ocis/ocis-pkg/shared"
|
||||
"github.com/owncloud/ocis/ocis-pkg/sync"
|
||||
"github.com/owncloud/ocis/ocis-pkg/version"
|
||||
"github.com/owncloud/ocis/storage/pkg/config"
|
||||
"github.com/owncloud/ocis/storage/pkg/logging"
|
||||
"github.com/owncloud/ocis/storage/pkg/server/debug"
|
||||
"github.com/owncloud/ocis/storage/pkg/service/external"
|
||||
"github.com/owncloud/ocis/storage/pkg/tracing"
|
||||
@@ -43,7 +43,7 @@ func Gateway(cfg *config.Config) *cli.Command {
|
||||
return nil
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
logger := NewLogger(cfg)
|
||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||
tracing.Configure(cfg, logger)
|
||||
gr := run.Group{}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
@@ -425,16 +425,16 @@ func ParseConfig(c *cli.Context, cfg *config.Config, storageExtension string) er
|
||||
}
|
||||
|
||||
// provide with defaults for shared logging, since we need a valid destination address for BindEnv.
|
||||
if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil {
|
||||
cfg.Log = &shared.Log{
|
||||
Level: cfg.Commons.Log.Level,
|
||||
Pretty: cfg.Commons.Log.Pretty,
|
||||
Color: cfg.Commons.Log.Color,
|
||||
File: cfg.Commons.Log.File,
|
||||
}
|
||||
} else if cfg.Log == nil && cfg.Commons == nil {
|
||||
cfg.Log = &shared.Log{}
|
||||
}
|
||||
//if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil {
|
||||
// cfg.Log = &shared.Log{
|
||||
// Level: cfg.Commons.Log.Level,
|
||||
// Pretty: cfg.Commons.Log.Pretty,
|
||||
// Color: cfg.Commons.Log.Color,
|
||||
// File: cfg.Commons.Log.File,
|
||||
// }
|
||||
//} else if cfg.Log == nil && cfg.Commons == nil {
|
||||
// cfg.Log = &shared.Log{}
|
||||
//}
|
||||
|
||||
// load all env variables relevant to the config in the current context.
|
||||
conf.LoadOSEnv(config.GetEnv(cfg), false)
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
|
||||
"github.com/owncloud/ocis/ocis-pkg/sync"
|
||||
"github.com/owncloud/ocis/storage/pkg/config"
|
||||
"github.com/owncloud/ocis/storage/pkg/logging"
|
||||
"github.com/owncloud/ocis/storage/pkg/server/debug"
|
||||
"github.com/owncloud/ocis/storage/pkg/tracing"
|
||||
"github.com/thejerf/suture/v4"
|
||||
@@ -28,7 +29,7 @@ func Groups(cfg *config.Config) *cli.Command {
|
||||
return ParseConfig(c, cfg, "storage-groups")
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
logger := NewLogger(cfg)
|
||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||
tracing.Configure(cfg, logger)
|
||||
gr := run.Group{}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/owncloud/ocis/storage/pkg/config"
|
||||
"github.com/owncloud/ocis/storage/pkg/logging"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
@@ -17,7 +18,7 @@ func Health(cfg *config.Config) *cli.Command {
|
||||
return ParseConfig(c, cfg, "storage")
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
logger := NewLogger(cfg)
|
||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||
|
||||
resp, err := http.Get(
|
||||
fmt.Sprintf(
|
||||
|
||||
@@ -3,7 +3,6 @@ package command
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/owncloud/ocis/ocis-pkg/log"
|
||||
"github.com/owncloud/ocis/ocis-pkg/version"
|
||||
"github.com/owncloud/ocis/storage/pkg/config"
|
||||
"github.com/urfave/cli/v2"
|
||||
@@ -23,8 +22,10 @@ func Execute(cfg *config.Config) error {
|
||||
Email: "support@owncloud.com",
|
||||
},
|
||||
},
|
||||
|
||||
Before: func(c *cli.Context) error {
|
||||
return ParseConfig(c, cfg, "storage")
|
||||
cfg.Service.Version = version.String
|
||||
return ParseConfig(c, cfg, "_")
|
||||
},
|
||||
|
||||
Commands: []*cli.Command{
|
||||
@@ -57,14 +58,3 @@ func Execute(cfg *config.Config) error {
|
||||
|
||||
return app.Run(os.Args)
|
||||
}
|
||||
|
||||
// NewLogger initializes a service-specific logger instance.
|
||||
func NewLogger(cfg *config.Config) log.Logger {
|
||||
return log.NewLogger(
|
||||
log.Name("storage"),
|
||||
log.Level(cfg.Log.Level),
|
||||
log.Pretty(cfg.Log.Pretty),
|
||||
log.Color(cfg.Log.Color),
|
||||
log.File(cfg.Log.File),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/owncloud/ocis/storage/pkg/logging"
|
||||
"github.com/owncloud/ocis/storage/pkg/tracing"
|
||||
|
||||
"github.com/owncloud/ocis/ocis-pkg/sync"
|
||||
@@ -30,7 +31,7 @@ func Sharing(cfg *config.Config) *cli.Command {
|
||||
return ParseConfig(c, cfg, "storage-sharing")
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
logger := NewLogger(cfg)
|
||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||
|
||||
tracing.Configure(cfg, logger)
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"path"
|
||||
|
||||
"github.com/owncloud/ocis/ocis-pkg/sync"
|
||||
"github.com/owncloud/ocis/storage/pkg/logging"
|
||||
|
||||
"github.com/cs3org/reva/cmd/revad/runtime"
|
||||
"github.com/gofrs/uuid"
|
||||
@@ -34,7 +35,7 @@ func StorageMetadata(cfg *config.Config) *cli.Command {
|
||||
},
|
||||
Category: "Extensions",
|
||||
Action: func(c *cli.Context) error {
|
||||
logger := NewLogger(cfg)
|
||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||
tracing.Configure(cfg, logger)
|
||||
|
||||
gr := run.Group{}
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
|
||||
"github.com/owncloud/ocis/ocis-pkg/sync"
|
||||
"github.com/owncloud/ocis/storage/pkg/config"
|
||||
"github.com/owncloud/ocis/storage/pkg/logging"
|
||||
"github.com/owncloud/ocis/storage/pkg/server/debug"
|
||||
"github.com/owncloud/ocis/storage/pkg/tracing"
|
||||
"github.com/thejerf/suture/v4"
|
||||
@@ -28,7 +29,7 @@ func StoragePublicLink(cfg *config.Config) *cli.Command {
|
||||
},
|
||||
Category: "Extensions",
|
||||
Action: func(c *cli.Context) error {
|
||||
logger := NewLogger(cfg)
|
||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||
tracing.Configure(cfg, logger)
|
||||
gr := run.Group{}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"path"
|
||||
|
||||
"github.com/owncloud/ocis/ocis-pkg/sync"
|
||||
"github.com/owncloud/ocis/storage/pkg/logging"
|
||||
|
||||
"github.com/cs3org/reva/cmd/revad/runtime"
|
||||
"github.com/gofrs/uuid"
|
||||
@@ -28,7 +29,7 @@ func StorageShares(cfg *config.Config) *cli.Command {
|
||||
return ParseConfig(c, cfg, "storage-shares")
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
logger := NewLogger(cfg)
|
||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||
|
||||
tracing.Configure(cfg, logger)
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/owncloud/ocis/ocis-pkg/sync"
|
||||
"github.com/owncloud/ocis/storage/pkg/command/storagedrivers"
|
||||
"github.com/owncloud/ocis/storage/pkg/config"
|
||||
"github.com/owncloud/ocis/storage/pkg/logging"
|
||||
"github.com/owncloud/ocis/storage/pkg/server/debug"
|
||||
"github.com/owncloud/ocis/storage/pkg/tracing"
|
||||
"github.com/thejerf/suture/v4"
|
||||
@@ -28,7 +29,7 @@ func StorageUsers(cfg *config.Config) *cli.Command {
|
||||
return ParseConfig(c, cfg, "storage-userprovider")
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
logger := NewLogger(cfg)
|
||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||
|
||||
tracing.Configure(cfg, logger)
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
|
||||
"github.com/owncloud/ocis/ocis-pkg/sync"
|
||||
"github.com/owncloud/ocis/storage/pkg/config"
|
||||
"github.com/owncloud/ocis/storage/pkg/logging"
|
||||
"github.com/owncloud/ocis/storage/pkg/server/debug"
|
||||
"github.com/owncloud/ocis/storage/pkg/tracing"
|
||||
"github.com/thejerf/suture/v4"
|
||||
@@ -28,7 +29,7 @@ func Users(cfg *config.Config) *cli.Command {
|
||||
return ParseConfig(c, cfg, "storage-users")
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
logger := NewLogger(cfg)
|
||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||
|
||||
tracing.Configure(cfg, logger)
|
||||
|
||||
|
||||
@@ -10,6 +10,12 @@ import (
|
||||
"github.com/owncloud/ocis/ocis-pkg/shared"
|
||||
)
|
||||
|
||||
// Service defines the available service configuration.
|
||||
type Service struct {
|
||||
Name string
|
||||
Version string
|
||||
}
|
||||
|
||||
// Log defines the available logging configuration.
|
||||
type Log struct {
|
||||
Level string `ocisConfig:"level"`
|
||||
@@ -507,16 +513,15 @@ type Asset struct {
|
||||
type Config struct {
|
||||
*shared.Commons
|
||||
|
||||
Log *shared.Log `ocisConfig:"log"`
|
||||
Debug Debug `ocisConfig:"debug"`
|
||||
Reva Reva `ocisConfig:"reva"`
|
||||
Tracing Tracing `ocisConfig:"tracing"`
|
||||
Asset Asset `ocisConfig:"asset"`
|
||||
}
|
||||
Service Service `ocisConfig:"service"`
|
||||
|
||||
// New initializes a new configuration with or without defaults.
|
||||
func New() *Config {
|
||||
return &Config{}
|
||||
Tracing Tracing `ocisConfig:"tracing"`
|
||||
Log Log `ocisConfig:"log"`
|
||||
Debug Debug `ocisConfig:"debug"`
|
||||
|
||||
Reva Reva `ocisConfig:"reva"`
|
||||
|
||||
Asset Asset `ocisConfig:"asset"`
|
||||
}
|
||||
|
||||
func DefaultConfig() *Config {
|
||||
|
||||
17
storage/pkg/logging/logging.go
Normal file
17
storage/pkg/logging/logging.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package logging
|
||||
|
||||
import (
|
||||
"github.com/owncloud/ocis/ocis-pkg/log"
|
||||
"github.com/owncloud/ocis/storage/pkg/config"
|
||||
)
|
||||
|
||||
// LoggerFromConfig initializes a service-specific logger instance.
|
||||
func Configure(name string, cfg config.Log) log.Logger {
|
||||
return log.NewLogger(
|
||||
log.Name(name),
|
||||
log.Level(cfg.Level),
|
||||
log.Pretty(cfg.Pretty),
|
||||
log.Color(cfg.Color),
|
||||
log.File(cfg.File),
|
||||
)
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/owncloud/ocis/store/pkg/config"
|
||||
"github.com/owncloud/ocis/store/pkg/logging"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
@@ -17,7 +18,7 @@ func Health(cfg *config.Config) *cli.Command {
|
||||
return ParseConfig(c, cfg)
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
logger := NewLogger(cfg)
|
||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||
|
||||
resp, err := http.Get(
|
||||
fmt.Sprintf(
|
||||
|
||||
@@ -4,12 +4,13 @@ import (
|
||||
"context"
|
||||
"os"
|
||||
|
||||
"github.com/imdario/mergo"
|
||||
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/store/pkg/config"
|
||||
"github.com/thejerf/suture/v4"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/wkloucek/envdecode"
|
||||
)
|
||||
|
||||
// Execute is the entry point for the ocis-store command.
|
||||
@@ -52,29 +53,37 @@ func Execute(cfg *config.Config) error {
|
||||
return app.Run(os.Args)
|
||||
}
|
||||
|
||||
// NewLogger initializes a service-specific logger instance.
|
||||
func NewLogger(cfg *config.Config) log.Logger {
|
||||
return log.NewLogger(
|
||||
log.Name("store"),
|
||||
log.Level(cfg.Log.Level),
|
||||
log.Pretty(cfg.Log.Pretty),
|
||||
log.Color(cfg.Log.Color),
|
||||
log.File(cfg.Log.File),
|
||||
)
|
||||
}
|
||||
|
||||
// ParseConfig loads idp configuration from known paths.
|
||||
// ParseConfig loads accounts configuration from known paths.
|
||||
func ParseConfig(c *cli.Context, cfg *config.Config) error {
|
||||
conf, err := ociscfg.BindSourcesToStructs("store", cfg)
|
||||
_, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// load all env variables relevant to the config in the current context.
|
||||
conf.LoadOSEnv(config.GetEnv(), false)
|
||||
// provide with defaults for shared logging, since we need a valid destination address for BindEnv.
|
||||
//if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil {
|
||||
// cfg.Log = &shared.Log{
|
||||
// Level: cfg.Commons.Log.Level,
|
||||
// Pretty: cfg.Commons.Log.Pretty,
|
||||
// Color: cfg.Commons.Log.Color,
|
||||
// File: cfg.Commons.Log.File,
|
||||
// }
|
||||
//} else if cfg.Log == nil && cfg.Commons == nil {
|
||||
// cfg.Log = &shared.Log{}
|
||||
//}
|
||||
|
||||
bindings := config.StructMappings(cfg)
|
||||
return ociscfg.BindEnv(conf, bindings)
|
||||
// load all env variables relevant to the config in the current context.
|
||||
envCfg := config.Config{}
|
||||
if err := envdecode.Decode(&envCfg); err != nil && err.Error() != "none of the target fields were set from environment variables" {
|
||||
return err
|
||||
}
|
||||
|
||||
// merge environment variable config on top of the current config
|
||||
if err := mergo.Merge(cfg, envCfg, mergo.WithOverride); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SutureService allows for the store command to be embedded and supervised by a suture supervisor tree.
|
||||
|
||||
@@ -3,10 +3,7 @@ package command
|
||||
import (
|
||||
"context"
|
||||
|
||||
gofig "github.com/gookit/config/v2"
|
||||
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
|
||||
"github.com/owncloud/ocis/ocis-pkg/shared"
|
||||
|
||||
"github.com/owncloud/ocis/store/pkg/logging"
|
||||
"github.com/owncloud/ocis/store/pkg/tracing"
|
||||
|
||||
"github.com/oklog/run"
|
||||
@@ -23,31 +20,16 @@ func Server(cfg *config.Config) *cli.Command {
|
||||
Name: "server",
|
||||
Usage: "Start integrated server",
|
||||
Before: func(ctx *cli.Context) error {
|
||||
// remember shared logging info to prevent empty overwrites
|
||||
inLog := cfg.Log
|
||||
if err := ParseConfig(ctx, cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if (cfg.Log == shared.Log{}) && (inLog != shared.Log{}) {
|
||||
// set the default to the parent config
|
||||
cfg.Log = inLog
|
||||
|
||||
// and parse the environment
|
||||
conf := &gofig.Config{}
|
||||
conf.LoadOSEnv(config.GetEnv(), false)
|
||||
bindings := config.StructMappings(cfg)
|
||||
if err := ociscfg.BindEnv(conf, bindings); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
logger := NewLogger(cfg)
|
||||
|
||||
if err := tracing.Configure(cfg); err != nil {
|
||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||
err := tracing.Configure(cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -5,60 +5,63 @@ import (
|
||||
"path"
|
||||
|
||||
"github.com/owncloud/ocis/ocis-pkg/config/defaults"
|
||||
"github.com/owncloud/ocis/ocis-pkg/shared"
|
||||
)
|
||||
|
||||
// Debug defines the available debug configuration.
|
||||
type Debug struct {
|
||||
Addr string `ocisConfig:"addr"`
|
||||
Token string `ocisConfig:"token"`
|
||||
Pprof bool `ocisConfig:"pprof"`
|
||||
Zpages bool `ocisConfig:"zpages"`
|
||||
Addr string `ocisConfig:"addr" env:"STORE_DEBUG_ADDR"`
|
||||
Token string `ocisConfig:"token" env:"STORE_DEBUG_TOKEN"`
|
||||
Pprof bool `ocisConfig:"pprof" env:"STORE_DEBUG_PPROF"`
|
||||
Zpages bool `ocisConfig:"zpages" env:"STORE_DEBUG_ZPAGES"`
|
||||
}
|
||||
|
||||
// GRPC defines the available grpc configuration.
|
||||
type GRPC struct {
|
||||
Addr string `ocisConfig:"addr"`
|
||||
Root string `ocisConfig:"root"`
|
||||
Addr string `ocisConfig:"addr" env:"STORE_GRPC_ADDR"`
|
||||
Namespace string
|
||||
}
|
||||
|
||||
// Service defines the available service configuration.
|
||||
type Service struct {
|
||||
Name string `ocisConfig:"name"`
|
||||
Version string `ocisConfig:"version"`
|
||||
Name string
|
||||
Version string
|
||||
}
|
||||
|
||||
// Tracing defines the available tracing configuration.
|
||||
type Tracing struct {
|
||||
Enabled bool `ocisConfig:"enabled"`
|
||||
Type string `ocisConfig:"type"`
|
||||
Endpoint string `ocisConfig:"endpoint"`
|
||||
Collector string `ocisConfig:"collector"`
|
||||
Service string `ocisConfig:"service"`
|
||||
Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;STORE_TRACING_ENABLED"`
|
||||
Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;STORE_TRACING_TYPE"`
|
||||
Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;STORE_TRACING_ENDPOINT"`
|
||||
Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;STORE_TRACING_COLLECTOR"`
|
||||
Service string `ocisConfig:"service" env:"STORE_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name?
|
||||
}
|
||||
|
||||
// Log defines the available log configuration.
|
||||
type Log struct {
|
||||
Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;STORE_LOG_LEVEL"`
|
||||
Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;STORE_LOG_PRETTY"`
|
||||
Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;STORE_LOG_COLOR"`
|
||||
File string `mapstructure:"file" env:"OCIS_LOG_FILE;STORE_LOG_FILE"`
|
||||
}
|
||||
|
||||
// Config combines all available configuration parts.
|
||||
type Config struct {
|
||||
Log shared.Log `ocisConfig:"log"`
|
||||
Debug Debug `ocisConfig:"debug"`
|
||||
GRPC GRPC `ocisConfig:"grpc"`
|
||||
Tracing Tracing `ocisConfig:"tracing"`
|
||||
Datapath string `ocisConfig:"data_path"`
|
||||
Service Service `ocisConfig:"service"`
|
||||
Service Service `ocisConfig:"service"`
|
||||
|
||||
Tracing Tracing `ocisConfig:"tracing"`
|
||||
Log Log `ocisConfig:"log"`
|
||||
Debug Debug `ocisConfig:"debug"`
|
||||
|
||||
GRPC GRPC `ocisConfig:"grpc"`
|
||||
|
||||
Datapath string `ocisConfig:"data_path" env:"STORE_DATA_PATH"`
|
||||
|
||||
Context context.Context
|
||||
Supervised bool
|
||||
}
|
||||
|
||||
// New initializes a new configuration with or without defaults.
|
||||
func New() *Config {
|
||||
return &Config{}
|
||||
}
|
||||
|
||||
func DefaultConfig() *Config {
|
||||
return &Config{
|
||||
Log: shared.Log{},
|
||||
Debug: Debug{
|
||||
Addr: "127.0.0.1:9464",
|
||||
Token: "",
|
||||
@@ -82,14 +85,3 @@ func DefaultConfig() *Config {
|
||||
Datapath: path.Join(defaults.BaseDataPath(), "store"),
|
||||
}
|
||||
}
|
||||
|
||||
// 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 {
|
||||
var r = make([]string, len(structMappings(&Config{})))
|
||||
for i := range structMappings(&Config{}) {
|
||||
r = append(r, structMappings(&Config{})[i].EnvVars...)
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
package config
|
||||
|
||||
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) []shared.EnvBinding {
|
||||
return []shared.EnvBinding{
|
||||
{
|
||||
EnvVars: []string{"OCIS_LOG_LEVEL", "STORE_LOG_LEVEL"},
|
||||
Destination: &cfg.Log.Level,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_LOG_PRETTY", "STORE_LOG_PRETTY"},
|
||||
Destination: &cfg.Log.Pretty,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_LOG_COLOR", "STORE_LOG_COLOR"},
|
||||
Destination: &cfg.Log.Color,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_LOG_FILE", "STORE_LOG_FILE"},
|
||||
Destination: &cfg.Log.File,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_TRACING_ENABLED", "STORE_TRACING_ENABLED"},
|
||||
Destination: &cfg.Tracing.Enabled,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_TRACING_TYPE", "STORE_TRACING_TYPE"},
|
||||
Destination: &cfg.Tracing.Type,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_TRACING_ENDPOINT", "STORE_TRACING_ENDPOINT"},
|
||||
Destination: &cfg.Tracing.Endpoint,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"OCIS_TRACING_COLLECTOR", "STORE_TRACING_COLLECTOR"},
|
||||
Destination: &cfg.Tracing.Collector,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"STORE_TRACING_SERVICE"},
|
||||
Destination: &cfg.Tracing.Service,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"STORE_DEBUG_ADDR"},
|
||||
Destination: &cfg.Debug.Addr,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"STORE_DEBUG_TOKEN"},
|
||||
Destination: &cfg.Debug.Token,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"STORE_DEBUG_PPROF"},
|
||||
Destination: &cfg.Debug.Pprof,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"STORE_DEBUG_ZPAGES"},
|
||||
Destination: &cfg.Debug.Zpages,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"STORE_GRPC_NAMESPACE"},
|
||||
Destination: &cfg.GRPC.Namespace,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"STORE_GRPC_ADDR"},
|
||||
Destination: &cfg.GRPC.Addr,
|
||||
},
|
||||
{
|
||||
EnvVars: []string{"STORE_DATA_PATH"},
|
||||
Destination: &cfg.Datapath,
|
||||
},
|
||||
}
|
||||
}
|
||||
17
store/pkg/logging/logging.go
Normal file
17
store/pkg/logging/logging.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package logging
|
||||
|
||||
import (
|
||||
"github.com/owncloud/ocis/ocis-pkg/log"
|
||||
"github.com/owncloud/ocis/store/pkg/config"
|
||||
)
|
||||
|
||||
// LoggerFromConfig initializes a service-specific logger instance.
|
||||
func Configure(name string, cfg config.Log) log.Logger {
|
||||
return log.NewLogger(
|
||||
log.Name(name),
|
||||
log.Level(cfg.Level),
|
||||
log.Pretty(cfg.Pretty),
|
||||
log.Color(cfg.Color),
|
||||
log.File(cfg.File),
|
||||
)
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/owncloud/ocis/thumbnails/pkg/config"
|
||||
"github.com/owncloud/ocis/thumbnails/pkg/logging"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
@@ -17,7 +18,7 @@ func Health(cfg *config.Config) *cli.Command {
|
||||
return ParseConfig(c, cfg)
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
logger := NewLogger(cfg)
|
||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||
|
||||
resp, err := http.Get(
|
||||
fmt.Sprintf(
|
||||
|
||||
@@ -4,14 +4,13 @@ import (
|
||||
"context"
|
||||
"os"
|
||||
|
||||
"github.com/owncloud/ocis/ocis-pkg/shared"
|
||||
|
||||
"github.com/imdario/mergo"
|
||||
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/thumbnails/pkg/config"
|
||||
"github.com/thejerf/suture/v4"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/wkloucek/envdecode"
|
||||
)
|
||||
|
||||
// Execute is the entry point for the ocis-thumbnails command.
|
||||
@@ -31,7 +30,7 @@ func Execute(cfg *config.Config) error {
|
||||
|
||||
Before: func(c *cli.Context) error {
|
||||
cfg.Service.Version = version.String
|
||||
return nil
|
||||
return ParseConfig(c, cfg)
|
||||
},
|
||||
|
||||
Commands: []*cli.Command{
|
||||
@@ -54,40 +53,37 @@ func Execute(cfg *config.Config) error {
|
||||
return app.Run(os.Args)
|
||||
}
|
||||
|
||||
// NewLogger initializes a service-specific logger instance.
|
||||
func NewLogger(cfg *config.Config) log.Logger {
|
||||
return log.NewLogger(
|
||||
log.Name("thumbnails"),
|
||||
log.Level(cfg.Log.Level),
|
||||
log.Pretty(cfg.Log.Pretty),
|
||||
log.Color(cfg.Log.Color),
|
||||
log.File(cfg.Log.File),
|
||||
)
|
||||
}
|
||||
|
||||
// ParseConfig loads configuration from Viper known paths.
|
||||
// ParseConfig loads glauth configuration from known paths.
|
||||
// ParseConfig loads accounts configuration from known paths.
|
||||
func ParseConfig(c *cli.Context, cfg *config.Config) error {
|
||||
conf, err := ociscfg.BindSourcesToStructs("thumbnails", cfg)
|
||||
_, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// provide with defaults for shared logging, since we need a valid destination address for BindEnv.
|
||||
if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil {
|
||||
cfg.Log = &shared.Log{
|
||||
Level: cfg.Commons.Log.Level,
|
||||
Pretty: cfg.Commons.Log.Pretty,
|
||||
Color: cfg.Commons.Log.Color,
|
||||
File: cfg.Commons.Log.File,
|
||||
}
|
||||
} else if cfg.Log == nil && cfg.Commons == nil {
|
||||
cfg.Log = &shared.Log{}
|
||||
//if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil {
|
||||
// cfg.Log = &shared.Log{
|
||||
// Level: cfg.Commons.Log.Level,
|
||||
// Pretty: cfg.Commons.Log.Pretty,
|
||||
// Color: cfg.Commons.Log.Color,
|
||||
// File: cfg.Commons.Log.File,
|
||||
// }
|
||||
//} else if cfg.Log == nil && cfg.Commons == nil {
|
||||
// cfg.Log = &shared.Log{}
|
||||
//}
|
||||
|
||||
// load all env variables relevant to the config in the current context.
|
||||
envCfg := config.Config{}
|
||||
if err := envdecode.Decode(&envCfg); err != nil && err.Error() != "none of the target fields were set from environment variables" {
|
||||
return err
|
||||
}
|
||||
|
||||
conf.LoadOSEnv(config.GetEnv(cfg), false)
|
||||
bindings := config.StructMappings(cfg)
|
||||
return ociscfg.BindEnv(conf, bindings)
|
||||
// merge environment variable config on top of the current config
|
||||
if err := mergo.Merge(cfg, envCfg, mergo.WithOverride); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SutureService allows for the thumbnails command to be embedded and supervised by a suture supervisor tree.
|
||||
@@ -97,7 +93,7 @@ type SutureService struct {
|
||||
|
||||
// NewSutureService creates a new thumbnails.SutureService
|
||||
func NewSutureService(cfg *ociscfg.Config) suture.Service {
|
||||
cfg.Thumbnails.Commons = cfg.Commons
|
||||
//cfg.Thumbnails.Commons = cfg.Commons
|
||||
return SutureService{
|
||||
cfg: cfg.Thumbnails,
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/oklog/run"
|
||||
"github.com/owncloud/ocis/thumbnails/pkg/config"
|
||||
"github.com/owncloud/ocis/thumbnails/pkg/logging"
|
||||
"github.com/owncloud/ocis/thumbnails/pkg/metrics"
|
||||
"github.com/owncloud/ocis/thumbnails/pkg/server/debug"
|
||||
"github.com/owncloud/ocis/thumbnails/pkg/server/grpc"
|
||||
@@ -25,8 +26,9 @@ func Server(cfg *config.Config) *cli.Command {
|
||||
return nil
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
logger := NewLogger(cfg)
|
||||
if err := tracing.Configure(cfg); err != nil {
|
||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||
err := tracing.Configure(cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -5,49 +5,56 @@ import (
|
||||
"path"
|
||||
|
||||
"github.com/owncloud/ocis/ocis-pkg/config/defaults"
|
||||
"github.com/owncloud/ocis/ocis-pkg/shared"
|
||||
)
|
||||
|
||||
// Debug defines the available debug configuration.
|
||||
type Debug struct {
|
||||
Addr string `ocisConfig:"addr"`
|
||||
Token string `ocisConfig:"token"`
|
||||
Pprof bool `ocisConfig:"pprof"`
|
||||
Zpages bool `ocisConfig:"zpages"`
|
||||
Addr string `ocisConfig:"addr" env:"THUMBNAILS_DEBUG_ADDR"`
|
||||
Token string `ocisConfig:"token" env:"THUMBNAILS_DEBUG_TOKEN"`
|
||||
Pprof bool `ocisConfig:"pprof" env:"THUMBNAILS_DEBUG_PPROF"`
|
||||
Zpages bool `ocisConfig:"zpages" env:"THUMBNAILS_DEBUG_ZPAGES"`
|
||||
}
|
||||
|
||||
// GRPC defines the available grpc configuration.
|
||||
type GRPC struct {
|
||||
Addr string `ocisConfig:"addr"`
|
||||
Addr string `ocisConfig:"addr" env:"THUMBNAILS_GRPC_ADDR"`
|
||||
Namespace string
|
||||
}
|
||||
|
||||
// Service provides configuration options for the service
|
||||
// Service defines the available service configuration.
|
||||
type Service struct {
|
||||
Name string `ocisConfig:"name"`
|
||||
Version string `ocisConfig:"version"`
|
||||
Name string
|
||||
Version string
|
||||
}
|
||||
|
||||
// Tracing defines the available tracing configuration.
|
||||
type Tracing struct {
|
||||
Enabled bool `ocisConfig:"enabled"`
|
||||
Type string `ocisConfig:"type"`
|
||||
Endpoint string `ocisConfig:"endpoint"`
|
||||
Collector string `ocisConfig:"collector"`
|
||||
Service string `ocisConfig:"service"`
|
||||
Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;THUMBNAILS_TRACING_ENABLED"`
|
||||
Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;THUMBNAILS_TRACING_TYPE"`
|
||||
Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;THUMBNAILS_TRACING_ENDPOINT"`
|
||||
Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;THUMBNAILS_TRACING_COLLECTOR"`
|
||||
Service string `ocisConfig:"service" env:"THUMBNAILS_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name?
|
||||
}
|
||||
|
||||
// Log defines the available log configuration.
|
||||
type Log struct {
|
||||
Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;THUMBNAILS_LOG_LEVEL"`
|
||||
Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;THUMBNAILS_LOG_PRETTY"`
|
||||
Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;THUMBNAILS_LOG_COLOR"`
|
||||
File string `mapstructure:"file" env:"OCIS_LOG_FILE;THUMBNAILS_LOG_FILE"`
|
||||
}
|
||||
|
||||
// Config combines all available configuration parts.
|
||||
type Config struct {
|
||||
*shared.Commons
|
||||
Service Service `ocisConfig:"service"`
|
||||
|
||||
File string `ocisConfig:"file"`
|
||||
Log *shared.Log `ocisConfig:"log"`
|
||||
Debug Debug `ocisConfig:"debug"`
|
||||
GRPC GRPC `ocisConfig:"grpc"`
|
||||
Service Service `ocisConfig:"service"`
|
||||
Tracing Tracing `ocisConfig:"tracing"`
|
||||
Thumbnail Thumbnail `ocisConfig:"thumbnail"`
|
||||
Tracing Tracing `ocisConfig:"tracing"`
|
||||
Log Log `ocisConfig:"log"`
|
||||
Debug Debug `ocisConfig:"debug"`
|
||||
|
||||
GRPC GRPC `ocisConfig:"grpc"`
|
||||
|
||||
Thumbnail Thumbnail `ocisConfig:"thumbnail"`
|
||||
|
||||
Context context.Context
|
||||
Supervised bool
|
||||
@@ -55,7 +62,7 @@ type Config struct {
|
||||
|
||||
// FileSystemStorage defines the available filesystem storage configuration.
|
||||
type FileSystemStorage struct {
|
||||
RootDirectory string `ocisConfig:"root_directory"`
|
||||
RootDirectory string `ocisConfig:"root_directory" env:"THUMBNAILS_FILESYSTEMSTORAGE_ROOT"`
|
||||
}
|
||||
|
||||
// FileSystemSource defines the available filesystem source configuration.
|
||||
@@ -65,17 +72,12 @@ type FileSystemSource struct {
|
||||
|
||||
// Thumbnail defines the available thumbnail related configuration.
|
||||
type Thumbnail struct {
|
||||
Resolutions []string `ocisConfig:"resolutions"`
|
||||
Resolutions []string `ocisConfig:"resolutions"` // TODO: how to configure
|
||||
FileSystemStorage FileSystemStorage `ocisConfig:"filesystem_storage"`
|
||||
WebdavAllowInsecure bool `ocisConfig:"webdav_allow_insecure"`
|
||||
CS3AllowInsecure bool `ocisConfig:"cs3_allow_insecure"`
|
||||
RevaGateway string `ocisConfig:"reva_gateway"`
|
||||
FontMapFile string `ocisConfig:"font_map_file"`
|
||||
}
|
||||
|
||||
// New initializes a new configuration with or without defaults.
|
||||
func New() *Config {
|
||||
return &Config{}
|
||||
WebdavAllowInsecure bool `ocisConfig:"webdav_allow_insecure" env:"OCIS_INSECURE;THUMBNAILS_WEBDAVSOURCE_INSECURE"`
|
||||
CS3AllowInsecure bool `ocisConfig:"cs3_allow_insecure" env:"OCIS_INSECURE;THUMBNAILS_CS3SOURCE_INSECURE"`
|
||||
RevaGateway string `ocisConfig:"reva_gateway" env:"REVA_GATEWAY"`
|
||||
FontMapFile string `ocisConfig:"font_map_file" env:"THUMBNAILS_TXT_FONTMAP_FILE"`
|
||||
}
|
||||
|
||||
func DefaultConfig() *Config {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user