Skip to content

Commit

Permalink
ocm: adapted handling of shares
Browse files Browse the repository at this point in the history
  • Loading branch information
glpatcern committed May 3, 2024
1 parent a7aab33 commit b0e1944
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
14 changes: 7 additions & 7 deletions internal/grpc/services/ocmshareprovider/ocmshareprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,13 @@ func getResourceType(info *providerpb.ResourceInfo) string {
return "unknown"
}

func (s *service) webdavURL(ctx context.Context, share *ocm.Share) string {
// the url is in the form of https://cernbox.cern.ch/remote.php/dav/ocm/token
p, _ := url.JoinPath(s.conf.WebDAVEndpoint, "/remote.php/dav/ocm", share.Token)
func (s *service) webdavURL(share *ocm.Share) string {
// the url is expected to be in the form https://ourserver/remote.php/dav/ocm/{ShareId}, see c.WebdavRoot in ocmprovider.go
p, _ := url.JoinPath(s.conf.WebDAVEndpoint, "/remote.php/dav/ocm", share.Id.OpaqueId)
return p
}

func (s *service) getWebdavProtocol(ctx context.Context, share *ocm.Share, m *ocm.AccessMethod_WebdavOptions) *ocmd.WebDAV {
func (s *service) getWebdavProtocol(share *ocm.Share, m *ocm.AccessMethod_WebdavOptions) *ocmd.WebDAV {
var perms []string
if m.WebdavOptions.Permissions.InitiateFileDownload {
perms = append(perms, "read")
Expand All @@ -195,7 +195,7 @@ func (s *service) getWebdavProtocol(ctx context.Context, share *ocm.Share, m *oc

return &ocmd.WebDAV{
Permissions: perms,
URL: s.webdavURL(ctx, share),
URL: s.webdavURL(share),
SharedSecret: share.Token,
}
}
Expand Down Expand Up @@ -233,7 +233,7 @@ func (s *service) getDataTransferProtocol(ctx context.Context, share *ocm.Share)
panic(err)
}
return &ocmd.Datatx{
SourceURI: s.webdavURL(ctx, share),
SourceURI: s.webdavURL(share),
Size: size,
}
}
Expand All @@ -248,7 +248,7 @@ func (s *service) getProtocols(ctx context.Context, share *ocm.Share) ocmd.Proto
for _, m := range share.AccessMethods {
switch t := m.Term.(type) {
case *ocm.AccessMethod_WebdavOptions:
p = append(p, s.getWebdavProtocol(ctx, share, t))
p = append(p, s.getWebdavProtocol(share, t))
case *ocm.AccessMethod_WebappOptions:
p = append(p, s.getWebappProtocol(share))
case *ocm.AccessMethod_TransferOptions:
Expand Down
4 changes: 2 additions & 2 deletions internal/http/services/owncloud/ocdav/propfind.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,8 @@ func (s *svc) mdToPropResponse(ctx context.Context, pf *propfindXML, md *provide
sublog := appctx.GetLogger(ctx).With().Str("ns", ns).Logger()
md.Path = strings.TrimPrefix(md.Path, ns)

// see internal/http/services/owncloud/ocdav/dav.go#L191-212:
// /<token>/ was injected in front of the path for the routing to work, we now remove it
// see internal/http/services/owncloud/ocdav/dav.go:
// /<token>/ was injected in front of the public-link or ocm path for the routing to work, we now remove it
_, md.Path = router.ShiftPath(md.Path)

baseURI := ctx.Value(ctxKeyBaseURI).(string)
Expand Down
2 changes: 1 addition & 1 deletion pkg/ocm/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (c *OCMClient) NewShare(ctx context.Context, endpoint string, r *NewShareRe
}

log := appctx.GetLogger(ctx)
log.Debug().Msgf("Sending OCM /shares POST to %s: %s", url, body)
log.Info().Str("url", url).Msgf("Sending OCM share: %s", body)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, body)
if err != nil {
return nil, errors.Wrap(err, "error creating request")
Expand Down
3 changes: 3 additions & 0 deletions pkg/ocm/storage/outcoming/ocm.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ func (d *driver) shareAndRelativePathFromRef(ctx context.Context, ref *provider.
}
path = makeRelative(path)

log := appctx.GetLogger(ctx)
log.Info().Interface("ref", ref).Str("path", path).Str("token", token).Msg("Accessing OCM share")

share, err := d.resolveToken(ctx, token)
if err != nil {
return nil, "", err
Expand Down
6 changes: 4 additions & 2 deletions pkg/ocm/storage/received/ocm.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
typepb "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
"github.com/cs3org/reva/internal/http/services/owncloud/ocdav"
"github.com/cs3org/reva/pkg/appctx"
"github.com/cs3org/reva/pkg/errtypes"
"github.com/cs3org/reva/pkg/mime"
"github.com/cs3org/reva/pkg/rgrpc/todo/pool"
Expand Down Expand Up @@ -153,11 +154,12 @@ func (d *driver) webdavClient(ctx context.Context, ref *provider.Reference) (*go
return nil, nil, "", err
}

// FIXME: it's still not clear from the OCM APIs how to use the shared secret
// will use as a token in the bearer authentication as this is the reva implementation
// use the secret as bearer authentication according to OCM v1.1+
c := gowebdav.NewClient(endpoint, "", "")
c.SetHeader("Authorization", "Bearer "+secret)

log := appctx.GetLogger(ctx)
log.Info().Str("endpoint", endpoint).Interface("share", share).Str("rel", rel).Str("secret", secret).Msg("Accessing OCM share")
return c, share, rel, nil
}

Expand Down

0 comments on commit b0e1944

Please sign in to comment.