From cbf149af1f07bb98c1f856948a79dcf3fb0c43b3 Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Mon, 4 Sep 2017 10:05:38 -0700 Subject: SESNotificationService to accept multiple destinations. notificationEmail is now a comma separated list of addresses. Adding unit tests for SESNotificationService. Refactored AWS credential selection into ConfigCredentialProvider. --- .../grow/backend/SESNotificationService.java | 37 ++++++---------------- 1 file changed, 9 insertions(+), 28 deletions(-) (limited to 'src/main/java/com/p4square/grow/backend/SESNotificationService.java') diff --git a/src/main/java/com/p4square/grow/backend/SESNotificationService.java b/src/main/java/com/p4square/grow/backend/SESNotificationService.java index 58b732d..b42d09b 100644 --- a/src/main/java/com/p4square/grow/backend/SESNotificationService.java +++ b/src/main/java/com/p4square/grow/backend/SESNotificationService.java @@ -1,13 +1,12 @@ package com.p4square.grow.backend; -import com.amazonaws.auth.AWSCredentials; -import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; import com.amazonaws.regions.Region; import com.amazonaws.regions.Regions; import com.amazonaws.services.simpleemail.AmazonSimpleEmailService; import com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient; import com.amazonaws.services.simpleemail.model.*; import com.p4square.grow.config.Config; +import com.p4square.grow.config.ConfigCredentialProvider; import org.apache.log4j.Logger; /** @@ -22,40 +21,22 @@ public class SESNotificationService implements NotificationService { private final Destination mDestination; public SESNotificationService(final Config config) { - AWSCredentials creds; - - String awsAccessKey = config.getString("awsAccessKey"); - if (awsAccessKey != null) { - creds = new AWSCredentials() { - @Override - public String getAWSAccessKeyId() { - return config.getString("awsAccessKey"); - } - @Override - public String getAWSSecretKey() { - return config.getString("awsSecretKey"); - } - }; - } else { - creds = new DefaultAWSCredentialsProviderChain().getCredentials(); - } - - mClient = new AmazonSimpleEmailServiceClient(creds); + this(config, new AmazonSimpleEmailServiceClient(new ConfigCredentialProvider(config))); + // Set the AWS region. String region = config.getString("awsRegion"); if (region != null) { mClient.setRegion(Region.getRegion(Regions.fromName(region))); } + } + + public SESNotificationService(Config config, AmazonSimpleEmailService client) { + mClient = client; mSourceAddress = config.getString("notificationSourceEmail"); - final String dest = config.getString("notificationEmail"); - if (dest != null) { - mDestination = new Destination().withToAddresses(dest); - } else { - // Notifications are not configured. - mDestination = null; - } + final String[] dests = config.getString("notificationEmail", "").split(","); + mDestination = new Destination().withToAddresses(dests); } @Override -- cgit v1.2.3