Class: Wafris::Configuration
- Inherits:
-
Object
- Object
- Wafris::Configuration
- Defined in:
- lib/wafris/configuration.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#db_file_name ⇒ Object
Returns the value of attribute db_file_name.
-
#db_file_path ⇒ Object
Returns the value of attribute db_file_path.
-
#downsync_custom_rules_interval ⇒ Object
Returns the value of attribute downsync_custom_rules_interval.
-
#downsync_data_subscriptions_interval ⇒ Object
Returns the value of attribute downsync_data_subscriptions_interval.
-
#downsync_url ⇒ Object
Returns the value of attribute downsync_url.
-
#last_upsync_timestamp ⇒ Object
Returns the value of attribute last_upsync_timestamp.
-
#local_only ⇒ Object
Returns the value of attribute local_only.
-
#max_body_size_mb ⇒ Object
Returns the value of attribute max_body_size_mb.
-
#rate_limiters ⇒ Object
Returns the value of attribute rate_limiters.
-
#upsync_interval ⇒ Object
Returns the value of attribute upsync_interval.
-
#upsync_queue ⇒ Object
Returns the value of attribute upsync_queue.
-
#upsync_queue_limit ⇒ Object
Returns the value of attribute upsync_queue_limit.
-
#upsync_status ⇒ Object
Returns the value of attribute upsync_status.
-
#upsync_url ⇒ Object
Returns the value of attribute upsync_url.
Instance Method Summary collapse
- #create_settings ⇒ Object
- #current_config ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/wafris/configuration.rb', line 21 def initialize # API Key - Required if ENV["WAFRIS_API_KEY"] @api_key = ENV["WAFRIS_API_KEY"] else unless @api_key LogSuppressor.puts_log("Firewall disabled as neither local only or API key set") end end # DB FILE PATH LOCATION - Optional @db_file_path = ENV["WAFRIS_DB_FILE_PATH"] || "./tmp/wafris" # Ensure that the db_file_path exists unless File.directory?(@db_file_path) LogSuppressor.puts_log("DB File Path does not exist - creating it now.") FileUtils.mkdir_p(@db_file_path) unless File.exist?(@db_file_path) end # DB FILE NAME - For local @db_file_name = ENV["WAFRIS_DB_FILE_NAME"] || "wafris.db" # DOWNSYNC # Custom Rules are checked often (default 1 minute) - Optional @downsync_custom_rules_interval = ENV["WAFRIS_DOWNSYNC_CUSTOM_RULES_INTERVAL"]&.to_i || 60 # Data Subscriptions are checked rarely (default 1 day) - Optional @downsync_data_subscriptions_interval = ENV["WAFRIS_DOWNSYNC_DATA_SUBSCRIPTIONS_INTERVAL"]&.to_i || 60 # Set Downsync URL - Optional # Used for both DataSubscription and CustomRules @downsync_url = ENV["WAFRIS_DOWNSYNC_URL"] || "https://distributor.wafris.org/v2/downsync" # UPSYNC - Optional # Set Upsync URL @upsync_url = ENV["WAFRIS_UPSYNC_URL"] || "https://collector.wafris.org/v2/upsync" # Set Upsync Interval - Optional @upsync_interval = ENV["WAFRIS_UPSYNC_INTERVAL"]&.to_i || 10 # Set Upsync Queued Request Limit - Optional @upsync_queue_limit = ENV["WAFRIS_UPSYNC_QUEUE_LIMIT"]&.to_i || 250 # Set Maximium Body Size for Requests - Optional (in Megabytes) @max_body_size_mb = if ENV["WAFRIS_MAX_BODY_SIZE_MB"] && ENV["WAFRIS_MAX_BODY_SIZE_MB"].to_i > 0 ENV["WAFRIS_MAX_BODY_SIZE_MB"].to_i else 10 end # Upsync Queue Defaults @upsync_queue = [] @last_upsync_timestamp = Time.now.to_i # Memory structure for rate limiting @rate_limiters = {} # Disable Upsync if Downsync API Key is invalid # This prevents the client from sending upsync requests # if the API key is known bad @upsync_status = "Disabled" end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
5 6 7 |
# File 'lib/wafris/configuration.rb', line 5 def api_key @api_key end |
#db_file_name ⇒ Object
Returns the value of attribute db_file_name.
7 8 9 |
# File 'lib/wafris/configuration.rb', line 7 def db_file_name @db_file_name end |
#db_file_path ⇒ Object
Returns the value of attribute db_file_path.
6 7 8 |
# File 'lib/wafris/configuration.rb', line 6 def db_file_path @db_file_path end |
#downsync_custom_rules_interval ⇒ Object
Returns the value of attribute downsync_custom_rules_interval.
8 9 10 |
# File 'lib/wafris/configuration.rb', line 8 def downsync_custom_rules_interval @downsync_custom_rules_interval end |
#downsync_data_subscriptions_interval ⇒ Object
Returns the value of attribute downsync_data_subscriptions_interval.
9 10 11 |
# File 'lib/wafris/configuration.rb', line 9 def downsync_data_subscriptions_interval @downsync_data_subscriptions_interval end |
#downsync_url ⇒ Object
Returns the value of attribute downsync_url.
10 11 12 |
# File 'lib/wafris/configuration.rb', line 10 def downsync_url @downsync_url end |
#last_upsync_timestamp ⇒ Object
Returns the value of attribute last_upsync_timestamp.
17 18 19 |
# File 'lib/wafris/configuration.rb', line 17 def @last_upsync_timestamp end |
#local_only ⇒ Object
Returns the value of attribute local_only.
16 17 18 |
# File 'lib/wafris/configuration.rb', line 16 def local_only @local_only end |
#max_body_size_mb ⇒ Object
Returns the value of attribute max_body_size_mb.
18 19 20 |
# File 'lib/wafris/configuration.rb', line 18 def max_body_size_mb @max_body_size_mb end |
#rate_limiters ⇒ Object
Returns the value of attribute rate_limiters.
19 20 21 |
# File 'lib/wafris/configuration.rb', line 19 def rate_limiters @rate_limiters end |
#upsync_interval ⇒ Object
Returns the value of attribute upsync_interval.
12 13 14 |
# File 'lib/wafris/configuration.rb', line 12 def upsync_interval @upsync_interval end |
#upsync_queue ⇒ Object
Returns the value of attribute upsync_queue.
15 16 17 |
# File 'lib/wafris/configuration.rb', line 15 def upsync_queue @upsync_queue end |
#upsync_queue_limit ⇒ Object
Returns the value of attribute upsync_queue_limit.
13 14 15 |
# File 'lib/wafris/configuration.rb', line 13 def upsync_queue_limit @upsync_queue_limit end |
#upsync_status ⇒ Object
Returns the value of attribute upsync_status.
14 15 16 |
# File 'lib/wafris/configuration.rb', line 14 def upsync_status @upsync_status end |
#upsync_url ⇒ Object
Returns the value of attribute upsync_url.
11 12 13 |
# File 'lib/wafris/configuration.rb', line 11 def upsync_url @upsync_url end |
Instance Method Details
#create_settings ⇒ Object
94 95 96 |
# File 'lib/wafris/configuration.rb', line 94 def create_settings @version = Wafris::VERSION end |
#current_config ⇒ Object
84 85 86 87 88 89 90 91 92 |
# File 'lib/wafris/configuration.rb', line 84 def current_config output = {} instance_variables.each do |var| output[var.to_s] = instance_variable_get(var) end output end |