Skip to content

Commit

Permalink
remve pw magic
Browse files Browse the repository at this point in the history
  • Loading branch information
labkode committed Feb 13, 2020
1 parent d146951 commit 2081c97
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 440 deletions.
1 change: 0 additions & 1 deletion cmd/revad/runtime/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
_ "github.com/cs3org/reva/pkg/publicshare/manager/loader"
_ "github.com/cs3org/reva/pkg/share/manager/loader"
_ "github.com/cs3org/reva/pkg/storage/fs/loader"
_ "github.com/cs3org/reva/pkg/storage/pw/loader"
_ "github.com/cs3org/reva/pkg/storage/registry/loader"
_ "github.com/cs3org/reva/pkg/token/manager/loader"
_ "github.com/cs3org/reva/pkg/user/manager/loader"
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQ
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d h1:TxyelI5cVkbREznMhfzycHdkp5cLA7DpE+GKjSslYhM=
gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d/go.mod h1:cuepJuh7vyXfUyUwEgHQXw849cJrilpS5NeIjOWESAw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/cheggaaa/pb.v1 v1.0.27 h1:kJdccidYzt3CaHD1crCFTS1hxyhSi059NhOFUf03YFo=
gopkg.in/cheggaaa/pb.v1 v1.0.27/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
Expand Down
16 changes: 0 additions & 16 deletions internal/grpc/services/storageprovider/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"github.com/cs3org/reva/pkg/rgrpc/status"
"github.com/cs3org/reva/pkg/storage"
"github.com/cs3org/reva/pkg/storage/fs/registry"
pwregistry "github.com/cs3org/reva/pkg/storage/pw/registry"
"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
"go.opencensus.io/trace"
Expand Down Expand Up @@ -134,10 +133,6 @@ func New(m map[string]interface{}, ss *grpc.Server) (rgrpc.Service, error) {
if err != nil {
return nil, err
}
pw, err := getPW(c)
if err != nil {
return nil, err
}

// parse data server url
u, err := url.Parse(c.DataServerURL)
Expand All @@ -158,7 +153,6 @@ func New(m map[string]interface{}, ss *grpc.Server) (rgrpc.Service, error) {
service := &service{
conf: c,
storage: fs,
pathWrapper: pw,
tmpFolder: tmpFolder,
mountPath: mountPath,
mountID: mountID,
Expand Down Expand Up @@ -789,16 +783,6 @@ func getFS(c *config) (storage.FS, error) {
return nil, fmt.Errorf("driver not found: %s", c.Driver)
}

func getPW(c *config) (storage.PathWrapper, error) {
if c.PathWrapper == "" {
return nil, nil
}
if f, ok := pwregistry.NewFuncs[c.PathWrapper]; ok {
return f(c.PathWrappers[c.PathWrapper])
}
return nil, fmt.Errorf("path wrapper not found: %s", c.Driver)
}

func (s *service) unwrap(ctx context.Context, ref *provider.Reference) (*provider.Reference, error) {
if ref.GetId() != nil {
idRef := &provider.Reference{
Expand Down
91 changes: 49 additions & 42 deletions pkg/storage/fs/eos/eos.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@ import (
"strconv"
"strings"

"github.com/cs3org/reva/pkg/storage/fs/registry"
"github.com/cs3org/reva/pkg/storage/helper"

"github.com/cs3org/reva/pkg/appctx"
"github.com/cs3org/reva/pkg/eosclient"
"github.com/cs3org/reva/pkg/mime"
"github.com/cs3org/reva/pkg/storage"
"github.com/cs3org/reva/pkg/storage/acl"
"github.com/cs3org/reva/pkg/storage/fs/registry"
"github.com/cs3org/reva/pkg/storage/templates"
"github.com/cs3org/reva/pkg/user"
"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
Expand Down Expand Up @@ -121,8 +120,11 @@ type config struct {
// SingleUsername is the username to use when SingleUserMode is enabled
SingleUsername string `mapstructure:"single_username"`

// Layout
Layout string `mapstructure:"layout"`
// UserLayout wraps the internal path with user information.
// Example: if mountpoint is /eos/user and received path is /docs
// and the UserLayout is {{.Username}} the internal path will be:
// /eos/user/<username>/docs
UserLayout string `mapstructure:"layout"`
}

func getUser(ctx context.Context) (*userpb.User, error) {
Expand Down Expand Up @@ -159,10 +161,6 @@ func (c *config) init() {
if c.CacheDirectory == "" {
c.CacheDirectory = os.TempDir()
}

if c.Layout == "" {
c.Layout = "{{.Username}}"
}
}

// New returns a new implementation of the storage.FS interface that connects to EOS.
Expand Down Expand Up @@ -205,33 +203,43 @@ func New(m map[string]interface{}) (storage.FS, error) {
return eosStorage, nil
}

func (fs *eosStorage) getHomeForUser(u *userpb.User) (string, error) {
userhome, err := helper.GetUserHomePath(u, fs.conf.Layout)
if err != nil {
return "", err
}

home := path.Join(fs.mountpoint, userhome)
return home, nil
}

func (fs *eosStorage) Shutdown(ctx context.Context) error {
// TODO(labkode): in a grpc implementation we can close connections.
return nil
}

func (fs *eosStorage) getInternalPath(ctx context.Context, fn string) string {
internalPath := path.Join(fs.mountpoint, fn)
return internalPath
func (fs *eosStorage) wrap(ctx context.Context, fn string) (internal string) {
if fs.conf.EnableHome && fs.conf.UserLayout != "" {
u, err := getUser(ctx)
if err != nil {
err = errors.Wrap(err, "eos: wrap: no user in ctx and home is enabled")
panic(err)
}
layout := templates.WithUser(u, fs.conf.UserLayout)
internal = path.Join(fs.mountpoint, layout, fn)
} else {
internal = path.Join(fs.mountpoint, fn)
}
return
}

func (fs *eosStorage) removeNamespace(ctx context.Context, np string) string {
p := strings.TrimPrefix(np, fs.mountpoint)
if p == "" {
p = "/"
func (fs *eosStorage) unwrap(ctx context.Context, np string) (external string) {
if fs.conf.EnableHome && fs.conf.UserLayout != "" {
u, err := getUser(ctx)
if err != nil {
err = errors.Wrap(err, "eos: unwrap: no user in ctx and home is enabled")
panic(err)
}
layout := templates.WithUser(u, fs.conf.UserLayout)
trim := path.Join(fs.mountpoint, layout)
external = strings.TrimPrefix(np, trim)
} else {
external = strings.TrimPrefix(np, fs.mountpoint)
if external == "" {
external = "/"
}
}

return p
return
}

func (fs *eosStorage) GetPathByID(ctx context.Context, id *provider.ResourceId) (string, error) {
Expand Down Expand Up @@ -259,7 +267,7 @@ func (fs *eosStorage) GetPathByID(ctx context.Context, id *provider.ResourceId)
// resolve takes in a request path or request id and converts it to a internal path.
func (fs *eosStorage) resolve(ctx context.Context, u *userpb.User, ref *provider.Reference) (string, error) {
if ref.GetPath() != "" {
return fs.getInternalPath(ctx, ref.GetPath()), nil
return fs.wrap(ctx, ref.GetPath()), nil
}

if ref.GetId() != nil {
Expand Down Expand Up @@ -577,26 +585,25 @@ func (fs *eosStorage) GetQuota(ctx context.Context) (int, int, error) {
}

func (fs *eosStorage) GetHome(ctx context.Context) (string, error) {
u, err := getUser(ctx)
if err != nil {
return "", errors.Wrap(err, "eos: no user in ctx")
}

home, err := fs.getHomeForUser(u)
if err != nil {
return "", err
if !fs.conf.EnableHome {
return "", errtypes.NotSupported("eos: get home not supported")
}

home := fs.wrap(ctx, "/")
return home, nil
}

func (fs *eosStorage) CreateHome(ctx context.Context) error {
if !fs.conf.EnableHome {
return errtypes.NotSupported("eos: create home not supported")
}

u, err := getUser(ctx)
if err != nil {
return errors.Wrap(err, "eos: no user in ctx")
}

home, err := fs.getHomeForUser(u)
home := fs.wrap(ctx, "/")
if err != nil {
return err
}
Expand Down Expand Up @@ -665,7 +672,7 @@ func (fs *eosStorage) CreateDir(ctx context.Context, fn string) error {
return errors.Wrap(err, "eos: no user in ctx")
}

fn = fs.getInternalPath(ctx, fn)
fn = fs.wrap(ctx, fn)
return fs.c.CreateDir(ctx, u.Username, fn)
}

Expand Down Expand Up @@ -810,7 +817,7 @@ func (fs *eosStorage) DownloadRevision(ctx context.Context, ref *provider.Refere
return nil, errors.Wrap(err, "eos: error resolving reference")
}

fn = fs.getInternalPath(ctx, fn)
fn = fs.wrap(ctx, fn)
return fs.c.ReadVersion(ctx, u.Username, fn, revisionKey)
}

Expand Down Expand Up @@ -878,7 +885,7 @@ func (fs *eosStorage) RestoreRecycleItem(ctx context.Context, key string) error

func (fs *eosStorage) convertToRecycleItem(ctx context.Context, eosDeletedItem *eosclient.DeletedEntry) *provider.RecycleItem {
recycleItem := &provider.RecycleItem{
Path: fs.removeNamespace(ctx, eosDeletedItem.RestorePath),
Path: fs.unwrap(ctx, eosDeletedItem.RestorePath),
Key: eosDeletedItem.RestoreKey,
Size: eosDeletedItem.Size,
DeletionTime: &types.Timestamp{Seconds: eosDeletedItem.DeletionMTime / 1000}, // TODO(labkode): check if eos time is millis or nanos
Expand All @@ -903,7 +910,7 @@ func (fs *eosStorage) convertToRevision(ctx context.Context, eosFileInfo *eoscli
}

func (fs *eosStorage) convertToResourceInfo(ctx context.Context, eosFileInfo *eosclient.FileInfo) *provider.ResourceInfo {
path := fs.removeNamespace(ctx, eosFileInfo.File)
path := fs.unwrap(ctx, eosFileInfo.File)
size := eosFileInfo.Size
if eosFileInfo.IsDir {
size = eosFileInfo.TreeSize
Expand Down
Loading

0 comments on commit 2081c97

Please sign in to comment.