Skip to content

Update dependencies to use aws sdk v2 #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
module github.com/blueimp/aws-smtp-relay

go 1.14
go 1.19

require (
github.com/aws/aws-sdk-go v1.38.61
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-sql-driver/mysql v1.5.0 // indirect
github.com/kr/pretty v0.2.0 // indirect
github.com/mhale/smtpd v0.0.0-20210322105601-438c8edb069c
github.com/stretchr/testify v1.5.1 // indirect
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
github.com/aws/aws-sdk-go-v2/service/pinpointemail v1.12.4
github.com/aws/aws-sdk-go-v2/service/ses v1.15.3
github.com/mhale/smtpd v0.8.0
golang.org/x/crypto v0.6.0
)

require (
github.com/aws/aws-sdk-go-v2 v1.17.5 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.29 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.23 // indirect
github.com/aws/smithy-go v1.13.5 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
)
66 changes: 20 additions & 46 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,56 +1,30 @@
github.com/aws/aws-sdk-go v1.30.3 h1:tmaR+qpBSig6RfhP9IoxALJEE1m0vfLy5tlnEIXu6WI=
github.com/aws/aws-sdk-go v1.30.3/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/aws/aws-sdk-go v1.38.61 h1:wizuqQZe0K4iYJ+Slrs0aSQ4P94FAwqBUHwk46Iz5UA=
github.com/aws/aws-sdk-go v1.38.61/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
github.com/aws/aws-sdk-go-v2 v1.17.5 h1:TzCUW1Nq4H8Xscph5M/skINUitxM5UBAyvm2s7XBzL4=
github.com/aws/aws-sdk-go-v2 v1.17.5/go.mod h1:uzbQtefpm44goOPmdKyAlXSNcwlRgF3ePWVW6EtJvvw=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.29 h1:9/aKwwus0TQxppPXFmf010DFrE+ssSbzroLVYINA+xE=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.29/go.mod h1:Dip3sIGv485+xerzVv24emnjX5Sg88utCL8fwGmCeWg=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.23 h1:b/Vn141DBuLVgXbhRWIrl9g+ww7G+ScV5SzniWR13jQ=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.23/go.mod h1:mr6c4cHC+S/MMkrjtSlG4QA36kOznDep+0fga5L/fGQ=
github.com/aws/aws-sdk-go-v2/service/pinpointemail v1.12.4 h1:NcxMBuHmNENvStkgvIJgAqvTmjBGv/drQSmxGuLRjVg=
github.com/aws/aws-sdk-go-v2/service/pinpointemail v1.12.4/go.mod h1:slY3ISjHIVPkU8yFb9qDa12tBDaITlqdHLSbF+wIy7c=
github.com/aws/aws-sdk-go-v2/service/ses v1.15.3 h1:O7gl6f1Zi80GLQkyWFJi2PYzF8c7qd/iUBmLIVVp8og=
github.com/aws/aws-sdk-go-v2/service/ses v1.15.3/go.mod h1:xIWGz5r8k9h6T0f0jhkFdLMZJ10abjOfxmUWoWevw14=
github.com/aws/smithy-go v1.13.5 h1:hgz0X/DX0dGqTYpGALqXJoRKRj5oQ7150i5FdTePzO8=
github.com/aws/smithy-go v1.13.5/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/jmespath/go-jmespath v0.3.0 h1:OS12ieG61fsCg5+qLJ+SsW9NicxNkg3b25OyT2yCeUc=
github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeYCZ7fLUTSywik=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mhale/smtpd v0.0.0-20181125220505-3c4c908952b8 h1:DuLRJOD3tr0rbrwDXXw5mw8YRPl70y8RbFpUtCjzOkU=
github.com/mhale/smtpd v0.0.0-20181125220505-3c4c908952b8/go.mod h1:qqKwvL5sfYgFxcMy96Kjx3TCorMfDaQBvmEL2nvdidc=
github.com/mhale/smtpd v0.0.0-20210322105601-438c8edb069c h1:AjouS6Z9yUjUzX7Y2iC9z9XSOIZNx1pJuhpHoX526wg=
github.com/mhale/smtpd v0.0.0-20210322105601-438c8edb069c/go.mod h1:MQl+y2hwIEQCXtNhe5+55n0GZOjSmeqORDIXbqUL3x4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/mhale/smtpd v0.8.0 h1:5JvdsehCg33PQrZBvFyDMMUDQmvbzVpZgKob7eYBJc0=
github.com/mhale/smtpd v0.8.0/go.mod h1:MQl+y2hwIEQCXtNhe5+55n0GZOjSmeqORDIXbqUL3x4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59 h1:3zb4D3T4G8jdExgVU/95+vQXfpEPiMdCaZgmGVxjNHM=
golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a h1:kr2P4QFmQr29mSLA43kwrOcgcReGTfbE9N577tCTuBc=
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc=
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
37 changes: 19 additions & 18 deletions internal/relay/pinpoint/relay.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
package relay

