Websites/app/logical/cloudflare_service.rb
Donovan Daniels b1c702e3cd
Add image management ui
poorly tested but it worked well enough, I'm sure I'll be patching bugs over the next few weeks
Also remove turbo because it sucks
Also changed the way we handle hosts in dev
2024-05-06 03:25:17 -05:00

16 lines
477 B
Ruby

# frozen_string_literal: true
module CloudflareService
def self.ips
text, code = Cache.fetch("cloudflare_ips", expires_in: 24.hours) do
resp = HTTParty.get("https://api.cloudflare.com/client/v4/ips", Websites.config.httparty_options)
[resp.body, resp.code]
end
return [] if code != 200
json = JSON.parse(text, symbolize_names: true)
ips = json[:result][:ipv4_cidrs] + json[:result][:ipv6_cidrs]
ips.map { |ip| IPAddr.new(ip) }
end
end