Skip to content

Commit

Permalink
Space grants (cs3org#2464)
Browse files Browse the repository at this point in the history
* send spacegrants and pass them to decomposedfs

Signed-off-by: jkoberg <[email protected]>

* add changelog item

Signed-off-by: jkoberg <[email protected]>
  • Loading branch information
kobergj authored and butonic committed Feb 14, 2022
1 parent d07d63e commit bc20acb
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 6 deletions.
9 changes: 9 additions & 0 deletions changelog/unreleased/extract-space-grants.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Bugfix: pass spacegrants when adding member to space

When creating a space grant there should not be created a new space.
Unfortunately SpaceGrant didn't work when adding members to a space.
Now a value is placed in the ctx of the storageprovider on which decomposedfs reacts



https://github.com/cs3org/reva/pull/2464
9 changes: 9 additions & 0 deletions internal/grpc/services/storageprovider/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,15 @@ func (s *service) DenyGrant(ctx context.Context, req *provider.DenyGrantRequest)
}

func (s *service) AddGrant(ctx context.Context, req *provider.AddGrantRequest) (*provider.AddGrantResponse, error) {
// TODO: update CS3 APIs
if req.Opaque != nil {
_, spacegrant := req.Opaque.Map["spacegrant"]
if spacegrant {
ctx = context.WithValue(ctx, utils.SpaceGrant, struct{}{})
}

}

// check grantee type is valid
if req.Grant.Grantee.Type == provider.GranteeType_GRANTEE_TYPE_INVALID {
return &provider.AddGrantResponse{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,16 @@ func (h *Handler) addSpaceMember(w http.ResponseWriter, r *http.Request, info *p
return
}

// TODO: change CS3 APIs
opaque := &types.Opaque{
Map: map[string]*types.OpaqueEntry{
"spacegrant": {},
},
}

addGrantRes, err := providerClient.AddGrant(ctx, &provider.AddGrantRequest{
Ref: ref,
Opaque: opaque,
Ref: ref,
Grant: &provider.Grant{
Grantee: &grantee,
Permissions: role.CS3ResourcePermissions(),
Expand Down
6 changes: 2 additions & 4 deletions pkg/storage/utils/decomposedfs/grants.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@ import (
"github.com/cs3org/reva/pkg/storage/utils/ace"
"github.com/cs3org/reva/pkg/storage/utils/decomposedfs/node"
"github.com/cs3org/reva/pkg/storage/utils/decomposedfs/xattrs"
"github.com/cs3org/reva/pkg/utils"
"github.com/pkg/xattr"
)

// SpaceGrant is the key used to signal not to create a new space when a grant is assigned to a storage space.
var SpaceGrant struct{}

// DenyGrant denies access to a resource.
func (fs *Decomposedfs) DenyGrant(ctx context.Context, ref *provider.Reference, g *provider.Grantee) error {
return errtypes.NotSupported("decomposedfs: not supported")
Expand Down Expand Up @@ -71,7 +69,7 @@ func (fs *Decomposedfs) AddGrant(ctx context.Context, ref *provider.Reference, g
}

// when a grant is added to a space, do not add a new space under "shares"
if spaceGrant := ctx.Value(SpaceGrant); spaceGrant == nil {
if spaceGrant := ctx.Value(utils.SpaceGrant); spaceGrant == nil {
err := fs.createStorageSpace(ctx, "share", node.ID)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/utils/decomposedfs/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (fs *Decomposedfs) CreateStorageSpace(ctx context.Context, req *provider.Cr
},
}

ctx = context.WithValue(ctx, SpaceGrant, struct{}{})
ctx = context.WithValue(ctx, utils.SpaceGrant, struct{}{})

if err := fs.AddGrant(ctx, &provider.Reference{
ResourceId: resp.StorageSpace.Root,
Expand Down
3 changes: 3 additions & 0 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ var (

// PublicStorageProviderID is the id used by the sharestorageprovider
PublicStorageProviderID = "7993447f-687f-490d-875c-ac95e89a62a4"

// SpaceGrant is used to signal the storageprovider that the grant is on a space
SpaceGrant struct{}
)

// Skip evaluates whether a source endpoint contains any of the prefixes.
Expand Down

0 comments on commit bc20acb

Please sign in to comment.