mirror of
https://forge.liiib.re/indiehost/libre.sh/libre.sh.git
synced 2024-12-27 22:26:41 +00:00
feat: remove realm update & add display name
This commit is contained in:
parent
d62b133df2
commit
74ea9b1445
3 changed files with 9 additions and 14 deletions
|
@ -58,6 +58,9 @@ type RealmSpec struct {
|
|||
// Disable realm
|
||||
// +kubebuilder:validation:Optional
|
||||
Disable bool `json:"disable,omitempty"`
|
||||
// Display Name for realm, if not set default de Realm Name
|
||||
// +kubebuilder:validation:Optional
|
||||
DisplayName string `json:"displayName,omitempty"`
|
||||
// Realm host, if not set it will be provider host.
|
||||
// +kubebuilder:validation:Optional
|
||||
Host string `json:"host,omitempty"`
|
||||
|
|
2
go.mod
2
go.mod
|
@ -171,4 +171,4 @@ require (
|
|||
sigs.k8s.io/kustomize/api v0.15.0 // indirect
|
||||
sigs.k8s.io/kustomize/kyaml v0.15.0 // indirect
|
||||
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
|
||||
)
|
||||
)
|
|
@ -111,12 +111,12 @@ func (r *RealmReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
|
|||
return internal.HandleError(ctx, r, patcher, &realm, err)
|
||||
}
|
||||
|
||||
realmRepresentation, err := keycloakClient.GetRealm(ctx, keycloakClient.AccessToken(), realm.Name)
|
||||
_, err = keycloakClient.GetRealm(ctx, keycloakClient.AccessToken(), realm.Name)
|
||||
if err != nil {
|
||||
apiError := err.(*gocloak.APIError)
|
||||
if apiError.Code == 404 && apiError.Message == "404 Not Found: Realm not found." {
|
||||
log.Log.Info("Creating Realm")
|
||||
realmRepresentation = &gocloak.RealmRepresentation{}
|
||||
realmRepresentation := &gocloak.RealmRepresentation{}
|
||||
MutateRealmRepresentation(realm, realmRepresentation)
|
||||
_, err := keycloakClient.CreateRealm(ctx, keycloakClient.AccessToken(), *realmRepresentation)
|
||||
if err != nil {
|
||||
|
@ -128,13 +128,6 @@ func (r *RealmReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
|
|||
}
|
||||
}
|
||||
|
||||
r.log.Info("Updating Realm")
|
||||
MutateRealmRepresentation(realm, realmRepresentation)
|
||||
err = keycloakClient.UpdateRealm(ctx, keycloakClient.AccessToken(), *realmRepresentation)
|
||||
if err != nil {
|
||||
return internal.HandleError(ctx, r, patcher, &realm, err)
|
||||
}
|
||||
|
||||
secret := &corev1.Secret{}
|
||||
secret.Name = lshcore.IDPSecretName
|
||||
secret.Namespace = realm.Namespace
|
||||
|
@ -602,6 +595,9 @@ func MutateRealmRepresentation(realm keycloakv1alpha1.Realm, realmRepresentation
|
|||
realmRepresentation.Realm = &realm.Name
|
||||
realmRepresentation.Enabled = gocloak.BoolP(!realm.Spec.Disable)
|
||||
|
||||
if len(realm.Spec.DisplayName) > 0 {
|
||||
realmRepresentation.DisplayName = &realm.Spec.DisplayName
|
||||
}
|
||||
if len(realm.Spec.Themes.Login) > 0 {
|
||||
realmRepresentation.LoginTheme = &realm.Spec.Themes.Login
|
||||
}
|
||||
|
@ -616,7 +612,6 @@ func MutateRealmRepresentation(realm keycloakv1alpha1.Realm, realmRepresentation
|
|||
}
|
||||
|
||||
realmRepresentation.BruteForceProtected = gocloak.BoolP(!realm.Spec.DisableBruteForce)
|
||||
|
||||
realmRepresentation.InternationalizationEnabled = gocloak.BoolP(true)
|
||||
|
||||
// Set default
|
||||
|
@ -632,9 +627,6 @@ func MutateRealmRepresentation(realm keycloakv1alpha1.Realm, realmRepresentation
|
|||
realmRepresentation.SupportedLocales = &realm.Spec.Locale.Available
|
||||
|
||||
// Following fields are only set at creation, modifications made in ui will prevail
|
||||
if realmRepresentation.DisplayName == nil {
|
||||
realmRepresentation.DisplayName = &realm.Name
|
||||
}
|
||||
if realmRepresentation.DisplayNameHTML == nil {
|
||||
realmRepresentation.DisplayNameHTML = &realm.Name
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue