Class: ShopCircle::Orbit::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/shopcircle/orbit/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/shopcircle/orbit/configuration.rb', line 24

def initialize
  @client_id       = nil
  @client_secret   = nil
  @api_url         = nil
  @device_id       = nil
  @flush_interval  = 2
  @max_batch_size  = 10
  @max_queue_size  = 1_000
  @max_retries     = 3
  @base_retry_delay = 1
  @request_timeout = 10
  @logger          = nil
  @stub            = false
  @on_error        = nil
  @redact_pii      = true
  @exclude_paths   = []
end

Instance Attribute Details

#api_urlObject

Returns the value of attribute api_url.



8
9
10
# File 'lib/shopcircle/orbit/configuration.rb', line 8

def api_url
  @api_url
end

#base_retry_delayObject

Returns the value of attribute base_retry_delay.



8
9
10
# File 'lib/shopcircle/orbit/configuration.rb', line 8

def base_retry_delay
  @base_retry_delay
end

#client_idObject

Returns the value of attribute client_id.



8
9
10
# File 'lib/shopcircle/orbit/configuration.rb', line 8

def client_id
  @client_id
end

#client_secretObject

Returns the value of attribute client_secret.



8
9
10
# File 'lib/shopcircle/orbit/configuration.rb', line 8

def client_secret
  @client_secret
end

#device_idObject

Returns the value of attribute device_id.



8
9
10
# File 'lib/shopcircle/orbit/configuration.rb', line 8

def device_id
  @device_id
end

#exclude_pathsObject

Returns the value of attribute exclude_paths.



8
9
10
# File 'lib/shopcircle/orbit/configuration.rb', line 8

def exclude_paths
  @exclude_paths
end

#flush_intervalObject

Returns the value of attribute flush_interval.



8
9
10
# File 'lib/shopcircle/orbit/configuration.rb', line 8

def flush_interval
  @flush_interval
end

#loggerObject

Returns the value of attribute logger.



8
9
10
# File 'lib/shopcircle/orbit/configuration.rb', line 8

def logger
  @logger
end

#max_batch_sizeObject

Returns the value of attribute max_batch_size.



8
9
10
# File 'lib/shopcircle/orbit/configuration.rb', line 8

def max_batch_size
  @max_batch_size
end

#max_queue_sizeObject

Returns the value of attribute max_queue_size.



8
9
10
# File 'lib/shopcircle/orbit/configuration.rb', line 8

def max_queue_size
  @max_queue_size
end

#max_retriesObject

Returns the value of attribute max_retries.



8
9
10
# File 'lib/shopcircle/orbit/configuration.rb', line 8

def max_retries
  @max_retries
end

#on_errorObject

Returns the value of attribute on_error.



8
9
10
# File 'lib/shopcircle/orbit/configuration.rb', line 8

def on_error
  @on_error
end

#redact_piiObject

Returns the value of attribute redact_pii.



8
9
10
# File 'lib/shopcircle/orbit/configuration.rb', line 8

def redact_pii
  @redact_pii
end

#request_timeoutObject

Returns the value of attribute request_timeout.



8
9
10
# File 'lib/shopcircle/orbit/configuration.rb', line 8

def request_timeout
  @request_timeout
end

#stubObject

Returns the value of attribute stub.



8
9
10
# File 'lib/shopcircle/orbit/configuration.rb', line 8

def stub
  @stub
end

Instance Method Details

#inspectObject

Redact sensitive fields from inspect output to prevent accidental credential leakage in logs/debugging.



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/shopcircle/orbit/configuration.rb', line 69

def inspect
  redacted = instance_variables.each_with_object({}) do |var, hash|
    val = instance_variable_get(var)
    hash[var] = if var == :@client_secret && val
                  "[REDACTED]"
                else
                  val
                end
  end
  "#<#{self.class} #{redacted.map { |k, v| "#{k}=#{v.inspect}" }.join(', ')}>"
end

#resolved_loggerObject



63
64
65
# File 'lib/shopcircle/orbit/configuration.rb', line 63

def resolved_logger
  @logger || default_logger
end

#validate!Object

Raises:



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/shopcircle/orbit/configuration.rb', line 42

def validate!
  raise ConfigurationError, "client_id is required" if @client_id.nil? || @client_id.to_s.empty?
  raise ConfigurationError, "api_url is required" if @api_url.nil? || @api_url.to_s.empty?
  raise ConfigurationError, "device_id max 128 chars" if @device_id && @device_id.to_s.length > 128

  validate_positive!(:flush_interval, @flush_interval)
  validate_positive!(:max_batch_size, @max_batch_size)
  validate_positive!(:max_queue_size, @max_queue_size)
  validate_positive!(:request_timeout, @request_timeout)
  validate_positive!(:base_retry_delay, @base_retry_delay)
  raise ConfigurationError, "max_retries must be >= 0" if !@max_retries.is_a?(Numeric) || @max_retries < 0

  uri = URI.parse(@api_url.to_s)
  unless uri.scheme == "https" || ENV["ORBIT_ALLOW_HTTP"] == "1"
    raise ConfigurationError, "api_url must use https:// in production. Set ORBIT_ALLOW_HTTP=1 for local development."
  end
  if uri.scheme != "https"
    resolved_logger.warn("[shopcircle-orbit] WARNING: Sending data over plaintext HTTP. Do not use in production.")
  end
end