Skip to content

Commit

Permalink
Normalise email address value before adding to index table (#1550)
Browse files Browse the repository at this point in the history
* Normalise email address value before adding to index table

* If parsing fails, log a warning and return the original value (this should not happen normally but we can investigate further).

* Remove duplicated code
  • Loading branch information
eshryane authored Sep 25, 2024
1 parent 348ab1a commit 24303ac
Show file tree
Hide file tree
Showing 4 changed files with 411 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public final class IndexStrategies {
static {
final IndexStrategy[] indexStrategies = {
new IndexWithReference(AttributeType.ABUSE_C, "abuse_c", "pe_ro_id"),
new IndexWithValueAndType(AttributeType.ABUSE_MAILBOX, "abuse_mailbox", "abuse_mailbox"),
new IndexWithEmailAddressValueAndType(AttributeType.ABUSE_MAILBOX, "abuse_mailbox", "abuse_mailbox"),
new Unindexed(AttributeType.ADDRESS),
new IndexWithReference(AttributeType.ADMIN_C, "admin_c", "pe_ro_id"),
new Unindexed(AttributeType.AGGR_BNDRY),
Expand All @@ -43,7 +43,7 @@ public final class IndexStrategies {
new Unindexed(AttributeType.EXPORT),
new Unindexed(AttributeType.EXPORT_VIA),
new Unindexed(AttributeType.EXPORT_COMPS),
new IndexWithValueAndType(AttributeType.E_MAIL, "e_mail", "e_mail"),
new IndexWithEmailAddressValueAndType(AttributeType.E_MAIL, "e_mail", "e_mail"),
new Unindexed(AttributeType.FAX_NO),
new Unindexed(AttributeType.FILTER),
new IndexWithValue(AttributeType.FILTER_SET, "filter_set", "filter_set"),
Expand All @@ -61,7 +61,7 @@ public final class IndexStrategies {
new Unindexed(AttributeType.INJECT),
new Unindexed(AttributeType.INTERFACE),
new IndexWithValue(AttributeType.IRT, "irt", "irt"),
new IndexWithValue(AttributeType.IRT_NFY, "irt_nfy", "irt_nfy"),
new IndexWithEmailAddressValue(AttributeType.IRT_NFY, "irt_nfy", "irt_nfy"),
new IndexWithValue(AttributeType.KEY_CERT, "key_cert", "key_cert"),
new Unindexed(AttributeType.LANGUAGE),
new Unindexed(AttributeType.LAST_MODIFIED),
Expand All @@ -75,7 +75,7 @@ public final class IndexStrategies {
new IndexWithReference(AttributeType.MNT_DOMAINS, "mnt_domains", "mnt_id"),
new IndexWithReference(AttributeType.MNT_IRT, "mnt_irt", "irt_id"),
new IndexWithReference(AttributeType.MNT_LOWER, "mnt_lower", "mnt_id"),
new IndexWithValue(AttributeType.MNT_NFY, "mnt_nfy", "mnt_nfy"),
new IndexWithEmailAddressValue(AttributeType.MNT_NFY, "mnt_nfy", "mnt_nfy"),
new IndexWithReference(AttributeType.MNT_REF, "mnt_ref", "mnt_id"),
new IndexWithMntRoutes(AttributeType.MNT_ROUTES),
new Unindexed(AttributeType.MP_DEFAULT),
Expand All @@ -87,7 +87,7 @@ public final class IndexStrategies {
new Unindexed(AttributeType.MP_PEERING),
new Unindexed(AttributeType.NETNAME), // TODO: [AH] ATM this is handled by JdbcInetnumDao/JdbcInet6numDao as a special case
new IndexWithValueAndType(AttributeType.NIC_HDL, "person_role", "nic_hdl"),
new IndexWithValueAndType(AttributeType.NOTIFY, "notify", "notify"),
new IndexWithEmailAddressValueAndType(AttributeType.NOTIFY, "notify", "notify"),
new IndexWithNServer(AttributeType.NSERVER, "nserver", "host"),
new IndexWithReference(AttributeType.ORG, "org", "org_id"),
new Unindexed(AttributeType.ORG_TYPE),
Expand All @@ -104,7 +104,7 @@ public final class IndexStrategies {
new Unindexed(AttributeType.PINGABLE),
new IndexWithValue(AttributeType.POEM, "poem", "poem"),
new IndexWithValue(AttributeType.POETIC_FORM, "poetic_form", "poetic_form"),
new IndexWithValue(AttributeType.REF_NFY, "ref_nfy", "ref_nfy"),
new IndexWithEmailAddressValue(AttributeType.REF_NFY, "ref_nfy", "ref_nfy"),
new Unindexed(AttributeType.REMARKS),
new IndexWithNameAndType(AttributeType.ROLE, ObjectType.ROLE, "names"),
new IndexWithRoute(AttributeType.ROUTE),
Expand All @@ -117,7 +117,7 @@ public final class IndexStrategies {
new IndexWithValueAndType(AttributeType.STATUS, "status", "status"),
new IndexWithReference(AttributeType.TECH_C, "tech_c", "pe_ro_id"),
new Unindexed(AttributeType.TEXT),
new IndexWithValue(AttributeType.UPD_TO, "upd_to", "upd_to"),
new IndexWithEmailAddressValue(AttributeType.UPD_TO, "upd_to", "upd_to"),
new IndexWithReference(AttributeType.ZONE_C, "zone_c", "pe_ro_id")
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package net.ripe.db.whois.common.dao.jdbc.index;

import net.ripe.db.whois.common.dao.RpslObjectInfo;
import net.ripe.db.whois.common.rpsl.AttributeParser;
import net.ripe.db.whois.common.rpsl.AttributeType;
import net.ripe.db.whois.common.rpsl.RpslObject;
import net.ripe.db.whois.common.rpsl.attrs.AttributeParseException;
import org.springframework.jdbc.core.JdbcTemplate;

class IndexWithEmailAddressValue extends IndexWithValue {

private static final AttributeParser.EmailParser EMAIL_PARSER = new AttributeParser.EmailParser();

public IndexWithEmailAddressValue(final AttributeType attributeType, final String lookupTableName, final String lookupColumnName) {
super(attributeType, lookupTableName, lookupColumnName);
}

@Override
public int addToIndex(final JdbcTemplate jdbcTemplate, final RpslObjectInfo objectInfo, final RpslObject object, final String value) {
return super.addToIndex(jdbcTemplate, objectInfo, object, normaliseEmailAddress(value));
}

protected static String normaliseEmailAddress(final String emailAddress) {
try {
return EMAIL_PARSER.parse(emailAddress).getAddress();
} catch (AttributeParseException e) {
return emailAddress;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package net.ripe.db.whois.common.dao.jdbc.index;

import net.ripe.db.whois.common.dao.RpslObjectInfo;
import net.ripe.db.whois.common.rpsl.AttributeType;
import net.ripe.db.whois.common.rpsl.RpslObject;
import org.springframework.jdbc.core.JdbcTemplate;

class IndexWithEmailAddressValueAndType extends IndexWithValueAndType {

public IndexWithEmailAddressValueAndType(final AttributeType attributeType, final String lookupTableName, final String lookupColumnName) {
super(attributeType, lookupTableName, lookupColumnName);
}

@Override
public int addToIndex(JdbcTemplate jdbcTemplate, RpslObjectInfo objectInfo, RpslObject object, String value) {
return super.addToIndex(jdbcTemplate, objectInfo, object, IndexWithEmailAddressValue.normaliseEmailAddress(value));
}
}
Loading

0 comments on commit 24303ac

Please sign in to comment.