Skip to content

Commit

Permalink
ResourceInfo.Ref -> ResourceInfo.Path
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
  • Loading branch information
butonic committed May 26, 2021
1 parent 6805f8f commit 7e777ec
Show file tree
Hide file tree
Showing 26 changed files with 91 additions and 91 deletions.
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1036,8 +1036,8 @@ github.com/prometheus/statsd_exporter v0.20.0 h1:M0hQphnq2WyWKS5CefQL8PqWwBOBPhi
github.com/prometheus/statsd_exporter v0.20.0/go.mod h1:YL3FWCG8JBBtaUSxAg4Gz2ZYu22bS84XM89ZQXXTWmQ=
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/refs/go-cs3apis v0.0.0-20210520134557-97cdc479815b h1:EQM9QE2M63TQNy4p/iqQqZAsFjTO8SDBy9ZHWpqqu4w=
github.com/refs/go-cs3apis v0.0.0-20210520134557-97cdc479815b/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/refs/go-cs3apis v0.0.0-20210526140949-6696966c6248 h1:3mTgRQy5TjZ0tEV0n2ESGaSQIgrfbrHO/Ikg9iM7Ol8=
github.com/refs/go-cs3apis v0.0.0-20210526140949-6696966c6248/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/remyoudompheng/bigfft v0.0.0-20190728182440-6a916e37a237/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/rhnvrm/simples3 v0.5.0/go.mod h1:Y+3vYm2V7Y4VijFoJHHTrja6OgPrJ2cBti8dPGkC3sA=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
Expand Down
6 changes: 3 additions & 3 deletions internal/grpc/interceptors/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,9 @@ func dismantleToken(ctx context.Context, tkn string, req interface{}, mgr token.
return nil, err
}

if ref.StorageId == statResponse.Info.Ref.StorageId &&
ref.NodeId == statResponse.Info.Ref.NodeId &&
strings.HasPrefix(ref.GetPath(), statResponse.Info.Ref.Path) {
if ref.StorageId == statResponse.Info.Path.StorageId &&
ref.NodeId == statResponse.Info.Path.NodeId &&
strings.HasPrefix(ref.GetPath(), statResponse.Info.Path.Path) {
// The path corresponds to the resource to which the token has access.
// We allow access to it.
return u, nil
Expand Down
86 changes: 43 additions & 43 deletions internal/grpc/services/gateway/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ func (s *svc) InitiateFileDownload(ctx context.Context, req *provider.InitiateFi
// 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 = ri.Ref
log.Debug().Str("storage", ri.Ref.StorageId).Str("node", ri.Ref.NodeId).Str("path", ri.Ref.Path).Msg("download")
req.Ref = ri.Path
log.Debug().Str("storage", ri.Path.StorageId).Str("node", ri.Path.NodeId).Str("path", ri.Path.Path).Msg("download")
return s.initiateFileDownload(ctx, req)
}

Expand Down Expand Up @@ -344,7 +344,7 @@ func (s *svc) InitiateFileDownload(ctx context.Context, req *provider.InitiateFi
}

// append child to target
req.Ref.Path = path.Join(ri.Ref.Path, shareChild)
req.Ref.Path = path.Join(ri.Path.Path, shareChild)
log.Debug().Str("storage", req.Ref.StorageId).Str("node", req.Ref.NodeId).Str("path", req.Ref.Path).Msg("download")
return s.initiateFileDownload(ctx, req)
}
Expand Down Expand Up @@ -481,7 +481,7 @@ func (s *svc) InitiateFileUpload(ctx context.Context, req *provider.InitiateFile
// 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 = ri.Ref
req.Ref = ri.Path
log.Debug().Str("storage", req.Ref.StorageId).Str("node", req.Ref.NodeId).Str("path", req.Ref.Path).Msg("upload")
return s.initiateFileUpload(ctx, req)
}
Expand Down Expand Up @@ -541,7 +541,7 @@ func (s *svc) InitiateFileUpload(ctx context.Context, req *provider.InitiateFile
}

// append child to target
req.Ref.Path = path.Join(ri.Ref.Path, shareChild)
req.Ref.Path = path.Join(ri.Path.Path, shareChild)
return s.initiateFileUpload(ctx, req)
}

