Class: ApiKeys::Configuration
- Inherits:
-
Object
- Object
- ApiKeys::Configuration
- Defined in:
- lib/api_keys/configuration.rb
Overview
Defines the configuration options for the ApiKeys gem. These options can be set in an initializer, e.g., config/initializers/api_keys.rb
Constant Summary collapse
- DEFAULT_CALLBACK =
Default empty callback proc
->(_context){}.freeze
- DEFAULT_PARENT_CONTROLLER =
"::ApplicationController"- VALID_HASH_STRATEGIES =
%i[sha256 bcrypt].freeze
- VALID_TOKEN_ALPHABETS =
%i[base58 hex].freeze
- TOKEN_LENGTH_RANGE =
(16..64)
- MAX_CONFIGURED_SCOPES =
100- CONFIG_NAME_PATTERN =
/\A[a-zA-Z0-9_-]{1,64}\z/- HTTP_HEADER_PATTERN =
/\A[!#$%&'*+\-.^_`|~0-9A-Za-z]{1,128}\z/- QUERY_PARAM_PATTERN =
/\A[a-zA-Z0-9_.~-]{1,128}\z/- METHOD_NAME_PATTERN =
/\A[a-zA-Z_]\w*[!?]?\z/- CONSTANT_NAME_PATTERN =
/\A(?:::)?[A-Z]\w*(?:::[A-Z]\w*)*\z/- BOOLEAN_SETTINGS =
%i[ require_key_name track_requests_count https_only_production https_strict_mode enable_async_operations debug_logging strict_environment_isolation dashboard_allow_cross_environment ].freeze
Instance Attribute Summary collapse
-
#after_authentication ⇒ Object
Callbacks (Placeholders for future extension).
-
#authenticate_owner_method ⇒ Object
Owner Context Configuration.
-
#before_authentication ⇒ Object
Callbacks (Placeholders for future extension).
-
#cache_ttl ⇒ Object
Performance.
-
#callbacks_job_queue ⇒ Object
Background Job Queues.
-
#current_environment ⇒ Proc, Symbol
Lambda or symbol returning current environment.
-
#current_owner_method ⇒ Object
Owner Context Configuration.
-
#dashboard_allow_cross_environment ⇒ Object
Key Types & Environments (Stripe-style publishable/secret keys).
-
#debug_logging ⇒ Object
readonly
Debugging.
-
#default_key_type ⇒ Symbol?
Default key type when not specified in create_api_key!.
-
#default_max_keys_per_owner ⇒ Object
Optional Behaviors.
-
#default_scopes ⇒ Object
Returns the value of attribute default_scopes.
-
#enable_async_operations ⇒ Object
readonly
Global Async Toggle.
-
#environments ⇒ Hash
Environment definitions.
-
#expire_after ⇒ Object
Returns the value of attribute expire_after.
-
#hash_strategy ⇒ Object
Storage & Verification.
-
#header ⇒ Object
Core Authentication.
-
#https_only_production ⇒ Object
readonly
Security.
-
#https_strict_mode ⇒ Object
readonly
Security.
-
#key_store_adapter ⇒ Object
Returns the value of attribute key_store_adapter.
-
#key_types ⇒ Object
Custom writer for key_types that validates prefix uniqueness.
-
#parent_controller ⇒ Object
Engine Configuration.
-
#policy_provider ⇒ Object
Returns the value of attribute policy_provider.
-
#query_param ⇒ Object
Core Authentication.
-
#require_key_name ⇒ Object
readonly
Optional Behaviors.
-
#return_text ⇒ Object
Engine UI Configuration.
-
#return_url ⇒ Object
Engine UI Configuration.
-
#secure_compare_proc ⇒ Object
Returns the value of attribute secure_compare_proc.
-
#stats_job_queue ⇒ Object
Background Job Queues.
-
#stats_update_interval ⇒ Object
Performance.
-
#strict_environment_isolation ⇒ Boolean
If true, keys only work in their matching environment.
-
#tenant_resolver ⇒ Object
Tenant Resolution.
-
#token_alphabet ⇒ Object
Token Generation.
-
#token_length ⇒ Object
Token Generation.
-
#token_prefix ⇒ Object
Token Generation.
-
#track_requests_count ⇒ Object
readonly
Returns the value of attribute track_requests_count.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
Initialization ==.
- #parent_controller_class ⇒ Object
- #resolved_token_prefix ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Initialization ==
477 478 479 |
# File 'lib/api_keys/configuration.rb', line 477 def initialize set_defaults end |
Instance Attribute Details
#after_authentication ⇒ Object
Callbacks (Placeholders for future extension)
48 49 50 |
# File 'lib/api_keys/configuration.rb', line 48 def after_authentication @after_authentication end |
#authenticate_owner_method ⇒ Object
Owner Context Configuration
32 33 34 |
# File 'lib/api_keys/configuration.rb', line 32 def authenticate_owner_method @authenticate_owner_method end |
#before_authentication ⇒ Object
Callbacks (Placeholders for future extension)
48 49 50 |
# File 'lib/api_keys/configuration.rb', line 48 def before_authentication @before_authentication end |
#cache_ttl ⇒ Object
Performance
39 40 41 |
# File 'lib/api_keys/configuration.rb', line 39 def cache_ttl @cache_ttl end |
#callbacks_job_queue ⇒ Object
Background Job Queues
51 52 53 |
# File 'lib/api_keys/configuration.rb', line 51 def callbacks_job_queue @callbacks_job_queue end |
#current_environment ⇒ Proc, Symbol
Returns Lambda or symbol returning current environment.
103 104 |
# File 'lib/api_keys/configuration.rb', line 103 attr_reader :environments, :current_environment, :strict_environment_isolation, :default_key_type, :dashboard_allow_cross_environment |
#current_owner_method ⇒ Object
Owner Context Configuration
32 33 34 |
# File 'lib/api_keys/configuration.rb', line 32 def current_owner_method @current_owner_method end |
#dashboard_allow_cross_environment ⇒ Object
Key Types & Environments (Stripe-style publishable/secret keys)
103 104 |
# File 'lib/api_keys/configuration.rb', line 103 attr_reader :environments, :current_environment, :strict_environment_isolation, :default_key_type, :dashboard_allow_cross_environment |
#debug_logging ⇒ Object (readonly)
Debugging
60 61 62 |
# File 'lib/api_keys/configuration.rb', line 60 def debug_logging @debug_logging end |
#default_key_type ⇒ Symbol?
Returns Default key type when not specified in create_api_key!.
103 104 |
# File 'lib/api_keys/configuration.rb', line 103 attr_reader :environments, :current_environment, :strict_environment_isolation, :default_key_type, :dashboard_allow_cross_environment |
#default_max_keys_per_owner ⇒ Object
Optional Behaviors
35 36 37 |
# File 'lib/api_keys/configuration.rb', line 35 def default_max_keys_per_owner @default_max_keys_per_owner end |
#default_scopes ⇒ Object
Returns the value of attribute default_scopes.
36 37 38 |
# File 'lib/api_keys/configuration.rb', line 36 def default_scopes @default_scopes end |
#enable_async_operations ⇒ Object (readonly)
Global Async Toggle
54 55 56 |
# File 'lib/api_keys/configuration.rb', line 54 def enable_async_operations @enable_async_operations end |
#environments ⇒ Hash
Returns Environment definitions. Each environment has:
- :prefix_segment [String, nil] Middle part of prefix (e.g., "test" → pk_test_).
103 104 105 |
# File 'lib/api_keys/configuration.rb', line 103 def environments @environments end |
#expire_after ⇒ Object
Returns the value of attribute expire_after.
36 37 38 |
# File 'lib/api_keys/configuration.rb', line 36 def expire_after @expire_after end |
#hash_strategy ⇒ Object
Storage & Verification
24 25 26 |
# File 'lib/api_keys/configuration.rb', line 24 def hash_strategy @hash_strategy end |
#header ⇒ Object
Core Authentication
18 19 20 |
# File 'lib/api_keys/configuration.rb', line 18 def header @header end |
#https_only_production ⇒ Object (readonly)
Security
42 43 44 |
# File 'lib/api_keys/configuration.rb', line 42 def https_only_production @https_only_production end |
#https_strict_mode ⇒ Object (readonly)
Security
42 43 44 |
# File 'lib/api_keys/configuration.rb', line 42 def https_strict_mode @https_strict_mode end |
#key_store_adapter ⇒ Object
Returns the value of attribute key_store_adapter.
26 27 28 |
# File 'lib/api_keys/configuration.rb', line 26 def key_store_adapter @key_store_adapter end |
#key_types ⇒ Object
Custom writer for key_types that validates prefix uniqueness
103 104 |
# File 'lib/api_keys/configuration.rb', line 103 attr_reader :environments, :current_environment, :strict_environment_isolation, :default_key_type, :dashboard_allow_cross_environment |
#parent_controller ⇒ Object
Engine Configuration
29 30 31 |
# File 'lib/api_keys/configuration.rb', line 29 def parent_controller @parent_controller end |
#policy_provider ⇒ Object
Returns the value of attribute policy_provider.
26 27 28 |
# File 'lib/api_keys/configuration.rb', line 26 def policy_provider @policy_provider end |
#query_param ⇒ Object
Core Authentication
18 19 20 |
# File 'lib/api_keys/configuration.rb', line 18 def query_param @query_param end |
#require_key_name ⇒ Object (readonly)
Optional Behaviors
35 36 37 |
# File 'lib/api_keys/configuration.rb', line 35 def require_key_name @require_key_name end |
#return_text ⇒ Object
Engine UI Configuration
57 58 59 |
# File 'lib/api_keys/configuration.rb', line 57 def return_text @return_text end |
#return_url ⇒ Object
Engine UI Configuration
57 58 59 |
# File 'lib/api_keys/configuration.rb', line 57 def return_url @return_url end |
#secure_compare_proc ⇒ Object
Returns the value of attribute secure_compare_proc.
25 26 27 |
# File 'lib/api_keys/configuration.rb', line 25 def secure_compare_proc @secure_compare_proc end |
#stats_job_queue ⇒ Object
Background Job Queues
51 52 53 |
# File 'lib/api_keys/configuration.rb', line 51 def stats_job_queue @stats_job_queue end |
#stats_update_interval ⇒ Object
Performance
39 40 41 |
# File 'lib/api_keys/configuration.rb', line 39 def stats_update_interval @stats_update_interval end |
#strict_environment_isolation ⇒ Boolean
Returns If true, keys only work in their matching environment.
103 104 |
# File 'lib/api_keys/configuration.rb', line 103 attr_reader :environments, :current_environment, :strict_environment_isolation, :default_key_type, :dashboard_allow_cross_environment |
#tenant_resolver ⇒ Object
Tenant Resolution
45 46 47 |
# File 'lib/api_keys/configuration.rb', line 45 def tenant_resolver @tenant_resolver end |
#token_alphabet ⇒ Object
Token Generation
21 22 23 |
# File 'lib/api_keys/configuration.rb', line 21 def token_alphabet @token_alphabet end |
#token_length ⇒ Object
Token Generation
21 22 23 |
# File 'lib/api_keys/configuration.rb', line 21 def token_length @token_length end |
#token_prefix ⇒ Object
Token Generation
21 22 23 |
# File 'lib/api_keys/configuration.rb', line 21 def token_prefix @token_prefix end |
#track_requests_count ⇒ Object (readonly)
Returns the value of attribute track_requests_count.
36 37 38 |
# File 'lib/api_keys/configuration.rb', line 36 def track_requests_count @track_requests_count end |
Instance Method Details
#parent_controller_class ⇒ Object
194 195 196 197 198 199 200 201 202 |
# File 'lib/api_keys/configuration.rb', line 194 def parent_controller_class candidate = if !@parent_controller_explicitly_configured && defined?(ApiKeys::Engine) && ApiKeys::Engine.config.parent_controller.present? ApiKeys::Engine.config.parent_controller else parent_controller end candidate.is_a?(Class) ? candidate : candidate.constantize end |
#resolved_token_prefix ⇒ Object
275 276 277 278 279 |
# File 'lib/api_keys/configuration.rb', line 275 def resolved_token_prefix value = @token_prefix.respond_to?(:call) ? @token_prefix.call : @token_prefix validate_resolved_prefix!(value) value end |