Class: Stitches::Configuration

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

Defined Under Namespace

Classes: NonNullInteger, NonNullString, UnsetString

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



6
7
8
# File 'lib/stitches/configuration.rb', line 6

def initialize
  reset_to_defaults!
end

Instance Attribute Details

#allowlist_regexpObject

A RegExp that allows URLS around the mime type and api key requirements. nil means that ever request must have a proper mime type and api key.



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

def allowlist_regexp
  @allowlist_regexp
end

#disable_api_key_supportObject

Returns the value of attribute disable_api_key_support.



23
24
25
# File 'lib/stitches/configuration.rb', line 23

def disable_api_key_support
  @disable_api_key_support
end

#disabled_key_leniency_error_log_threshold_in_secondsObject

Returns the value of attribute disabled_key_leniency_error_log_threshold_in_seconds.



23
24
25
# File 'lib/stitches/configuration.rb', line 23

def disabled_key_leniency_error_log_threshold_in_seconds
  @disabled_key_leniency_error_log_threshold_in_seconds
end

#disabled_key_leniency_in_secondsObject

Returns the value of attribute disabled_key_leniency_in_seconds.



23
24
25
# File 'lib/stitches/configuration.rb', line 23

def disabled_key_leniency_in_seconds
  @disabled_key_leniency_in_seconds
end

Instance Method Details

#custom_http_auth_schemeObject

The name of your custom http auth scheme. This must be set, and has no default



36
37
38
# File 'lib/stitches/configuration.rb', line 36

def custom_http_auth_scheme
  @custom_http_auth_scheme.to_s
end

#custom_http_auth_scheme=(new_custom_http_auth_scheme) ⇒ Object



40
41
42
# File 'lib/stitches/configuration.rb', line 40

def custom_http_auth_scheme=(new_custom_http_auth_scheme)
  @custom_http_auth_scheme = NonNullString.new("custom_http_auth_scheme",new_custom_http_auth_scheme)
end

#env_var_to_hold_api_clientObject



56
57
58
# File 'lib/stitches/configuration.rb', line 56

def env_var_to_hold_api_client
  @env_var_to_hold_api_client.to_s
end

#env_var_to_hold_api_client=(new_env_var_to_hold_api_client) ⇒ Object



60
61
62
# File 'lib/stitches/configuration.rb', line 60

def env_var_to_hold_api_client=(new_env_var_to_hold_api_client)
  @env_var_to_hold_api_client= NonNullString.new("env_var_to_hold_api_client",new_env_var_to_hold_api_client)
end

#env_var_to_hold_api_client_primary_keyObject

The name of the environment variable that the ApiKey middleware should use to place the primary key of the authenticated ApiKey. For example, if a user provides the api key 1234-1234-1234-1234, and that maps to the primary key 42 in your database, the environment will contain “42” in the key provided here.



48
49
50
# File 'lib/stitches/configuration.rb', line 48

def env_var_to_hold_api_client_primary_key
  @env_var_to_hold_api_client_primary_key.to_s
end

#env_var_to_hold_api_client_primary_key=(new_env_var_to_hold_api_client_primary_key) ⇒ Object



52
53
54
# File 'lib/stitches/configuration.rb', line 52

def env_var_to_hold_api_client_primary_key=(new_env_var_to_hold_api_client_primary_key)
  @env_var_to_hold_api_client_primary_key = NonNullString.new("env_var_to_hold_api_client_primary_key",new_env_var_to_hold_api_client_primary_key)
end

#max_cache_sizeObject



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

def max_cache_size
  @max_cache_size.to_i
end

#max_cache_size=(new_max_cache_size) ⇒ Object



76
77
78
# File 'lib/stitches/configuration.rb', line 76

def max_cache_size=(new_max_cache_size)
  @max_cache_size = NonNullInteger.new("max_cache_size", new_max_cache_size)
end

#max_cache_ttlObject



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

def max_cache_ttl
  @max_cache_ttl.to_i
end

#max_cache_ttl=(new_max_cache_ttl) ⇒ Object



68
69
70
# File 'lib/stitches/configuration.rb', line 68

def max_cache_ttl=(new_max_cache_ttl)
  @max_cache_ttl = NonNullInteger.new("max_cache_ttl", new_max_cache_ttl)
end

#reset_to_defaults!Object

Mainly for testing, this resets all configuration to the default value



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/stitches/configuration.rb', line 11

def reset_to_defaults!
  @allowlist_regexp = nil
  @custom_http_auth_scheme = UnsetString.new("custom_http_auth_scheme")
  @env_var_to_hold_api_client_primary_key = NonNullString.new("env_var_to_hold_api_client_primary_key","STITCHES_API_CLIENT_ID")
  @env_var_to_hold_api_client= NonNullString.new("env_var_to_hold_api_client","STITCHES_API_CLIENT")
  @max_cache_ttl = NonNullInteger.new("max_cache_ttl", 0)
  @max_cache_size = NonNullInteger.new("max_cache_size", 0)
  @disabled_key_leniency_in_seconds = ActiveSupport::Duration.days(3)
  @disabled_key_leniency_error_log_threshold_in_seconds = ActiveSupport::Duration.days(2)
  @disable_api_key_support = false
end