From 8ee5aac82bc7682f7b6e36ff3b2fbee11301ef6f Mon Sep 17 00:00:00 2001 From: Ishank Arora Date: Mon, 12 Apr 2021 14:52:57 +0200 Subject: [PATCH] Add option to read registry rules from json file --- changelog/unreleased/storage-registry-json.md | 3 +++ storage/pkg/command/frontend.go | 5 +++-- storage/pkg/command/gateway.go | 13 +++++++++++++ storage/pkg/config/config.go | 2 ++ storage/pkg/flagset/frontend.go | 7 +++++++ storage/pkg/flagset/gateway.go | 10 ++++++++-- 6 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 changelog/unreleased/storage-registry-json.md diff --git a/changelog/unreleased/storage-registry-json.md b/changelog/unreleased/storage-registry-json.md new file mode 100644 index 0000000000..4ed10b42aa --- /dev/null +++ b/changelog/unreleased/storage-registry-json.md @@ -0,0 +1,3 @@ +Enhancement: Add option to reading registry rules from json file + +https://github.com/owncloud/ocis/pull/1917 diff --git a/storage/pkg/command/frontend.go b/storage/pkg/command/frontend.go index e4d2362c91..928a73fc9b 100644 --- a/storage/pkg/command/frontend.go +++ b/storage/pkg/command/frontend.go @@ -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", diff --git a/storage/pkg/command/gateway.go b/storage/pkg/command/gateway.go index 083b798b54..76d1a02715 100644 --- a/storage/pkg/command/gateway.go +++ b/storage/pkg/command/gateway.go @@ -2,7 +2,9 @@ package command import ( "context" + "encoding/json" "flag" + "io/ioutil" "os" "path" "strings" @@ -184,6 +186,17 @@ 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 { + return nil + } + var rules map[string]map[string]interface{} + _ = json.Unmarshal(data, &rules) + return rules + } + // generate rules based on default config return map[string]map[string]interface{}{ cfg.Reva.StorageHome.MountPath: {"address": cfg.Reva.StorageHome.Endpoint}, diff --git a/storage/pkg/config/config.go b/storage/pkg/config/config.go index 11b395e921..fed0a64083 100644 --- a/storage/pkg/config/config.go +++ b/storage/pkg/config/config.go @@ -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. @@ -109,6 +110,7 @@ type FrontendPort struct { OCDavPrefix string OCSPrefix string OCSSharePrefix string + OCSHomeNamespace string PublicURL string Middleware Middleware } diff --git a/storage/pkg/flagset/frontend.go b/storage/pkg/flagset/frontend.go index ab09f983e8..e872cfdf29 100644 --- a/storage/pkg/flagset/frontend.go +++ b/storage/pkg/flagset/frontend.go @@ -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{ diff --git a/storage/pkg/flagset/gateway.go b/storage/pkg/flagset/gateway.go index 6211948a46..af603478fe 100644 --- a/storage/pkg/flagset/gateway.go +++ b/storage/pkg/flagset/gateway.go @@ -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