fix accounts backend regression from #2590

This commit is contained in:
Willy Kloucek
2021-10-27 12:27:25 +02:00
parent a012f392d8
commit 405809f13a
4 changed files with 60 additions and 58 deletions
+1 -1
View File
@@ -184,7 +184,7 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag {
},
&cli.StringFlag{
Name: "storage-backend",
Value: flags.OverrideDefaultString(cfg.Repo.Disk.Path, "CS3"),
Value: flags.OverrideDefaultString(cfg.Repo.Backend, "CS3"),
Usage: "Which backend to use to store accounts data (CS3 or disk)",
EnvVars: []string{"ACCOUNTS_STORAGE_BACKEND"},
Destination: &cfg.Repo.Backend,
+52 -43
View File
@@ -2,13 +2,14 @@ package service
import (
"context"
"errors"
"path"
"path/filepath"
"strconv"
"strings"
"time"
"github.com/pkg/errors"
"github.com/owncloud/ocis/ocis-pkg/service/grpc"
"github.com/owncloud/ocis/accounts/pkg/storage"
@@ -48,17 +49,22 @@ func New(opts ...Option) (s *Service, err error) {
roleManager = &m
}
storage, err := createMetadataStorage(cfg, logger)
if err != nil {
return nil, errors.Wrap(err, "could not create metadata storage")
}
s = &Service{
id: cfg.GRPC.Namespace + "." + cfg.Server.Name,
log: logger,
Config: cfg,
RoleService: roleService,
RoleManager: roleManager,
repo: createMetadataStorage(cfg, logger),
repo: storage,
}
r := oreg.GetRegistry()
if strings.ToLower(cfg.Repo.Backend) != "disk" {
if strings.ToLower(cfg.Repo.Backend) == "cs3" {
if _, err := r.GetService("com.owncloud.storage.metadata"); err != nil {
logger.Error().Err(err).Msg("index: storage-metadata service not present")
return nil, err
@@ -113,40 +119,41 @@ func configFromSvc(cfg *config.Config) (*idxcfg.Config, error) {
}
}(cfg)
if (config.Repo{}) != cfg.Repo {
if (config.Disk{}) != cfg.Repo.Disk {
c.Repo = idxcfg.Repo{
Disk: idxcfg.Disk{
Path: cfg.Repo.Disk.Path,
},
}
switch backend := strings.ToLower(cfg.Repo.Backend); backend {
case "disk":
c.Repo = idxcfg.Repo{
Backend: backend,
Disk: idxcfg.Disk{
Path: cfg.Repo.Disk.Path,
},
}
case "cs3":
c.Repo = idxcfg.Repo{
Backend: backend,
CS3: idxcfg.CS3{
ProviderAddr: cfg.Repo.CS3.ProviderAddr,
DataURL: cfg.Repo.CS3.DataURL,
DataPrefix: cfg.Repo.CS3.DataPrefix,
JWTSecret: cfg.Repo.CS3.JWTSecret,
},
}
default:
return nil, errors.New("index backend " + cfg.Repo.Backend + " is not supported")
}
if (config.CS3{}) != cfg.Repo.CS3 {
c.Repo = idxcfg.Repo{
CS3: idxcfg.CS3{
ProviderAddr: cfg.Repo.CS3.ProviderAddr,
DataURL: cfg.Repo.CS3.DataURL,
DataPrefix: cfg.Repo.CS3.DataPrefix,
JWTSecret: cfg.Repo.CS3.JWTSecret,
},
}
if (config.Index{}) != cfg.Index {
c.Index = idxcfg.Index{
UID: idxcfg.Bound{
Lower: cfg.Index.UID.Lower,
},
GID: idxcfg.Bound{
Lower: cfg.Index.GID.Lower,
},
}
}
if (config.Index{}) != cfg.Index {
c.Index = idxcfg.Index{
UID: idxcfg.Bound{
Lower: cfg.Index.UID.Lower,
},
GID: idxcfg.Bound{
Lower: cfg.Index.GID.Lower,
},
}
}
if (config.ServiceUser{}) != cfg.ServiceUser {
c.ServiceUser = cfg.ServiceUser
}
if (config.ServiceUser{}) != cfg.ServiceUser {
c.ServiceUser = cfg.ServiceUser
}
return c, nil
@@ -417,17 +424,19 @@ func (s Service) createDefaultGroups(withDemoGroups bool) (err error) {
return nil
}
func createMetadataStorage(cfg *config.Config, logger log.Logger) storage.Repo {
// for now we detect the used storage implementation based on which storage is configured
// the config with defaults needs to be checked last
if cfg.Repo.Disk.Path != "" {
return storage.NewDiskRepo(cfg, logger)
func createMetadataStorage(cfg *config.Config, logger log.Logger) (storage.Repo, error) {
switch strings.ToLower(cfg.Repo.Backend) {
case "disk":
return storage.NewDiskRepo(cfg, logger), nil
case "cs3":
repo, err := storage.NewCS3Repo(cfg)
if err != nil {
return nil, errors.Wrap(err, "cs3 backend was configured but failed to start")
}
return repo, nil
default:
return nil, errors.New("backend type " + cfg.Repo.Backend + " is not supported")
}
repo, err := storage.NewCS3Repo(cfg)
if err != nil {
logger.Fatal().Err(err).Msg("cs3 storage was configured but failed to start")
}
return repo
}
// Service implements the AccountsServiceHandler interface
+3 -2
View File
@@ -7,8 +7,9 @@ import (
// Repo defines which storage implementation is to be used.
type Repo struct {
Disk Disk
CS3 CS3
Backend string
Disk Disk
CS3 CS3
}
// Disk is the local disk implementation of the storage.
+4 -12
View File
@@ -3,10 +3,11 @@ package indexer
import (
"fmt"
"github.com/owncloud/ocis/ocis-pkg/sync"
"path"
"strings"
"github.com/owncloud/ocis/ocis-pkg/sync"
"github.com/CiscoM31/godata"
"github.com/iancoleman/strcase"
"github.com/owncloud/ocis/ocis-pkg/indexer/config"
@@ -39,14 +40,6 @@ func CreateIndexer(cfg *config.Config) *Indexer {
}
}
func getRegistryStrategy(cfg *config.Config) string {
if cfg.Repo.Disk.Path != "" {
return "disk"
}
return "cs3"
}
// Reset takes care of deleting all indices from storage and from the internal map of indices
func (i *Indexer) Reset() error {
for j := range i.indices {
@@ -66,11 +59,10 @@ func (i *Indexer) Reset() error {
// AddIndex adds a new index to the indexer receiver.
func (i *Indexer) AddIndex(t interface{}, indexBy, pkName, entityDirName, indexType string, bound *option.Bound, caseInsensitive bool) error {
strategy := getRegistryStrategy(i.config)
f := registry.IndexConstructorRegistry[strategy][indexType]
f := registry.IndexConstructorRegistry[i.config.Repo.Backend][indexType]
var idx index.Index
if strategy == "cs3" {
if i.config.Repo.Backend == "cs3" {
idx = f(
option.CaseInsensitive(caseInsensitive),
option.WithEntity(t),