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

[WIP] New References #2081

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 2 additions & 0 deletions accounts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ replace (
github.com/owncloud/ocis/ocis-pkg => ../ocis-pkg
github.com/owncloud/ocis/settings => ../settings
github.com/owncloud/ocis/store => ../store
github.com/cs3org/go-cs3apis => github.com/refs/go-cs3apis v0.0.0-20210520134557-97cdc479815b
github.com/cs3org/reva => github.com/butonic/reva v0.0.0-20210526094447-9dfa8ec812ac
// taken from https://github.com/asim/go-micro/blob/master/plugins/registry/etcd/go.mod#L14-L16
go.etcd.io/etcd/api/v3 => go.etcd.io/etcd/api/v3 v3.0.0-20210204162551-dae29bb719dd
go.etcd.io/etcd/pkg/v3 => go.etcd.io/etcd/pkg/v3 v3.0.0-20210204162551-dae29bb719dd
Expand Down
27 changes: 9 additions & 18 deletions accounts/pkg/storage/cs3.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"encoding/json"
"github.com/cs3org/reva/pkg/auth/scope"
"io"
"io/ioutil"
"net/http"
Expand All @@ -13,6 +12,8 @@ import (
"strconv"
"strings"

"github.com/cs3org/reva/pkg/auth/scope"

user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
v1beta11 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
Expand Down Expand Up @@ -107,9 +108,7 @@ func (r CS3Repo) LoadAccounts(ctx context.Context, a *[]*proto.Account) (err err

ctx = metadata.AppendToOutgoingContext(ctx, token.TokenHeader, t)
res, err := r.storageProvider.ListContainer(ctx, &provider.ListContainerRequest{
Ref: &provider.Reference{
Spec: &provider.Reference_Path{Path: path.Join("/meta", accountsFolder)},
},
Ref: &provider.Reference{Path: path.Join("/meta", accountsFolder)},
})
if err != nil {
return err
Expand All @@ -118,7 +117,7 @@ func (r CS3Repo) LoadAccounts(ctx context.Context, a *[]*proto.Account) (err err
log := olog.NewLogger(olog.Pretty(r.cfg.Log.Pretty), olog.Color(r.cfg.Log.Color), olog.Level(r.cfg.Log.Level))
for i := range res.Infos {
acc := &proto.Account{}
err := r.loadAccount(filepath.Base(res.Infos[i].Path), t, acc)
err := r.loadAccount(filepath.Base(res.Infos[i].Ref.GetPath()), t, acc)
if err != nil {
log.Err(err).Msg("could not load account")
continue
Expand Down Expand Up @@ -158,9 +157,7 @@ func (r CS3Repo) DeleteAccount(ctx context.Context, id string) (err error) {
ctx = metadata.AppendToOutgoingContext(ctx, token.TokenHeader, t)

resp, err := r.storageProvider.Delete(ctx, &provider.DeleteRequest{
Ref: &provider.Reference{
Spec: &provider.Reference_Path{Path: path.Join("/meta", accountsFolder, id)},
},
Ref: &provider.Reference{Path: path.Join("/meta", accountsFolder, id)},
})

if err != nil {
Expand Down Expand Up @@ -221,9 +218,7 @@ func (r CS3Repo) LoadGroups(ctx context.Context, g *[]*proto.Group) (err error)

ctx = metadata.AppendToOutgoingContext(ctx, token.TokenHeader, t)
res, err := r.storageProvider.ListContainer(ctx, &provider.ListContainerRequest{
Ref: &provider.Reference{
Spec: &provider.Reference_Path{Path: path.Join("/meta", groupsFolder)},
},
Ref: &provider.Reference{Path: path.Join("/meta", groupsFolder)},
})
if err != nil {
return err
Expand All @@ -232,7 +227,7 @@ func (r CS3Repo) LoadGroups(ctx context.Context, g *[]*proto.Group) (err error)
log := olog.NewLogger(olog.Pretty(r.cfg.Log.Pretty), olog.Color(r.cfg.Log.Color), olog.Level(r.cfg.Log.Level))
for i := range res.Infos {
grp := &proto.Group{}
err := r.loadGroup(filepath.Base(res.Infos[i].Path), t, grp)
err := r.loadGroup(filepath.Base(res.Infos[i].Ref.GetPath()), t, grp)
if err != nil {
log.Err(err).Msg("could not load account")
continue
Expand Down Expand Up @@ -272,9 +267,7 @@ func (r CS3Repo) DeleteGroup(ctx context.Context, id string) (err error) {
ctx = metadata.AppendToOutgoingContext(ctx, token.TokenHeader, t)

resp, err := r.storageProvider.Delete(ctx, &provider.DeleteRequest{
Ref: &provider.Reference{
Spec: &provider.Reference_Path{Path: path.Join("/meta", groupsFolder, id)},
},
Ref: &provider.Reference{Path: path.Join("/meta", groupsFolder, id)},
})

if err != nil {
Expand Down Expand Up @@ -334,9 +327,7 @@ func (r CS3Repo) makeRootDirIfNotExist(ctx context.Context, folder string) error

// MakeDirIfNotExist will create a root node in the metadata storage. Requires an authenticated context.
func MakeDirIfNotExist(ctx context.Context, sp provider.ProviderAPIClient, folder string) error {
var rootPathRef = &provider.Reference{
Spec: &provider.Reference_Path{Path: path.Join("/meta", folder)},
}
var rootPathRef = &provider.Reference{Path: path.Join("/meta", folder)}

resp, err := sp.Stat(ctx, &provider.StatRequest{
Ref: rootPathRef,
Expand Down
2 changes: 2 additions & 0 deletions graph/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ require (
replace (
github.com/owncloud/ocis/ocis-pkg => ../ocis-pkg
github.com/owncloud/ocis/store => ../store
github.com/cs3org/go-cs3apis => github.com/refs/go-cs3apis v0.0.0-20210520134557-97cdc479815b
github.com/cs3org/reva => github.com/butonic/reva v0.0.0-20210526094447-9dfa8ec812ac
// taken from https://github.com/asim/go-micro/blob/master/plugins/registry/etcd/go.mod#L14-L16
go.etcd.io/etcd/api/v3 => go.etcd.io/etcd/api/v3 v3.0.0-20210204162551-dae29bb719dd
go.etcd.io/etcd/pkg/v3 => go.etcd.io/etcd/pkg/v3 v3.0.0-20210204162551-dae29bb719dd
Expand Down
23 changes: 10 additions & 13 deletions graph/pkg/service/v0/drives.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package svc

import (
"github.com/go-chi/render"
"google.golang.org/grpc/metadata"
"net/http"
"strings"
"time"

"github.com/go-chi/render"
"google.golang.org/grpc/metadata"

gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
cs3rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
storageprovider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
Expand Down Expand Up @@ -58,15 +59,13 @@ func (g Graph) GetRootDriveChildren(w http.ResponseWriter, r *http.Request) {
ClientSecret: accessToken,
}

authRes, _ := client.Authenticate(ctx, authReq);
authRes, _ := client.Authenticate(ctx, authReq)
ctx = token.ContextSetToken(ctx, authRes.Token)
ctx = metadata.AppendToOutgoingContext(ctx, "x-access-token", authRes.Token)

g.logger.Info().Msgf("provides access token %v", ctx)

ref := &storageprovider.Reference{
Spec: &storageprovider.Reference_Path{Path: fn},
}
ref := &storageprovider.Reference{Path: fn}

req := &storageprovider.ListContainerRequest{
Ref: ref,
Expand Down Expand Up @@ -94,23 +93,22 @@ func (g Graph) GetRootDriveChildren(w http.ResponseWriter, r *http.Request) {
render.JSON(w, r, &listResponse{Value: files})
}


func cs3ResourceToDriveItem(res *storageprovider.ResourceInfo) (*msgraph.DriveItem, error) {
size := new(int)
*size = int(res.Size) // uint64 -> int :boom:
name := strings.TrimPrefix(res.Path, "/home/")
name := strings.TrimPrefix(res.Ref.GetPath(), "/home/")
lastModified := new(time.Time)
*lastModified = time.Unix(int64(res.Mtime.Seconds), int64(res.Mtime.Nanos))

driveItem := &msgraph.DriveItem{
BaseItem: msgraph.BaseItem{
Entity: msgraph.Entity{
Object: msgraph.Object{},
ID: &res.Id.OpaqueId,
ID: &res.Id.NodeId,
},
Name: &name,
Name: &name,
LastModifiedDateTime: lastModified,
ETag: &res.Etag,
ETag: &res.Etag,
},
Size: size,
}
Expand All @@ -120,8 +118,7 @@ func cs3ResourceToDriveItem(res *storageprovider.ResourceInfo) (*msgraph.DriveIt
}
}
if res.Type == storageprovider.ResourceType_RESOURCE_TYPE_CONTAINER {
driveItem.Folder = &msgraph.Folder{
}
driveItem.Folder = &msgraph.Folder{}
}
return driveItem, nil
}
Expand Down
2 changes: 2 additions & 0 deletions ocis-pkg/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ replace (
github.com/crewjam/saml => github.com/crewjam/saml v0.4.5
github.com/owncloud/ocis/accounts => ../accounts
github.com/owncloud/ocis/glauth => ../glauth
github.com/cs3org/go-cs3apis => github.com/refs/go-cs3apis v0.0.0-20210520134557-97cdc479815b
github.com/cs3org/reva => github.com/butonic/reva v0.0.0-20210526094447-9dfa8ec812ac
github.com/owncloud/ocis/graph => ../graph
github.com/owncloud/ocis/graph-explorer => ../graph-explorer
github.com/owncloud/ocis/idp => ../idp
Expand Down
22 changes: 8 additions & 14 deletions ocis-pkg/indexer/index/cs3/autoincrement.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,7 @@ func (idx *Autoincrement) Remove(id string, v string) error {

deletePath := path.Join("/meta", idx.indexRootDir, v)
resp, err := idx.storageProvider.Delete(ctx, &provider.DeleteRequest{
Ref: &provider.Reference{
Spec: &provider.Reference_Path{Path: deletePath},
},
Ref: &provider.Reference{Path: deletePath},
})

if err != nil {
Expand Down Expand Up @@ -213,9 +211,7 @@ func (idx *Autoincrement) Search(pattern string) ([]string, error) {
}

res, err := idx.storageProvider.ListContainer(ctx, &provider.ListContainerRequest{
Ref: &provider.Reference{
Spec: &provider.Reference_Path{Path: path.Join("/meta", idx.indexRootDir)},
},
Ref: &provider.Reference{Path: path.Join("/meta", idx.indexRootDir)},
})

if err != nil {
Expand All @@ -225,12 +221,12 @@ func (idx *Autoincrement) Search(pattern string) ([]string, error) {
searchPath := idx.indexRootDir
matches := make([]string, 0)
for _, i := range res.GetInfos() {
if found, err := filepath.Match(pattern, path.Base(i.Path)); found {
if found, err := filepath.Match(pattern, path.Base(i.Ref.GetPath())); found {
if err != nil {
return nil, err
}

oldPath, err := idx.resolveSymlink(path.Join(searchPath, path.Base(i.Path)))
oldPath, err := idx.resolveSymlink(path.Join(searchPath, path.Base(i.Ref.GetPath())))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -326,9 +322,7 @@ func (idx *Autoincrement) next() (int, error) {
}

res, err := idx.storageProvider.ListContainer(ctx, &provider.ListContainerRequest{
Ref: &provider.Reference{
Spec: &provider.Reference_Path{Path: path.Join("/meta", idx.indexRootDir)},
},
Ref: &provider.Reference{Path: path.Join("/meta", idx.indexRootDir)},
})

if err != nil {
Expand All @@ -341,12 +335,12 @@ func (idx *Autoincrement) next() (int, error) {

infos := res.GetInfos()
sort.Slice(infos, func(i, j int) bool {
a, _ := strconv.Atoi(path.Base(infos[i].Path))
b, _ := strconv.Atoi(path.Base(infos[j].Path))
a, _ := strconv.Atoi(path.Base(infos[i].Ref.GetPath()))
b, _ := strconv.Atoi(path.Base(infos[j].Ref.GetPath()))
return a < b
})

latest, err := strconv.Atoi(path.Base(infos[len(infos)-1].Path)) // would returning a string be a better interface?
latest, err := strconv.Atoi(path.Base(infos[len(infos)-1].Ref.GetPath())) // would returning a string be a better interface?
if err != nil {
return -1, err
}
Expand Down
4 changes: 1 addition & 3 deletions ocis-pkg/indexer/index/cs3/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import (

func deleteIndexRoot(ctx context.Context, storageProvider provider.ProviderAPIClient, indexRootDir string) error {
res, err := storageProvider.Delete(ctx, &provider.DeleteRequest{
Ref: &provider.Reference{
Spec: &provider.Reference_Path{Path: path.Join("/meta", indexRootDir)},
},
Ref: &provider.Reference{Path: path.Join("/meta", indexRootDir)},
})
if err != nil {
return err
Expand Down
32 changes: 10 additions & 22 deletions ocis-pkg/indexer/index/cs3/non_unique.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,15 @@ func (idx *NonUnique) Lookup(v string) ([]string, error) {
}

res, err := idx.storageProvider.ListContainer(ctx, &provider.ListContainerRequest{
Ref: &provider.Reference{
Spec: &provider.Reference_Path{Path: path.Join("/meta", idx.indexRootDir, v)},
},
Ref: &provider.Reference{Path: path.Join("/meta", idx.indexRootDir, v)},
})

if err != nil {
return nil, err
}

for _, info := range res.Infos {
matches = append(matches, path.Base(info.Path))
matches = append(matches, path.Base(info.Ref.GetPath()))
}

return matches, nil
Expand Down Expand Up @@ -191,9 +189,7 @@ func (idx *NonUnique) Remove(id string, v string) error {

deletePath := path.Join("/meta", idx.indexRootDir, v, id)
resp, err := idx.storageProvider.Delete(ctx, &provider.DeleteRequest{
Ref: &provider.Reference{
Spec: &provider.Reference_Path{Path: deletePath},
},
Ref: &provider.Reference{Path: deletePath},
})

if err != nil {
Expand All @@ -206,9 +202,7 @@ func (idx *NonUnique) Remove(id string, v string) error {

toStat := path.Join("/meta", idx.indexRootDir, v)
lcResp, err := idx.storageProvider.ListContainer(ctx, &provider.ListContainerRequest{
Ref: &provider.Reference{
Spec: &provider.Reference_Path{Path: toStat},
},
Ref: &provider.Reference{Path: toStat},
})
if err != nil {
return err
Expand All @@ -217,9 +211,7 @@ func (idx *NonUnique) Remove(id string, v string) error {
if len(lcResp.Infos) == 0 {
deletePath = path.Join("/meta", idx.indexRootDir, v)
_, err := idx.storageProvider.Delete(ctx, &provider.DeleteRequest{
Ref: &provider.Reference{
Spec: &provider.Reference_Path{Path: deletePath},
},
Ref: &provider.Reference{Path: deletePath},
})
if err != nil {
return err
Expand Down Expand Up @@ -261,34 +253,30 @@ func (idx *NonUnique) Search(pattern string) ([]string, error) {
foldersMatched := make([]string, 0)
matches := make([]string, 0)
res, err := idx.storageProvider.ListContainer(ctx, &provider.ListContainerRequest{
Ref: &provider.Reference{
Spec: &provider.Reference_Path{Path: path.Join("/meta", idx.indexRootDir)},
},
Ref: &provider.Reference{Path: path.Join("/meta", idx.indexRootDir)},
})

if err != nil {
return nil, err
}

for _, i := range res.Infos {
if found, err := filepath.Match(pattern, path.Base(i.Path)); found {
if found, err := filepath.Match(pattern, path.Base(i.Ref.GetPath())); found {
if err != nil {
return nil, err
}

foldersMatched = append(foldersMatched, i.Path)
foldersMatched = append(foldersMatched, i.Ref.GetPath())
}
}

for i := range foldersMatched {
res, _ := idx.storageProvider.ListContainer(ctx, &provider.ListContainerRequest{
Ref: &provider.Reference{
Spec: &provider.Reference_Path{Path: foldersMatched[i]},
},
Ref: &provider.Reference{Path: foldersMatched[i]},
})

for _, info := range res.Infos {
matches = append(matches, path.Base(info.Path))
matches = append(matches, path.Base(info.Ref.GetPath()))
}
}

Expand Down
12 changes: 4 additions & 8 deletions ocis-pkg/indexer/index/cs3/unique.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,7 @@ func (idx *Unique) Remove(id string, v string) error {
deletePath := path.Join("/meta", idx.indexRootDir, v)
ctx = metadata.AppendToOutgoingContext(ctx, token.TokenHeader, t)
resp, err := idx.storageProvider.Delete(ctx, &provider.DeleteRequest{
Ref: &provider.Reference{
Spec: &provider.Reference_Path{Path: deletePath},
},
Ref: &provider.Reference{Path: deletePath},
})

if err != nil {
Expand Down Expand Up @@ -239,9 +237,7 @@ func (idx *Unique) Search(pattern string) ([]string, error) {

ctx = metadata.AppendToOutgoingContext(ctx, token.TokenHeader, t)
res, err := idx.storageProvider.ListContainer(ctx, &provider.ListContainerRequest{
Ref: &provider.Reference{
Spec: &provider.Reference_Path{Path: path.Join("/meta", idx.indexRootDir)},
},
Ref: &provider.Reference{Path: path.Join("/meta", idx.indexRootDir)},
})

if err != nil {
Expand All @@ -251,12 +247,12 @@ func (idx *Unique) Search(pattern string) ([]string, error) {
searchPath := idx.indexRootDir
matches := make([]string, 0)
for _, i := range res.GetInfos() {
if found, err := filepath.Match(pattern, path.Base(i.Path)); found {
if found, err := filepath.Match(pattern, path.Base(i.Ref.GetPath())); found {
if err != nil {
return nil, err
}

oldPath, err := idx.resolveSymlink(path.Join(searchPath, path.Base(i.Path)))
oldPath, err := idx.resolveSymlink(path.Join(searchPath, path.Base(i.Ref.GetPath())))
if err != nil {
return nil, err
}
Expand Down
Loading