Expand Down Expand Up @@ -622,7 +622,7 @@ func (s *svc) GetPath(ctx context.Context, req *provider.GetPathRequest) (*provi

return &provider.GetPathResponse{
Status: statRes.Status,
Ref: statRes.GetInfo().GetRef(),
Ref: statRes.GetInfo().GetPath(),
}, nil
}

Expand Down Expand Up @@ -687,7 +687,7 @@ func (s *svc) CreateContainer(ctx context.Context, req *provider.CreateContainer
}

// append child to target
req.Ref.Path = path.Join(ri.Ref.Path, shareChild)
req.Ref.Path = path.Join(ri.Path.Path, shareChild)
return s.createContainer(ctx, req)
}

Expand Down Expand Up @@ -789,7 +789,7 @@ func (s *svc) Delete(ctx context.Context, req *provider.DeleteRequest) (*provide
}

// append child to target
req.Ref.Path = path.Join(ri.Ref.Path, shareChild)
req.Ref.Path = path.Join(ri.Path.Path, shareChild)
return s.delete(ctx, req)
}

Expand Down Expand Up @@ -887,14 +887,14 @@ func (s *svc) Move(ctx context.Context, req *provider.MoveRequest) (*provider.Mo
}

src := &provider.Reference{
StorageId: ri.Ref.StorageId,
NodeId: ri.Ref.NodeId,
Path: path.Join(ri.Ref.Path, shareChild),
StorageId: ri.Path.StorageId,
NodeId: ri.Path.NodeId,
Path: path.Join(ri.Path.Path, shareChild),
}
dst := &provider.Reference{
StorageId: ri.Ref.StorageId,
NodeId: ri.Ref.NodeId,
Path: path.Join(ri.Ref.Path, dshareChild),
StorageId: ri.Path.StorageId,
NodeId: ri.Path.NodeId,
Path: path.Join(ri.Path.Path, dshareChild),
}

req.Source = src
Expand Down Expand Up @@ -1007,7 +1007,7 @@ func (s *svc) statHome(ctx context.Context) (*provider.StatResponse, error) {
}, nil
}

