Browse Source

Add PaaS configuration for redis

pull/356/head
Stéphane Meny 3 years ago
parent
commit
b240e210ba
No known key found for this signature in database
GPG Key ID: 9D0AFEA988527923
  1. 1
      Gemfile
  2. 2
      Gemfile.lock
  3. 9
      config/initializers/rack_attack.rb
  4. 1
      spec/services/paas_configuration_service_spec.rb

1
Gemfile

@ -51,6 +51,7 @@ gem "paper_trail"
gem "paper_trail-globalid"
# Receive exceptions and configure alerts
gem "rack-attack"
gem "redis"
gem "sentry-rails"
gem "sentry-ruby"

2
Gemfile.lock

@ -334,6 +334,7 @@ GEM
rb-fsevent (0.11.1)
rb-inotify (0.10.1)
ffi (~> 1.0)
redis (4.6.0)
regexp_parser (2.2.1)
request_store (1.5.1)
rack (>= 1.4)
@ -495,6 +496,7 @@ DEPENDENCIES
rack-attack
rack-mini-profiler (~> 2.0)
rails (~> 7.0.1)
redis
roo
rspec-rails
rubocop-govuk

9
config/initializers/rack_attack.rb

@ -1,5 +1,10 @@
Rack::Attack.cache.store = ActiveSupport::Cache::MemoryStore.new
Rack::Attack.enabled = false
if Rails.env.development? || Rails.env.test?
Rack::Attack.cache.store = ActiveSupport::Cache::MemoryStore.new
Rack::Attack.enabled = false
else
redis_url = PaasConfigurationService.new.redis_uris[:"dluhc-core-#{Redis.env}-redis-rate-limit"]
Rack::Attack.cache.store = ActiveSupport::Cache::RedisCacheStore.new(url: redis_url)
end
Rack::Attack.throttle("password reset requests", limit: 5, period: 60.seconds) do |request|
if request.params["user"].present? && request.path == "/users/password" && request.post?

1
spec/services/paas_configuration_service_spec.rb

@ -136,5 +136,4 @@ RSpec.describe PaasConfigurationService do
expect(config_service.redis_uris).to be_empty
end
end
end

Loading…
Cancel
Save