diff --git a/ocis/go.sum b/ocis/go.sum index 262bfd63c..b2d1336ee 100644 --- a/ocis/go.sum +++ b/ocis/go.sum @@ -217,6 +217,7 @@ github.com/bwmarrin/discordgo v0.20.2/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVO github.com/c-bata/go-prompt v0.2.5/go.mod h1:vFnjEGDIIA/Lib7giyE4E9c50Lvl8j0S+7FVlAwDAVw= github.com/caddyserver/certmagic v0.10.6 h1:sCya6FmfaN74oZE46kqfaFOVoROD/mF36rTQfjN7TZc= github.com/caddyserver/certmagic v0.10.6/go.mod h1:Y8jcUBctgk/IhpAzlHKfimZNyXCkfGgRTC0orl8gROQ= +github.com/cenkalti/backoff v2.1.1+incompatible h1:tKJnvO2kl0zmb/jA5UKAt4VoEVw1qxKWjE/Bpp46npY= github.com/cenkalti/backoff v2.1.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4= github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= diff --git a/ocis/pkg/command/accounts.go b/ocis/pkg/command/accounts.go index 36b740c41..71ce7102f 100644 --- a/ocis/pkg/command/accounts.go +++ b/ocis/pkg/command/accounts.go @@ -28,12 +28,13 @@ func AccountsCommand(cfg *config.Config) *cli.Command { command.PrintVersion(cfg.Accounts), }, Action: func(c *cli.Context) error { - accountsCommand := command.Server(configureAccounts(cfg)) - if err := accountsCommand.Before(c); err != nil { + origCmd := command.Server(configureAccounts(cfg)) + + if err := origCmd.Before(c); err != nil { return err } - return cli.HandleAction(accountsCommand.Action, c) + return cli.HandleAction(origCmd.Action, c) }, } } diff --git a/ocis/pkg/command/glauth.go b/ocis/pkg/command/glauth.go index e891ff3cb..7094c9b62 100644 --- a/ocis/pkg/command/glauth.go +++ b/ocis/pkg/command/glauth.go @@ -18,16 +18,13 @@ func GLAuthCommand(cfg *config.Config) *cli.Command { Category: "Extensions", Flags: flagset.ServerWithConfig(cfg.GLAuth), Action: func(c *cli.Context) error { + origCmd := command.Server(configureGLAuth(cfg)) - cfg.GLAuth.Backend.Servers = c.StringSlice("backend-server") - cfg.GLAuth.Fallback.Servers = c.StringSlice("fallback-server") + if err := origCmd.Before(c); err != nil { + return err + } - scfg := configureGLAuth(cfg) - - return cli.HandleAction( - command.Server(scfg).Action, - c, - ) + return cli.HandleAction(origCmd.Action, c) }, } } diff --git a/ocis/pkg/command/ocs.go b/ocis/pkg/command/ocs.go index fdf7510a9..646be8b7f 100644 --- a/ocis/pkg/command/ocs.go +++ b/ocis/pkg/command/ocs.go @@ -22,14 +22,14 @@ func OCSCommand(cfg *config.Config) *cli.Command { Subcommands: []*cli.Command{ command.PrintVersion(cfg.OCS), }, - Action: func(ctx *cli.Context) error { - ocsCommand := command.Server(configureOCS(cfg)) + Action: func(c *cli.Context) error { + origCmd := command.Server(configureOCS(cfg)) - if err := ocsCommand.Before(ctx); err != nil { + if err := origCmd.Before(c); err != nil { return err } - return cli.HandleAction(ocsCommand.Action, ctx) + return cli.HandleAction(origCmd.Action, c) }, } } diff --git a/ocis/pkg/command/onlyoffice.go b/ocis/pkg/command/onlyoffice.go index 928169cb7..2b07f0624 100644 --- a/ocis/pkg/command/onlyoffice.go +++ b/ocis/pkg/command/onlyoffice.go @@ -1,12 +1,11 @@ package command import ( - "strings" - "github.com/micro/cli/v2" "github.com/owncloud/ocis/ocis/pkg/config" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/onlyoffice/pkg/command" + svcconfig "github.com/owncloud/ocis/onlyoffice/pkg/config" "github.com/owncloud/ocis/onlyoffice/pkg/flagset" ) @@ -17,26 +16,19 @@ func OnlyofficeCommand(cfg *config.Config) *cli.Command { Usage: "Start onlyoffice server", Category: "Extensions", Flags: flagset.ServerWithConfig(cfg.Onlyoffice), - Before: func(c *cli.Context) error { - if cfg.HTTP.Root != "/" { - cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") - } - - return nil - }, Action: func(c *cli.Context) error { - onlyofficeCommand := command.Server(configureOnlyoffice(cfg).Onlyoffice) + origCmd := command.Server(configureOnlyoffice(cfg)) - if err := onlyofficeCommand.Before(c); err != nil { + if err := origCmd.Before(c); err != nil { return err } - return cli.HandleAction(onlyofficeCommand.Action, c) + return cli.HandleAction(origCmd.Action, c) }, } } -func configureOnlyoffice(cfg *config.Config) *config.Config { +func configureOnlyoffice(cfg *config.Config) *svcconfig.Config { cfg.Onlyoffice.Log.Level = cfg.Log.Level cfg.Onlyoffice.Log.Pretty = cfg.Log.Pretty cfg.Onlyoffice.Log.Color = cfg.Log.Color @@ -48,7 +40,7 @@ func configureOnlyoffice(cfg *config.Config) *config.Config { cfg.Onlyoffice.Tracing.Collector = cfg.Tracing.Collector } - return cfg + return cfg.Onlyoffice } func init() { diff --git a/ocis/pkg/command/proxy.go b/ocis/pkg/command/proxy.go index 4957bc88b..1da074e8e 100644 --- a/ocis/pkg/command/proxy.go +++ b/ocis/pkg/command/proxy.go @@ -22,14 +22,14 @@ func ProxyCommand(cfg *config.Config) *cli.Command { Subcommands: []*cli.Command{ command.PrintVersion(cfg.Proxy), }, - Action: func(ctx *cli.Context) error { - proxyCommand := command.Server(configureProxy(cfg)) + Action: func(c *cli.Context) error { + origCmd := command.Server(configureProxy(cfg)) - if err := proxyCommand.Before(ctx); err != nil { + if err := origCmd.Before(c); err != nil { return err } - return cli.HandleAction(proxyCommand.Action, ctx) + return cli.HandleAction(origCmd.Action, c) }, } } diff --git a/ocis/pkg/command/settings.go b/ocis/pkg/command/settings.go index 6183a9cd3..bd4948ec1 100644 --- a/ocis/pkg/command/settings.go +++ b/ocis/pkg/command/settings.go @@ -22,14 +22,14 @@ func SettingsCommand(cfg *config.Config) *cli.Command { Subcommands: []*cli.Command{ command.PrintVersion(cfg.Settings), }, - Action: func(ctx *cli.Context) error { - settingsCommand := command.Server(configureSettings(cfg)) + Action: func(c *cli.Context) error { + origCmd := command.Server(configureSettings(cfg)) - if err := settingsCommand.Before(ctx); err != nil { + if err := origCmd.Before(c); err != nil { return err } - return cli.HandleAction(settingsCommand.Action, ctx) + return cli.HandleAction(origCmd.Action, c) }, } } diff --git a/ocis/pkg/command/storageauthbasic.go b/ocis/pkg/command/storageauthbasic.go index 29e7473bd..c5d6d315a 100644 --- a/ocis/pkg/command/storageauthbasic.go +++ b/ocis/pkg/command/storageauthbasic.go @@ -19,12 +19,13 @@ func StorageAuthBasicCommand(cfg *config.Config) *cli.Command { Category: "Extensions", Flags: flagset.AuthBasicWithConfig(cfg.Storage), Action: func(c *cli.Context) error { - scfg := configureStorageAuthBasic(cfg) + origCmd := command.AuthBasic(configureStorageAuthBasic(cfg)) - return cli.HandleAction( - command.AuthBasic(scfg).Action, - c, - ) + if err := origCmd.Before(c); err != nil { + return err + } + + return cli.HandleAction(origCmd.Action, c) }, } } diff --git a/ocis/pkg/command/storageauthbearer.go b/ocis/pkg/command/storageauthbearer.go index 7d1c9a719..2609c4421 100644 --- a/ocis/pkg/command/storageauthbearer.go +++ b/ocis/pkg/command/storageauthbearer.go @@ -19,12 +19,13 @@ func StorageAuthBearerCommand(cfg *config.Config) *cli.Command { Category: "Extensions", Flags: flagset.AuthBearerWithConfig(cfg.Storage), Action: func(c *cli.Context) error { - scfg := configureStorageAuthBearer(cfg) + origCmd := command.AuthBearer(configureStorageAuthBearer(cfg)) - return cli.HandleAction( - command.AuthBearer(scfg).Action, - c, - ) + if err := origCmd.Before(c); err != nil { + return err + } + + return cli.HandleAction(origCmd.Action, c) }, } } diff --git a/ocis/pkg/command/storagefrontend.go b/ocis/pkg/command/storagefrontend.go index 8f56ad64c..2c46f249f 100644 --- a/ocis/pkg/command/storagefrontend.go +++ b/ocis/pkg/command/storagefrontend.go @@ -19,16 +19,13 @@ func StorageFrontendCommand(cfg *config.Config) *cli.Command { Category: "Extensions", Flags: flagset.FrontendWithConfig(cfg.Storage), Action: func(c *cli.Context) error { - scfg := configureStorageFrontend(cfg) + origCmd := command.Frontend(configureStorageFrontend(cfg)) - if err := command.Frontend(scfg).Before(c); err != nil { + if err := origCmd.Before(c); err != nil { return err } - return cli.HandleAction( - command.Frontend(scfg).Action, - c, - ) + return cli.HandleAction(origCmd.Action, c) }, } } diff --git a/ocis/pkg/command/storagegateway.go b/ocis/pkg/command/storagegateway.go index e07c5da03..154a9ab14 100644 --- a/ocis/pkg/command/storagegateway.go +++ b/ocis/pkg/command/storagegateway.go @@ -19,12 +19,13 @@ func StorageGatewayCommand(cfg *config.Config) *cli.Command { Category: "Extensions", Flags: flagset.GatewayWithConfig(cfg.Storage), Action: func(c *cli.Context) error { - scfg := configureStorageGateway(cfg) + origCmd := command.Gateway(configureStorageGateway(cfg)) - return cli.HandleAction( - command.Gateway(scfg).Action, - c, - ) + if err := origCmd.Before(c); err != nil { + return err + } + + return cli.HandleAction(origCmd.Action, c) }, } } diff --git a/ocis/pkg/command/storagehome.go b/ocis/pkg/command/storagehome.go index 819416bfa..011bb520a 100644 --- a/ocis/pkg/command/storagehome.go +++ b/ocis/pkg/command/storagehome.go @@ -19,12 +19,13 @@ func StorageHomeCommand(cfg *config.Config) *cli.Command { Category: "Extensions", Flags: flagset.StorageHomeWithConfig(cfg.Storage), Action: func(c *cli.Context) error { - scfg := configureStorageHome(cfg) + origCmd := command.StorageHome(configureStorageHome(cfg)) - return cli.HandleAction( - command.StorageHome(scfg).Action, - c, - ) + if err := origCmd.Before(c); err != nil { + return err + } + + return cli.HandleAction(origCmd.Action, c) }, } } diff --git a/ocis/pkg/command/storagemetadata.go b/ocis/pkg/command/storagemetadata.go index 3f8df079e..479537c2a 100644 --- a/ocis/pkg/command/storagemetadata.go +++ b/ocis/pkg/command/storagemetadata.go @@ -17,13 +17,13 @@ func StorageMetadataCommand(cfg *config.Config) *cli.Command { Category: "Extensions", Flags: flagset.StorageMetadata(cfg.Storage), Action: func(c *cli.Context) error { - revaStorageMetadataCommand := command.StorageMetadata(configureStorageMetadata(cfg)) + origCmd := command.StorageMetadata(configureStorageMetadata(cfg)) - if err := revaStorageMetadataCommand.Before(c); err != nil { + if err := origCmd.Before(c); err != nil { return err } - return cli.HandleAction(revaStorageMetadataCommand.Action, c) + return cli.HandleAction(origCmd.Action, c) }, } } diff --git a/ocis/pkg/command/storagepubliclink.go b/ocis/pkg/command/storagepubliclink.go index dddf2cbe6..a132bbf47 100644 --- a/ocis/pkg/command/storagepubliclink.go +++ b/ocis/pkg/command/storagepubliclink.go @@ -19,12 +19,13 @@ func StoragePublicLinkCommand(cfg *config.Config) *cli.Command { Category: "Extensions", Flags: flagset.StoragePublicLink(cfg.Storage), Action: func(c *cli.Context) error { - scfg := configureStoragePublicLink(cfg) + origCmd := command.StoragePublicLink(configureStoragePublicLink(cfg)) - return cli.HandleAction( - command.StoragePublicLink(scfg).Action, - c, - ) + if err := origCmd.Before(c); err != nil { + return err + } + + return cli.HandleAction(origCmd.Action, c) }, } } diff --git a/ocis/pkg/command/storagesharing.go b/ocis/pkg/command/storagesharing.go index 8fbb7db11..1ac8b2cf4 100644 --- a/ocis/pkg/command/storagesharing.go +++ b/ocis/pkg/command/storagesharing.go @@ -19,12 +19,13 @@ func StorageSharingCommand(cfg *config.Config) *cli.Command { Category: "Extensions", Flags: flagset.SharingWithConfig(cfg.Storage), Action: func(c *cli.Context) error { - scfg := configureStorageSharing(cfg) + origCmd := command.Sharing(configureStorageSharing(cfg)) - return cli.HandleAction( - command.Sharing(scfg).Action, - c, - ) + if err := origCmd.Before(c); err != nil { + return err + } + + return cli.HandleAction(origCmd.Action, c) }, } } diff --git a/ocis/pkg/command/storageuserprovider.go b/ocis/pkg/command/storageuserprovider.go index 74062bd21..968cf4100 100644 --- a/ocis/pkg/command/storageuserprovider.go +++ b/ocis/pkg/command/storageuserprovider.go @@ -19,12 +19,13 @@ func StorageUserProviderCommand(cfg *config.Config) *cli.Command { Category: "Extensions", Flags: flagset.UsersWithConfig(cfg.Storage), Action: func(c *cli.Context) error { - scfg := configureStorageUserProvider(cfg) + origCmd := command.Users(configureStorageUserProvider(cfg)) - return cli.HandleAction( - command.Users(scfg).Action, - c, - ) + if err := origCmd.Before(c); err != nil { + return err + } + + return cli.HandleAction(origCmd.Action, c) }, } } diff --git a/ocis/pkg/command/storageusers.go b/ocis/pkg/command/storageusers.go index 1427fcefd..48dff5b25 100644 --- a/ocis/pkg/command/storageusers.go +++ b/ocis/pkg/command/storageusers.go @@ -19,12 +19,13 @@ func StorageUsersCommand(cfg *config.Config) *cli.Command { Category: "Extensions", Flags: flagset.StorageUsersWithConfig(cfg.Storage), Action: func(c *cli.Context) error { - scfg := configureStorageUsers(cfg) + origCmd := command.StorageUsers(configureStorageUsers(cfg)) - return cli.HandleAction( - command.StorageUsers(scfg).Action, - c, - ) + if err := origCmd.Before(c); err != nil { + return err + } + + return cli.HandleAction(origCmd.Action, c) }, } } diff --git a/ocis/pkg/command/store.go b/ocis/pkg/command/store.go index eda6edd4f..bd52b8662 100644 --- a/ocis/pkg/command/store.go +++ b/ocis/pkg/command/store.go @@ -22,14 +22,14 @@ func StoreCommand(cfg *config.Config) *cli.Command { Subcommands: []*cli.Command{ command.PrintVersion(cfg.Store), }, - Action: func(ctx *cli.Context) error { - storeCommand := command.Server(configureStore(cfg)) + Action: func(c *cli.Context) error { + origCmd := command.Server(configureStore(cfg)) - if err := storeCommand.Before(ctx); err != nil { + if err := origCmd.Before(c); err != nil { return err } - return cli.HandleAction(storeCommand.Action, ctx) + return cli.HandleAction(origCmd.Action, c) }, } } diff --git a/ocis/pkg/command/thumbnails.go b/ocis/pkg/command/thumbnails.go index 097189d3b..090329735 100644 --- a/ocis/pkg/command/thumbnails.go +++ b/ocis/pkg/command/thumbnails.go @@ -24,13 +24,13 @@ func ThumbnailsCommand(cfg *config.Config) *cli.Command { command.PrintVersion(cfg.Thumbnails), }, Action: func(c *cli.Context) error { - thumbnailsCommand := command.Server(configureThumbnails(cfg)) + origCmd := command.Server(configureThumbnails(cfg)) - if err := thumbnailsCommand.Before(c); err != nil { + if err := origCmd.Before(c); err != nil { return err } - return cli.HandleAction(thumbnailsCommand.Action, c) + return cli.HandleAction(origCmd.Action, c) }, } } diff --git a/ocis/pkg/command/web.go b/ocis/pkg/command/web.go index 64ae0b4b1..19209af79 100644 --- a/ocis/pkg/command/web.go +++ b/ocis/pkg/command/web.go @@ -1,12 +1,11 @@ package command import ( - "strings" - "github.com/micro/cli/v2" "github.com/owncloud/ocis/ocis/pkg/config" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/web/pkg/command" + svcconfig "github.com/owncloud/ocis/web/pkg/config" "github.com/owncloud/ocis/web/pkg/flagset" ) @@ -17,27 +16,19 @@ func WebCommand(cfg *config.Config) *cli.Command { Usage: "Start web server", Category: "Extensions", Flags: flagset.ServerWithConfig(cfg.Web), - Before: func(c *cli.Context) error { - if cfg.HTTP.Root != "/" { - cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") - } - - cfg.Web.Web.Config.Apps = c.StringSlice("web-config-app") - return nil - }, Action: func(c *cli.Context) error { - webCommand := command.Server(configureWeb(cfg).Web) + origCmd := command.Server(configureWeb(cfg)) - if err := webCommand.Before(c); err != nil { + if err := origCmd.Before(c); err != nil { return err } - return cli.HandleAction(webCommand.Action, c) + return cli.HandleAction(origCmd.Action, c) }, } } -func configureWeb(cfg *config.Config) *config.Config { +func configureWeb(cfg *config.Config) *svcconfig.Config { cfg.Web.Log.Level = cfg.Log.Level cfg.Web.Log.Pretty = cfg.Log.Pretty cfg.Web.Log.Color = cfg.Log.Color @@ -49,7 +40,7 @@ func configureWeb(cfg *config.Config) *config.Config { cfg.Web.Tracing.Collector = cfg.Tracing.Collector } - return cfg + return cfg.Web } func init() { diff --git a/ocis/pkg/command/webdav.go b/ocis/pkg/command/webdav.go index 2595318a2..3dbc4e73e 100644 --- a/ocis/pkg/command/webdav.go +++ b/ocis/pkg/command/webdav.go @@ -23,13 +23,13 @@ func WebDAVCommand(cfg *config.Config) *cli.Command { command.PrintVersion(cfg.WebDAV), }, Action: func(c *cli.Context) error { - webdavCommand := command.Server(configureWebDAV(cfg)) + origCmd := command.Server(configureWebDAV(cfg)) - if err := webdavCommand.Before(c); err != nil { + if err := origCmd.Before(c); err != nil { return err } - return cli.HandleAction(webdavCommand.Action, c) + return cli.HandleAction(origCmd.Action, c) }, } } diff --git a/onlyoffice/pkg/command/server.go b/onlyoffice/pkg/command/server.go index 90218bdd0..c8b19904f 100644 --- a/onlyoffice/pkg/command/server.go +++ b/onlyoffice/pkg/command/server.go @@ -34,8 +34,6 @@ func Server(cfg *config.Config) *cli.Command { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } - // When running on single binary mode the before hook from the root command won't get called. We manually - // call this before hook from ocis command, so the configuration can be loaded. return ParseConfig(ctx, cfg) }, Action: func(c *cli.Context) error {