if etagIface, err := s.etagCache.Get(statRes.Info.Owner.OpaqueId + ":" + statRes.Info.Ref.Path); err == nil { // FIXME @butonic REFERENCE also use node fo etag cache?
if etagIface, err := s.etagCache.Get(statRes.Info.Owner.OpaqueId + ":" + statRes.Info.Path.Path); err == nil { // FIXME @butonic REFERENCE also use node fo etag cache?
resMtime := utils.TSToTime(statRes.Info.Mtime)
resEtag := etagIface.(etagWithTS)
// Use the updated etag if the home folder has been modified
Expand All @@ -1017,7 +1017,7 @@ func (s *svc) statHome(ctx context.Context) (*provider.StatResponse, error) {
} else {
statRes.Info.Etag = etag.GenerateEtagFromResources(statRes.Info, []*provider.ResourceInfo{statSharedFolder.Info})
if s.c.EtagCacheTTL > 0 {
_ = s.etagCache.Set(statRes.Info.Owner.OpaqueId+":"+statRes.Info.Ref.Path, etagWithTS{statRes.Info.Etag, time.Now()}) // FIXME @butonic REFERENCE also use node fo etag cache?
_ = s.etagCache.Set(statRes.Info.Owner.OpaqueId+":"+statRes.Info.Path.Path, etagWithTS{statRes.Info.Etag, time.Now()}) // FIXME @butonic REFERENCE also use node fo etag cache?
}
}

Expand Down Expand Up @@ -1050,7 +1050,7 @@ func (s *svc) statSharesFolder(ctx context.Context) (*provider.StatResponse, err
}, nil
}

if etagIface, err := s.etagCache.Get(statRes.Info.Owner.OpaqueId + ":" + statRes.Info.Ref.Path); err == nil { // FIXME @butonic REFERENCE also use node fo etag cache?
if etagIface, err := s.etagCache.Get(statRes.Info.Owner.OpaqueId + ":" + statRes.Info.Path.Path); err == nil { // FIXME @butonic REFERENCE also use node fo etag cache?
resMtime := utils.TSToTime(statRes.Info.Mtime)
resEtag := etagIface.(etagWithTS)
// Use the updated etag if the shares folder has been modified, i.e., a new
Expand All @@ -1061,7 +1061,7 @@ func (s *svc) statSharesFolder(ctx context.Context) (*provider.StatResponse, err
} else {
statRes.Info.Etag = etag.GenerateEtagFromResources(statRes.Info, lsRes.Infos)
if s.c.EtagCacheTTL > 0 {
_ = s.etagCache.Set(statRes.Info.Owner.OpaqueId+":"+statRes.Info.Ref.Path, etagWithTS{statRes.Info.Etag, time.Now()}) // FIXME @butonic REFERENCE also use node fo etag cache?
_ = s.etagCache.Set(statRes.Info.Owner.OpaqueId+":"+statRes.Info.Path.Path, etagWithTS{statRes.Info.Etag, time.Now()}) // FIXME @butonic REFERENCE also use node fo etag cache?
}
}
return statRes, nil
Expand Down Expand Up @@ -1121,7 +1121,7 @@ func (s *svc) stat(ctx context.Context, req *provider.StatRequest) (*provider.St
NodeId: uuid.New().String(),
},
Type: provider.ResourceType_RESOURCE_TYPE_CONTAINER,
Ref: &provider.Reference{Path: resPath}, // TODO this is an absolute path ... we should only return the name
Path: &provider.Reference{Path: resPath}, // TODO this is an absolute path ... we should only return the name
Size: totalSize,
},
}, nil
Expand All @@ -1147,7 +1147,7 @@ func (s *svc) statOnProvider(ctx context.Context, req *provider.StatRequest, res
}
if res == nil {
res = &provider.ResourceInfo{
Ref: &provider.Reference{},
Path: &provider.Reference{},
}
}
*res = *r.Info
Expand Down Expand Up @@ -1208,9 +1208,9 @@ func (s *svc) Stat(ctx context.Context, req *provider.StatRequest) (*provider.St
// information. For example, if requests comes to: /home/MyShares/photos and photos
// is reference to /user/peter/Holidays/photos, we need to still return to the user
// /home/MyShares/photos
orgPath := statRes.Info.Ref.Path
orgPath := statRes.Info.Path.Path
statRes.Info = ri
statRes.Info.Ref.Path = orgPath
statRes.Info.Path.Path = orgPath
return statRes, nil

}
Expand Down Expand Up @@ -1246,15 +1246,15 @@ func (s *svc) Stat(ctx context.Context, req *provider.StatRequest) (*provider.St
Status: status.NewInternal(ctx, err, "gateway: error resolving webdav reference: "+p),
}, nil
}
ri.Ref.Path = p
ri.Path.Path = p
return &provider.StatResponse{
Status: status.NewOK(ctx),
Info: ri,
}, nil
}

