WIP - replace flags in storage commands

This commit is contained in:
A.Unger
2021-11-15 16:58:22 +01:00
parent fde5e35496
commit cfbe37de61
17 changed files with 811 additions and 354 deletions

View File

@@ -115,7 +115,7 @@ func New() *Config {
Store: store.DefaultConfig(),
Thumbnails: thumbnails.DefaultConfig(),
WebDAV: webdav.DefaultConfig(),
Storage: storage.New(),
Storage: storage.DefaultConfig(),
}
}
@@ -160,7 +160,7 @@ func DefaultConfig() *Config {
Store: store.DefaultConfig(),
Thumbnails: thumbnails.DefaultConfig(),
WebDAV: webdav.DefaultConfig(),
Storage: storage.New(),
Storage: storage.DefaultConfig(),
}
}

View 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)
}
}

View File

@@ -12,7 +12,6 @@ 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/flagset"
"github.com/owncloud/ocis/storage/pkg/server/debug"
"github.com/owncloud/ocis/storage/pkg/tracing"
"github.com/thejerf/suture/v4"
@@ -24,11 +23,11 @@ func AppProvider(cfg *config.Config) *cli.Command {
return &cli.Command{
Name: "app-provider",
Usage: "Start appprovider for providing apps",
Flags: flagset.AppProviderWithConfig(cfg),
//Flags: flagset.AppProviderWithConfig(cfg),
Before: func(c *cli.Context) error {
cfg.Reva.AppProvider.Services = c.StringSlice("service")
return nil
return ParseConfig(c, cfg, "storage-app-provider")
},
Action: func(c *cli.Context) error {
logger := NewLogger(cfg)

View File

@@ -13,7 +13,6 @@ 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/flagset"
"github.com/owncloud/ocis/storage/pkg/server/debug"
"github.com/owncloud/ocis/storage/pkg/tracing"
"github.com/thejerf/suture/v4"
@@ -25,11 +24,11 @@ func AuthBasic(cfg *config.Config) *cli.Command {
return &cli.Command{
Name: "auth-basic",
Usage: "Start authprovider for basic auth",
Flags: flagset.AuthBasicWithConfig(cfg),
//Flags: flagset.AuthBasicWithConfig(cfg),
Before: func(c *cli.Context) error {
cfg.Reva.AuthBasic.Services = c.StringSlice("service")
return nil
return ParseConfig(c, cfg, "storage-auth-basic")
},
Action: func(c *cli.Context) error {
logger := NewLogger(cfg)

View File

@@ -12,7 +12,6 @@ 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/flagset"
"github.com/owncloud/ocis/storage/pkg/server/debug"
"github.com/owncloud/ocis/storage/pkg/tracing"
"github.com/thejerf/suture/v4"
@@ -24,11 +23,11 @@ func AuthBearer(cfg *config.Config) *cli.Command {
return &cli.Command{
Name: "auth-bearer",
Usage: "Start authprovider for bearer auth",
Flags: flagset.AuthBearerWithConfig(cfg),
//Flags: flagset.AuthBearerWithConfig(cfg),
Before: func(c *cli.Context) error {
cfg.Reva.AuthBearer.Services = c.StringSlice("service")
return nil
return ParseConfig(c, cfg, "storage-auth-bearer")
},
Action: func(c *cli.Context) error {
logger := NewLogger(cfg)

View File

@@ -12,7 +12,6 @@ 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/flagset"
"github.com/owncloud/ocis/storage/pkg/server/debug"
"github.com/owncloud/ocis/storage/pkg/tracing"
"github.com/thejerf/suture/v4"
@@ -24,11 +23,11 @@ func AuthMachine(cfg *config.Config) *cli.Command {
return &cli.Command{
Name: "auth-machine",
Usage: "Start authprovider for machine auth",
Flags: flagset.AuthMachineWithConfig(cfg),
//Flags: flagset.AuthMachineWithConfig(cfg),
Before: func(c *cli.Context) error {
cfg.Reva.AuthMachine.Services = c.StringSlice("service")
return nil
return ParseConfig(c, cfg, "storage-auth-machine")
},
Action: func(c *cli.Context) error {
logger := NewLogger(cfg)

View File

@@ -16,7 +16,6 @@ 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/flagset"
"github.com/owncloud/ocis/storage/pkg/server/debug"
"github.com/owncloud/ocis/storage/pkg/tracing"
"github.com/thejerf/suture/v4"
@@ -28,11 +27,14 @@ func Frontend(cfg *config.Config) *cli.Command {
return &cli.Command{
Name: "frontend",
Usage: "Start frontend service",
Flags: flagset.FrontendWithConfig(cfg),
//Flags: flagset.FrontendWithConfig(cfg),
Before: func(c *cli.Context) error {
cfg.Reva.Frontend.Services = c.StringSlice("service")
cfg.Reva.ChecksumSupportedTypes = c.StringSlice("checksum-supported-type")
return loadUserAgent(c, cfg)
if err := loadUserAgent(c, cfg); err != nil {
return err
}
return ParseConfig(c, cfg, "storage-frontend")
},
Action: func(c *cli.Context) error {
logger := NewLogger(cfg)

View File

@@ -9,21 +9,19 @@ import (
"path"
"strings"
"github.com/mitchellh/mapstructure"
"github.com/owncloud/ocis/storage/pkg/tracing"
"github.com/owncloud/ocis/ocis-pkg/sync"
"github.com/owncloud/ocis/ocis-pkg/version"
"github.com/cs3org/reva/cmd/revad/runtime"
"github.com/gofrs/uuid"
"github.com/mitchellh/mapstructure"
"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/flagset"
"github.com/owncloud/ocis/storage/pkg/server/debug"
"github.com/owncloud/ocis/storage/pkg/service/external"
"github.com/owncloud/ocis/storage/pkg/tracing"
"github.com/thejerf/suture/v4"
"github.com/urfave/cli/v2"
)
@@ -33,7 +31,7 @@ func Gateway(cfg *config.Config) *cli.Command {
return &cli.Command{
Name: "gateway",
Usage: "Start gateway",
Flags: flagset.GatewayWithConfig(cfg),
//Flags: flagset.GatewayWithConfig(cfg),
Before: func(c *cli.Context) error {
cfg.Reva.Gateway.Services = c.StringSlice("service")
cfg.Reva.StorageRegistry.Rules = c.StringSlice("storage-registry-rule")
@@ -42,7 +40,7 @@ func Gateway(cfg *config.Config) *cli.Command {
cfg.Reva.DataGateway.PublicURL = strings.TrimRight(cfg.Reva.Frontend.PublicURL, "/") + "/data"
}
return nil
return ParseConfig(c, cfg, "storage-gatway")
},
Action: func(c *cli.Context) error {
logger := NewLogger(cfg)
@@ -222,11 +220,12 @@ func rules(cfg *config.Config, logger log.Logger) map[string]map[string]interfac
// generate rules based on default config
return map[string]map[string]interface{}{
cfg.Reva.StorageHome.MountPath: {"address": cfg.Reva.StorageHome.Endpoint},
cfg.Reva.StorageHome.MountID: {"address": cfg.Reva.StorageHome.Endpoint},
cfg.Reva.StorageUsers.MountPath: {"address": cfg.Reva.StorageUsers.Endpoint},
cfg.Reva.StorageUsers.MountID + ".*": {"address": cfg.Reva.StorageUsers.Endpoint},
cfg.Reva.StoragePublicLink.MountPath: {"address": cfg.Reva.StoragePublicLink.Endpoint},
cfg.Reva.StorageHome.MountPath: {"address": cfg.Reva.StorageHome.Endpoint},
// this is an ugly hack. Why is it here in the first place?
"1284d238-aa92-42ce-bdc4-0b0000009154": {"address": cfg.Reva.StorageHome.Endpoint},
cfg.Reva.StorageUsers.MountPath: {"address": cfg.Reva.StorageUsers.Endpoint},
cfg.Reva.StorageUsers.MountID + ".*": {"address": cfg.Reva.StorageUsers.Endpoint},
cfg.Reva.StoragePublicLink.MountPath: {"address": cfg.Reva.StoragePublicLink.Endpoint},
// public link storage returns the mount id of the actual storage
// medatada storage not part of the global namespace
}
@@ -378,3 +377,29 @@ func (s GatewaySutureService) Serve(ctx context.Context) error {
return nil
}
// ParseConfig loads accounts configuration from known paths.
func ParseConfig(c *cli.Context, cfg *config.Config, storageExtension string) error {
conf, err := ociscfg.BindSourcesToStructs(storageExtension, 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{}
}
// load all env variables relevant to the config in the current context.
conf.LoadOSEnv(config.GetEnv(cfg), false)
bindings := config.StructMappings(cfg)
return ociscfg.BindEnv(conf, bindings)
}

View File

@@ -13,7 +13,6 @@ 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/flagset"
"github.com/owncloud/ocis/storage/pkg/server/debug"
"github.com/owncloud/ocis/storage/pkg/tracing"
"github.com/thejerf/suture/v4"
@@ -25,11 +24,11 @@ func Groups(cfg *config.Config) *cli.Command {
return &cli.Command{
Name: "groups",
Usage: "Start groups service",
Flags: flagset.GroupsWithConfig(cfg),
//Flags: flagset.GroupsWithConfig(cfg),
Before: func(c *cli.Context) error {
cfg.Reva.Groups.Services = c.StringSlice("service")
return nil
return ParseConfig(c, cfg, "storage-groups")
},
Action: func(c *cli.Context) error {
logger := NewLogger(cfg)

View File

@@ -2,14 +2,10 @@ package command
import (
"os"
"strings"
"github.com/owncloud/ocis/ocis-pkg/shared"
"github.com/owncloud/ocis/ocis-pkg/log"
"github.com/owncloud/ocis/ocis-pkg/version"
"github.com/owncloud/ocis/storage/pkg/config"
"github.com/spf13/viper"
"github.com/urfave/cli/v2"
)
@@ -28,49 +24,7 @@ func Execute(cfg *config.Config) error {
},
},
Before: func(c *cli.Context) error {
if cfg.Log == nil {
cfg.Log = &shared.Log{}
}
logger := NewLogger(cfg)
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.SetEnvPrefix("STORAGE")
viper.AutomaticEnv()
if c.IsSet("config-file") {
viper.SetConfigFile(c.String("config-file"))
} else {
viper.SetConfigName("storage")
viper.AddConfigPath("/etc/ocis")
viper.AddConfigPath("$HOME/.ocis")
viper.AddConfigPath("./config")
}
if err := viper.ReadInConfig(); err != nil {
switch err.(type) {
case viper.ConfigFileNotFoundError:
logger.Debug().
Msg("no config found on preconfigured location")
case viper.UnsupportedConfigError:
logger.Fatal().
Err(err).
Msg("unsupported config type")
default:
logger.Fatal().
Err(err).
Msg("failed to read config")
}
}
if err := viper.Unmarshal(&cfg); err != nil {
logger.Fatal().
Err(err).
Msg("failed to parse config")
}
return nil
return ParseConfig(c, cfg, "storage")
},
Commands: []*cli.Command{

View File

@@ -16,7 +16,6 @@ import (
"github.com/oklog/run"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/storage/pkg/config"
"github.com/owncloud/ocis/storage/pkg/flagset"
"github.com/owncloud/ocis/storage/pkg/server/debug"
"github.com/thejerf/suture/v4"
"github.com/urfave/cli/v2"
@@ -27,11 +26,11 @@ func Sharing(cfg *config.Config) *cli.Command {
return &cli.Command{
Name: "sharing",
Usage: "Start sharing service",
Flags: flagset.SharingWithConfig(cfg),
//Flags: flagset.SharingWithConfig(cfg),
Before: func(c *cli.Context) error {
cfg.Reva.Sharing.Services = c.StringSlice("service")
return nil
return ParseConfig(c, cfg, "storage-sharing")
},
Action: func(c *cli.Context) error {
logger := NewLogger(cfg)

View File

@@ -14,7 +14,6 @@ import (
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/storage/pkg/command/storagedrivers"
"github.com/owncloud/ocis/storage/pkg/config"
"github.com/owncloud/ocis/storage/pkg/flagset"
"github.com/owncloud/ocis/storage/pkg/server/debug"
"github.com/owncloud/ocis/storage/pkg/tracing"
"github.com/thejerf/suture/v4"
@@ -26,11 +25,11 @@ func StorageHome(cfg *config.Config) *cli.Command {
return &cli.Command{
Name: "storage-home",
Usage: "Start storage-home service",
Flags: flagset.StorageHomeWithConfig(cfg),
//Flags: flagset.StorageHomeWithConfig(cfg),
Before: func(c *cli.Context) error {
cfg.Reva.StorageHome.Services = c.StringSlice("service")
return nil
return ParseConfig(c, cfg, "storage-home")
},
Action: func(c *cli.Context) error {
logger := NewLogger(cfg)

View File

@@ -15,7 +15,6 @@ import (
"github.com/owncloud/ocis/ocis-pkg/version"
"github.com/owncloud/ocis/storage/pkg/command/storagedrivers"
"github.com/owncloud/ocis/storage/pkg/config"
"github.com/owncloud/ocis/storage/pkg/flagset"
"github.com/owncloud/ocis/storage/pkg/server/debug"
"github.com/owncloud/ocis/storage/pkg/service/external"
"github.com/owncloud/ocis/storage/pkg/tracing"
@@ -31,7 +30,10 @@ func StorageMetadata(cfg *config.Config) *cli.Command {
Name: "storage-metadata",
Usage: "Start storage-metadata service",
// TODO(refs) at this point it might make sense delegate log flags to each individual storage command.
Flags: flagset.StorageMetadata(cfg),
//Flags: flagset.StorageMetadata(cfg),
Before: func(c *cli.Context) error {
return ParseConfig(c, cfg, "storage-metadata")
},
Category: "Extensions",
Action: func(c *cli.Context) error {
logger := NewLogger(cfg)

View File

@@ -12,7 +12,6 @@ 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/flagset"
"github.com/owncloud/ocis/storage/pkg/server/debug"
"github.com/owncloud/ocis/storage/pkg/tracing"
"github.com/thejerf/suture/v4"
@@ -22,9 +21,12 @@ import (
// StoragePublicLink is the entrypoint for the reva-storage-public-link command.
func StoragePublicLink(cfg *config.Config) *cli.Command {
return &cli.Command{
Name: "storage-public-link",
Usage: "Start storage-public-link service",
Flags: flagset.StoragePublicLink(cfg),
Name: "storage-public-link",
Usage: "Start storage-public-link service",
//Flags: flagset.StoragePublicLink(cfg),
Before: func(c *cli.Context) error {
return ParseConfig(c, cfg, "storage-public-link")
},
Category: "Extensions",
Action: func(c *cli.Context) error {
logger := NewLogger(cfg)

View File

@@ -13,7 +13,6 @@ 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/flagset"
"github.com/owncloud/ocis/storage/pkg/server/debug"
"github.com/owncloud/ocis/storage/pkg/tracing"
"github.com/thejerf/suture/v4"
@@ -25,11 +24,11 @@ func StorageUsers(cfg *config.Config) *cli.Command {
return &cli.Command{
Name: "storage-users",
Usage: "Start storage-users service",
Flags: flagset.StorageUsersWithConfig(cfg),
//Flags: flagset.StorageUsersWithConfig(cfg),
Before: func(c *cli.Context) error {
cfg.Reva.StorageHome.Services = c.StringSlice("service")
return nil
return ParseConfig(c, cfg, "storage-userprovider")
},
Action: func(c *cli.Context) error {
logger := NewLogger(cfg)

View File

@@ -13,7 +13,6 @@ 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/flagset"
"github.com/owncloud/ocis/storage/pkg/server/debug"
"github.com/owncloud/ocis/storage/pkg/tracing"
"github.com/thejerf/suture/v4"
@@ -25,11 +24,11 @@ func Users(cfg *config.Config) *cli.Command {
return &cli.Command{
Name: "users",
Usage: "Start users service",
Flags: flagset.UsersWithConfig(cfg),
//Flags: flagset.UsersWithConfig(cfg),
Before: func(c *cli.Context) error {
cfg.Reva.Users.Services = c.StringSlice("service")
return nil
return ParseConfig(c, cfg, "storage-users")
},
Action: func(c *cli.Context) error {
logger := NewLogger(cfg)

File diff suppressed because it is too large Load Diff