Start PP service in single binary (configurable)
Start PP service in single binary (configurable) Start PP service in single binary (configurable) start pp service with single binary and make it configurable Signed-off-by: jkoberg <jkoberg@owncloud.com> implement delay step Signed-off-by: jkoberg <jkoberg@owncloud.com> deactivate functionality Signed-off-by: jkoberg <jkoberg@owncloud.com> configure tokensigning Signed-off-by: jkoberg <jkoberg@owncloud.com> deactivate async uploads Signed-off-by: jkoberg <jkoberg@owncloud.com> final touches Signed-off-by: jkoberg <jkoberg@owncloud.com> next bump of the reva Signed-off-by: jkoberg <jkoberg@owncloud.com>
This commit is contained in:
1 parent
8cf928ad91
commit
e208a96430
14 files changed
+120
-71
No files matched your search
@@ -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
|
||||
}
|
||||
Reference in new issue
Block a user