1
0
mirror of https://github.com/google/nomulus synced 2026-04-26 19:15:24 +00:00

Add a parameter to prevent spec11 from sending emails (#1407)

This commit is contained in:
sarahcaseybot
2021-11-05 13:02:59 -04:00
committed by GitHub
parent 01d3932122
commit 2d1a67b01b
4 changed files with 50 additions and 1 deletions

View File

@@ -14,6 +14,7 @@
package google.registry.reporting;
import static google.registry.request.RequestParameters.extractOptionalBooleanParameter;
import static google.registry.request.RequestParameters.extractOptionalParameter;
import static google.registry.request.RequestParameters.extractRequiredParameter;
@@ -55,6 +56,12 @@ public class ReportingModule {
/** The request parameter specifying the jobId for a running Dataflow pipeline. */
public static final String PARAM_JOB_ID = "jobId";
/**
* The request parameter name used by actions to indicate if an email should be sent. This
* parameter defaults to true if not specified.
*/
public static final String SEND_EMAIL = "email";
/** Provides the Cloud Dataflow jobId for a pipeline. */
@Provides
@Parameter(PARAM_JOB_ID)
@@ -62,6 +69,13 @@ public class ReportingModule {
return extractRequiredParameter(req, PARAM_JOB_ID);
}
/** Provides the boolean value indicating if emails should be sent. */
@Provides
@Parameter(SEND_EMAIL)
static boolean provideSendEmail(HttpServletRequest req) {
return extractOptionalBooleanParameter(req, SEND_EMAIL).orElse(true);
}
/** Extracts an optional YearMonth in yyyy-MM format from the request. */
@Provides
@Parameter(PARAM_YEAR_MONTH)

View File

@@ -72,6 +72,7 @@ public class GenerateSpec11ReportAction implements Runnable {
private final Response response;
private final Dataflow dataflow;
private final PrimaryDatabase database;
private final boolean sendEmail;
@Inject
GenerateSpec11ReportAction(
@@ -82,6 +83,7 @@ public class GenerateSpec11ReportAction implements Runnable {
@Key("safeBrowsingAPIKey") String apiKey,
@Parameter(ReportingModule.PARAM_DATE) LocalDate date,
@Parameter(RequestParameters.PARAM_DATABASE) PrimaryDatabase database,
@Parameter(ReportingModule.SEND_EMAIL) boolean sendEmail,
Clock clock,
Response response,
Dataflow dataflow) {
@@ -98,6 +100,7 @@ public class GenerateSpec11ReportAction implements Runnable {
this.clock = clock;
this.response = response;
this.dataflow = dataflow;
this.sendEmail = sendEmail;
}
@Override
@@ -136,7 +139,9 @@ public class GenerateSpec11ReportAction implements Runnable {
Map<String, String> beamTaskParameters =
ImmutableMap.of(
ReportingModule.PARAM_JOB_ID, jobId, ReportingModule.PARAM_DATE, date.toString());
enqueueBeamReportingTask(PublishSpec11ReportAction.PATH, beamTaskParameters);
if (sendEmail) {
enqueueBeamReportingTask(PublishSpec11ReportAction.PATH, beamTaskParameters);
}
response.setStatus(SC_OK);
response.setPayload(String.format("Launched Spec11 pipeline: %s", jobId));
} catch (IOException e) {