-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathhook_delivery.rb
More file actions
38 lines (29 loc) · 762 Bytes
/
hook_delivery.rb
File metadata and controls
38 lines (29 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class HookDelivery
include MongoMapper::Document
key :headers, String
key :payload, String
timestamps!
def secrets_match?
return false unless ENV["SECRET_TOKEN"] && headers["X-Hub-Signature"]
signature = "sha1=" + OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("sha1"), ENV["SECRET_TOKEN"], raw_payload)
Rack::Utils.secure_compare(signature, headers["X-Hub-Signature"])
end
def headers
JSON.parse(read_attribute(:headers))
end
def payload
JSON.parse(read_attribute(:payload))
end
def raw_payload
read_attribute(:payload)
end
def pretty_headers
JSON.pretty_generate(headers)
end
def pretty_payload
JSON.pretty_generate(payload)
end
def seconds_ago
(Time.now - created_at).to_i
end
end