Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip file check for OCM data transfers #1636

Merged
merged 1 commit into from
Apr 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/unreleased/ocm-file-downloads.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Bugfix: Skip file check for OCM data transfers

https://github.com/cs3org/reva/pull/1636
39 changes: 21 additions & 18 deletions internal/grpc/services/gateway/ocmshareprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,27 @@ func (s *svc) RemoveOCMShare(ctx context.Context, req *ocm.RemoveOCMShareRequest
}, nil
}

// if we need to commit the share, we need the resource it points to.
var share *ocm.Share
if s.c.CommitShareToStorageGrant {
getShareReq := &ocm.GetOCMShareRequest{
Ref: req.Ref,
}
getShareRes, err := c.GetOCMShare(ctx, getShareReq)
if err != nil {
return nil, errors.Wrap(err, "gateway: error calling GetShare")
}

if getShareRes.Status.Code != rpc.Code_CODE_OK {
res := &ocm.RemoveOCMShareResponse{
Status: status.NewInternal(ctx, status.NewErrorFromCode(getShareRes.Status.Code, "gateway"),
"error getting share when committing to the storage"),
}
return res, nil
}
share = getShareRes.Share
}

res, err := c.RemoveOCMShare(ctx, req)
if err != nil {
return nil, errors.Wrap(err, "gateway: error calling RemoveShare")
Expand All @@ -86,24 +107,6 @@ func (s *svc) RemoveOCMShare(ctx context.Context, req *ocm.RemoveOCMShareRequest
return res, nil
}

// if we need to commit the share, we need the resource it points to.
getShareReq := &ocm.GetOCMShareRequest{
Ref: req.Ref,
}
getShareRes, err := c.GetOCMShare(ctx, getShareReq)
if err != nil {
return nil, errors.Wrap(err, "gateway: error calling GetShare")
}

if getShareRes.Status.Code != rpc.Code_CODE_OK {
res := &ocm.RemoveOCMShareResponse{
Status: status.NewInternal(ctx, status.NewErrorFromCode(getShareRes.Status.Code, "gateway"),
"error getting share when committing to the storage"),
}
return res, nil
}
share := getShareRes.Share

// 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)
Expand Down
86 changes: 42 additions & 44 deletions internal/grpc/services/gateway/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,40 +258,39 @@ func (s *svc) InitiateFileDownload(ctx context.Context, req *provider.InitiateFi
}, nil
}

// if it is a file allow download
if ri.Type == provider.ResourceType_RESOURCE_TYPE_FILE {
log.Debug().Str("path", p).Interface("ri", ri).Msg("path points to share name file")

if protocol == "webdav" {
// TODO(ishank011): pass this through the datagateway service
// for now, we just expose the file server to the user
ep, opaque, err := s.webdavRefTransferEndpoint(ctx, statRes.Info.Target)
if err != nil {
return &gateway.InitiateFileDownloadResponse{
Status: status.NewInternal(ctx, err, "gateway: error downloading from webdav host: "+p),
}, nil
}
if protocol == "webdav" {
// TODO(ishank011): pass this through the datagateway service
// for now, we just expose the file server to the user
ep, opaque, err := s.webdavRefTransferEndpoint(ctx, statRes.Info.Target)
if err != nil {
return &gateway.InitiateFileDownloadResponse{
Status: status.NewOK(ctx),
Protocols: []*gateway.FileDownloadProtocol{
{
Opaque: opaque,
Protocol: "simple",
DownloadEndpoint: ep,
},
},
Status: status.NewInternal(ctx, err, "gateway: error downloading from webdav host: "+p),
}, nil
}
return &gateway.InitiateFileDownloadResponse{
Status: status.NewOK(ctx),
Protocols: []*gateway.FileDownloadProtocol{
{
Opaque: opaque,
Protocol: "simple",
DownloadEndpoint: ep,
},
},
}, nil
}

// if it is a file allow download
if ri.Type == provider.ResourceType_RESOURCE_TYPE_FILE {
log.Debug().Str("path", p).Interface("ri", ri).Msg("path points to share name file")
req.Ref = &provider.Reference{
Spec: &provider.Reference_Path{
Path: ri.Path,
},
}
log.Debug().Msg("download path: " + ri.Path)
return s.initiateFileDownload(ctx, req)

}

log.Debug().Str("path", p).Interface("statRes", statRes).Msg("path:%s points to share name")
err = errtypes.PermissionDenied("gateway: cannot download share name: path=" + p)
log.Err(err).Str("path", p).Msg("gateway: error downloading")
Expand Down Expand Up @@ -471,40 +470,39 @@ func (s *svc) InitiateFileUpload(ctx context.Context, req *provider.InitiateFile
}, nil
}

// if it is a file allow upload
if ri.Type == provider.ResourceType_RESOURCE_TYPE_FILE {
log.Debug().Str("path", p).Interface("ri", ri).Msg("path points to share name file")

if protocol == "webdav" {
// TODO(ishank011): pass this through the datagateway service
// for now, we just expose the file server to the user
ep, opaque, err := s.webdavRefTransferEndpoint(ctx, statRes.Info.Target)
if err != nil {
return &gateway.InitiateFileUploadResponse{
Status: status.NewInternal(ctx, err, "gateway: error downloading from webdav host: "+p),
}, nil
}
if protocol == "webdav" {
// TODO(ishank011): pass this through the datagateway service
// for now, we just expose the file server to the user
ep, opaque, err := s.webdavRefTransferEndpoint(ctx, statRes.Info.Target)
if err != nil {
return &gateway.InitiateFileUploadResponse{
Status: status.NewOK(ctx),
Protocols: []*gateway.FileUploadProtocol{
{
Opaque: opaque,
Protocol: "simple",
UploadEndpoint: ep,
},
},
Status: status.NewInternal(ctx, err, "gateway: error downloading from webdav host: "+p),
}, nil
}
return &gateway.InitiateFileUploadResponse{
Status: status.NewOK(ctx),
Protocols: []*gateway.FileUploadProtocol{
{
Opaque: opaque,
Protocol: "simple",
UploadEndpoint: ep,
},
},
}, nil
}

// if it is a file allow upload
if ri.Type == provider.ResourceType_RESOURCE_TYPE_FILE {
log.Debug().Str("path", p).Interface("ri", ri).Msg("path points to share name file")
req.Ref = &provider.Reference{
Spec: &provider.Reference_Path{
Path: ri.Path,
},
}
log.Debug().Msg("upload path: " + ri.Path)
return s.initiateFileUpload(ctx, req)

}

err = errtypes.PermissionDenied("gateway: cannot upload to share name: path=" + p)
log.Err(err).Msg("gateway: error uploading")
return &gateway.InitiateFileUploadResponse{
Expand Down