From 77b55b7823872d2d7e0e29e1ceb93315248c5c97 Mon Sep 17 00:00:00 2001 From: Ry Biesemeyer Date: Tue, 23 Apr 2024 13:56:52 -0700 Subject: [PATCH] geoip: implement `GeoIpDatabase` methods added in ES 8.14 (#139) 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 --- .../geoip/GeoIpDatabaseAdapter.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/co/elastic/logstash/filters/elasticintegration/geoip/GeoIpDatabaseAdapter.java b/src/main/java/co/elastic/logstash/filters/elasticintegration/geoip/GeoIpDatabaseAdapter.java index e200ffd..f3d9914 100644 --- a/src/main/java/co/elastic/logstash/filters/elasticintegration/geoip/GeoIpDatabaseAdapter.java +++ b/src/main/java/co/elastic/logstash/filters/elasticintegration/geoip/GeoIpDatabaseAdapter.java @@ -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; @@ -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 getResponse(final InetAddress inetAddress, MaxmindTryLookup resolver) { try { return resolver.lookup(inetAddress).orElse(null);