Skip to content

Commit

Permalink
continue update
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 Jun 15, 2021
1 parent 9aa86a2 commit 4873399
Show file tree
Hide file tree
Showing 28 changed files with 140 additions and 133 deletions.
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ github.com/bmatcuk/doublestar/v2 v2.0.3/go.mod h1:QMmcs3H2AUQICWhfzLXz+IYln8lRQm
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40 h1:y4B3+GPxKlrigF1ha5FFErxK+sr6sWxQovRMzwMhejo=
github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c=
github.com/butonic/go-cs3apis v0.0.0-20210608111428-0b2c079174c9 h1:q2UFrmiIZwdFOislnGjUWlyqIpttjBRIB6K3QOUmZkY=
github.com/butonic/go-cs3apis v0.0.0-20210608111428-0b2c079174c9/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/c-bata/go-prompt v0.2.5 h1:3zg6PecEywxNn0xiqcXHD96fkbxghD+gdB2tbsYfl+Y=
github.com/c-bata/go-prompt v0.2.5/go.mod h1:vFnjEGDIIA/Lib7giyE4E9c50Lvl8j0S+7FVlAwDAVw=
github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
Expand Down Expand Up @@ -153,6 +151,8 @@ github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7Do
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e h1:tqSPWQeueWTKnJVMJffz4pz0o1WuQxJ28+5x5JgaHD8=
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4=
github.com/cs3org/go-cs3apis v0.0.0-20210614143420-5ee2eb1e7887 h1:X5Se3M/kbh9w6LZQvyLS7djAGKcWGzmaY6IOa7Talpk=
github.com/cs3org/go-cs3apis v0.0.0-20210614143420-5ee2eb1e7887/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/cucumber/godog v0.8.1/go.mod h1:vSh3r/lM+psC1BPXvdkSEuNjmXfpVqrMGYAElF6hxnA=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down
6 changes: 2 additions & 4 deletions internal/grpc/services/gateway/ocmshareprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ 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 {
rid := &provider.Reference{ResourceId: req.ResourceId}
addGrantStatus, err := s.addGrant(ctx, rid, req.Grant.Grantee, req.Grant.Permissions.Permissions)
addGrantStatus, err := s.addGrant(ctx, req.ResourceId, 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 @@ -110,8 +109,7 @@ 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 {
rid := &provider.Reference{ResourceId: share.ResourceId}
removeGrantStatus, err := s.removeGrant(ctx, rid, share.Grantee, share.Permissions.Permissions)
removeGrantStatus, err := s.removeGrant(ctx, share.ResourceId, share.Grantee, share.Permissions.Permissions)
if err != nil {
return nil, errors.Wrap(err, "gateway: error removing OCM grant from storage")
}
Expand Down
56 changes: 36 additions & 20 deletions internal/grpc/services/gateway/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,16 @@ func (s *svc) ListStorageSpaces(ctx context.Context, req *provider.ListStorageSp
id = f.GetId()
}
}
c, err := s.find(ctx, &provider.Reference{
StorageId: id.OpaqueId, // FIXME REFERENCE the StorageSpaceId is a storageid + a nodeid
})
parts := strings.SplitN(id.OpaqueId, "!", 2)
if len(parts) != 2 {
return &provider.ListStorageSpacesResponse{
Status: status.NewInvalidArg(ctx, "space id must be separated by !"),
}, nil
}
c, err := s.find(ctx, &provider.Reference{ResourceId: &provider.ResourceId{
StorageId: parts[0], // FIXME REFERENCE the StorageSpaceId is a storageid + a opaqueid
OpaqueId: parts[1],
}})
if err != nil {
return &provider.ListStorageSpacesResponse{
Status: status.NewStatusFromErrType(ctx, "error finding path", err),
Expand All @@ -144,7 +151,7 @@ func (s *svc) ListStorageSpaces(ctx context.Context, req *provider.ListStorageSp
func (s *svc) UpdateStorageSpace(ctx context.Context, req *provider.UpdateStorageSpaceRequest) (*provider.UpdateStorageSpaceResponse, error) {
log := appctx.GetLogger(ctx)
// TODO: needs to be fixed
c, err := s.find(ctx, req.StorageSpace.Root)
c, err := s.find(ctx, &provider.Reference{ResourceId: req.StorageSpace.Root})
if err != nil {
return &provider.UpdateStorageSpaceResponse{
Status: status.NewStatusFromErrType(ctx, "error finding ID", err),
Expand All @@ -164,9 +171,16 @@ func (s *svc) UpdateStorageSpace(ctx context.Context, req *provider.UpdateStorag
func (s *svc) DeleteStorageSpace(ctx context.Context, req *provider.DeleteStorageSpaceRequest) (*provider.DeleteStorageSpaceResponse, error) {
log := appctx.GetLogger(ctx)
// TODO: needs to be fixed
c, err := s.find(ctx, &provider.Reference{
StorageId: req.Id.OpaqueId, // FIXME REFERENCE the StorageSpaceId is a storageid + a nodeid
})
parts := strings.SplitN(req.Id.OpaqueId, "!", 2)
if len(parts) != 2 {
return &provider.DeleteStorageSpaceResponse{
Status: status.NewInvalidArg(ctx, "space id must be separated by !"),
}, nil
}
c, err := s.find(ctx, &provider.Reference{ResourceId: &provider.ResourceId{
StorageId: parts[0], // FIXME REFERENCE the StorageSpaceId is a storageid + a opaqueid
OpaqueId: parts[1],
}})
if err != nil {
return &provider.DeleteStorageSpaceResponse{
Status: status.NewStatusFromErrType(ctx, "error finding path", err),
Expand All @@ -185,7 +199,7 @@ func (s *svc) DeleteStorageSpace(ctx context.Context, req *provider.DeleteStorag

func (s *svc) GetHome(ctx context.Context, _ *provider.GetHomeRequest) (*provider.GetHomeResponse, error) {
home := s.getHome(ctx)
homeRes := &provider.GetHomeResponse{Ref: &provider.Reference{Path: home}, Status: status.NewOK(ctx)}
homeRes := &provider.GetHomeResponse{Path: home, Status: status.NewOK(ctx)}
return homeRes, nil
}

Expand Down Expand Up @@ -283,7 +297,7 @@ func (s *svc) InitiateFileDownload(ctx context.Context, req *provider.InitiateFi
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.Path = ri.Path
log.Debug().Str("storage", ri.Id.StorageId).Str("node", ri.Id.NodeId).Str("path", req.Ref.Path).Msg("download")
log.Debug().Str("path", ri.Path).Msg("download")
return s.initiateFileDownload(ctx, req)
}

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

// append child to target
req.Ref.Path = path.Join(ri.Path, shareChild)
log.Debug().Str("storage", ri.Id.StorageId).Str("node", ri.Id.NodeId).Str("path", req.Ref.Path).Msg("download")
log.Debug().Str("path", req.Ref.Path).Msg("download")
return s.initiateFileDownload(ctx, req)
}

Expand Down Expand Up @@ -482,7 +496,7 @@ func (s *svc) InitiateFileUpload(ctx context.Context, req *provider.InitiateFile
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.Path = ri.Path
log.Debug().Str("storage", req.Ref.StorageId).Str("node", req.Ref.NodeId).Str("path", req.Ref.Path).Msg("upload")
log.Debug().Str("path", ri.Path).Msg("upload")
return s.initiateFileUpload(ctx, req)
}

Expand Down Expand Up @@ -607,7 +621,7 @@ func (s *svc) initiateFileUpload(ctx context.Context, req *provider.InitiateFile
}

func (s *svc) GetPath(ctx context.Context, req *provider.GetPathRequest) (*provider.GetPathResponse, error) {
statReq := &provider.StatRequest{Ref: req.ResourceId}
statReq := &provider.StatRequest{Ref: &provider.Reference{ResourceId: req.ResourceId}}
statRes, err := s.stat(ctx, statReq)
if err != nil {
err = errors.Wrap(err, "gateway: error stating ref:"+statReq.Ref.String())
Expand Down Expand Up @@ -1108,9 +1122,9 @@ func (s *svc) stat(ctx context.Context, req *provider.StatRequest) (*provider.St
return &provider.StatResponse{
Status: status.NewOK(ctx),
Info: &provider.ResourceInfo{
Id: &provider.Reference{
Id: &provider.ResourceId{
StorageId: "/",
NodeId: uuid.New().String(),
OpaqueId: uuid.New().String(),
},
Type: provider.ResourceType_RESOURCE_TYPE_CONTAINER,
Path: resPath,
Expand Down Expand Up @@ -1307,8 +1321,10 @@ func (s *svc) handleCS3Ref(ctx context.Context, opaque string) (*provider.Resour

req := &provider.StatRequest{
Ref: &provider.Reference{
StorageId: parts[0],
NodeId: parts[1],
ResourceId: &provider.ResourceId{
StorageId: parts[0],
OpaqueId: parts[1],
},
},
}
res, err := s.stat(ctx, req)
Expand Down Expand Up @@ -1460,9 +1476,9 @@ func (s *svc) listContainer(ctx context.Context, req *provider.ListContainerRequ

for k, v := range indirects {
inf := &provider.ResourceInfo{
Id: &provider.Reference{
Id: &provider.ResourceId{
StorageId: "/",
NodeId: uuid.New().String(),
OpaqueId: uuid.New().String(),
},
Type: provider.ResourceType_RESOURCE_TYPE_CONTAINER,
Etag: etag.GenerateEtagFromResources(nil, v),
Expand Down Expand Up @@ -1679,7 +1695,7 @@ func (s *svc) ListContainer(ctx context.Context, req *provider.ListContainerRequ
func (s *svc) getPath(ctx context.Context, ref *provider.Reference, keys ...string) (string, *rpc.Status) {

// check if it is an id based or combined reference first
if ref.StorageId != "" && ref.NodeId != "" {
if ref.ResourceId != nil {
req := &provider.StatRequest{Ref: ref, ArbitraryMetadataKeys: keys}
res, err := s.stat(ctx, req)
if (res != nil && res.Status.Code != rpc.Code_CODE_OK) || err != nil {
Expand All @@ -1689,7 +1705,7 @@ func (s *svc) getPath(ctx context.Context, ref *provider.Reference, keys ...stri
return res.Info.Path, res.Status
}

if ref.StorageId == "" && ref.NodeId == "" && ref.Path != "" {
if ref.Path != "" {
return ref.Path, &rpc.Status{Code: rpc.Code_CODE_OK}
}
return "", &rpc.Status{Code: rpc.Code_CODE_INTERNAL}
Expand Down
8 changes: 3 additions & 5 deletions internal/grpc/services/ocmcore/ocmcore.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,9 @@ func (s *service) CreateOCMCoreShare(ctx context.Context, req *ocmcore.CreateOCM
}, nil
}

resource := &provider.Reference{
ResourceId: &provider.ResourceId{
StorageId: parts[0],
OpaqueId: parts[1],
},
resource := &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.ResourceId.StorageId != "" || ref.ResourceId.OpaqueId != "" {
if ref.ResourceId != nil {
return "", "", errtypes.BadRequest("need absolute path ref: got " + ref.String())
}

Expand Down
8 changes: 4 additions & 4 deletions internal/grpc/services/storageprovider/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ func (s *service) GetHome(ctx context.Context, req *provider.GetHomeRequest) (*p

res := &provider.GetHomeResponse{
Status: status.NewOK(ctx),
Ref: &provider.Reference{Path: home},
Path: home,
}

return res, nil
Expand Down Expand Up @@ -839,8 +839,8 @@ func (s *service) RestoreRecycleItem(ctx context.Context, req *provider.RestoreR

func (s *service) PurgeRecycle(ctx context.Context, req *provider.PurgeRecycleRequest) (*provider.PurgeRecycleResponse, error) {
// if a key was sent as opacque id purge only that item
if req.GetRef() != nil && req.GetRef().NodeId != "" {
if err := s.storage.PurgeRecycleItem(ctx, req.GetRef().NodeId); err != nil {
if req.GetRef() != nil && req.GetRef().GetResourceId().OpaqueId != "" {
if err := s.storage.PurgeRecycleItem(ctx, req.GetRef().GetResourceId().OpaqueId); err != nil {
var st *rpc.Status
switch err.(type) {
case errtypes.IsNotFound:
Expand Down Expand Up @@ -1095,7 +1095,7 @@ func getFS(c *config) (storage.FS, error) {
}

func (s *service) unwrap(ctx context.Context, ref *provider.Reference) (*provider.Reference, error) {
if ref.StorageId != "" {
if ref.GetResourceId() != nil {
return ref, nil
}

Expand Down
14 changes: 6 additions & 8 deletions internal/http/services/owncloud/ocdav/ocdav.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ func applyLayout(ctx context.Context, ns string, useLoggedInUserNS bool, request
return templates.WithUser(u, ns)
}

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

// The fileID must be encoded
Expand All @@ -218,7 +218,7 @@ func wrap(sid string, oid string) string {
return base64.URLEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", sid, oid)))
}

func unwrap(rid string) *provider.Reference {
func unwrap(rid string) *provider.ResourceId {
decodedID, err := base64.URLEncoding.DecodeString(rid)
if err != nil {
return nil
Expand All @@ -233,11 +233,9 @@ func unwrap(rid string) *provider.Reference {
return nil
}

return &provider.Reference{
ResourceId: &provider.ResourceId{
StorageId: parts[0],
OpaqueId: parts[1],
},
return &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(&provider.Reference{ResourceId: newInfo.Id}))
w.Header().Set("OC-FileId", wrapResourceID(newInfo.Id))
w.Header().Set("OC-ETag", newInfo.Etag)
t := utils.TSToTime(newInfo.Mtime).UTC()
lastModifiedString := t.Format(time.RFC1123Z)
Expand Down
17 changes: 7 additions & 10 deletions internal/http/services/owncloud/ocdav/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (h *VersionsHandler) init(c *Config) error {
// Handler handles requests
// versions can be listed with a PROPFIND to /remote.php/dav/meta/<fileid>/v
// a version is identified by a timestamp, eg. /remote.php/dav/meta/<fileid>/v/1561410426
func (h *VersionsHandler) Handler(s *svc, rid *provider.Reference) http.Handler {
func (h *VersionsHandler) Handler(s *svc, rid *provider.ResourceId) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()

Expand Down Expand Up @@ -78,7 +78,7 @@ func (h *VersionsHandler) Handler(s *svc, rid *provider.Reference) http.Handler
})
}

func (h *VersionsHandler) doListVersions(w http.ResponseWriter, r *http.Request, s *svc, rid *provider.Reference) {
func (h *VersionsHandler) doListVersions(w http.ResponseWriter, r *http.Request, s *svc, rid *provider.ResourceId) {
ctx := r.Context()
ctx, span := trace.StartSpan(ctx, "listVersions")
defer span.End()
Expand All @@ -99,8 +99,8 @@ func (h *VersionsHandler) doListVersions(w http.ResponseWriter, r *http.Request,
return
}

req := &provider.StatRequest{Ref: rid}
res, err := client.Stat(ctx, req)
ref := &provider.Reference{ResourceId: rid}
res, err := client.Stat(ctx, &provider.StatRequest{Ref: ref})
if err != nil {
sublog.Error().Err(err).Msg("error sending a grpc stat request")
w.WriteHeader(http.StatusInternalServerError)
Expand All @@ -113,10 +113,7 @@ func (h *VersionsHandler) doListVersions(w http.ResponseWriter, r *http.Request,

info := res.Info

lvReq := &provider.ListFileVersionsRequest{
Ref: rid,
}
lvRes, err := client.ListFileVersions(ctx, lvReq)
lvRes, err := client.ListFileVersions(ctx, &provider.ListFileVersionsRequest{Ref: ref})
if err != nil {
sublog.Error().Err(err).Msg("error sending list container grpc request")
w.WriteHeader(http.StatusInternalServerError)
Expand Down Expand Up @@ -175,7 +172,7 @@ func (h *VersionsHandler) doListVersions(w http.ResponseWriter, r *http.Request,

}

func (h *VersionsHandler) doRestore(w http.ResponseWriter, r *http.Request, s *svc, rid *provider.Reference, key string) {
func (h *VersionsHandler) doRestore(w http.ResponseWriter, r *http.Request, s *svc, rid *provider.ResourceId, key string) {
ctx := r.Context()
ctx, span := trace.StartSpan(ctx, "restore")
defer span.End()
Expand All @@ -190,7 +187,7 @@ func (h *VersionsHandler) doRestore(w http.ResponseWriter, r *http.Request, s *s
}

req := &provider.RestoreFileVersionRequest{
Ref: rid,
Ref: &provider.Reference{ResourceId: rid},
Key: key,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (h *Handler) listPublicShares(r *http.Request, filters []*link.ListPublicSh
}

for _, share := range res.GetShare() {
info, status, err := h.getResourceInfoByID(ctx, client, &provider.Reference{ResourceId: share.ResourceId})
info, status, err := h.getResourceInfoByID(ctx, client, share.ResourceId)
if err != nil || status.Code != rpc.Code_CODE_OK {
log.Debug().Interface("share", share).Interface("status", status).Err(err).Msg("could not stat share, skipping")
continue
Expand Down
Loading

0 comments on commit 4873399

Please sign in to comment.