From d47150e8440a03ce34d6085fb693bddf2c02620b Mon Sep 17 00:00:00 2001 From: aeneasr <3372410+aeneasr@users.noreply.github.com> Date: Sun, 6 Mar 2022 16:34:25 +0100 Subject: [PATCH] fix(courier): improve composability --- courier/courier.go | 8 ++++---- courier/email_templates.go | 4 +++- courier/smtp.go | 6 ++++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/courier/courier.go b/courier/courier.go index d296097c601d..2eb1f647d00f 100644 --- a/courier/courier.go +++ b/courier/courier.go @@ -4,15 +4,15 @@ import ( "context" "time" + "github.com/ory/kratos/courier/template" + "github.com/cenkalti/backoff" "github.com/gofrs/uuid" - "github.com/hashicorp/go-retryablehttp" "github.com/pkg/errors" "github.com/ory/kratos/driver/config" "github.com/ory/kratos/x" gomail "github.com/ory/mail/v3" - "github.com/ory/x/httpx" ) type ( @@ -20,7 +20,7 @@ type ( PersistenceProvider x.LoggingProvider ConfigProvider - HTTPClient(ctx context.Context, opts ...httpx.ResilientOptions) *retryablehttp.Client + x.HTTPClientProvider } Courier interface { @@ -31,7 +31,7 @@ type ( DispatchQueue(ctx context.Context) error DispatchMessage(ctx context.Context, msg Message) error SetGetEmailTemplateType(f func(t EmailTemplate) (TemplateType, error)) - SetNewEmailTemplateFromMessage(f func(d Dependencies, msg Message) (EmailTemplate, error)) + SetNewEmailTemplateFromMessage(f func(d template.Dependencies, msg Message) (EmailTemplate, error)) } Provider interface { diff --git a/courier/email_templates.go b/courier/email_templates.go index 2ea3ea3bdf30..401d517881ae 100644 --- a/courier/email_templates.go +++ b/courier/email_templates.go @@ -4,6 +4,8 @@ import ( "context" "encoding/json" + "github.com/ory/kratos/courier/template" + "github.com/pkg/errors" "github.com/ory/kratos/courier/template/email" @@ -47,7 +49,7 @@ func GetEmailTemplateType(t EmailTemplate) (TemplateType, error) { } } -func NewEmailTemplateFromMessage(d Dependencies, msg Message) (EmailTemplate, error) { +func NewEmailTemplateFromMessage(d template.Dependencies, msg Message) (EmailTemplate, error) { switch msg.TemplateType { case TypeRecoveryInvalid: var t email.RecoveryInvalidModel diff --git a/courier/smtp.go b/courier/smtp.go index 90598a4da4d7..75707d9c272b 100644 --- a/courier/smtp.go +++ b/courier/smtp.go @@ -8,6 +8,8 @@ import ( "strconv" "time" + "github.com/ory/kratos/courier/template" + "github.com/ory/kratos/driver/config" "github.com/gofrs/uuid" @@ -21,7 +23,7 @@ type smtpClient struct { *gomail.Dialer GetTemplateType func(t EmailTemplate) (TemplateType, error) - NewTemplateFromMessage func(d Dependencies, msg Message) (EmailTemplate, error) + NewTemplateFromMessage func(d template.Dependencies, msg Message) (EmailTemplate, error) } func newSMTP(ctx context.Context, deps Dependencies) *smtpClient { @@ -74,7 +76,7 @@ func (c *courier) SetGetEmailTemplateType(f func(t EmailTemplate) (TemplateType, c.smtpClient.GetTemplateType = f } -func (c *courier) SetNewEmailTemplateFromMessage(f func(d Dependencies, msg Message) (EmailTemplate, error)) { +func (c *courier) SetNewEmailTemplateFromMessage(f func(d template.Dependencies, msg Message) (EmailTemplate, error)) { c.smtpClient.NewTemplateFromMessage = f }