Skip to content

Commit b5496e7

Browse files
zmotsodougkirkley
authored andcommitted
feat: Add support for list of attributes with the same key
Signed-off-by: Douglass Kirkley <doug.kirkley@gmail.com>
1 parent aed0c7b commit b5496e7

26 files changed

+564
-69
lines changed

api/v1/keycloakclient_types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,17 @@ type ServiceAccount struct {
213213
ClientRoles []UserClientRole `json:"clientRoles,omitempty"`
214214

215215
// Attributes is a map of service account attributes.
216+
// Deprecated: Use AttributesV2 instead.
216217
// +nullable
217218
// +optional
218219
Attributes map[string]string `json:"attributes,omitempty"`
219220

221+
// AttributesV2 is a map of service account attributes.
222+
// this multi-value attributes
223+
// +nullable
224+
// +optional
225+
AttributesV2 map[string][]string `json:"attributesV2,omitempty"`
226+
220227
// Groups is a list of groups assigned to service account
221228
// +nullable
222229
// +optional

api/v1/keycloakrealmuser_types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,17 @@ type KeycloakRealmUserSpec struct {
5656
Groups []string `json:"groups,omitempty"`
5757

5858
// Attributes is a map of user attributes.
59+
// Deprecated: Use AttributesV2 instead.
5960
// +nullable
6061
// +optional
6162
Attributes map[string]string `json:"attributes,omitempty"`
6263

64+
// AttributesV2 is a map of service account attributes.
65+
// this multi-value attributes
66+
// +nullable
67+
// +optional
68+
AttributesV2 map[string][]string `json:"attributesV2,omitempty"`
69+
6370
// ReconciliationStrategy is a strategy for reconciliation. Possible values: full, create-only.
6471
// Default value: full. If set to create-only, user will be created only if it does not exist. If user exists, it will not be updated.
6572
// If set to full, user will be created if it does not exist, or updated if it exists.

api/v1/zz_generated.deepcopy.go

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/v1.edp.epam.com_keycloakclients.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,19 @@ spec:
613613
attributes:
614614
additionalProperties:
615615
type: string
616-
description: Attributes is a map of service account attributes.
616+
description: |-
617+
Attributes is a map of service account attributes.
618+
Deprecated: Use AttributesV2 instead.
619+
nullable: true
620+
type: object
621+
attributesV2:
622+
additionalProperties:
623+
items:
624+
type: string
625+
type: array
626+
description: |-
627+
AttributesV2 is a map of service account attributes.
628+
this multi-value attributes
617629
nullable: true
618630
type: object
619631
clientRoles:

config/crd/bases/v1.edp.epam.com_keycloakrealmusers.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,19 @@ spec:
4747
attributes:
4848
additionalProperties:
4949
type: string
50-
description: Attributes is a map of user attributes.
50+
description: |-
51+
Attributes is a map of user attributes.
52+
Deprecated: Use AttributesV2 instead.
53+
nullable: true
54+
type: object
55+
attributesV2:
56+
additionalProperties:
57+
items:
58+
type: string
59+
type: array
60+
description: |-
61+
AttributesV2 is a map of service account attributes.
62+
this multi-value attributes
5163
nullable: true
5264
type: object
5365
clientRoles:

deploy-templates/crds/v1.edp.epam.com_keycloakclients.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,19 @@ spec:
613613
attributes:
614614
additionalProperties:
615615
type: string
616-
description: Attributes is a map of service account attributes.
616+
description: |-
617+
Attributes is a map of service account attributes.
618+
Deprecated: Use AttributesV2 instead.
619+
nullable: true
620+
type: object
621+
attributesV2:
622+
additionalProperties:
623+
items:
624+
type: string
625+
type: array
626+
description: |-
627+
AttributesV2 is a map of service account attributes.
628+
this multi-value attributes
617629
nullable: true
618630
type: object
619631
clientRoles:

deploy-templates/crds/v1.edp.epam.com_keycloakrealmusers.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,19 @@ spec:
4747
attributes:
4848
additionalProperties:
4949
type: string
50-
description: Attributes is a map of user attributes.
50+
description: |-
51+
Attributes is a map of user attributes.
52+
Deprecated: Use AttributesV2 instead.
53+
nullable: true
54+
type: object
55+
attributesV2:
56+
additionalProperties:
57+
items:
58+
type: string
59+
type: array
60+
description: |-
61+
AttributesV2 is a map of service account attributes.
62+
this multi-value attributes
5163
nullable: true
5264
type: object
5365
clientRoles:

docs/api.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3394,7 +3394,16 @@ ServiceAccount is a service account configuration.
33943394
<td><b>attributes</b></td>
33953395
<td>map[string]string</td>
33963396
<td>
3397-
Attributes is a map of service account attributes.<br/>
3397+
Attributes is a map of service account attributes.
3398+
Deprecated: Use AttributesV2 instead.<br/>
3399+
</td>
3400+
<td>false</td>
3401+
</tr><tr>
3402+
<td><b>attributesV2</b></td>
3403+
<td>map[string][]string</td>
3404+
<td>
3405+
AttributesV2 is a map of service account attributes.
3406+
this multi-value attributes<br/>
33983407
</td>
33993408
<td>false</td>
34003409
</tr><tr>
@@ -6496,7 +6505,16 @@ KeycloakRealmUserSpec defines the desired state of KeycloakRealmUser.
64966505
<td><b>attributes</b></td>
64976506
<td>map[string]string</td>
64986507
<td>
6499-
Attributes is a map of user attributes.<br/>
6508+
Attributes is a map of user attributes.
6509+
Deprecated: Use AttributesV2 instead.<br/>
6510+
</td>
6511+
<td>false</td>
6512+
</tr><tr>
6513+
<td><b>attributesV2</b></td>
6514+
<td>map[string][]string</td>
6515+
<td>
6516+
AttributesV2 is a map of service account attributes.
6517+
this multi-value attributes<br/>
65006518
</td>
65016519
<td>false</td>
65026520
</tr><tr>

internal/controller/keycloakclient/chain/service_account.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ func (el *ServiceAccount) Serve(_ context.Context, keycloakClient *keycloakApi.K
4545
}
4646
}
4747

48-
if keycloakClient.Spec.ServiceAccount.Attributes != nil {
48+
if keycloakClient.Spec.ServiceAccount.AttributesV2 != nil {
4949
if err := el.keycloakApiClient.SetServiceAccountAttributes(realmName, keycloakClient.Status.ClientID,
50-
keycloakClient.Spec.ServiceAccount.Attributes, addOnly); err != nil {
50+
keycloakClient.Spec.ServiceAccount.AttributesV2, addOnly); err != nil {
5151
return errors.Wrap(err, "unable to set service account attributes")
5252
}
5353
}

internal/controller/keycloakclient/chain/service_account_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ func TestServiceAccount_Serve(t *testing.T) {
2020
},
2121
ServiceAccount: &keycloakApi.ServiceAccount{
2222
Enabled: true,
23-
Attributes: map[string]string{
24-
"foo": "bar",
23+
AttributesV2: map[string][]string{
24+
"foo": {"bar"},
2525
},
2626
ClientRoles: []keycloakApi.UserClientRole{
2727
{
@@ -48,7 +48,7 @@ func TestServiceAccount_Serve(t *testing.T) {
4848
apiClient.On("SyncServiceAccountGroups", realmName, kc.Status.ClientID,
4949
kc.Spec.ServiceAccount.Groups, false).Return(nil)
5050
apiClient.On("SetServiceAccountAttributes", realmName, kc.Status.ClientID,
51-
kc.Spec.ServiceAccount.Attributes, false).Return(nil)
51+
kc.Spec.ServiceAccount.AttributesV2, false).Return(nil)
5252

5353
sa := NewServiceAccount(apiClient)
5454

0 commit comments

Comments
 (0)