Skip to content

Commit

Permalink
allow listing all storage spaces
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 Dec 8, 2021
1 parent 3abd76e commit 11c7fea
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 26 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/spaces-registry-allow-list-all.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: allow listing all storage spaces

To implement the drives api we allow listing all spaces by sending a spaceid `*!*`. This is a workaround until a proper filter to list all storage spaces a user has access to / can manage is implemented, or we make that the implicit default filter.

https://github.com/cs3org/reva/pull/2344
53 changes: 27 additions & 26 deletions pkg/storage/registry/spaces/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ func (r *registry) ListProviders(ctx context.Context, filters map[string]string)
return r.findProvidersForResource(ctx, filters["storage_id"]+"!"+filters["opaque_id"]), nil
case filters["path"] != "":
return r.findProvidersForAbsolutePathReference(ctx, filters["path"]), nil
// TODO add filter for all spaces the user can manage?
}
return []*registrypb.ProviderInfo{}, nil
}
Expand All @@ -284,6 +285,7 @@ func (r *registry) ListProviders(ctx context.Context, filters map[string]string)
// for share spaces the res.StorageId tells the registry the spaceid and res.OpaqueId is a node in that space
func (r *registry) findProvidersForResource(ctx context.Context, id string) []*registrypb.ProviderInfo {
currentUser := ctxpkg.ContextMustGetUser(ctx)
providerInfos := []*registrypb.ProviderInfo{}
for address, provider := range r.c.Providers {
p := &registrypb.ProviderInfo{
Address: address,
Expand Down Expand Up @@ -312,36 +314,35 @@ func (r *registry) findProvidersForResource(ctx context.Context, id string) []*r
continue
}

switch len(spaces) {
case 0:
// nothing to do, will continue with next provider
case 1:
space := spaces[0]
for spaceType, sc := range provider.Spaces {
if spaceType == space.SpaceType {
providerPath, err := sc.SpacePath(currentUser, space)
if err != nil {
appctx.GetLogger(ctx).Error().Err(err).Interface("provider", provider).Interface("space", space).Msg("failed to execute template, continuing")
continue
}
spacePaths := map[string]string{
space.Id.OpaqueId: providerPath,
}
p.Opaque, err = spacePathsToOpaque(spacePaths)
if err != nil {
appctx.GetLogger(ctx).Debug().Err(err).Msg("marshaling space paths map failed, continuing")
continue
}
return []*registrypb.ProviderInfo{p}
}
// build the correct path for every space
spacePaths := map[string]string{}
for _, space := range spaces {
var sc *spaceConfig
var ok bool
if sc, ok = provider.Spaces[space.SpaceType]; !ok {
continue
}
spacePaths[space.Id.OpaqueId], err = sc.SpacePath(currentUser, space)
if err != nil {
appctx.GetLogger(ctx).Error().Err(err).Interface("provider", provider).Interface("space", space).Msg("failed to execute template, continuing")
continue
}
default:
// there should not be multiple spaces with the same id per provider
appctx.GetLogger(ctx).Error().Err(err).Interface("provider", provider).Interface("spaces", spaces).Msg("multiple spaces returned, ignoring")
}

if len(spacePaths) == 0 {
// do not add provider to result
continue
}

// add spaces to providerinfo
p.Opaque, err = spacePathsToOpaque(spacePaths)
if err != nil {
appctx.GetLogger(ctx).Debug().Err(err).Msg("marshaling space paths map failed, continuing")
continue
}
providerInfos = append(providerInfos, p)
}
return []*registrypb.ProviderInfo{}
return providerInfos
}

// findProvidersForAbsolutePathReference takes a path and ruturns the storage provider with the longest matching path prefix
Expand Down

0 comments on commit 11c7fea

Please sign in to comment.