Merge pull request #30370 from StateFarmIns/notifications-ses-config
fix: Add optional config for ses mail options with sourceArn, etc.
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-notifications-backend-module-email': patch
|
||||
---
|
||||
|
||||
Add optional config for `ses` mail options with `sourceArn`, `fromArn`, `configurationSetName`
|
||||
@@ -79,6 +79,11 @@ notifications:
|
||||
# Who to send email for broadcast notifications
|
||||
broadcastConfig:
|
||||
receiver: 'users'
|
||||
# Optional SES config
|
||||
# sesConfig:
|
||||
# sourceArn: 'arn:aws:ses:us-west-2:123456789012:identity/example.com'
|
||||
# fromArn: 'arn:aws:ses:us-west-2:123456789012:identity/example.com'
|
||||
# configurationSetName: 'custom-config'
|
||||
# How many emails to send concurrently, defaults to 2
|
||||
concurrencyLimit: 10
|
||||
# How much to throttle between emails, defaults to 100ms
|
||||
|
||||
@@ -132,6 +132,23 @@ export interface Config {
|
||||
*/
|
||||
receiverEmails?: string[];
|
||||
};
|
||||
/**
|
||||
* Optional SES config for mail options. Allows for delegated sender
|
||||
*/
|
||||
sesConfig?: {
|
||||
/**
|
||||
* ARN of the identity to use as the source of the email
|
||||
*/
|
||||
sourceArn?: string;
|
||||
/**
|
||||
* ARN of the identity to use for the "From"/sender address of the email
|
||||
*/
|
||||
fromArn?: string;
|
||||
/**
|
||||
* Name of the configuration set to use when sending email via ses
|
||||
*/
|
||||
configurationSetName?: string;
|
||||
};
|
||||
cache?: {
|
||||
/**
|
||||
* Email cache TTL, defaults to 1 hour
|
||||
|
||||
+60
@@ -442,4 +442,64 @@ describe('NotificationsEmailProcessor', () => {
|
||||
to: 'mock@backstage.io',
|
||||
});
|
||||
});
|
||||
|
||||
it('should send email with ses config', async () => {
|
||||
const SES_SENDMAIL_CONFIG = {
|
||||
app: {
|
||||
baseUrl: 'https://example.org',
|
||||
},
|
||||
notifications: {
|
||||
processors: {
|
||||
email: {
|
||||
transportConfig: {
|
||||
transport: 'ses',
|
||||
region: 'us-west-2',
|
||||
},
|
||||
sender: 'backstage@backstage.io',
|
||||
replyTo: 'no-reply@backstage.io',
|
||||
sesConfig: {
|
||||
sourceArn:
|
||||
'arn:aws:ses:us-west-2:123456789012:identity/example.com',
|
||||
fromArn:
|
||||
'arn:aws:ses:us-west-2:123456789012:identity/example.com',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
(createTransport as jest.Mock).mockReturnValue(mockTransport);
|
||||
const processor = new NotificationsEmailProcessor(
|
||||
logger,
|
||||
mockServices.rootConfig({ data: SES_SENDMAIL_CONFIG }),
|
||||
catalogServiceMock({ entities: [DEFAULT_ENTITIES_RESPONSE.items[0]] }),
|
||||
auth,
|
||||
);
|
||||
|
||||
await processor.postProcess(
|
||||
{
|
||||
origin: 'plugin',
|
||||
id: '1234',
|
||||
user: 'user:default/mock',
|
||||
created: new Date(),
|
||||
payload: { title: 'notification' },
|
||||
},
|
||||
{
|
||||
recipients: { type: 'entity', entityRef: 'user:default/mock' },
|
||||
payload: { title: 'notification' },
|
||||
},
|
||||
);
|
||||
|
||||
expect(sendmailMock).toHaveBeenCalledWith({
|
||||
from: 'backstage@backstage.io',
|
||||
html: '<p><a href="https://example.org/notifications">https://example.org/notifications</a></p>',
|
||||
replyTo: 'no-reply@backstage.io',
|
||||
subject: 'notification',
|
||||
text: 'https://example.org/notifications',
|
||||
to: 'mock@backstage.io',
|
||||
ses: {
|
||||
SourceArn: 'arn:aws:ses:us-west-2:123456789012:identity/example.com',
|
||||
FromArn: 'arn:aws:ses:us-west-2:123456789012:identity/example.com',
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+22
@@ -52,6 +52,7 @@ export class NotificationsEmailProcessor implements NotificationProcessor {
|
||||
private readonly transportConfig: Config;
|
||||
private readonly sender: string;
|
||||
private readonly replyTo?: string;
|
||||
private readonly sesConfig?: Config;
|
||||
private readonly cacheTtl: number;
|
||||
private readonly concurrencyLimit: number;
|
||||
private readonly throttleInterval: number;
|
||||
@@ -76,6 +77,7 @@ export class NotificationsEmailProcessor implements NotificationProcessor {
|
||||
emailProcessorConfig.getOptionalConfig('broadcastConfig');
|
||||
this.sender = emailProcessorConfig.getString('sender');
|
||||
this.replyTo = emailProcessorConfig.getOptionalString('replyTo');
|
||||
this.sesConfig = emailProcessorConfig.getOptionalConfig('sesConfig');
|
||||
this.concurrencyLimit =
|
||||
emailProcessorConfig.getOptionalNumber('concurrencyLimit') ?? 2;
|
||||
this.throttleInterval = emailProcessorConfig.has('throttleInterval')
|
||||
@@ -292,6 +294,24 @@ export class NotificationsEmailProcessor implements NotificationProcessor {
|
||||
return contentParts.join('\n\n');
|
||||
}
|
||||
|
||||
private async getSesOptions() {
|
||||
if (!this.sesConfig) {
|
||||
return undefined;
|
||||
}
|
||||
const ses: Record<string, string> = {};
|
||||
const sourceArn = this.sesConfig.getOptionalString('sourceArn');
|
||||
const fromArn = this.sesConfig.getOptionalString('fromArn');
|
||||
const configurationSetName = this.sesConfig.getOptionalString(
|
||||
'configurationSetName',
|
||||
);
|
||||
|
||||
if (sourceArn) ses.SourceArn = sourceArn;
|
||||
if (fromArn) ses.FromArn = fromArn;
|
||||
if (configurationSetName) ses.ConfigurationSetName = configurationSetName;
|
||||
|
||||
return Object.keys(ses).length > 0 ? ses : undefined;
|
||||
}
|
||||
|
||||
private async sendPlainEmail(notification: Notification, emails: string[]) {
|
||||
const mailOptions = {
|
||||
from: this.sender,
|
||||
@@ -299,6 +319,7 @@ export class NotificationsEmailProcessor implements NotificationProcessor {
|
||||
html: this.getHtmlContent(notification),
|
||||
text: this.getTextContent(notification),
|
||||
replyTo: this.replyTo,
|
||||
ses: await this.getSesOptions(),
|
||||
};
|
||||
|
||||
await this.sendMails(mailOptions, emails);
|
||||
@@ -316,6 +337,7 @@ export class NotificationsEmailProcessor implements NotificationProcessor {
|
||||
html: await this.templateRenderer?.getHtml?.(notification),
|
||||
text: await this.templateRenderer?.getText?.(notification),
|
||||
replyTo: this.replyTo,
|
||||
ses: await this.getSesOptions(),
|
||||
};
|
||||
|
||||
await this.sendMails(mailOptions, emails);
|
||||
|
||||
Reference in New Issue
Block a user