losing my mind

This commit is contained in:
A.Unger
2021-11-11 15:12:37 +01:00
parent a29f10e764
commit 3580e16771
21 changed files with 59 additions and 66 deletions

View File

@@ -5,7 +5,6 @@ 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/settings/pkg/command"
"github.com/urfave/cli/v2"
@@ -13,8 +12,6 @@ import (
// SettingsCommand is the entry point for the settings command.
func SettingsCommand(cfg *config.Config) *cli.Command {
var globalLog shared.Log
return &cli.Command{
Name: "settings",
Usage: "Start settings server",
@@ -27,16 +24,13 @@ func SettingsCommand(cfg *config.Config) *cli.Command {
return err
}
globalLog = cfg.Log
if cfg.Commons != nil {
cfg.Settings.Commons = cfg.Commons
}
return nil
},
Action: func(c *cli.Context) error {
// if accounts logging is empty in ocis.yaml
if (cfg.Settings.Log == shared.Log{}) && (globalLog != shared.Log{}) {
// we can safely inherit the global logging values.
cfg.Settings.Log = globalLog
}
origCmd := command.Server(cfg.Settings)
return handleOriginalAction(c, origCmd)
},

View File

@@ -159,6 +159,11 @@ func Start(o ...Option) error {
FailureBackoff: 3 * time.Second,
})
s.cfg.Storage.Log.Color = s.cfg.Log.Color
s.cfg.Storage.Log.Level = s.cfg.Log.Level
s.cfg.Storage.Log.Pretty = s.cfg.Log.Pretty
s.cfg.Storage.Log.File = s.cfg.Log.File
if err = rpc.Register(s); err != nil {
if s != nil {
s.Log.Fatal().Err(err)

View File

@@ -71,7 +71,20 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error {
if err != nil {
return err
}
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{}
}
conf.LoadOSEnv(config.GetEnv(cfg), false)
bindings := config.StructMappings(cfg)
return ociscfg.BindEnv(conf, bindings)
}
@@ -83,9 +96,7 @@ type SutureService struct {
// NewSutureService creates a new settings.SutureService
func NewSutureService(cfg *ociscfg.Config) suture.Service {
if (cfg.Settings.Log == shared.Log{}) {
cfg.Settings.Log = cfg.Log
}
cfg.Settings.Commons = cfg.Commons
return SutureService{
cfg: cfg.Settings,
}

View File

@@ -4,10 +4,6 @@ import (
"context"
"strings"
gofig "github.com/gookit/config/v2"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/shared"
"github.com/oklog/run"
"github.com/owncloud/ocis/ocis-pkg/sync"
"github.com/owncloud/ocis/settings/pkg/config"
@@ -25,9 +21,6 @@ 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 cfg.HTTP.Root != "/" {
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
}
@@ -36,19 +29,6 @@ func Server(cfg *config.Config) *cli.Command {
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 {

View File

@@ -68,9 +68,11 @@ type TokenManager struct {
// Config combines all available configuration parts.
type Config struct {
*shared.Commons
File string
Service Service
Log shared.Log
Log *shared.Log
Debug Debug
HTTP HTTP
GRPC GRPC
@@ -90,7 +92,6 @@ func New() *Config {
// DefaultConfig provides sane bootstrapping defaults.
func DefaultConfig() *Config {
return &Config{
Log: shared.Log{},
Service: Service{
Name: "settings",
DataPath: path.Join(defaults.BaseDataPath(), "settings"),
@@ -132,14 +133,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
}

View File

@@ -2,6 +2,17 @@ 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.

View File

@@ -24,17 +24,17 @@ type Store struct {
// New creates a new store
func New(cfg *config.Config) settings.Manager {
s := Store{
Logger: olog.NewLogger(
olog.Color(cfg.Log.Color),
olog.Pretty(cfg.Log.Pretty),
olog.Level(cfg.Log.Level),
olog.File(cfg.Log.File),
),
//Logger: olog.NewLogger(
// olog.Color(cfg.Log.Color),
// olog.Pretty(cfg.Log.Pretty),
// olog.Level(cfg.Log.Level),
// olog.File(cfg.Log.File),
//),
}
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)
err = os.MkdirAll(cfg.Service.DataPath, 0700)
if err != nil {
s.Logger.Err(err).Msgf("providing container on %v", cfg.Service.DataPath)

View File

@@ -132,7 +132,7 @@ type AppProviderSutureService struct {
// NewAppProvider creates a new store.AppProviderSutureService
func NewAppProvider(cfg *ociscfg.Config) suture.Service {
cfg.Storage.Log = cfg.Commons.Log
cfg.Storage.Commons = cfg.Commons
return AppProviderSutureService{
cfg: cfg.Storage,
}

View File

@@ -151,7 +151,7 @@ type AuthBasicSutureService struct {
// NewAuthBasicSutureService creates a new store.AuthBasicSutureService
func NewAuthBasic(cfg *ociscfg.Config) suture.Service {
cfg.Storage.Log = cfg.Commons.Log
cfg.Storage.Commons = cfg.Commons
return AuthBasicSutureService{
cfg: cfg.Storage,
}

View File

@@ -127,7 +127,7 @@ type AuthBearerSutureService struct {
// NewAuthBearerSutureService creates a new gateway.AuthBearerSutureService
func NewAuthBearer(cfg *ociscfg.Config) suture.Service {
cfg.Storage.Log = cfg.Commons.Log
cfg.Storage.Commons = cfg.Commons
return AuthBearerSutureService{
cfg: cfg.Storage,
}

View File

@@ -123,7 +123,7 @@ type AuthMachineSutureService struct {
// NewAuthMachineSutureService creates a new gateway.AuthMachineSutureService
func NewAuthMachine(cfg *ociscfg.Config) suture.Service {
cfg.Storage.Log = cfg.Commons.Log
cfg.Storage.Commons = cfg.Commons
return AuthMachineSutureService{
cfg: cfg.Storage,
}

View File

@@ -337,7 +337,7 @@ type FrontendSutureService struct {
// NewFrontend creates a new frontend.FrontendSutureService
func NewFrontend(cfg *ociscfg.Config) suture.Service {
cfg.Storage.Log = cfg.Commons.Log
cfg.Storage.Commons = cfg.Commons
return FrontendSutureService{
cfg: cfg.Storage,
}

View File

@@ -351,7 +351,7 @@ type GatewaySutureService struct {
// NewGatewaySutureService creates a new gateway.GatewaySutureService
func NewGateway(cfg *ociscfg.Config) suture.Service {
cfg.Storage.Log = cfg.Commons.Log
cfg.Storage.Commons = cfg.Commons
return GatewaySutureService{
cfg: cfg.Storage,
}

View File

@@ -165,7 +165,7 @@ type GroupSutureService struct {
// NewGroupProviderSutureService creates a new storage.GroupProvider
func NewGroupProvider(cfg *ociscfg.Config) suture.Service {
cfg.Storage.Log = cfg.Commons.Log
cfg.Storage.Commons = cfg.Commons
return GroupSutureService{
cfg: cfg.Storage,
}

View File

@@ -191,7 +191,7 @@ type SharingSutureService struct {
// NewSharingSutureService creates a new store.SharingSutureService
func NewSharing(cfg *ociscfg.Config) suture.Service {
cfg.Storage.Log = cfg.Commons.Log
cfg.Storage.Commons = cfg.Commons
return SharingSutureService{
cfg: cfg.Storage,
}

View File

@@ -150,7 +150,7 @@ type StorageHomeSutureService struct {
// NewStorageHomeSutureService creates a new storage.StorageHomeSutureService
func NewStorageHome(cfg *ociscfg.Config) suture.Service {
cfg.Storage.Log = cfg.Commons.Log
cfg.Storage.Commons = cfg.Commons
return StorageHomeSutureService{
cfg: cfg.Storage,
}

View File

@@ -166,7 +166,7 @@ type MetadataSutureService struct {
// NewSutureService creates a new storagemetadata.SutureService
func NewStorageMetadata(cfg *ociscfg.Config) suture.Service {
cfg.Storage.Log = cfg.Commons.Log
cfg.Storage.Commons = cfg.Commons
return MetadataSutureService{
cfg: cfg.Storage,
}

View File

@@ -124,7 +124,7 @@ type StoragePublicLinkSutureService struct {
// NewStoragePublicLinkSutureService creates a new storage.StoragePublicLinkSutureService
func NewStoragePublicLink(cfg *ociscfg.Config) suture.Service {
cfg.Storage.Log = cfg.Commons.Log
cfg.Storage.Commons = cfg.Commons
return StoragePublicLinkSutureService{
cfg: cfg.Storage,
}

View File

@@ -150,7 +150,7 @@ type StorageUsersSutureService struct {
// NewStorageUsersSutureService creates a new storage.StorageUsersSutureService
func NewStorageUsers(cfg *ociscfg.Config) suture.Service {
cfg.Storage.Log = cfg.Commons.Log
cfg.Storage.Commons = cfg.Commons
return StorageUsersSutureService{
cfg: cfg.Storage,
}

View File

@@ -186,7 +186,7 @@ type UserProviderSutureService struct {
// NewUserProviderSutureService creates a new storage.UserProvider
func NewUserProvider(cfg *ociscfg.Config) suture.Service {
cfg.Storage.Log = cfg.Commons.Log
cfg.Storage.Commons = cfg.Commons
return UserProviderSutureService{
cfg: cfg.Storage,
}

View File

@@ -500,6 +500,8 @@ type Asset struct {
// Config combines all available configuration parts.
type Config struct {
*shared.Commons
File string
Log *shared.Log
Debug Debug