Skip to content

Commit

Permalink
add GetHome from storage provider
Browse files Browse the repository at this point in the history
  • Loading branch information
labkode committed Jan 14, 2020
1 parent 025923c commit ff09fe4
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 36 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/aws/aws-sdk-go v1.26.7
github.com/cheggaaa/pb v1.0.28
github.com/coreos/go-oidc v2.1.0+incompatible
github.com/cs3org/go-cs3apis v0.0.0-20200113082535-e58b99ae8f80
github.com/cs3org/go-cs3apis v0.0.0-20200113170445-f5790f408edc
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/fatih/color v1.7.0 // indirect
github.com/go-openapi/strfmt v0.19.2 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ github.com/coreos/go-oidc v2.1.0+incompatible/go.mod h1:CgnwVTmzoESiwO9qyAFEMiHo
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/cs3org/go-cs3apis v0.0.0-20200113082535-e58b99ae8f80 h1:ui+ztsFshmOv1yR3HRPaDRz1J/G6VQLd0ZUaBG33fWU=
github.com/cs3org/go-cs3apis v0.0.0-20200113082535-e58b99ae8f80/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/cs3org/go-cs3apis v0.0.0-20200113170445-f5790f408edc h1:qY/nHxpK3mJHkmWveEpwQCWHeNBjlDgk+o4t/5QeZM4=
github.com/cs3org/go-cs3apis v0.0.0-20200113170445-f5790f408edc/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
38 changes: 32 additions & 6 deletions internal/grpc/services/gateway/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (s *svc) sign(ctx context.Context, target string) (string, error) {
}

