add storage metadata to the runtime and fix its config parsing when running on supervised mode

This commit is contained in:
A.Unger
2021-03-03 17:36:03 +01:00
parent 22e3d2fd35
commit 59de8198c6
8 changed files with 84 additions and 95 deletions
+2 -1
View File
@@ -4,10 +4,11 @@ import (
"os"
"github.com/owncloud/ocis/storage/pkg/command"
"github.com/owncloud/ocis/storage/pkg/config"
)
func main() {
if err := command.Execute(); err != nil {
if err := command.Execute(config.New()); err != nil {
os.Exit(1)
}
}
+1 -3
View File
@@ -13,9 +13,7 @@ import (
)
// Execute is the entry point for the storage command.
func Execute() error {
cfg := config.New()
func Execute(cfg *config.Config) error {
app := &cli.App{
Name: "storage",
Version: version.String,
+45 -3
View File
@@ -2,6 +2,7 @@ package command
import (
"context"
"flag"
"os"
"os/signal"
"path"
@@ -23,9 +24,10 @@ import (
// It provides a ocis-specific storage store metadata (shares,account,settings...)
func StorageMetadata(cfg *config.Config) *cli.Command {
return &cli.Command{
Name: "storage-metadata",
Usage: "Start storage-metadata service",
Flags: flagset.StorageMetadata(cfg),
Name: "storage-metadata",
Usage: "Start storage-metadata service",
// TODO(refs) at this point it might make sense delegate log flags to each individual storage command.
Flags: append(flagset.StorageMetadata(cfg), flagset.RootWithConfig(cfg)...),
Category: "Extensions",
Before: func(c *cli.Context) error {
storageRoot := c.String("storage-root")
@@ -217,3 +219,43 @@ func StorageMetadata(cfg *config.Config) *cli.Command {
},
}
}
// SutureService allows for the settings command to be embedded and supervised by a suture supervisor tree.
type SutureService struct {
ctx context.Context
cancel context.CancelFunc // used to cancel the context go-micro services used to shutdown a service.
cfg *config.Config
}
// NewSutureService creates a new storagemetadata.SutureService
func NewStorageMetadata(ctx context.Context, cfg *config.Config) SutureService {
sctx, cancel := context.WithCancel(ctx)
cfg.Context = sctx
return SutureService{
ctx: sctx,
cancel: cancel,
cfg: cfg,
}
}
func (s SutureService) Serve() {
f := &flag.FlagSet{}
for k := range StorageMetadata(s.cfg).Flags {
if err := StorageMetadata(s.cfg).Flags[k].Apply(f); err != nil {
panic(err)
}
}
ctx := cli.NewContext(nil, f, nil)
if StorageMetadata(s.cfg).Before != nil {
if err := StorageMetadata(s.cfg).Before(ctx); err != nil {
panic(err)
}
}
if err := StorageMetadata(s.cfg).Action(ctx); err != nil {
panic(err)
}
}
func (s SutureService) Stop() {
s.cancel()
}
+4
View File
@@ -1,5 +1,7 @@
package config
import "context"
// Log defines the available logging configuration.
type Log struct {
Level string
@@ -376,6 +378,8 @@ type Config struct {
Reva Reva
Tracing Tracing
Asset Asset
Context context.Context
}
// New initializes a new configuration with or without defaults.
+3 -4
View File
@@ -17,21 +17,20 @@ func RootWithConfig(cfg *config.Config) []cli.Flag {
},
&cli.StringFlag{
Name: "log-level",
Value: "info",
Usage: "Set logging level",
EnvVars: []string{"STORAGE_LOG_LEVEL"},
EnvVars: []string{"STORAGE_LOG_LEVEL", "OCIS_LOG_LEVEL"},
Destination: &cfg.Log.Level,
},
&cli.BoolFlag{
Name: "log-pretty",
Usage: "Enable pretty logging",
EnvVars: []string{"STORAGE_LOG_PRETTY"},
EnvVars: []string{"STORAGE_LOG_PRETTY", "OCIS_LOG_PRETTY"},
Destination: &cfg.Log.Pretty,
},
&cli.BoolFlag{
Name: "log-color",
Usage: "Enable colored logging",
EnvVars: []string{"STORAGE_LOG_COLOR"},
EnvVars: []string{"STORAGE_LOG_COLOR", "OCIS_LOG_COLOR"},
Destination: &cfg.Log.Color,
},
}