From 12c14e313563bce54c6d1c5fa789da349311014b Mon Sep 17 00:00:00 2001 From: David Christofas Date: Thu, 21 Apr 2022 16:17:41 +0200 Subject: [PATCH] make storage publiclink config similar to other services --- .../pkg/command/storagepubliclink.go | 61 +++++++++-------- .../storage-publiclink/pkg/config/config.go | 63 ++++++++++++++++++ .../pkg/config/defaults/defaultconfig.go | 65 +++++++++++++++++++ extensions/storage/pkg/command/root.go | 2 +- ocis-pkg/config/config.go | 52 ++++++++------- ocis-pkg/config/defaultconfig.go | 52 ++++++++------- ocis/pkg/command/storagepubliclink.go | 10 +-- ocis/pkg/runtime/service/service.go | 3 +- 8 files changed, 225 insertions(+), 83 deletions(-) rename extensions/{storage => storage-publiclink}/pkg/command/storagepubliclink.go (70%) create mode 100644 extensions/storage-publiclink/pkg/config/config.go create mode 100644 extensions/storage-publiclink/pkg/config/defaults/defaultconfig.go diff --git a/extensions/storage/pkg/command/storagepubliclink.go b/extensions/storage-publiclink/pkg/command/storagepubliclink.go similarity index 70% rename from extensions/storage/pkg/command/storagepubliclink.go rename to extensions/storage-publiclink/pkg/command/storagepubliclink.go index b2acc05748..e128aadb61 100644 --- a/extensions/storage/pkg/command/storagepubliclink.go +++ b/extensions/storage-publiclink/pkg/command/storagepubliclink.go @@ -9,11 +9,12 @@ import ( "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-publiclink/pkg/config" "github.com/owncloud/ocis/extensions/storage/pkg/server/debug" - "github.com/owncloud/ocis/extensions/storage/pkg/tracing" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/sync" + "github.com/owncloud/ocis/ocis-pkg/tracing" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" ) @@ -23,13 +24,19 @@ 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") - }, + // Before: func(c *cli.Context) error { + // return ParseConfig(c, cfg, "storage-public-link") + // }, Category: "extensions", Action: func(c *cli.Context) error { - logger := NewLogger(cfg) - tracing.Configure(cfg, logger) + logCfg := cfg.Logging + logger := log.NewLogger( + log.Level(logCfg.Level), + log.File(logCfg.File), + log.Pretty(logCfg.Pretty), + log.Color(logCfg.Color), + ) + tracing.Configure(cfg.Tracing.Enabled, cfg.Tracing.Type, logger) gr := run.Group{} ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -54,10 +61,12 @@ func StoragePublicLink(cfg *config.Config) *cli.Command { debugServer, err := debug.Server( debug.Name(c.Command.Name+"-debug"), - debug.Addr(cfg.Reva.StoragePublicLink.DebugAddr), + debug.Addr(cfg.Debug.Addr), debug.Logger(logger), debug.Context(ctx), - debug.Config(cfg), + debug.Pprof(cfg.Debug.Pprof), + debug.Zpages(cfg.Debug.Zpages), + debug.Token(cfg.Debug.Token), ) if err != nil { @@ -69,7 +78,7 @@ func StoragePublicLink(cfg *config.Config) *cli.Command { cancel() }) - if !cfg.Reva.StoragePublicLink.Supervised { + if !cfg.Supervised { sync.Trap(&gr, cancel) } @@ -82,33 +91,32 @@ func StoragePublicLink(cfg *config.Config) *cli.Command { func storagePublicLinkConfigFromStruct(c *cli.Context, cfg *config.Config) map[string]interface{} { rcfg := map[string]interface{}{ "core": map[string]interface{}{ - "max_cpus": cfg.Reva.StoragePublicLink.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, + "jwt_secret": cfg.JWTSecret, + "gatewaysvc": cfg.GatewayEndpoint, + "skip_user_groups_in_token": cfg.SkipUserGroupsInToken, }, "grpc": map[string]interface{}{ - "network": cfg.Reva.StoragePublicLink.GRPCNetwork, - "address": cfg.Reva.StoragePublicLink.GRPCAddr, + "network": cfg.GRPC.Protocol, + "address": cfg.GRPC.Addr, "interceptors": map[string]interface{}{ "log": map[string]interface{}{}, }, "services": map[string]interface{}{ "publicstorageprovider": map[string]interface{}{ - "mount_id": cfg.Reva.StoragePublicLink.MountID, - "gateway_addr": cfg.Reva.Gateway.Endpoint, + "mount_id": cfg.StorageProvider.MountID, + "gateway_addr": cfg.StorageProvider.GatewayEndpoint, }, "authprovider": map[string]interface{}{ "auth_manager": "publicshares", "auth_managers": map[string]interface{}{ "publicshares": map[string]interface{}{ - "gateway_addr": cfg.Reva.Gateway.Endpoint, + "gateway_addr": cfg.AuthProvider.GatewayEndpoint, }, }, }, @@ -125,28 +133,29 @@ type StoragePublicLinkSutureService struct { // NewStoragePublicLinkSutureService creates a new storage.StoragePublicLinkSutureService func NewStoragePublicLink(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Commons = cfg.Commons + cfg.StoragePublicLink.Commons = cfg.Commons return StoragePublicLinkSutureService{ - cfg: cfg.Storage, + cfg: cfg.StoragePublicLink, } } func (s StoragePublicLinkSutureService) Serve(ctx context.Context) error { - s.cfg.Reva.StoragePublicLink.Context = ctx + // s.cfg.Reva.StoragePublicLink.Context = ctx + cmd := StoragePublicLink(s.cfg) f := &flag.FlagSet{} - cmdFlags := StoragePublicLink(s.cfg).Flags + cmdFlags := cmd.Flags for k := range cmdFlags { if err := cmdFlags[k].Apply(f); err != nil { return err } } cliCtx := cli.NewContext(nil, f, nil) - if StoragePublicLink(s.cfg).Before != nil { - if err := StoragePublicLink(s.cfg).Before(cliCtx); err != nil { + if cmd.Before != nil { + if err := cmd.Before(cliCtx); err != nil { return err } } - if err := StoragePublicLink(s.cfg).Action(cliCtx); err != nil { + if err := cmd.Action(cliCtx); err != nil { return err } diff --git a/extensions/storage-publiclink/pkg/config/config.go b/extensions/storage-publiclink/pkg/config/config.go new file mode 100644 index 0000000000..3766e35ead --- /dev/null +++ b/extensions/storage-publiclink/pkg/config/config.go @@ -0,0 +1,63 @@ +package config + +import ( + "context" + + "github.com/owncloud/ocis/ocis-pkg/shared" +) + +type Config struct { + *shared.Commons `yaml:"-"` + Service Service `yaml:"-"` + Tracing *Tracing `yaml:"tracing"` + Logging *Logging `yaml:"log"` + Debug Debug `yaml:"debug"` + Supervised bool + + GRPC GRPCConfig `yaml:"grpc"` + + Context context.Context + JWTSecret string + GatewayEndpoint string + SkipUserGroupsInToken bool + AuthProvider AuthProvider + StorageProvider StorageProvider +} +type Tracing struct { + Enabled bool `yaml:"enabled" env:"OCIS_TRACING_ENABLED;STORAGE_METADATA_TRACING_ENABLED" desc:"Activates tracing."` + Type string `yaml:"type" env:"OCIS_TRACING_TYPE;STORAGE_METADATA_TRACING_TYPE"` + Endpoint string `yaml:"endpoint" env:"OCIS_TRACING_ENDPOINT;STORAGE_METADATA_TRACING_ENDPOINT" desc:"The endpoint to the tracing collector."` + Collector string `yaml:"collector" env:"OCIS_TRACING_COLLECTOR;STORAGE_METADATA_TRACING_COLLECTOR"` +} + +type Logging struct { + Level string `yaml:"level" env:"OCIS_LOG_LEVEL;STORAGE_METADATA_LOG_LEVEL" desc:"The log level."` + Pretty bool `yaml:"pretty" env:"OCIS_LOG_PRETTY;STORAGE_METADATA_LOG_PRETTY" desc:"Activates pretty log output."` + Color bool `yaml:"color" env:"OCIS_LOG_COLOR;STORAGE_METADATA_LOG_COLOR" desc:"Activates colorized log output."` + File string `yaml:"file" env:"OCIS_LOG_FILE;STORAGE_METADATA_LOG_FILE" desc:"The target log file."` +} + +type Service struct { + Name string `yaml:"-"` +} + +type Debug struct { + Addr string `yaml:"addr" env:"STORAGE_METADATA_DEBUG_ADDR"` + Token string `yaml:"token" env:"STORAGE_METADATA_DEBUG_TOKEN"` + Pprof bool `yaml:"pprof" env:"STORAGE_METADATA_DEBUG_PPROF"` + Zpages bool `yaml:"zpages" env:"STORAGE_METADATA_DEBUG_ZPAGES"` +} + +type GRPCConfig struct { + Addr string `yaml:"addr" env:"STORAGE_METADATA_GRPC_ADDR" desc:"The address of the grpc service."` + Protocol string `yaml:"protocol" env:"STORAGE_METADATA_GRPC_PROTOCOL" desc:"The transport protocol of the grpc service."` +} + +type AuthProvider struct { + GatewayEndpoint string +} + +type StorageProvider struct { + MountID string + GatewayEndpoint string +} diff --git a/extensions/storage-publiclink/pkg/config/defaults/defaultconfig.go b/extensions/storage-publiclink/pkg/config/defaults/defaultconfig.go new file mode 100644 index 0000000000..e04338caa9 --- /dev/null +++ b/extensions/storage-publiclink/pkg/config/defaults/defaultconfig.go @@ -0,0 +1,65 @@ +package defaults + +import ( + "github.com/owncloud/ocis/extensions/storage-publiclink/pkg/config" +) + +func FullDefaultConfig() *config.Config { + cfg := DefaultConfig() + + EnsureDefaults(cfg) + + return cfg +} + +func DefaultConfig() *config.Config { + return &config.Config{ + Debug: config.Debug{ + Addr: "127.0.0.1:9179", + Token: "", + Pprof: false, + Zpages: false, + }, + GRPC: config.GRPCConfig{ + Addr: "127.0.0.1:9178", + Protocol: "tcp", + }, + Service: config.Service{ + Name: "storage-publiclink", + }, + GatewayEndpoint: "127.0.0.1:9142", + JWTSecret: "Pive-Fumkiu4", + AuthProvider: config.AuthProvider{ + GatewayEndpoint: "127.0.0.1:9142", + }, + StorageProvider: config.StorageProvider{ + MountID: "7993447f-687f-490d-875c-ac95e89a62a4", + GatewayEndpoint: "127.0.0.1:9142", + }, + } +} + +func EnsureDefaults(cfg *config.Config) { + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + if cfg.Logging == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Logging = &config.Logging{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Logging == nil { + cfg.Logging = &config.Logging{} + } + // provide with defaults for shared tracing, since we need a valid destination address for BindEnv. + if cfg.Tracing == nil && cfg.Commons != nil && cfg.Commons.Tracing != nil { + cfg.Tracing = &config.Tracing{ + Enabled: cfg.Commons.Tracing.Enabled, + Type: cfg.Commons.Tracing.Type, + Endpoint: cfg.Commons.Tracing.Endpoint, + Collector: cfg.Commons.Tracing.Collector, + } + } else if cfg.Tracing == nil { + cfg.Tracing = &config.Tracing{} + } +} diff --git a/extensions/storage/pkg/command/root.go b/extensions/storage/pkg/command/root.go index 64ba120022..386b0dd4cb 100644 --- a/extensions/storage/pkg/command/root.go +++ b/extensions/storage/pkg/command/root.go @@ -21,7 +21,7 @@ func GetCommands(cfg *config.Config) cli.Commands { // AuthBearer(cfg), // AuthMachine(cfg), // Sharing(cfg), - StoragePublicLink(cfg), + // StoragePublicLink(cfg), StorageShares(cfg), StorageUsers(cfg), // StorageMetadata(cfg), diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index cad9bf10e6..71150ce779 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -22,6 +22,7 @@ import ( settings "github.com/owncloud/ocis/extensions/settings/pkg/config" sharing "github.com/owncloud/ocis/extensions/sharing/pkg/config" storagemetadata "github.com/owncloud/ocis/extensions/storage-metadata/pkg/config" + storagepublic "github.com/owncloud/ocis/extensions/storage-publiclink/pkg/config" storage "github.com/owncloud/ocis/extensions/storage/pkg/config" store "github.com/owncloud/ocis/extensions/store/pkg/config" thumbnails "github.com/owncloud/ocis/extensions/thumbnails/pkg/config" @@ -67,29 +68,30 @@ type Config struct { TokenManager TokenManager `yaml:"token_manager"` Runtime Runtime `yaml:"runtime"` - Audit *audit.Config `yaml:"audit"` - Accounts *accounts.Config `yaml:"accounts"` - GLAuth *glauth.Config `yaml:"glauth"` - Graph *graph.Config `yaml:"graph"` - GraphExplorer *graphExplorer.Config `yaml:"graph_explorer"` - IDP *idp.Config `yaml:"idp"` - IDM *idm.Config `yaml:"idm"` - Nats *nats.Config `yaml:"nats"` - Notifications *notifications.Config `yaml:"notifications"` - OCS *ocs.Config `yaml:"ocs"` - Web *web.Config `yaml:"web"` - Proxy *proxy.Config `yaml:"proxy"` - Settings *settings.Config `yaml:"settings"` - Storage *storage.Config `yaml:"storage"` - AuthBasic *authbasic.Config `yaml:"auth_basic"` - AuthBearer *authbearer.Config `yaml:"auth_bearer"` - AuthMachine *authmachine.Config `yaml:"auth_machine"` - User *user.Config `yaml:"user"` - Group *group.Config `yaml:"group"` - AppProvider *appprovider.Config `yaml:"app_provider"` - Sharing *sharing.Config `yaml:"app_provider"` - StorageMetadata *storagemetadata.Config `yaml:"storage_metadata"` - Store *store.Config `yaml:"store"` - Thumbnails *thumbnails.Config `yaml:"thumbnails"` - WebDAV *webdav.Config `yaml:"webdav"` + Audit *audit.Config `yaml:"audit"` + Accounts *accounts.Config `yaml:"accounts"` + GLAuth *glauth.Config `yaml:"glauth"` + Graph *graph.Config `yaml:"graph"` + GraphExplorer *graphExplorer.Config `yaml:"graph_explorer"` + IDP *idp.Config `yaml:"idp"` + IDM *idm.Config `yaml:"idm"` + Nats *nats.Config `yaml:"nats"` + Notifications *notifications.Config `yaml:"notifications"` + OCS *ocs.Config `yaml:"ocs"` + Web *web.Config `yaml:"web"` + Proxy *proxy.Config `yaml:"proxy"` + Settings *settings.Config `yaml:"settings"` + Storage *storage.Config `yaml:"storage"` + AuthBasic *authbasic.Config `yaml:"auth_basic"` + AuthBearer *authbearer.Config `yaml:"auth_bearer"` + AuthMachine *authmachine.Config `yaml:"auth_machine"` + User *user.Config `yaml:"user"` + Group *group.Config `yaml:"group"` + AppProvider *appprovider.Config `yaml:"app_provider"` + Sharing *sharing.Config `yaml:"app_provider"` + StorageMetadata *storagemetadata.Config `yaml:"storage_metadata"` + StoragePublicLink *storagepublic.Config `yaml:"storage_public"` + Store *store.Config `yaml:"store"` + Thumbnails *thumbnails.Config `yaml:"thumbnails"` + WebDAV *webdav.Config `yaml:"webdav"` } diff --git a/ocis-pkg/config/defaultconfig.go b/ocis-pkg/config/defaultconfig.go index ea78d638a4..bc6e31cebc 100644 --- a/ocis-pkg/config/defaultconfig.go +++ b/ocis-pkg/config/defaultconfig.go @@ -20,6 +20,7 @@ import ( settings "github.com/owncloud/ocis/extensions/settings/pkg/config/defaults" sharing "github.com/owncloud/ocis/extensions/sharing/pkg/config/defaults" storagemetadata "github.com/owncloud/ocis/extensions/storage-metadata/pkg/config/defaults" + storagepublic "github.com/owncloud/ocis/extensions/storage-publiclink/pkg/config/defaults" storage "github.com/owncloud/ocis/extensions/storage/pkg/config/defaults" store "github.com/owncloud/ocis/extensions/store/pkg/config/defaults" thumbnails "github.com/owncloud/ocis/extensions/thumbnails/pkg/config/defaults" @@ -37,30 +38,31 @@ func DefaultConfig() *Config { Port: "9250", Host: "localhost", }, - Audit: audit.DefaultConfig(), - Accounts: accounts.DefaultConfig(), - GLAuth: glauth.DefaultConfig(), - Graph: graph.DefaultConfig(), - IDP: idp.DefaultConfig(), - IDM: idm.DefaultConfig(), - Nats: nats.DefaultConfig(), - Notifications: notifications.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(), - AuthBasic: authbasic.FullDefaultConfig(), - AuthBearer: authbearer.FullDefaultConfig(), - AuthMachine: authmachine.FullDefaultConfig(), - User: user.FullDefaultConfig(), - Group: group.FullDefaultConfig(), - Sharing: sharing.FullDefaultConfig(), - StorageMetadata: storagemetadata.FullDefaultConfig(), - AppProvider: appprovider.FullDefaultConfig(), + Audit: audit.DefaultConfig(), + Accounts: accounts.DefaultConfig(), + GLAuth: glauth.DefaultConfig(), + Graph: graph.DefaultConfig(), + IDP: idp.DefaultConfig(), + IDM: idm.DefaultConfig(), + Nats: nats.DefaultConfig(), + Notifications: notifications.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(), + AuthBasic: authbasic.FullDefaultConfig(), + AuthBearer: authbearer.FullDefaultConfig(), + AuthMachine: authmachine.FullDefaultConfig(), + User: user.FullDefaultConfig(), + Group: group.FullDefaultConfig(), + Sharing: sharing.FullDefaultConfig(), + StorageMetadata: storagemetadata.FullDefaultConfig(), + StoragePublicLink: storagepublic.FullDefaultConfig(), + AppProvider: appprovider.FullDefaultConfig(), } } diff --git a/ocis/pkg/command/storagepubliclink.go b/ocis/pkg/command/storagepubliclink.go index 516bc6c72d..0ad1c43fbb 100644 --- a/ocis/pkg/command/storagepubliclink.go +++ b/ocis/pkg/command/storagepubliclink.go @@ -1,7 +1,7 @@ package command import ( - "github.com/owncloud/ocis/extensions/storage/pkg/command" + "github.com/owncloud/ocis/extensions/storage-publiclink/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" @@ -14,11 +14,11 @@ func StoragePublicLinkCommand(cfg *config.Config) *cli.Command { Usage: "start storage public link storage", Category: "extensions", //Flags: flagset.StoragePublicLink(cfg.Storage), - Before: func(ctx *cli.Context) error { - return ParseStorageCommon(ctx, cfg) - }, + // Before: func(ctx *cli.Context) error { + // return ParseStorageCommon(ctx, cfg) + // }, Action: func(c *cli.Context) error { - origCmd := command.StoragePublicLink(cfg.Storage) + origCmd := command.StoragePublicLink(cfg.StoragePublicLink) return handleOriginalAction(c, origCmd) }, } diff --git a/ocis/pkg/runtime/service/service.go b/ocis/pkg/runtime/service/service.go index 8786bb4825..d63d033472 100644 --- a/ocis/pkg/runtime/service/service.go +++ b/ocis/pkg/runtime/service/service.go @@ -37,6 +37,7 @@ import ( settings "github.com/owncloud/ocis/extensions/settings/pkg/command" sharing "github.com/owncloud/ocis/extensions/sharing/pkg/command" storagemetadata "github.com/owncloud/ocis/extensions/storage-metadata/pkg/command" + storagepublic "github.com/owncloud/ocis/extensions/storage-publiclink/pkg/command" storage "github.com/owncloud/ocis/extensions/storage/pkg/command" store "github.com/owncloud/ocis/extensions/store/pkg/command" thumbnails "github.com/owncloud/ocis/extensions/thumbnails/pkg/command" @@ -124,7 +125,7 @@ func NewService(options ...Option) (*Service, error) { s.ServicesRegistry["storage-authmachine"] = authmachine.NewAuthMachine s.ServicesRegistry["storage-users"] = storage.NewStorageUsers s.ServicesRegistry["storage-shares"] = storage.NewStorageShares - s.ServicesRegistry["storage-public-link"] = storage.NewStoragePublicLink + s.ServicesRegistry["storage-public-link"] = storagepublic.NewStoragePublicLink s.ServicesRegistry["storage-appprovider"] = appprovider.NewAppProvider s.ServicesRegistry["notifications"] = notifications.NewSutureService