Class: Parse::LiveQuery::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/parse/live_query/configuration.rb

Overview

Centralized configuration for LiveQuery client.

Examples:

Configure LiveQuery

Parse::LiveQuery.configure do |config|
  config.url = "wss://your-server.com"
  config.ping_interval = 20.0
  config.logging_enabled = true
end

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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_insecureBoolean

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.

Returns:

  • (Boolean)

    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_idString

Returns Parse application ID.

Returns:

  • (String)

    Parse application ID



21
22
23
# File 'lib/parse/live_query/configuration.rb', line 21

def application_id
  @application_id
end

#auto_connectBoolean

Returns automatically connect on client creation (default: true).

Returns:

  • (Boolean)

    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_reconnectBoolean

Returns automatically reconnect on disconnect (default: true).

Returns:

  • (Boolean)

    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_strategySymbol

Returns backpressure strategy :block, :drop_oldest, :drop_newest (default: :drop_oldest).

Returns:

  • (Symbol)

    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_thresholdInteger

Circuit breaker settings

Returns:

  • (Integer)

    failures before circuit opens (default: 5)



44
45
46
# File 'lib/parse/live_query/configuration.rb', line 44

def circuit_failure_threshold
  @circuit_failure_threshold
end

#circuit_reset_timeoutFloat

Returns seconds before circuit transitions to half-open (default: 60.0).

Returns:

  • (Float)

    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_keyString

Returns Parse client key.

Returns:

  • (String)

    Parse client key



24
25
26
# File 'lib/parse/live_query/configuration.rb', line 24

def client_key
  @client_key
end

#event_queue_sizeInteger

Event queue settings

Returns:

  • (Integer)

    maximum queued events before backpressure (default: 1000)



64
65
66
# File 'lib/parse/live_query/configuration.rb', line 64

def event_queue_size
  @event_queue_size
end

#frame_read_timeoutInteger

Returns frame read timeout in seconds (default: 30) Prevents indefinite blocking when reading from socket.

Returns:

  • (Integer)

    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_intervalFloat

Reconnection backoff settings

Returns:

  • (Float)

    initial reconnect delay in seconds (default: 1.0)



51
52
53
# File 'lib/parse/live_query/configuration.rb', line 51

def initial_reconnect_interval
  @initial_reconnect_interval
end

#log_levelSymbol

Returns log level :debug, :info, :warn, :error (default: :info).

Returns:

  • (Symbol)

    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

#loggerLogger?

Returns custom logger instance (default: nil, uses STDOUT).

Returns:

  • (Logger, nil)

    custom logger instance (default: nil, uses STDOUT)



124
125
126
# File 'lib/parse/live_query/configuration.rb', line 124

def logger
  @logger
end

#logging_enabledBoolean

Logging settings

Returns:

  • (Boolean)

    enable structured logging (default: false)



118
119
120
# File 'lib/parse/live_query/configuration.rb', line 118

def logging_enabled
  @logging_enabled
end

#master_keyString

Returns Parse master key (optional).

Returns:

  • (String)

    Parse master key (optional)



27
28
29
# File 'lib/parse/live_query/configuration.rb', line 27

def master_key
  @master_key
end

#max_message_sizeInteger

Security settings

Returns:

  • (Integer)

    maximum WebSocket message size in bytes (default: 1MB) Prevents memory exhaustion from malicious oversized frames



72
73
74
# File 'lib/parse/live_query/configuration.rb', line 72

def max_message_size
  @max_message_size
end

#max_reconnect_intervalFloat

Returns maximum reconnect delay in seconds (default: 30.0).

Returns:

  • (Float)

    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_intervalFloat

Health monitoring settings

Returns:

  • (Float)

    seconds between ping frames (default: 30.0)



37
38
39
# File 'lib/parse/live_query/configuration.rb', line 37

def ping_interval
  @ping_interval
end

#pong_timeoutFloat

Returns seconds to wait for pong response (default: 10.0).

Returns:

  • (Float)

    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_jitterFloat

Returns jitter factor for reconnect delay, 0.0-1.0 (default: 0.2).

Returns:

  • (Float)

    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_multiplierFloat

Returns reconnect delay multiplier (default: 1.5).

Returns:

  • (Float)

    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_versionSymbol?

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).

Returns:

  • (Symbol, nil)

    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_versionSymbol?

Returns minimum TLS version :TLSv1, :TLSv1_1, :TLSv1_2, :TLSv1_3 (default: :TLSv1_2) Enforces minimum TLS version for WebSocket connections.

Returns:

  • (Symbol, nil)

    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

#urlString

Connection settings

Returns:

  • (String)

    WebSocket URL for LiveQuery server



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

Parameters:

  • version (Symbol, nil)

    TLS version symbol

Returns:

  • (Integer, nil)

    OpenSSL TLS version constant or nil



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_hHash

Convert to hash

Returns:



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

Returns:

  • (Boolean)


190
191
192
# File 'lib/parse/live_query/configuration.rb', line 190

def valid?
  validate.empty?
end

#validateArray<String>

Validate configuration

Returns:



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