Class: Hooksmith::Configuration
- Inherits:
-
Object
- Object
- Hooksmith::Configuration
- Defined in:
- lib/hooksmith/configuration.rb
Overview
Configuration holds the registry of all processors, verifiers, and idempotency settings.
The registry uses string keys internally to prevent Symbol DoS attacks when processing untrusted webhook input. Provider and event names from external sources are converted to strings, not symbols.
Instance Attribute Summary collapse
-
#event_store_config ⇒ Hooksmith::Config::EventStore
readonly
Configuration for event persistence.
-
#idempotency_keys ⇒ Hash
readonly
A registry mapping provider strings to idempotency key extractors.
-
#registry ⇒ Hash
readonly
A registry mapping provider strings to arrays of processor entries.
-
#verifiers ⇒ Hash
readonly
A registry mapping provider strings to verifier instances.
Instance Method Summary collapse
-
#event_store {|Hooksmith::Config::EventStore| ... } ⇒ Object
Configure event store persistence.
-
#idempotency_key_for(provider) ⇒ Proc?
Returns the idempotency key extractor for a given provider.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#processors_for(provider, event) ⇒ Array<Hash>
Returns all processor entries for a given provider and event.
-
#provider(provider_name) {|Hooksmith::Config::Provider| ... } ⇒ Object
Groups registrations under a specific provider.
-
#register_processor(provider, event, processor_class_name) ⇒ Object
Direct registration of a processor.
-
#register_verifier(provider, verifier) ⇒ Object
Registers a verifier for a provider directly.
-
#verifier_for(provider) ⇒ Hooksmith::Verifiers::Base?
Returns the verifier for a given provider.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
21 22 23 24 25 26 27 28 |
# File 'lib/hooksmith/configuration.rb', line 21 def initialize # Registry structure: { "provider" => [{ event: "event", processor: "ProcessorClass" }, ...] } # Uses strings to prevent Symbol DoS from untrusted webhook input @registry = Hash.new { |hash, key| hash[key] = [] } @verifiers = {} @idempotency_keys = {} @event_store_config = Hooksmith::Config::EventStore.new end |
Instance Attribute Details
#event_store_config ⇒ Hooksmith::Config::EventStore (readonly)
Returns configuration for event persistence.
19 20 21 |
# File 'lib/hooksmith/configuration.rb', line 19 def event_store_config @event_store_config end |
#idempotency_keys ⇒ Hash (readonly)
Returns a registry mapping provider strings to idempotency key extractors.
17 18 19 |
# File 'lib/hooksmith/configuration.rb', line 17 def idempotency_keys @idempotency_keys end |
#registry ⇒ Hash (readonly)
Returns a registry mapping provider strings to arrays of processor entries.
13 14 15 |
# File 'lib/hooksmith/configuration.rb', line 13 def registry @registry end |
#verifiers ⇒ Hash (readonly)
Returns a registry mapping provider strings to verifier instances.
15 16 17 |
# File 'lib/hooksmith/configuration.rb', line 15 def verifiers @verifiers end |
Instance Method Details
#event_store {|Hooksmith::Config::EventStore| ... } ⇒ Object
Configure event store persistence.
100 101 102 |
# File 'lib/hooksmith/configuration.rb', line 100 def event_store yield(@event_store_config) end |
#idempotency_key_for(provider) ⇒ Proc?
Returns the idempotency key extractor for a given provider.
81 82 83 |
# File 'lib/hooksmith/configuration.rb', line 81 def idempotency_key_for(provider) @idempotency_keys[provider.to_s] end |
#processors_for(provider, event) ⇒ Array<Hash>
Returns all processor entries for a given provider and event.
57 58 59 |
# File 'lib/hooksmith/configuration.rb', line 57 def processors_for(provider, event) registry[provider.to_s].select { |entry| entry[:event] == event.to_s } end |
#provider(provider_name) {|Hooksmith::Config::Provider| ... } ⇒ Object
Groups registrations under a specific provider.
34 35 36 37 38 39 40 41 |
# File 'lib/hooksmith/configuration.rb', line 34 def provider(provider_name) provider_config = Hooksmith::Config::Provider.new(provider_name) yield(provider_config) provider_key = provider_name.to_s registry[provider_key].concat(provider_config.entries) @verifiers[provider_key] = provider_config.verifier if provider_config.verifier @idempotency_keys[provider_key] = provider_config.idempotency_key if provider_config.idempotency_key end |
#register_processor(provider, event, processor_class_name) ⇒ Object
Direct registration of a processor.
48 49 50 |
# File 'lib/hooksmith/configuration.rb', line 48 def register_processor(provider, event, processor_class_name) registry[provider.to_s] << { event: event.to_s, processor: processor_class_name } end |
#register_verifier(provider, verifier) ⇒ Object
Registers a verifier for a provider directly.
73 74 75 |
# File 'lib/hooksmith/configuration.rb', line 73 def register_verifier(provider, verifier) @verifiers[provider.to_s] = verifier end |
#verifier_for(provider) ⇒ Hooksmith::Verifiers::Base?
Returns the verifier for a given provider.
65 66 67 |
# File 'lib/hooksmith/configuration.rb', line 65 def verifier_for(provider) @verifiers[provider.to_s] end |