mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-03 02:39:52 -06:00
fix download helper for accounts service and indexer
This commit is contained in:
committed by
Willy Kloucek
parent
3fd070061d
commit
08641a8e45
@@ -25,6 +25,10 @@ import (
|
||||
"google.golang.org/grpc/metadata"
|
||||
)
|
||||
|
||||
const (
|
||||
storageMountPath = "/meta"
|
||||
)
|
||||
|
||||
// CS3Repo provides a cs3 implementation of the Repo interface
|
||||
type CS3Repo struct {
|
||||
cfg *config.Config
|
||||
@@ -99,7 +103,7 @@ func (r CS3Repo) LoadAccounts(ctx context.Context, a *[]*proto.Account) (err err
|
||||
ctx = metadata.AppendToOutgoingContext(ctx, revactx.TokenHeader, t)
|
||||
res, err := r.storageProvider.ListContainer(ctx, &provider.ListContainerRequest{
|
||||
Ref: &provider.Reference{
|
||||
Path: path.Join("/meta", accountsFolder),
|
||||
Path: path.Join(storageMountPath, accountsFolder),
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -142,7 +146,7 @@ func (r CS3Repo) DeleteAccount(ctx context.Context, id string) (err error) {
|
||||
|
||||
resp, err := r.storageProvider.Delete(ctx, &provider.DeleteRequest{
|
||||
Ref: &provider.Reference{
|
||||
Path: path.Join("/meta", accountsFolder, id),
|
||||
Path: path.Join(storageMountPath, accountsFolder, id),
|
||||
},
|
||||
})
|
||||
|
||||
@@ -200,7 +204,7 @@ func (r CS3Repo) LoadGroups(ctx context.Context, g *[]*proto.Group) (err error)
|
||||
ctx = metadata.AppendToOutgoingContext(ctx, revactx.TokenHeader, t)
|
||||
res, err := r.storageProvider.ListContainer(ctx, &provider.ListContainerRequest{
|
||||
Ref: &provider.Reference{
|
||||
Path: path.Join("/meta", groupsFolder),
|
||||
Path: path.Join(storageMountPath, groupsFolder),
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -243,7 +247,7 @@ func (r CS3Repo) DeleteGroup(ctx context.Context, id string) (err error) {
|
||||
|
||||
resp, err := r.storageProvider.Delete(ctx, &provider.DeleteRequest{
|
||||
Ref: &provider.Reference{
|
||||
Path: path.Join("/meta", groupsFolder, id),
|
||||
Path: path.Join(storageMountPath, groupsFolder, id),
|
||||
},
|
||||
})
|
||||
|
||||
@@ -268,6 +272,7 @@ func AuthenticateCS3(ctx context.Context, su config.ServiceUser, tm token.Manage
|
||||
u := &user.User{
|
||||
Id: &user.UserId{
|
||||
OpaqueId: su.UUID,
|
||||
Type: user.UserType_USER_TYPE_APPLICATION,
|
||||
},
|
||||
Groups: []string{},
|
||||
UidNumber: su.UID,
|
||||
@@ -295,7 +300,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{
|
||||
Path: path.Join("/meta", folder),
|
||||
Path: path.Join(storageMountPath, folder),
|
||||
}
|
||||
|
||||
resp, err := sp.Stat(ctx, &provider.StatRequest{
|
||||
@@ -319,11 +324,11 @@ func MakeDirIfNotExist(ctx context.Context, sp provider.ProviderAPIClient, folde
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r CS3Repo) uploadHelper(ctx context.Context, path string, content []byte) error {
|
||||
func (r CS3Repo) uploadHelper(ctx context.Context, uploadpath string, content []byte) error {
|
||||
|
||||
ref := provider.InitiateFileUploadRequest{
|
||||
Ref: &provider.Reference{
|
||||
Path: path,
|
||||
Path: path.Join(storageMountPath, uploadpath),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -348,6 +353,8 @@ func (r CS3Repo) uploadHelper(ctx context.Context, path string, content []byte)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
md, _ := metadata.FromOutgoingContext(ctx)
|
||||
req.Header.Add(revactx.TokenHeader, md.Get(revactx.TokenHeader)[0])
|
||||
resp, err := r.dataGatewayClient.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -358,11 +365,11 @@ func (r CS3Repo) uploadHelper(ctx context.Context, path string, content []byte)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r CS3Repo) downloadHelper(ctx context.Context, path string) (content []byte, err error) {
|
||||
func (r CS3Repo) downloadHelper(ctx context.Context, downloadpath string) (content []byte, err error) {
|
||||
|
||||
ref := provider.InitiateFileDownloadRequest{
|
||||
Ref: &provider.Reference{
|
||||
Path: path,
|
||||
Path: path.Join(storageMountPath, downloadpath),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -387,6 +394,8 @@ func (r CS3Repo) downloadHelper(ctx context.Context, path string) (content []byt
|
||||
if err != nil {
|
||||
return []byte{}, err
|
||||
}
|
||||
md, _ := metadata.FromOutgoingContext(ctx)
|
||||
req.Header.Add(revactx.TokenHeader, md.Get(revactx.TokenHeader)[0])
|
||||
resp, err := r.dataGatewayClient.Do(req)
|
||||
if err != nil {
|
||||
return []byte{}, err
|
||||
|
||||
@@ -4,11 +4,19 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"path"
|
||||
|
||||
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
||||
revactx "github.com/cs3org/reva/pkg/ctx"
|
||||
"github.com/cs3org/reva/pkg/token"
|
||||
"google.golang.org/grpc/metadata"
|
||||
)
|
||||
|
||||
const (
|
||||
storageMountPath = "/meta"
|
||||
)
|
||||
|
||||
type metadataStorage struct {
|
||||
@@ -17,11 +25,11 @@ type metadataStorage struct {
|
||||
dataGatewayClient *http.Client
|
||||
}
|
||||
|
||||
func (r metadataStorage) uploadHelper(ctx context.Context, path string, content []byte) error {
|
||||
func (r metadataStorage) uploadHelper(ctx context.Context, uploadpath string, content []byte) error {
|
||||
|
||||
ref := provider.InitiateFileUploadRequest{
|
||||
Ref: &provider.Reference{
|
||||
Path: path,
|
||||
Path: path.Join(storageMountPath, uploadpath),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -46,6 +54,9 @@ func (r metadataStorage) uploadHelper(ctx context.Context, path string, content
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
md, _ := metadata.FromOutgoingContext(ctx)
|
||||
req.Header.Add(revactx.TokenHeader, md.Get(revactx.TokenHeader)[0])
|
||||
resp, err := r.dataGatewayClient.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -56,11 +67,10 @@ func (r metadataStorage) uploadHelper(ctx context.Context, path string, content
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r metadataStorage) downloadHelper(ctx context.Context, path string) (content []byte, err error) {
|
||||
|
||||
func (r metadataStorage) downloadHelper(ctx context.Context, downloadpath string) (content []byte, err error) {
|
||||
ref := provider.InitiateFileDownloadRequest{
|
||||
Ref: &provider.Reference{
|
||||
Path: path,
|
||||
Path: path.Join(storageMountPath, downloadpath),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -85,14 +95,17 @@ func (r metadataStorage) downloadHelper(ctx context.Context, path string) (conte
|
||||
if err != nil {
|
||||
return []byte{}, err
|
||||
}
|
||||
|
||||
md, _ := metadata.FromOutgoingContext(ctx)
|
||||
req.Header.Add(revactx.TokenHeader, md.Get(revactx.TokenHeader)[0])
|
||||
resp, err := r.dataGatewayClient.Do(req)
|
||||
if err != nil {
|
||||
return []byte{}, err
|
||||
}
|
||||
|
||||
//if resp.StatusCode != http.StatusOK {
|
||||
// return []byte{}, ¬FoundErr{}
|
||||
//}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return []byte{}, ¬FoundErr{}
|
||||
}
|
||||
|
||||
b, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
@@ -105,3 +118,17 @@ func (r metadataStorage) downloadHelper(ctx context.Context, path string) (conte
|
||||
|
||||
return b, nil
|
||||
}
|
||||
|
||||
type notFoundErr struct {
|
||||
typ, id string
|
||||
}
|
||||
|
||||
func (e notFoundErr) Error() string {
|
||||
return fmt.Sprintf("%s with id %s not found", e.typ, e.id)
|
||||
}
|
||||
|
||||
// IsNotFoundErr can be returned by repo Load and Delete operations
|
||||
func IsNotFoundErr(e error) bool {
|
||||
_, ok := e.(*notFoundErr)
|
||||
return ok
|
||||
}
|
||||
|
||||
@@ -922,7 +922,7 @@ func DefaultConfig() *Config {
|
||||
},
|
||||
Driver: "ocis",
|
||||
ExposeDataServer: false,
|
||||
DataServerURL: "http://localhost:9216",
|
||||
DataServerURL: "http://localhost:9216/data",
|
||||
TempFolder: path.Join(defaults.BaseDataPath(), "tmp", "metadata"),
|
||||
DataProvider: DataProvider{},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user