mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-04-22 19:19:18 -05:00
move config validation to parser package
Signed-off-by: jkoberg <jkoberg@owncloud.com>
This commit is contained in:
@@ -2,7 +2,10 @@ package parser
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/cs3org/reva/v2/pkg/events"
|
||||
ociscfg "github.com/owncloud/ocis/v2/ocis-pkg/config"
|
||||
"github.com/owncloud/ocis/v2/services/postprocessing/pkg/config"
|
||||
"github.com/owncloud/ocis/v2/services/postprocessing/pkg/config/defaults"
|
||||
@@ -32,6 +35,33 @@ func ParseConfig(cfg *config.Config) error {
|
||||
return Validate(cfg)
|
||||
}
|
||||
|
||||
// Validate validates the config
|
||||
func Validate(cfg *config.Config) error {
|
||||
if cfg.Postprocessing.Virusscan {
|
||||
if !contains(cfg.Postprocessing.Steps, events.PPStepAntivirus) {
|
||||
cfg.Postprocessing.Steps = append(cfg.Postprocessing.Steps, string(events.PPStepAntivirus))
|
||||
fmt.Printf("ATTENTION: POSTPROCESSING_VIRUSSCAN is deprecated. Use `POSTPROCESSING_STEPS=%v` in the future\n", strings.Join(cfg.Postprocessing.Steps, ","))
|
||||
}
|
||||
}
|
||||
|
||||
if cfg.Postprocessing.Delayprocessing != 0 {
|
||||
if !contains(cfg.Postprocessing.Steps, events.PPStepDelay) {
|
||||
if len(cfg.Postprocessing.Steps) > 0 {
|
||||
s := strings.Join(append(cfg.Postprocessing.Steps, string(events.PPStepDelay)), ",")
|
||||
fmt.Printf("Added delay step to the list of postprocessing steps. NOTE: Use envvar `POSTPROCESSING_STEPS=%s` to suppress this message and choose the order of postprocessing steps.\n", s)
|
||||
}
|
||||
|
||||
cfg.Postprocessing.Steps = append(cfg.Postprocessing.Steps, string(events.PPStepDelay))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func contains(all []string, candidate events.Postprocessingstep) bool {
|
||||
for _, s := range all {
|
||||
if s == string(candidate) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/cs3org/reva/v2/pkg/events"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
||||
"github.com/owncloud/ocis/v2/services/postprocessing/pkg/config"
|
||||
@@ -88,39 +85,5 @@ func getSteps(c config.Postprocessing) []events.Postprocessingstep {
|
||||
steps = append(steps, events.Postprocessingstep(s))
|
||||
}
|
||||
|
||||
if c.Virusscan {
|
||||
if !contains(steps, events.PPStepAntivirus) {
|
||||
steps = append(steps, events.PPStepAntivirus)
|
||||
fmt.Printf("ATTENTION: POSTPROCESSING_VIRUSSCAN is deprecated. Use `POSTPROCESSING_STEPS=%v` in the future\n", join(steps))
|
||||
}
|
||||
}
|
||||
|
||||
if c.Delayprocessing != 0 {
|
||||
if !contains(steps, events.PPStepDelay) {
|
||||
if len(steps) > 0 {
|
||||
fmt.Printf("Added delay step to the list of postprocessing steps. NOTE: Use envvar `POSTPROCESSING_STEPS=%v` to suppress this message and choose the order of postprocessing steps.\n", join(append(steps, events.PPStepDelay)))
|
||||
}
|
||||
|
||||
steps = append(steps, events.PPStepDelay)
|
||||
}
|
||||
}
|
||||
|
||||
return steps
|
||||
}
|
||||
|
||||
func contains(all []events.Postprocessingstep, candidate events.Postprocessingstep) bool {
|
||||
for _, s := range all {
|
||||
if s == candidate {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func join(all []events.Postprocessingstep) string {
|
||||
var slice []string
|
||||
for _, s := range all {
|
||||
slice = append(slice, string(s))
|
||||
}
|
||||
return strings.Join(slice, ",")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user