summaryrefslogtreecommitdiff
path: root/lib/gitlab/request_context.rb
diff options
context:
space:
mode:
authorPawel Chojnacki <pawel@chojnacki.ws>2017-02-06 13:48:46 +0100
committerPawel Chojnacki <pawel@chojnacki.ws>2017-03-06 15:41:24 +0100
commite5cf3f51fb568361a247d715facb6cd9bb15bb16 (patch)
treed12f9644c8b0dd0765fd0de90d69027848341083 /lib/gitlab/request_context.rb
parent27729aa3a4666c6b06006c76023f4bff60f8ba25 (diff)
downloadgitlab-ce-e5cf3f51fb568361a247d715facb6cd9bb15bb16.tar.gz
Allow limiting logging in users from too many different IPs.
Diffstat (limited to 'lib/gitlab/request_context.rb')
-rw-r--r--lib/gitlab/request_context.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/gitlab/request_context.rb b/lib/gitlab/request_context.rb
new file mode 100644
index 00000000000..5daf04dc92b
--- /dev/null
+++ b/lib/gitlab/request_context.rb
@@ -0,0 +1,25 @@
+module Gitlab
+ class RequestStoreNotActive < StandardError
+ end
+
+ class RequestContext
+ class << self
+ def client_ip
+ RequestStore[:client_ip]
+ end
+ end
+
+ def initialize(app)
+ @app = app
+ end
+
+ def call(env)
+ raise RequestStoreNotActive.new unless RequestStore.active?
+ req = Rack::Request.new(env)
+
+ RequestStore[:client_ip] = req.ip
+
+ @app.call(env)
+ end
+ end
+end \ No newline at end of file