add fixes from review

This commit is contained in:
Willy Kloucek
2022-04-29 16:10:21 +02:00
parent 4fdd3170cc
commit 1cdb81bd3e
30 changed files with 29 additions and 147 deletions
-34
View File
@@ -4,7 +4,6 @@ import (
"context"
"flag"
"fmt"
"strings"
"github.com/cs3org/reva/v2/pkg/micro/ocdav"
"github.com/oklog/run"
@@ -12,7 +11,6 @@ import (
"github.com/owncloud/ocis/extensions/ocdav/pkg/config/parser"
"github.com/owncloud/ocis/extensions/storage/pkg/server/debug"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/conversions"
"github.com/owncloud/ocis/ocis-pkg/log"
"github.com/owncloud/ocis/ocis-pkg/sync"
"github.com/owncloud/ocis/ocis-pkg/tracing"
@@ -26,13 +24,6 @@ func OCDav(cfg *config.Config) *cli.Command {
return &cli.Command{
Name: "ocdav",
Usage: "start ocdav service",
// TODO: check
//Before: func(c *cli.Context) error {
// if err := loadUserAgent(c, cfg); err != nil {
// return err
// }
// return nil
//},
Before: func(ctx *cli.Context) error {
err := parser.ParseConfig(cfg)
if err != nil {
@@ -153,28 +144,3 @@ func (s OCDavSutureService) Serve(ctx context.Context) error {
return nil
}
// loadUserAgent reads the user-agent-whitelist-lock-in, since it is a string flag, and attempts to construct a map of
// "user-agent":"challenge" locks in for Reva.
// Modifies cfg. Spaces don't need to be trimmed as urfavecli takes care of it. User agents with spaces are valid. i.e:
// Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:83.0) Gecko/20100101 Firefox/83.0
// This function works by relying in our format of specifying [user-agent:challenge] and the fact that the user agent
// might contain ":" (colon), so the original string is reversed, split in two parts, by the time it is split we
// have the indexes reversed and the tuple is in the format of [challenge:user-agent], then the same process is applied
// in reverse for each individual part
func loadUserAgent(c *cli.Context, cfg *config.Config) error {
cfg.Middleware.Auth.CredentialsByUserAgent = make(map[string]string)
locks := c.StringSlice("user-agent-whitelist-lock-in")
for _, v := range locks {
vv := conversions.Reverse(v)
parts := strings.SplitN(vv, ":", 2)
if len(parts) != 2 {
return fmt.Errorf("unexpected config value for user-agent lock-in: %v, expected format is user-agent:challenge", v)
}
cfg.Middleware.Auth.CredentialsByUserAgent[conversions.Reverse(parts[1])] = conversions.Reverse(parts[0])
}
return nil
}