Add error log for failing to read from json file
This commit is contained in:
1 parent
8ee5aac82b
commit
0241467958
1 file changed
+10
-5
@@ -18,6 +18,7 @@ import (
|
|||||||
"github.com/micro/cli/v2"
|
"github.com/micro/cli/v2"
|
||||||
"github.com/oklog/run"
|
"github.com/oklog/run"
|
||||||
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
|
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
|
||||||
|
"github.com/owncloud/ocis/ocis-pkg/log"
|
||||||
"github.com/owncloud/ocis/storage/pkg/config"
|
"github.com/owncloud/ocis/storage/pkg/config"
|
||||||
"github.com/owncloud/ocis/storage/pkg/flagset"
|
"github.com/owncloud/ocis/storage/pkg/flagset"
|
||||||
"github.com/owncloud/ocis/storage/pkg/server/debug"
|
"github.com/owncloud/ocis/storage/pkg/server/debug"
|
||||||
@@ -48,7 +49,7 @@ func Gateway(cfg *config.Config) *cli.Command {
|
|||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
uuid := uuid.Must(uuid.NewV4())
|
uuid := uuid.Must(uuid.NewV4())
|
||||||
pidFile := path.Join(os.TempDir(), "revad-"+c.Command.Name+"-"+uuid.String()+".pid")
|
pidFile := path.Join(os.TempDir(), "revad-"+c.Command.Name+"-"+uuid.String()+".pid")
|
||||||
rcfg := gatewayConfigFromStruct(c, cfg)
|
rcfg := gatewayConfigFromStruct(c, cfg, logger)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
gr.Add(func() error {
|
gr.Add(func() error {
|
||||||
@@ -105,7 +106,7 @@ func Gateway(cfg *config.Config) *cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// gatewayConfigFromStruct will adapt an oCIS config struct into a reva mapstructure to start a reva service.
|
// gatewayConfigFromStruct will adapt an oCIS config struct into a reva mapstructure to start a reva service.
|
||||||
func gatewayConfigFromStruct(c *cli.Context, cfg *config.Config) map[string]interface{} {
|
func gatewayConfigFromStruct(c *cli.Context, cfg *config.Config, logger log.Logger) map[string]interface{} {
|
||||||
rcfg := map[string]interface{}{
|
rcfg := map[string]interface{}{
|
||||||
"core": map[string]interface{}{
|
"core": map[string]interface{}{
|
||||||
"max_cpus": cfg.Reva.Users.MaxCPUs,
|
"max_cpus": cfg.Reva.Users.MaxCPUs,
|
||||||
@@ -164,7 +165,7 @@ func gatewayConfigFromStruct(c *cli.Context, cfg *config.Config) map[string]inte
|
|||||||
"drivers": map[string]interface{}{
|
"drivers": map[string]interface{}{
|
||||||
"static": map[string]interface{}{
|
"static": map[string]interface{}{
|
||||||
"home_provider": cfg.Reva.StorageRegistry.HomeProvider,
|
"home_provider": cfg.Reva.StorageRegistry.HomeProvider,
|
||||||
"rules": rules(cfg),
|
"rules": rules(cfg, logger),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -174,7 +175,7 @@ func gatewayConfigFromStruct(c *cli.Context, cfg *config.Config) map[string]inte
|
|||||||
return rcfg
|
return rcfg
|
||||||
}
|
}
|
||||||
|
|
||||||
func rules(cfg *config.Config) map[string]map[string]interface{} {
|
func rules(cfg *config.Config, logger log.Logger) map[string]map[string]interface{} {
|
||||||
|
|
||||||
// if a list of rules is given it overrides the generated rules from below
|
// if a list of rules is given it overrides the generated rules from below
|
||||||
if len(cfg.Reva.StorageRegistry.Rules) > 0 {
|
if len(cfg.Reva.StorageRegistry.Rules) > 0 {
|
||||||
@@ -190,10 +191,14 @@ func rules(cfg *config.Config) map[string]map[string]interface{} {
|
|||||||
if cfg.Reva.StorageRegistry.JSON != "" {
|
if cfg.Reva.StorageRegistry.JSON != "" {
|
||||||
data, err := ioutil.ReadFile(cfg.Reva.StorageRegistry.JSON)
|
data, err := ioutil.ReadFile(cfg.Reva.StorageRegistry.JSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logger.Error().Err(err).Msg("Failed to read storage registry rules from JSON file: " + cfg.Reva.StorageRegistry.JSON)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
var rules map[string]map[string]interface{}
|
var rules map[string]map[string]interface{}
|
||||||
_ = json.Unmarshal(data, &rules)
|
if err = json.Unmarshal(data, &rules); err != nil {
|
||||||
|
logger.Error().Err(err).Msg("Failed to unmarshal storage registry rules")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return rules
|
return rules
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user