Class: Turnstile::Configuration
- Inherits:
-
Object
- Object
- Turnstile::Configuration
- Defined in:
- lib/turnstile/configuration.rb
Overview
This class enables detailed configuration of the turnstile captcha services.
By calling
Turnstile.configuration # => instance of Turnstile::Configuration
or
Turnstile.configure do |config|
config # => instance of Turnstile::Configuration
end
you are able to perform configuration updates.
Your are able to customize all attributes listed below. All values have sensitive default and will very likely not need to be changed.
Please note that the site and secret key for the Turnstile captcha API Access have no useful default value. The keys may be set via the Shell environment or using this configuration. Settings within this configuration always take precedence.
Setting the keys with this Configuration
Turnstile.configure do |config|
config.site_key = '0x4AAAAAAAC1z764FTJAewGm'
config.secret_key = '0x4AAAAAAAC1z_XZkOcOamwjRONkb-xoXMU'
end
Constant Summary collapse
- DEFAULTS =
{ 'server_url' => 'https://challenges.cloudflare.com/turnstile/v0/api.js', 'verify_url' => 'https://challenges.cloudflare.com/turnstile/v0/siteverify', }.freeze
Instance Attribute Summary collapse
- #api_server_url ⇒ Object
-
#default_env ⇒ Object
Returns the value of attribute default_env.
-
#handle_timeouts_gracefully ⇒ Object
Returns the value of attribute handle_timeouts_gracefully.
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#proxy ⇒ Object
Returns the value of attribute proxy.
-
#response_limit ⇒ Object
Returns the value of attribute response_limit.
-
#secret_key ⇒ Object
Returns the value of attribute secret_key.
-
#site_key ⇒ Object
Returns the value of attribute site_key.
-
#skip_verify_env ⇒ Object
Returns the value of attribute skip_verify_env.
- #verify_url ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
:nodoc:.
- #secret_key! ⇒ Object
- #site_key! ⇒ Object
Constructor Details
#initialize ⇒ Configuration
:nodoc:
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/turnstile/configuration.rb', line 42 def initialize # :nodoc: @default_env = ENV['RAILS_ENV'] || ENV['RACK_ENV'] || (Rails.env if defined? Rails.env) @skip_verify_env = %w[test cucumber rspec] @handle_timeouts_gracefully = true @secret_key = ENV['TURNSTILE_SECRET_KEY'] @site_key = ENV['TURNSTILE_SITE_KEY'] @verify_url = ENV['TURNSTILE_VERIFY_URL'] @api_server_url = ENV['TURNSTILE_SERVER_URL'] # Default response token size # https://developers.cloudflare.com/turnstile/frequently-asked-questions/#what-is-the-length-of-a-turnstile-token @response_limit = 2048 end |
Instance Attribute Details
#api_server_url ⇒ Object
66 67 68 |
# File 'lib/turnstile/configuration.rb', line 66 def api_server_url @api_server_url || DEFAULTS.fetch('server_url') end |
#default_env ⇒ Object
Returns the value of attribute default_env.
38 39 40 |
# File 'lib/turnstile/configuration.rb', line 38 def default_env @default_env end |
#handle_timeouts_gracefully ⇒ Object
Returns the value of attribute handle_timeouts_gracefully.
38 39 40 |
# File 'lib/turnstile/configuration.rb', line 38 def handle_timeouts_gracefully @handle_timeouts_gracefully end |
#hostname ⇒ Object
Returns the value of attribute hostname.
38 39 40 |
# File 'lib/turnstile/configuration.rb', line 38 def hostname @hostname end |
#proxy ⇒ Object
Returns the value of attribute proxy.
38 39 40 |
# File 'lib/turnstile/configuration.rb', line 38 def proxy @proxy end |
#response_limit ⇒ Object
Returns the value of attribute response_limit.
38 39 40 |
# File 'lib/turnstile/configuration.rb', line 38 def response_limit @response_limit end |
#secret_key ⇒ Object
Returns the value of attribute secret_key.
38 39 40 |
# File 'lib/turnstile/configuration.rb', line 38 def secret_key @secret_key end |
#site_key ⇒ Object
Returns the value of attribute site_key.
38 39 40 |
# File 'lib/turnstile/configuration.rb', line 38 def site_key @site_key end |
#skip_verify_env ⇒ Object
Returns the value of attribute skip_verify_env.
38 39 40 |
# File 'lib/turnstile/configuration.rb', line 38 def skip_verify_env @skip_verify_env end |
#verify_url ⇒ Object
70 71 72 |
# File 'lib/turnstile/configuration.rb', line 70 def verify_url @verify_url || DEFAULTS.fetch('verify_url') end |
Instance Method Details
#secret_key! ⇒ Object
58 59 60 |
# File 'lib/turnstile/configuration.rb', line 58 def secret_key! secret_key || raise(TurnstileError, "No secret key specified.") end |
#site_key! ⇒ Object
62 63 64 |
# File 'lib/turnstile/configuration.rb', line 62 def site_key! site_key || raise(TurnstileError, "No site key specified.") end |