Merge pull request #1917 from ishank011/registry-json

This commit is contained in:
Alex Unger
2021-04-14 14:26:30 +02:00
committed by GitHub
6 changed files with 45 additions and 8 deletions
+3 -2
View File
@@ -156,8 +156,9 @@ func frontendConfigFromStruct(c *cli.Context, cfg *config.Config, filesCfg map[s
"public_url": cfg.Reva.Frontend.PublicURL,
},
"ocs": map[string]interface{}{
"share_prefix": cfg.Reva.Frontend.OCSSharePrefix,
"prefix": cfg.Reva.Frontend.OCSPrefix,
"share_prefix": cfg.Reva.Frontend.OCSSharePrefix,
"home_namespace": cfg.Reva.Frontend.OCSHomeNamespace,
"prefix": cfg.Reva.Frontend.OCSPrefix,
"config": map[string]interface{}{
"version": "1.8",
"website": "reva",
+22 -4
View File
@@ -2,7 +2,9 @@ package command
import (
"context"
"encoding/json"
"flag"
"io/ioutil"
"os"
"path"
"strings"
@@ -16,6 +18,7 @@ import (
"github.com/micro/cli/v2"
"github.com/oklog/run"
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/flagset"
"github.com/owncloud/ocis/storage/pkg/server/debug"
@@ -46,7 +49,7 @@ func Gateway(cfg *config.Config) *cli.Command {
ctx, cancel := context.WithCancel(context.Background())
uuid := uuid.Must(uuid.NewV4())
pidFile := path.Join(os.TempDir(), "revad-"+c.Command.Name+"-"+uuid.String()+".pid")
rcfg := gatewayConfigFromStruct(c, cfg)
rcfg := gatewayConfigFromStruct(c, cfg, logger)
defer cancel()
gr.Add(func() error {
@@ -103,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.
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{}{
"core": map[string]interface{}{
"max_cpus": cfg.Reva.Users.MaxCPUs,
@@ -162,7 +165,7 @@ func gatewayConfigFromStruct(c *cli.Context, cfg *config.Config) map[string]inte
"drivers": map[string]interface{}{
"static": map[string]interface{}{
"home_provider": cfg.Reva.StorageRegistry.HomeProvider,
"rules": rules(cfg),
"rules": rules(cfg, logger),
},
},
},
@@ -172,7 +175,7 @@ func gatewayConfigFromStruct(c *cli.Context, cfg *config.Config) map[string]inte
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 len(cfg.Reva.StorageRegistry.Rules) > 0 {
@@ -184,6 +187,21 @@ func rules(cfg *config.Config) map[string]map[string]interface{} {
return rules
}
// check if the rules have to be read from a json file
if cfg.Reva.StorageRegistry.JSON != "" {
data, err := ioutil.ReadFile(cfg.Reva.StorageRegistry.JSON)
if err != nil {
logger.Error().Err(err).Msg("Failed to read storage registry rules from JSON file: " + cfg.Reva.StorageRegistry.JSON)
return nil
}
var rules map[string]map[string]interface{}
if err = json.Unmarshal(data, &rules); err != nil {
logger.Error().Err(err).Msg("Failed to unmarshal storage registry rules")
return nil
}
return rules
}
// generate rules based on default config
return map[string]map[string]interface{}{
cfg.Reva.StorageHome.MountPath: {"address": cfg.Reva.StorageHome.Endpoint},