Skip to content

Commit 5131a45

Browse files
cleanup of newman package (#6)
* cleanup, ensure interface is met, httpsling, resend tests Signed-off-by: Sarah Funkhouser <147884153+golanglemonade@users.noreply.github.com> * tabs and spaces :( Signed-off-by: Sarah Funkhouser <147884153+golanglemonade@users.noreply.github.com> * sonare version Signed-off-by: Sarah Funkhouser <147884153+golanglemonade@users.noreply.github.com> * one last pass Signed-off-by: Sarah Funkhouser <147884153+golanglemonade@users.noreply.github.com> * add mock provider Signed-off-by: Sarah Funkhouser <147884153+golanglemonade@users.noreply.github.com> * handle errors Signed-off-by: Sarah Funkhouser <147884153+golanglemonade@users.noreply.github.com> --------- Signed-off-by: Sarah Funkhouser <147884153+golanglemonade@users.noreply.github.com>
1 parent e7ba7d6 commit 5131a45

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1073
-427
lines changed

.buildkite/pipeline.yml

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,58 @@ steps:
1616
command: ["task", "go:lint"]
1717
environment:
1818
- "GOTOOLCHAIN=auto"
19+
- label: ":golang: go test"
20+
key: "go_test"
21+
cancel_on_build_failing: true
22+
plugins:
1923
- docker#v5.11.0:
20-
image: "ghcr.io/theopenlane/build-image:latest"
24+
image: golang:1.23.0
2125
always-pull: true
22-
command: ["task", "go:test"]
26+
command: ["go", "test", "-coverprofile=coverage.out", "./..."]
27+
environment:
28+
- "GOTOOLCHAIN=auto"
29+
artifact_paths: ["coverage.out"]
30+
- group: ":closed_lock_with_key: Security Checks"
31+
depends_on: "go_test"
32+
key: "security"
33+
steps:
34+
- label: ":closed_lock_with_key: gosec"
35+
key: "gosec"
36+
plugins:
37+
- docker#v5.11.0:
38+
image: "registry.hub.docker.com/securego/gosec:2.20.0"
39+
command: ["-no-fail", "-exclude-generated", "-fmt sonarqube", "-out", "results.txt", "./..."]
2340
environment:
2441
- "GOTOOLCHAIN=auto"
42+
artifact_paths: ["results.txt"]
43+
- label: ":github: upload PR reports"
44+
key: "scan-upload-pr"
45+
if: build.pull_request.id != null
46+
depends_on: ["gosec", "go_test"]
47+
plugins:
48+
- artifacts#v1.9.4:
49+
download: "results.txt"
50+
- artifacts#v1.9.4:
51+
download: "coverage.out"
52+
step: "go_test"
53+
- docker#v5.11.0:
54+
image: "sonarsource/sonar-scanner-cli:11.0"
55+
environment:
56+
- "SONAR_TOKEN"
57+
- "SONAR_HOST_URL=$SONAR_HOST"
58+
- "SONAR_SCANNER_OPTS=-Dsonar.pullrequest.branch=$BUILDKITE_BRANCH -Dsonar.pullrequest.base=$BUILDKITE_PULL_REQUEST_BASE_BRANCH -Dsonar.pullrequest.key=$BUILDKITE_PULL_REQUEST"
59+
- label: ":github: upload reports"
60+
key: "scan-upload"
61+
if: build.branch == "main"
62+
depends_on: ["gosec", "go_test"]
63+
plugins:
64+
- artifacts#v1.9.4:
65+
download: results.txt
66+
- artifacts#v1.9.4:
67+
download: coverage.out
68+
step: "go_test"
69+
- docker#v5.11.0:
70+
image: "sonarsource/sonar-scanner-cli:11.0"
71+
environment:
72+
- "SONAR_TOKEN"
73+
- "SONAR_HOST_URL=$SONAR_HOST"

.github/labeler.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ enhancement:
77
# Add 'breaking-change' label to any PR where the head branch name starts with `breaking-change` or has a `breaking-change` section in the name
88
breaking-change:
99
- head-branch: ["^breaking-change", "breaking-change"]
10+
# Add 'dependencies' label to any PR where the head branch name starts with `dependencies` or has a `dependencies` section in the name
11+
dependencies:
12+
- head-branch: ["^dependencies", "dependencies", "^deps", "deps"]
1013
ci:
1114
- changed-files:
1215
- any-glob-to-any-file: .github/**

.gitignore

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,5 @@ Thumbs.db
3838
*.mime
3939
*.mim
4040

41-
*.env
42-
*.env-dev
43-
*.config.yaml
41+
test/*
42+
emails/*

.golangci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ issues:
4141
- .buildkite/*
4242
- .github/*
4343
- docker/*
44+
- test/*
4445
exclude-files: []

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ repos:
1212
hooks:
1313
- id: yamlfmt
1414
- repo: https://github.com/crate-ci/typos
15-
rev: typos-dict-v0.11.27
15+
rev: v1.24.5
1616
hooks:
1717
- id: typos

README.md

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,42 @@ import (
3939
)
4040

4141
func main() {
42-
sender := resend.NewResendEmailSender("your_resend_api_token")
43-
msg := newman.NewEmailMessage("no-reply@youremailaddress.com", []string{"mitb@emailsendingfun.com"}, "Isnt sending emails with golang fun?", "Oh Yes! Mark my words, Seinfeld! Your day of reckoning is coming")
44-
45-
if err := sender.SendEmail(context.TODO(), *msg); err != nil {
46-
log.Fatal(err)
47-
}
42+
sender, err := resend.New("your_resend_api_token")
43+
if err != nil {
44+
log.Fatal(err)
45+
}
46+
47+
msg := newman.NewEmailMessageWithOptions(
48+
newman.WithFrom("no-reply@youremailaddress.com"),
49+
newman.WithTo([]string{"mitb@emailsendingfun.com"}),
50+
newman.WithSubject("Isn't sending emails with golang fun?"),
51+
newman.WithHTML("<p>Oh Yes! Mark my words, Seinfeld! Your day of reckoning is coming</p>"),
52+
)
53+
54+
if err := sender.SendEmail(msg); err != nil {
55+
log.Fatal(err)
56+
}
4857
}
4958
```
5059

51-
This package supports various email providers and can be extended to include more
60+
### Development Mode
61+
62+
To switch to development an just log the email to a file instead of sending an email you can use the `mock` provider. With the `resend` provider, this is made easy with the `WithDevMode` option
63+
64+
```go
65+
sender, err := resend.New("", resend.WithDevMode("emails"))
66+
if err != nil {
67+
log.Fatal(err)
68+
}
69+
```
5270

53-
### Implemented providers
71+
This will put the emails that would be send in the `emails/` directory instead.
72+
73+
74+
75+
## Implemented Providers
76+
77+
This package supports various email providers and can be extended to include more
5478

5579
- Gmail
5680
- SendGrid

Taskfile.yaml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ tasks:
1616
aliases: [cover]
1717
cmds:
1818
- go test -v ./... -coverprofile=coverage.out
19+
20+
go:test:coverout:
21+
desc: runs and outputs results of created go tests with coverage
22+
aliases: [cover]
23+
cmds:
24+
- task: go:test:cover
1925
- go tool cover -html=coverage.out
2026

2127
go:fmt:
@@ -29,19 +35,14 @@ tasks:
2935
cmds:
3036
- go mod tidy
3137

32-
go:build:
33-
desc: Runs go build for the newman server
34-
cmds:
35-
- go build -mod=mod -o newman
36-
3738
go:all:
3839
aliases: [go]
3940
desc: Runs all go test and lint related tasks
4041
cmds:
4142
- task: go:tidy
4243
- task: go:fmt
4344
- task: go:lint
44-
- task: go:test:cover
45+
- task: go:test:coverout
4546

4647
precommit-full:
4748
desc: Lint the project against all files

go.mod

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,51 +3,54 @@ module github.com/theopenlane/newman
33
go 1.23.0
44

55
require (
6+
github.com/mailgun/mailgun-go/v4 v4.15.0
67
github.com/microcosm-cc/bluemonday v1.0.27
8+
github.com/resend/resend-go/v2 v2.11.0
79
github.com/sendgrid/rest v2.6.9+incompatible
10+
github.com/sendgrid/sendgrid-go v3.16.0+incompatible
11+
github.com/stretchr/testify v1.9.0
12+
github.com/theopenlane/httpsling v0.2.0
13+
golang.org/x/oauth2 v0.23.0
14+
google.golang.org/api v0.196.0
815
)
916

1017
require (
1118
cloud.google.com/go/auth v0.9.3 // indirect
1219
cloud.google.com/go/auth/oauth2adapt v0.2.4 // indirect
1320
cloud.google.com/go/compute/metadata v0.5.0 // indirect
14-
github.com/davecgh/go-spew v1.1.1 // indirect
21+
github.com/aymerick/douceur v0.2.0 // indirect
22+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
1523
github.com/felixge/httpsnoop v1.0.4 // indirect
1624
github.com/go-chi/chi/v5 v5.0.8 // indirect
1725
github.com/go-logr/logr v1.4.2 // indirect
1826
github.com/go-logr/stdr v1.2.2 // indirect
1927
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
28+
github.com/google/go-querystring v1.1.0 // indirect
2029
github.com/google/s2a-go v0.1.8 // indirect
2130
github.com/google/uuid v1.6.0 // indirect
2231
github.com/googleapis/enterprise-certificate-proxy v0.3.3 // indirect
2332
github.com/googleapis/gax-go/v2 v2.13.0 // indirect
24-
github.com/json-iterator/go v1.1.10 // indirect
25-
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
26-
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 // indirect
27-
github.com/pkg/errors v0.8.1 // indirect
28-
github.com/pmezard/go-difflib v1.0.0 // indirect
33+
github.com/gorilla/css v1.0.1 // indirect
34+
github.com/json-iterator/go v1.1.12 // indirect
35+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
36+
github.com/modern-go/reflect2 v1.0.2 // indirect
37+
github.com/pkg/errors v0.9.1 // indirect
38+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
39+
github.com/theopenlane/echox v0.1.0 // indirect
40+
github.com/theopenlane/utils v0.1.5 // indirect
2941
go.opencensus.io v0.24.0 // indirect
3042
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect
3143
go.opentelemetry.io/otel v1.29.0 // indirect
3244
go.opentelemetry.io/otel/metric v1.29.0 // indirect
3345
go.opentelemetry.io/otel/trace v1.29.0 // indirect
3446
golang.org/x/crypto v0.26.0 // indirect
47+
golang.org/x/net v0.28.0 // indirect
3548
golang.org/x/sys v0.24.0 // indirect
3649
golang.org/x/text v0.17.0 // indirect
50+
google.golang.org/genproto/googleapis/api v0.0.0-20240725223205-93522f1f2a9f // indirect
3751
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
3852
google.golang.org/grpc v1.66.0 // indirect
3953
google.golang.org/protobuf v1.34.2 // indirect
4054
gopkg.in/yaml.v3 v3.0.1 // indirect
41-
)
4255

43-
require (
44-
github.com/aymerick/douceur v0.2.0 // indirect
45-
github.com/gorilla/css v1.0.1 // indirect
46-
github.com/mailgun/mailgun-go/v4 v4.15.0
47-
github.com/resend/resend-go/v2 v2.11.0
48-
github.com/sendgrid/sendgrid-go v3.16.0+incompatible
49-
github.com/stretchr/testify v1.9.0
50-
golang.org/x/net v0.28.0 // indirect
51-
golang.org/x/oauth2 v0.23.0
52-
google.golang.org/api v0.196.0
5356
)

go.sum

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA
1212
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
1313
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
1414
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
15-
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1615
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
16+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
17+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1718
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
1819
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
1920
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
@@ -52,9 +53,12 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
5253
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
5354
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
5455
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
56+
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
5557
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
5658
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
5759
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
60+
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
61+
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
5862
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
5963
github.com/google/s2a-go v0.1.8 h1:zZDs9gcbt9ZPLV0ndSyQk6Kacx2g/X+SKYovpnz3SMM=
6064
github.com/google/s2a-go v0.1.8/go.mod h1:6iNWHTpQ+nfNRN5E00MSdfDwVesa8hhS32PhPO8deJA=
@@ -67,20 +71,25 @@ github.com/googleapis/gax-go/v2 v2.13.0 h1:yitjD5f7jQHhyDsnhKEBU52NdvvdSeGzlAnDP
6771
github.com/googleapis/gax-go/v2 v2.13.0/go.mod h1:Z/fvTZXF8/uw7Xu5GuslPw+bplx6SS338j1Is2S+B7A=
6872
github.com/gorilla/css v1.0.1 h1:ntNaBIghp6JmvWnxbZKANoLyuXTPZ4cAMlo6RyhlbO8=
6973
github.com/gorilla/css v1.0.1/go.mod h1:BvnYkspnSzMmwRK+b8/xgNPLiIuNZr6vbZBTPQ2A3b0=
70-
github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68=
7174
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
75+
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
76+
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
7277
github.com/mailgun/mailgun-go/v4 v4.15.0 h1:3NQU0r2XItJbyIZ21iBI9ps0+vPIMoGyI2XK7ZTN/DQ=
7378
github.com/mailgun/mailgun-go/v4 v4.15.0/go.mod h1:L9s941Lgk7iB3TgywTPz074pK2Ekkg4kgbnAaAyJ2z8=
7479
github.com/microcosm-cc/bluemonday v1.0.27 h1:MpEUotklkwCSLeH+Qdx1VJgNqLlpY2KXwXFM08ygZfk=
7580
github.com/microcosm-cc/bluemonday v1.0.27/go.mod h1:jFi9vgW+H7c3V0lb6nR74Ib/DIB5OBs92Dimizgw2cA=
76-
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
7781
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
78-
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
82+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
83+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
7984
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
80-
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
85+
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
86+
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
8187
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
82-
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
88+
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
89+
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
8390
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
91+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
92+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
8493
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
8594
github.com/resend/resend-go/v2 v2.11.0 h1:Ja5eXizUCbvyLgbiP8sFsJW/UN1b7d6IEUqi80IlgiU=
8695
github.com/resend/resend-go/v2 v2.11.0/go.mod h1:ihnxc7wPpSgans8RV8d8dIF4hYWVsqMK5KxXAr9LIos=
@@ -97,6 +106,12 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
97106
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
98107
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
99108
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
109+
github.com/theopenlane/echox v0.1.0 h1:y4Z2shaODCLwXHsHBrY/EkH/2sIuo49xdIfxx7h+Zvg=
110+
github.com/theopenlane/echox v0.1.0/go.mod h1:RaynhPvY9qbLOVlcO7Js1NqZ66+CP9hVBa0c7ehNYA4=
111+
github.com/theopenlane/httpsling v0.2.0 h1:5k/PoFA5jjak9dnijATFvTVTvgUSMFdEZeyctyv1cWU=
112+
github.com/theopenlane/httpsling v0.2.0/go.mod h1:Ta/8bjv4JhKT0Xk1hD2Iott9BKLCqXvscmjolSB/bBY=
113+
github.com/theopenlane/utils v0.1.5 h1:4DRieQmsBF87n4lPjEkTt6s4iVRQaCGYlk2+C05lt3o=
114+
github.com/theopenlane/utils v0.1.5/go.mod h1:LWJzG9FfklsLlqWx/VdmfBMuNk700cWqHAwQL0299FM=
100115
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
101116
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
102117
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 h1:TT4fX+nBOA/+LUkobKGW1ydGcn+G3vRw9+g5HwCphpk=
@@ -154,9 +169,8 @@ google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7
154169
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
155170
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
156171
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
157-
google.golang.org/genproto v0.0.0-20240903143218-8af14fe29dc1 h1:BulPr26Jqjnd4eYDVe+YvyR7Yc2vJGkO5/0UxD0/jZU=
158-
google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d h1:kHjw/5UfflP/L5EbledDrcG4C2597RtymmGRZvHiCuY=
159-
google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d/go.mod h1:mw8MG/Qz5wfgYr6VqVCiZcHe/GJEfI+oGGDCohaVgB0=
172+
google.golang.org/genproto/googleapis/api v0.0.0-20240725223205-93522f1f2a9f h1:b1Ln/PG8orm0SsBbHZWke8dDp2lrCD4jSmfglFpTZbk=
173+
google.golang.org/genproto/googleapis/api v0.0.0-20240725223205-93522f1f2a9f/go.mod h1:AHT0dDg3SoMOgZGnZk29b5xTbPHMoEC8qthmBLJCpys=
160174
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 h1:pPJltXNxVzT4pK9yD8vR9X75DaWYYmLGMsEvBfFQZzQ=
161175
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
162176
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=

newman.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
package newman
22

3-
import "github.com/theopenlane/newman/shared"
3+
import (
4+
"context"
5+
6+
"github.com/theopenlane/newman/shared"
7+
)
48

59
// EmailSender interface defines the method to send an email
610
type EmailSender interface {
711
// SendEmail sends an email with the given message
812
SendEmail(message *EmailMessage) error
13+
// SendEmailWithContext sends an email with the given message and context
14+
SendEmailWithContext(ctx context.Context, message *EmailMessage) error
915
}
1016

1117
// EmailMessage represents an email message
@@ -14,14 +20,23 @@ type EmailMessage = shared.EmailMessage
1420
// Attachment represents an email attachment with its filename and content
1521
type Attachment = shared.Attachment
1622

23+
// Tag is used to define custom metadata for message
24+
type Tag = shared.Tag
25+
1726
// NewEmailMessage creates a new EmailMessage with the required fields
1827
func NewEmailMessage(from string, to []string, subject string, body string) *EmailMessage {
1928
return shared.NewEmailMessage(from, to, subject, body)
2029
}
2130

22-
// NewFullEmailMessage creates a new EmailMessage with all fields
23-
func NewFullEmailMessage(from string, to []string, subject string, cc []string, bcc []string, replyTo string, textBody string, htmlBody string, attachments []*Attachment) *EmailMessage {
24-
return shared.NewFullEmailMessage(from, to, subject, cc, bcc, replyTo, textBody, htmlBody, attachments)
31+
// NewEmailMessageWithOptions creates a new EmailMessage with the specified options.
32+
func NewEmailMessageWithOptions(options ...MessageOption) *EmailMessage {
33+
s := EmailMessage{}
34+
35+
for _, option := range options {
36+
option(&s)
37+
}
38+
39+
return &s
2540
}
2641

2742
// NewAttachment creates a new Attachment instance with the specified filename and content
@@ -41,12 +56,12 @@ func BuildMimeMessage(message *EmailMessage) ([]byte, error) {
4156

4257
// ValidateEmail validates and sanitizes an email address
4358
func ValidateEmail(email string) string {
44-
return shared.ValidateEmail(email)
59+
return shared.ValidateEmailAddress(email)
4560
}
4661

4762
// ValidateEmailSlice validates and sanitizes a slice of email addresses
4863
func ValidateEmailSlice(emails []string) []string {
49-
return shared.ValidateEmailSlice(emails)
64+
return shared.ValidateEmailAddresses(emails)
5065
}
5166

5267
// GetMimeType returns the MIME type based on the file extension

0 commit comments

Comments
 (0)