Skip to content

Commit

Permalink
geoip: implement GeoIpDatabase methods added in ES 8.14 (#139)
Browse files Browse the repository at this point in the history
Catches up with Elasticsearch 8.14+ support for user-provided databases:
 - `Anonymous-IP` elastic/elasticsearch#107287
 - `Enterprise` elastic/elasticsearch#107377

When compiled against Elasticsearch < 8.14, these methods neither exist in the
interface nor are reachable by the GeoIP processor.

Co-authored-by: Joe Gallo <joegallo@gmail.com>
  • Loading branch information
yaauie and joegallo committed Apr 23, 2024
1 parent 9aa0db9 commit 77b55b7
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
import org.elasticsearch.ingest.geoip.shaded.com.maxmind.db.NodeCache;
import org.elasticsearch.ingest.geoip.shaded.com.maxmind.geoip2.DatabaseReader;
import org.elasticsearch.ingest.geoip.shaded.com.maxmind.geoip2.model.AbstractResponse;
import org.elasticsearch.ingest.geoip.shaded.com.maxmind.geoip2.model.AnonymousIpResponse;
import org.elasticsearch.ingest.geoip.shaded.com.maxmind.geoip2.model.AsnResponse;
import org.elasticsearch.ingest.geoip.shaded.com.maxmind.geoip2.model.CityResponse;
import org.elasticsearch.ingest.geoip.shaded.com.maxmind.geoip2.model.CountryResponse;
import org.elasticsearch.ingest.geoip.shaded.com.maxmind.geoip2.model.EnterpriseResponse;

import java.io.Closeable;
import java.io.File;
Expand Down Expand Up @@ -52,6 +54,16 @@ public AsnResponse getAsn(InetAddress inetAddress) {
return getResponse(inetAddress, this.databaseReader::tryAsn);
}

/* @Override // neither available nor reachable until Elasticsearch 8.14 */
public AnonymousIpResponse getAnonymousIp(InetAddress ipAddress) {
return getResponse(ipAddress, this.databaseReader::tryAnonymousIp);
}

/* @Override // neither available nor reachable until Elasticsearch 8.14 */
public EnterpriseResponse getEnterprise(InetAddress ipAddress) {
return getResponse(ipAddress, this.databaseReader::tryEnterprise);
}

private <T extends AbstractResponse> T getResponse(final InetAddress inetAddress, MaxmindTryLookup<T> resolver) {
try {
return resolver.lookup(inetAddress).orElse(null);
Expand Down

0 comments on commit 77b55b7

Please sign in to comment.