wafris 2.1.2 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b9b1568fdef719383076bc488ff10f37d62b07aeaf143665e2e766e1d5d61b6
4
- data.tar.gz: d96a46ce2ef95bbe3bfbd4d4d4b08d10a72f8270e1808f8e0f212692249a6634
3
+ metadata.gz: 722b44b21ce69ec8d515c442b3ee5fd783298de0714105eb9cd9585f3f007af9
4
+ data.tar.gz: d93da5905d328163e235e193998e63033a2be5b1e509a4b62ecbe804b0023289
5
5
  SHA512:
6
- metadata.gz: 3cf48c2b9aee1ac009b1e242490e6512e45e231d4a57d698cb89237a5c83f466cea1ef428feb4550dce39d786a102790257c861ddd4314e5f7865dad1967e32d
7
- data.tar.gz: 29b8543c5dd1236471a60c29f45cd9ce71793db0ae77a349b6666c1862e4bcec90ee5e6ba211b87e719a74584fad142bead0afa04b6643f9999636e928aeb24e
6
+ metadata.gz: 9945fef04660a4e6aeaf6aac33669bcfc210c1386ba684e7a147602f76542c0764c98dd9072fe35faace14bbaaf5d0be492e21c754da9b2607dae204ee350b1b
7
+ data.tar.gz: d219c32ddb8f9375bb1b006d3b0b3d49c5fe47ca4632e5bb8b8bd93a398c05d2dd183d5ad5a79510d4de89bf6f677d0c84ed038ea40fd0a7b4319bc6aff28d03
@@ -1,98 +1,66 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "version"
2
4
 
3
5
  module Wafris
4
6
  class Configuration
5
- attr_accessor :api_key
6
- attr_accessor :db_file_path
7
- attr_accessor :db_file_name
8
- attr_accessor :downsync_custom_rules_interval
9
- attr_accessor :downsync_data_subscriptions_interval
10
- attr_accessor :downsync_url
11
- attr_accessor :upsync_url
12
- attr_accessor :upsync_interval
13
- attr_accessor :upsync_queue_limit
14
- attr_accessor :upsync_status
15
- attr_accessor :upsync_queue
16
- attr_accessor :local_only
17
- attr_accessor :last_upsync_timestamp
18
- attr_accessor :max_body_size_mb
19
- attr_accessor :rate_limiters
7
+ attr_accessor :api_key,
8
+ :db_file_path,
9
+ :db_file_name,
10
+ :downsync_custom_rules_interval,
11
+ :downsync_data_subscriptions_interval,
12
+ :downsync_url,
13
+ :upsync_url,
14
+ :upsync_interval,
15
+ :upsync_queue_limit,
16
+ :upsync_status,
17
+ :upsync_queue,
18
+ :local_only,
19
+ :last_upsync_timestamp,
20
+ :max_body_size_mb,
21
+ :rate_limiters
20
22
 
21
23
  def initialize
22
- # API Key - Required
23
- if ENV["WAFRIS_API_KEY"]
24
- @api_key = ENV["WAFRIS_API_KEY"]
25
- else
26
- unless @api_key
27
- LogSuppressor.puts_log("Firewall disabled as neither local only or API key set")
28
- end
29
- end
30
-
31
- # DB FILE PATH LOCATION - Optional
24
+ @api_key = ENV["WAFRIS_API_KEY"]
32
25
  @db_file_path = ENV["WAFRIS_DB_FILE_PATH"] || "./tmp/wafris"
33
-
34
- # Ensure that the db_file_path exists
35
- unless File.directory?(@db_file_path)
36
- LogSuppressor.puts_log("DB File Path does not exist - creating it now.")
37
- FileUtils.mkdir_p(@db_file_path) unless File.exist?(@db_file_path)
38
- end
39
-
40
- # DB FILE NAME - For local
41
26
  @db_file_name = ENV["WAFRIS_DB_FILE_NAME"] || "wafris.db"
42
-
43
- # DOWNSYNC
44
- # Custom Rules are checked often (default 1 minute) - Optional
45
27
  @downsync_custom_rules_interval = ENV["WAFRIS_DOWNSYNC_CUSTOM_RULES_INTERVAL"]&.to_i || 60
46
-
47
- # Data Subscriptions are checked rarely (default 1 day) - Optional
48
28
  @downsync_data_subscriptions_interval = ENV["WAFRIS_DOWNSYNC_DATA_SUBSCRIPTIONS_INTERVAL"]&.to_i || 60
49
-
50
- # Set Downsync URL - Optional
51
- # Used for both DataSubscription and CustomRules
52
29
  @downsync_url = ENV["WAFRIS_DOWNSYNC_URL"] || "https://distributor.wafris.org/v2/downsync"
