cloudflare-rails 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aa44d2f1afb581fda6300182a71286d900e69097
4
- data.tar.gz: 3427435d477646191a2b05e289e52e7dc8a9f036
3
+ metadata.gz: 947aaffd0442fcd48550cbc359a2f5d80685d0a4
4
+ data.tar.gz: d29744071bb75ba4e9232466248acaa13b7cc272
5
5
  SHA512:
6
- metadata.gz: f05254ee54a69a711e7e612f7e1ee029b25186efb04f693a199dc00bc1c991799e704419674827d15fd1cf49e047e0247595f839b290121332924c5f4ff79645
7
- data.tar.gz: c2e048580350035589e53e0ababdf4bed4f5d693d383564adac879d2b08a10f8f66bdc3816d2acec5cd425a03fac273ac012b695b10130a9d7df6ac96cf6268f
6
+ metadata.gz: 038cacccbde117a5e9e684a351102921e2947a1b7f2248e05ba033516ce4c163d28fdcb537e1735189caf5af88256a63b142ff6ae540f6ac324454f53026a7c7
7
+ data.tar.gz: 146fc51215c8c709b4fed30a78fa9b8ba41c65e69ea3ffc4b16fc4c1f227186e9396b494af8c1559506997f04a80061da6038cf4d1238cb196fef3aba3c3d12e
data/README.md CHANGED
@@ -2,12 +2,17 @@
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`:
8
13
 
9
14
  ```ruby
10
- group :production
15
+ group :production do
11
16
  # or :staging or :beta or whatever environments you are using cloudflare in.
12
17
  # you probably don't want this for :test or :development
13
18
  gem 'cloudflare-rails'
@@ -36,4 +41,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
36
41
 
37
42
  ## Contributing
38
43
 
39
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cloudflare-rails.
44
+ Bug reports and pull requests are welcome on GitHub at https://github.com/modosc/cloudflare-rails.
@@ -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.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudflare-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - jonathan schatz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-28 00:00:00.000000000 Z
11
+ date: 2016-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -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