package controllers import ( keycloakv1alpha1 "git.zom.bi/images/keycloak-operator/api/v1alpha1" "github.com/Nerzal/gocloak/v7" ) // ConvertToRealm takes a CRD representation and converts it into a datatype // that can be understood by GoCloak. func ConvertToRealm(realmCrd keycloakv1alpha1.KeycloakRealm) (gocloak.RealmRepresentation, error) { var realm gocloak.RealmRepresentation realmSpec := realmCrd.Spec // Mandatory Properties realm.Realm = &realmSpec.RealmName // Optional Properties realm.Enabled = realmSpec.Enabled realm.DisplayName = realmSpec.DisplayName realm.DisplayNameHTML = realmSpec.DisplayNameHTML realm.LoginTheme = realmSpec.LoginTheme realm.LoginWithEmailAllowed = realmSpec.LoginWithEmailAllowed realm.RegistrationAllowed = realmSpec.RegistrationAllowed realm.EditUsernameAllowed = realmSpec.EditUsernameAllowed realm.RegistrationEmailAsUsername = realmSpec.RegistrationEmailAsUsername realm.ResetPasswordAllowed = realmSpec.ResetPasswordAllowed realm.DuplicateEmailsAllowed = realmSpec.DuplicateEmailsAllowed realm.VerifyEmail = realmSpec.VerifyEmail realm.RememberMe = realmSpec.RememberMe if realmSpec.SMTP != nil { smtp := map[string]string{} if realmSpec.SMTP.Auth { smtp["auth"] = "true" } if realmSpec.SMTP.Secret != nil { // TODO } if realmSpec.SMTP.From != "" { smtp["from"] = realmSpec.SMTP.From } realm.SMTPServer = &smtp } //realm.AccessCodeLifespan = "" //realm.AccessCodeLifespanLogin = "" //realm.AccessCodeLifespanUserAction = "" //realm.AccessTokenLifespan = "" //realm.AccessTokenLifespanForImplicitFlow = "" //realm.AccountTheme = "" //realm.ActionTokenGeneratedByAdminLifespan = "" //realm.ActionTokenGeneratedByUserLifespan = "" //realm.AdminEventsDetailsEnabled = "" //realm.AdminEventsEnabled = "" //realm.AdminTheme = "" //realm.Attributes = "" //realm.AuthenticationFlows = "" //realm.AuthenticatorConfig = "" //realm.BrowserFlow = "" //realm.BrowserSecurityHeaders = "" //realm.BruteForceProtected = "" //realm.ClientAuthenticationFlow = "" //realm.ClientScopeMappings = "" //realm.ClientScopes = "" //realm.Clients = "" //realm.Components = "" //realm.DefaultDefaultClientScopes = "" //realm.DefaultGroups = "" //realm.DefaultLocale = "" //realm.DefaultOptionalClientScopes = "" //realm.DefaultRoles = "" //realm.DefaultSignatureAlgorithm = "" //realm.DirectGrantFlow = "" //realm.DockerAuthenticationFlow = "" //realm.EmailTheme = "" //realm.EnabledEventTypes = "" //realm.EventsEnabled = "" //realm.EventsExpiration = "" //realm.EventsListeners = "" //realm.FailureFactor = "" //realm.FederatedUsers = "" //realm.Groups = "" //realm.ID = "" //realm.IdentityProviderMappers = "" //realm.IdentityProviders = "" //realm.InternationalizationEnabled = "" //realm.KeycloakVersion = "" //realm.MaxDeltaTimeSeconds = "" //realm.MaxFailureWaitSeconds = "" //realm.MinimumQuickLoginWaitSeconds = "" //realm.NotBefore = "" //realm.OfflineSessionIdleTimeout = "" //realm.OfflineSessionMaxLifespan = "" //realm.OfflineSessionMaxLifespanEnabled = "" //realm.OtpPolicyAlgorithm = "" //realm.OtpPolicyDigits = "" //realm.OtpPolicyInitialCounter = "" //realm.OtpPolicyLookAheadWindow = "" //realm.OtpPolicyPeriod = "" //realm.OtpPolicyType = "" //realm.OtpSupportedApplications = "" //realm.PasswordPolicy = "" //realm.PermanentLockout = "" //realm.ProtocolMappers = "" //realm.QuickLoginCheckMilliSeconds = "" //realm.RefreshTokenMaxReuse = "" //realm.RegistrationFlow = "" //realm.RequiredActions = "" //realm.ResetCredentialsFlow = "" //realm.RevokeRefreshToken = "" //realm.Roles = "" //realm.ScopeMappings = "" //realm.SMTPServer = "" //realm.SslRequired = "" //realm.SsoSessionIdleTimeout = "" //realm.SsoSessionIdleTimeoutRememberMe = "" //realm.SsoSessionMaxLifespan = "" //realm.SsoSessionMaxLifespanRememberMe = "" //realm.SupportedLocales = "" //realm.UserFederationMappers = "" //realm.UserFederationProviders = "" //realm.UserManagedAccessAllowed = "" //realm.Users = "" //realm.WaitIncrementSeconds = "" return realm, nil }