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)
|
||||
}
|
||||
}
|
||||
var smtpId string
|
||||
resp, err := adminClient.GetSMTPConfig(ctx, &adm.GetSMTPConfigRequest{})
|
||||
resp, err := adminClient.GetEmailProvider(ctx, &adm.GetEmailProviderRequest{})
|
||||
if err != nil {
|
||||
if !strings.Contains(err.Error(), "SMTP configuration not found") {
|
||||
return ctrl.Result{}, fmt.Errorf("Error getting SMTP config: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
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{
|
||||
if strings.Contains(err.Error(), "not found") {
|
||||
adminRequest := &adm.AddEmailProviderSMTPRequest{
|
||||
SenderAddress: zitadel.Spec.SMTPConfig.SenderAddress,
|
||||
SenderName: zitadel.Spec.SMTPConfig.SenderName,
|
||||
Tls: zitadel.Spec.SMTPConfig.TLS,
|
||||
@@ -600,23 +565,53 @@ func (r *ZitadelClusterReconciler) reconcileSMTPConfig(ctx context.Context, zita
|
||||
adminRequest.ReplyToAddress = *zitadel.Spec.SMTPConfig.ReplyToAddress
|
||||
}
|
||||
|
||||
addRes, err := adminClient.AddSMTPConfig(ctx, adminRequest)
|
||||
addRes, err := adminClient.AddEmailProviderSMTP(ctx, adminRequest)
|
||||
if err != nil {
|
||||
return ctrl.Result{}, fmt.Errorf("Could not add SMTP config: %v", err)
|
||||
}
|
||||
smtpId = addRes.Id
|
||||
}
|
||||
|
||||
if _, err := adminClient.ActivateSMTPConfig(ctx, &adm.ActivateSMTPConfigRequest{
|
||||
Id: smtpId,
|
||||
if _, err := adminClient.ActivateEmailProvider(ctx, &adm.ActivateEmailProviderRequest{
|
||||
Id: addRes.Id,
|
||||
}); err != nil {
|
||||
if !strings.Contains(err.Error(), "AlreadyActive") {
|
||||
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())
|
||||
zitadel.Status.SMTPProviderId = smtpId
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user