cloudflare-rails 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 708b25e86234376fc261a955e9f0c3aabc5c04ba
4
- data.tar.gz: 62abfd55daae6feb63eb3a6b3a5859311a8e7e3d
3
+ metadata.gz: 947aaffd0442fcd48550cbc359a2f5d80685d0a4
4
+ data.tar.gz: d29744071bb75ba4e9232466248acaa13b7cc272
5
5
  SHA512:
6
- metadata.gz: f1ba5dae5d80a21e6a1cda5020d44454d17bb9de917c6e86d493b08622f4ca349a11e10235d1fa07aa9409bdc7bbc4a37199f9224ea0b0b1265f8ee4b7157054
7
- data.tar.gz: 72d2b28ff23675d030aa1868cde98a4f442ada49c32106d64fd305114738ec61ed59af153f8bc12fb31bccdbb9e5c3a74d19a91d339d74fa5060e7499231ba98
6
+ metadata.gz: 038cacccbde117a5e9e684a351102921e2947a1b7f2248e05ba033516ce4c163d28fdcb537e1735189caf5af88256a63b142ff6ae540f6ac324454f53026a7c7
7
+ data.tar.gz: 146fc51215c8c709b4fed30a78fa9b8ba41c65e69ea3ffc4b16fc4c1f227186e9396b494af8c1559506997f04a80061da6038cf4d1238cb196fef3aba3c3d12e
data/README.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  This gem correctly configures Rails for [CloudFlare](https://www.cloudflare.com) so that `request.remote_ip` / `request.ip` both work correctly.
4
4
 
5
+ ## Rails Compatibility
6
+
7
+ For Rails 5, use 0.2.x
8
+ For Rails 4.2, use 0.1.x
9
+
5
10
  ## Installation
6
11
 
7
12
  Add this line to your application's `Gemfile`:
@@ -23,11 +23,9 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
24
  spec.add_development_dependency "rspec"
25
25
  spec.add_development_dependency "rspec-rails"
26
-
27
26
  spec.add_development_dependency "webmock"
28
27
 
29
- # TODO - no idea if this is 4.x specific, should test with older versions
30
- spec.add_dependency "rails", "~> 4.0"
28
+ spec.add_dependency "rails", "~> 5.0"
31
29
  spec.add_dependency 'httparty'
32
30
 
33
31
  # we need Module#prepend
@@ -4,7 +4,7 @@ module Cloudflare
4
4
  module Rails
5
5
  class Railtie < ::Rails::Railtie
6
6
 
7
- # patch rack::request to use our cloudflare ips - this way request.ip is
7
+ # patch rack::request::helpers to use our cloudflare ips - this way request.ip is
8
8
  # correct inside of rack and rails
9
9
  module CheckTrustedProxies
10
10
  def trusted_proxy?(ip)
@@ -12,11 +12,12 @@ module Cloudflare
12
12
  end
13
13
  end
14
14
 
15
- Rack::Request.prepend CheckTrustedProxies
15
+ Rack::Request::Helpers.prepend CheckTrustedProxies
16
16
 
17
17
  # patch ActionDispatch::RemoteIP to use our cloudflare ips - this way
18
18
  # request.remote_ip is correct inside of rails
19
19
  module RemoteIpProxies
20
+
20
21
  def proxies
21
22
  super + ::Rails.application.config.cloudflare.ips
22
23
  end
@@ -63,7 +64,7 @@ module Cloudflare
63
64
  end
64
65
  end
65
66
 
66
- # setup defaults before we configure our app.
67
+ # setup defaults before we configure our app.
67
68
  DEFAULTS = {
68
69
  expires_in: 12.hours,
69
70
  timeout: 5.seconds,
@@ -93,82 +94,3 @@ module Cloudflare
93
94
  end
94
95
  end
95
96
  end
96
- # bail if ActionDispatch::RemoteIp isn't already loaded
97
- # if app.config.middleware.middlewares.exclude? ActionDispatch::RemoteIp
98
- # ::Rails.logger.error "Couldn't find ActionDispatch::RemoteIp middleware, skipping CloudFlare::Rails initialization"
99
- # return false
100
- # end
101
-
102
-
103
- # change our default timeout if specified
104
- # default_timeout app.config.cloudflare.timeout if app.config.cloudflare.timeout.present?
105
-
106
- #cf_config = app.config.cloudflare.reverse_merge Importer::DEFAULT_CONFIG
107
-
108
- # Importer.default_timeout Config.config
109
-
110
-
111
- # caching is here so that we have app.config.cloudflare in scope - i
112
- # suppose we could move this into fetch and take expires_in as a
113
- # param?
114
-
115
- # cloudflare_ips += ::Rails.cache.fetch("cloudflare-rails:ip_v4", expires_in: cf_config[:expires_in]) do
116
- # ip_v4
117
- # end.map{|ip| IPAddr.new ip }
118
- #
119
- # cloudflare_ips += ::Rails.cache.fetch("cloudflare-rails:ip_v6", expires_in: cf_config[:expires_in]) do
120
- # ip_v6
121
- # end.map{|ip| IPAddr.new "[#{ip}]" }
122
- #
123
- # [:ips_v4, :ips_v6].each do |type|
124
- # begin
125
- # ips = ::Rails.cache.fetch("cloudflare-rails:#{type}", expires_in: cf_config[:expires_in]) do
126
- # Importer.send type
127
- # end
128
- # app.config.cloudflare.ips += ips if ips.present?
129
- # rescue Importer::ResponseError => e
130
- # ::Rails.logger.error "Cloudflare::Rails: Couldn't import #{type} blocks from CloudFlare: #{e.response}"
131
- # rescue => e
132
- # ::Rails.logger.error "Cloudflare::Rails: Got exception: #{e} for type:#{type}, cloudflare_ips: #{cloudflare_ips}"
133
- # end
134
- # end
135
- #
136
- # if app.config.cloudflare.ips.present?
137
- # # i don't know what uses these beyond ActionDispatch::RemoteIp (which
138
- # # we are patching below) but we should go ahead and keep this in sync
139
- # # anyway
140
- # if app.config.action_dispatch.trusted_proxies.blank?
141
- # # this behavior is copied from:
142
- # #
143
- # # https://github.com/rails/rails/blob/a59a9b7f729870de6c9282bd8e2a7ed7f86fc868/actionpack/lib/action_dispatch/middleware/remote_ip.rb#L76
144
- # #
145
- # # we want to make the addition of cloudflare_ips as transparent as
146
- # # possible but by adding our array in we change the behavior of
147
- # # ActionDispatch::RemoteIp
148
- # app.config.action_dispatch.trusted_proxies = ActionDispatch::RemoteIp::TRUSTED_PROXIES + cloudflare_ips
149
- # elsif app.config.action_dispatch.trusted_proxies.respond_to?(:any)
150
- # app.config.action_dispatch.trusted_proxies += app.config.cloudflare.ips
151
- # else
152
- # app.config.action_dispatch.trusted_proxies = Array(app.config.action_dispatch.trusted_proxies) + ActionDispatch::RemoteIp::TRUSTED_PROXIES + app.config.cloudflare.ips
153
- # end
154
- #
155
- # # now we have to patch ActionDispatch::RemoteIp since by the time we
156
- # # get here it's already been configured and initialized and we can't
157
- # # easily mess around with the middleware stack.
158
- # remote_ip_patch = Module.new
159
- #
160
- # remote_ip_patch.instance_eval do
161
- # define_method :proxies do
162
- # @proxies + app.config.cloudflare.ips
163
- # end
164
- # end
165
- #
166
- # # remote_ip_patch.const_set :CLOUDFLARE_IPS, cloudflare_ips
167
- # # pp "remote_ip_patch.constants is #{remote_ip_patch.constants}"
168
- # ActionDispatch::RemoteIp.prepend remote_ip_patch
169
- # # pp ActionDispatch::RemoteIp::CLOUDFLARE_IPS
170
- # end
171
- # end
172
- # end
173
- # end
174
- # end
@@ -1,5 +1,5 @@
1
1
  module Cloudflare
2
2
  module Rails
3
- VERSION = "0.1.2"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudflare-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - jonathan schatz
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '4.0'
89
+ version: '5.0'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '4.0'
96
+ version: '5.0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: httparty
99
99
  requirement: !ruby/object:Gem::Requirement