fluent-plugin-webhook-github 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: de9f951a5814c20c8c607c6bee818f7d2c05f199
4
- data.tar.gz: 2096cb5f1e9da7bec2661639c3d4a626aa8cd411
3
+ metadata.gz: 8f47ed6d885acef4b87c753446dc05675296d94f
4
+ data.tar.gz: ea63e9ab346f09b76cc759ca4de90141f3a64e51
5
5
  SHA512:
6
- metadata.gz: 6b985724b8552de1b4e9ea9d17303b165c5d9579dafcd30002b7005e8c7676928e0af7dc5acddd27d929d9b686103565c76e8859c77c7c4ffe228df9d4d70683
7
- data.tar.gz: 44d0fa1289062639b4fe1c69e7b9e50e1a3437eb5ce1fbd4d508f08e6ab540c68a43c740dfa9a4d66740b38f4ba95862333a9ecba72a2c3d68496a650ad2c5fd
6
+ metadata.gz: 300884d7315f5b022ed69151880fed2b275bd795b489d214fc8e424350ce401d0848de2797909927461ad991617393d43be98342708f8bd68fadc2fb1131c5ce
7
+ data.tar.gz: 6805ecddc5520c97c26aa6f624a89cf064999751e5de47f8cb5c0a1bd4277f2f186c7098cb7741ff9711172acb379eb25f3bc898d8f4f1e49bd520841532c60e
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.email = ["k@uu59.org"]
10
10
  spec.summary = %q{fluentd input plugin for receive GitHub webhook}
11
11
  spec.description = %q{fluentd input plugin for receive GitHub webhook}
12
- spec.homepage = ""
12
+ spec.homepage = "https://github.com/uu59/fluent-plugin-webhook-github"
13
13
  spec.license = "MIT"
14
14
 
15
15
  spec.files = `git ls-files -z`.split("\x0")
@@ -40,10 +40,13 @@ module Fluent
40
40
  begin
41
41
  $log.debug req.header
42
42
 
43
- if verify_signature(req)
44
- payload = JSON.parse(req.body || "{}")
43
+ if req.request_method != "POST"
44
+ res.status = 405
45
+ elsif verify_signature(req)
46
+ payload = JSON.parse(req.body)
45
47
  event = req.header["x-github-event"].first
46
- process(event, payload)
48
+ guid = req.header["x-github-delivery"].first
49
+ process(event, payload, guid)
47
50
  res.status = 204
48
51
  else
49
52
  res.status = 401
@@ -59,12 +62,15 @@ module Fluent
59
62
 
60
63
  def verify_signature(req)
61
64
  return true unless @secret
65
+ return false unless req.body
62
66
  sig = 'sha1='+OpenSSL::HMAC.hexdigest(HMAC_DIGEST, @secret, req.body)
63
67
  SecureCompare.compare(sig, req.header["x-hub-signature"].first)
64
68
  end
65
69
 
66
- def process(event, payload)
70
+ def process(event, payload, guid)
67
71
  content = case event
72
+ when nil
73
+ nil
68
74
  when "issue", "issue_comment"
69
75
  {
70
76
  :url => payload["issue"] && payload["issue"]["html_url"],
@@ -93,6 +99,7 @@ module Fluent
93
99
  if content
94
100
  content[:origin] = "github"
95
101
  content[:event] = event
102
+ content[:guid] = guid if guid
96
103
  content[:payload] = payload if @with_payload
97
104
  $log.info "tag: #{@tag.dup}.#{event}, event:#{event}, content:#{content}"
98
105
  Engine.emit("#{@tag.dup}.#{event}", Engine.now, content) if content
@@ -40,6 +40,7 @@ class GithubWebhookInputTest < Test::Unit::TestCase
40
40
  :user => 'Ore',
41
41
  :body => 'Karada',
42
42
  :origin => 'github',
43
+ :guid => 'gggg',
43
44
  }
44
45
 
45
46
  payload = {
@@ -58,7 +59,8 @@ class GithubWebhookInputTest < Test::Unit::TestCase
58
59
  d.run do
59
60
  d.expected_emits.each {|tag, time, record|
60
61
  res = post("/", payload.to_json, {
61
- 'x-github-event' => 'issue',
62
+ 'x-github-event' => 'issue',
63
+ 'x-github-delivery' => 'gggg',
62
64
  })
63
65
  assert_equal "204", res.code
64
66
  }
@@ -81,6 +83,7 @@ class GithubWebhookInputTest < Test::Unit::TestCase
81
83
  :user => nil,
82
84
  :body => nil,
83
85
  :origin => 'github',
86
+ :guid => 'gggg',
84
87
  }
85
88
 
86
89
  d.run do
@@ -88,6 +91,7 @@ class GithubWebhookInputTest < Test::Unit::TestCase
88
91
  res = post("/", '{"hoge":"fuga"}', {
89
92
  'x-github-event' => 'issue',
90
93
  'x-hub-signature' => 'sha1=5ea783ea13c9feef6dbb9c8c805450e2ba1fb0c0',
94
+ 'x-github-delivery' => 'gggg',
91
95
  })
92
96
  assert_equal "204", res.code
93
97
  }
@@ -157,6 +161,15 @@ class GithubWebhookInputTest < Test::Unit::TestCase
157
161
  end
158
162
  end
159
163
 
164
+ def test_405
165
+ create_driver.run do
166
+ http = Net::HTTP.new("127.0.0.1", PORT)
167
+ req = Net::HTTP::Get.new('/')
168
+ res = http.request(req)
169
+
170
+ assert_equal "405", res.code
171
+ end
172
+ end
160
173
 
161
174
  def post(path, params, header = {})
162
175
  http = Net::HTTP.new("127.0.0.1", PORT)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-webhook-github
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - uu59
@@ -83,7 +83,7 @@ files:
83
83
  - lib/fluent/plugin/in_webhook_github.rb
84
84
  - test/helper.rb
85
85
  - test/plugin/test_in_webhook_github.rb
86
- homepage: ''
86
+ homepage: https://github.com/uu59/fluent-plugin-webhook-github
87
87
  licenses:
88
88
  - MIT
89
89
  metadata: {}