diff --git a/core/src/main/java/google/registry/reporting/icann/IcannReportingStagingAction.java b/core/src/main/java/google/registry/reporting/icann/IcannReportingStagingAction.java index a5ed560a1..52d505264 100644 --- a/core/src/main/java/google/registry/reporting/icann/IcannReportingStagingAction.java +++ b/core/src/main/java/google/registry/reporting/icann/IcannReportingStagingAction.java @@ -29,6 +29,7 @@ import com.google.common.net.MediaType; import google.registry.batch.CloudTasksUtils; import google.registry.bigquery.BigqueryJobFailureException; import google.registry.config.RegistryConfig.Config; +import google.registry.groups.GmailClient; import google.registry.reporting.icann.IcannReportingModule.ReportType; import google.registry.request.Action; import google.registry.request.Action.Service; @@ -37,7 +38,6 @@ import google.registry.request.Response; import google.registry.request.auth.Auth; import google.registry.util.EmailMessage; import google.registry.util.Retrier; -import google.registry.util.SendEmailService; import java.util.Optional; import javax.inject.Inject; import javax.mail.internet.InternetAddress; @@ -83,8 +83,12 @@ public final class IcannReportingStagingAction implements Runnable { @Inject Retrier retrier; @Inject Response response; @Inject @Config("gSuiteOutgoingEmailAddress") InternetAddress sender; - @Inject @Config("alertRecipientEmailAddress") InternetAddress recipient; - @Inject SendEmailService emailService; + + @Inject + @Config("newAlertRecipientEmailAddress") + InternetAddress recipient; + + @Inject GmailClient gmailClient; @Inject CloudTasksUtils cloudTasksUtils; @Inject IcannReportingStagingAction() {} @@ -103,7 +107,7 @@ public final class IcannReportingStagingAction implements Runnable { stager.createAndUploadManifest(subdir, manifestedFiles); logger.atInfo().log("Completed staging %d report files.", manifestedFiles.size()); - emailService.sendEmail( + gmailClient.sendEmail( EmailMessage.newBuilder() .setSubject("ICANN Monthly report staging summary [SUCCESS]") .setBody( @@ -130,7 +134,7 @@ public final class IcannReportingStagingAction implements Runnable { }, BigqueryJobFailureException.class); } catch (Throwable e) { - emailService.sendEmail( + gmailClient.sendEmail( EmailMessage.create( "ICANN Monthly report staging summary [FAILURE]", String.format( diff --git a/core/src/main/java/google/registry/reporting/icann/IcannReportingUploadAction.java b/core/src/main/java/google/registry/reporting/icann/IcannReportingUploadAction.java index 9f43f6f26..af9d88e79 100644 --- a/core/src/main/java/google/registry/reporting/icann/IcannReportingUploadAction.java +++ b/core/src/main/java/google/registry/reporting/icann/IcannReportingUploadAction.java @@ -27,6 +27,7 @@ import com.google.common.flogger.FluentLogger; import com.google.common.io.ByteStreams; import google.registry.config.RegistryConfig.Config; import google.registry.gcs.GcsUtils; +import google.registry.groups.GmailClient; import google.registry.model.common.Cursor; import google.registry.model.common.Cursor.CursorType; import google.registry.model.tld.Tld; @@ -41,7 +42,6 @@ import google.registry.request.lock.LockHandler; import google.registry.util.Clock; import google.registry.util.EmailMessage; import google.registry.util.Retrier; -import google.registry.util.SendEmailService; import java.io.IOException; import java.io.InputStream; import java.util.Map; @@ -87,8 +87,12 @@ public final class IcannReportingUploadAction implements Runnable { @Inject Retrier retrier; @Inject Response response; @Inject @Config("gSuiteOutgoingEmailAddress") InternetAddress sender; - @Inject @Config("alertRecipientEmailAddress") InternetAddress recipient; - @Inject SendEmailService emailService; + + @Inject + @Config("newAlertRecipientEmailAddress") + InternetAddress recipient; + + @Inject GmailClient gmailClient; @Inject Clock clock; @Inject LockHandler lockHandler; @@ -293,7 +297,7 @@ public final class IcannReportingUploadAction implements Runnable { (e) -> String.format("%s - %s", e.getKey(), e.getValue() ? "SUCCESS" : "FAILURE")) .collect(Collectors.joining("\n"))); - emailService.sendEmail(EmailMessage.create(subject, body, recipient, sender)); + gmailClient.sendEmail(EmailMessage.create(subject, body, recipient, sender)); } private byte[] readBytesFromGcs(BlobId reportFilename) throws IOException { diff --git a/core/src/test/java/google/registry/reporting/icann/IcannReportingStagingActionTest.java b/core/src/test/java/google/registry/reporting/icann/IcannReportingStagingActionTest.java index 06b22702e..bf0c63e85 100644 --- a/core/src/test/java/google/registry/reporting/icann/IcannReportingStagingActionTest.java +++ b/core/src/test/java/google/registry/reporting/icann/IcannReportingStagingActionTest.java @@ -25,6 +25,7 @@ import com.google.cloud.tasks.v2.HttpMethod; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import google.registry.bigquery.BigqueryJobFailureException; +import google.registry.groups.GmailClient; import google.registry.reporting.icann.IcannReportingModule.ReportType; import google.registry.request.HttpException.BadRequestException; import google.registry.testing.CloudTasksHelper; @@ -34,7 +35,6 @@ import google.registry.testing.FakeResponse; import google.registry.testing.FakeSleeper; import google.registry.util.EmailMessage; import google.registry.util.Retrier; -import google.registry.util.SendEmailService; import java.util.Optional; import javax.mail.internet.InternetAddress; import org.joda.time.DateTime; @@ -65,7 +65,7 @@ class IcannReportingStagingActionTest { action.retrier = new Retrier(new FakeSleeper(new FakeClock()), 3); action.sender = new InternetAddress("sender@example.com"); action.recipient = new InternetAddress("recipient@example.com"); - action.emailService = mock(SendEmailService.class); + action.gmailClient = mock(GmailClient.class); action.cloudTasksUtils = cloudTasksHelper.getTestCloudTasksUtils(); when(stager.stageReports(yearMonth, subdir, ReportType.ACTIVITY)) @@ -89,7 +89,7 @@ class IcannReportingStagingActionTest { action.run(); verify(stager).stageReports(yearMonth, subdir, ReportType.ACTIVITY); verify(stager).createAndUploadManifest(subdir, ImmutableList.of("a", "b")); - verify(action.emailService) + verify(action.gmailClient) .sendEmail( EmailMessage.create( "ICANN Monthly report staging summary [SUCCESS]", @@ -105,7 +105,7 @@ class IcannReportingStagingActionTest { verify(stager).stageReports(yearMonth, subdir, ReportType.ACTIVITY); verify(stager).stageReports(yearMonth, subdir, ReportType.TRANSACTIONS); verify(stager).createAndUploadManifest(subdir, ImmutableList.of("a", "b", "c", "d")); - verify(action.emailService) + verify(action.gmailClient) .sendEmail( EmailMessage.create( "ICANN Monthly report staging summary [SUCCESS]", @@ -124,7 +124,7 @@ class IcannReportingStagingActionTest { verify(stager, times(2)).stageReports(yearMonth, subdir, ReportType.ACTIVITY); verify(stager, times(2)).stageReports(yearMonth, subdir, ReportType.TRANSACTIONS); verify(stager).createAndUploadManifest(subdir, ImmutableList.of("a", "b", "c", "d")); - verify(action.emailService) + verify(action.gmailClient) .sendEmail( EmailMessage.create( "ICANN Monthly report staging summary [SUCCESS]", @@ -147,7 +147,7 @@ class IcannReportingStagingActionTest { .hasMessageThat() .isEqualTo("BigqueryJobFailureException: Expected failure"); verify(stager, times(3)).stageReports(yearMonth, subdir, ReportType.ACTIVITY); - verify(action.emailService) + verify(action.gmailClient) .sendEmail( EmailMessage.create( "ICANN Monthly report staging summary [FAILURE]", diff --git a/core/src/test/java/google/registry/reporting/icann/IcannReportingUploadActionTest.java b/core/src/test/java/google/registry/reporting/icann/IcannReportingUploadActionTest.java index 3538d7b55..411289afe 100644 --- a/core/src/test/java/google/registry/reporting/icann/IcannReportingUploadActionTest.java +++ b/core/src/test/java/google/registry/reporting/icann/IcannReportingUploadActionTest.java @@ -31,6 +31,7 @@ import com.google.cloud.storage.BlobId; import com.google.cloud.storage.contrib.nio.testing.LocalStorageHelper; import com.google.common.testing.TestLogHandler; import google.registry.gcs.GcsUtils; +import google.registry.groups.GmailClient; import google.registry.model.common.Cursor; import google.registry.model.common.Cursor.CursorType; import google.registry.model.tld.Tld; @@ -43,7 +44,6 @@ import google.registry.testing.FakeResponse; import google.registry.testing.FakeSleeper; import google.registry.util.EmailMessage; import google.registry.util.Retrier; -import google.registry.util.SendEmailService; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; @@ -63,7 +63,7 @@ class IcannReportingUploadActionTest { private static final byte[] PAYLOAD_SUCCESS = "test,csv\n13,37".getBytes(UTF_8); private static final byte[] PAYLOAD_FAIL = "ahah,csv\n12,34".getBytes(UTF_8); private final IcannHttpReporter mockReporter = mock(IcannHttpReporter.class); - private final SendEmailService emailService = mock(SendEmailService.class); + private final GmailClient gmailClient = mock(GmailClient.class); private final FakeResponse response = new FakeResponse(); private final GcsUtils gcsUtils = new GcsUtils(LocalStorageHelper.getOptions()); private final TestLogHandler logHandler = new TestLogHandler(); @@ -77,7 +77,7 @@ class IcannReportingUploadActionTest { action.gcsUtils = gcsUtils; action.retrier = new Retrier(new FakeSleeper(new FakeClock()), 3); action.reportingBucket = "basin"; - action.emailService = emailService; + action.gmailClient = gmailClient; action.sender = new InternetAddress("sender@example.com"); action.recipient = new InternetAddress("recipient@example.com"); action.response = response; @@ -127,7 +127,7 @@ class IcannReportingUploadActionTest { verify(mockReporter).send(PAYLOAD_SUCCESS, "tld-transactions-200606.csv"); verifyNoMoreInteractions(mockReporter); - verify(emailService) + verify(gmailClient) .sendEmail( EmailMessage.create( "ICANN Monthly report upload summary: 3/4 succeeded", @@ -162,7 +162,7 @@ class IcannReportingUploadActionTest { verify(mockReporter).send(PAYLOAD_SUCCESS, "tld-transactions-200512.csv"); verifyNoMoreInteractions(mockReporter); - verify(emailService) + verify(gmailClient) .sendEmail( EmailMessage.create( "ICANN Monthly report upload summary: 2/2 succeeded", @@ -191,7 +191,7 @@ class IcannReportingUploadActionTest { IcannReportingUploadAction action = createAction(); action.run(); verifyNoMoreInteractions(mockReporter); - verifyNoMoreInteractions(emailService); + verifyNoMoreInteractions(gmailClient); } @Test @@ -206,7 +206,7 @@ class IcannReportingUploadActionTest { verify(mockReporter).send(PAYLOAD_SUCCESS, "foo-transactions-200606.csv"); verify(mockReporter, times(2)).send(PAYLOAD_SUCCESS, "tld-transactions-200606.csv"); verifyNoMoreInteractions(mockReporter); - verify(emailService) + verify(gmailClient) .sendEmail( EmailMessage.create( "ICANN Monthly report upload summary: 3/4 succeeded", @@ -266,7 +266,7 @@ class IcannReportingUploadActionTest { verify(mockReporter).send(PAYLOAD_SUCCESS, "foo-transactions-200606.csv"); verify(mockReporter).send(PAYLOAD_SUCCESS, "tld-transactions-200606.csv"); verifyNoMoreInteractions(mockReporter); - verify(emailService) + verify(gmailClient) .sendEmail( EmailMessage.create( "ICANN Monthly report upload summary: 3/4 succeeded", @@ -336,7 +336,7 @@ class IcannReportingUploadActionTest { verify(mockReporter).send(PAYLOAD_SUCCESS, "tld-transactions-200606.csv"); verifyNoMoreInteractions(mockReporter); - verify(emailService) + verify(gmailClient) .sendEmail( EmailMessage.create( "ICANN Monthly report upload summary: 3/4 succeeded",