3
0

Migrate storage path to options.StorageOpt struct

This commit is contained in:
Denis Arh
2019-07-31 15:20:09 +02:00
parent aabff3df6e
commit 9f58f8e83e
7 changed files with 47 additions and 12 deletions
+3 -3
View File
@@ -11,7 +11,6 @@ import (
"github.com/cortezaproject/corteza-server/compose/internal/service"
"github.com/cortezaproject/corteza-server/compose/rest"
"github.com/cortezaproject/corteza-server/pkg/cli"
"github.com/cortezaproject/corteza-server/pkg/cli/options"
)
const (
@@ -36,8 +35,9 @@ func Configure() *cli.Config {
}
servicesInitialized = true
storagePath := options.EnvString("", "COMPOSE_STORAGE_PATH", "var/store")
cli.HandleError(service.Init(ctx, c.Log, storagePath))
cli.HandleError(service.Init(ctx, c.Log, service.Config{
Storage: *c.StorageOpt,
}))
},
ApiServerPreRun: cli.Runners{
+8 -3
View File
@@ -9,6 +9,7 @@ import (
"github.com/cortezaproject/corteza-server/compose/internal/repository"
"github.com/cortezaproject/corteza-server/internal/permissions"
"github.com/cortezaproject/corteza-server/internal/store"
"github.com/cortezaproject/corteza-server/pkg/cli/options"
)
type (
@@ -16,6 +17,10 @@ type (
accessControlPermissionServicer
Watch(ctx context.Context)
}
Config struct {
Storage options.StorageOpt
}
)
var (
@@ -35,11 +40,11 @@ var (
DefaultNamespace NamespaceService
)
func Init(ctx context.Context, log *zap.Logger, storePath string) (err error) {
func Init(ctx context.Context, log *zap.Logger, c Config) (err error) {
DefaultLogger = log.Named("service")
fs, err := store.New(storePath)
log.Info("initializing store", zap.String("path", storePath), zap.Error(err))
fs, err := store.New(c.Storage.Path)
log.Info("initializing store", zap.String("path", c.Storage.Path), zap.Error(err))
if err != nil {
return err
}
+6 -1
View File
@@ -12,6 +12,7 @@ import (
"go.uber.org/zap"
messagingMigrate "github.com/cortezaproject/corteza-server/messaging/db"
"github.com/cortezaproject/corteza-server/pkg/cli/options"
"github.com/cortezaproject/corteza-server/pkg/logger"
dbLogger "github.com/titpetric/factory/logger"
)
@@ -33,7 +34,11 @@ func TestMain(m *testing.M) {
return
}
Init(context.Background(), zap.NewNop(), "/tmp/corteza-messaging-store")
Init(context.Background(), zap.NewNop(), Config{
Storage: options.StorageOpt{
Path: "/tmp/corteza-messaging-store",
},
})
os.Exit(m.Run())
}
+8 -3
View File
@@ -10,6 +10,7 @@ import (
"github.com/cortezaproject/corteza-server/internal/permissions"
"github.com/cortezaproject/corteza-server/internal/store"
"github.com/cortezaproject/corteza-server/messaging/internal/repository"
"github.com/cortezaproject/corteza-server/pkg/cli/options"
)
type (
@@ -21,6 +22,10 @@ type (
accessControlPermissionServicer
Watch(ctx context.Context)
}
Config struct {
Storage options.StorageOpt
}
)
var (
@@ -38,11 +43,11 @@ var (
DefaultWebhook WebhookService
)
func Init(ctx context.Context, log *zap.Logger, storePath string) (err error) {
func Init(ctx context.Context, log *zap.Logger, c Config) (err error) {
DefaultLogger = log.Named("service")
fs, err := store.New(storePath)
log.Info("initializing store", zap.String("path", storePath), zap.Error(err))
fs, err := store.New(c.Storage.Path)
log.Info("initializing store", zap.String("path", c.Storage.Path), zap.Error(err))
if err != nil {
return err
}
+3 -2
View File
@@ -43,8 +43,9 @@ func Configure() *cli.Config {
}
servicesInitialized = true
storagePath := options.EnvString("", "MESSAGING_STORAGE_PATH", "var/store")
cli.HandleError(service.Init(ctx, c.Log, storagePath))
cli.HandleError(service.Init(ctx, c.Log, service.Config{
Storage: *c.StorageOpt,
}))
},
ApiServerPreRun: cli.Runners{
+17
View File
@@ -0,0 +1,17 @@
package options
type (
StorageOpt struct {
Path string `env:"STORAGE_PATH"`
}
)
func Storage(pfix string) (o *StorageOpt) {
o = &StorageOpt{
Path: "var/store",
}
fill(o, pfix)
return
}
+2
View File
@@ -49,6 +49,7 @@ type (
DbOpt *options.DBOpt
ProvisionOpt *options.ProvisionOpt
SentryOpt *options.SentryOpt
StorageOpt *options.StorageOpt
// DB Connection name, defaults to ServiceName
DatabaseName string
@@ -186,6 +187,7 @@ func (c *Config) Init() {
c.DbOpt = options.DB(c.ServiceName)
c.ProvisionOpt = options.Provision(c.ServiceName)
c.SentryOpt = options.Sentry(c.EnvPrefix)
c.StorageOpt = options.Storage(c.EnvPrefix)
if c.RootCommandDBSetup == nil {
c.RootCommandDBSetup = Runners{func(ctx context.Context, cmd *cobra.Command, c *Config) (err error) {