diff options
author | Jesse Morgan <jesse@jesterpm.net> | 2017-09-04 10:05:38 -0700 |
---|---|---|
committer | Jesse Morgan <jesse@jesterpm.net> | 2017-09-04 10:05:38 -0700 |
commit | cbf149af1f07bb98c1f856948a79dcf3fb0c43b3 (patch) | |
tree | 7901334e10e181ba2c79c09b3a9a32f16c1abc42 /src/main/java/com/p4square/grow/backend/SESNotificationService.java | |
parent | 72ee0f10ddca0d880e50d13446f9ac0269e542eb (diff) |
SESNotificationService to accept multiple destinations.20170904
notificationEmail is now a comma separated list of addresses.
Adding unit tests for SESNotificationService.
Refactored AWS credential selection into ConfigCredentialProvider.
Diffstat (limited to 'src/main/java/com/p4square/grow/backend/SESNotificationService.java')
-rw-r--r-- | src/main/java/com/p4square/grow/backend/SESNotificationService.java | 37 |
1 files changed, 9 insertions, 28 deletions
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 |