Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub-issue#253 : Implemented download maxmind test mmdb files to re… #3193

Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions data-prepper-plugins/geoip-processor/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import javax.net.ssl.HttpsURLConnection
import javax.net.ssl.SSLContext
import javax.net.ssl.TrustManager
import javax.net.ssl.X509TrustManager
import java.security.cert.X509Certificate

/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
Expand Down Expand Up @@ -25,6 +31,73 @@ dependencies {
testImplementation project(':data-prepper-test-common')
}

task copyGeoLite2Files(type: Copy) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than use a Copy task, you can use a Download task.

See this example:

tasks.create("${downloadJDKTask}", Download, {
src jdkSources.get(platform + '_' + architecture)
dest "${buildDir}/${platform}${architecture}/openjdk/openjdk.tar.gz"
overwrite false
})

The download plugin will help:

id 'de.undercouch.download' version '4.1.2' apply false

def urls = [
'https://github.com/maxmind/MaxMind-DB/tree/main/test-data/GeoLite2-City-Test.mmdb',
'https://github.com/maxmind/MaxMind-DB/tree/main/test-data/GeoLite2-Country-Test.mmdb',
'https://github.com/maxmind/MaxMind-DB/tree/main/test-data/GeoLite2-ASN-Test.mmdb'
]

def geoLite2Dir = file('/src/test/resources/mmdb-file/geo-lite2')

from(urls.collect { url ->
def testFileName = url.substring(url.lastIndexOf('/') + 1)
def testMmdbSubString = testFileName.substring(testFileName.lastIndexOf('-'))
def fileName = testFileName.substring(0, testFileName.length() - testMmdbSubString.length())
ant.get(src:url, dest: "$geoLite2Dir/$fileName" + ".mmdb")
})

into(geoLite2Dir)

doFirst {
// Trust all certificates
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to trust all? The GitHub certificate is valid.

For example, a simple download works just fine:

wget https://github.com/maxmind/MaxMind-DB/tree/main/test-data/GeoLite2-City-Test.mmdb

def trustAllCertificates = new TrustManager[] {
new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() { null }
public void checkClientTrusted(X509Certificate[] certs, String authType) {}
public void checkServerTrusted(X509Certificate[] certs, String authType) {}
}
}

SSLContext sc = SSLContext.getInstance("SSL")
sc.init(null, trustAllCertificates, new java.security.SecureRandom())
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory())
}
}

task copyGeoIP2File(type: Copy) {

def urls = [
'https://github.com/maxmind/MaxMind-DB/tree/main/test-data/GeoIP2-Enterprise-Test.mmdb'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is still checked in. Let's remove this too.

]

def geoIP2Dir = file('src/test/resources/mmdb-file/geo-enterprise')

from(urls.collect { url ->
def testFileName = url.substring(url.lastIndexOf('/') + 1)
def testMmdbSubString = testFileName.substring(testFileName.lastIndexOf('-'))
def fileName = testFileName.substring(0, testFileName.length() - testMmdbSubString.length())
ant.get(src:url, dest: "$geoIP2Dir/$fileName" + ".mmdb")
})

into(geoIP2Dir)

doFirst {
// Trust all certificates
def trustAllCertificates = new TrustManager[] {
new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() { null }
public void checkClientTrusted(X509Certificate[] certs, String authType) {}
public void checkServerTrusted(X509Certificate[] certs, String authType) {}
}
}

SSLContext sc = SSLContext.getInstance("SSL")
sc.init(null, trustAllCertificates, new java.security.SecureRandom())
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory())
}
}


test {
useJUnitPlatform()
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading