Class: EventQ::SignatureProviders::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/eventq_base/signature_providers.rb

Instance Method Summary collapse

Constructor Details

#initializeManager

Returns a new instance of Manager.



9
10
11
12
# File 'lib/eventq_base/signature_providers.rb', line 9

def initialize
  @providers = {}
  @providers[SHA256] = EventQ::SignatureProviders::Sha256SignatureProvider
end

Instance Method Details

#get_provider(provider_type) ⇒ Object

This method is called to get a signature provider



15
16
17
18
19
20
21
# File 'lib/eventq_base/signature_providers.rb', line 15

def get_provider(provider_type)
  provider = @providers[provider_type]
  if provider == nil
    raise "Invalid provider type specified: #{provider_type}"
  end
  return provider.new
end

#validate_signature(message:, queue:) ⇒ Object

This method is called to validate a queue message’s signature



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/eventq_base/signature_providers.rb', line 24

def validate_signature(message:, queue:)
  valid = true

  if queue.require_signature == true && message.signature == nil
    valid = false
  elsif message.signature != nil
    provider = get_provider(EventQ::Configuration.signature_provider)
    valid = provider.valid?(message: message, secret: EventQ::Configuration.signature_secret)
  end

  if !valid
    raise EventQ::Exceptions::InvalidSignatureException.new
  end

  true

end