Skip to content
Snippets Groups Projects
Commit 6875b64c authored by Oded Ben-Ozer's avatar Oded Ben-Ozer
Browse files

Address issues raised in review:

- Rename some vars
- Cleanup some comments
- Tiny refactor to improve readability

Signed-off-by: default avatarOded Ben-Ozer <obenozer@wayfair.com>
parent 7f0056cf
No related branches found
No related tags found
No related merge requests found
...@@ -88,7 +88,7 @@ type Config struct { ...@@ -88,7 +88,7 @@ type Config struct {
GroupsKey string `json:"groups"` // defaults to "groups" GroupsKey string `json:"groups"` // defaults to "groups"
} `json:"claimMapping"` } `json:"claimMapping"`
// ClaimModifications holds all claim modifications options, current has only newGroupsFromClaims // ClaimModifications holds all claim modifications options
ClaimModifications struct { ClaimModifications struct {
NewGroupsFromClaims []NewGroupsFromClaims `json:"newGroupsFromClaims"` NewGroupsFromClaims []NewGroupsFromClaims `json:"newGroupsFromClaims"`
} `json:"claimModifications"` } `json:"claimModifications"`
...@@ -450,25 +450,26 @@ func (c *oidcConnector) createIdentity(ctx context.Context, identity connector.I ...@@ -450,25 +450,26 @@ func (c *oidcConnector) createIdentity(ctx context.Context, identity connector.I
} }
} }
for _, newGroupsElementConfig := range c.newGroupsFromClaims { for _, config := range c.newGroupsFromClaims {
newGroupsElement := []string{ newGroupSegments := []string{
newGroupsElementConfig.Prefix, config.Prefix,
} }
for _, claimName := range newGroupsElementConfig.ClaimList { for _, claimName := range config.ClaimList {
claimValue, ok := claims[claimName].(string)
// Non string claim value are ignored, concatenating them doesn't really make any sense // Non string claim value are ignored, concatenating them doesn't really make any sense
if claimValue, ok := claims[claimName].(string); ok { if !ok {
if newGroupsElementConfig.ClearDelimiter { continue
// Removing the delimiier string from the concatenated claim to ensure resulting claim structure
// is in full control of Dex operator
claimCleanedValue := strings.ReplaceAll(claimValue, newGroupsElementConfig.Delimiter, "")
newGroupsElement = append(newGroupsElement, claimCleanedValue)
} else {
newGroupsElement = append(newGroupsElement, claimValue)
}
} }
if config.ClearDelimiter {
// Removing the delimiter string from the concatenated claim to ensure resulting claim structure
// is in full control of Dex operator
claimValue = strings.ReplaceAll(claimValue, config.Delimiter, "")
}
newGroupSegments = append(newGroupSegments, claimValue)
} }
if len(newGroupsElement) > 1 {
groups = append(groups, strings.Join(newGroupsElement, newGroupsElementConfig.Delimiter)) if len(newGroupSegments) > 1 {
groups = append(groups, strings.Join(newGroupSegments, config.Delimiter))
} }
} }
......
...@@ -290,7 +290,7 @@ func TestHandleCallback(t *testing.T) { ...@@ -290,7 +290,7 @@ func TestHandleCallback(t *testing.T) {
}, },
}, },
{ {
name: "concatinateClaim", name: "newGroupFromClaims",
userIDKey: "", // not configured userIDKey: "", // not configured
userNameKey: "", // not configured userNameKey: "", // not configured
expectUserID: "subvalue", expectUserID: "subvalue",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment