ip_restriction 0.0.1 → 0.0.2

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: 68e94b900f295426882409cf6dfb3a304612f901
4
- data.tar.gz: a132349a45a4e0bacd6401b9aac945a4dc7c7b68
3
+ metadata.gz: 610c67804a38c1dca7d3d83a9e9a70296ae03c3c
4
+ data.tar.gz: e306e1710319105b71f70c1dd5faf8f42f2144a1
5
5
  SHA512:
6
- metadata.gz: 2f334e979fa2aa66dab507cc7fd7bab013ea1671917e65db6b836b0d9872b44bb380a57d699591fd854124130caa9af0a4708def3470b887f749d1327c22ac03
7
- data.tar.gz: cd12370e41a165550f59a28c287ce7b6bd36f14e60ae8b5cbbaf00af5b2095ae9de35dd5e126be18ceef83fb4460c47a20834e61f429e41c6a32ada09860165c
6
+ metadata.gz: 9015fa7a7db6bc9d723fb9d64ce408821869507fb785b1bf788629cd11493bc984a949d90be30fb904ab41824cce0c4404291cdbe6a406762f340a0b533667d8
7
+ data.tar.gz: 2f838fc3c5f0de2b2aa8613ac971cc1a69d2ea06b2a57bb03acd5c310109c857d5e2169b1bad9f4e4e4a40dcf37d961ebaa27c4b999fbdd08af748f464fbfbc8
@@ -2,7 +2,7 @@ require 'yaml'
2
2
 
3
3
  module IpRestriction
4
4
  class IpLoader
5
- DEFAULT_IPS = ['127.0.0.1']
5
+ DEFAULT_IPS = ['127.0.0.1', '::1']
6
6
 
7
7
  attr_reader :file_path
8
8
 
@@ -0,0 +1,27 @@
1
+ require 'singleton'
2
+
3
+ module IpRestriction
4
+ class Middleware
5
+ def initialize(app)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ constraint = Constraint.instance
11
+
12
+ if constraint.checker.allowed?(env["REMOTE_ADDR"])
13
+ @app.call(env)
14
+ else
15
+ [404, {'Content-Type' => 'text/html'}, ['Not found!']]
16
+ end
17
+ end
18
+
19
+ class Constraint
20
+ include Singleton
21
+
22
+ def checker
23
+ @checker ||= IpRestriction::IpChecker.new(IpRestriction::IpsRetriever.new.office_ips)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,3 +1,3 @@
1
1
  module IpRestriction
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ip_restriction
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Locaweb
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-10 00:00:00.000000000 Z
11
+ date: 2015-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry-nav
@@ -123,7 +123,7 @@ files:
123
123
  - lib/ip_restriction/ip_checker.rb
124
124
  - lib/ip_restriction/ip_loader.rb
125
125
  - lib/ip_restriction/ips_retriever.rb
126
- - lib/ip_restriction/locaweb_allowed_ips_constraint.rb
126
+ - lib/ip_restriction/middleware.rb
127
127
  - lib/ip_restriction/version.rb
128
128
  homepage: ''
129
129
  licenses:
@@ -145,9 +145,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
145
  version: '0'
146
146
  requirements: []
147
147
  rubyforge_project:
148
- rubygems_version: 2.4.5
148
+ rubygems_version: 2.4.7
149
149
  signing_key:
150
150
  specification_version: 4
151
151
  summary: Restrict some IPs
152
152
  test_files: []
153
- has_rdoc:
@@ -1,13 +0,0 @@
1
- module IpRestriction
2
- class AllowedIpsConstraint
3
- def matches?(request)
4
- checker.allowed?(request.remote_ip)
5
- end
6
-
7
- private
8
-
9
- def checker
10
- @checker ||= IpChecker.new(IpsRetriever.new.office_ips)
11
- end
12
- end
13
- end