fix smtp flow
[ZITADOPER-7]
This commit is contained in:
@@ -542,45 +542,10 @@ func (r *ZitadelClusterReconciler) reconcileSMTPConfig(ctx context.Context, zita
|
|||||||
return ctrl.Result{}, fmt.Errorf("Could add smtp trusted domain: %v", err)
|
return ctrl.Result{}, fmt.Errorf("Could add smtp trusted domain: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var smtpId string
|
resp, err := adminClient.GetEmailProvider(ctx, &adm.GetEmailProviderRequest{})
|
||||||
resp, err := adminClient.GetSMTPConfig(ctx, &adm.GetSMTPConfigRequest{})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !strings.Contains(err.Error(), "SMTP configuration not found") {
|
if strings.Contains(err.Error(), "not found") {
|
||||||
return ctrl.Result{}, fmt.Errorf("Error getting SMTP config: %v", err)
|
adminRequest := &adm.AddEmailProviderSMTPRequest{
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp != nil && resp.SmtpConfig != nil {
|
|
||||||
adminRequest := &adm.UpdateSMTPConfigRequest{
|
|
||||||
SenderAddress: zitadel.Spec.SMTPConfig.SenderAddress,
|
|
||||||
SenderName: zitadel.Spec.SMTPConfig.SenderName,
|
|
||||||
Tls: zitadel.Spec.SMTPConfig.TLS,
|
|
||||||
Host: zitadel.Spec.SMTPConfig.Host,
|
|
||||||
Id: resp.SmtpConfig.Id,
|
|
||||||
Password: "test",
|
|
||||||
Description: "autogenerated by k8s-operator",
|
|
||||||
}
|
|
||||||
if zitadel.Spec.SMTPConfig.User != nil && zitadel.Spec.SMTPConfig.Password != nil {
|
|
||||||
|
|
||||||
passwordSecret, err := r.RefResolver.SecretKeyRef(ctx, zitadel.Spec.SMTPConfig.Password.SecretKeyRef, zitadel.Namespace)
|
|
||||||
if err != nil {
|
|
||||||
return ctrl.Result{}, err
|
|
||||||
}
|
|
||||||
adminRequest.Password = passwordSecret
|
|
||||||
adminRequest.User = *zitadel.Spec.SMTPConfig.User
|
|
||||||
}
|
|
||||||
if zitadel.Spec.SMTPConfig.ReplyToAddress != nil {
|
|
||||||
adminRequest.ReplyToAddress = *zitadel.Spec.SMTPConfig.ReplyToAddress
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err = adminClient.UpdateSMTPConfig(ctx, adminRequest); err != nil {
|
|
||||||
if !strings.Contains(err.Error(), "No changes") {
|
|
||||||
return ctrl.Result{}, fmt.Errorf("Could not update SMTP config: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
smtpId = resp.SmtpConfig.Id
|
|
||||||
} else {
|
|
||||||
adminRequest := &adm.AddSMTPConfigRequest{
|
|
||||||
SenderAddress: zitadel.Spec.SMTPConfig.SenderAddress,
|
SenderAddress: zitadel.Spec.SMTPConfig.SenderAddress,
|
||||||
SenderName: zitadel.Spec.SMTPConfig.SenderName,
|
SenderName: zitadel.Spec.SMTPConfig.SenderName,
|
||||||
Tls: zitadel.Spec.SMTPConfig.TLS,
|
Tls: zitadel.Spec.SMTPConfig.TLS,
|
||||||
@@ -600,24 +565,54 @@ func (r *ZitadelClusterReconciler) reconcileSMTPConfig(ctx context.Context, zita
|
|||||||
adminRequest.ReplyToAddress = *zitadel.Spec.SMTPConfig.ReplyToAddress
|
adminRequest.ReplyToAddress = *zitadel.Spec.SMTPConfig.ReplyToAddress
|
||||||
}
|
}
|
||||||
|
|
||||||
addRes, err := adminClient.AddSMTPConfig(ctx, adminRequest)
|
addRes, err := adminClient.AddEmailProviderSMTP(ctx, adminRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ctrl.Result{}, fmt.Errorf("Could not add SMTP config: %v", err)
|
return ctrl.Result{}, fmt.Errorf("Could not add SMTP config: %v", err)
|
||||||
}
|
}
|
||||||
smtpId = addRes.Id
|
if _, err := adminClient.ActivateEmailProvider(ctx, &adm.ActivateEmailProviderRequest{
|
||||||
}
|
Id: addRes.Id,
|
||||||
|
|
||||||
if _, err := adminClient.ActivateSMTPConfig(ctx, &adm.ActivateSMTPConfigRequest{
|
|
||||||
Id: smtpId,
|
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
if !strings.Contains(err.Error(), "AlreadyActive") {
|
if !strings.Contains(err.Error(), "AlreadyActive") {
|
||||||
return ctrl.Result{}, fmt.Errorf("Error activating SMTP config: %v", err)
|
return ctrl.Result{}, fmt.Errorf("Error activating SMTP config: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return ctrl.Result{}, fmt.Errorf("Error getting SMTP config: %v", err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
adminRequest := &adm.UpdateEmailProviderSMTPRequest{
|
||||||
|
SenderAddress: zitadel.Spec.SMTPConfig.SenderAddress,
|
||||||
|
SenderName: zitadel.Spec.SMTPConfig.SenderName,
|
||||||
|
Tls: zitadel.Spec.SMTPConfig.TLS,
|
||||||
|
Host: zitadel.Spec.SMTPConfig.Host,
|
||||||
|
Id: resp.Config.Id,
|
||||||
|
Password: "test",
|
||||||
|
Description: "autogenerated by k8s-operator",
|
||||||
|
}
|
||||||
|
if zitadel.Spec.SMTPConfig.User != nil && zitadel.Spec.SMTPConfig.Password != nil {
|
||||||
|
|
||||||
|
passwordSecret, err := r.RefResolver.SecretKeyRef(ctx, zitadel.Spec.SMTPConfig.Password.SecretKeyRef, zitadel.Namespace)
|
||||||
|
if err != nil {
|
||||||
|
return ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
adminRequest.Password = passwordSecret
|
||||||
|
adminRequest.User = *zitadel.Spec.SMTPConfig.User
|
||||||
|
}
|
||||||
|
if zitadel.Spec.SMTPConfig.ReplyToAddress != nil {
|
||||||
|
adminRequest.ReplyToAddress = *zitadel.Spec.SMTPConfig.ReplyToAddress
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err = adminClient.UpdateEmailProviderSMTP(ctx, adminRequest); err != nil {
|
||||||
|
if !strings.Contains(err.Error(), "No changes") {
|
||||||
|
return ctrl.Result{}, fmt.Errorf("Could not update SMTP config: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
patch := client.MergeFrom(zitadel.DeepCopy())
|
patch := client.MergeFrom(zitadel.DeepCopy())
|
||||||
zitadel.Status.SMTPProviderId = smtpId
|
|
||||||
return ctrl.Result{}, r.Status().Patch(ctx, zitadel, patch)
|
return ctrl.Result{}, r.Status().Patch(ctx, zitadel, patch)
|
||||||
}
|
}
|
||||||
|
return ctrl.Result{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (r *ZitadelClusterReconciler) reconcileDomainPolicy(ctx context.Context, zitadel *zitadelv1alpha1.ZitadelCluster) (ctrl.Result, error) {
|
func (r *ZitadelClusterReconciler) reconcileDomainPolicy(ctx context.Context, zitadel *zitadelv1alpha1.ZitadelCluster) (ctrl.Result, error) {
|
||||||
adminClient, err := zitadelClient.NewAdminClient(ctx, zitadel, *r.RefResolver)
|
adminClient, err := zitadelClient.NewAdminClient(ctx, zitadel, *r.RefResolver)
|
||||||
|
|||||||
Reference in New Issue
Block a user