logstash-input-github 2.0.5 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 75b950faaa90a8d69f219585d1b9879954679235
4
- data.tar.gz: b5c3615bbd9107be9b26a51251cbe01f05b6a857
3
+ metadata.gz: a4130cbc51930de60ce2849178e6880c5b5eb7d2
4
+ data.tar.gz: dc658741d0aa06170bf51ab1139730fa65fdcb6b
5
5
  SHA512:
6
- metadata.gz: 881a50ddb33822e7a675d5a59a6280109b9f83f7341fe7b0708d66f291c17919ea6ae31d33706b8d89ec7cfa2c7f4f68e7815d096b9f9eea939d561509394753
7
- data.tar.gz: 40d3dd7cac5edea351dbfa9ee33565953c1d3b287e646d61ac0109c8534a85b65092016e6b3f54599802023c616928049ab811ca28c4546bed076023f1073a0d
6
+ metadata.gz: bac6c5400c17f3530cd1c3cc646968b0c5643ef067f199c29b04f33b90a6ae6f4ef933ee2bb31342ee347a2962ea229dc3c5e5c841c693ef31fa7759d7a4e237
7
+ data.tar.gz: cefd895337b752a05657517b3895b138712284e4e255b907b5bd65c5d9687af40a60805921347d39b726a46f89e2dded711a47fc27e4251b8ef2f4525f6552cf
@@ -1,7 +1,15 @@
1
- # 2.0.5
2
- - Depend on logstash-core-plugin-api instead of logstash-core, removing the need to mass update plugins on major releases of logstash
3
- # 2.0.4
4
- - New dependency requirements for logstash-core for the 5.0 release
1
+ ## 3.0.1
2
+ - Relax constraint on logstash-core-plugin-api to >= 1.60 <= 2.99
3
+
4
+ ## 3.0.0
5
+ - breaking: Updated plugin to use new Java Event APIs
6
+
7
+ ## 2.0.5
8
+ - Depend on logstash-core-plugin-api instead of logstash-core, removing the need to mass update plugins on major releases of logstash
9
+
10
+ ## 2.0.4
11
+ - New dependency requirements for logstash-core for the 5.0 release
12
+
5
13
  ## 2.0.0
6
14
  - Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully,
7
15
  instead of using Thread.raise on the plugins' threads. Ref: https://github.com/elastic/logstash/pull/3895
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012–2015 Elasticsearch <http://www.elastic.co>
1
+ Copyright (c) 2012–2016 Elasticsearch <http://www.elastic.co>
2
2
 
3
3
  Licensed under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License.
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # Logstash Plugin
2
2
 