func (s *svc) CreateHome(ctx context.Context, req *provider.CreateHomeRequest) (*provider.CreateHomeResponse, error) {
homeReq := &registry.GetHomeRequest{}
homeReq := &provider.GetHomeRequest{}
homeRes, err := s.GetHome(ctx, homeReq)
if err != nil {
err := errors.Wrap(err, "gateway: error calling GetHome")
Expand Down Expand Up @@ -95,20 +95,46 @@ func (s *svc) CreateHome(ctx context.Context, req *provider.CreateHomeRequest) (
return res, nil

}
func (s *svc) GetHome(ctx context.Context, ref *registry.GetHomeRequest) (*registry.GetHomeResponse, error) {
func (s *svc) GetHome(ctx context.Context, req *provider.GetHomeRequest) (*provider.GetHomeResponse, error) {
c, err := pool.GetStorageRegistryClient(s.c.StorageRegistryEndpoint)
if err != nil {
err = errors.Wrap(err, "gateway: error getting storage registry client")
return nil, err
return &provider.GetHomeResponse{
Status: status.NewInternal(ctx, err, "error finding storage registry"),
}, nil
}

res, err := c.GetHome(ctx, &registry.GetHomeRequest{})

if err != nil {
err = errors.Wrap(err, "gateway: error calling GetHome")
return nil, err
return &provider.GetHomeResponse{
Status: status.NewInternal(ctx, err, "error calling GetHome"),
}, nil
}
return res, nil

if res.Status.Code != rpc.Code_CODE_OK {
err := status.NewErrorFromCode(res.Status.Code, "gateway")
return &provider.GetHomeResponse{
Status: status.NewInternal(ctx, err, "error calling GetHome"),
}, nil
}

storageClient, err := pool.GetStorageProviderServiceClient(res.Provider.Address)
if err != nil {
err = errors.Wrap(err, "gateway: error getting storage provider client")
return &provider.GetHomeResponse{
Status: status.NewInternal(ctx, err, "error getting home"),
}, nil
}

homeRes, err := storageClient.GetHome(ctx, req)
if err != nil {
err = errors.Wrap(err, "gateway: error getting GetHome from storage provider")
return &provider.GetHomeResponse{
Status: status.NewInternal(ctx, err, "error getting home"),
}, nil
}
return homeRes, nil
}

func (s *svc) InitiateFileDownload(ctx context.Context, req *provider.InitiateFileDownloadRequest) (*gateway.InitiateFileDownloadResponse, error) {
Expand Down
16 changes: 2 additions & 14 deletions internal/grpc/services/gateway/usershareprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
registry "github.com/cs3org/go-cs3apis/cs3/storage/registry/v1beta1"
"github.com/cs3org/reva/pkg/appctx"
"github.com/cs3org/reva/pkg/errtypes"
"github.com/cs3org/reva/pkg/rgrpc/status"
Expand Down Expand Up @@ -389,19 +388,8 @@ func (s *svc) UpdateReceivedShare(ctx context.Context, req *collaboration.Update

share := getShareRes.Share

// get user home
storageRegClient, err := pool.GetStorageRegistryClient(s.c.StorageRegistryEndpoint)
if err != nil {
log.Err(err).Msg("gateway: error getting storage registry client")
return &collaboration.UpdateReceivedShareResponse{
Status: &rpc.Status{
Code: rpc.Code_CODE_INTERNAL,
},
}, nil
}

homeReq := &registry.GetHomeRequest{}
homeRes, err := storageRegClient.GetHome(ctx, homeReq)
homeReq := &provider.GetHomeRequest{}
homeRes, err := s.GetHome(ctx, homeReq)
if err != nil {
err := errors.Wrap(err, "gateway: error calling GetHome")
return &collaboration.UpdateReceivedShareResponse{
Expand Down
25 changes: 25 additions & 0 deletions internal/grpc/services/storageprovider/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,31 @@ func (s *service) GetPath(ctx context.Context, req *provider.GetPathRequest) (*p
return res, nil
}

func (s *service) GetHome(ctx context.Context, req *provider.GetHomeRequest) (*provider.GetHomeResponse, error) {
if !s.conf.EnableHomeCreation {
err := errtypes.NotSupported("storageprovider: getting home directories not supported")
st := status.NewUnimplemented(ctx, err, "getting home directories is disabled")
return &provider.GetHomeResponse{
Status: st,
}, nil

}

home, err := s.storage.GetHome(ctx)
if err != nil {
st := status.NewInternal(ctx, err, "error getting home")
return &provider.GetHomeResponse{
Status: st,
}, nil
}

res := &provider.GetHomeResponse{
Status: status.NewOK(ctx),
Path: home,
}
return res, nil
}

func (s *service) CreateHome(ctx context.Context, req *provider.CreateHomeRequest) (*provider.CreateHomeResponse, error) {
if !s.conf.EnableHomeCreation {
err := errtypes.NotSupported("storageprovider: create home directories not supported")
Expand Down
4 changes: 2 additions & 2 deletions internal/grpc/services/storageregistry/storageregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ func (s *service) GetHome(ctx context.Context, req *registrypb.GetHomeRequest) (
}

res := &registrypb.GetHomeResponse{
Status: status.NewOK(ctx),
Path: p,
Status: status.NewOK(ctx),
Provider: p,
}
return res, nil
}
Expand Down
3 changes: 1 addition & 2 deletions internal/http/services/owncloud/ocdav/trashbin.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
registry "github.com/cs3org/go-cs3apis/cs3/storage/registry/v1beta1"
"github.com/cs3org/reva/internal/http/utils"
"github.com/cs3org/reva/pkg/appctx"
"github.com/cs3org/reva/pkg/rgrpc/todo/pool"
Expand Down Expand Up @@ -161,7 +160,7 @@ func (h *TrashbinHandler) listTrashbin(w http.ResponseWriter, r *http.Request, s
return
}

getHomeRes, err := gc.GetHome(ctx, &registry.GetHomeRequest{})
getHomeRes, err := gc.GetHome(ctx, &provider.GetHomeRequest{})
if err != nil {
log.Error().Err(err).Msg("error calling GetHomeProvider")
w.WriteHeader(http.StatusInternalServerError)
Expand Down
22 changes: 19 additions & 3 deletions pkg/storage/fs/eos/eos.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ func New(m map[string]interface{}) (storage.FS, error) {
return eosStorage, nil
}

func (fs *eosStorage) getHomeForUser(u *userpb.User) string {
// TODO(labkode): define home path layout in configuration
// like home: %letter%/%username% and then do string substitution.
home := path.Join(fs.mountpoint, u.Username)
return home
}

func (fs *eosStorage) Shutdown(ctx context.Context) error {
// TODO(labkode): in a grpc implementation we can close connections.
return nil
Expand Down Expand Up @@ -558,15 +565,24 @@ func (fs *eosStorage) GetQuota(ctx context.Context) (int, int, error) {
return fs.c.GetQuota(ctx, u.Username, fs.conf.Namespace)
}

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 := fs.getHomeForUser(u)
return home, nil
}

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

// TODO(labkode): define home path layout in configuration
// like home: %letter%/%username% and then do string substitution.
home := path.Join(fs.mountpoint, u.Username)
home := fs.getHomeForUser(u)

_, err = fs.c.GetFileInfoByPath(ctx, u.Username, home)
if err == nil { // home already exists
return nil
Expand Down
4 changes: 4 additions & 0 deletions pkg/storage/fs/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ func (fs *localFS) UnsetArbitraryMetadata(ctx context.Context, ref *provider.Ref
return errtypes.NotSupported("local: operation not supported")
}

func (fs *localFS) GetHome(ctx context.Context) (string, error) {
return "", errtypes.NotSupported("local: creating home not supported")
}

func (fs *localFS) CreateHome(ctx context.Context) error {
return errtypes.NotSupported("local: creating home not supported")
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/storage/fs/owncloud/owncloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,11 @@ func (fs *ocFS) GetQuota(ctx context.Context) (int, int, error) {
func (fs *ocFS) CreateHome(ctx context.Context) error {
return errtypes.NotSupported("ocFS: not supported")
}

func (fs *ocFS) GetHome(ctx context.Context) (string, error) {
return "", errtypes.NotSupported("ocFS: not supported")
}

func (fs *ocFS) CreateDir(ctx context.Context, fn string) (err error) {
np := fs.getInternalPath(ctx, fn)
if err = os.Mkdir(np, 0700); err != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/storage/fs/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,10 @@ func (fs *s3FS) CreateReference(ctx context.Context, path string, targetURI *url
return errtypes.NotSupported("s3: operation not supported")
}

func (fs *s3FS) GetHome(ctx context.Context) (string, error) {
return "", errtypes.NotSupported("eos: not supported")
}

func (fs *s3FS) CreateHome(ctx context.Context) error {
return errtypes.NotSupported("s3fs: not supported")
}
Expand Down
19 changes: 12 additions & 7 deletions pkg/storage/registry/static/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func init() {
}

type reg struct {
c *config
rules map[string]string
}

Expand All @@ -52,13 +53,16 @@ func (b *reg) ListProviders(ctx context.Context) ([]*registrypb.ProviderInfo, er

// returns the the root path of the first provider in the list.
// TODO(labkode): this is not production ready.
func (b *reg) GetHome(ctx context.Context) (string, error) {
for k := range b.rules {
if strings.HasPrefix(k, "/") {
return k, nil
func (b *reg) GetHome(ctx context.Context) (*registrypb.ProviderInfo, error) {
for k, v := range b.rules {
if k == b.c.HomeProvider {
return &registrypb.ProviderInfo{
ProviderPath: k,
Address: v,
}, nil
}
}
return "", errors.New("static: home not found")
return nil, errors.New("static: home not found")
}

func (b *reg) FindProvider(ctx context.Context, ref *provider.Reference) (*registrypb.ProviderInfo, error) {
Expand Down Expand Up @@ -101,7 +105,8 @@ func (b *reg) FindProvider(ctx context.Context, ref *provider.Reference) (*regis
}

type config struct {
Rules map[string]string `mapstructure:"rules"`
Rules map[string]string `mapstructure:"rules"`
HomeProvider string `mapstructure:"home_provider"`
}

func parseConfig(m map[string]interface{}) (*config, error) {
Expand All @@ -119,5 +124,5 @@ func New(m map[string]interface{}) (storage.Registry, error) {
if err != nil {
return nil, err
}
return &reg{rules: c.Rules}, nil
return &reg{rules: c.Rules, c: c}, nil
}
3 changes: 2 additions & 1 deletion pkg/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

// FS is the interface to implement access to the storage.
type FS interface {
GetHome(ctx context.Context) (string, error)
CreateHome(ctx context.Context) error
CreateDir(ctx context.Context, fn string) error
Delete(ctx context.Context, ref *provider.Reference) error
Expand Down Expand Up @@ -61,7 +62,7 @@ type FS interface {
type Registry interface {
FindProvider(ctx context.Context, ref *provider.Reference) (*registry.ProviderInfo, error)
ListProviders(ctx context.Context) ([]*registry.ProviderInfo, error)
GetHome(ctx context.Context) (string, error)
GetHome(ctx context.Context) (*registry.ProviderInfo, error)
}

// PathWrapper is the interface to implement for path transformations
Expand Down

0 comments on commit ff09fe4

Please sign in to comment.