keycloak-operator/controllers/keycloakclient.go

63 lines
2.1 KiB
Go
Raw Permalink Normal View History

2021-01-11 06:32:28 +01:00
package controllers
import (
keycloakv1alpha1 "git.zom.bi/images/keycloak-operator/api/v1alpha1"
"github.com/Nerzal/gocloak/v7"
)
// ConvertToClient takes a CRD representation and converts it into a datatype
// that can be understood by GoCloak.
func ConvertToClient(clientCrd keycloakv1alpha1.KeycloakClient) (gocloak.Client, error) {
var client gocloak.Client
clientSpec := clientCrd.Spec
// Mandatory Properties
client.ClientID = &clientSpec.ClientID
// Optional Properties
client.Enabled = clientSpec.Enabled
client.Name = clientSpec.Name
client.Description = clientSpec.Description
client.Protocol = clientSpec.Protocol
client.ClientAuthenticatorType = clientSpec.ClientAuthenticatorType
client.DirectAccessGrantsEnabled = clientSpec.DirectAccessGrantsEnabled
client.PublicClient = clientSpec.PublicClient
client.ImplicitFlowEnabled = clientSpec.ImplicitFlowEnabled
client.StandardFlowEnabled = clientSpec.StandardFlowEnabled
client.ServiceAccountsEnabled = clientSpec.ServiceAccountsEnabled
client.RegistrationAccessToken = clientSpec.RegistrationAccessToken
client.SurrogateAuthRequired = clientSpec.SurrogateAuthRequired
client.BearerOnly = clientSpec.BearerOnly
client.ConsentRequired = clientSpec.ConsentRequired
client.DefaultClientScopes = clientSpec.DefaultClientScopes
client.OptionalClientScopes = clientSpec.OptionalClientScopes
client.BaseURL = clientSpec.BaseURL
client.RootURL = clientSpec.RootURL
client.AdminURL = clientSpec.AdminURL
client.RedirectURIs = clientSpec.RedirectURIs
client.WebOrigins = clientSpec.WebOrigins
if clientSpec.Secret != nil {
// TODO
// client.Secret = ""
}
// client.Access = ""
// client.Attributes = ""
// client.AuthenticationFlowBindingOverrides = ""
// client.AuthorizationServicesEnabled = ""
// client.AuthorizationSettings = ""
// client.DefaultRoles = ""
// client.FrontChannelLogout = ""
// client.FullScopeAllowed = ""
// client.ID = ""
// client.NodeReRegistrationTimeout = ""
// client.NotBefore = ""
// client.Origin = ""
// client.ProtocolMappers = ""
// client.RegisteredNodes = ""
return client, nil
}