Skip to content

Commit

Permalink
gateway should talk to itself
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>

extract method

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
  • Loading branch information
butonic committed Jul 30, 2024
1 parent 9289df5 commit 10764b4
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 17 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/omit-some-lookups-in-gateway.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Gateways should directly talk to themselves

The CS3 gateway can directly to itself when it wants to talk to the registries running in the same reva runtime.

https://github.com/owncloud/ocis/pull/9714
24 changes: 21 additions & 3 deletions ocis-pkg/config/helpers.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package config

import (
gofig "github.com/gookit/config/v2"
gooyaml "github.com/gookit/config/v2/yaml"
"github.com/owncloud/ocis/v2/ocis-pkg/config/defaults"
"io/fs"
"os"
"path"
"strings"

gofig "github.com/gookit/config/v2"
gooyaml "github.com/gookit/config/v2/yaml"
"github.com/owncloud/ocis/v2/ocis-pkg/config/defaults"
)

var (
Expand Down Expand Up @@ -49,3 +50,20 @@ func bindSourcesToStructs(fileSystem fs.FS, filePath, service string, dst interf

return nil
}

// LocalEndpoint returns the local endpoint for a given protocol and address.
// Use it when configuring the reva runtime to get a service endpoint in the same
// runtime, e.g. a gateway talking to an authregistry service.
func LocalEndpoint(protocol, addr string) string {
localEndpoint := addr
switch protocol {
case "tcp":
parts := strings.SplitN(addr, ":", 2)
if len(parts) == 2 {
localEndpoint = "dns:127.0.0.1:" + parts[1]
}
case "unix":
localEndpoint = "unix:" + addr
}
return localEndpoint
}
7 changes: 5 additions & 2 deletions services/gateway/pkg/revaconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import (
"strings"

"github.com/cs3org/reva/v2/pkg/utils"
pkgconfig "github.com/owncloud/ocis/v2/ocis-pkg/config"
"github.com/owncloud/ocis/v2/ocis-pkg/log"
"github.com/owncloud/ocis/v2/services/gateway/pkg/config"
)

// GatewayConfigFromStruct will adapt an oCIS config struct into a reva mapstructure to start a reva service.
func GatewayConfigFromStruct(cfg *config.Config, logger log.Logger) map[string]interface{} {
localEndpoint := pkgconfig.LocalEndpoint(cfg.GRPC.Protocol, cfg.GRPC.Addr)

rcfg := map[string]interface{}{
"core": map[string]interface{}{
"tracing_enabled": cfg.Tracing.Enabled,
Expand Down Expand Up @@ -39,8 +42,8 @@ func GatewayConfigFromStruct(cfg *config.Config, logger log.Logger) map[string]i
"gateway": map[string]interface{}{
"applicationauthsvc": cfg.AuthAppEndpoint,
// registries are located on the gateway
"authregistrysvc": cfg.Reva.Address,
"storageregistrysvc": cfg.Reva.Address,
"authregistrysvc": localEndpoint,
"storageregistrysvc": localEndpoint,
"appregistrysvc": cfg.AppRegistryEndpoint,
// user metadata is located on the users services
"preferencessvc": cfg.UsersEndpoint,
Expand Down
27 changes: 15 additions & 12 deletions services/storage-system/pkg/revaconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package revaconfig

import (
userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
pkgconfig "github.com/owncloud/ocis/v2/ocis-pkg/config"
"github.com/owncloud/ocis/v2/services/storage-system/pkg/config"
)

// StorageSystemFromStruct will adapt an oCIS config struct into a reva mapstructure to start a reva service.
func StorageSystemFromStruct(cfg *config.Config) map[string]interface{} {
localEndpoint := pkgconfig.LocalEndpoint(cfg.GRPC.Protocol, cfg.GRPC.Addr)

rcfg := map[string]interface{}{
"shared": map[string]interface{}{
"jwt_secret": cfg.TokenManager.JWTSecret,
Expand All @@ -25,12 +28,12 @@ func StorageSystemFromStruct(cfg *config.Config) map[string]interface{} {
"services": map[string]interface{}{
"gateway": map[string]interface{}{
// registries are located on the gateway
"authregistrysvc": "com.owncloud.api.storage-system",
"storageregistrysvc": "com.owncloud.api.storage-system",
"authregistrysvc": localEndpoint,
"storageregistrysvc": localEndpoint,
// user metadata is located on the users services
"userprovidersvc": "com.owncloud.api.storage-system",
"groupprovidersvc": "com.owncloud.api.storage-system",
"permissionssvc": "com.owncloud.api.storage-system",
"userprovidersvc": localEndpoint,
"groupprovidersvc": localEndpoint,
"permissionssvc": localEndpoint,
// other
"disable_home_creation_on_login": true, // metadata manually creates a space
// metadata always uses the simple upload, so no transfer secret or datagateway needed
Expand Down Expand Up @@ -60,7 +63,7 @@ func StorageSystemFromStruct(cfg *config.Config) map[string]interface{} {
"drivers": map[string]interface{}{
"static": map[string]interface{}{
"rules": map[string]interface{}{
"machine": "com.owncloud.api.storage-system",
"machine": localEndpoint,
},
},
},
Expand All @@ -70,7 +73,7 @@ func StorageSystemFromStruct(cfg *config.Config) map[string]interface{} {
"auth_managers": map[string]interface{}{
"machine": map[string]interface{}{
"api_key": cfg.SystemUserAPIKey,
"gateway_addr": "com.owncloud.api.storage-system",
"gateway_addr": localEndpoint,
},
},
},
Expand All @@ -86,15 +89,15 @@ func StorageSystemFromStruct(cfg *config.Config) map[string]interface{} {
"static": map[string]interface{}{
"rules": map[string]interface{}{
"/": map[string]interface{}{
"address": "com.owncloud.api.storage-system",
"address": localEndpoint,
},
},
},
},
},
"storageprovider": map[string]interface{}{
"driver": cfg.Driver,
"drivers": metadataDrivers(cfg),
"drivers": metadataDrivers(localEndpoint, cfg),
"data_server_url": cfg.DataServerURL,
},
},
Expand All @@ -113,7 +116,7 @@ func StorageSystemFromStruct(cfg *config.Config) map[string]interface{} {
"dataprovider": map[string]interface{}{
"prefix": "data",
"driver": cfg.Driver,
"drivers": metadataDrivers(cfg),
"drivers": metadataDrivers(localEndpoint, cfg),
"data_txs": map[string]interface{}{
"simple": map[string]interface{}{
"cache_store": "noop",
Expand Down Expand Up @@ -144,15 +147,15 @@ func StorageSystemFromStruct(cfg *config.Config) map[string]interface{} {
return rcfg
}

func metadataDrivers(cfg *config.Config) map[string]interface{} {
func metadataDrivers(localEndpoint string, cfg *config.Config) map[string]interface{} {
return map[string]interface{}{
"ocis": map[string]interface{}{
"metadata_backend": cfg.Drivers.OCIS.MetadataBackend,
"root": cfg.Drivers.OCIS.Root,
"user_layout": "{{.Id.OpaqueId}}",
"treetime_accounting": false,
"treesize_accounting": false,
"permissionssvc": "com.owncloud.api.storage-system",
"permissionssvc": localEndpoint,
"max_acquire_lock_cycles": cfg.Drivers.OCIS.MaxAcquireLockCycles,
"lock_cycle_duration_factor": cfg.Drivers.OCIS.LockCycleDurationFactor,
"disable_versioning": true,
Expand Down

0 comments on commit 10764b4

Please sign in to comment.