actionpack-cloudfront 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +22 -0
- data/Appraisals +16 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +60 -0
- data/Rakefile +10 -0
- data/actionpack-cloudfront.gemspec +23 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/gemfiles/rails42.gemfile +8 -0
- data/gemfiles/rails42.gemfile.lock +134 -0
- data/gemfiles/rails50.gemfile +7 -0
- data/gemfiles/rails50.gemfile.lock +136 -0
- data/gemfiles/rails51.gemfile +9 -0
- data/gemfiles/rails51.gemfile.lock +151 -0
- data/lib/action_pack/cloudfront.rb +14 -0
- data/lib/action_pack/cloudfront/ip-ranges.json +6508 -0
- data/lib/action_pack/cloudfront/ip_ranges.rb +59 -0
- data/lib/action_pack/cloudfront/railtie.rb +19 -0
- data/lib/action_pack/cloudfront/version.rb +5 -0
- data/lib/actionpack-cloudfront.rb +1 -0
- metadata +137 -0
@@ -0,0 +1,59 @@
|
|
1
|
+
module ActionPack
|
2
|
+
module Cloudfront
|
3
|
+
module IpRanges
|
4
|
+
|
5
|
+
class Range
|
6
|
+
attr_reader :ip_prefix, :region, :service
|
7
|
+
|
8
|
+
def initialize(attrs)
|
9
|
+
@service = attrs['service']
|
10
|
+
@ip_prefix = attrs['ip_prefix'] || attrs['ipv6_prefix']
|
11
|
+
@region = attrs['region']
|
12
|
+
end
|
13
|
+
|
14
|
+
def cloudfront?
|
15
|
+
service =~ /cloudfront/i
|
16
|
+
end
|
17
|
+
|
18
|
+
def ipaddr
|
19
|
+
IPAddr.new(ip_prefix)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def trusted_proxies
|
24
|
+
cloudfront_proxies + ActionDispatch::RemoteIp::TRUSTED_PROXIES
|
25
|
+
end
|
26
|
+
|
27
|
+
def cloudfront_proxies
|
28
|
+
ip_ranges.select(&:cloudfront?).map(&:ipaddr)
|
29
|
+
end
|
30
|
+
|
31
|
+
def ip_ranges
|
32
|
+
@ip_ranges ||= begin
|
33
|
+
data = ip_data
|
34
|
+
prefixes = data['prefixes']
|
35
|
+
prefixesv6 = data['ipv6_prefixes']
|
36
|
+
(prefixes + prefixesv6).map do |attrs|
|
37
|
+
Range.new(attrs)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def ip_data
|
43
|
+
Timeout.timeout(5) do
|
44
|
+
uri = URI('https://ip-ranges.amazonaws.com/ip-ranges.json')
|
45
|
+
res = Net::HTTP.get(uri)
|
46
|
+
JSON.parse(res)
|
47
|
+
end
|
48
|
+
rescue
|
49
|
+
backup_json = File.join File.dirname(__FILE__), 'ip-ranges.json'
|
50
|
+
JSON.parse File.read(backup_json)
|
51
|
+
end
|
52
|
+
|
53
|
+
extend self
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rails/railtie'
|
2
|
+
|
3
|
+
module ActionPack
|
4
|
+
module Cloudfront
|
5
|
+
class Railtie < ::Rails::Railtie
|
6
|
+
|
7
|
+
config.action_pack_cloudfront = ActiveSupport::OrderedOptions.new
|
8
|
+
config.action_pack_cloudfront.load_proxies = !::Rails.env.test? && !::Rails.env.development?
|
9
|
+
|
10
|
+
config.before_initialize do |app|
|
11
|
+
if app.config.load_proxies
|
12
|
+
trusted_proxies = ActionPack::Cloudfront::IpRanges.trusted_proxies
|
13
|
+
app.config.action_dispatch.trusted_proxies = trusted_proxies
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'action_pack/cloudfront'
|
metadata
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: actionpack-cloudfront
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ken Collins
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-11-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: appraisal
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Simple gem that adds Amazon CloudFront IP prefixes to the trusted proxies
|
84
|
+
to Rails RemoteIp middleware.
|
85
|
+
email:
|
86
|
+
- kcollins@customink.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".travis.yml"
|
93
|
+
- Appraisals
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- actionpack-cloudfront.gemspec
|
99
|
+
- bin/console
|
100
|
+
- bin/setup
|
101
|
+
- gemfiles/rails42.gemfile
|
102
|
+
- gemfiles/rails42.gemfile.lock
|
103
|
+
- gemfiles/rails50.gemfile
|
104
|
+
- gemfiles/rails50.gemfile.lock
|
105
|
+
- gemfiles/rails51.gemfile
|
106
|
+
- gemfiles/rails51.gemfile.lock
|
107
|
+
- lib/action_pack/cloudfront.rb
|
108
|
+
- lib/action_pack/cloudfront/ip-ranges.json
|
109
|
+
- lib/action_pack/cloudfront/ip_ranges.rb
|
110
|
+
- lib/action_pack/cloudfront/railtie.rb
|
111
|
+
- lib/action_pack/cloudfront/version.rb
|
112
|
+
- lib/actionpack-cloudfront.rb
|
113
|
+
homepage: https://github.com/customink/actionpack-cloudfront
|
114
|
+
licenses:
|
115
|
+
- MIT
|
116
|
+
metadata: {}
|
117
|
+
post_install_message:
|
118
|
+
rdoc_options: []
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
requirements: []
|
132
|
+
rubyforge_project:
|
133
|
+
rubygems_version: 2.6.8
|
134
|
+
signing_key:
|
135
|
+
specification_version: 4
|
136
|
+
summary: Configure ActionDispatch::RemoteIp trusted proxies for Amazon CloudFront.
|
137
|
+
test_files: []
|