Class: GotFixed::Receivers::GithubWebhook

Inherits:
Object
  • Object
show all
Defined in:
lib/got_fixed/receivers/github_webhook.rb

Defined Under Namespace

Classes: SignatureError

Constant Summary collapse

HMAC_DIGEST =
OpenSSL::Digest::Digest.new('sha1')

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ GithubWebhook

Returns a new instance of GithubWebhook.



7
8
9
# File 'lib/got_fixed/receivers/github_webhook.rb', line 7

def initialize(options = {})
  @secret = options[:secret]
end

Instance Method Details

#check_hub_signature!(header, body) ⇒ Object



13
14
15
16
17
18
# File 'lib/got_fixed/receivers/github_webhook.rb', line 13

def check_hub_signature!(header, body)
  expected_signature = "sha1=#{OpenSSL::HMAC.hexdigest(HMAC_DIGEST, @secret, body)}"
  if header != expected_signature
    raise SignatureError.new "#{header} != #{expected_signature}"
  end
end