wafris 1.1.3 → 1.1.4

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
  SHA256:
3
- metadata.gz: 389651499912f24676b1254c9a5f4dc2b1093e441a47da4a288a657020bc3494
4
- data.tar.gz: 9801b9f106f043b03816cee5ea26e3a85fc1f3f0ea0e572ffc0e4060368bfe78
3
+ metadata.gz: 6600b4667202df4429e13018d9eb1bdc0473029ad20dd5052e993f8390f06330
4
+ data.tar.gz: a4cf7a7781a19b03aa2c6389e24093b69f8b448c49beff1ddf798de9e9c97ef0
5
5
  SHA512:
6
- metadata.gz: 7ed5770968fc34f646830d45596f5035134bdf741d0d44cafe82b13386b370621a6071b992c54d26997e07a5098ed1b136b6dc9fc6fe2122345877017284631c
7
- data.tar.gz: 81e1e4fe9e4d01ee137a9ff1ee14e7b4422b20ad237a91f7611c3a0855d73b0d08deccf1cb53950ee58e10e55e1e6a485ff36f8e738524211acbe7460d494f2d
6
+ metadata.gz: 8eef758330be30b532d5b069df5db72d7bbbf8e98d277fe3cacc6842e8d01c997fcb1532810467497a2c87864f809b9fd83a0f13bfeef91a0503bfceace2f893
7
+ data.tar.gz: 0da7423796d0eb18d0d21d6ccda75555fe7042e1d5d999b539bfb13bde301d17b581b2b399faa122afc4e3acb32c567d5426cb04326dff34a81271319e341fd2
@@ -6,18 +6,11 @@ module Wafris
6
6
  class Configuration
7
7
  attr_accessor :redis
8
8
  attr_accessor :redis_pool_size
9
+ attr_accessor :maxmemory
9
10
 
10
11
  def initialize
11
- @redis = Redis.new(
12
- url: ENV['REDIS_URL'],
13
- ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE }
14
- )
15
12
  @redis_pool_size = 20
16
-
17
- puts "[Wafris] attempting firewall connection via REDIS_URL." unless LogSuppressor.suppress_logs?
18
- create_settings
19
- rescue Redis::CannotConnectError
20
- puts "[Wafris] firewall disabled. Cannot connect to REDIS_URL. Will attempt Wafris.configure if it exists." unless LogSuppressor.suppress_logs?
13
+ @maxmemory = 25
21
14
  end
22
15
 
23
16
  def connection_pool
@@ -29,8 +22,10 @@ module Wafris
29
22
  redis.hset('waf-settings',
30
23
  'version', Wafris::VERSION,
31
24
  'client', 'ruby',
32
- 'redis-host', 'heroku')
33
- puts "[Wafris] firewall enabled. Connected to Redis. Ready to process requests. Set rules at: https://wafris.org/hub" unless LogSuppressor.suppress_logs?
25
+ 'maxmemory', @maxmemory)
26
+ LogSuppressor.puts_log(
27
+ "[Wafris] firewall enabled. Connected to Redis. Ready to process requests. Set rules at: https://wafris.org/hub"
28
+ )
34
29
  end
35
30
 
36
31
  def core_sha
@@ -2,6 +2,10 @@
2
2
 
3
3
  module Wafris
4
4
  class LogSuppressor
5
+ def self.puts_log(message)
6
+ message unless suppress_logs?
7
+ end
8
+
5
9
  def self.suppress_logs?
6
10
  suppressed_environments.include?(current_environment)
7
11
  end
@@ -33,7 +33,9 @@ module Wafris
33
33
  [403, {}, ['Blocked']]
34
34
  end
35
35
  rescue StandardError => e
36
- puts "[Wafris] Redis connection error: #{e.message}. Request passed without rules check." unless LogSuppressor.suppress_logs?
36
+ LogSuppressor.puts_log(
37
+ "[Wafris] Redis connection error: #{e.message}. Request passed without rules check."
38
+ )
37
39
  @app.call(env)
38
40
  end
39
41
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Wafris
4
- VERSION = "1.1.3"
4
+ VERSION = "1.1.4"
5
5
  end
data/lib/wafris.rb CHANGED
@@ -12,20 +12,21 @@ require 'wafris/railtie' if defined?(Rails::Railtie)
12
12
 
13
13
  module Wafris
14
14
  class << self
15
- def configure
16
- yield configuration
17
- puts "[Wafris] attempting firewall connection via Wafris.configure initializer." unless LogSuppressor.suppress_logs?
18
- configuration.create_settings
19
- rescue Redis::CannotConnectError
20
- puts "[Wafris] firewall disabled. Cannot connect via Wafris.configure. Please check your configuration settings." unless LogSuppressor.suppress_logs?
21
- end
15
+ attr_accessor :configuration
22
16
 
23
- def configuration
24
- @configuration ||= Wafris::Configuration.new
25
- end
17
+ def configure
18
+ raise ArgumentError, "[Wafris] block is required to configure Wafris" unless block_given?
26
19
 
27
- def reset
28
- @configuration = Wafris::Configuration.new
20
+ self.configuration ||= Wafris::Configuration.new
21
+ yield(configuration)
22
+ LogSuppressor.puts_log(
23
+ "[Wafris] attempting firewall connection via Wafris.configure initializer."
24
+ )
25
+ configuration.create_settings
26
+ rescue Redis::CannotConnectError, ArgumentError
27
+ LogSuppressor.puts_log(
28
+ "[Wafris] firewall disabled. Cannot connect via Wafris.configure. Please check your configuration settings."
29
+ )
29
30
  end
30
31
 
31
32
  def allow_request?(request)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wafris
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micahel Buckbee
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-09-19 00:00:00.000000000 Z
12
+ date: 2023-09-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: connection_pool