Skip to content

Commit

Permalink
Skip file check for OCM data transfers (cs3org#1636)
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 authored and fbx committed Apr 19, 2021
1 parent 4375300 commit dbff853
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 62 deletions.
3 changes: 3 additions & 0 deletions changelog/unreleased/ocm-file-downloads.md
@@ -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
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
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

0 comments on commit dbff853

Please sign in to comment.