Merge pull request #6685 from foxdalas/geoip_local_mirror

Add GeoIP Local mirror support
This commit is contained in:
Kubernetes Prow Robot 2020-12-29 04:48:30 -08:00 committed by GitHub
commit cff52e69c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 2 deletions

View file

@ -36,6 +36,9 @@ var MaxmindEditionIDs = ""
// MaxmindEditionFiles maxmind databases on disk
var MaxmindEditionFiles []string
// MaxmindMirror maxmind database mirror url (http://geoip.local)
var MaxmindMirror = ""
const (
geoIPPath = "/etc/nginx/geoip"
dbExtension = ".mmdb"
@ -68,8 +71,15 @@ func DownloadGeoLite2DB() error {
return nil
}
func createURL(mirror, licenseKey, dbName string) string {
if len(mirror) > 0 {
return fmt.Sprintf("%s/%s.tar.gz", mirror, dbName)
}
return fmt.Sprintf(maxmindURL, licenseKey, dbName)
}
func downloadDatabase(dbName string) error {
url := fmt.Sprintf(maxmindURL, MaxmindLicenseKey, dbName)
url := createURL(MaxmindMirror, MaxmindLicenseKey, dbName)
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return err