@@ -14,6 +14,7 @@ import (
1414 lifecyclesubroutine "github.com/platform-mesh/golang-commons/controller/lifecycle/subroutine"
1515 "github.com/platform-mesh/golang-commons/errors"
1616 "github.com/platform-mesh/golang-commons/logger"
17+ "github.com/platform-mesh/security-operator/internal/config"
1718 apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
1819 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1920 ctrl "sigs.k8s.io/controller-runtime"
@@ -33,12 +34,14 @@ var (
3334type realmSubroutine struct {
3435 k8s client.Client
3536 baseDomain string
37+ cfg * config.Config
3638}
3739
38- func NewRealmSubroutine (k8s client.Client , baseDomain string ) * realmSubroutine {
40+ func NewRealmSubroutine (k8s client.Client , cfg * config. Config , baseDomain string ) * realmSubroutine {
3941 return & realmSubroutine {
4042 k8s ,
4143 baseDomain ,
44+ cfg ,
4245 }
4346}
4447
@@ -86,30 +89,60 @@ func (r *realmSubroutine) Process(ctx context.Context, instance lifecycleruntime
8689 return ctrl.Result {}, errors .NewOperatorError (fmt .Errorf ("failed to get workspace path" ), true , false )
8790 }
8891
89- patch := map [string ]interface {} {
90- "crossplane" : map [string ]interface {} {
91- "realm" : map [string ]interface {} {
92+ patch := map [string ]any {
93+ "crossplane" : map [string ]any {
94+ "realm" : map [string ]any {
9295 "name" : workspaceName ,
9396 "displayName" : workspaceName ,
9497 },
95- "client" : map [string ]interface {} {
98+ "client" : map [string ]any {
9699 "name" : workspaceName ,
97100 "displayName" : workspaceName ,
98101 "validRedirectUris" : []string {
99102 fmt .Sprintf ("https://%s.%s/callback*" , workspaceName , r .baseDomain ),
100103 },
101104 },
105+ "organization" : map [string ]any {
106+ "domain" : "example.com" , // TODO: change
107+ },
102108 },
103- "keycloakConfig" : map [string ]interface {} {
104- "client" : map [string ]interface {} {
109+ "keycloakConfig" : map [string ]any {
110+ "client" : map [string ]any {
105111 "name" : workspaceName ,
106- "targetSecret" : map [string ]interface {} {
112+ "targetSecret" : map [string ]any {
107113 "name" : fmt .Sprintf ("portal-client-secret-%s" , workspaceName ),
108114 },
109115 },
110116 },
111117 }
112118
119+ if r .cfg .IDP .SMTPServer != "" {
120+
121+ smtpConfig := map [string ]any {
122+ "host" : r .cfg .IDP .SMTPServer ,
123+ "port" : fmt .Sprintf ("%d" , r .cfg .IDP .SMTPPort ),
124+ "from" : r .cfg .IDP .FromAddress ,
125+ "ssl" : r .cfg .IDP .SSL ,
126+ "starttls" : r .cfg .IDP .StartTLS ,
127+ }
128+
129+ if r .cfg .IDP .SMTPUser != "" {
130+ smtpConfig ["auth" ] = map [string ]any {
131+ "username" : r .cfg .IDP .SMTPUser ,
132+ "passwordSecretRef" : map [string ]any {
133+ "namespace" : "platform-mesh-system" ,
134+ "name" : r .cfg .IDP .SMTPPasswordSecretName ,
135+ "key" : r .cfg .IDP .SMTPPasswordSecretKey ,
136+ },
137+ }
138+ }
139+
140+ err := unstructured .SetNestedField (patch , []any {smtpConfig }, "crossplane" , "realm" , "smtpConfig" )
141+ if err != nil {
142+ return ctrl.Result {}, errors .NewOperatorError (fmt .Errorf ("failed to set SMTP server config: %w" , err ), true , true )
143+ }
144+ }
145+
113146 marshalledPatch , err := json .Marshal (patch )
114147 if err != nil {
115148 return ctrl.Result {}, errors .NewOperatorError (fmt .Errorf ("failed to marshall patch map: %w" , err ), true , true )
0 commit comments