nexaas-throttle 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 +4 -4
- data/README.md +5 -1
- data/lib/nexaas/throttle/configuration.rb +6 -0
- data/lib/nexaas/throttle/guardian.rb +9 -4
- data/lib/nexaas/throttle/middleware.rb +1 -1
- data/lib/nexaas/throttle/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f56136a362918eb1468dbe7e0ba6b51c3f74c047
|
4
|
+
data.tar.gz: 3a5c43b886faa83d35cbd1501a5367d6a9da1d3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c5fe3080a4613d73281f30a45e26520b3de6f36c2944fa1ae196333c8407ccd7754f65d2ffa4812792bcaa6767f2ba77451fe26a7cefd70ba61d5de99742d0e
|
7
|
+
data.tar.gz: 5d815288a6a313a0f2e1c585bcf073e5b12d3ff863c770eda71d0c7695e945ae848858665a34b0cdc6948a8e4e54233803941451a0ee174812ece2cf4117da91
|
data/README.md
CHANGED
@@ -91,6 +91,11 @@ end
|
|
91
91
|
</pre>
|
92
92
|
</td>
|
93
93
|
</tr>
|
94
|
+
<tr>
|
95
|
+
<td><code>ignored_user_agents</code></td>
|
96
|
+
<td>Ignores how many User-Agent the application wants, in case of other applications from the same organization.</td>
|
97
|
+
<td><code>nil</code></td>
|
98
|
+
</tr>
|
94
99
|
</table>
|
95
100
|
|
96
101
|
### Request Identification
|
@@ -145,4 +150,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/myfree
|
|
145
150
|
## License
|
146
151
|
|
147
152
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
148
|
-
|
@@ -37,6 +37,11 @@ module Nexaas
|
|
37
37
|
# @return [Hash]
|
38
38
|
attr_reader :redis_options
|
39
39
|
|
40
|
+
# Ignores how many User-Agent the application wants, in case of other applications from the same organization.
|
41
|
+
# Example: ["Google", "Amazons"]
|
42
|
+
# @return [Array]
|
43
|
+
attr_accessor :ignored_user_agents
|
44
|
+
|
40
45
|
alias_method :throttleable?, :throttle
|
41
46
|
alias_method :trackable?, :track
|
42
47
|
|
@@ -47,6 +52,7 @@ module Nexaas
|
|
47
52
|
@limit = 60
|
48
53
|
@request_identifier = nil
|
49
54
|
@redis_options = default_redis_options
|
55
|
+
@ignored_user_agents = nil
|
50
56
|
end
|
51
57
|
|
52
58
|
def check!
|
@@ -3,9 +3,10 @@ require "base64"
|
|
3
3
|
module Nexaas
|
4
4
|
module Throttle
|
5
5
|
class Guardian
|
6
|
-
def initialize(request,
|
6
|
+
def initialize(request, configuration)
|
7
7
|
@request = request
|
8
|
-
@token = request_identifier.new(request).token
|
8
|
+
@token = configuration.request_identifier.new(request).token
|
9
|
+
@ignored_user_agents = configuration.ignored_user_agents
|
9
10
|
end
|
10
11
|
|
11
12
|
def throttle!
|
@@ -18,10 +19,10 @@ module Nexaas
|
|
18
19
|
|
19
20
|
private
|
20
21
|
|
21
|
-
attr_reader :request, :token
|
22
|
+
attr_reader :request, :token, :ignored_user_agents
|
22
23
|
|
23
24
|
def validate
|
24
|
-
return if assets? || !api? || token.blank?
|
25
|
+
return if ignore_user_agents? || assets? || !api? || token.blank?
|
25
26
|
request.env["nexaas.token"] = token
|
26
27
|
yield if block_given?
|
27
28
|
end
|
@@ -42,6 +43,10 @@ module Nexaas
|
|
42
43
|
/\.(#{extensions.join("|")})/
|
43
44
|
end
|
44
45
|
end
|
46
|
+
|
47
|
+
def ignore_user_agents?
|
48
|
+
ignored_user_agents && ignored_user_agents.include?(request.user_agent)
|
49
|
+
end
|
45
50
|
end
|
46
51
|
end
|
47
52
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nexaas-throttle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wanderson Policarpo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -182,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
182
182
|
version: '0'
|
183
183
|
requirements: []
|
184
184
|
rubyforge_project:
|
185
|
-
rubygems_version: 2.5.
|
185
|
+
rubygems_version: 2.5.2
|
186
186
|
signing_key:
|
187
187
|
specification_version: 4
|
188
188
|
summary: A tiny engine to allow throttling and blacklisting requests.
|