Skip to content

Commit

Permalink
move config validation to parser package
Browse files Browse the repository at this point in the history
Signed-off-by: jkoberg <[email protected]>
  • Loading branch information
kobergj committed Jan 26, 2023
1 parent d468a23 commit ab4d8c3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 37 deletions.
30 changes: 30 additions & 0 deletions services/postprocessing/pkg/config/parser/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
37 changes: 0 additions & 37 deletions services/postprocessing/pkg/service/service.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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, ",")
}

0 comments on commit ab4d8c3

Please sign in to comment.