module TrelloWebhook::Processor
Constants
- HMAC_DIGEST
Public Instance Methods
create()
click to toggle source
# File lib/trello_webhook/processor.rb, line 15 def create if self.respond_to? event self.send event, json_body head(:ok) else fail CallbackNotImplementedError, "#{self.class.name}##{event} not implemented" end end
show()
click to toggle source
# File lib/trello_webhook/processor.rb, line 24 def show if request.head? puts "[TrelloWebhook::Processor] Hook ping received" p request_body head :ok end end
Private Instance Methods
authenticate_trello_request!()
click to toggle source
# File lib/trello_webhook/processor.rb, line 36 def authenticate_trello_request! raise UnspecifiedWebhookSecretError.new unless respond_to?(:webhook_secret) expected = base64digest(base64digest(request_body + request_url)) actual = base64digest(signature_header) if actual != expected raise SignatureError.new "Actual: #{actual}, Expected: #{expected}" end end
base64digest(message)
click to toggle source
# File lib/trello_webhook/processor.rb, line 47 def base64digest(message) hash = OpenSSL::HMAC.digest('sha1', webhook_secret, message) Base64.strict_encode64(hash) end
event()
click to toggle source
# File lib/trello_webhook/processor.rb, line 71 def event @event ||= json_body["action"]["type"].underscore end
json_body()
click to toggle source
# File lib/trello_webhook/processor.rb, line 63 def json_body @json_body ||= ActiveSupport::HashWithIndifferentAccess.new(JSON.load(request_body)) end
request_body()
click to toggle source
# File lib/trello_webhook/processor.rb, line 52 def request_body @request_body ||= ( request.body.rewind request.body.read ) end
request_url()
click to toggle source
# File lib/trello_webhook/processor.rb, line 59 def request_url request.original_url end
signature_header()
click to toggle source
# File lib/trello_webhook/processor.rb, line 67 def signature_header @signature_header ||= request.headers['X-Trello-Webhook'] end