rack-attack-rate-limit 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ae6161b3d1a8760682d587b41b570240aea058f4
4
+ data.tar.gz: 96c6e87f6143f46feb7c38c136a16c00fc6e7188
5
+ SHA512:
6
+ metadata.gz: 4b487f260716def9aa4bba218fcbda154a214132eaaa0055cc13e6e90702f9008d2bc146fd0c00d86f4f77ac1c186c9a0f6d6898a276d2f9ad723c2f78f520b8
7
+ data.tar.gz: 6a34a589b16e7ea377ed4e1ec751ffee171a0897d11e6087b3f1ac339aef2bcbcb9ca1f966eadd0bb21682f273640bda3f2fd8e91441cd141a8a3689e1eceaa1
@@ -0,0 +1,6 @@
1
+ Encoding:
2
+ Enabled: false
3
+ Documentation:
4
+ Enabled: false
5
+ LineLength:
6
+ Max: 120
@@ -0,0 +1,12 @@
1
+ # rack-attack-rate-limit changelog
2
+
3
+ ## 1.0.0
4
+
5
+ * Support for Rails 4
6
+ * Rack::Attack should be *class* not a *module*.
7
+ * Define Rack::Attack class if not already defined.
8
+ * Style changes.
9
+
10
+ ## 0.1.0
11
+
12
+ * Initial release.
@@ -1,11 +1,17 @@
1
+ unless defined?(Rack::Attack)
2
+ module Rack
3
+ class Attack
4
+ end
5
+ end
6
+ end
7
+
1
8
  module Rack
2
- module Attack
9
+ class Attack
3
10
  class RateLimit
4
-
5
11
  RACK_ATTACK_KEY = 'rack.attack.throttle_data'
6
12
 
7
13
  attr_reader :app, :options
8
-
14
+
9
15
  def initialize(app, options = {})
10
16
  @app = app
11
17
  @options = default_options.merge(options)
@@ -13,31 +19,31 @@ module Rack
13
19
 
14
20
  def call(env)
15
21
  # If env does not have necessary data to extract rate limit data for the provider, then app.call
16
- return app.call(env) unless rate_limit_available?(env)
22
+ return app.call(env) unless rate_limit_available?(env)
17
23
  # Otherwise, add rate limit headers
18
24
  status, headers, body = app.call(env)
19
25
  add_rate_limit_headers!(headers, env)
20
- [status, headers, body]
26
+ [status, headers, body]
21
27
  end
22
-
28
+
23
29
  # Returns env key used by Rack::Attack to namespace data
24
30
  #
25
31
  # Returns string
26
32
  def rack_attack_key
27
33
  RACK_ATTACK_KEY
28
34
  end
29
-
35
+
30
36
  # Default options to configure Rack::RateLimit
31
37
  #
32
38
  # Returns hash
33
39
  def default_options
34
40
  { throttle: 'throttle' }
35
41
  end
36
-
42
+
37
43
  def throttle
38
44
  options[:throttle] || ''
39
45
  end
40
-
46
+
41
47
  # Return hash of headers with Rate Limiting data
42
48
  #
43
49
  # headers - Hash of headers
@@ -48,9 +54,9 @@ module Rack
48
54
  headers['X-RateLimit-Remaining'] = rate_limit_remaining(env).to_s
49
55
  headers
50
56
  end
51
-
57
+
52
58
  protected
53
-
59
+
54
60
  # RateLimit upper limit from Rack::Attack
55
61
  #
56
62
  # env - Hash
@@ -59,7 +65,7 @@ module Rack
59
65
  def rate_limit_limit(env)
60
66
  env[rack_attack_key][throttle][:limit]
61
67
  end
62
-
68
+
63
69
  # RateLimit remaining request from Rack::Attack
64
70
  #
65
71
  # env - Hash
@@ -68,17 +74,16 @@ module Rack
68
74
  def rate_limit_remaining(env)
69
75
  rate_limit_limit(env) - env[rack_attack_key][throttle][:count]
70
76
  end
71
-
77
+
72
78
  # Rate Limit available method for Rack::Attack provider
