Class: Parse::LiveQuery::Configuration
- Inherits:
-
Object
- Object
- Parse::LiveQuery::Configuration
- Defined in:
- lib/parse/live_query/configuration.rb
Overview
Centralized configuration for LiveQuery client.
Constant Summary collapse
- TLS_VERSION_MAP =
Map of TLS version symbols to OpenSSL constants
{ TLSv1: OpenSSL::SSL::TLS1_VERSION, TLSv1_1: OpenSSL::SSL::TLS1_1_VERSION, TLSv1_2: OpenSSL::SSL::TLS1_2_VERSION, TLSv1_3: OpenSSL::SSL::TLS1_3_VERSION, }.freeze
- VALID_TLS_VERSIONS =
Valid TLS version symbols
[nil, :TLSv1, :TLSv1_1, :TLSv1_2, :TLSv1_3].freeze
Instance Attribute Summary collapse
-
#allow_insecure ⇒ Boolean
When false (default), refuse to derive a ‘ws://` URL from an `http://` server URL on any non-loopback host.
-
#application_id ⇒ String
Parse application ID.
-
#auto_connect ⇒ Boolean
Automatically connect on client creation (default: true).
-
#auto_reconnect ⇒ Boolean
Automatically reconnect on disconnect (default: true).
-
#backpressure_strategy ⇒ Symbol
Backpressure strategy :block, :drop_oldest, :drop_newest (default: :drop_oldest).
-
#circuit_failure_threshold ⇒ Integer
Circuit breaker settings.
-
#circuit_reset_timeout ⇒ Float
Seconds before circuit transitions to half-open (default: 60.0).
-
#client_key ⇒ String
Parse client key.
-
#event_queue_size ⇒ Integer
Event queue settings.
-
#frame_read_timeout ⇒ Integer
Frame read timeout in seconds (default: 30) Prevents indefinite blocking when reading from socket.
-
#initial_reconnect_interval ⇒ Float
Reconnection backoff settings.
-
#log_level ⇒ Symbol
Log level :debug, :info, :warn, :error (default: :info).
-
#logger ⇒ Logger?
Custom logger instance (default: nil, uses STDOUT).
-
#logging_enabled ⇒ Boolean
Logging settings.
-
#master_key ⇒ String
Parse master key (optional).
-
#max_message_size ⇒ Integer
Security settings.
-
#max_reconnect_interval ⇒ Float
Maximum reconnect delay in seconds (default: 30.0).
-
#ping_interval ⇒ Float
Health monitoring settings.
-
#pong_timeout ⇒ Float
Seconds to wait for pong response (default: 10.0).
-
#reconnect_jitter ⇒ Float
Jitter factor for reconnect delay, 0.0-1.0 (default: 0.2).
-
#reconnect_multiplier ⇒ Float
Reconnect delay multiplier (default: 1.5).
-
#ssl_max_version ⇒ Symbol?
Maximum TLS version :TLSv1, :TLSv1_1, :TLSv1_2, :TLSv1_3 (default: nil = highest available) Caps the maximum TLS version (rarely needed, use for compatibility).
-
#ssl_min_version ⇒ Symbol?
Minimum TLS version :TLSv1, :TLSv1_1, :TLSv1_2, :TLSv1_3 (default: :TLSv1_2) Enforces minimum TLS version for WebSocket connections.
-
#url ⇒ String
Connection settings.
Class Method Summary collapse
-
.tls_version_constant(version) ⇒ Integer?
Convert a TLS version symbol to OpenSSL constant.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
Initialize with sensible defaults.
-
#to_h ⇒ Hash
Convert to hash.
-
#valid? ⇒ Boolean
Check if configuration is valid.
-
#validate ⇒ Array<String>
Validate configuration.
Constructor Details
#initialize ⇒ Configuration
Initialize with sensible defaults
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/parse/live_query/configuration.rb', line 127 def initialize # Connection @url = nil @application_id = nil @client_key = nil @master_key = nil @auto_connect = true @auto_reconnect = true # Health monitoring @ping_interval = 30.0 @pong_timeout = 10.0 # Circuit breaker @circuit_failure_threshold = 5 @circuit_reset_timeout = 60.0 # Reconnection backoff @initial_reconnect_interval = 1.0 @max_reconnect_interval = 30.0 @reconnect_multiplier = 1.5 @reconnect_jitter = 0.2 # Event queue @event_queue_size = 1000 @backpressure_strategy = :drop_oldest # Security @max_message_size = 1_048_576 # 1MB @frame_read_timeout = 30 # 30 seconds @ssl_min_version = :TLSv1_2 # Enforce modern TLS by default @ssl_max_version = nil # No maximum (use highest available) @allow_insecure = false # Refuse ws:// downgrade on non-loopback hosts # Logging @logging_enabled = false @log_level = :info @logger = nil end |
Instance Attribute Details
#allow_insecure ⇒ Boolean
Returns when false (default), refuse to derive a ‘ws://` URL from an `http://` server URL on any non-loopback host. The default `Parse::LiveQuery::Client#derive_websocket_url` path silently picks `ws://` when the Parse server URL is `http://`, carrying master keys and session tokens over a cleartext socket. Set to `true` to explicitly opt into insecure WebSocket transport (local development, container-internal networks). Loopback hosts (`localhost`, `127.0.0.1`, `::1`) are exempt and emit a warning instead.
87 88 89 |
# File 'lib/parse/live_query/configuration.rb', line 87 def allow_insecure @allow_insecure end |
#application_id ⇒ String
Returns Parse application ID.
21 22 23 |
# File 'lib/parse/live_query/configuration.rb', line 21 def application_id @application_id end |
#auto_connect ⇒ Boolean
Returns automatically connect on client creation (default: true).
30 31 32 |
# File 'lib/parse/live_query/configuration.rb', line 30 def auto_connect @auto_connect end |
#auto_reconnect ⇒ Boolean
Returns automatically reconnect on disconnect (default: true).
33 34 35 |
# File 'lib/parse/live_query/configuration.rb', line 33 def auto_reconnect @auto_reconnect end |
#backpressure_strategy ⇒ Symbol
Returns backpressure strategy :block, :drop_oldest, :drop_newest (default: :drop_oldest).
67 68 69 |
# File 'lib/parse/live_query/configuration.rb', line 67 def backpressure_strategy @backpressure_strategy end |
#circuit_failure_threshold ⇒ Integer
Circuit breaker settings
44 45 46 |
# File 'lib/parse/live_query/configuration.rb', line 44 def circuit_failure_threshold @circuit_failure_threshold end |
#circuit_reset_timeout ⇒ Float
Returns seconds before circuit transitions to half-open (default: 60.0).
47 48 49 |
# File 'lib/parse/live_query/configuration.rb', line 47 def circuit_reset_timeout @circuit_reset_timeout end |
#client_key ⇒ String
Returns Parse client key.
24 25 26 |
# File 'lib/parse/live_query/configuration.rb', line 24 def client_key @client_key end |
#event_queue_size ⇒ Integer
Event queue settings
64 65 66 |
# File 'lib/parse/live_query/configuration.rb', line 64 def event_queue_size @event_queue_size end |
#frame_read_timeout ⇒ Integer
Returns frame read timeout in seconds (default: 30) Prevents indefinite blocking when reading from socket.
76 77 78 |
# File 'lib/parse/live_query/configuration.rb', line 76 def frame_read_timeout @frame_read_timeout end |
#initial_reconnect_interval ⇒ Float
Reconnection backoff settings
51 52 53 |
# File 'lib/parse/live_query/configuration.rb', line 51 def initial_reconnect_interval @initial_reconnect_interval end |
#log_level ⇒ Symbol
Returns log level :debug, :info, :warn, :error (default: :info).
121 122 123 |
# File 'lib/parse/live_query/configuration.rb', line 121 def log_level @log_level end |
#logger ⇒ Logger?
Returns custom logger instance (default: nil, uses STDOUT).
124 125 126 |
# File 'lib/parse/live_query/configuration.rb', line 124 def logger @logger end |
#logging_enabled ⇒ Boolean
Logging settings
118 119 120 |
# File 'lib/parse/live_query/configuration.rb', line 118 def logging_enabled @logging_enabled end |
#master_key ⇒ String
Returns Parse master key (optional).
27 28 29 |
# File 'lib/parse/live_query/configuration.rb', line 27 def master_key @master_key end |
#max_message_size ⇒ Integer
Security settings
72 73 74 |
# File 'lib/parse/live_query/configuration.rb', line 72 def @max_message_size end |
#max_reconnect_interval ⇒ Float
Returns maximum reconnect delay in seconds (default: 30.0).
54 55 56 |
# File 'lib/parse/live_query/configuration.rb', line 54 def max_reconnect_interval @max_reconnect_interval end |
#ping_interval ⇒ Float
Health monitoring settings
37 38 39 |
# File 'lib/parse/live_query/configuration.rb', line 37 def ping_interval @ping_interval end |
#pong_timeout ⇒ Float
Returns seconds to wait for pong response (default: 10.0).
40 41 42 |
# File 'lib/parse/live_query/configuration.rb', line 40 def pong_timeout @pong_timeout end |
#reconnect_jitter ⇒ Float
Returns jitter factor for reconnect delay, 0.0-1.0 (default: 0.2).
60 61 62 |
# File 'lib/parse/live_query/configuration.rb', line 60 def reconnect_jitter @reconnect_jitter end |
#reconnect_multiplier ⇒ Float
Returns reconnect delay multiplier (default: 1.5).
57 58 59 |
# File 'lib/parse/live_query/configuration.rb', line 57 def reconnect_multiplier @reconnect_multiplier end |
#ssl_max_version ⇒ Symbol?
Returns maximum TLS version :TLSv1, :TLSv1_1, :TLSv1_2, :TLSv1_3 (default: nil = highest available) Caps the maximum TLS version (rarely needed, use for compatibility).
95 96 97 |
# File 'lib/parse/live_query/configuration.rb', line 95 def ssl_max_version @ssl_max_version end |
#ssl_min_version ⇒ Symbol?
Returns minimum TLS version :TLSv1, :TLSv1_1, :TLSv1_2, :TLSv1_3 (default: :TLSv1_2) Enforces minimum TLS version for WebSocket connections.
91 92 93 |
# File 'lib/parse/live_query/configuration.rb', line 91 def ssl_min_version @ssl_min_version end |
#url ⇒ String
Connection settings
18 19 20 |
# File 'lib/parse/live_query/configuration.rb', line 18 def url @url end |
Class Method Details
.tls_version_constant(version) ⇒ Integer?
Convert a TLS version symbol to OpenSSL constant
111 112 113 114 |
# File 'lib/parse/live_query/configuration.rb', line 111 def self.tls_version_constant(version) return nil if version.nil? TLS_VERSION_MAP[version] end |
Instance Method Details
#to_h ⇒ Hash
Convert to hash
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/parse/live_query/configuration.rb', line 196 def to_h { url: @url, application_id: @application_id, client_key: @client_key.nil? ? nil : "[REDACTED]", master_key: @master_key.nil? ? nil : "[REDACTED]", auto_connect: @auto_connect, auto_reconnect: @auto_reconnect, ping_interval: @ping_interval, pong_timeout: @pong_timeout, circuit_failure_threshold: @circuit_failure_threshold, circuit_reset_timeout: @circuit_reset_timeout, initial_reconnect_interval: @initial_reconnect_interval, max_reconnect_interval: @max_reconnect_interval, reconnect_multiplier: @reconnect_multiplier, reconnect_jitter: @reconnect_jitter, event_queue_size: @event_queue_size, backpressure_strategy: @backpressure_strategy, max_message_size: @max_message_size, frame_read_timeout: @frame_read_timeout, ssl_min_version: @ssl_min_version, ssl_max_version: @ssl_max_version, logging_enabled: @logging_enabled, log_level: @log_level, } end |
#valid? ⇒ Boolean
Check if configuration is valid
190 191 192 |
# File 'lib/parse/live_query/configuration.rb', line 190 def valid? validate.empty? end |
#validate ⇒ Array<String>
Validate configuration
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/parse/live_query/configuration.rb', line 169 def validate errors = [] errors << "ping_interval must be positive" if @ping_interval && @ping_interval <= 0 errors << "pong_timeout must be positive" if @pong_timeout && @pong_timeout <= 0 errors << "circuit_failure_threshold must be positive" if @circuit_failure_threshold && @circuit_failure_threshold <= 0 errors << "event_queue_size must be positive" if @event_queue_size && @event_queue_size <= 0 errors << "reconnect_jitter must be between 0.0 and 1.0" if @reconnect_jitter && (@reconnect_jitter < 0.0 || @reconnect_jitter > 1.0) errors << "backpressure_strategy must be :block, :drop_oldest, or :drop_newest" unless [:block, :drop_oldest, :drop_newest].include?(@backpressure_strategy) errors << "max_message_size must be positive" if @max_message_size && @max_message_size <= 0 errors << "frame_read_timeout must be positive" if @frame_read_timeout && @frame_read_timeout <= 0 errors << "log_level must be :debug, :info, :warn, or :error" unless [:debug, :info, :warn, :error].include?(@log_level) # SSL/TLS version validation errors << "ssl_min_version must be nil, :TLSv1, :TLSv1_1, :TLSv1_2, or :TLSv1_3" unless VALID_TLS_VERSIONS.include?(@ssl_min_version) errors << "ssl_max_version must be nil, :TLSv1, :TLSv1_1, :TLSv1_2, or :TLSv1_3" unless VALID_TLS_VERSIONS.include?(@ssl_max_version) errors end |