-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ROX-23249: multiple emailsender issues discovered by debugging (#1869)
fixed some issue discovered by local debugging
- Loading branch information
1 parent
69e60e1
commit ed33c31
Showing
5 changed files
with
19 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,6 +76,7 @@ emailsender: | |
clusterId: "" | ||
clusterName: "" | ||
environment: "" | ||
senderAddress: "[email protected]" | ||
authConfigFromKubernetes: true | ||
resources: | ||
requests: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,8 +44,8 @@ func main() { | |
glog.Errorf("Failed to initialise SES Client: %v", err) | ||
os.Exit(1) | ||
} | ||
temporarySenderName := "[email protected]" | ||
emailSender := email.NewEmailSender(temporarySenderName, sesClient) | ||
|
||
emailSender := email.NewEmailSender(cfg.SenderAddress, sesClient) | ||
emailHandler := api.NewEmailHandler(emailSender) | ||
|
||
router, err := api.SetupRoutes(cfg.AuthConfig, emailHandler) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ type Config struct { | |
MetricsAddress string `env:"METRICS_ADDRESS" envDefault:":9090"` | ||
AuthConfigFile string `env:"AUTH_CONFIG_FILE" envDefault:"config/emailsender-authz.yaml"` | ||
AuthConfigFromKubernetes bool `env:"AUTH_CONFIG_FROM_KUBERNETES" envDefault:"false"` | ||
SenderAddress string `env:"SENDER_ADDRESS" envDefault:"[email protected]"` | ||
AuthConfig AuthConfig | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,41 @@ | ||
package email | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
|
||
"github.com/golang/glog" | ||
) | ||
|
||
const fromTemplate = "From: RHACS Cloud Service <%s>\r\n" | ||
|
||
// Sender defines the interface to send emails | ||
type Sender interface { | ||
Send(ctx context.Context, to []string, rawMessage []byte) error | ||
} | ||
|
||
// MailSender is the default implementation for the Sender interface | ||
type MailSender struct { | ||
from string | ||
ses *SES | ||
} | ||
|
||
// NewEmailSender returns a new MailSender instance | ||
func NewEmailSender(from string, ses *SES) *MailSender { | ||
return &MailSender{ | ||
from: from, | ||
ses: ses, | ||
} | ||
} | ||
|
||
// Send sends an email to the given AWS SES | ||
func (s *MailSender) Send(ctx context.Context, to []string, rawMessage []byte) error { | ||
_, err := s.ses.SendRawEmail(ctx, s.from, to, rawMessage) | ||
// Even though AWS adds the from handler we need to set it the the message to show | ||
// an alias in email inboxes that is more human friendly ([email protected] vs. RHACS Cloud Service) | ||
fromBytes := []byte(fmt.Sprintf(fromTemplate, s.from)) | ||
raw := bytes.Join([][]byte{fromBytes, rawMessage}, nil) | ||
_, err := s.ses.SendRawEmail(ctx, s.from, to, raw) | ||
if err != nil { | ||
glog.Errorf("Failed sending email: %v", err) | ||
return fmt.Errorf("failed to send email: %v", err) | ||
|