import (
"context"
"net"
"regexp"

"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/pinpointemail"
"github.com/aws/aws-sdk-go/service/pinpointemail/pinpointemailiface"
"github.com/aws/aws-sdk-go-v2/service/pinpointemail"
pinpointemailtypes "github.com/aws/aws-sdk-go-v2/service/pinpointemail/types"
"github.com/blueimp/aws-smtp-relay/internal/relay"
)

type PinpointEmailClient interface {
SendEmail(context.Context, *pinpointemail.SendEmailInput, ...func(*pinpointemail.Options)) (*pinpointemail.SendEmailOutput, error)
}

// Client implements the Relay interface.
type Client struct {
pinpointAPI pinpointemailiface.PinpointEmailAPI
pinpointClient PinpointEmailClient
setName *string
allowFromRegExp *regexp.Regexp
denyToRegExp *regexp.Regexp
Expand All @@ -32,22 +36,19 @@ func (c Client) Send(
c.denyToRegExp,
)
if err != nil {
relay.Log(origin, &from, deniedRecipients, err)
relay.Log(origin, from, deniedRecipients, err)
}
if len(allowedRecipients) > 0 {
_, err := c.pinpointAPI.SendEmail(&pinpointemail.SendEmailInput{
ConfigurationSetName: c.setName,
FromEmailAddress: &from,
Destination: &pinpointemail.Destination{
ToAddresses: allowedRecipients,
},
Content: &pinpointemail.EmailContent{
Raw: &pinpointemail.RawMessage{
Data: data,
},
},
_, err := c.pinpointClient.SendEmail(context.Background(), &pinpointemail.SendEmailInput{
Content: &pinpointemailtypes.EmailContent{Raw: &pinpointemailtypes.RawMessage{Data: data}},
Destination: &pinpointemailtypes.Destination{ToAddresses: allowedRecipients},
ConfigurationSetName: c.setName,
EmailTags: []pinpointemailtypes.MessageTag{},
FeedbackForwardingEmailAddress: new(string),
FromEmailAddress: &from,
ReplyToAddresses: to,
})
relay.Log(origin, &from, allowedRecipients, err)
relay.Log(origin, from, allowedRecipients, err)
if err != nil {
return err
}
Expand All @@ -62,7 +63,7 @@ func New(
denyToRegExp *regexp.Regexp,
) Client {
return Client{
pinpointAPI: pinpointemail.New(session.Must(session.NewSession())),
pinpointClient: pinpointemail.New(pinpointemail.Options{}),
setName: configurationSetName,
allowFromRegExp: allowFromRegExp,
denyToRegExp: denyToRegExp,
Expand Down
32 changes: 13 additions & 19 deletions internal/relay/pinpoint/relay_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package relay

import (
"context"
"errors"
"io/ioutil"
"net"
"os"
"regexp"
"testing"

"github.com/aws/aws-sdk-go/service/pinpointemail"
"github.com/aws/aws-sdk-go/service/pinpointemail/pinpointemailiface"
"github.com/aws/aws-sdk-go-v2/service/pinpointemail"
"github.com/blueimp/aws-smtp-relay/internal/relay"
)

Expand All @@ -19,18 +19,12 @@ var testData = struct {
}{}

type mockPinpointEmailClient struct {
pinpointemailiface.PinpointEmailAPI
}

func (m *mockPinpointEmailClient) CreateConfigurationSet(
input *pinpointemail.CreateConfigurationSetInput,
) (*pinpointemail.CreateConfigurationSetOutput, error) {
return &pinpointemail.CreateConfigurationSetOutput{}, nil
}

func (m *mockPinpointEmailClient) SendEmail(
context context.Context,
input *pinpointemail.SendEmailInput,
) (*pinpointemail.SendEmailOutput, error) {
fns ...func(*pinpointemail.Options)) (*pinpointemail.SendEmailOutput, error) {
testData.input = input
return nil, testData.err
}
Expand Down Expand Up @@ -59,7 +53,7 @@ func sendHelper(
os.Stderr = errWriter
func() {
c := Client{
pinpointAPI: &mockPinpointEmailClient{},
pinpointClient: &mockPinpointEmailClient{},
setName: configurationSetName,
allowFromRegExp: allowFromRegExp,
denyToRegExp: denyToRegExp,
Expand Down Expand Up @@ -95,10 +89,10 @@ func TestSend(t *testing.T) {
1,
)
}
if *input.Destination.ToAddresses[0] != to[0] {
if input.Destination.ToAddresses[0] != to[0] {
t.Errorf(
"Unexpected destination: %s. Expected: %s",
*input.Destination.ToAddresses[0],
input.Destination.ToAddresses[0],
to[0],
)
}
Expand Down Expand Up @@ -128,10 +122,10 @@ func TestSendWithMultipleRecipients(t *testing.T) {
2,
)
}
if *input.Destination.ToAddresses[0] != to[0] {
if input.Destination.ToAddresses[0] != to[0] {
t.Errorf(
"Unexpected destination: %s. Expected: %s",
*input.Destination.ToAddresses[0],
input.Destination.ToAddresses[0],
to[0],
)
}
Expand Down Expand Up @@ -184,10 +178,10 @@ func TestSendWithDeniedRecipient(t *testing.T) {
1,
)
}
if *input.Destination.ToAddresses[0] != to[1] {
if input.Destination.ToAddresses[0] != to[1] {
t.Errorf(
"Unexpected destination: %s. Expected: %s",
*input.Destination.ToAddresses[0],
input.Destination.ToAddresses[0],
to[1],
)
}
Expand Down Expand Up @@ -224,10 +218,10 @@ func TestSendWithApiError(t *testing.T) {
1,
)
}
if *input.Destination.ToAddresses[0] != to[0] {
if input.Destination.ToAddresses[0] != to[0] {
t.Errorf(
"Unexpected destination: %s. Expected: %s",
*input.Destination.ToAddresses[0],
input.Destination.ToAddresses[0],
to[0],
)
}
Expand Down
20 changes: 10 additions & 10 deletions internal/relay/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ type Client interface {

type logEntry struct {
Time time.Time
IP *string
From *string
To []*string
IP string
From string
To []string
Error *string
}

// Log creates a log entry and prints it as JSON to STDOUT.
func Log(origin net.Addr, from *string, to []*string, err error) {
func Log(origin net.Addr, from string, to []string, err error) {
ip := origin.(*net.TCPAddr).IP.String()
entry := &logEntry{
Time: time.Now().UTC(),
IP: &ip,
IP: ip,
From: from,
To: to,
}
Expand All @@ -67,9 +67,9 @@ func FilterAddresses(
to []string,
allowFromRegExp *regexp.Regexp,
denyToRegExp *regexp.Regexp,
) (allowedRecipients []*string, deniedRecipients []*string, err error) {
allowedRecipients = []*string{}
deniedRecipients = []*string{}
) (allowedRecipients []string, deniedRecipients []string, err error) {
allowedRecipients = []string{}
deniedRecipients = []string{}
if allowFromRegExp != nil && !allowFromRegExp.MatchString(from) {
err = ErrDeniedSender
}
Expand All @@ -78,9 +78,9 @@ func FilterAddresses(
// Deny all recipients if the sender address is not allowed
if err != nil ||
(denyToRegExp != nil && denyToRegExp.MatchString(*recipient)) {
deniedRecipients = append(deniedRecipients, recipient)
deniedRecipients = append(deniedRecipients, *recipient)
} else {
allowedRecipients = append(allowedRecipients, recipient)
allowedRecipients = append(allowedRecipients, *recipient)
}
}
if err == nil && len(deniedRecipients) > 0 {
Expand Down
Loading