// append child to target
req.Ref.Path = path.Join(ri.Ref.Path, shareChild)
req.Ref.Path = path.Join(ri.Path.Path, shareChild)
res, err := s.stat(ctx, req)
if err != nil {
return &provider.StatResponse{
Expand All @@ -1269,7 +1269,7 @@ func (s *svc) Stat(ctx context.Context, req *provider.StatRequest) (*provider.St

// we need to make sure we don't expose the reference target in the resource
// information.
res.Info.Ref.Path = p
res.Info.Path.Path = p
return res, nil
}

Expand Down Expand Up @@ -1370,7 +1370,7 @@ func (s *svc) listHome(ctx context.Context, req *provider.ListContainerRequest)
}

for i := range lcr.Infos {
if s.isSharedFolder(ctx, lcr.Infos[i].Ref.Path) {
if s.isSharedFolder(ctx, lcr.Infos[i].Path.Path) {
statSharedFolder, err := s.statSharesFolder(ctx)
if err != nil {
return &provider.ListContainerResponse{
Expand Down Expand Up @@ -1422,7 +1422,7 @@ func (s *svc) listSharesFolder(ctx context.Context) (*provider.ListContainerResp
}
}

info.Ref = lcr.Infos[i].Ref
info.Path = lcr.Infos[i].Path
checkedInfos = append(checkedInfos, info)
}
lcr.Infos = checkedInfos
Expand Down Expand Up @@ -1458,8 +1458,8 @@ func (s *svc) listContainer(ctx context.Context, req *provider.ListContainerRequ
}, nil
}
for _, inf := range infoFromProviders[i] {
if parent := path.Dir(inf.Ref.Path); resPath != "" && resPath != parent {
parts := strings.Split(strings.TrimPrefix(inf.Ref.Path, resPath), "/")
if parent := path.Dir(inf.Path.Path); resPath != "" && resPath != parent {
parts := strings.Split(strings.TrimPrefix(inf.Path.Path, resPath), "/")
p := path.Join(resPath, parts[1])
indirects[p] = append(indirects[p], inf)
} else {
Expand All @@ -1476,7 +1476,7 @@ func (s *svc) listContainer(ctx context.Context, req *provider.ListContainerRequ
},
Type: provider.ResourceType_RESOURCE_TYPE_CONTAINER,
Etag: etag.GenerateEtagFromResources(nil, v),
Ref: &provider.Reference{Path: k},
Path: &provider.Reference{Path: k},
Size: 0,
}
infos = append(infos, inf)
Expand Down Expand Up @@ -1562,8 +1562,8 @@ func (s *svc) ListContainer(ctx context.Context, req *provider.ListContainerRequ
}

for _, info := range infos {
base := path.Base(info.Ref.Path)
info.Ref.Path = path.Join(p, base)
base := path.Base(info.Path.Path)
info.Path.Path = path.Join(p, base)
}
return &provider.ListContainerResponse{
Status: status.NewOK(ctx),
Expand All @@ -1572,15 +1572,15 @@ func (s *svc) ListContainer(ctx context.Context, req *provider.ListContainerRequ
}

if ri.Type != provider.ResourceType_RESOURCE_TYPE_CONTAINER {
err := errtypes.NotSupported("gateway: list container: cannot list non-container type:" + ri.Ref.Path)
err := errtypes.NotSupported("gateway: list container: cannot list non-container type:" + ri.Path.Path)
log.Err(err).Msg("gateway: error listing")
return &provider.ListContainerResponse{
Status: status.NewInvalidArg(ctx, "resource is not a container"),
}, nil
}

newReq := &provider.ListContainerRequest{
Ref: &provider.Reference{Path: ri.Ref.Path},
Ref: &provider.Reference{Path: ri.Path.Path},
ArbitraryMetadataKeys: req.ArbitraryMetadataKeys,
}
newRes, err := s.listContainer(ctx, newReq)
Expand All @@ -1598,8 +1598,8 @@ func (s *svc) ListContainer(ctx context.Context, req *provider.ListContainerRequ

// paths needs to be converted
for _, info := range newRes.Infos {
base := path.Base(info.Ref.Path)
info.Ref.Path = path.Join(p, base)
base := path.Base(info.Path.Path)
info.Path.Path = path.Join(p, base)
}

return newRes, nil
Expand Down Expand Up @@ -1639,8 +1639,8 @@ func (s *svc) ListContainer(ctx context.Context, req *provider.ListContainerRequ
}

for _, info := range infos {
base := path.Base(info.Ref.Path)
info.Ref.Path = path.Join(shareName, shareChild, base)
base := path.Base(info.Path.Path)
info.Path.Path = path.Join(shareName, shareChild, base)
}
return &provider.ListContainerResponse{
Status: status.NewOK(ctx),
Expand All @@ -1649,15 +1649,15 @@ func (s *svc) ListContainer(ctx context.Context, req *provider.ListContainerRequ
}

if ri.Type != provider.ResourceType_RESOURCE_TYPE_CONTAINER {
err := errtypes.NotSupported("gateway: list container: cannot list non-container type:" + ri.Ref.Path)
err := errtypes.NotSupported("gateway: list container: cannot list non-container type:" + ri.Path.Path)
log.Err(err).Msg("gateway: error listing")
return &provider.ListContainerResponse{
Status: status.NewInvalidArg(ctx, "resource is not a container"),
}, nil
}

newReq := &provider.ListContainerRequest{
Ref: &provider.Reference{Path: path.Join(ri.Ref.Path, shareChild)},
Ref: &provider.Reference{Path: path.Join(ri.Path.Path, shareChild)},
ArbitraryMetadataKeys: req.ArbitraryMetadataKeys,
}
newRes, err := s.listContainer(ctx, newReq)
Expand All @@ -1675,8 +1675,8 @@ func (s *svc) ListContainer(ctx context.Context, req *provider.ListContainerRequ

// paths needs to be converted
for _, info := range newRes.Infos {
base := path.Base(info.Ref.Path)
info.Ref.Path = path.Join(shareName, shareChild, base)
base := path.Base(info.Path.Path)
info.Path.Path = path.Join(shareName, shareChild, base)
}

return newRes, nil
Expand All @@ -1695,7 +1695,7 @@ func (s *svc) getPath(ctx context.Context, ref *provider.Reference, keys ...stri
return "", res.Status
}

return res.Info.Ref.Path, res.Status
return res.Info.Path.Path, res.Status
}

if ref.Path != "" {
Expand Down
2 changes: 1 addition & 1 deletion internal/grpc/services/gateway/usershareprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ 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.Ref.Path))
refPath := path.Join(homeRes.Ref.Path, s.c.ShareFolder, path.Base(statRes.Info.Path.Path))
log.Info().Msg("mount path will be:" + refPath)

createRefReq := &provider.CreateReferenceRequest{
Expand Down
2 changes: 1 addition & 1 deletion internal/grpc/services/gateway/webdavstorageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func (s *svc) getWebdavEndpoint(ctx context.Context, domain string) (string, err
func normalize(info *gowebdav.File) *provider.ResourceInfo {
return &provider.ResourceInfo{
// TODO(ishank011): Add Id, PermissionSet, Owner
Ref: &provider.Reference{Path: info.Path()},
Path: &provider.Reference{Path: info.Path()},
Type: getResourceType(info.IsDir()),
Etag: info.ETag(),
MimeType: info.ContentType(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (s *service) ListPublicShares(ctx context.Context, req *link.ListPublicShar
log.Info().Str("publicshareprovider", "list").Msg("list public share")
user, _ := user.ContextGetUser(ctx)

shares, err := s.sm.ListPublicShares(ctx, user, req.Filters, &provider.ResourceInfo{Ref: &provider.Reference{}}, req.GetSign())
shares, err := s.sm.ListPublicShares(ctx, user, req.Filters, &provider.ResourceInfo{Path: &provider.Reference{}}, req.GetSign())
if err != nil {
log.Err(err).Msg("error listing shares")
return &link.ListPublicSharesResponse{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ func (s *service) Stat(ctx context.Context, req *provider.StatRequest) (*provide
if err := addShare(statResponse.Info, ls); err != nil {
appctx.GetLogger(ctx).Error().Err(err).Interface("share", ls).Interface("info", statResponse.Info).Msg("error when adding share")
}
statResponse.Info.Ref.Path = path.Join(s.mountPath, "/", tkn, relativePath)
statResponse.Info.Path.Path = path.Join(s.mountPath, "/", tkn, relativePath)
filterPermissions(statResponse.Info.PermissionSet, ls.GetPermissions().Permissions)
}

Expand Down Expand Up @@ -542,7 +542,7 @@ func (s *service) ListContainer(ctx context.Context, req *provider.ListContainer

for i := range listContainerR.Infos {
filterPermissions(listContainerR.Infos[i].PermissionSet, ls.GetPermissions().Permissions)
listContainerR.Infos[i].Ref.Path = path.Join(s.mountPath, "/", tkn, relativePath, path.Base(listContainerR.Infos[i].Ref.Path))
listContainerR.Infos[i].Path.Path = path.Join(s.mountPath, "/", tkn, relativePath, path.Base(listContainerR.Infos[i].Path.Path))
if err := addShare(listContainerR.Infos[i], ls); err != nil {
appctx.GetLogger(ctx).Error().Err(err).Interface("share", ls).Interface("info", listContainerR.Infos[i]).Msg("error when adding share")
}
Expand Down
2 changes: 1 addition & 1 deletion internal/grpc/services/storageprovider/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,6 @@ func (s *service) wrap(ctx context.Context, ri *provider.ResourceInfo) error {
// For wrapper drivers, the storage ID might already be set. In that case, skip setting it
ri.Id.StorageId = s.mountID
}
ri.Ref.Path = path.Join(s.mountPath, ri.Ref.Path) // FIXME @butonic REFERENCE nooooo the provider should not know where it is mounted
ri.Path.Path = path.Join(s.mountPath, ri.Path.Path) // FIXME @butonic REFERENCE nooooo the provider should not know where it is mounted
return nil
}
Loading

0 comments on commit 7e777ec

Please sign in to comment.