Module: ActionPack::Cloudfront::IpRanges

Extended by:
IpRanges
Included in:
IpRanges
Defined in:
lib/action_pack/cloudfront/ip_ranges.rb

Defined Under Namespace

Classes: Range

Instance Method Summary collapse

Instance Method Details

#cloudfront_proxiesObject



27
28
29
# File 'lib/action_pack/cloudfront/ip_ranges.rb', line 27

def cloudfront_proxies
  ip_ranges.select(&:cloudfront?).map(&:ipaddr)
end

#ip_dataObject



42
43
44
45
46
47
48
49
50
51
# 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_rangesObject



31
32
33
34
35
36
37
38
39
40
# 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_proxiesObject



23
24
25
# File 'lib/action_pack/cloudfront/ip_ranges.rb', line 23

def trusted_proxies
  cloudfront_proxies + ActionDispatch::RemoteIp::TRUSTED_PROXIES
end