module ActionPack::Cloudfront::IpRanges

Public Instance Methods

cloudfront_proxies() click to toggle source
# File lib/action_pack/cloudfront/ip_ranges.rb, line 27
def cloudfront_proxies
  ip_ranges.select(&:cloudfront?).map(&:ipaddr)
end
ip_data() click to toggle source
# File lib/action_pack/cloudfront/ip_ranges.rb, line 42
def ip_data
  Timeout.timeout(5) do
    uri = URI('https://ip-ranges.amazonaws.com/ip-ranges.json')
    res = Net::HTTP.get(uri)
    JSON.parse(res)
  end
rescue
  backup_json = File.join File.dirname(__FILE__), 'ip-ranges.json'
  JSON.parse File.read(backup_json)
end
ip_ranges() click to toggle source
# File lib/action_pack/cloudfront/ip_ranges.rb, line 31
def ip_ranges
  @ip_ranges ||= begin
    data = ip_data
    prefixes = data['prefixes']
    prefixesv6 = data['ipv6_prefixes']
    (prefixes + prefixesv6).map do |attrs|
      Range.new(attrs)
    end
  end
end
trusted_proxies() click to toggle source
# File lib/action_pack/cloudfront/ip_ranges.rb, line 23
def trusted_proxies
  cloudfront_proxies + ActionDispatch::RemoteIp::TRUSTED_PROXIES
end