Add GeoIP Local mirror support
This commit is contained in:
parent
944d36fdba
commit
b55f4371e3
4 changed files with 29 additions and 2 deletions
|
@ -98,6 +98,9 @@ spec:
|
||||||
- --validating-webhook-certificate={{ .Values.controller.admissionWebhooks.certificate }}
|
- --validating-webhook-certificate={{ .Values.controller.admissionWebhooks.certificate }}
|
||||||
- --validating-webhook-key={{ .Values.controller.admissionWebhooks.key }}
|
- --validating-webhook-key={{ .Values.controller.admissionWebhooks.key }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- if .Values.controller.maxmindMirror }}
|
||||||
|
- --maxmind-mirror={{ .Values.controller.maxmindMirror }}
|
||||||
|
{{- end}}
|
||||||
{{- if .Values.controller.maxmindLicenseKey }}
|
{{- if .Values.controller.maxmindLicenseKey }}
|
||||||
- --maxmind-license-key={{ .Values.controller.maxmindLicenseKey }}
|
- --maxmind-license-key={{ .Values.controller.maxmindLicenseKey }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
|
@ -173,6 +173,7 @@ Takes the form "<host>:port". If not provided, no admission controller is starte
|
||||||
statusUpdateInterval = flags.Int("status-update-interval", status.UpdateInterval, "Time interval in seconds in which the status should check if an update is required. Default is 60 seconds")
|
statusUpdateInterval = flags.Int("status-update-interval", status.UpdateInterval, "Time interval in seconds in which the status should check if an update is required. Default is 60 seconds")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
flags.StringVar(&nginx.MaxmindMirror, "maxmind-mirror", "", `Maxmind mirror url (example: http://geoip.local/databases`)
|
||||||
flags.StringVar(&nginx.MaxmindLicenseKey, "maxmind-license-key", "", `Maxmind license key to download GeoLite2 Databases.
|
flags.StringVar(&nginx.MaxmindLicenseKey, "maxmind-license-key", "", `Maxmind license key to download GeoLite2 Databases.
|
||||||
https://blog.maxmind.com/2019/12/18/significant-changes-to-accessing-and-using-geolite2-databases`)
|
https://blog.maxmind.com/2019/12/18/significant-changes-to-accessing-and-using-geolite2-databases`)
|
||||||
flags.StringVar(&nginx.MaxmindEditionIDs, "maxmind-edition-ids", "GeoLite2-City,GeoLite2-ASN", `Maxmind edition ids to download GeoLite2 Databases.`)
|
flags.StringVar(&nginx.MaxmindEditionIDs, "maxmind-edition-ids", "GeoLite2-City,GeoLite2-ASN", `Maxmind edition ids to download GeoLite2 Databases.`)
|
||||||
|
@ -299,7 +300,7 @@ https://blog.maxmind.com/2019/12/18/significant-changes-to-accessing-and-using-g
|
||||||
config.RootCAFile = *rootCAFile
|
config.RootCAFile = *rootCAFile
|
||||||
}
|
}
|
||||||
|
|
||||||
if nginx.MaxmindLicenseKey != "" && nginx.MaxmindEditionIDs != "" {
|
if (nginx.MaxmindLicenseKey != "" || nginx.MaxmindMirror != "") && nginx.MaxmindEditionIDs != "" {
|
||||||
if err := nginx.ValidateGeoLite2DBEditions(); err != nil {
|
if err := nginx.ValidateGeoLite2DBEditions(); err != nil {
|
||||||
return false, nil, err
|
return false, nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,3 +92,16 @@ func TestMaxmindEdition(t *testing.T) {
|
||||||
t.Fatalf("Expected an error parsing flags but none returned")
|
t.Fatalf("Expected an error parsing flags but none returned")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMaxmindMirror(t *testing.T) {
|
||||||
|
resetForTesting(func() { t.Fatal("Parsing failed") })
|
||||||
|
|
||||||
|
oldArgs := os.Args
|
||||||
|
defer func() { os.Args = oldArgs }()
|
||||||
|
os.Args = []string{"cmd", "--publish-service", "namespace/test", "--http-port", "0", "--https-port", "0", "--maxmind-mirror", "http://geoip.local", "--maxmind-license-key", "0000000", "--maxmind-edition-ids", "GeoLite2-City, TestCheck"}
|
||||||
|
|
||||||
|
_, _, err := parseFlags()
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("Expected an error parsing flags but none returned")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -36,6 +36,9 @@ var MaxmindEditionIDs = ""
|
||||||
// MaxmindEditionFiles maxmind databases on disk
|
// MaxmindEditionFiles maxmind databases on disk
|
||||||
var MaxmindEditionFiles []string
|
var MaxmindEditionFiles []string
|
||||||
|
|
||||||
|
// MaxmindMirror maxmind database mirror url (http://geoip.local)
|
||||||
|
var MaxmindMirror = ""
|
||||||
|
|
||||||
const (
|
const (
|
||||||
geoIPPath = "/etc/nginx/geoip"
|
geoIPPath = "/etc/nginx/geoip"
|
||||||
dbExtension = ".mmdb"
|
dbExtension = ".mmdb"
|
||||||
|
@ -68,8 +71,15 @@ func DownloadGeoLite2DB() error {
|
||||||
return nil
|
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 {
|
func downloadDatabase(dbName string) error {
|
||||||
url := fmt.Sprintf(maxmindURL, MaxmindLicenseKey, dbName)
|
url := createURL(MaxmindMirror, MaxmindLicenseKey, dbName)
|
||||||
req, err := http.NewRequest(http.MethodGet, url, nil)
|
req, err := http.NewRequest(http.MethodGet, url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in a new issue