Fix tests after refactoring
This commit is contained in:
@@ -3,6 +3,8 @@ package service
|
||||
import (
|
||||
"github.com/owncloud/ocis-accounts/pkg/config"
|
||||
"github.com/owncloud/ocis-pkg/v2/log"
|
||||
"github.com/owncloud/ocis-pkg/v2/roles"
|
||||
settings "github.com/owncloud/ocis-settings/pkg/proto/v0"
|
||||
)
|
||||
|
||||
// Option defines a single option function.
|
||||
@@ -12,6 +14,8 @@ type Option func(o *Options)
|
||||
type Options struct {
|
||||
Logger log.Logger
|
||||
Config *config.Config
|
||||
RoleService settings.RoleService
|
||||
RoleManager *roles.Manager
|
||||
}
|
||||
|
||||
func newOptions(opts ...Option) Options {
|
||||
@@ -24,16 +28,30 @@ func newOptions(opts ...Option) Options {
|
||||
return opt
|
||||
}
|
||||
|
||||
// Logger provides a function to set the logger option.
|
||||
// Logger provides a function to set the Logger option.
|
||||
func Logger(val log.Logger) Option {
|
||||
return func(o *Options) {
|
||||
o.Logger = val
|
||||
}
|
||||
}
|
||||
|
||||
// Config provides a function to set the config option.
|
||||
// Config provides a function to set the Config option.
|
||||
func Config(val *config.Config) Option {
|
||||
return func(o *Options) {
|
||||
o.Config = val
|
||||
}
|
||||
}
|
||||
|
||||
// RoleService provides a function to set the RoleService option.
|
||||
func RoleService(val settings.RoleService) Option {
|
||||
return func(o *Options) {
|
||||
o.RoleService = val
|
||||
}
|
||||
}
|
||||
|
||||
// RoleManager provides a function to set the RoleManager option.
|
||||
func RoleManager(val *roles.Manager) Option {
|
||||
return func(o *Options) {
|
||||
o.RoleManager = val
|
||||
}
|
||||
}
|
||||
|
||||
+17
-10
@@ -33,22 +33,29 @@ func New(opts ...Option) (s *Service, err error) {
|
||||
logger := options.Logger
|
||||
cfg := options.Config
|
||||
|
||||
// TODO this won't work with a registry other than mdns. Look into Micro's client initialization.
|
||||
// https://github.com/owncloud/ocis-proxy/issues/38
|
||||
roleService := settings.NewRoleService("com.owncloud.api.settings", mclient.DefaultClient)
|
||||
roleManager := roles.NewManager(
|
||||
roles.CacheSize(1024),
|
||||
roles.CacheTTL(time.Hour*24*7),
|
||||
roles.Logger(options.Logger),
|
||||
roles.RoleService(roleService),
|
||||
)
|
||||
roleService := options.RoleService
|
||||
if roleService == nil {
|
||||
// https://github.com/owncloud/ocis-proxy/issues/38
|
||||
// TODO this won't work with a registry other than mdns. Look into Micro's client initialization.
|
||||
roleService = settings.NewRoleService("com.owncloud.api.settings", mclient.DefaultClient)
|
||||
}
|
||||
roleManager := options.RoleManager
|
||||
if roleManager == nil {
|
||||
m := roles.NewManager(
|
||||
roles.CacheSize(1024),
|
||||
roles.CacheTTL(time.Hour*24*7),
|
||||
roles.Logger(options.Logger),
|
||||
roles.RoleService(roleService),
|
||||
)
|
||||
roleManager = &m
|
||||
}
|
||||
|
||||
s = &Service{
|
||||
id: cfg.GRPC.Namespace + "." + cfg.Server.Name,
|
||||
log: logger,
|
||||
Config: cfg,
|
||||
RoleService: roleService,
|
||||
RoleManager: &roleManager,
|
||||
RoleManager: roleManager,
|
||||
}
|
||||
|
||||
// build an index
|
||||
|
||||
Reference in New Issue
Block a user