53
-
54
- # UPSYNC - Optional
55
- # Set Upsync URL
56
30
  @upsync_url = ENV["WAFRIS_UPSYNC_URL"] || "https://collector.wafris.org/v2/upsync"
57
-
58
- # Set Upsync Interval - Optional
59
31
  @upsync_interval = ENV["WAFRIS_UPSYNC_INTERVAL"]&.to_i || 10
60
-
61
- # Set Upsync Queued Request Limit - Optional
62
32
  @upsync_queue_limit = ENV["WAFRIS_UPSYNC_QUEUE_LIMIT"]&.to_i || 250
63
-
64
- # Set Maximium Body Size for Requests - Optional (in Megabytes)
65
- @max_body_size_mb = if ENV["WAFRIS_MAX_BODY_SIZE_MB"] && ENV["WAFRIS_MAX_BODY_SIZE_MB"].to_i > 0
66
- ENV["WAFRIS_MAX_BODY_SIZE_MB"].to_i
67
- else
68
- 10
69
- end
70
-
71
- # Upsync Queue Defaults
33
+ @max_body_size_mb = set_max_body_size
72
34
  @upsync_queue = []
73
35
  @last_upsync_timestamp = Time.now.to_i
74
-
75
- # Memory structure for rate limiting
76
36
  @rate_limiters = {}
77
-
78
- # Disable Upsync if Downsync API Key is invalid
79
- # This prevents the client from sending upsync requests
80
- # if the API key is known bad
81
37
  @upsync_status = "Disabled"
82
38
  end
83
39
 
84
- def current_config
85
- output = {}
86
-
87
- instance_variables.each do |var|
88
- output[var.to_s] = instance_variable_get(var)
40
+ def setup
41
+ if @api_key
42
+ create_db_file_path
43
+ else
44
+ LogSuppressor.puts_log("Firewall disabled as API key is not set.")
89
45
  end
46
+ end
90
47
 
91
- output
48
+ private
49
+
50
+ def set_max_body_size
51
+ if ENV["WAFRIS_MAX_BODY_SIZE_MB"] && ENV["WAFRIS_MAX_BODY_SIZE_MB"].to_i > 0
52
+ ENV["WAFRIS_MAX_BODY_SIZE_MB"].to_i
53
+ else
54
+ 10
55
+ end
92
56
  end
93
57
 
94
- def create_settings
95
- @version = Wafris::VERSION
58
+ def create_db_file_path
59
+ # Ensure that the db_file_path exists
60
+ unless File.directory?(@db_file_path)
61
+ LogSuppressor.puts_log("DB File Path does not exist - creating it now.")
62
+ FileUtils.mkdir_p(@db_file_path) unless File.exist?(@db_file_path)
63
+ end
96
64
  end
97
65
  end
98
66
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Wafris
4
- VERSION = "2.1.2"
4
+ VERSION = "2.2.0"
5
5
  end
data/lib/wafris.rb CHANGED
@@ -34,12 +34,18 @@ module Wafris
34
34
 
35
35
  def configure
36
36
  self.configuration ||= Wafris::Configuration.new
37
- yield(configuration)
37
+ if block_given?
38
+ yield(configuration)
39
+ LogSuppressor.puts_log("Configuration settings created with configure block.")
40
+ else
41
+ LogSuppressor.puts_log("Configuration settings created with defaults and ENV vars.")
42
+ end
38
43
 
39
- LogSuppressor.puts_log("[Wafris] Configuration settings created.")
40
- configuration.create_settings
44
+ configuration.setup
45
+
46
+ return configuration
41
47
  rescue => e
42
- puts "[Wafris] firewall disabled due to: #{e.message}. Cannot connect via Wafris.configure. Please check your configuration settings. More info can be found at: https://github.com/Wafris/wafris-rb"
48
+ LogSuppressor.puts_log("Firewall disabled due to: #{e.message}. Please check your configuration settings.")
43
49
  end
44
50
 
45
51
  def zero_pad(number, length)
@@ -432,7 +438,9 @@ module Wafris
432
438
  # This is the main loop that evaluates the request
433
439
  # as well as sorts out when downsync and upsync should be called
434
440
  def evaluate(request)
435
- @configuration ||= Wafris::Configuration.new
441
+ if @configuration.nil?
442
+ configure
443
+ end
436
444
 
437
445
  return "Passed" if @configuration.api_key.nil?
438
446
 
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: 2.1.2
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Buckbee
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-11-19 00:00:00.000000000 Z
12
+ date: 2024-11-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack