Skip to content

Commit

Permalink
Fix template in eoshomewrapper to use context user rather than resour…
Browse files Browse the repository at this point in the history
…ce (#1865)
  • Loading branch information
ishank011 authored Jul 6, 2021
1 parent a2b1507 commit c780366
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
3 changes: 3 additions & 0 deletions changelog/unreleased/eoshomewrapper-template-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Bugfix: Fix template in eoshomewrapper to use context user rather than resource

https://github.com/cs3org/reva/pull/1885
4 changes: 2 additions & 2 deletions pkg/cbox/group/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (m *manager) getGroupByParam(ctx context.Context, param, val string) (map[s
return nil, err
}
if len(responseData) != 1 {
return nil, errors.New("rest: group not found")
return nil, errors.New("rest: group not found: " + param + ":" + val)
}

userData, ok := responseData[0].(map[string]interface{})
Expand Down Expand Up @@ -227,7 +227,7 @@ func (m *manager) GetGroupByClaim(ctx context.Context, claim, value string) (*gr
case "group_name":
claim = "groupIdentifier"
default:
return nil, errors.New("rest: invalid field")
return nil, errors.New("rest: invalid field: " + claim)
}

groupData, err := m.getGroupByParam(ctx, claim, value)
Expand Down
13 changes: 6 additions & 7 deletions pkg/cbox/storage/eoshomewrapper/eoshomewrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/cs3org/reva/pkg/storage"
"github.com/cs3org/reva/pkg/storage/fs/registry"
"github.com/cs3org/reva/pkg/storage/utils/eosfs"
"github.com/cs3org/reva/pkg/user"
"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -55,7 +56,7 @@ func parseConfig(m map[string]interface{}) (*eosfs.Config, string, error) {

t, ok := m["mount_id_template"].(string)
if !ok || t == "" {
t = "eoshome-{{ trimAll \"/\" .Path | substr 0 1 }}"
t = "eoshome-{{substr 0 1 .Username}}"
}

return c, t, nil
Expand Down Expand Up @@ -94,8 +95,8 @@ func (w *wrapper) GetMD(ctx context.Context, ref *provider.Reference, mdKeys []s

// We need to extract the mount ID based on the mapping template.
//
// Take the first letter of the resource path after the namespace has been removed.
// If it's empty, leave it empty to be filled by storageprovider.
// Take the first letter of the username of the logged-in user, as the home
// storage provider restricts requests only to the home namespace.
res.Id.StorageId = w.getMountID(ctx, res)
return res, nil
}
Expand All @@ -112,11 +113,9 @@ func (w *wrapper) ListFolder(ctx context.Context, ref *provider.Reference, mdKey
}

func (w *wrapper) getMountID(ctx context.Context, r *provider.ResourceInfo) string {
if r == nil {
return ""
}
u := user.ContextMustGetUser(ctx)
b := bytes.Buffer{}
if err := w.mountIDTemplate.Execute(&b, r); err != nil {
if err := w.mountIDTemplate.Execute(&b, u); err != nil {
return ""
}
return b.String()
Expand Down
6 changes: 3 additions & 3 deletions pkg/cbox/user/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (m *manager) getUserByParam(ctx context.Context, param, val string) (map[st
return nil, err
}
if len(responseData) != 1 {
return nil, errors.New("rest: user not found")
return nil, errors.New("rest: user not found: " + param + ":" + val)
}

userData, ok := responseData[0].(map[string]interface{})
Expand Down Expand Up @@ -230,7 +230,7 @@ func (m *manager) GetUserByClaim(ctx context.Context, claim, value string) (*use
case "username":
claim = "upn"
default:
return nil, errors.New("rest: invalid field")
return nil, errors.New("rest: invalid field: " + claim)
}

userData, err := m.getUserByParam(ctx, claim, value)
Expand Down Expand Up @@ -294,7 +294,7 @@ func (m *manager) FindUsers(ctx context.Context, query string) ([]*userpb.User,
case emailRegex.MatchString(query):
filters = []string{"primaryAccountEmail"}
default:
return nil, errors.New("rest: illegal characters present in query")
return nil, errors.New("rest: illegal characters present in query: " + query)
}

users := make(map[string]*userpb.User)
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import (
var (
matchFirstCap = regexp.MustCompile("(.)([A-Z][a-z]+)")
matchAllCap = regexp.MustCompile("([a-z0-9])([A-Z])")
matchEmail = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")
matchEmail = regexp.MustCompile(`^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$`)
// GlobalRegistry configures a service registry globally accessible. It defaults to a memory registry. The usage of
// globals is not encouraged, and this is a workaround until the PR is out of a draft state.
GlobalRegistry registry.Registry = memory.New(map[string]interface{}{})
Expand Down

0 comments on commit c780366

Please sign in to comment.