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.



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

def allowlist_regexp
  @allowlist_regexp
end

#disabled_key_leniency_error_log_threshold_in_secondsObject

Returns the value of attribute disabled_key_leniency_error_log_threshold_in_seconds.



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

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.



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

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



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

def custom_http_auth_scheme
  @custom_http_auth_scheme.to_s
end

#custom_http_auth_scheme=(new_custom_http_auth_scheme) ⇒ Object



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

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



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

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



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

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.



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

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



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

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



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

def max_cache_size
  @max_cache_size.to_i
end

#max_cache_size=(new_max_cache_size) ⇒ Object



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

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

#max_cache_ttlObject



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

def max_cache_ttl
  @max_cache_ttl.to_i
end

#max_cache_ttl=(new_max_cache_ttl) ⇒ Object



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

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
# 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)
end