Skip to content

Commit

Permalink
Merge pull request #1917 from ishank011/registry-json
Browse files Browse the repository at this point in the history
  • Loading branch information
refs authored Apr 14, 2021
2 parents 20bc2a2 + 0241467 commit 85550a3
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 8 deletions.
3 changes: 3 additions & 0 deletions changelog/unreleased/storage-registry-json.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Enhancement: Add option to reading registry rules from json file

https://github.com/owncloud/ocis/pull/1917
5 changes: 3 additions & 2 deletions storage/pkg/command/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
26 changes: 22 additions & 4 deletions storage/pkg/command/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package command

import (
"context"
"encoding/json"
"flag"
"io/ioutil"
"os"
"path"
"strings"
Expand All @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
},
},
},
Expand All @@ -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 {
Expand All @@ -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},
Expand Down
2 changes: 2 additions & 0 deletions storage/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type StorageRegistry struct {
// HomeProvider is the path in the global namespace that the static storage registry uses to determine the home storage
HomeProvider string
Rules []string
JSON string
}

// Sharing defines the available sharing configuration.
Expand Down Expand Up @@ -112,6 +113,7 @@ type FrontendPort struct {
OCDavPrefix string
OCSPrefix string
OCSSharePrefix string
OCSHomeNamespace string
PublicURL string
Middleware Middleware
}
Expand Down
7 changes: 7 additions & 0 deletions storage/pkg/flagset/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ func FrontendWithConfig(cfg *config.Config) []cli.Flag {
EnvVars: []string{"STORAGE_FRONTEND_OCS_SHARE_PREFIX"},
Destination: &cfg.Reva.Frontend.OCSSharePrefix,
},
&cli.StringFlag{
Name: "ocs-home-namespace",
Value: flags.OverrideDefaultString(cfg.Reva.Frontend.OCSHomeNamespace, "/home"),
Usage: "the prefix prepended to the incoming requests in OCS",
EnvVars: []string{"STORAGE_FRONTEND_OCS_HOME_NAMESPACE"},
Destination: &cfg.Reva.Frontend.OCSHomeNamespace,
},
// Gateway

&cli.StringFlag{
Expand Down
10 changes: 8 additions & 2 deletions storage/pkg/flagset/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,20 @@ func GatewayWithConfig(cfg *config.Config) []cli.Flag {
Usage: `Replaces the generated storage registry rules with this set: --storage-registry-rule "/eos=localhost:9158" [--storage-registry-rule "1284d238-aa92-42ce-bdc4-0b0000009162=localhost:9162"]`,
EnvVars: []string{"STORAGE_STORAGE_REGISTRY_RULES"},
},

&cli.StringFlag{
Name: "storage-home-provider",
Value: flags.OverrideDefaultString(cfg.Reva.StorageRegistry.HomeProvider, "/home"),
Usage: "mount point of the storage provider for user homes in the global namespace",
EnvVars: []string{"STORAGE_REGISTRY_HOME_PROVIDER"},
EnvVars: []string{"STORAGE_STORAGE_REGISTRY_HOME_PROVIDER"},
Destination: &cfg.Reva.StorageRegistry.HomeProvider,
},
&cli.StringFlag{
Name: "storage-registry-json",
Value: flags.OverrideDefaultString(cfg.Reva.StorageRegistry.JSON, ""),
Usage: "JSON file containing the storage registry rules",
EnvVars: []string{"STORAGE_STORAGE_REGISTRY_JSON"},
Destination: &cfg.Reva.StorageRegistry.JSON,
},

// please note that STORAGE_FRONTEND_PUBLIC_URL is also defined in
// storage/pkg/flagset/frontend.go because this setting may be consumed
Expand Down

0 comments on commit 85550a3

Please sign in to comment.