DEV: Introduce maxmind_mirror_url GlobalSetting (#26458)

Why this change?

This allows downloading the MaxMind databases from a mirror in cases
where downloading directly from MaxMind's API endpoint is problematic
due to API limits.
This commit is contained in:
Alan Guo Xiang Tan
2024-04-02 14:53:53 +08:00
committed by GitHub
parent 6c1b320e2e
commit 9182501366
3 changed files with 34 additions and 10 deletions

View File

@ -25,16 +25,18 @@ class DiscourseIpInfo
end
def self.mmdb_download(name)
if GlobalSetting.maxmind_license_key.blank?
STDERR.puts "MaxMind IP database updates require a license"
STDERR.puts "Please set DISCOURSE_MAXMIND_LICENSE_KEY to one you generated at https://www.maxmind.com"
return
end
FileUtils.mkdir_p(path)
url =
"https://download.maxmind.com/app/geoip_download?license_key=#{GlobalSetting.maxmind_license_key}&edition_id=#{name}&suffix=tar.gz"
if GlobalSetting.maxmind_mirror_url.present?
URI.join(GlobalSetting.maxmind_mirror_url, "#{name}.tar.gz").to_s
else
if GlobalSetting.maxmind_license_key.blank?
STDERR.puts "MaxMind IP database updates require a license"
STDERR.puts "Please set DISCOURSE_MAXMIND_LICENSE_KEY to one you generated at https://www.maxmind.com"
return
end
"https://download.maxmind.com/app/geoip_download?license_key=#{GlobalSetting.maxmind_license_key}&edition_id=#{name}&suffix=tar.gz"
end
gz_file =
FileHelper.download(