Skip to content

Commit

Permalink
Common: Enable IP Lookup Enrichment for IPv6 with port number (close #…
Browse files Browse the repository at this point in the history
  • Loading branch information
oguzhanunlu committed Jul 10, 2020
1 parent 05949bf commit ee8cb9f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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._
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit ee8cb9f

Please sign in to comment.