Skip to content

Commit

Permalink
use storageproviderid for space routing
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
  • Loading branch information
butonic committed Apr 28, 2022
1 parent 753492b commit 0241146
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
5 changes: 5 additions & 0 deletions changelog/unreleased/use-storageproviderid-for-routing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: use storageproviderid for spaces routing

We made the spaces registry aware of storageprovider ids and use them to route directly to the correct storageprovider

https://github.com/cs3org/reva/pull/?
11 changes: 10 additions & 1 deletion pkg/storage/registry/spaces/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"github.com/cs3org/reva/v2/pkg/sharedconf"
"github.com/cs3org/reva/v2/pkg/storage"
pkgregistry "github.com/cs3org/reva/v2/pkg/storage/registry/registry"
"github.com/cs3org/reva/v2/pkg/utils/resourceid"
"github.com/mitchellh/mapstructure"
"google.golang.org/grpc"
)
Expand Down Expand Up @@ -76,7 +77,8 @@ func (sc *spaceConfig) SpacePath(currentUser *userpb.User, space *providerpb.Sto
// Provider holds information on Spaces
type Provider struct {
// Spaces is a map from space type to space config
Spaces map[string]*spaceConfig `mapstructure:"spaces"`
Spaces map[string]*spaceConfig `mapstructure:"spaces"`
ProviderID string `mapstructure:"providerid"`
}

type templateData struct {
Expand Down Expand Up @@ -367,7 +369,14 @@ func (r *registry) findProvidersForFilter(ctx context.Context, filters []*provid
func (r *registry) findProvidersForResource(ctx context.Context, id string, findMoundpoint, findGrant bool) []*registrypb.ProviderInfo {
currentUser := ctxpkg.ContextMustGetUser(ctx)
providerInfos := []*registrypb.ProviderInfo{}
_, sdid := resourceid.StorageIDUnwrap(id)

for address, provider := range r.c.Providers {
// try to find provider based on storageproviderid prefix
if provider.ProviderID != "" && sdid != "" && provider.ProviderID != sdid {
// skip mismatching storageproviders
continue
}
p := &registrypb.ProviderInfo{
Address: address,
ProviderId: id,
Expand Down
6 changes: 6 additions & 0 deletions tests/oc-integration-tests/drone/gateway.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ driver = "spaces"
home_template = "/users/{{.Id.OpaqueId}}"

## obviously, we do not want to define a rule for every user and space, which is why we can define naming rules:
[grpc.services.storageregistry.drivers.spaces.providers."localhost:11000"]
providerid = "1284d238-aa92-42ce-bdc4-0b0000009157"
[grpc.services.storageregistry.drivers.spaces.providers."localhost:11000".spaces]
"personal" = { "mount_point" = "/users", "path_template" = "/users/{{.Space.Owner.Id.OpaqueId}}" }

Expand All @@ -67,6 +69,8 @@ home_template = "/users/{{.Id.OpaqueId}}"

## the virtual /Shares folder of every user is routed like this:
## whenever the path matches the pattern /users/{{.CurrentUser.Id.OpaqueId}}/Shares we forward requests to the sharesstorageprovider
[grpc.services.storageregistry.drivers.spaces.providers."localhost:14000"]
providerid = "a0ca6a90-a365-4782-871e-d44447bbc668"
[grpc.services.storageregistry.drivers.spaces.providers."localhost:14000".spaces]
"virtual" = { "mount_point" = "/users/{{.CurrentUser.Id.OpaqueId}}/Shares" }
"grant" = { "mount_point" = "." }
Expand All @@ -77,6 +81,8 @@ home_template = "/users/{{.Id.OpaqueId}}"

## While public shares are mounted at /public logged in end will should never see that path because it is only created by the spaces registry when
## a public link is accessed.
[grpc.services.storageregistry.drivers.spaces.providers."localhost:13000"]
providerid = "7993447f-687f-490d-875c-ac95e89a62a4"
[grpc.services.storageregistry.drivers.spaces.providers."localhost:13000".spaces]
"grant" = { "mount_point" = "." }
"mountpoint" = { "mount_point" = "/public", "path_template" = "/public/{{.Space.Root.OpaqueId}}" }
Expand Down
6 changes: 6 additions & 0 deletions tests/oc-integration-tests/local/gateway.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ driver = "spaces"
home_template = "/users/{{.Id.OpaqueId}}"

## obviously, we do not want to define a rule for every user and space, which is why we can define naming rules:
[grpc.services.storageregistry.drivers.spaces.providers."localhost:11000"]
providerid = "1284d238-aa92-42ce-bdc4-0b0000009157"
[grpc.services.storageregistry.drivers.spaces.providers."localhost:11000".spaces]
"personal" = { "mount_point" = "/users", "path_template" = "/users/{{.Space.Owner.Id.OpaqueId}}" }

Expand All @@ -73,6 +75,8 @@ home_template = "/users/{{.Id.OpaqueId}}"

## the virtual /Shares folder of every user is routed like this:
## whenever the path matches the pattern /users/{{.CurrentUser.Id.OpaqueId}}/Shares we forward requests to the sharesstorageprovider
[grpc.services.storageregistry.drivers.spaces.providers."localhost:14000"]
providerid = "a0ca6a90-a365-4782-871e-d44447bbc668"
[grpc.services.storageregistry.drivers.spaces.providers."localhost:14000".spaces]
"virtual" = { "mount_point" = "/users/{{.CurrentUser.Id.OpaqueId}}/Shares" }
"grant" = { "mount_point" = "." }
Expand All @@ -83,6 +87,8 @@ home_template = "/users/{{.Id.OpaqueId}}"

## While public shares are mounted at /public logged in end will should never see that path because it is only created by the spaces registry when
## a public link is accessed.
[grpc.services.storageregistry.drivers.spaces.providers."localhost:13000"]
providerid = "7993447f-687f-490d-875c-ac95e89a62a4"
[grpc.services.storageregistry.drivers.spaces.providers."localhost:13000".spaces]
"grant" = { "mount_point" = "." }
"mountpoint" = { "mount_point" = "/public", "path_template" = "/public/{{.Space.Root.OpaqueId}}" }
Expand Down

0 comments on commit 0241146

Please sign in to comment.