Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance error handling for grappa REST drivers #1478

Merged
merged 1 commit into from
Feb 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/unreleased/grappa-drivers-errors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Enhancement: Enhance error handling for grappa REST drivers

https://github.com/cs3org/reva/pull/1478
23 changes: 14 additions & 9 deletions pkg/cbox/group/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,11 @@ func (m *manager) getInternalGroupID(ctx context.Context, gid *grouppb.GroupId)
}

func (m *manager) parseAndCacheGroup(ctx context.Context, groupData map[string]interface{}) *grouppb.Group {
id, _ := groupData["groupIdentifier"].(string)
name, _ := groupData["displayName"].(string)

groupID := &grouppb.GroupId{
OpaqueId: groupData["groupIdentifier"].(string),
OpaqueId: id,
Idp: m.conf.IDProvider,
}
gid, ok := groupData["gid"].(int64)
Expand All @@ -293,9 +296,9 @@ func (m *manager) parseAndCacheGroup(ctx context.Context, groupData map[string]i
}
g := &grouppb.Group{
Id: groupID,
GroupName: groupData["groupIdentifier"].(string),
Mail: groupData["groupIdentifier"].(string) + "@cern.ch",
DisplayName: groupData["displayName"].(string),
GroupName: id,
Mail: id + "@cern.ch",
DisplayName: name,
GidNumber: gid,
}

Expand Down Expand Up @@ -375,11 +378,13 @@ func (m *manager) findGroupsByFilter(ctx context.Context, url string, groups map
for _, grp := range groupData {
grpInfo, ok := grp.(map[string]interface{})
if !ok {
return errors.New("rest: error in type assertion")
continue
}
id, _ := grpInfo["groupIdentifier"].(string)
name, _ := grpInfo["displayName"].(string)

groupID := &grouppb.GroupId{
OpaqueId: grpInfo["groupIdentifier"].(string),
OpaqueId: id,
Idp: m.conf.IDProvider,
}
gid, ok := grpInfo["gid"].(int64)
Expand All @@ -388,9 +393,9 @@ func (m *manager) findGroupsByFilter(ctx context.Context, url string, groups map
}
groups[groupID.OpaqueId] = &grouppb.Group{
Id: groupID,
GroupName: grpInfo["groupIdentifier"].(string),
Mail: grpInfo["groupIdentifier"].(string) + "@cern.ch",
DisplayName: grpInfo["displayName"].(string),
GroupName: id,
Mail: id + "@cern.ch",
DisplayName: name,
GidNumber: gid,
}
}
Expand Down
34 changes: 21 additions & 13 deletions pkg/cbox/user/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,15 +287,19 @@ func (m *manager) getInternalUserID(ctx context.Context, uid *userpb.UserId) (st
}

func (m *manager) parseAndCacheUser(ctx context.Context, userData map[string]interface{}) *userpb.User {
upn, _ := userData["upn"].(string)
mail, _ := userData["primaryAccountEmail"].(string)
name, _ := userData["displayName"].(string)

userID := &userpb.UserId{
OpaqueId: userData["upn"].(string),
OpaqueId: upn,
Idp: m.conf.IDProvider,
}
u := &userpb.User{
Id: userID,
Username: userData["upn"].(string),
Mail: userData["primaryAccountEmail"].(string),
DisplayName: userData["displayName"].(string),
Username: upn,
Mail: mail,
DisplayName: name,
Opaque: &types.Opaque{
Map: map[string]*types.OpaqueEntry{
"uid": &types.OpaqueEntry{
Expand Down Expand Up @@ -384,22 +388,23 @@ func (m *manager) findUsersByFilter(ctx context.Context, url string, users map[s

for _, usr := range userData {
usrInfo, ok := usr.(map[string]interface{})
if !ok {
return errors.New("rest: error in type assertion")
}
if usrInfo["type"].(string) == "Application" || strings.HasPrefix(usrInfo["upn"].(string), "guest") {
if !ok || usrInfo["type"].(string) == "Application" || strings.HasPrefix(usrInfo["upn"].(string), "guest") {
continue
}

upn, _ := usrInfo["upn"].(string)
mail, _ := usrInfo["primaryAccountEmail"].(string)
name, _ := usrInfo["displayName"].(string)

uid := &userpb.UserId{
OpaqueId: usrInfo["upn"].(string),
OpaqueId: upn,
Idp: m.conf.IDProvider,
}
users[uid.OpaqueId] = &userpb.User{
Id: uid,
Username: usrInfo["upn"].(string),
Mail: usrInfo["primaryAccountEmail"].(string),
DisplayName: usrInfo["displayName"].(string),
Username: upn,
Mail: mail,
DisplayName: name,
Opaque: &types.Opaque{
Map: map[string]*types.OpaqueEntry{
"uid": &types.OpaqueEntry{
Expand Down Expand Up @@ -473,7 +478,10 @@ func (m *manager) GetUserGroups(ctx context.Context, uid *userpb.UserId) ([]stri
if !ok {
return nil, errors.New("rest: error in type assertion")
}
groups = append(groups, groupInfo["displayName"].(string))
name, ok := groupInfo["displayName"].(string)
if ok {
groups = append(groups, name)
}
}

if err = m.cacheUserGroups(uid, groups); err != nil {
Expand Down