• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mindersec / minder / 14701580974

28 Apr 2025 06:20AM UTC coverage: 56.887%. First build
14701580974

Pull #5609

github

web-flow
Merge 1ba185623 into 4f29c3363
Pull Request #5609: build(deps): bump gitlab.com/gitlab-org/api/client-go from 0.127.0 to 0.128.0

18357 of 32269 relevant lines covered (56.89%)

36.93 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/internal/email/awsses/awsses.go
1
// SPDX-FileCopyrightText: Copyright 2024 The Minder Authors
2
// SPDX-License-Identifier: Apache-2.0
3

4
// Package awsses provides the email utilities for minder
5
package awsses
6

7
import (
8
        "context"
9
        "encoding/json"
10
        "fmt"
11

12
        "github.com/ThreeDotsLabs/watermill/message"
13
        "github.com/aws/aws-sdk-go-v2/aws"
14
        "github.com/aws/aws-sdk-go-v2/config"
15
        "github.com/aws/aws-sdk-go-v2/service/sesv2"
16
        "github.com/aws/aws-sdk-go-v2/service/sesv2/types"
17
        "github.com/rs/zerolog"
18

19
        "github.com/mindersec/minder/internal/email"
20
        "github.com/mindersec/minder/pkg/eventer/interfaces"
21
)
22

23
const (
24
        // CharSet is the character set for the email
25
        CharSet = "UTF-8"
26
)
27

28
// awsSES is the AWS SES client
29
type awsSES struct {
30
        sender string
31
        svc    *sesv2.Client
32
}
33

34
// New creates a new AWS SES client
35
func New(ctx context.Context, sender, region string) (*awsSES, error) {
×
36
        // Load the AWS SDK configuration
×
37
        cfg, err := config.LoadDefaultConfig(ctx, config.WithRegion(region))
×
38
        if err != nil {
×
39
                return nil, err
×
40
        }
×
41

42
        // Create an SES service client.
43
        return &awsSES{
×
44
                sender: sender,
×
45
                svc:    sesv2.NewFromConfig(cfg),
×
46
        }, nil
×
47
}
48

49
// Register implements the Consumer interface.
50
func (a *awsSES) Register(reg interfaces.Registrar) {
×
51
        reg.Register(email.TopicQueueInviteEmail, func(msg *message.Message) error {
×
52
                var e email.MailEventPayload
×
53

×
54
                // Get the message context
×
55
                msgCtx := msg.Context()
×
56

×
57
                // Unmarshal the message payload
×
58
                if err := json.Unmarshal(msg.Payload, &e); err != nil {
×
59
                        return fmt.Errorf("error unmarshalling invite email event: %w", err)
×
60
                }
×
61

62
                // Send the email
63
                return a.sendEmail(msgCtx, e.Address, e.Subject, e.BodyHTML, e.BodyText)
×
64
        })
65
}
66

67
// SendEmail sends an email using AWS SES
68
func (a *awsSES) sendEmail(ctx context.Context, to, subject, bodyHTML, bodyText string) error {
×
69
        zerolog.Ctx(ctx).Info().
×
70
                Str("invitee", to).
×
71
                Str("subject", subject).
×
72
                Msg("beginning to send email to invitee")
×
73

×
74
        // Assemble the email.
×
75
        input := &sesv2.SendEmailInput{
×
76
                // Set the email sender
×
77
                FromEmailAddress: aws.String(a.sender),
×
78
                // Set the email destination
×
79
                Destination: &types.Destination{
×
80
                        CcAddresses: []string{},
×
81
                        ToAddresses: []string{to},
×
82
                },
×
83
                // Set the email content
×
84
                Content: &types.EmailContent{
×
85
                        Simple: &types.Message{
×
86
                                Body: &types.Body{
×
87
                                        Html: &types.Content{
×
88
                                                Charset: aws.String(CharSet),
×
89
                                                Data:    aws.String(bodyHTML),
×
90
                                        },
×
91
                                        Text: &types.Content{
×
92
                                                Charset: aws.String(CharSet),
×
93
                                                Data:    aws.String(bodyText),
×
94
                                        },
×
95
                                },
×
96
                                Subject: &types.Content{
×
97
                                        Charset: aws.String(CharSet),
×
98
                                        Data:    aws.String(subject),
×
99
                                },
×
100
                        },
×
101
                },
×
102
                // Uncomment to use a configuration set
×
103
                //ConfigurationSetName: aws.String(ConfigurationSet),
×
104
        }
×
105

×
106
        // Attempt to send the email.
×
107
        result, err := a.svc.SendEmail(ctx, input)
×
108

×
109
        // Display error messages if they occur.
×
110
        if err != nil {
×
111
                zerolog.Ctx(ctx).Error().Err(err).
×
112
                        Msg("error sending email")
×
113
                return err
×
114
        }
×
115

116
        // Log the message ID of the message sent to the user
117
        zerolog.Ctx(ctx).Info().
×
118
                Str("invitee", to).
×
119
                Str("emailMsgId", *result.MessageId).
×
120
                Msg("email sent successfully")
×
121

×
122
        return nil
×
123
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc