Skip to content

Commit

Permalink
start updating references
Browse files Browse the repository at this point in the history
  • Loading branch information
refs committed Jun 14, 2021
1 parent 94032a3 commit c718c67
Show file tree
Hide file tree
Showing 36 changed files with 161 additions and 111 deletions.
4 changes: 2 additions & 2 deletions cmd/reva/ocm-share-list.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ func ocmShareListCommand() *command {
if len(tokens) != 2 {
return fmt.Errorf("resource id invalid")
}
id := &provider.Reference{
id := &provider.ResourceId{
StorageId: tokens[0],
NodeId: tokens[1],
OpaqueId: tokens[1],
}
shareRequest.Filters = []*ocm.ListOCMSharesRequest_Filter{
&ocm.ListOCMSharesRequest_Filter{
Expand Down
4 changes: 2 additions & 2 deletions cmd/reva/public-share-list.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ func publicShareListCommand() *command {
if len(tokens) != 2 {
return fmt.Errorf("resource id invalid")
}
id := &provider.Reference{
id := &provider.ResourceId{
StorageId: tokens[0],
NodeId: tokens[1],
OpaqueId: tokens[1],
}
shareRequest.Filters = []*link.ListPublicSharesRequest_Filter{
&link.ListPublicSharesRequest_Filter{
Expand Down
4 changes: 3 additions & 1 deletion cmd/reva/recycle-list.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ func recycleListCommand() *command {
}

req := &gateway.ListRecycleRequest{
Ref: getHomeRes.Ref,
Ref: &provider.Reference{
Path: getHomeRes.Path,
},
}
res, err := client.ListRecycle(ctx, req)
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion cmd/reva/recycle-purge.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ func recyclePurgeCommand() *command {
return err
}

req := &gateway.PurgeRecycleRequest{Ref: getHomeRes.Ref}
req := &gateway.PurgeRecycleRequest{
Ref: &provider.Reference{
Path: getHomeRes.Path,
},
}

res, err := client.PurgeRecycle(ctx, req)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion cmd/reva/recycle-restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ func recycleRestoreCommand() *command {
}

req := &provider.RestoreRecycleItemRequest{
Ref: getHomeRes.Ref,
Ref: &provider.Reference{
Path: getHomeRes.Path,
},
Key: key,
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/reva/share-list.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ func shareListCommand() *command {
if len(tokens) != 2 {
return fmt.Errorf("resource id invalid")
}
id := &provider.Reference{
id := &provider.ResourceId{
StorageId: tokens[0],
NodeId: tokens[1],
OpaqueId: tokens[1],
}
shareRequest.Filters = []*collaboration.ListSharesRequest_Filter{
&collaboration.ListSharesRequest_Filter{
Expand Down
2 changes: 1 addition & 1 deletion cmd/reva/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func uploadCommand() *command {

info := res2.Info

fmt.Printf("File uploaded: %s:%s %d %s\n", info.Id.StorageId, info.Id.NodeId, info.Size, info.Path)
fmt.Printf("File uploaded: %s:%s %d %s\n", info.Id.StorageId, info.Id.OpaqueId, info.Size, info.Path)

return nil
}
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/cheggaaa/pb v1.0.29
github.com/coreos/go-oidc v2.2.1+incompatible
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e
github.com/cs3org/go-cs3apis v0.0.0-20210527092509-2b828e94ed4c
github.com/cs3org/go-cs3apis v0.0.0-20210614143420-5ee2eb1e7887
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/eventials/go-tus v0.0.0-20200718001131-45c7ec8f5d59
github.com/gdexlab/go-render v1.0.1
Expand Down Expand Up @@ -61,7 +61,6 @@ require (
go 1.16

replace (
github.com/cs3org/go-cs3apis => github.com/butonic/go-cs3apis v0.0.0-20210608111428-0b2c079174c9
github.com/eventials/go-tus => github.com/andrewmostello/go-tus v0.0.0-20200314041820-904a9904af9a
github.com/oleiade/reflections => github.com/oleiade/reflections v1.0.1
google.golang.org/grpc => google.golang.org/grpc v1.26.0 // temporary downgrade
Expand Down
6 changes: 5 additions & 1 deletion internal/grpc/interceptors/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,11 @@ func dismantleToken(ctx context.Context, tkn string, req interface{}, mgr token.

// Since the public share is obtained from the scope, the current token
// has access to it.
statReq := &provider.StatRequest{Ref: share.ResourceId}
statReq := &provider.StatRequest{
Ref: &provider.Reference{
ResourceId: share.ResourceId,
},
}

statResponse, err := client.Stat(ctx, statReq)
if err != nil || statResponse.Status.Code != rpc.Code_CODE_OK {
Expand Down
2 changes: 1 addition & 1 deletion internal/grpc/services/appprovider/appprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (s *service) OpenInApp(ctx context.Context, req *providerpb.OpenInAppReques
}

q := httpReq.URL.Query()
q.Add("fileid", req.ResourceInfo.GetId().NodeId)
q.Add("fileid", req.ResourceInfo.GetId().OpaqueId)
q.Add("endpoint", req.ResourceInfo.GetId().StorageId)
q.Add("viewmode", req.ViewMode.String())
// TODO the folder URL should be resolved as e.g. `'https://cernbox.cern.ch/index.php/apps/files/?dir=' + filepath.Dir(req.Ref.GetPath())`
Expand Down
12 changes: 7 additions & 5 deletions internal/grpc/services/gateway/ocmshareprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ func (s *svc) CreateOCMShare(ctx context.Context, req *ocm.CreateOCMShareRequest

// TODO(labkode): if both commits are enabled they could be done concurrently.
if s.c.CommitShareToStorageGrant {
addGrantStatus, err := s.addGrant(ctx, req.ResourceId, req.Grant.Grantee, req.Grant.Permissions.Permissions)
rid := &provider.Reference{ResourceId: req.ResourceId}
addGrantStatus, err := s.addGrant(ctx, rid, req.Grant.Grantee, req.Grant.Permissions.Permissions)
if err != nil {
return nil, errors.Wrap(err, "gateway: error adding OCM grant to storage")
}
Expand Down Expand Up @@ -109,7 +110,8 @@ func (s *svc) RemoveOCMShare(ctx context.Context, req *ocm.RemoveOCMShareRequest

// TODO(labkode): if both commits are enabled they could be done concurrently.
if s.c.CommitShareToStorageGrant {
removeGrantStatus, err := s.removeGrant(ctx, share.ResourceId, share.Grantee, share.Permissions.Permissions)
rid := &provider.Reference{ResourceId: share.ResourceId}
removeGrantStatus, err := s.removeGrant(ctx, rid, share.Grantee, share.Permissions.Permissions)
if err != nil {
return nil, errors.Wrap(err, "gateway: error removing OCM grant from storage")
}
Expand Down Expand Up @@ -318,7 +320,7 @@ func (s *svc) createOCMReference(ctx context.Context, share *ocm.Share) (*rpc.St
if share.ShareType == ocm.Share_SHARE_TYPE_TRANSFER {
createTransferDir, err := s.CreateContainer(ctx, &provider.CreateContainerRequest{
Ref: &provider.Reference{
Path: path.Join(homeRes.Ref.Path, s.c.DataTransfersFolder),
Path: path.Join(homeRes.Path, s.c.DataTransfersFolder),
},
})
if err != nil {
Expand All @@ -329,14 +331,14 @@ func (s *svc) createOCMReference(ctx context.Context, share *ocm.Share) (*rpc.St
return status.NewInternal(ctx, err, "error creating transfers directory"), nil
}

refPath = path.Join(homeRes.Ref.Path, s.c.DataTransfersFolder, path.Base(share.Name))
refPath = path.Join(homeRes.Path, s.c.DataTransfersFolder, path.Base(share.Name))
targetURI = fmt.Sprintf("datatx://%s@%s?name=%s", token, share.Creator.Idp, share.Name)
} else {
// reference path is the home path + some name on the corresponding
// mesh provider (/home/MyShares/x)
// It is the responsibility of the gateway to resolve these references and merge the response back
// from the main request.
refPath = path.Join(homeRes.Ref.Path, s.c.ShareFolder, path.Base(share.Name))
refPath = path.Join(homeRes.Path, s.c.ShareFolder, path.Base(share.Name))
// webdav is the scheme, token@host the opaque part and the share name the query of the URL.
targetURI = fmt.Sprintf("webdav://%s@%s?name=%s", token, share.Creator.Idp, share.Name)
}
Expand Down
42 changes: 26 additions & 16 deletions internal/grpc/services/gateway/usershareprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,14 @@ func (s *svc) UpdateReceivedShare(ctx context.Context, req *collaboration.Update
}, nil
}

func (s *svc) createReference(ctx context.Context, resourceID *provider.Reference) *rpc.Status {

func (s *svc) createReference(ctx context.Context, resourceID *provider.ResourceId) *rpc.Status {
ref := &provider.Reference{
ResourceId: resourceID,
}
log := appctx.GetLogger(ctx)

// get the metadata about the share
c, err := s.find(ctx, resourceID)
c, err := s.find(ctx, ref)
if err != nil {
if _, ok := err.(errtypes.IsNotFound); ok {
return status.NewNotFound(ctx, "storage provider not found")
Expand All @@ -334,7 +336,7 @@ func (s *svc) createReference(ctx context.Context, resourceID *provider.Referenc
}

statReq := &provider.StatRequest{
Ref: resourceID,
Ref: ref,
}

statRes, err := c.Stat(ctx, statReq)
Expand Down Expand Up @@ -364,13 +366,13 @@ func (s *svc) createReference(ctx context.Context, resourceID *provider.Referenc
// It is the responsibility of the gateway to resolve these references and merge the response back
// from the main request.
// TODO(labkode): the name of the share should be the filename it points to by default.
refPath := path.Join(homeRes.Ref.Path, s.c.ShareFolder, path.Base(statRes.Info.Path))
refPath := path.Join(homeRes.Path, s.c.ShareFolder, path.Base(statRes.Info.Path))
log.Info().Msg("mount path will be:" + refPath)

createRefReq := &provider.CreateReferenceRequest{
Ref: &provider.Reference{Path: refPath},
// cs3 is the Scheme and %s/%s is the Opaque parts of a net.URL.
TargetUri: fmt.Sprintf("cs3:%s/%s", resourceID.GetStorageId(), resourceID.GetNodeId()),
TargetUri: fmt.Sprintf("cs3:%s/%s", resourceID.GetStorageId(), resourceID.GetOpaqueId()),
}

c, err = s.findByPath(ctx, refPath)
Expand All @@ -397,17 +399,20 @@ func (s *svc) createReference(ctx context.Context, resourceID *provider.Referenc
return status.NewOK(ctx)
}

func (s *svc) addGrant(ctx context.Context, id *provider.Reference, g *provider.Grantee, p *provider.ResourcePermissions) (*rpc.Status, error) {
func (s *svc) addGrant(ctx context.Context, id *provider.ResourceId, g *provider.Grantee, p *provider.ResourcePermissions) (*rpc.Status, error) {
ref := &provider.Reference{
ResourceId: id,
}

grantReq := &provider.AddGrantRequest{
Ref: id,
Ref: ref,
Grant: &provider.Grant{
Grantee: g,
Permissions: p,
},
}

c, err := s.find(ctx, id)
c, err := s.find(ctx, ref)
if err != nil {
if _, ok := err.(errtypes.IsNotFound); ok {
return status.NewNotFound(ctx, "storage provider not found"), nil
Expand All @@ -427,17 +432,19 @@ func (s *svc) addGrant(ctx context.Context, id *provider.Reference, g *provider.
return status.NewOK(ctx), nil
}

func (s *svc) updateGrant(ctx context.Context, id *provider.Reference, g *provider.Grantee, p *provider.ResourcePermissions) (*rpc.Status, error) {

func (s *svc) updateGrant(ctx context.Context, id *provider.ResourceId, g *provider.Grantee, p *provider.ResourcePermissions) (*rpc.Status, error) {
ref := &provider.Reference{
ResourceId: id,
}
grantReq := &provider.UpdateGrantRequest{
Ref: id,
Ref: ref,
Grant: &provider.Grant{
Grantee: g,
Permissions: p,
},
}

c, err := s.find(ctx, id)
c, err := s.find(ctx, ref)
if err != nil {
if _, ok := err.(errtypes.IsNotFound); ok {
return status.NewNotFound(ctx, "storage provider not found"), nil
Expand All @@ -457,17 +464,20 @@ func (s *svc) updateGrant(ctx context.Context, id *provider.Reference, g *provid
return status.NewOK(ctx), nil
}

func (s *svc) removeGrant(ctx context.Context, id *provider.Reference, g *provider.Grantee, p *provider.ResourcePermissions) (*rpc.Status, error) {
func (s *svc) removeGrant(ctx context.Context, id *provider.ResourceId, g *provider.Grantee, p *provider.ResourcePermissions) (*rpc.Status, error) {
ref := &provider.Reference{
ResourceId: id,
}

grantReq := &provider.RemoveGrantRequest{
Ref: id,
Ref: ref,
Grant: &provider.Grant{
Grantee: g,
Permissions: p,
},
}

c, err := s.find(ctx, id)
c, err := s.find(ctx, ref)
if err != nil {
if _, ok := err.(errtypes.IsNotFound); ok {
return status.NewNotFound(ctx, "storage provider not found"), nil
Expand Down
6 changes: 4 additions & 2 deletions internal/grpc/services/ocmcore/ocmcore.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,10 @@ func (s *service) CreateOCMCoreShare(ctx context.Context, req *ocmcore.CreateOCM
}

resource := &provider.Reference{
StorageId: parts[0],
NodeId: parts[1],
ResourceId: &provider.ResourceId{
StorageId: parts[0],
OpaqueId: parts[1],
},
}

var resourcePermissions *provider.ResourcePermissions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ func filterPermissions(l *provider.ResourcePermissions, r *provider.ResourcePerm
}

func (s *service) unwrap(ctx context.Context, ref *provider.Reference) (token string, relativePath string, err error) {
if ref.StorageId != "" || ref.NodeId != "" {
if ref.ResourceId.StorageId != "" || ref.ResourceId.OpaqueId != "" {
return "", "", errtypes.BadRequest("need absolute path ref: got " + ref.String())
}

Expand Down Expand Up @@ -694,7 +694,9 @@ func (s *service) resolveToken(ctx context.Context, token string) (string, *link
}

sRes, err := s.gateway.Stat(ctx, &provider.StatRequest{
Ref: publicShareResponse.GetShare().GetResourceId(),
Ref: &provider.Reference{
ResourceId: publicShareResponse.GetShare().GetResourceId(),
},
})
switch {
case err != nil:
Expand Down
8 changes: 5 additions & 3 deletions internal/http/services/owncloud/ocdav/ocdav.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func applyLayout(ctx context.Context, ns string, useLoggedInUserNS bool, request
}

func wrapResourceID(r *provider.Reference) string {
return wrap(r.StorageId, r.NodeId)
return wrap(r.ResourceId.StorageId, r.ResourceId.OpaqueId)
}

// The fileID must be encoded
Expand All @@ -234,8 +234,10 @@ func unwrap(rid string) *provider.Reference {
}

return &provider.Reference{
StorageId: parts[0],
NodeId: parts[1],
ResourceId: &provider.ResourceId{
StorageId: parts[0],
OpaqueId: parts[1],
},
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/http/services/owncloud/ocdav/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ func (s *svc) handlePutHelper(w http.ResponseWriter, r *http.Request, content io

w.Header().Add("Content-Type", newInfo.MimeType)
w.Header().Set("ETag", newInfo.Etag)
w.Header().Set("OC-FileId", wrapResourceID(newInfo.Id))
w.Header().Set("OC-FileId", wrapResourceID(&provider.Reference{ResourceId: newInfo.Id}))
w.Header().Set("OC-ETag", newInfo.Etag)
t := utils.TSToTime(newInfo.Mtime).UTC()
lastModifiedString := t.Format(time.RFC1123Z)
Expand Down
14 changes: 9 additions & 5 deletions internal/http/services/owncloud/ocdav/trashbin.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (h *TrashbinHandler) listTrashbin(w http.ResponseWriter, r *http.Request, s

// ask gateway for recycle items
// TODO(labkode): add Reference to ListRecycleRequest
getRecycleRes, err := gc.ListRecycle(ctx, &gateway.ListRecycleRequest{Ref: getHomeRes.Ref})
getRecycleRes, err := gc.ListRecycle(ctx, &gateway.ListRecycleRequest{Ref: &provider.Reference{Path: getHomeRes.Path}})

if err != nil {
sublog.Error().Err(err).Msg("error calling ListRecycle")
Expand Down Expand Up @@ -393,7 +393,9 @@ func (h *TrashbinHandler) restore(w http.ResponseWriter, r *http.Request, s *svc
// this means we can only undelete on the same storage, not to a different folder
// use the key which is prefixed with the StoragePath to lookup the correct storage ...
// TODO currently limited to the home storage
Ref: getHomeRes.Ref,
Ref: &provider.Reference{
Path: getHomeRes.Path,
},
Key: key,
RestoreRef: &provider.Reference{Path: dst},
}
Expand Down Expand Up @@ -437,7 +439,7 @@ func (h *TrashbinHandler) delete(w http.ResponseWriter, r *http.Request, s *svc,
HandleErrorStatus(&sublog, w, getHomeRes.Status)
return
}
sRes, err := client.Stat(ctx, &provider.StatRequest{Ref: getHomeRes.Ref})
sRes, err := client.Stat(ctx, &provider.StatRequest{Ref: &provider.Reference{Path: getHomeRes.Path}})
if err != nil {
sublog.Error().Err(err).Msg("error calling Stat")
w.WriteHeader(http.StatusInternalServerError)
Expand All @@ -453,8 +455,10 @@ func (h *TrashbinHandler) delete(w http.ResponseWriter, r *http.Request, s *svc,

req := &gateway.PurgeRecycleRequest{
Ref: &provider.Reference{
NodeId: key,
StorageId: sRes.Info.Id.StorageId,
ResourceId: &provider.ResourceId{
StorageId: sRes.Info.Id.StorageId,
OpaqueId: key,
},
},
}

Expand Down
6 changes: 3 additions & 3 deletions internal/http/services/owncloud/ocdav/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ func (h *VersionsHandler) doListVersions(w http.ResponseWriter, r *http.Request,
// TODO(jfd) we cannot access version content, this will be a problem when trying to fetch version thumbnails
// Opaque
Type: provider.ResourceType_RESOURCE_TYPE_FILE,
Id: &provider.Reference{
StorageId: "versions", // this is a virtual storage
NodeId: info.Id.NodeId + "@" + versions[i].GetKey(),
Id: &provider.ResourceId{
StorageId: "versions",
OpaqueId: info.Id.OpaqueId + "@" + versions[i].GetKey(),
},
// Checksum
Etag: versions[i].Etag,
Expand Down
Loading

0 comments on commit c718c67

Please sign in to comment.