diff --git a/go.mod b/go.mod index 0af7730c4e9..ad27527983f 100644 --- a/go.mod +++ b/go.mod @@ -266,3 +266,5 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect stash.kopano.io/kgol/kcc-go/v5 v5.0.1 // indirect ) + +replace github.com/cs3org/reva/v2 => github.com/kobergj/reva/v2 v2.0.0-20220715115301-a13b2dbba41c diff --git a/go.sum b/go.sum index 2ff5a357551..5c557f2c608 100644 --- a/go.sum +++ b/go.sum @@ -298,10 +298,15 @@ github.com/crewjam/httperr v0.2.0/go.mod h1:Jlz+Sg/XqBQhyMjdDiC+GNNRzZTD7x39Gu3p github.com/crewjam/saml v0.4.6 h1:XCUFPkQSJLvzyl4cW9OvpWUbRf0gE7VUpU8ZnilbeM4= github.com/crewjam/saml v0.4.6/go.mod h1:ZBOXnNPFzB3CgOkRm7Nd6IVdkG+l/wF+0ZXLqD96t1A= github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4= +<<<<<<< HEAD github.com/cs3org/go-cs3apis v0.0.0-20220711084433-8f71d4e812a3 h1:QSQ2DGKPMChB4vHSs1Os9TnOJl21BrzKX9D5EtQfDog= github.com/cs3org/go-cs3apis v0.0.0-20220711084433-8f71d4e812a3/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY= github.com/cs3org/reva/v2 v2.7.2 h1:R6+tlAYDZz2ylUvq3KWBDMmsyLOD7yJpe51GzIZpWr0= github.com/cs3org/reva/v2 v2.7.2/go.mod h1:gbbAUK+8gmyTJ8J+JWwbKbKRlpNRcoMuAXNFN0HbfIE= +======= +github.com/cs3org/go-cs3apis v0.0.0-20220621145831-c38cca0796c2 h1:o/ovJzS4pyL/rZgp0MtC4Q7JIle5DikimilTLBw2TjY= +github.com/cs3org/go-cs3apis v0.0.0-20220621145831-c38cca0796c2/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY= +>>>>>>> 5a34d4e4e (Start PP service in single binary (configurable)) github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI= github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY= github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4= @@ -809,6 +814,8 @@ github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa02 github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= +github.com/kobergj/reva/v2 v2.0.0-20220715115301-a13b2dbba41c h1:Zwjmp5Y5124IjvftMypyYc2dOQ5lf+Lin2iZ9RMIfHI= +github.com/kobergj/reva/v2 v2.0.0-20220715115301-a13b2dbba41c/go.mod h1:l0OF3ZrWKJPQg8Qx7GyqsuDCfvpu7dJ/E4wUuRVmMgM= github.com/kolo/xmlrpc v0.0.0-20200310150728-e0350524596b/go.mod h1:o03bZfuBwAXHetKXuInt4S7omeXUu62/A845kiycsSQ= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= diff --git a/ocis-pkg/config/defaultconfig.go b/ocis-pkg/config/defaultconfig.go index b0546c7af00..68b7cada396 100644 --- a/ocis-pkg/config/defaultconfig.go +++ b/ocis-pkg/config/defaultconfig.go @@ -18,6 +18,7 @@ import ( notifications "github.com/owncloud/ocis/v2/services/notifications/pkg/config/defaults" ocdav "github.com/owncloud/ocis/v2/services/ocdav/pkg/config/defaults" ocs "github.com/owncloud/ocis/v2/services/ocs/pkg/config/defaults" + postprocessing "github.com/owncloud/ocis/v2/services/postprocessing/pkg/config/defaults" proxy "github.com/owncloud/ocis/v2/services/proxy/pkg/config/defaults" search "github.com/owncloud/ocis/v2/services/search/pkg/config/defaults" settings "github.com/owncloud/ocis/v2/services/settings/pkg/config/defaults" @@ -57,6 +58,7 @@ func DefaultConfig() *Config { Notifications: notifications.DefaultConfig(), OCDav: ocdav.DefaultConfig(), OCS: ocs.DefaultConfig(), + Postprocessing: postprocessing.DefaultConfig(), Proxy: proxy.DefaultConfig(), Search: search.FullDefaultConfig(), Settings: settings.DefaultConfig(), diff --git a/ocis/pkg/runtime/service/service.go b/ocis/pkg/runtime/service/service.go index 2cc5a3e3db7..39a0f6071e3 100644 --- a/ocis/pkg/runtime/service/service.go +++ b/ocis/pkg/runtime/service/service.go @@ -36,6 +36,7 @@ import ( notifications "github.com/owncloud/ocis/v2/services/notifications/pkg/command" ocdav "github.com/owncloud/ocis/v2/services/ocdav/pkg/command" ocs "github.com/owncloud/ocis/v2/services/ocs/pkg/command" + postprocessing "github.com/owncloud/ocis/v2/services/postprocessing/pkg/command" proxy "github.com/owncloud/ocis/v2/services/proxy/pkg/command" search "github.com/owncloud/ocis/v2/services/search/pkg/command" settings "github.com/owncloud/ocis/v2/services/settings/pkg/command" @@ -129,6 +130,7 @@ func NewService(options ...Option) (*Service, error) { s.ServicesRegistry[opts.Config.AppProvider.Service.Name] = appProvider.NewSutureService s.ServicesRegistry[opts.Config.Notifications.Service.Name] = notifications.NewSutureService s.ServicesRegistry[opts.Config.Search.Service.Name] = search.NewSutureService + s.ServicesRegistry[opts.Config.Postprocessing.Service.Name] = postprocessing.NewSutureService // populate delayed services s.Delayed[opts.Config.Sharing.Service.Name] = sharing.NewSutureService diff --git a/services/postprocessing/pkg/command/root.go b/services/postprocessing/pkg/command/root.go index 20106c6855f..0b558d9b787 100644 --- a/services/postprocessing/pkg/command/root.go +++ b/services/postprocessing/pkg/command/root.go @@ -43,17 +43,14 @@ type SutureService struct { // NewSutureService creates a new postprocessing.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - cfg.Notifications.Commons = cfg.Commons + cfg.Postprocessing.Commons = cfg.Commons return SutureService{ cfg: cfg.Postprocessing, } } +// Serve to implement Server interface func (s SutureService) Serve(ctx context.Context) error { s.cfg.Context = ctx - if err := Execute(s.cfg); err != nil { - return err - } - - return nil + return Execute(s.cfg) } diff --git a/services/postprocessing/pkg/config/config.go b/services/postprocessing/pkg/config/config.go index bf2aa0d7261..a1d1b67bdd7 100644 --- a/services/postprocessing/pkg/config/config.go +++ b/services/postprocessing/pkg/config/config.go @@ -2,6 +2,7 @@ package config import ( "context" + "time" "github.com/owncloud/ocis/v2/ocis-pkg/shared" ) @@ -12,8 +13,7 @@ type Config struct { Service Service `yaml:"-"` - Log *Log `yaml:"log"` - Debug Debug `yaml:"debug"` + Log *Log `yaml:"log"` Postprocessing Postprocessing `yaml:"postprocessing"` @@ -22,27 +22,14 @@ type Config struct { // Postprocessing definces the config options for the postprocessing service. type Postprocessing struct { - Events Events `yaml:"events"` - - Steps []string - // TODO: optional steps? - - // TODO: still needed? - // RevaGateway string `yaml:"reva_gateway" env:"REVA_GATEWAY;NOTIFICATIONS_REVA_GATEWAY" desc:"CS3 gateway used to look up user metadata"` - // MachineAuthAPIKey string `yaml:"machine_auth_api_key" env:"OCIS_MACHINE_AUTH_API_KEY;NOTIFICATIONS_MACHINE_AUTH_API_KEY" desc:"Machine auth API key used to validate internal requests necessary for the access to resources from other services."` -} - -// SMTP combines the smtp configuration options. -type SMTP struct { - Host string `yaml:"smtp_host" env:"NOTIFICATIONS_SMTP_HOST" desc:"SMTP host, to connect to."` - Port string `yaml:"smtp_port" env:"NOTIFICATIONS_SMTP_PORT" desc:"Port of the SMTP host, to connect to."` - Sender string `yaml:"smtp_sender" env:"NOTIFICATIONS_SMTP_SENDER" desc:"Sender of emails, that will be sent."` - Password string `yaml:"smtp_password" env:"NOTIFICATIONS_SMTP_PASSWORD" desc:"Password of the SMTP host, to connect to."` + Events Events `yaml:"events"` + Virusscan bool `yaml:"virusscan" env:"POSTPROCESSING_VIRUSSCAN" desc:"should the system do a virusscan? Needs antivirus service"` + FTSIndex bool `yaml:"fulltextsearch" env:"POSTPROCESSING_FTS" desc:"should the system index files for fts? Needs search service"` + Delayprocessing time.Duration `yaml:"delayprocessing" env:"POSTPROCESSING_DELAY" desc:"the sytem sleeps for this time while postprocessing"` } // Events combines the configuration options for the event bus. type Events struct { - Endpoint string `yaml:"endpoint" env:"NOTIFICATIONS_EVENTS_ENDPOINT" desc:"Endpoint of the event system."` - Cluster string `yaml:"cluster" env:"NOTIFICATIONS_EVENTS_CLUSTER" desc:"Cluster ID of the event system."` - ConsumerGroup string `yaml:"group" env:"NOTIFICATIONS_EVENTS_GROUP" desc:"Name of the event group / queue on the event system."` + Endpoint string `yaml:"endpoint" env:"POSTPROCESSING_EVENTS_ENDPOINT" desc:"Endpoint of the event system."` + Cluster string `yaml:"cluster" env:"POSTPROCESSING_EVENTS_CLUSTER" desc:"Cluster ID of the event system."` } diff --git a/services/postprocessing/pkg/config/debug.go b/services/postprocessing/pkg/config/debug.go deleted file mode 100644 index 8eac6d526e6..00000000000 --- a/services/postprocessing/pkg/config/debug.go +++ /dev/null @@ -1,9 +0,0 @@ -package config - -// Debug defines the available debug configuration. -type Debug struct { - Addr string `yaml:"addr" env:"NOTIFICATIONS_DEBUG_ADDR" desc:"Bind address of the debug server, where metrics, health, config and debug endpoints will be exposed."` - Token string `yaml:"token" env:"NOTIFICATIONS_DEBUG_TOKEN" desc:"Token to secure the metrics endpoint"` - Pprof bool `yaml:"pprof" env:"NOTIFICATIONS_DEBUG_PPROF" desc:"Enables pprof, which can be used for profiling"` - Zpages bool `yaml:"zpages" env:"NOTIFICATIONS_DEBUG_ZPAGES" desc:"Enables zpages, which can be used for collecting and viewing in-memory traces."` -} diff --git a/services/postprocessing/pkg/config/defaults/defaultconfig.go b/services/postprocessing/pkg/config/defaults/defaultconfig.go index 972c2018c4a..c0f3343e555 100644 --- a/services/postprocessing/pkg/config/defaults/defaultconfig.go +++ b/services/postprocessing/pkg/config/defaults/defaultconfig.go @@ -11,23 +11,18 @@ func FullDefaultConfig() *config.Config { return cfg } -// NOTE: Most of this configuration is not needed to keep it as simple as possible -// TODO: Clean up unneeded configuration - func DefaultConfig() *config.Config { return &config.Config{ - Debug: config.Debug{ - Addr: "127.0.0.1:9174", - }, Service: config.Service{ Name: "postprocessing", }, Postprocessing: config.Postprocessing{ Events: config.Events{ - Endpoint: "127.0.0.1:9233", - Cluster: "ocis-cluster", - ConsumerGroup: "postprocessing", + Endpoint: "127.0.0.1:9233", + Cluster: "ocis-cluster", }, + // Virusscan: true, + // FTSIndex: true, }, } } diff --git a/services/postprocessing/pkg/config/log.go b/services/postprocessing/pkg/config/log.go index 5f13153ce99..bdbd36bd54e 100644 --- a/services/postprocessing/pkg/config/log.go +++ b/services/postprocessing/pkg/config/log.go @@ -2,8 +2,8 @@ package config // Log defines the available log configuration. type Log struct { - Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;NOTIFICATIONS_LOG_LEVEL" desc:"The log level. Valid values are: \"panic\", \"fatal\", \"error\", \"warn\", \"info\", \"debug\", \"trace\"."` - Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;NOTIFICATIONS_LOG_PRETTY" desc:"Activates pretty log output."` - Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;NOTIFICATIONS_LOG_COLOR" desc:"Activates colorized log output."` - File string `mapstructure:"file" env:"OCIS_LOG_FILE;NOTIFICATIONS_LOG_FILE" desc:"The path to the log file. Activates logging to this file if set."` + Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;POSTPROCESSING_LOG_LEVEL" desc:"The log level. Valid values are: \"panic\", \"fatal\", \"error\", \"warn\", \"info\", \"debug\", \"trace\"."` + Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;POSTPROCESSING_LOG_PRETTY" desc:"Activates pretty log output."` + Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;POSTPROCESSING_LOG_COLOR" desc:"Activates colorized log output."` + File string `mapstructure:"file" env:"OCIS_LOG_FILE;POSTPROCESSING_LOG_FILE" desc:"The path to the log file. Activates logging to this file if set."` } diff --git a/services/postprocessing/pkg/postprocessing/postprocessing.go b/services/postprocessing/pkg/postprocessing/postprocessing.go index d224ceea8b1..860a9f79873 100644 --- a/services/postprocessing/pkg/postprocessing/postprocessing.go +++ b/services/postprocessing/pkg/postprocessing/postprocessing.go @@ -1,57 +1,106 @@ package postprocessing import ( + "time" + "github.com/cs3org/reva/v2/pkg/events" "github.com/owncloud/ocis/v2/services/postprocessing/pkg/config" ) // Postprocessing handles postprocessing of a file type Postprocessing struct { - id string - url string - m map[events.Postprocessingstep]interface{} - c config.Postprocessing + id string + url string + m map[events.Postprocessingstep]interface{} + c config.Postprocessing + steps []events.Postprocessingstep } // New returns a new postprocessing instance func New(uploadID string, uploadURL string, c config.Postprocessing) *Postprocessing { return &Postprocessing{ - id: uploadID, - url: uploadURL, - m: make(map[events.Postprocessingstep]interface{}), - c: c, + id: uploadID, + url: uploadURL, + m: make(map[events.Postprocessingstep]interface{}), + c: c, + steps: getSteps(c), } } // Init is the first step of the postprocessing func (pp *Postprocessing) Init(ev events.BytesReceived) interface{} { pp.m["init"] = ev - return events.StartPostprocessingStep{ - UploadID: pp.id, - URL: pp.url, - StepToStart: events.PPStepAntivirus, // TODO: make order configurable + + if len(pp.steps) == 0 { + return pp.finished("continue") } + return pp.nextStep(pp.steps[0]) } // Virusscan is the virusscanning step of the postprocessing func (pp *Postprocessing) Virusscan(ev events.VirusscanFinished) interface{} { - pp.m["virusscan"] = ev + pp.m[events.PPStepAntivirus] = ev - var action string switch { case ev.Infected: - action = "delete" + return pp.finished("delete") case ev.Error != nil: - action = "abort" + return pp.finished("abort") default: - action = "continue" + return pp.next(events.PPStepAntivirus) } +} +// Delay will sleep the configured time then continue +func (pp *Postprocessing) Delay(ev events.StartPostprocessingStep) interface{} { + pp.m[events.PPStepDelay] = ev + time.Sleep(pp.c.Delayprocessing) + return pp.next(events.PPStepDelay) +} + +func (pp *Postprocessing) next(current events.Postprocessingstep) interface{} { + l := len(pp.steps) + for i, s := range pp.steps { + if s == current && i+1 < l { + return pp.next(pp.steps[i+1]) + } + } + return pp.finished("continue") +} + +func (pp *Postprocessing) nextStep(next events.Postprocessingstep) events.StartPostprocessingStep { + return events.StartPostprocessingStep{ + UploadID: pp.id, + URL: pp.url, + StepToStart: next, + } +} + +func (pp *Postprocessing) finished(action string) events.PostprocessingFinished { return events.PostprocessingFinished{ UploadID: pp.id, Result: pp.m, Action: action, } - +} + +func getSteps(c config.Postprocessing) []events.Postprocessingstep { + // NOTE: first version only contains very basic configuration options + // But we aim for a system where postprocessing steps and their order can be configured per space + // ideally by the spaceadmin itself + // We need to iterate over configuring PP service when we see fit + var steps []events.Postprocessingstep + if c.Virusscan { + steps = append(steps, events.PPStepAntivirus) + } + + if c.FTSIndex { + steps = append(steps, events.PPStepFTS) + } + + if c.Delayprocessing != 0 { + steps = append(steps, events.PPStepDelay) + } + return steps } diff --git a/services/postprocessing/pkg/service/service.go b/services/postprocessing/pkg/service/service.go index 871be73540e..c1fad193f5a 100644 --- a/services/postprocessing/pkg/service/service.go +++ b/services/postprocessing/pkg/service/service.go @@ -19,6 +19,7 @@ type PostprocessingService struct { func NewPostprocessingService(stream events.Stream, logger log.Logger, c config.Postprocessing) (*PostprocessingService, error) { evs, err := events.Consume(stream, "postprocessing", events.BytesReceived{}, + events.StartPostprocessingStep{}, events.VirusscanFinished{}, events.UploadReady{}, ) @@ -47,6 +48,12 @@ func (pps *PostprocessingService) Run() error { case events.VirusscanFinished: pp := current[ev.UploadID] next = pp.Virusscan(ev) + case events.StartPostprocessingStep: + if ev.StepToStart != events.PPStepDelay { + continue + } + pp := current[ev.UploadID] + next = pp.Delay(ev) case events.UploadReady: // the storage provider thinks the upload is done - so no need to keep it any more delete(current, ev.UploadID) diff --git a/services/storage-users/pkg/config/config.go b/services/storage-users/pkg/config/config.go index f13122af927..a4ba2435eba 100644 --- a/services/storage-users/pkg/config/config.go +++ b/services/storage-users/pkg/config/config.go @@ -24,6 +24,8 @@ type Config struct { Driver string `yaml:"driver" env:"STORAGE_USERS_DRIVER" desc:"The storage driver which should be used by the service"` Drivers Drivers `yaml:"drivers"` DataServerURL string `yaml:"data_server_url" env:"STORAGE_USERS_DATA_SERVER_URL" desc:"URL of the data server, needs to be reachable by the data gateway provided by the frontend service or the user if directly exposed."` + DataGatewayURL string `yaml:"data_gateway_url" env:"STORAGE_USERS_DATA_GATEWAY_URL" desc:"URL of the data gateway server"` + TransferExpires int64 `yaml:"transfer_expires" env:"STORAGE_USERS_TRANSFER_EXPIRES" desc:"the time after which the token for upload postprocessing expires"` Events Events `yaml:"events"` MountID string `yaml:"mount_id" env:"STORAGE_USERS_MOUNT_ID" desc:"Mount ID of this storage."` ExposeDataServer bool `yaml:"expose_data_server" env:"STORAGE_USERS_EXPOSE_DATA_SERVER" desc:"Exposes the data server directly to users and bypasses the data gateway. Ensure that the data server address is reachable by users."` diff --git a/services/storage-users/pkg/config/defaults/defaultconfig.go b/services/storage-users/pkg/config/defaults/defaultconfig.go index e792c92077a..116c3be0bd6 100644 --- a/services/storage-users/pkg/config/defaults/defaultconfig.go +++ b/services/storage-users/pkg/config/defaults/defaultconfig.go @@ -39,9 +39,11 @@ func DefaultConfig() *config.Config { Reva: &config.Reva{ Address: "127.0.0.1:9142", }, - DataServerURL: "http://localhost:9158/data", - MountID: "1284d238-aa92-42ce-bdc4-0b0000009157", - Driver: "ocis", + DataServerURL: "http://localhost:9158/data", + DataGatewayURL: "https://localhost:9200/data", + TransferExpires: 86400, + MountID: "1284d238-aa92-42ce-bdc4-0b0000009157", + Driver: "ocis", Drivers: config.Drivers{ OwnCloudSQL: config.OwnCloudSQLDriver{ Root: filepath.Join(defaults.BaseDataPath(), "storage", "owncloud"), diff --git a/services/storage-users/pkg/revaconfig/user.go b/services/storage-users/pkg/revaconfig/user.go index c04961dbdc4..a40331e20d0 100644 --- a/services/storage-users/pkg/revaconfig/user.go +++ b/services/storage-users/pkg/revaconfig/user.go @@ -95,11 +95,17 @@ func UserDrivers(cfg *config.Config) map[string]interface{} { "treetime_accounting": true, "treesize_accounting": true, "permissionssvc": cfg.Drivers.OCIS.PermissionsEndpoint, - "asyncfileuploads": true, + // "asyncfileuploads": true, "events": map[string]interface{}{ "natsaddress": cfg.Events.Addr, "natsclusterid": cfg.Events.ClusterID, }, + "tokens": map[string]interface{}{ + "transfer_shared_secret": cfg.Commons.TransferSecret, + "transfer_expires": cfg.TransferExpires, + "download_endpoint": cfg.DataServerURL, + "datagateway_endpoint": cfg.DataGatewayURL, + }, }, "s3": map[string]interface{}{ "enable_home": false,