From 2cf008f5015793fc681d0f9a7628bd74b0aea1be Mon Sep 17 00:00:00 2001 From: David Christofas Date: Fri, 22 Apr 2022 16:31:40 +0200 Subject: [PATCH] clean up the new commands --- extensions/auth-basic/pkg/command/command.go | 3 - extensions/auth-bearer/pkg/command/command.go | 3 - .../auth-machine/pkg/command/command.go | 3 - extensions/frontend/pkg/command/command.go | 1 - extensions/gateway/pkg/command/command.go | 4 - extensions/group/pkg/command/command.go | 3 - extensions/ocdav/pkg/command/ocdav.go | 1 - .../pkg/command/storagepubliclink.go | 7 +- .../storage-shares/pkg/command/command.go | 3 - .../storage-users/pkg/command/command.go | 3 - extensions/storage/pkg/command/health.go | 6 +- extensions/storage/pkg/command/root.go | 6 +- extensions/storage/pkg/command/sharing.go | 240 ------------------ 13 files changed, 8 insertions(+), 275 deletions(-) delete mode 100644 extensions/storage/pkg/command/sharing.go diff --git a/extensions/auth-basic/pkg/command/command.go b/extensions/auth-basic/pkg/command/command.go index 71b962be421..7f42e7cc91b 100644 --- a/extensions/auth-basic/pkg/command/command.go +++ b/extensions/auth-basic/pkg/command/command.go @@ -26,9 +26,6 @@ func AuthBasic(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "auth-basic", Usage: "start authprovider for basic auth", - // Before: func(c *cli.Context) error { - // return ParseConfig(c, cfg, "storage-auth-basic") - // }, Action: func(c *cli.Context) error { logCfg := cfg.Logging logger := log.NewLogger( diff --git a/extensions/auth-bearer/pkg/command/command.go b/extensions/auth-bearer/pkg/command/command.go index 6fc42b616b5..93b4ef3430d 100644 --- a/extensions/auth-bearer/pkg/command/command.go +++ b/extensions/auth-bearer/pkg/command/command.go @@ -24,9 +24,6 @@ func AuthBearer(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "auth-bearer", Usage: "start authprovider for bearer auth", - // Before: func(c *cli.Context) error { - // return ParseConfig(c, cfg, "storage-auth-bearer") - // }, Action: func(c *cli.Context) error { logCfg := cfg.Logging logger := log.NewLogger( diff --git a/extensions/auth-machine/pkg/command/command.go b/extensions/auth-machine/pkg/command/command.go index 671cb1eb7af..6248955489e 100644 --- a/extensions/auth-machine/pkg/command/command.go +++ b/extensions/auth-machine/pkg/command/command.go @@ -24,9 +24,6 @@ func AuthMachine(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "auth-machine", Usage: "start authprovider for machine auth", - // Before: func(c *cli.Context) error { - // return ParseConfig(c, cfg, "storage-auth-machine") - // }, Action: func(c *cli.Context) error { logCfg := cfg.Logging logger := log.NewLogger( diff --git a/extensions/frontend/pkg/command/command.go b/extensions/frontend/pkg/command/command.go index 7e7f2c32c1e..2fb237f67fa 100644 --- a/extensions/frontend/pkg/command/command.go +++ b/extensions/frontend/pkg/command/command.go @@ -32,7 +32,6 @@ func Frontend(cfg *config.Config) *cli.Command { if err := loadUserAgent(c, cfg); err != nil { return err } - // return ParseConfig(c, cfg, "storage-frontend") return nil }, Action: func(c *cli.Context) error { diff --git a/extensions/gateway/pkg/command/command.go b/extensions/gateway/pkg/command/command.go index 5858cbe0569..5b731605d55 100644 --- a/extensions/gateway/pkg/command/command.go +++ b/extensions/gateway/pkg/command/command.go @@ -31,10 +31,6 @@ func Gateway(cfg *config.Config) *cli.Command { Name: "gateway", Usage: "start gateway", Before: func(c *cli.Context) error { - // if err := ParseConfig(c, cfg, "storage-gateway"); err != nil { - // return err - // } - if cfg.DataGatewayPublicURL == "" { cfg.DataGatewayPublicURL = strings.TrimRight(cfg.FrontendPublicURL, "/") + "/data" } diff --git a/extensions/group/pkg/command/command.go b/extensions/group/pkg/command/command.go index 9e5d6d3d10d..ab71caef114 100644 --- a/extensions/group/pkg/command/command.go +++ b/extensions/group/pkg/command/command.go @@ -26,9 +26,6 @@ func Groups(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "groups", Usage: "start groups service", - // Before: func(c *cli.Context) error { - // return ParseConfig(c, cfg, "storage-groups") - // }, Action: func(c *cli.Context) error { logCfg := cfg.Logging logger := log.NewLogger( diff --git a/extensions/ocdav/pkg/command/ocdav.go b/extensions/ocdav/pkg/command/ocdav.go index e29cfad59f6..e73f5d1b1ee 100644 --- a/extensions/ocdav/pkg/command/ocdav.go +++ b/extensions/ocdav/pkg/command/ocdav.go @@ -29,7 +29,6 @@ func OCDav(cfg *config.Config) *cli.Command { if err := loadUserAgent(c, cfg); err != nil { return err } - // return ParseConfig(c, cfg, "ocdav") return nil }, Action: func(c *cli.Context) error { diff --git a/extensions/storage-publiclink/pkg/command/storagepubliclink.go b/extensions/storage-publiclink/pkg/command/storagepubliclink.go index e128aadb61b..5991885449a 100644 --- a/extensions/storage-publiclink/pkg/command/storagepubliclink.go +++ b/extensions/storage-publiclink/pkg/command/storagepubliclink.go @@ -22,11 +22,8 @@ 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", - // Before: func(c *cli.Context) error { - // return ParseConfig(c, cfg, "storage-public-link") - // }, + Name: "storage-public-link", + Usage: "start storage-public-link service", Category: "extensions", Action: func(c *cli.Context) error { logCfg := cfg.Logging diff --git a/extensions/storage-shares/pkg/command/command.go b/extensions/storage-shares/pkg/command/command.go index 97ab89fa943..b6804326f31 100644 --- a/extensions/storage-shares/pkg/command/command.go +++ b/extensions/storage-shares/pkg/command/command.go @@ -25,9 +25,6 @@ func StorageShares(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "storage-shares", Usage: "start storage-shares service", - // Before: func(c *cli.Context) error { - // return ParseConfig(c, cfg, "storage-shares") - // }, Action: func(c *cli.Context) error { logCfg := cfg.Logging logger := log.NewLogger( diff --git a/extensions/storage-users/pkg/command/command.go b/extensions/storage-users/pkg/command/command.go index b6b3c5cb966..564dd4e558d 100644 --- a/extensions/storage-users/pkg/command/command.go +++ b/extensions/storage-users/pkg/command/command.go @@ -24,9 +24,6 @@ func StorageUsers(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "storage-users", Usage: "start storage-users service", - // Before: func(c *cli.Context) error { - // return ParseConfig(c, cfg, "storage-userprovider") - // }, Action: func(c *cli.Context) error { logCfg := cfg.Logging logger := log.NewLogger( diff --git a/extensions/storage/pkg/command/health.go b/extensions/storage/pkg/command/health.go index 3582a7731c0..2c6fbd1848a 100644 --- a/extensions/storage/pkg/command/health.go +++ b/extensions/storage/pkg/command/health.go @@ -14,9 +14,9 @@ func Health(cfg *config.Config) *cli.Command { Name: "health", Usage: "check health status", Category: "info", - Before: func(c *cli.Context) error { - return ParseConfig(c, cfg, "storage") - }, + // Before: func(c *cli.Context) error { + // return ParseConfig(c, cfg, "storage") + // }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) diff --git a/extensions/storage/pkg/command/root.go b/extensions/storage/pkg/command/root.go index de87cccc1cd..55911eea94d 100644 --- a/extensions/storage/pkg/command/root.go +++ b/extensions/storage/pkg/command/root.go @@ -35,9 +35,9 @@ func Execute(cfg *config.Config) error { Name: "storage", Usage: "Storage service for oCIS", - Before: func(c *cli.Context) error { - return ParseConfig(c, cfg, "storage") - }, + // Before: func(c *cli.Context) error { + // return ParseConfig(c, cfg, "storage") + // }, Commands: GetCommands(cfg), }) diff --git a/extensions/storage/pkg/command/sharing.go b/extensions/storage/pkg/command/sharing.go deleted file mode 100644 index 274eda34239..00000000000 --- a/extensions/storage/pkg/command/sharing.go +++ /dev/null @@ -1,240 +0,0 @@ -package command - -import ( - "context" - "flag" - "os" - "path" - "path/filepath" - - "github.com/owncloud/ocis/extensions/storage/pkg/tracing" - - "github.com/owncloud/ocis/ocis-pkg/sync" - - "github.com/cs3org/reva/v2/cmd/revad/runtime" - "github.com/gofrs/uuid" - "github.com/oklog/run" - "github.com/owncloud/ocis/extensions/storage/pkg/config" - "github.com/owncloud/ocis/extensions/storage/pkg/server/debug" - ociscfg "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/thejerf/suture/v4" - "github.com/urfave/cli/v2" -) - -// Sharing is the entrypoint for the sharing command. -func Sharing(cfg *config.Config) *cli.Command { - return &cli.Command{ - Name: "sharing", - Usage: "start sharing service", - Before: func(c *cli.Context) error { - return ParseConfig(c, cfg, "storage-sharing") - }, - Action: func(c *cli.Context) error { - logger := NewLogger(cfg) - - tracing.Configure(cfg, logger) - - gr := run.Group{} - ctx, cancel := context.WithCancel(context.Background()) - - defer cancel() - - // precreate folders - if cfg.Reva.Sharing.UserDriver == "json" && cfg.Reva.Sharing.UserJSONFile != "" { - if err := os.MkdirAll(filepath.Dir(cfg.Reva.Sharing.UserJSONFile), os.FileMode(0700)); err != nil { - return err - } - } - if cfg.Reva.Sharing.PublicDriver == "json" && cfg.Reva.Sharing.PublicJSONFile != "" { - if err := os.MkdirAll(filepath.Dir(cfg.Reva.Sharing.PublicJSONFile), os.FileMode(0700)); err != nil { - return err - } - } - - uuid := uuid.Must(uuid.NewV4()) - pidFile := path.Join(os.TempDir(), "revad-"+c.Command.Name+"-"+uuid.String()+".pid") - - rcfg := sharingConfigFromStruct(c, cfg) - - gr.Add(func() error { - runtime.RunWithOptions( - rcfg, - pidFile, - runtime.WithLogger(&logger.Logger), - ) - return nil - }, func(_ error) { - logger.Info(). - Str("server", c.Command.Name). - Msg("Shutting down server") - - cancel() - }) - - debug, err := debug.Server( - debug.Name(c.Command.Name+"-debug"), - debug.Addr(cfg.Reva.Sharing.DebugAddr), - debug.Logger(logger), - debug.Context(ctx), - debug.Config(cfg), - ) - - if err != nil { - logger.Info().Err(err).Str("server", c.Command.Name+"-debug").Msg("Failed to initialize server") - return err - } - - gr.Add(debug.ListenAndServe, func(_ error) { - cancel() - }) - - if !cfg.Reva.Sharing.Supervised { - sync.Trap(&gr, cancel) - } - - return gr.Run() - }, - } -} - -// sharingConfigFromStruct will adapt an oCIS config struct into a reva mapstructure to start a reva service. -func sharingConfigFromStruct(c *cli.Context, cfg *config.Config) map[string]interface{} { - rcfg := map[string]interface{}{ - "core": map[string]interface{}{ - "max_cpus": cfg.Reva.Sharing.MaxCPUs, - "tracing_enabled": cfg.Tracing.Enabled, - "tracing_endpoint": cfg.Tracing.Endpoint, - "tracing_collector": cfg.Tracing.Collector, - "tracing_service_name": c.Command.Name, - }, - "shared": map[string]interface{}{ - "jwt_secret": cfg.Reva.JWTSecret, - "gatewaysvc": cfg.Reva.Gateway.Endpoint, - "skip_user_groups_in_token": cfg.Reva.SkipUserGroupsInToken, - }, - "grpc": map[string]interface{}{ - "network": cfg.Reva.Sharing.GRPCNetwork, - "address": cfg.Reva.Sharing.GRPCAddr, - // TODO build services dynamically - "services": map[string]interface{}{ - "usershareprovider": map[string]interface{}{ - "driver": cfg.Reva.Sharing.UserDriver, - "drivers": map[string]interface{}{ - "json": map[string]interface{}{ - "file": cfg.Reva.Sharing.UserJSONFile, - "gateway_addr": cfg.Reva.Gateway.Endpoint, - }, - "sql": map[string]interface{}{ // cernbox sql - "db_username": cfg.Reva.Sharing.UserSQLUsername, - "db_password": cfg.Reva.Sharing.UserSQLPassword, - "db_host": cfg.Reva.Sharing.UserSQLHost, - "db_port": cfg.Reva.Sharing.UserSQLPort, - "db_name": cfg.Reva.Sharing.UserSQLName, - "password_hash_cost": cfg.Reva.Sharing.PublicPasswordHashCost, - "enable_expired_shares_cleanup": cfg.Reva.Sharing.PublicEnableExpiredSharesCleanup, - "janitor_run_interval": cfg.Reva.Sharing.PublicJanitorRunInterval, - }, - "owncloudsql": map[string]interface{}{ - "gateway_addr": cfg.Reva.Gateway.Endpoint, - "storage_mount_id": cfg.Reva.Sharing.UserStorageMountID, - "db_username": cfg.Reva.Sharing.UserSQLUsername, - "db_password": cfg.Reva.Sharing.UserSQLPassword, - "db_host": cfg.Reva.Sharing.UserSQLHost, - "db_port": cfg.Reva.Sharing.UserSQLPort, - "db_name": cfg.Reva.Sharing.UserSQLName, - }, - "cs3": map[string]interface{}{ - "gateway_addr": cfg.Reva.Gateway.Endpoint, - "provider_addr": cfg.Reva.Sharing.CS3ProviderAddr, - "service_user_id": cfg.Reva.Sharing.CS3ServiceUser, - "service_user_idp": cfg.Reva.Sharing.CS3ServiceUserIdp, - "machine_auth_apikey": cfg.Reva.AuthMachineConfig.MachineAuthAPIKey, - }, - }, - }, - "publicshareprovider": map[string]interface{}{ - "driver": cfg.Reva.Sharing.PublicDriver, - "drivers": map[string]interface{}{ - "json": map[string]interface{}{ - "file": cfg.Reva.Sharing.PublicJSONFile, - "gateway_addr": cfg.Reva.Gateway.Endpoint, - }, - "sql": map[string]interface{}{ - "db_username": cfg.Reva.Sharing.UserSQLUsername, - "db_password": cfg.Reva.Sharing.UserSQLPassword, - "db_host": cfg.Reva.Sharing.UserSQLHost, - "db_port": cfg.Reva.Sharing.UserSQLPort, - "db_name": cfg.Reva.Sharing.UserSQLName, - "password_hash_cost": cfg.Reva.Sharing.PublicPasswordHashCost, - "enable_expired_shares_cleanup": cfg.Reva.Sharing.PublicEnableExpiredSharesCleanup, - "janitor_run_interval": cfg.Reva.Sharing.PublicJanitorRunInterval, - }, - "owncloudsql": map[string]interface{}{ - "gateway_addr": cfg.Reva.Gateway.Endpoint, - "storage_mount_id": cfg.Reva.Sharing.UserStorageMountID, - "db_username": cfg.Reva.Sharing.UserSQLUsername, - "db_password": cfg.Reva.Sharing.UserSQLPassword, - "db_host": cfg.Reva.Sharing.UserSQLHost, - "db_port": cfg.Reva.Sharing.UserSQLPort, - "db_name": cfg.Reva.Sharing.UserSQLName, - "password_hash_cost": cfg.Reva.Sharing.PublicPasswordHashCost, - "enable_expired_shares_cleanup": cfg.Reva.Sharing.PublicEnableExpiredSharesCleanup, - "janitor_run_interval": cfg.Reva.Sharing.PublicJanitorRunInterval, - }, - "cs3": map[string]interface{}{ - "gateway_addr": cfg.Reva.Gateway.Endpoint, - "provider_addr": cfg.Reva.Sharing.CS3ProviderAddr, - "service_user_id": cfg.Reva.Sharing.CS3ServiceUser, - "service_user_idp": cfg.Reva.Sharing.CS3ServiceUserIdp, - "machine_auth_apikey": cfg.Reva.AuthMachineConfig.MachineAuthAPIKey, - }, - }, - }, - }, - "interceptors": map[string]interface{}{ - "eventsmiddleware": map[string]interface{}{ - "group": "sharing", - "type": "nats", - "address": cfg.Reva.Sharing.Events.Address, - "clusterID": cfg.Reva.Sharing.Events.ClusterID, - }, - }, - }, - } - return rcfg -} - -// SharingSutureService allows for the storage-sharing command to be embedded and supervised by a suture supervisor tree. -type SharingSutureService struct { - cfg *config.Config -} - -// NewSharingSutureService creates a new store.SharingSutureService -func NewSharing(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Commons = cfg.Commons - return SharingSutureService{ - cfg: cfg.Storage, - } -} - -func (s SharingSutureService) Serve(ctx context.Context) error { - s.cfg.Reva.Sharing.Context = ctx - f := &flag.FlagSet{} - cmdFlags := Sharing(s.cfg).Flags - for k := range cmdFlags { - if err := cmdFlags[k].Apply(f); err != nil { - return err - } - } - cliCtx := cli.NewContext(nil, f, nil) - if Sharing(s.cfg).Before != nil { - if err := Sharing(s.cfg).Before(cliCtx); err != nil { - return err - } - } - if err := Sharing(s.cfg).Action(cliCtx); err != nil { - return err - } - - return nil -}