Skip to content

Commit 200c870

Browse files
committed
feat: Add adminEventsExpiration to KeycloakRealm realmEventConfig (#122)
1 parent 17d376a commit 200c870

16 files changed

+152
-23
lines changed

api/v1/keycloakrealm_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ type RealmEventConfig struct {
110110
// +optional
111111
AdminEventsEnabled bool `json:"adminEventsEnabled,omitempty"`
112112

113+
// AdminEventsExpiration sets the expiration for events in seconds.
114+
// Expired events are periodically deleted from the database.
115+
// +optional
116+
AdminEventsExpiration int `json:"adminEventsExpiration,omitempty"`
117+
113118
// EnabledEventTypes is a list of event types to enable.
114119
// +optional
115120
// +nullable.

api/v1/zz_generated.deepcopy.go

Lines changed: 52 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha1/clusterkeycloakrealm_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ type RealmEventConfig struct {
119119
// +optional
120120
AdminEventsEnabled bool `json:"adminEventsEnabled,omitempty"`
121121

122+
// AdminEventsExpiration sets the expiration for events in seconds.
123+
// Expired events are periodically deleted from the database.
124+
// +optional
125+
AdminEventsExpiration int `json:"adminEventsExpiration,omitempty"`
126+
122127
// EnabledEventTypes is a list of event types to enable.
123128
// +optional
124129
// +nullable.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ spec:
127127
description: AdminEventsEnabled indicates whether to enable admin
128128
events.
129129
type: boolean
130+
adminEventsExpiration:
131+
description: |-
132+
AdminEventsExpiration sets the expiration for events in seconds.
133+
Expired events are periodically deleted from the database.
134+
type: integer
130135
enabledEventTypes:
131136
description: EnabledEventTypes is a list of event types to enable.
132137
items:

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ spec:
132132
description: AdminEventsEnabled indicates whether to enable admin
133133
events.
134134
type: boolean
135+
adminEventsExpiration:
136+
description: |-
137+
AdminEventsExpiration sets the expiration for events in seconds.
138+
Expired events are periodically deleted from the database.
139+
type: integer
135140
enabledEventTypes:
136141
description: EnabledEventTypes is a list of event types to enable.
137142
items:

controllers/clusterkeycloakrealm/chain/put_realm_settings.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ func (h PutRealmSettings) ServeRequest(ctx context.Context, realm *v1alpha1.Clus
6767

6868
settings.TokenSettings = adapter.ToRealmTokenSettings(realm.Spec.TokenSettings)
6969

70+
if realm.Spec.RealmEventConfig != nil && realm.Spec.RealmEventConfig.AdminEventsEnabled {
71+
specCopy := realm.Spec.DeepCopy()
72+
73+
settings.AdminEventsExpiration = &specCopy.RealmEventConfig.AdminEventsExpiration
74+
}
75+
7076
if err := kClient.UpdateRealmSettings(realm.Spec.RealmName, &settings); err != nil {
7177
return errors.Wrap(err, "unable to update realm settings")
7278
}

controllers/clusterkeycloakrealm/clusterkeycloakrealm_controller_integration_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ var _ = Describe("ClusterKeycloakRealm controller", func() {
3939
},
4040
DisplayName: "Test Realm",
4141
DisplayHTMLName: "<b>Test Realm</b>",
42+
RealmEventConfig: &keycloakAlpha.RealmEventConfig{
43+
AdminEventsEnabled: true,
44+
AdminEventsExpiration: 100,
45+
},
4246
},
4347
}
4448
Expect(k8sClient.Create(ctx, keycloakRealm)).Should(Succeed())

controllers/keycloakclient/chain/put_client_admin_fine_grained_perms.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
const (
1515
// RealmManagementClient built-in Keycloak client for the realm
16-
// This client manages admin fine-grained permissions for other clients
16+
// This client manages admin fine-grained permissions for other clients.
1717
RealmManagementClient = "realm-management"
1818
)
1919

controllers/keycloakrealm/chain/realm_settings.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ func (h RealmSettings) ServeRequest(ctx context.Context, realm *keycloakApi.Keyc
5858

5959
settings.TokenSettings = adapter.ToRealmTokenSettings(realm.Spec.TokenSettings)
6060

61+
if realm.Spec.RealmEventConfig != nil && realm.Spec.RealmEventConfig.AdminEventsEnabled {
62+
specCopy := realm.Spec.DeepCopy()
63+
64+
settings.AdminEventsExpiration = &specCopy.RealmEventConfig.AdminEventsExpiration
65+
}
66+
6167
if err := kClient.UpdateRealmSettings(realm.Spec.RealmName, &settings); err != nil {
6268
return errors.Wrap(err, "unable to update realm settings")
6369
}

controllers/keycloakrealm/chain/realm_settings_test.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/pkg/errors"
99
"github.com/stretchr/testify/mock"
1010
"github.com/stretchr/testify/require"
11+
"k8s.io/utils/ptr"
1112

1213
keycloakApi "github.com/epam/edp-keycloak-operator/api/v1"
1314
"github.com/epam/edp-keycloak-operator/pkg/client/keycloak/adapter"
@@ -37,7 +38,9 @@ func TestRealmSettings_ServeRequest(t *testing.T) {
3738
"foo": "bar",
3839
},
3940
RealmEventConfig: &keycloakApi.RealmEventConfig{
40-
EventsListeners: []string{"foo", "bar"},
41+
EventsListeners: []string{"foo", "bar"},
42+
AdminEventsEnabled: true,
43+
AdminEventsExpiration: 100,
4144
},
4245
PasswordPolicies: []keycloakApi.PasswordPolicy{
4346
{Type: "foo", Value: "bar"},
@@ -57,20 +60,23 @@ func TestRealmSettings_ServeRequest(t *testing.T) {
5760
PasswordPolicies: []adapter.PasswordPolicy{
5861
{Type: "foo", Value: "bar"},
5962
},
60-
DisplayHTMLName: realm.Spec.DisplayHTMLName,
61-
FrontendURL: realm.Spec.FrontendURL,
62-
DisplayName: realm.Spec.DisplayName,
63+
DisplayHTMLName: realm.Spec.DisplayHTMLName,
64+
FrontendURL: realm.Spec.FrontendURL,
65+
DisplayName: realm.Spec.DisplayName,
66+
AdminEventsExpiration: ptr.To(100),
6367
}).Return(nil)
6468

6569
kClient.On("SetRealmEventConfig", realm.Spec.RealmName, &adapter.RealmEventConfig{
66-
EventsListeners: []string{"foo", "bar"},
70+
EventsListeners: []string{"foo", "bar"},
71+
AdminEventsEnabled: true,
6772
}).Return(nil).Once()
6873

6974
err = rs.ServeRequest(ctx, &realm, kClient)
7075
require.NoError(t, err)
7176

7277
kClient.On("SetRealmEventConfig", realm.Spec.RealmName, &adapter.RealmEventConfig{
73-
EventsListeners: []string{"foo", "bar"},
78+
EventsListeners: []string{"foo", "bar"},
79+
AdminEventsEnabled: true,
7480
}).Return(errors.New("event config fatal")).Once()
7581
kClient.On("UpdateRealmSettings", mock.Anything, mock.Anything).Return(nil)
7682

0 commit comments

Comments
 (0)