Skip to content

Commit

Permalink
Address issues raised in review:
Browse files Browse the repository at this point in the history
- Rename some vars
- Cleanup some comments
- Tiny refactor to improve readability

Signed-off-by: Oded Ben-Ozer <[email protected]>
  • Loading branch information
Oded-B committed Oct 9, 2023
1 parent 7f0056c commit 6875b64
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
33 changes: 17 additions & 16 deletions connector/oidc/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ type Config struct {
GroupsKey string `json:"groups"` // defaults to "groups"
} `json:"claimMapping"`

// ClaimModifications holds all claim modifications options, current has only newGroupsFromClaims
// ClaimModifications holds all claim modifications options
ClaimModifications struct {
NewGroupsFromClaims []NewGroupsFromClaims `json:"newGroupsFromClaims"`
} `json:"claimModifications"`
Expand Down Expand Up @@ -450,25 +450,26 @@ func (c *oidcConnector) createIdentity(ctx context.Context, identity connector.I
}
}

for _, newGroupsElementConfig := range c.newGroupsFromClaims {
newGroupsElement := []string{
newGroupsElementConfig.Prefix,
for _, config := range c.newGroupsFromClaims {
newGroupSegments := []string{
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
if claimValue, ok := claims[claimName].(string); ok {
if newGroupsElementConfig.ClearDelimiter {
// 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 !ok {
continue
}
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))
}
}

Expand Down
2 changes: 1 addition & 1 deletion connector/oidc/oidc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func TestHandleCallback(t *testing.T) {
},
},
{
name: "concatinateClaim",
name: "newGroupFromClaims",
userIDKey: "", // not configured
userNameKey: "", // not configured
expectUserID: "subvalue",
Expand Down

0 comments on commit 6875b64

Please sign in to comment.