mirror of
https://github.com/google/nomulus.git
synced 2025-05-28 12:31:08 +02:00
Add Spec11 registrar emailing mechanism
This adds the terminal step of the Spec11 pipeline- processing the output of the Beam pipeline to send an e-mail to each registrar informing them of identified 'bad urls.' This also factors out methods common between invoicing (which uses similar beam pipeline tools) and spec11 to the common superpackage ReportingModule + ReportingUtils classes. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=210932496
This commit is contained in:
parent
e4bb1c281c
commit
c5e6eae555
26 changed files with 816 additions and 93 deletions
|
@ -55,6 +55,21 @@ import org.json.JSONObject;
|
|||
*/
|
||||
public class Spec11Pipeline implements Serializable {
|
||||
|
||||
/**
|
||||
* Returns the subdirectory spec11 reports reside in for a given yearMonth in yyyy-MM format.
|
||||
*
|
||||
* @see google.registry.beam.spec11.Spec11Pipeline
|
||||
* @see google.registry.reporting.spec11.Spec11EmailUtils
|
||||
*/
|
||||
public static String getSpec11Subdirectory(String yearMonth) {
|
||||
return String.format("icann/spec11/%s/SPEC11_MONTHLY_REPORT", yearMonth);
|
||||
}
|
||||
|
||||
/** The JSON object field we put the registrar's e-mail address for Spec11 reports. */
|
||||
public static final String REGISTRAR_EMAIL_FIELD = "registrarEmailAddress";
|
||||
/** The JSON object field we put the threat match array for Spec11 reports. */
|
||||
public static final String THREAT_MATCHES_FIELD = "threatMatches";
|
||||
|
||||
@Inject
|
||||
@Config("projectId")
|
||||
String projectId;
|
||||
|
@ -68,8 +83,8 @@ public class Spec11Pipeline implements Serializable {
|
|||
String spec11TemplateUrl;
|
||||
|
||||
@Inject
|
||||
@Config("spec11BucketUrl")
|
||||
String spec11BucketUrl;
|
||||
@Config("reportingBucketUrl")
|
||||
String reportingBucketUrl;
|
||||
|
||||
@Inject
|
||||
Retrier retrier;
|
||||
|
@ -165,12 +180,12 @@ public class Spec11Pipeline implements Serializable {
|
|||
(KV<String, Iterable<ThreatMatch>> kv) -> {
|
||||
JSONObject output = new JSONObject();
|
||||
try {
|
||||
output.put("registrarEmailAddress", kv.getKey());
|
||||
output.put(REGISTRAR_EMAIL_FIELD, kv.getKey());
|
||||
JSONArray threatMatches = new JSONArray();
|
||||
for (ThreatMatch match : kv.getValue()) {
|
||||
threatMatches.put(match.toJSON());
|
||||
}
|
||||
output.put("threatMatches", threatMatches);
|
||||
output.put(THREAT_MATCHES_FIELD, threatMatches);
|
||||
return output.toString();
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(
|
||||
|
@ -187,8 +202,10 @@ public class Spec11Pipeline implements Serializable {
|
|||
yearMonthProvider,
|
||||
yearMonth ->
|
||||
String.format(
|
||||
"%s/%s/%s-monthly-report", spec11BucketUrl, yearMonth, yearMonth)))
|
||||
"%s/%s",
|
||||
reportingBucketUrl, getSpec11Subdirectory(yearMonth))))
|
||||
.withoutSharding()
|
||||
.withHeader("Map from registrar email to detected subdomain threats:"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,9 +26,10 @@ public abstract class ThreatMatch implements Serializable {
|
|||
private static final String THREAT_TYPE_FIELD = "threatType";
|
||||
private static final String PLATFORM_TYPE_FIELD = "platformType";
|
||||
private static final String METADATA_FIELD = "threatEntryMetadata";
|
||||
private static final String DOMAIN_NAME_FIELD = "fullyQualifiedDomainName";
|
||||
|
||||
/** Returns what kind of threat it is (malware, phishing etc.) */
|
||||
abstract String threatType();
|
||||
public abstract String threatType();
|
||||
/** Returns what platforms it affects (Windows, Linux etc.) */
|
||||
abstract String platformType();
|
||||
/**
|
||||
|
@ -40,7 +41,7 @@ public abstract class ThreatMatch implements Serializable {
|
|||
*/
|
||||
abstract String metadata();
|
||||
/** Returns the fully qualified domain name [SLD].[TLD] of the matched threat. */
|
||||
abstract String fullyQualifiedDomainName();
|
||||
public abstract String fullyQualifiedDomainName();
|
||||
|
||||
/**
|
||||
* Constructs a {@link ThreatMatch} by parsing a {@code SafeBrowsing API} response {@link
|
||||
|
@ -59,14 +60,21 @@ public abstract class ThreatMatch implements Serializable {
|
|||
fullyQualifiedDomainName);
|
||||
}
|
||||
|
||||
/** Returns a {@link String} containing the simplest details about this threat. */
|
||||
String getSimpleDetails() {
|
||||
return String.format("%s;%s", this.fullyQualifiedDomainName(), this.threatType());
|
||||
}
|
||||
/** Returns a {@link JSONObject} representing a subset of this object's data. */
|
||||
JSONObject toJSON() throws JSONException {
|
||||
return new JSONObject()
|
||||
.put("fullyQualifiedDomainName", fullyQualifiedDomainName())
|
||||
.put("threatType", threatType());
|
||||
.put(THREAT_TYPE_FIELD, threatType())
|
||||
.put(PLATFORM_TYPE_FIELD, platformType())
|
||||
.put(METADATA_FIELD, metadata())
|
||||
.put(DOMAIN_NAME_FIELD, fullyQualifiedDomainName());
|
||||
}
|
||||
|
||||
/** Parses a {@link JSONObject} and returns an equivalent {@link ThreatMatch}. */
|
||||
public static ThreatMatch fromJSON(JSONObject threatMatch) throws JSONException {
|
||||
return new AutoValue_ThreatMatch(
|
||||
threatMatch.getString(THREAT_TYPE_FIELD),
|
||||
threatMatch.getString(PLATFORM_TYPE_FIELD),
|
||||
threatMatch.getString(METADATA_FIELD),
|
||||
threatMatch.getString(DOMAIN_NAME_FIELD));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue