rack_api_key_limit 0.0.1
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 +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +76 -0
- data/Rakefile +1 -0
- data/lib/rack_api_key_limit.rb +9 -0
- data/lib/rack_api_key_limit/base.rb +90 -0
- data/lib/rack_api_key_limit/cache/redis.rb +22 -0
- data/lib/rack_api_key_limit/hourly.rb +23 -0
- data/lib/rack_api_key_limit/version.rb +5 -0
- data/rack_api_key_limit.gemspec +29 -0
- data/spec/lib/rack_api_key_limit/base_spec.rb +73 -0
- data/spec/lib/rack_api_key_limit/hourly_spec.rb +27 -0
- data/spec/spec_helper.rb +27 -0
- data/spec/support/cache_stub.rb +13 -0
- data/spec/support/lib/cache_stub.rb +13 -0
- data/spec/support/lib/limiter_stub.rb +19 -0
- data/spec/support/limiter_stub.rb +19 -0
- metadata +154 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 49300e2587c6f79851b558faa073eef6e8ec9296
|
4
|
+
data.tar.gz: b744e907b0cf41ad5476f8d3ca6c7339fe795b3c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d5b2b5a4290272d9fc05b3022a5bfd8af062bb6e901767dd705da5dc5db16f2bf626b10a40f6974b4a24c6796af6a80995f4f322f2a71482e246dee9be7400d1
|
7
|
+
data.tar.gz: c5d1c6e29f2fec7b92cd22e66f18d6016795bf4016fef7e7e316be9845ca30a99d91ba24ee8e548324530005f0526a2fd3dcc5eb969f34f127944b127e0caa90
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Rich Hollis
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# RackApiKeyLimit
|
2
|
+
|
3
|
+
Rack middleware for limiting requests based on an parameter - e.g. api_key
|
4
|
+
|
5
|
+
```
|
6
|
+
http://api.somewhere.com/api/v1/users?api_key=dflgjkd9o8345kdjbkcjvbij
|
7
|
+
```
|
8
|
+
|
9
|
+
The middleware uses a default strategy of hourly limiting for api keys but has been designed so that you can implement your own strategies. The default limit is 150 requests an hour.
|
10
|
+
|
11
|
+
## X-RateLimit headers
|
12
|
+
|
13
|
+
X-RateLimit headers are returned with each request where the api_key parameter is present:
|
14
|
+
|
15
|
+
<table>
|
16
|
+
<tr>
|
17
|
+
<td>X-RateLimit-Limit</td><td>The maximum number of requests per time period (e.g. hour)</td>
|
18
|
+
</tr>
|
19
|
+
<tr>
|
20
|
+
<td>X-RateLimit-Remaining</td><td>The number of requests remaining</td>
|
21
|
+
</tr>
|
22
|
+
<tr>
|
23
|
+
<td>X-RateLimit-Reset</td><td>The number of seconds until the current time period ends</td>
|
24
|
+
</tr>
|
25
|
+
</table>
|
26
|
+
|
27
|
+
I found this artcle on Stack Overflow very useful:
|
28
|
+
|
29
|
+
http://stackoverflow.com/questions/16022624/examples-of-http-api-rate-limiting-http-response-headers
|
30
|
+
|
31
|
+
It would be pretty easy to add a ```Retry-After``` header if you wanted to.
|
32
|
+
|
33
|
+
## Cache Stores
|
34
|
+
|
35
|
+
Redis is used for the cache store but again you could easily implement your own.
|
36
|
+
|
37
|
+
## Inspiration
|
38
|
+
|
39
|
+
This rack middleware was heavily inspired and uses parts of the no longer maintained [rack-throttle](https://github.com/datagraph/rack-throttle) middleware - in particular the design and specs saved me a lot of time.
|
40
|
+
|
41
|
+
## Installation
|
42
|
+
|
43
|
+
Add this line to your application's Gemfile:
|
44
|
+
|
45
|
+
gem 'rack_api_key_limit'
|
46
|
+
|
47
|
+
And then execute:
|
48
|
+
|
49
|
+
$ bundle
|
50
|
+
|
51
|
+
Or install it yourself as:
|
52
|
+
|
53
|
+
$ gem install rack_api_key_limit
|
54
|
+
|
55
|
+
## Usage
|
56
|
+
|
57
|
+
### Rails 3 installation
|
58
|
+
|
59
|
+
config/application.rb
|
60
|
+
|
61
|
+
```
|
62
|
+
config.middleware.insert_before 'Rack::Cache', Rack::ApiKeyLimit::Hourly, {
|
63
|
+
cache: Rack::ApiKeyLimit::Cache::Redis.new(your_redis_instance),
|
64
|
+
request_limit: 100
|
65
|
+
}
|
66
|
+
```
|
67
|
+
|
68
|
+
## Contributing
|
69
|
+
|
70
|
+
If you are contributing, please include good test coverage for your pull request - thanks!
|
71
|
+
|
72
|
+
1. Fork it
|
73
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
74
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
75
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
76
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module Rack
|
2
|
+
module ApiKeyLimit
|
3
|
+
class Base
|
4
|
+
def initialize(app, options)
|
5
|
+
@app = app
|
6
|
+
@options = options
|
7
|
+
end
|
8
|
+
|
9
|
+
def options
|
10
|
+
@options || {}
|
11
|
+
end
|
12
|
+
|
13
|
+
def cache
|
14
|
+
@options[:cache]
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(env)
|
18
|
+
request = Rack::Request.new(env)
|
19
|
+
key = get_key(request, cache)
|
20
|
+
allowed?(request, key) ? not_rate_limited(env, request, key) : rate_limit_exceeded(key)
|
21
|
+
end
|
22
|
+
|
23
|
+
def param_name
|
24
|
+
options[:param_name] || "api_key"
|
25
|
+
end
|
26
|
+
|
27
|
+
def param(request)
|
28
|
+
request.params[param_name]
|
29
|
+
end
|
30
|
+
|
31
|
+
def has_param?(request)
|
32
|
+
request.params.has_key?(param_name)
|
33
|
+
end
|
34
|
+
|
35
|
+
def get_key(request, cache)
|
36
|
+
raise NotImplementedError.new("You must implement get_key.")
|
37
|
+
end
|
38
|
+
|
39
|
+
def not_rate_limited(env, request, key)
|
40
|
+
status, headers, response = @app.call(env)
|
41
|
+
headers = headers.merge(rate_limit_headers(key)) if has_param?(request)
|
42
|
+
[status, headers, response]
|
43
|
+
end
|
44
|
+
|
45
|
+
def request_limit
|
46
|
+
options[:request_limit] || 150
|
47
|
+
end
|
48
|
+
|
49
|
+
def limit_seconds
|
50
|
+
raise NotImplementedError.new("You must implement limit_seconds.")
|
51
|
+
end
|
52
|
+
|
53
|
+
def rate_limit_headers(key)
|
54
|
+
headers = {}
|
55
|
+
headers["X-RateLimit-Limit"] = request_limit.to_s
|
56
|
+
headers["X-RateLimit-Remaining"] = remaining(key).to_s
|
57
|
+
headers["X-RateLimit-Reset"] = retry_after.to_f.ceil.to_s if respond_to?(:retry_after)
|
58
|
+
headers
|
59
|
+
end
|
60
|
+
|
61
|
+
def rate_limit_exceeded(key)
|
62
|
+
http_error(options[:status] || 429, options[:message] || 'Rate Limit Exceeded', rate_limit_headers(key))
|
63
|
+
end
|
64
|
+
|
65
|
+
def request_count(key)
|
66
|
+
request_count = cache.get(key)
|
67
|
+
(request_count.to_i if request_count) || 0
|
68
|
+
end
|
69
|
+
|
70
|
+
def remaining(key)
|
71
|
+
request_limit - request_count(key)
|
72
|
+
end
|
73
|
+
|
74
|
+
def allowed?(request, key)
|
75
|
+
return true unless has_param?(request) # always allowed if no key present
|
76
|
+
cache.increment(key, limit_seconds) and return true if remaining(key) > 0
|
77
|
+
end
|
78
|
+
|
79
|
+
def http_error(code, message = nil, headers = {})
|
80
|
+
[code, {'Content-Type' => 'text/plain; charset=utf-8'}.merge(headers),
|
81
|
+
[http_status(code) + (message.nil? ? "\n" : " (#{message})\n")]
|
82
|
+
]
|
83
|
+
end
|
84
|
+
|
85
|
+
def http_status(code)
|
86
|
+
[code, Rack::Utils::HTTP_STATUS_CODES[code]].join(' ')
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Rack
|
2
|
+
module ApiKeyLimit
|
3
|
+
module Cache
|
4
|
+
class Redis
|
5
|
+
def initialize(redis)
|
6
|
+
@redis = redis
|
7
|
+
end
|
8
|
+
|
9
|
+
def get(key)
|
10
|
+
@redis.get(key)
|
11
|
+
end
|
12
|
+
|
13
|
+
def increment(key, limit_seconds)
|
14
|
+
@redis.multi do
|
15
|
+
@redis.incr(key)
|
16
|
+
@redis.expire(key, limit_seconds)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Rack
|
2
|
+
module ApiKeyLimit
|
3
|
+
class Hourly < Base
|
4
|
+
def get_key(request, counter)
|
5
|
+
api_key = param(request)
|
6
|
+
"#{param_name}-rate-limit:#{api_key}-#{Time.now.hour}"
|
7
|
+
end
|
8
|
+
|
9
|
+
def limit_seconds
|
10
|
+
3600
|
11
|
+
end
|
12
|
+
|
13
|
+
def retry_after
|
14
|
+
retry_after_seconds(Time.now, limit_seconds)
|
15
|
+
end
|
16
|
+
|
17
|
+
def retry_after_seconds(time_now, period_seconds)
|
18
|
+
seconds_since_midnight = time_now.to_i % 86400
|
19
|
+
(period_seconds - seconds_since_midnight % period_seconds)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rack_api_key_limit/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rack_api_key_limit"
|
8
|
+
spec.version = Rack::ApiKeyLimit::VERSION
|
9
|
+
spec.authors = ["Rich Hollis"]
|
10
|
+
spec.email = ["richhollis@gmail.com"]
|
11
|
+
spec.description = %q{Rack middleware for limiting requests based on an parameter}
|
12
|
+
spec.summary = %q{The middleware uses a default strategy of hourly limiting for api keys but has been designed so that you can implement your own strategies and cache stores.}
|
13
|
+
spec.homepage = "https://github.com/richhollis/rack_api_key_limit"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake", "~> 10"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3"
|
24
|
+
spec.add_development_dependency "timecop", "~> 0"
|
25
|
+
spec.add_development_dependency 'rack-test', '~> 0.5'
|
26
|
+
|
27
|
+
spec.add_runtime_dependency 'rack', '~> 1.0'
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rack::ApiKeyLimit::Base do
|
4
|
+
|
5
|
+
include Rack::Test::Methods
|
6
|
+
|
7
|
+
let(:cache) { CacheStub.new }
|
8
|
+
let(:app) { app_stub_with_options({cache: cache}) }
|
9
|
+
|
10
|
+
context "api_key not present" do
|
11
|
+
before(:each) { get "/foo" }
|
12
|
+
it "when called without param is allowed" do
|
13
|
+
expect(last_response.body).to eq "Example App Body"
|
14
|
+
end
|
15
|
+
it "doesn't return X-RateLimit headers" do
|
16
|
+
expect(last_response.headers).to eq({"Content-Length" => "16"})
|
17
|
+
end
|
18
|
+
end
|
19
|
+
context "api_key present" do
|
20
|
+
context "counter at zero" do
|
21
|
+
it "allows call" do
|
22
|
+
get "/foo?api_key=test"
|
23
|
+
expect(last_response.body).to eq "Example App Body"
|
24
|
+
expect(last_response.headers).to include({"X-RateLimit-Remaining" => "149"})
|
25
|
+
end
|
26
|
+
it "increments the counter" do
|
27
|
+
Timecop.freeze { 3.times { get "/foo?api_key=test" } }
|
28
|
+
key = "api_key-rate-limit:test-13"
|
29
|
+
expect(app.request_count(key)).to eq 3
|
30
|
+
end
|
31
|
+
end
|
32
|
+
context "counter at max limit" do
|
33
|
+
before(:each) {
|
34
|
+
allow(cache).to receive(:get).and_return(150)
|
35
|
+
Timecop.freeze(spec_time) { get "/foo?api_key=test" }
|
36
|
+
}
|
37
|
+
it "returns rate limit error body" do
|
38
|
+
expect(last_response.body).to eq "429 Too Many Requests (Rate Limit Exceeded)\n"
|
39
|
+
end
|
40
|
+
it "returns rate limit status code" do
|
41
|
+
expect(last_response.status).to eq 429
|
42
|
+
end
|
43
|
+
it "retuns X-RateLimit headers" do
|
44
|
+
expect(last_response.headers).to include({"X-RateLimit-Limit" => "150"})
|
45
|
+
expect(last_response.headers).to include({"X-RateLimit-Remaining" => "0"})
|
46
|
+
expect(last_response.headers).to include({"X-RateLimit-Reset" => "300"})
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
context "options" do
|
51
|
+
context "param_name" do
|
52
|
+
let(:app) { app_stub_with_options({cache: cache, param_name: "my_api_key"}) }
|
53
|
+
it "uses specified param name" do
|
54
|
+
get "/foo?my_api_key=test"
|
55
|
+
expect(last_response.headers).to include({"X-RateLimit-Remaining" => "149"})
|
56
|
+
end
|
57
|
+
end
|
58
|
+
context "request_limit" do
|
59
|
+
let(:app) { app_stub_with_options({cache: cache, request_limit: 10}) }
|
60
|
+
it "uses specified request_limit" do
|
61
|
+
get "/foo?api_key=test"
|
62
|
+
expect(last_response.headers).to include({"X-RateLimit-Remaining" => "9"})
|
63
|
+
end
|
64
|
+
end
|
65
|
+
context "status & message" do
|
66
|
+
let(:app) { app_stub_with_options({cache: cache, status: 403, message: "Rate limit!", request_limit: 0}) }
|
67
|
+
it "uses specified status and message" do
|
68
|
+
get "/foo?api_key=test"
|
69
|
+
expect(last_response.body).to eq "403 Forbidden (Rate limit!)\n"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rack::ApiKeyLimit::Hourly do
|
4
|
+
|
5
|
+
include Rack::Test::Methods
|
6
|
+
|
7
|
+
let(:cache) { CacheStub.new }
|
8
|
+
let(:app) { described_class.new(example_target_app, {cache: cache}) }
|
9
|
+
|
10
|
+
describe "#get_key" do
|
11
|
+
it "returns expected format" do
|
12
|
+
request = double("request object")
|
13
|
+
allow(request).to receive(:params).and_return({"api_key" => "ABC" })
|
14
|
+
Timecop.freeze(spec_time) {
|
15
|
+
expect(app.get_key(request, cache)).to eq("api_key-rate-limit:ABC-13")
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
describe "#retry_after_seconds" do
|
20
|
+
it "returns correct value for minute remaining" do
|
21
|
+
expect(app.retry_after_seconds(Time.gm(2014,9,16,16,59,00), 3600)).to eq(60)
|
22
|
+
end
|
23
|
+
it "returns correct value for hour remaining" do
|
24
|
+
expect(app.retry_after_seconds(Time.gm(2014,9,16,00,00,00), 3600)).to eq(3600)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require "rack/test"
|
2
|
+
require "rack_api_key_limit"
|
3
|
+
require "timecop"
|
4
|
+
|
5
|
+
Dir[File.expand_path('../support/**/*.rb', __FILE__)].each { |f| require f }
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.expect_with :rspec do |c|
|
9
|
+
c.syntax = :expect
|
10
|
+
end
|
11
|
+
config.color = true
|
12
|
+
end
|
13
|
+
|
14
|
+
def example_target_app
|
15
|
+
app = double("Example Rack App")
|
16
|
+
allow(app).to receive(:call).and_return([200, {}, "Example App Body"])
|
17
|
+
app
|
18
|
+
end
|
19
|
+
|
20
|
+
def app_stub_with_options(options)
|
21
|
+
cache = CacheStub.new
|
22
|
+
LimiterStub.new(example_target_app, options)
|
23
|
+
end
|
24
|
+
|
25
|
+
def spec_time
|
26
|
+
Time.gm(2014,9,16,13,55,00)
|
27
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class LimiterStub < Rack::ApiKeyLimit::Base
|
2
|
+
def get_key(request, counter)
|
3
|
+
api_key = param(request)
|
4
|
+
"#{param_name}-rate-limit:#{api_key}-#{Time.now.hour}"
|
5
|
+
end
|
6
|
+
|
7
|
+
def limit_seconds
|
8
|
+
3600
|
9
|
+
end
|
10
|
+
|
11
|
+
def retry_after
|
12
|
+
retry_after_seconds(Time.now, limit_seconds)
|
13
|
+
end
|
14
|
+
|
15
|
+
def retry_after_seconds(time_now, period_seconds)
|
16
|
+
seconds_since_midnight = time_now.to_i % 86400
|
17
|
+
(period_seconds - seconds_since_midnight % period_seconds)
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class LimiterStub < Rack::ApiKeyLimit::Base
|
2
|
+
def get_key(request, counter)
|
3
|
+
api_key = param(request)
|
4
|
+
"#{param_name}-rate-limit:#{api_key}-#{Time.now.hour}"
|
5
|
+
end
|
6
|
+
|
7
|
+
def limit_seconds
|
8
|
+
3600
|
9
|
+
end
|
10
|
+
|
11
|
+
def retry_after
|
12
|
+
retry_after_seconds(Time.now, limit_seconds)
|
13
|
+
end
|
14
|
+
|
15
|
+
def retry_after_seconds(time_now, period_seconds)
|
16
|
+
seconds_since_midnight = time_now.to_i % 86400
|
17
|
+
(period_seconds - seconds_since_midnight % period_seconds)
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack_api_key_limit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rich Hollis
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: timecop
|
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: rack-test
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.5'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.5'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rack
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.0'
|
97
|
+
description: Rack middleware for limiting requests based on an parameter
|
98
|
+
email:
|
99
|
+
- richhollis@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- Gemfile
|
106
|
+
- LICENSE.txt
|
107
|
+
- README.md
|
108
|
+
- Rakefile
|
109
|
+
- lib/rack_api_key_limit.rb
|
110
|
+
- lib/rack_api_key_limit/base.rb
|
111
|
+
- lib/rack_api_key_limit/cache/redis.rb
|
112
|
+
- lib/rack_api_key_limit/hourly.rb
|
113
|
+
- lib/rack_api_key_limit/version.rb
|
114
|
+
- rack_api_key_limit.gemspec
|
115
|
+
- spec/lib/rack_api_key_limit/base_spec.rb
|
116
|
+
- spec/lib/rack_api_key_limit/hourly_spec.rb
|
117
|
+
- spec/spec_helper.rb
|
118
|
+
- spec/support/cache_stub.rb
|
119
|
+
- spec/support/lib/cache_stub.rb
|
120
|
+
- spec/support/lib/limiter_stub.rb
|
121
|
+
- spec/support/limiter_stub.rb
|
122
|
+
homepage: https://github.com/richhollis/rack_api_key_limit
|
123
|
+
licenses:
|
124
|
+
- MIT
|
125
|
+
metadata: {}
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
requirements: []
|
141
|
+
rubyforge_project:
|
142
|
+
rubygems_version: 2.2.2
|
143
|
+
signing_key:
|
144
|
+
specification_version: 4
|
145
|
+
summary: The middleware uses a default strategy of hourly limiting for api keys but
|
146
|
+
has been designed so that you can implement your own strategies and cache stores.
|
147
|
+
test_files:
|
148
|
+
- spec/lib/rack_api_key_limit/base_spec.rb
|
149
|
+
- spec/lib/rack_api_key_limit/hourly_spec.rb
|
150
|
+
- spec/spec_helper.rb
|
151
|
+
- spec/support/cache_stub.rb
|
152
|
+
- spec/support/lib/cache_stub.rb
|
153
|
+
- spec/support/lib/limiter_stub.rb
|
154
|
+
- spec/support/limiter_stub.rb
|