mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-05-25 00:46:37 -04:00
use cs3storage in metadatastorage
Signed-off-by: jkoberg <jkoberg@owncloud.com>
This commit is contained in:
2
go.mod
2
go.mod
@@ -22,7 +22,7 @@ require (
|
||||
github.com/blevesearch/bleve/v2 v2.3.0
|
||||
github.com/coreos/go-oidc/v3 v3.1.0
|
||||
github.com/cs3org/go-cs3apis v0.0.0-20220126114148-64c025ccdd19
|
||||
github.com/cs3org/reva v1.16.1-0.20220224115936-e17c65a48a5a
|
||||
github.com/cs3org/reva v1.16.1-0.20220225100612-8b6ec49c4068
|
||||
github.com/disintegration/imaging v1.6.2
|
||||
github.com/glauth/glauth/v2 v2.0.0-20211021011345-ef3151c28733
|
||||
github.com/go-chi/chi/v5 v5.0.7
|
||||
|
||||
2
go.sum
2
go.sum
@@ -341,6 +341,8 @@ github.com/cs3org/go-cs3apis v0.0.0-20220126114148-64c025ccdd19 h1:1jqPH58jCxvba
|
||||
github.com/cs3org/go-cs3apis v0.0.0-20220126114148-64c025ccdd19/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
|
||||
github.com/cs3org/reva v1.16.1-0.20220224115936-e17c65a48a5a h1:LgwfJ4N+ekLRFOK2vwVKbgtnQYYcrNiMtu5kekJvJ54=
|
||||
github.com/cs3org/reva v1.16.1-0.20220224115936-e17c65a48a5a/go.mod h1:M+Nausi93NaMDoinwiUX/Ekgrp/RrYv715FG5KrIarY=
|
||||
github.com/cs3org/reva v1.16.1-0.20220225100612-8b6ec49c4068 h1:erH/cfXGizPxLSWGwDf4iyZW+mU/pcPRFlYtpauza5s=
|
||||
github.com/cs3org/reva v1.16.1-0.20220225100612-8b6ec49c4068/go.mod h1:fdlrnZ0f+UtAdpZfLG+4LM0ZrhT5V8tPEQt6ycYm82c=
|
||||
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI=
|
||||
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY=
|
||||
github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=
|
||||
|
||||
@@ -9,8 +9,6 @@ import (
|
||||
settingsmsg "github.com/owncloud/ocis/protogen/gen/ocis/messages/settings/v0"
|
||||
)
|
||||
|
||||
var accountsFolderLocation = "settings/accounts"
|
||||
|
||||
// ListRoleAssignments loads and returns all role assignments matching the given assignment identifier.
|
||||
func (s Store) ListRoleAssignments(accountUUID string) ([]*settingsmsg.UserRoleAssignment, error) {
|
||||
assIDs, err := s.mdc.ReadDir(nil, accountPath(accountUUID))
|
||||
@@ -39,17 +37,16 @@ func (s Store) ListRoleAssignments(accountUUID string) ([]*settingsmsg.UserRoleA
|
||||
// WriteRoleAssignment appends the given role assignment to the existing assignments of the respective account.
|
||||
func (s Store) WriteRoleAssignment(accountUUID, roleID string) (*settingsmsg.UserRoleAssignment, error) {
|
||||
// as per https://github.com/owncloud/product/issues/103 "Each user can have exactly one role"
|
||||
assIDs, err := s.mdc.ReadDir(nil, accountPath(accountUUID))
|
||||
err := s.mdc.Delete(nil, accountPath(accountUUID))
|
||||
if err != nil {
|
||||
// TODO: How to differentiate between 'not found' and other errors?
|
||||
}
|
||||
|
||||
err = s.mdc.MakeDirIfNotExist(nil, accountPath(accountUUID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, assID := range assIDs {
|
||||
err := s.mdc.Delete(nil, assignmentPath(accountUUID, assID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
ass := &settingsmsg.UserRoleAssignment{
|
||||
Id: uuid.Must(uuid.NewV4()).String(),
|
||||
AccountUuid: accountUUID,
|
||||
|
||||
@@ -24,7 +24,7 @@ var (
|
||||
olog.Level("info"),
|
||||
)
|
||||
|
||||
mdc = &MockedMetadataClient{data: make(map[string][]byte)}
|
||||
mdc = NewMDC()
|
||||
|
||||
bundles = []*settingsmsg.Bundle{
|
||||
{
|
||||
|
||||
@@ -68,5 +68,5 @@ func (s Store) RemoveSettingFromBundle(bundleID string, settingID string) error
|
||||
}
|
||||
|
||||
func bundlePath(id string) string {
|
||||
return fmt.Sprintf("bundle/%s", id)
|
||||
return fmt.Sprintf("%s/%s", bundleFolderLocation, id)
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ var bundleScenarios = []struct {
|
||||
}
|
||||
|
||||
func TestBundles(t *testing.T) {
|
||||
mdc := &MockedMetadataClient{data: make(map[string][]byte)}
|
||||
mdc := NewMDC()
|
||||
s := Store{
|
||||
Logger: olog.NewLogger(
|
||||
olog.Color(true),
|
||||
|
||||
@@ -3,8 +3,10 @@ package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/cs3org/reva/pkg/storage/utils/metadata"
|
||||
olog "github.com/owncloud/ocis/ocis-pkg/log"
|
||||
"github.com/owncloud/ocis/settings/pkg/config"
|
||||
"github.com/owncloud/ocis/settings/pkg/settings"
|
||||
@@ -12,8 +14,13 @@ import (
|
||||
|
||||
var (
|
||||
// Name is the default name for the settings store
|
||||
Name = "ocis-settings"
|
||||
managerName = "metadata"
|
||||
Name = "ocis-settings"
|
||||
managerName = "metadata"
|
||||
settingsSpaceID = "f1bdd61a-da7c-49fc-8203-0558109d1b4f" // uuid.Must(uuid.NewV4()).String()
|
||||
rootFolderLocation = "settings"
|
||||
bundleFolderLocation = "settings/bundles"
|
||||
accountsFolderLocation = "settings/accounts"
|
||||
valuesFolderLocation = "settings/values"
|
||||
)
|
||||
|
||||
// MetadataClient is the interface to talk to metadata service
|
||||
@@ -22,6 +29,7 @@ type MetadataClient interface {
|
||||
SimpleUpload(ctx context.Context, id string, content []byte) error
|
||||
Delete(ctx context.Context, id string) error
|
||||
ReadDir(ctx context.Context, id string) ([]string, error)
|
||||
MakeDirIfNotExist(ctx context.Context, id string) error
|
||||
}
|
||||
|
||||
// Store interacts with the filesystem to manage settings information
|
||||
@@ -35,23 +43,43 @@ type Store struct {
|
||||
func New(cfg *config.Config) settings.Manager {
|
||||
s := Store{
|
||||
//Logger: olog.NewLogger(
|
||||
// olog.Color(cfg.Log.Color),
|
||||
// olog.Pretty(cfg.Log.Pretty),
|
||||
// olog.Level(cfg.Log.Level),
|
||||
// olog.File(cfg.Log.File),
|
||||
//olog.Color(cfg.Log.Color),
|
||||
//olog.Pretty(cfg.Log.Pretty),
|
||||
//olog.Level(cfg.Log.Level),
|
||||
//olog.File(cfg.Log.File),
|
||||
//),
|
||||
}
|
||||
|
||||
if _, err := os.Stat(cfg.DataPath); err != nil {
|
||||
s.Logger.Info().Msgf("creating container on %v", cfg.DataPath)
|
||||
err = os.MkdirAll(cfg.DataPath, 0700)
|
||||
s.mdc = NewMetadataClient(cfg)
|
||||
return &s
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
s.Logger.Err(err).Msgf("providing container on %v", cfg.DataPath)
|
||||
}
|
||||
// NewMetadataClient returns the MetadataClient
|
||||
func NewMetadataClient(cfg *config.Config) MetadataClient {
|
||||
mdc, err := metadata.NewCS3Storage("127.0.0.1:9142", "127.0.0.1:9215", "058bff95-6708-4fe5-91e4-9ea3d377588b", "change-me-please")
|
||||
if err != nil {
|
||||
log.Fatal("error connecting to mdc:", err)
|
||||
}
|
||||
|
||||
return &s
|
||||
fmt.Println(settingsSpaceID)
|
||||
err = mdc.Init(nil, settingsSpaceID)
|
||||
if err != nil {
|
||||
log.Fatal("error initializing mdc:", err)
|
||||
}
|
||||
|
||||
for _, p := range []string{
|
||||
rootFolderLocation,
|
||||
accountsFolderLocation,
|
||||
bundleFolderLocation,
|
||||
valuesFolderLocation,
|
||||
} {
|
||||
err = mdc.MakeDirIfNotExist(nil, p)
|
||||
if err != nil {
|
||||
log.Fatalf("error creating settings folder '%s': %s", p, err)
|
||||
}
|
||||
}
|
||||
return mdc
|
||||
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
@@ -3,6 +3,8 @@ package store
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/owncloud/ocis/settings/pkg/config"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -31,11 +33,25 @@ const (
|
||||
//value3 = "b42702d2-5e4d-4d73-b133-e1f9e285355e"
|
||||
)
|
||||
|
||||
// use "unit" or "integration" do define test type. You need a running ocis instance for integration tests
|
||||
var testtype = "unit"
|
||||
|
||||
// MockedMetadataClient mocks the metadataservice inmemory
|
||||
type MockedMetadataClient struct {
|
||||
data map[string][]byte
|
||||
}
|
||||
|
||||
// NewMDC instantiates a mocked MetadataClient
|
||||
func NewMDC() MetadataClient {
|
||||
switch testtype {
|
||||
case "unit":
|
||||
return &MockedMetadataClient{data: make(map[string][]byte)}
|
||||
case "integration":
|
||||
return NewMetadataClient(&config.Config{})
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func keys(m map[string][]byte) (s []string) {
|
||||
for k := range m {
|
||||
s = append(s, k)
|
||||
@@ -56,12 +72,15 @@ func (m *MockedMetadataClient) SimpleUpload(_ context.Context, id string, conten
|
||||
|
||||
// Delete can't error either
|
||||
func (m *MockedMetadataClient) Delete(_ context.Context, id string) error {
|
||||
delete(m.data, id)
|
||||
for k := range m.data {
|
||||
if strings.HasPrefix(k, id) {
|
||||
delete(m.data, k)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ReadDir returns nil, nil if not found
|
||||
// Known flaw: lists also subdirs
|
||||
func (m *MockedMetadataClient) ReadDir(_ context.Context, id string) ([]string, error) {
|
||||
var out []string
|
||||
for k := range m.data {
|
||||
@@ -75,6 +94,11 @@ func (m *MockedMetadataClient) ReadDir(_ context.Context, id string) ([]string,
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// MakeDirIfNotExist does nothing
|
||||
func (m *MockedMetadataClient) MakeDirIfNotExist(_ context.Context, id string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// IDExists is a helper to check if an id exists
|
||||
func (m *MockedMetadataClient) IDExists(id string) bool {
|
||||
_, ok := m.data[id]
|
||||
|
||||
@@ -42,5 +42,5 @@ func (s Store) WriteValue(value *settingsmsg.Value) (*settingsmsg.Value, error)
|
||||
}
|
||||
|
||||
func valuePath(id string) string {
|
||||
return fmt.Sprintf("%s/%s", "settings/values", id)
|
||||
return fmt.Sprintf("%s/%s", valuesFolderLocation, id)
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ var valueScenarios = []struct {
|
||||
}
|
||||
|
||||
func TestValues(t *testing.T) {
|
||||
mdc := &MockedMetadataClient{data: make(map[string][]byte)}
|
||||
mdc := NewMDC()
|
||||
s := Store{
|
||||
Logger: olog.NewLogger(
|
||||
olog.Color(true),
|
||||
|
||||
Reference in New Issue
Block a user