73
79
  # Checks the key identifed by options[:namespace] under the rack.attak.throttle_data env hash key
74
80
  #
75
81
  # env - Hash
76
82
  #
77
- # Returns boolean
83
+ # Returns boolean
78
84
  def rate_limit_available?(env)
79
- env.key?(rack_attack_key) and env[rack_attack_key].key?(throttle)
85
+ env.key?(rack_attack_key) && env[rack_attack_key].key?(throttle)
80
86
  end
81
-
82
87
  end
83
88
  end
84
89
  end
@@ -1,7 +1,7 @@
1
1
  module Rack
2
- module Attack
2
+ class Attack
3
3
  class RateLimit
4
- VERSION = "0.1.0"
4
+ VERSION = '1.0.0'
5
5
  end
6
6
  end
7
7
  end
@@ -18,12 +18,13 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
20
  spec.require_paths = ["lib"]
21
-
21
+
22
22
  spec.add_dependency 'rack'
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.3"
25
- spec.add_development_dependency "rake"
26
- spec.add_development_dependency "rspec"
27
- spec.add_development_dependency "rack-test"
28
-
25
+ spec.add_development_dependency 'rake'
26
+ spec.add_development_dependency 'rspec'
27
+ spec.add_development_dependency 'rack-test'
28
+ spec.add_development_dependency 'rubocop'
29
+
29
30
  end
@@ -5,10 +5,8 @@ require 'rack/test'
5
5
  require 'rack/attack/rate-limit'
6
6
 
7
7
  RSpec::configure do |config|
8
-
8
+
9
9
  config.treat_symbols_as_metadata_keys_with_true_values = true
10
- config.formatter = :documentation
10
+ config.formatter = :documentation
11
11
  config.tty = true
12
- config.color_enabled = true
13
-
14
- end
12
+ end
metadata CHANGED
@@ -1,105 +1,110 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-attack-rate-limit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
5
- prerelease:
4
+ version: 1.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jason Byck
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-10-29 00:00:00.000000000 Z
11
+ date: 2014-06-23 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rack
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: bundler
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
33
  version: '1.3'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
40
  version: '1.3'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rake
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rspec
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - ">="
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - ">="
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rack-test
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - ">="
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - ">="
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
- description: ! ' Add RateLimit headers for Rack::Attack throttling '
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: " Add RateLimit headers for Rack::Attack throttling "
95
98
  email:
96
99
  - jasonbyck@gmail.com
97
100
  executables: []
98
101
  extensions: []
99
102
  extra_rdoc_files: []
100
103
  files:
101
- - .gitignore
102
- - .travis.yml
104
+ - ".gitignore"
105
+ - ".rubocop.yml"
106
+ - ".travis.yml"
107
+ - CHANGELOG.md
103
108
  - Gemfile
104
109
  - LICENSE.txt
105
110
  - README.md
@@ -112,27 +117,26 @@ files:
112
117
  homepage: https://github.com/jbyck/rack-attack-rate-limit
113
118
  licenses:
114
119
  - MIT
120
+ metadata: {}
115
121
  post_install_message:
116
122
  rdoc_options: []
117
123
  require_paths:
118
124
  - lib
119
125
  required_ruby_version: !ruby/object:Gem::Requirement
120
- none: false
121
126
  requirements:
122
- - - ! '>='
127
+ - - ">="
123
128
  - !ruby/object:Gem::Version
124
129
  version: '0'
125
130
  required_rubygems_version: !ruby/object:Gem::Requirement
126
- none: false
127
131
  requirements:
128
- - - ! '>='
132
+ - - ">="
129
133
  - !ruby/object:Gem::Version
130
134
  version: '0'
131
135
  requirements: []
132
136
  rubyforge_project:
133
- rubygems_version: 1.8.23
137
+ rubygems_version: 2.2.2
134
138
  signing_key:
135
- specification_version: 3
139
+ specification_version: 4
136
140
  summary: Add RateLimit headers for Rack::Attack throttling
137
141
  test_files:
138
142
  - spec/rack/attack/rate-limit_spec.rb