Class: Castle::Configuration
- Inherits:
-
Object
- Object
- Castle::Configuration
- Includes:
- Singleton
- Defined in:
- lib/castle/configuration.rb
Overview
manages configuration variables
Constant Summary collapse
- HOST =
'api.castle.io'
- PORT =
443
- URL_PREFIX =
'/v1'
- FAILOVER_STRATEGY =
:allow
- REQUEST_TIMEOUT =
in milliseconds
500
- FAILOVER_STRATEGIES =
%i[allow deny challenge throw].freeze
- TRUSTED_PROXIES =
regexp of trusted proxies which is always appended to the trusted proxy list
[/ \A127\.0\.0\.1\Z| \A(10|172\.(1[6-9]|2[0-9]|30|31)|192\.168)\.| \A::1\Z|\Afd[0-9a-f]{2}:.+| \Alocalhost\Z| \Aunix\Z| \Aunix: /ix].freeze
- DEFAULT_WHITELIST =
Note:
this value is not assigned as we don’t recommend using a whitelist. If you need to use one, this constant is provided as a good default.
%w[ Accept Accept-Charset Accept-Datetime Accept-Encoding Accept-Language Cache-Control Connection Content-Length Content-Type Host Origin Pragma Referer TE Upgrade-Insecure-Requests X-Castle-Client-Id ].freeze
Instance Attribute Summary collapse
-
#api_secret ⇒ Object
Returns the value of attribute api_secret.
-
#blacklisted ⇒ Object
Returns the value of attribute blacklisted.
-
#failover_strategy ⇒ Object
Returns the value of attribute failover_strategy.
-
#host ⇒ Object
Returns the value of attribute host.
-
#ip_headers ⇒ Object
Returns the value of attribute ip_headers.
-
#port ⇒ Object
Returns the value of attribute port.
-
#request_timeout ⇒ Object
Returns the value of attribute request_timeout.
-
#trust_proxy_chain ⇒ Object
Returns the value of attribute trust_proxy_chain.
-
#trusted_proxies ⇒ Object
Returns the value of attribute trusted_proxies.
-
#trusted_proxy_depth ⇒ Object
Returns the value of attribute trusted_proxy_depth.
-
#url_prefix ⇒ Object
Returns the value of attribute url_prefix.
-
#whitelisted ⇒ Object
Returns the value of attribute whitelisted.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #reset ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
51 52 53 54 55 |
# File 'lib/castle/configuration.rb', line 51 def initialize @formatter = Castle::HeadersFormatter @request_timeout = REQUEST_TIMEOUT reset end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(setting, *_args) ⇒ Object (private)
119 120 121 |
# File 'lib/castle/configuration.rb', line 119 def method_missing(setting, *_args) raise Castle::ConfigurationError, "there is no such a config #{setting}" end |
Instance Attribute Details
#api_secret ⇒ Object
Returns the value of attribute api_secret.
48 49 50 |
# File 'lib/castle/configuration.rb', line 48 def api_secret @api_secret end |
#blacklisted ⇒ Object
Returns the value of attribute blacklisted.
48 49 50 |
# File 'lib/castle/configuration.rb', line 48 def blacklisted @blacklisted end |
#failover_strategy ⇒ Object
Returns the value of attribute failover_strategy.
48 49 50 |
# File 'lib/castle/configuration.rb', line 48 def failover_strategy @failover_strategy end |
#host ⇒ Object
Returns the value of attribute host.
47 48 49 |
# File 'lib/castle/configuration.rb', line 47 def host @host end |
#ip_headers ⇒ Object
Returns the value of attribute ip_headers.
48 49 50 |
# File 'lib/castle/configuration.rb', line 48 def ip_headers @ip_headers end |
#port ⇒ Object
Returns the value of attribute port.
47 48 49 |
# File 'lib/castle/configuration.rb', line 47 def port @port end |
#request_timeout ⇒ Object
Returns the value of attribute request_timeout.
47 48 49 |
# File 'lib/castle/configuration.rb', line 47 def request_timeout @request_timeout end |
#trust_proxy_chain ⇒ Object
Returns the value of attribute trust_proxy_chain.
47 48 49 |
# File 'lib/castle/configuration.rb', line 47 def trust_proxy_chain @trust_proxy_chain end |
#trusted_proxies ⇒ Object
Returns the value of attribute trusted_proxies.
48 49 50 |
# File 'lib/castle/configuration.rb', line 48 def trusted_proxies @trusted_proxies end |
#trusted_proxy_depth ⇒ Object
Returns the value of attribute trusted_proxy_depth.
48 49 50 |
# File 'lib/castle/configuration.rb', line 48 def trusted_proxy_depth @trusted_proxy_depth end |
#url_prefix ⇒ Object
Returns the value of attribute url_prefix.
47 48 49 |
# File 'lib/castle/configuration.rb', line 47 def url_prefix @url_prefix end |
#whitelisted ⇒ Object
Returns the value of attribute whitelisted.
48 49 50 |
# File 'lib/castle/configuration.rb', line 48 def whitelisted @whitelisted end |
Instance Method Details
#reset ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/castle/configuration.rb', line 57 def reset self.failover_strategy = FAILOVER_STRATEGY self.host = HOST self.port = PORT self.url_prefix = URL_PREFIX self.whitelisted = [].freeze self.blacklisted = [].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 end |
#valid? ⇒ Boolean
104 105 106 |
# File 'lib/castle/configuration.rb', line 104 def valid? !api_secret.to_s.empty? && !host.to_s.empty? && !port.to_s.empty? end |