Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 43 lines (33 sloc) 1.149 kB
b7fe29e @technoweenie service hook for http posts
technoweenie authored
1 class Service::Web < Service
2 HMAC_DIGEST = OpenSSL::Digest::Digest.new('sha1')
3
4 string :url,
5 # adds a X-Hub-Signature of the body content
6 # X-Hub-Signature: sha1=....
7 :secret,
8
9 # old hooks send form params ?payload=JSON(...)
10 # new hooks should set content_type == 'json'
11 :content_type
12
bb1d927 @technoweenie sometimes web hooks dont have verifiable certs :(
technoweenie authored
13 boolean :insecure_ssl # :(
14
dc69616 @technoweenie web hook accepts all events
technoweenie authored
15 def receive_event
b55413b @technoweenie add test to ensure url params are added to the body
technoweenie authored
16 # set this so that basic auth is added,
17 # and GET params are added to the POST body
18 http.url_prefix = data['url']
d32c584 @technoweenie wtf is this ivar
technoweenie authored
19 http.headers['X-GitHub-Event'] = event.to_s
b55413b @technoweenie add test to ensure url params are added to the body
technoweenie authored
20
bb1d927 @technoweenie sometimes web hooks dont have verifiable certs :(
technoweenie authored
21 if data['insecure_ssl'].to_i == 1
22 http.ssl[:verify] = false
23 end
24
b7fe29e @technoweenie service hook for http posts
technoweenie authored
25 body = if data['content_type'] == 'json'
26 http.headers['content-type'] = 'application/json'
27 JSON.generate(payload)
28 else
29 http.headers['content-type'] = 'application/x-www-form-urlencoded'
30 Faraday::Utils.build_nested_query(
fe077ab @technoweenie test that web service hooks respect basic auth and get params. get p…
technoweenie authored
31 http.params.merge(:payload => JSON.generate(payload)))
b7fe29e @technoweenie service hook for http posts
technoweenie authored
32 end
33
34 if !(secret = data['secret'].to_s).empty?
35 http.headers['X-Hub-Signature'] =
122c8f0 @technoweenie add sha1= prefix to the X-Hub-Signature header
technoweenie authored
36 'sha1='+OpenSSL::HMAC.hexdigest(HMAC_DIGEST, secret, body)
b7fe29e @technoweenie service hook for http posts
technoweenie authored
37 end
38
b4216ad @technoweenie pass the url directly to http_post so trailing slashes are kept
technoweenie authored
39 http_post data['url'], body
b7fe29e @technoweenie service hook for http posts
technoweenie authored
40 end
41 end
42
Something went wrong with that request. Please try again.