mirror of
https://github.com/google/nomulus.git
synced 2025-05-17 01:47:14 +02:00
Use the registrar client ID and abuse email address in Spec11
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=244899045
This commit is contained in:
parent
9f979790e4
commit
2b12ca42f5
9 changed files with 87 additions and 27 deletions
|
@ -12,6 +12,7 @@ java_library(
|
|||
"//java/google/registry/config",
|
||||
"//java/google/registry/gcs",
|
||||
"//java/google/registry/keyring/api",
|
||||
"//java/google/registry/model",
|
||||
"//java/google/registry/reporting",
|
||||
"//java/google/registry/reporting/spec11/soy:soy_java_wrappers",
|
||||
"//java/google/registry/request",
|
||||
|
|
|
@ -52,8 +52,8 @@ import org.json.JSONException;
|
|||
* Retries until a {@code Dataflow} job with a given {@code jobId} completes, continuing the Spec11
|
||||
* pipeline accordingly.
|
||||
*
|
||||
* <p>This calls {@link Spec11EmailUtils#emailSpec11Reports(SoyTemplateInfo, String, Set)} on
|
||||
* success or {@link Spec11EmailUtils#sendAlertEmail(String, String)} on failure.
|
||||
* <p>This calls {@link Spec11EmailUtils#emailSpec11Reports(LocalDate, SoyTemplateInfo, String,
|
||||
* Set)} on success or {@link Spec11EmailUtils#sendAlertEmail(String, String)} on failure.
|
||||
*/
|
||||
@Action(
|
||||
service = Action.Service.BACKEND,
|
||||
|
@ -193,7 +193,7 @@ public class PublishSpec11ReportAction implements Runnable {
|
|||
// Group by email address then flat-map all of the ThreatMatch objects together
|
||||
return ImmutableMap.copyOf(
|
||||
Maps.transformValues(
|
||||
Multimaps.index(registrarThreatMatches, RegistrarThreatMatches::registrarEmailAddress)
|
||||
Multimaps.index(registrarThreatMatches, RegistrarThreatMatches::clientId)
|
||||
.asMap(),
|
||||
registrarThreatMatchesCollection ->
|
||||
registrarThreatMatchesCollection.stream()
|
||||
|
|
|
@ -23,13 +23,11 @@ import java.util.List;
|
|||
@AutoValue
|
||||
public abstract class RegistrarThreatMatches {
|
||||
|
||||
public abstract String registrarEmailAddress();
|
||||
public abstract String clientId();
|
||||
|
||||
public abstract ImmutableList<ThreatMatch> threatMatches();
|
||||
|
||||
static RegistrarThreatMatches create(
|
||||
String registrarEmailAddress, List<ThreatMatch> threatMatches) {
|
||||
return new AutoValue_RegistrarThreatMatches(
|
||||
registrarEmailAddress, ImmutableList.copyOf(threatMatches));
|
||||
static RegistrarThreatMatches create(String clientId, List<ThreatMatch> threatMatches) {
|
||||
return new AutoValue_RegistrarThreatMatches(clientId, ImmutableList.copyOf(threatMatches));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,8 @@ import com.google.template.soy.parseinfo.SoyTemplateInfo;
|
|||
import com.google.template.soy.tofu.SoyTofu;
|
||||
import com.google.template.soy.tofu.SoyTofu.Renderer;
|
||||
import google.registry.config.RegistryConfig.Config;
|
||||
import google.registry.model.registrar.Registrar;
|
||||
import google.registry.model.registrar.RegistrarContact;
|
||||
import google.registry.reporting.spec11.soy.Spec11EmailSoyInfo;
|
||||
import google.registry.util.EmailMessage;
|
||||
import google.registry.util.SendEmailService;
|
||||
|
@ -105,11 +107,10 @@ public class Spec11EmailUtils {
|
|||
String.format("Spec11 Emailing Failure %s", date),
|
||||
String.format("Emailing Spec11 reports failed due to %s", firstThrowable.getMessage()));
|
||||
for (int i = 1; i < failedMatches.size(); i++) {
|
||||
// TODO(b/129401965): Use only client IDs in this message
|
||||
logger.atSevere().withCause(failedMatchesList.get(i).getValue()).log(
|
||||
"Additional exception thrown when sending email to registrar %s, in addition to the"
|
||||
+ " re-thrown exception",
|
||||
failedMatchesList.get(i).getKey().registrarEmailAddress());
|
||||
failedMatchesList.get(i).getKey().clientId());
|
||||
}
|
||||
throw new RuntimeException(
|
||||
"Emailing Spec11 reports failed, first exception:", firstThrowable);
|
||||
|
@ -131,7 +132,7 @@ public class Spec11EmailUtils {
|
|||
.setBody(getContent(date, soyTemplateInfo, registrarThreatMatches))
|
||||
.setContentType(MediaType.HTML_UTF_8)
|
||||
.setFrom(outgoingEmailAddress)
|
||||
.addRecipient(new InternetAddress(registrarThreatMatches.registrarEmailAddress()))
|
||||
.addRecipient(getEmailAddressForRegistrar(registrarThreatMatches.clientId()))
|
||||
.setBcc(spec11ReplyToAddress)
|
||||
.build());
|
||||
}
|
||||
|
@ -176,4 +177,19 @@ public class Spec11EmailUtils {
|
|||
throw new RuntimeException("The spec11 alert e-mail system failed.", e);
|
||||
}
|
||||
}
|
||||
|
||||
private InternetAddress getEmailAddressForRegistrar(String clientId) throws MessagingException {
|
||||
// Attempt to use the registrar's WHOIS abuse contact, then fall back to the regular address.
|
||||
Registrar registrar =
|
||||
Registrar.loadByClientIdCached(clientId)
|
||||
.orElseThrow(
|
||||
() ->
|
||||
new IllegalArgumentException(
|
||||
String.format("Could not find registrar %s", clientId)));
|
||||
return new InternetAddress(
|
||||
registrar
|
||||
.getWhoisAbuseContact()
|
||||
.map(RegistrarContact::getEmailAddress)
|
||||
.orElse(registrar.getEmailAddress()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,12 +98,12 @@ public class Spec11RegistrarThreatMatchesParser {
|
|||
|
||||
private RegistrarThreatMatches parseRegistrarThreatMatch(String line) throws JSONException {
|
||||
JSONObject reportJSON = new JSONObject(line);
|
||||
String registrarEmail = reportJSON.getString(Spec11Pipeline.REGISTRAR_EMAIL_FIELD);
|
||||
String clientId = reportJSON.getString(Spec11Pipeline.REGISTRAR_CLIENT_ID_FIELD);
|
||||
JSONArray threatMatchesArray = reportJSON.getJSONArray(Spec11Pipeline.THREAT_MATCHES_FIELD);
|
||||
ImmutableList.Builder<ThreatMatch> threatMatches = ImmutableList.builder();
|
||||
for (int i = 0; i < threatMatchesArray.length(); i++) {
|
||||
threatMatches.add(ThreatMatch.fromJSON(threatMatchesArray.getJSONObject(i)));
|
||||
}
|
||||
return RegistrarThreatMatches.create(registrarEmail, threatMatches.build());
|
||||
return RegistrarThreatMatches.create(clientId, threatMatches.build());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue