2024-02-25 12:15:55 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-11-25 11:27:38 -05:00
|
|
|
module CloudflareService
|
2024-04-26 09:57:56 -04:00
|
|
|
def self.endpoint
|
|
|
|
"https://api.cloudflare.com/client/v4/ips"
|
|
|
|
end
|
|
|
|
|
2023-05-19 16:53:20 -04:00
|
|
|
def self.ips
|
2024-04-27 17:01:10 -04:00
|
|
|
text, status = Cache.fetch("cloudflare_ips", expires_in: 24.hours) do
|
|
|
|
resp = Faraday.new(Danbooru.config.faraday_options).get(endpoint)
|
|
|
|
[resp.body, resp.status]
|
2022-11-25 11:27:38 -05:00
|
|
|
end
|
2024-04-27 17:01:10 -04:00
|
|
|
return [] if status != 200
|
2018-11-11 21:18:21 -05:00
|
|
|
|
|
|
|
json = JSON.parse(text, symbolize_names: true)
|
|
|
|
ips = json[:result][:ipv4_cidrs] + json[:result][:ipv6_cidrs]
|
|
|
|
ips.map { |ip| IPAddr.new(ip) }
|
|
|
|
end
|
2017-11-22 16:19:30 -05:00
|
|
|
end
|