class Castle::Configuration
manages configuration variables
Constants
- BASE_URL
API
endpoint- DEFAULT_ALLOWLIST
@note this value is not assigned as we don’t recommend using a allowlist. If you need to use
one, this constant is provided as a good default.
- REQUEST_TIMEOUT
- TRUSTED_PROXIES
regexp of trusted proxies which is always appended to the trusted proxy list
Attributes
allowlisted[R]
api_secret[R]
base_url[R]
denylisted[R]
failover_strategy[R]
ip_headers[R]
logger[RW]
request_timeout[RW]
trust_proxy_chain[RW]
trusted_proxies[R]
trusted_proxy_depth[R]
Public Class Methods
new()
click to toggle source
# File lib/castle/configuration.rb, line 61 def initialize @header_format = Castle::Headers::Format @request_timeout = REQUEST_TIMEOUT reset end
Public Instance Methods
allowlisted=(value)
click to toggle source
# File lib/castle/configuration.rb, line 88 def allowlisted=(value) @allowlisted = (value ? value.map { |header| @header_format.call(header) } : []).freeze end
api_secret=(value)
click to toggle source
# File lib/castle/configuration.rb, line 84 def api_secret=(value) @api_secret = value.to_s end
base_url=(value)
click to toggle source
# File lib/castle/configuration.rb, line 80 def base_url=(value) @base_url = URI(value) end
denylisted=(value)
click to toggle source
# File lib/castle/configuration.rb, line 92 def denylisted=(value) @denylisted = (value ? value.map { |header| @header_format.call(header) } : []).freeze end
failover_strategy=(value)
click to toggle source
# File lib/castle/configuration.rb, line 121 def failover_strategy=(value) @failover_strategy = Castle::Failover::STRATEGIES.detect { |strategy| strategy == value.to_sym } raise Castle::ConfigurationError, 'unrecognized failover strategy' if @failover_strategy.nil? end
ip_headers=(value)
click to toggle source
sets ip headers @param value [Array<String>]
# File lib/castle/configuration.rb, line 98 def ip_headers=(value) raise Castle::ConfigurationError, 'ip headers must be an Array' unless value.is_a?(Array) @ip_headers = value.map { |header| @header_format.call(header) }.freeze end
reset()
click to toggle source
# File lib/castle/configuration.rb, line 67 def reset self.failover_strategy = Castle::Failover::Strategy::ALLOW self.base_url = BASE_URL self.allowlisted = [].freeze self.denylisted = [].freeze self.api_secret = ENV.fetch('CASTLE_API_SECRET', '') self.ip_headers = [].freeze self.trusted_proxies = [].freeze self.trust_proxy_chain = false self.trusted_proxy_depth = nil self.logger = nil end
trusted_proxies=(value)
click to toggle source
sets trusted proxies @param value [Array<String,Regexp>]
# File lib/castle/configuration.rb, line 106 def trusted_proxies=(value) raise Castle::ConfigurationError, 'trusted proxies must be an Array' unless value.is_a?(Array) @trusted_proxies = value end
trusted_proxy_depth=(value)
click to toggle source
@param value [String,Number,NilClass]
# File lib/castle/configuration.rb, line 113 def trusted_proxy_depth=(value) @trusted_proxy_depth = value.to_i end
valid?()
click to toggle source
# File lib/castle/configuration.rb, line 117 def valid? !api_secret.to_s.empty? && !base_url.host.to_s.empty? && !base_url.port.to_s.empty? end
Private Instance Methods
method_missing(setting, *_args)
click to toggle source
# File lib/castle/configuration.rb, line 132 def method_missing(setting, *_args) raise Castle::ConfigurationError, "there is no such a config #{setting}" end
respond_to_missing?(method_name, _include_private)
click to toggle source
# File lib/castle/configuration.rb, line 128 def respond_to_missing?(method_name, _include_private) /^(\w+)=$/ =~ method_name end