3
- [![Build
4
- Status](http://build-eu-00.elastic.co/view/LS%20Plugins/view/LS%20Inputs/job/logstash-plugin-input-github-unit/badge/icon)](http://build-eu-00.elastic.co/view/LS%20Plugins/view/LS%20Inputs/job/logstash-plugin-input-github-unit/)
3
+ [![Travis Build Status](https://travis-ci.org/logstash-plugins/logstash-input-github.svg)](https://travis-ci.org/logstash-plugins/logstash-input-github)
5
4
 
6
5
  This is a plugin for [Logstash](https://github.com/elastic/logstash).
7
6
 
@@ -56,7 +55,12 @@ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
56
55
  ```
57
56
  - Install plugin
58
57
  ```sh
58
+ # Logstash 2.3 and higher
59
+ bin/logstash-plugin install --no-verify
60
+
61
+ # Prior to Logstash 2.3
59
62
  bin/plugin install --no-verify
63
+
60
64
  ```
61
65
  - Run Logstash with your plugin
62
66
  ```sh
@@ -74,7 +78,12 @@ gem build logstash-filter-awesome.gemspec
74
78
  ```
75
79
  - Install the plugin from the Logstash home
76
80
  ```sh
77
- bin/plugin install /your/local/plugin/logstash-filter-awesome.gem
81
+ # Logstash 2.3 and higher
82
+ bin/logstash-plugin install --no-verify
83
+
84
+ # Prior to Logstash 2.3
85
+ bin/plugin install --no-verify
86
+
78
87
  ```
79
88
  - Start Logstash and proceed to test the plugin
80
89
 
@@ -17,9 +17,9 @@ class LogStash::Inputs::GitHub < LogStash::Inputs::Base
17
17
  # Your GitHub Secret Token for the webhook
18
18
  config :secret_token, :validate => :string, :required => false
19
19
 
20
- # If Secret is defined, we drop the events that don't match.
21
- # Otherwise, we'll just add a invalid tag
22
- config :drop_invalid, :validate => :boolean
20
+ # If Secret is defined, we drop the events that don't match.
21
+ # Otherwise, we'll just add an invalid tag
22
+ config :drop_invalid, :validate => :boolean, :default => false
23
23
 
24
24
  def register
25
25
  require "ftw"
@@ -29,27 +29,13 @@ class LogStash::Inputs::GitHub < LogStash::Inputs::Base
29
29
  def run(output_queue)
30
30
  @server = FTW::WebServer.new(@ip, @port) do |request, response|
31
31
  body = request.read_body
32
- begin
33
- event = LogStash::Event.new(JSON.parse(body))
34
- rescue JSON::ParserError => e
35
- @logger.info("JSON parse failure. Falling back to plain-text", :error => e, :data => body)
36
- event = LogStash::Event.new("message" => body, "tags" => "_invalidjson")
37
- end
38
- event['headers'] = request.headers.to_hash
39
- if defined? @secret_token and event['headers']['x-hub-signature']
40
- event['hash'] = 'sha1=' + OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), @secret_token, body)
41
- if not Rack::Utils.secure_compare(event['hash'], event['headers']['x-hub-signature'])
42
- if not @drop_invalid
43
- event['tags'] = "_Invalid_Github_Message"
44
- else
45
- @logger.info("Dropping invalid Github message")
46
- drop = true
47
- end
48
- end
49
- end
50
- if not drop
51
- decorate(event)
52
- output_queue << event
32
+ event = build_event_from_request(body, request.headers_.to_hash)
33
+ valid_event = verify_signature(event,body)
34
+ if !valid_event && @drop_invalid
35
+ @logger.info("Dropping invalid Github message")
36
+ else
37
+ decorate(event)
38
+ output_queue << event
53
39
  end
54
40
  response.status = 200
55
41
  response.body = "Accepted!"
@@ -57,6 +43,31 @@ class LogStash::Inputs::GitHub < LogStash::Inputs::Base
57
43
  @server.run
58
44
  end # def run
59
45
 
46
+ def build_event_from_request(body, headers)
47
+ begin
48
+ event = LogStash::Event.new(JSON.parse(body))
49
+ rescue JSON::ParserError => e
50
+ @logger.info("JSON parse failure. Falling back to plain-text", :error => e, :data => body)
51
+ event = LogStash::Event.new("message" => body, "tags" => "_invalidjson")
52
+ end
53
+ event.set('headers', headers)
54
+ return event
55
+ end
56
+
57
+ def verify_signature(event,body)
58
+ is_valid = true
59
+ sign_header = event.get("[headers][x-hub-signature]")
60
+ if @secret_token && sign_header
61
+ hash = 'sha1=' + OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), @secret_token, body)
62
+ event.set("hash", hash)
63
+ if not Rack::Utils.secure_compare(hash, sign_header)
64
+ event.tag("_Invalid_Github_Message")
65
+ is_valid = false
66
+ end
67
+ end
68
+ return is_valid
69
+ end
70
+
60
71
  def close
61
72
  @server.stop
62
73
  end # def close
@@ -1,10 +1,10 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-input-github'
4
- s.version = '2.0.5'
4
+ s.version = '3.0.1'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "Accept events from github webhooks."
7
- s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
7
+ s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
8
8
  s.authors = ["Elastic"]
9
9
  s.email = 'jason.kendall@elastic.co'
10
10
  s.homepage = "http://www.elastic.co/guide/en/logstash/current/index.html"
@@ -20,12 +20,12 @@ Gem::Specification.new do |s|
20
20
  s.metadata = { "logstash_plugin" => "true", "logstash_group" => "input" }
21
21
 
22
22
  # Gem dependencies
23
- s.add_runtime_dependency "logstash-core-plugin-api", "~> 1.0"
23
+ s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
24
24
 
25
25
  s.add_runtime_dependency 'addressable'
26
26
  s.add_runtime_dependency 'logstash-codec-plain'
27
27
  s.add_runtime_dependency 'ftw', '~> 0.0.42'
28
28
 
29
- s.add_development_dependency 'logstash-devutils', '~> 0'
29
+ s.add_development_dependency 'logstash-devutils'
30
30
  end
31
31
 
@@ -0,0 +1,113 @@
1
+ {
2
+ "ref": "0.0.1",
3
+ "ref_type": "tag",
4
+ "master_branch": "master",
5
+ "description": "",
6
+ "pusher_type": "user",
7
+ "repository": {
8
+ "id": 35129377,
9
+ "name": "public-repo",
10
+ "full_name": "baxterthehacker/public-repo",
11
+ "owner": {
12
+ "login": "baxterthehacker",
13
+ "id": 6752317,
14
+ "avatar_url": "https://avatars.githubusercontent.com/u/6752317?v=3",
15
+ "gravatar_id": "",
16
+ "url": "https://api.github.com/users/baxterthehacker",
17
+ "html_url": "https://github.com/baxterthehacker",
18
+ "followers_url": "https://api.github.com/users/baxterthehacker/followers",
19
+ "following_url": "https://api.github.com/users/baxterthehacker/following{/other_user}",
20
+ "gists_url": "https://api.github.com/users/baxterthehacker/gists{/gist_id}",
21
+ "starred_url": "https://api.github.com/users/baxterthehacker/starred{/owner}{/repo}",
22
+ "subscriptions_url": "https://api.github.com/users/baxterthehacker/subscriptions",
23
+ "organizations_url": "https://api.github.com/users/baxterthehacker/orgs",
24
+ "repos_url": "https://api.github.com/users/baxterthehacker/repos",
25
+ "events_url": "https://api.github.com/users/baxterthehacker/events{/privacy}",
26
+ "received_events_url": "https://api.github.com/users/baxterthehacker/received_events",
27
+ "type": "User",
28
+ "site_admin": false
29
+ },
30
+ "private": false,
31
+ "html_url": "https://github.com/baxterthehacker/public-repo",
32
+ "description": "",
33
+ "fork": false,
34
+ "url": "https://api.github.com/repos/baxterthehacker/public-repo",
35
+ "forks_url": "https://api.github.com/repos/baxterthehacker/public-repo/forks",
36
+ "keys_url": "https://api.github.com/repos/baxterthehacker/public-repo/keys{/key_id}",
37
+ "collaborators_url": "https://api.github.com/repos/baxterthehacker/public-repo/collaborators{/collaborator}",
38
+ "teams_url": "https://api.github.com/repos/baxterthehacker/public-repo/teams",
39
+ "hooks_url": "https://api.github.com/repos/baxterthehacker/public-repo/hooks",
40
+ "issue_events_url": "https://api.github.com/repos/baxterthehacker/public-repo/issues/events{/number}",
41
+ "events_url": "https://api.github.com/repos/baxterthehacker/public-repo/events",
42
+ "assignees_url": "https://api.github.com/repos/baxterthehacker/public-repo/assignees{/user}",
43
+ "branches_url": "https://api.github.com/repos/baxterthehacker/public-repo/branches{/branch}",
44
+ "tags_url": "https://api.github.com/repos/baxterthehacker/public-repo/tags",
45
+ "blobs_url": "https://api.github.com/repos/baxterthehacker/public-repo/git/blobs{/sha}",
46
+ "git_tags_url": "https://api.github.com/repos/baxterthehacker/public-repo/git/tags{/sha}",
47
+ "git_refs_url": "https://api.github.com/repos/baxterthehacker/public-repo/git/refs{/sha}",
48
+ "trees_url": "https://api.github.com/repos/baxterthehacker/public-repo/git/trees{/sha}",
49
+ "statuses_url": "https://api.github.com/repos/baxterthehacker/public-repo/statuses/{sha}",
50
+ "languages_url": "https://api.github.com/repos/baxterthehacker/public-repo/languages",
51
+ "stargazers_url": "https://api.github.com/repos/baxterthehacker/public-repo/stargazers",
52
+ "contributors_url": "https://api.github.com/repos/baxterthehacker/public-repo/contributors",
53
+ "subscribers_url": "https://api.github.com/repos/baxterthehacker/public-repo/subscribers",
54
+ "subscription_url": "https://api.github.com/repos/baxterthehacker/public-repo/subscription",
55
+ "commits_url": "https://api.github.com/repos/baxterthehacker/public-repo/commits{/sha}",
56
+ "git_commits_url": "https://api.github.com/repos/baxterthehacker/public-repo/git/commits{/sha}",
57
+ "comments_url": "https://api.github.com/repos/baxterthehacker/public-repo/comments{/number}",
58
+ "issue_comment_url": "https://api.github.com/repos/baxterthehacker/public-repo/issues/comments{/number}",
59
+ "contents_url": "https://api.github.com/repos/baxterthehacker/public-repo/contents/{+path}",
60
+ "compare_url": "https://api.github.com/repos/baxterthehacker/public-repo/compare/{base}...{head}",
61
+ "merges_url": "https://api.github.com/repos/baxterthehacker/public-repo/merges",
62
+ "archive_url": "https://api.github.com/repos/baxterthehacker/public-repo/{archive_format}{/ref}",
63
+ "downloads_url": "https://api.github.com/repos/baxterthehacker/public-repo/downloads",
64
+ "issues_url": "https://api.github.com/repos/baxterthehacker/public-repo/issues{/number}",
65
+ "pulls_url": "https://api.github.com/repos/baxterthehacker/public-repo/pulls{/number}",
66
+ "milestones_url": "https://api.github.com/repos/baxterthehacker/public-repo/milestones{/number}",
67
+ "notifications_url": "https://api.github.com/repos/baxterthehacker/public-repo/notifications{?since,all,participating}",
68
+ "labels_url": "https://api.github.com/repos/baxterthehacker/public-repo/labels{/name}",
69
+ "releases_url": "https://api.github.com/repos/baxterthehacker/public-repo/releases{/id}",
70
+ "created_at": "2015-05-05T23:40:12Z",
71
+ "updated_at": "2015-05-05T23:40:30Z",
72
+ "pushed_at": "2015-05-05T23:40:38Z",
73
+ "git_url": "git://github.com/baxterthehacker/public-repo.git",
74
+ "ssh_url": "git@github.com:baxterthehacker/public-repo.git",
75
+ "clone_url": "https://github.com/baxterthehacker/public-repo.git",
76
+ "svn_url": "https://github.com/baxterthehacker/public-repo",
77
+ "homepage": null,
78
+ "size": 0,
79
+ "stargazers_count": 0,
80
+ "watchers_count": 0,
81
+ "language": null,
82
+ "has_issues": true,
83
+ "has_downloads": true,
84
+ "has_wiki": true,
85
+ "has_pages": true,
86
+ "forks_count": 0,
87
+ "mirror_url": null,
88
+ "open_issues_count": 2,
89
+ "forks": 0,
90
+ "open_issues": 2,
91
+ "watchers": 0,
92
+ "default_branch": "master"
93
+ },
94
+ "sender": {
95
+ "login": "baxterthehacker",
96
+ "id": 6752317,
97
+ "avatar_url": "https://avatars.githubusercontent.com/u/6752317?v=3",
98
+ "gravatar_id": "",
99
+ "url": "https://api.github.com/users/baxterthehacker",
100
+ "html_url": "https://github.com/baxterthehacker",
101
+ "followers_url": "https://api.github.com/users/baxterthehacker/followers",
102
+ "following_url": "https://api.github.com/users/baxterthehacker/following{/other_user}",
103
+ "gists_url": "https://api.github.com/users/baxterthehacker/gists{/gist_id}",
104
+ "starred_url": "https://api.github.com/users/baxterthehacker/starred{/owner}{/repo}",
105
+ "subscriptions_url": "https://api.github.com/users/baxterthehacker/subscriptions",
106
+ "organizations_url": "https://api.github.com/users/baxterthehacker/orgs",
107
+ "repos_url": "https://api.github.com/users/baxterthehacker/repos",
108
+ "events_url": "https://api.github.com/users/baxterthehacker/events{/privacy}",
109
+ "received_events_url": "https://api.github.com/users/baxterthehacker/received_events",
110
+ "type": "User",
111
+ "site_admin": false
112
+ }
113
+ }
@@ -9,4 +9,50 @@ describe LogStash::Inputs::GitHub do
9
9
  it "register without errors" do
10
10
  expect { plugin.register }.to_not raise_error
11
11
  end
12
+
13
+ describe "building Logstash event from webhook" do
14
+ let(:body) {IO.read("spec/fixtures/event_create.json")}
15
+ let(:headers) { {"fake_header" => "fake_value"} }
16
+ let(:event) {plugin.build_event_from_request(body,headers)}
17
+
18
+ it "initialize event from webhook body" do
19
+ JSON.parse(body).each do |k,v|
20
+ expect(event.get(k)).to eq(v)
21
+ end
22
+ end
23
+
24
+ it "copy webhook http headers to event[headers]" do
25
+ expect(event.get('headers')).to eq (headers)
26
+ end
27
+ end
28
+
29
+ describe "verify webhook signature" do
30
+ let(:plugin) { LogStash::Plugin.lookup("input", "github").new( {"port" => 9999, "secret_token" => "my_secret"} ) }
31
+ let(:body) {IO.read("spec/fixtures/event_create.json")}
32
+ let(:headers) { {"x-hub-signature" => "hash"} }
33
+ let(:event) {plugin.build_event_from_request(body,headers)}
34
+ let(:hash) { "sha1=43b113fc453c47f1cd4d5b4ded2985581c00a715" }
35
+
36
+ it "accept event without signature" do
37
+ event.set('headers',{})
38
+ expect(plugin.verify_signature(event,body)).to eq(true)
39
+ expect(event.get("hash")).to be_nil
40
+ expect(event.get("tags")).to be_nil
41
+ end
42
+
43
+ it "reject event with invalid signature" do
44
+ event.set('headers',{"x-hub-signature" => "invalid"})
45
+ expect(plugin.verify_signature(event,body)).to eq(false)
46
+ expect(event.get("hash")).to eq(hash)
47
+ expect(event.get("tags")).to eq(["_Invalid_Github_Message"])
48
+ end
49
+
50
+ it "accept event with valid signature" do
51
+ event.set('headers', {"x-hub-signature" => hash})
52
+ expect(plugin.verify_signature(event,body)).to eq(true)
53
+ expect(event.get("hash")).to eq(hash)
54
+ expect(event.get("tags")).to be_nil
55
+ end
56
+
57
+ end
12
58
  end
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-input-github
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.5
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-24 00:00:00.000000000 Z
11
+ date: 2016-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
- - - "~>"
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '1.60'
19
+ - - "<="
17
20
  - !ruby/object:Gem::Version
18
- version: '1.0'
21
+ version: '2.99'
19
22
  name: logstash-core-plugin-api
20
23
  prerelease: false
21
24
  type: :runtime
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
- version: '1.0'
29
+ version: '1.60'
30
+ - - "<="
31
+ - !ruby/object:Gem::Version
32
+ version: '2.99'
27
33
  - !ruby/object:Gem::Dependency
28
34
  requirement: !ruby/object:Gem::Requirement
29
35
  requirements:
@@ -69,7 +75,7 @@ dependencies:
69
75
  - !ruby/object:Gem::Dependency
70
76
  requirement: !ruby/object:Gem::Requirement
71
77
  requirements:
72
- - - "~>"
78
+ - - ">="
73
79
  - !ruby/object:Gem::Version
74
80
  version: '0'
75
81
  name: logstash-devutils
@@ -77,10 +83,10 @@ dependencies:
77
83
  type: :development
78
84
  version_requirements: !ruby/object:Gem::Requirement
79
85
  requirements:
80
- - - "~>"
86
+ - - ">="
81
87
  - !ruby/object:Gem::Version
82
88
  version: '0'
83
- description: This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program
89
+ description: This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program
84
90
  email: jason.kendall@elastic.co
85
91
  executables: []
86
92
  extensions: []
@@ -95,6 +101,7 @@ files:
95
101
  - README.md
96
102
  - lib/logstash/inputs/github.rb
97
103
  - logstash-input-github.gemspec
104
+ - spec/fixtures/event_create.json
98
105
  - spec/inputs/github_spec.rb
99
106
  homepage: http://www.elastic.co/guide/en/logstash/current/index.html
100
107
  licenses:
@@ -118,9 +125,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
125
  version: '0'
119
126
  requirements: []
120
127
  rubyforge_project:
121
- rubygems_version: 2.4.8
128
+ rubygems_version: 2.6.3
122
129
  signing_key:
123
130
  specification_version: 4
124
131
  summary: Accept events from github webhooks.
125
132
  test_files:
133
+ - spec/fixtures/event_create.json
126
134
  - spec/inputs/github_spec.rb