lib/geoip, cmd/relaypoolsrv, cmd/ursrv: Automatically manage GeoIP updates (#9342)

This adds a small package `geoip` which knows how to download and manage
the Maxmind GeoLite2 database we use. This removes the need for various
scripts to download and manage the geoip database, something that today
happens on Docker startup for the relay pool server and using various
hand written hacks for the usage reporting server.

The database is downloaded when needed and then refreshed on a
best-effort basis weekly.
This commit is contained in:
Jakob Borg
2024-05-18 20:31:49 +03:00
committed by GitHub
parent 57d399317e
commit ba6ac2f604
8 changed files with 212 additions and 62 deletions
+36
View File
@@ -0,0 +1,36 @@
// Copyright (C) 2024 The Syncthing Authors.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.
package geoip
import (
"context"
"net"
"os"
"strconv"
"testing"
)
func TestDownloadAndOpen(t *testing.T) {
acctID, _ := strconv.Atoi(os.Getenv("GEOIP_ACCOUNT_ID"))
if acctID == 0 {
t.Skip("No account ID set")
}
license := os.Getenv("GEOIP_LICENSE_KEY")
if license == "" {
t.Skip("No license key set")
}
p, err := NewGeoLite2CityProvider(context.Background(), acctID, license, t.TempDir())
if err != nil {
t.Fatal(err)
}
_, err = p.City(net.ParseIP("8.8.8.8"))
if err != nil {
t.Fatal(err)
}
}