From ee8cb9f91ee7c27fed9c73d71085ebb55daf02f2 Mon Sep 17 00:00:00 2001 From: Oguzhan Unlu Date: Thu, 9 Jul 2020 19:47:23 +0300 Subject: [PATCH] Common: Enable IP Lookup Enrichment for IPv6 with port number (close #284) --- .../common/enrichments/EnrichmentManager.scala | 5 ----- .../common/enrichments/registry/IpLookupsEnrichment.scala | 7 +++---- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/modules/common/src/main/scala/com.snowplowanalytics.snowplow.enrich/common/enrichments/EnrichmentManager.scala b/modules/common/src/main/scala/com.snowplowanalytics.snowplow.enrich/common/enrichments/EnrichmentManager.scala index 0fe26a791..ee5dad777 100644 --- a/modules/common/src/main/scala/com.snowplowanalytics.snowplow.enrich/common/enrichments/EnrichmentManager.scala +++ b/modules/common/src/main/scala/com.snowplowanalytics.snowplow.enrich/common/enrichments/EnrichmentManager.scala @@ -13,8 +13,6 @@ package com.snowplowanalytics.snowplow.enrich.common package enrichments -import scala.util.matching.Regex - import java.nio.charset.Charset import java.net.URI import java.time.Instant @@ -52,9 +50,6 @@ import utils.{IgluUtils, ConversionUtils => CU} object EnrichmentManager { - // Regex for IPv4 without port - val IPv4Regex: Regex = """(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}).*""".r - /** * Run the enrichment workflow * @param registry Contain configuration for all enrichments to apply diff --git a/modules/common/src/main/scala/com.snowplowanalytics.snowplow.enrich/common/enrichments/registry/IpLookupsEnrichment.scala b/modules/common/src/main/scala/com.snowplowanalytics.snowplow.enrich/common/enrichments/registry/IpLookupsEnrichment.scala index d49881aca..3fb81b183 100644 --- a/modules/common/src/main/scala/com.snowplowanalytics.snowplow.enrich/common/enrichments/registry/IpLookupsEnrichment.scala +++ b/modules/common/src/main/scala/com.snowplowanalytics.snowplow.enrich/common/enrichments/registry/IpLookupsEnrichment.scala @@ -16,6 +16,8 @@ package registry import java.net.URI +import inet.ipaddr.HostName + import cats.Functor import cats.data.{NonEmptyList, ValidatedNel} import cats.implicits._ @@ -120,10 +122,7 @@ final case class IpLookupsEnrichment[F[_]](ipLookups: IpLookups[F]) extends Enri * @return an IpLookupResult */ def extractIpInformation(ip: String): F[IpLookupResult] = - ip match { - case EnrichmentManager.IPv4Regex(ipv4WithoutPort) => ipLookups.performLookups(ipv4WithoutPort) - case _ => ipLookups.performLookups(ip) - } + ipLookups.performLookups(Either.catchNonFatal(new HostName(ip).toAddress).fold(_ => ip, addr => addr.toString)) } private[enrichments] final case class IpLookupsDatabase(