ahoy_matey 1.5.0 → 1.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 40222ba157a73c4362b78a26fe1796a9bbc9fb50
4
- data.tar.gz: 58a88b0ed382c126ceb141c902855f5c1492ee77
3
+ metadata.gz: 9e5a105f360566e591e93df058b2ef3f2b014d2b
4
+ data.tar.gz: 75b530f1d2ac5db181fce79e5e28772fee413e44
5
5
  SHA512:
6
- metadata.gz: e04afdc9015e4456e2062c718c38ef043777b3e7442435926420db88bbeecb5226b60d899d45b24d69faa9cadb4041f735a7460f6f8f0062180763c90fdadc8d
7
- data.tar.gz: 08de05c386b58857803d8867f92512293f68d41146d1c96d3e0c7082596ab4db0f0b920284ae28a9ffa946877440abe96279d2765b2cc030d68a65b6da62f9b6
6
+ metadata.gz: 04728f524b58d1b923072dbf88f2f3e028bd9e7c09b40b7e26dcf24b1311255fcf851401c1890d473d1ef43f6b35abac94be4ec71d889211d09f6ebd573f7934
7
+ data.tar.gz: 40cd9292793a8a9df4f91c474deb5fe787b483d9cf7f9b76d00ef9ebe36a0d82511fdc12dcf506acd71849b5443f072110af1faf4983596006c7a96543ac3c1b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 1.5.1
2
+
3
+ - Restored throttling after removing side effects
4
+
1
5
  ## 1.5.0
2
6
 
3
7
  - Removed throttling due to unintended side effects with its implementation
data/README.md CHANGED
@@ -530,18 +530,6 @@ Send a `POST` request as `Content-Type: application/json` to `/ahoy/events` with
530
530
 
531
531
  Use an array to pass multiple events at once.
532
532
 
533
- ## Throttling
534
-
535
- To throttle requests to Ahoy endpoints, check out [Rack::Attack](https://github.com/kickstarter/ack-attack). Here’s a sample config:
536
-
537
- ```ruby
538
- Rack::Attack.throttle("ahoy/ip", limit: 20, period: 1.minute) do |req|
539
- if req.path.start_with?("/ahoy/")
540
- req.ip
541
- end
542
- end
543
- ```
544
-
545
533
  ## Reference
546
534
 
547
535
  By default, Ahoy create endpoints at `/ahoy/visits` and `/ahoy/events`. To disable, use:
@@ -552,10 +540,6 @@ Ahoy.mount = false
552
540
 
553
541
  ## Upgrading
554
542
 
555
- ### 1.5.0
556
-
557
- There’s nothing to do, but it’s worth noting that simple throttling, which was added in `1.3.0`, was removed due to unintended side effects with its implementation. See the [Throttling](#throttling) section for how to properly add it by hand if needed.
558
-
559
543
  ### 1.4.0
560
544
 
561
545
  There’s nothing to do, but it’s worth noting the default store was changed from `ActiveRecordStore` to `ActiveRecordTokenStore` for new installations.
data/ahoy_matey.gemspec CHANGED
@@ -27,6 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.add_dependency "request_store"
28
28
  spec.add_dependency "uuidtools"
29
29
  spec.add_dependency "safely_block", ">= 0.1.1"
30
+ spec.add_dependency "rack-attack", "< 6"
30
31
 
31
32
  spec.add_development_dependency "bundler", "~> 1.5"
32
33
  spec.add_development_dependency "rake"
data/lib/ahoy.rb CHANGED
@@ -72,6 +72,15 @@ module Ahoy
72
72
  mattr_accessor :mount
73
73
  self.mount = true
74
74
 
75
+ mattr_accessor :throttle
76
+ self.throttle = true
77
+
78
+ mattr_accessor :throttle_limit
79
+ self.throttle_limit = 20
80
+
81
+ mattr_accessor :throttle_period
82
+ self.throttle_period = 1.minute
83
+
75
84
  mattr_accessor :job_queue
76
85
  self.job_queue = :ahoy
77
86
 
data/lib/ahoy/engine.rb CHANGED
@@ -1,6 +1,11 @@
1
1
  module Ahoy
2
2
  class Engine < ::Rails::Engine
3
3
  initializer "ahoy.middleware", after: "sprockets.environment" do |app|
4
+ if Ahoy.throttle
5
+ require "ahoy/throttle"
6
+ app.middleware.use Ahoy::Throttle
7
+ end
8
+
4
9
  next unless Ahoy.quiet
5
10
 
6
11
  # Parse PATH_INFO by assets prefix
@@ -0,0 +1,25 @@
1
+ require "rack/attack"
2
+
3
+ module Ahoy
4
+ class Throttle < Rack::Attack
5
+ throttle("ahoy/ip", limit: Ahoy.throttle_limit, period: Ahoy.throttle_period) do |req|
6
+ if req.path.start_with?("/ahoy/")
7
+ req.ip
8
+ end
9
+ end
10
+
11
+ def_delegators self, :whitelisted?, :blacklisted?, :throttled?, :tracked?, :blocklisted?, :safelisted?
12
+
13
+ def self.throttled_response
14
+ Rack::Attack.throttled_response
15
+ end
16
+
17
+ def self.blacklisted_response
18
+ Rack::Attack.blacklisted_response
19
+ end
20
+
21
+ def self.blocklisted_response
22
+ Rack::Attack.blocklisted_response
23
+ end
24
+ end
25
+ end
data/lib/ahoy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ahoy
2
- VERSION = "1.5.0"
2
+ VERSION = "1.5.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ahoy_matey
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
@@ -136,6 +136,20 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: 0.1.1
139
+ - !ruby/object:Gem::Dependency
140
+ name: rack-attack
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "<"
144
+ - !ruby/object:Gem::Version
145
+ version: '6'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "<"
151
+ - !ruby/object:Gem::Version
152
+ version: '6'
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: bundler
141
155
  requirement: !ruby/object:Gem::Requirement
@@ -260,6 +274,7 @@ files:
260
274
  - lib/ahoy/stores/log_store.rb
261
275
  - lib/ahoy/stores/mongoid_store.rb
262
276
  - lib/ahoy/subscribers/active_record.rb
277
+ - lib/ahoy/throttle.rb
263
278
  - lib/ahoy/tracker.rb
264
279
  - lib/ahoy/version.rb
265
280
  - lib/ahoy/visit_properties.rb