fluent-plugin-sendgrid-event 0.0.2 → 0.0.7

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
- SHA1:
3
- metadata.gz: 2ffe235b5621c727bcfa07587de682d13f2ebf1d
4
- data.tar.gz: b79173a1dc1c3134351ef4ec494de4c693e9b751
2
+ SHA256:
3
+ metadata.gz: ae9ff6af54ee32569deff026cb44dd5d0447a80e53abb73cd5d27ef412ef8689
4
+ data.tar.gz: 8b6f5fcd6821062c6207502954a270aaf7eb88841f62f6590469dd51bf848dab
5
5
  SHA512:
6
- metadata.gz: b4e2e92312512a50bfd916057c6bc7cf2b90b4485659051e5210ebc7a6da2f7d51c487218fa80a6c46502c97b97445057dc8e9350a1d68f19445350ae2d3eceb
7
- data.tar.gz: 04034943a93378947169bd27a4b5ecca4c90e5c835233ba4f32f24cdb3de6379a495fb420568370a026d509f87d16d74678c7a3918fbc2def87f8671b653fd4d
6
+ metadata.gz: 50b447df513ae16442f3ce186a2e8fb1e126d1274e072e144f77259def74df76346545fe966bbc8c3b7cf929607487345569b8734e52baceea45d6cde0d4f1c4
7
+ data.tar.gz: d5c2e5b6382a6b575d940a8275184e7a07b45dbb92ab86a77cb1d8cfff9550975d98559731dcb23dccc2bc73f0ee1351a63cbfe981dbbb1db8c25b7e2367ed8d
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  .ruby-version
11
+ /vendor/bundle
data/README.md CHANGED
@@ -34,6 +34,20 @@ The following is an example of configuration.
34
34
  </source>
35
35
  ```
36
36
 
37
+ You can use basic authentication.
38
+
39
+ ```
40
+ <source>
41
+ type sendgrid_event
42
+ host 127.0.0.1
43
+ port 9191
44
+ tag sendgrid
45
+
46
+ username auth_username
47
+ password auth_password
48
+ </source>
49
+
50
+ ```
37
51
  If you would like to use ssl, you can enable as below.
38
52
 
39
53
  ```
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "fluent-plugin-sendgrid-event"
7
- spec.version = "0.0.2"
7
+ spec.version = "0.0.7"
8
8
  spec.authors = ["Hiroaki Sano"]
9
9
  spec.email = ["hiroaki.sano.9stories@gmail.com"]
10
10
 
@@ -1,4 +1,5 @@
1
1
  require 'webrick/https'
2
+ require 'fluent/input'
2
3
 
3
4
  module Fluent
4
5
  class SendGridEventInput < Input
@@ -10,11 +11,17 @@ module Fluent
10
11
  config_param :ssl, :bool, :default => false
11
12
  config_param :certificate, :string, :default => nil
12
13
  config_param :private_key, :string, :default => nil
14
+ config_param :username, :string, :default => nil
15
+ config_param :password, :string, :default => nil, :secret => true
13
16
  config_param :request_uri, :string, :default => "/"
14
17
 
15
18
  unless method_defined?(:log)
16
19
  define_method("log") { $log }
17
20
  end
21
+
22
+ unless method_defined?(:router)
23
+ define_method("router") { Fluent::Engine }
24
+ end
18
25
 
19
26
  def initialize
20
27
  super
@@ -59,6 +66,13 @@ module Fluent
59
66
  log.error "in_sendgrid_event: couldn't find certificate: '#{@certificate}' or ssl key: '#{@private_key}'"
60
67
  end
61
68
  end
69
+ if @username && @password
70
+ listen[:RequestCallback] = lambda do |req, res|
71
+ WEBrick::HTTPAuth.basic_auth(req, res, "fluent-plugin-sendgrid-event") do |username, password|
72
+ username == @username && password == @password
73
+ end
74
+ end
75
+ end
62
76
 
63
77
  @server = WEBrick::HTTPServer.new(listen)
64
78
  @server.mount_proc(@request_uri) do |req, res|
@@ -91,7 +105,7 @@ module Fluent
91
105
 
92
106
  def emit_event(event)
93
107
  log.trace "in_sendgrid_event: emit_event"
94
- Engine.emit("#{tag}", Engine.now, event)
108
+ router.emit("#{tag}", Fluent::EventTime.now, event)
95
109
  end
96
110
  end
97
111
  end
@@ -90,6 +90,17 @@ class SendGridEventTest < Test::Unit::TestCase
90
90
  res
91
91
  end
92
92
 
93
+ def send_event_with_auth(post_data, username, password)
94
+ require 'net/http'
95
+ http = Net::HTTP.new("127.0.0.1", 9191)
96
+ req = Net::HTTP::Post.new('/')
97
+ req.basic_auth(username, password)
98
+ req.body = post_data
99
+ req["Content-Type"] = "application/json"
100
+ res = http.request(req)
101
+ res
102
+ end
103
+
93
104
  def test_with_valid_event_json
94
105
  d = create_driver %[
95
106
  type sendgrid_event
@@ -98,7 +109,7 @@ class SendGridEventTest < Test::Unit::TestCase
98
109
  tag sendgrid.event
99
110
  ]
100
111
 
101
- sleep 1
112
+ sleep 0.5
102
113
  d.run do
103
114
  res = send_event(valid_event_json)
104
115
  assert_equal("200", res.code)
@@ -156,7 +167,7 @@ class SendGridEventTest < Test::Unit::TestCase
156
167
  # tag sendgrid.event
157
168
  # ]
158
169
 
159
- # sleep 1
170
+ # sleep 0.5
160
171
  # d.run do
161
172
  # res = send_event_with_https(valid_event_json)
162
173
  # assert_equal("200", res.code)
@@ -187,4 +198,64 @@ class SendGridEventTest < Test::Unit::TestCase
187
198
  # assert_equal("group_unsubscribe", d.emits[2][2]["event"])
188
199
  # assert_equal(42, d.emits[2][2]["asm_group_id"])
189
200
  # end
201
+
202
+ def test_basic_auth
203
+ d = create_driver %[
204
+ type sendgrid_event
205
+ host 127.0.0.1
206
+ port 9191
207
+ tag sendgrid.event
208
+ username auth_user
209
+ password auth_pass
210
+ ]
211
+
212
+ sleep 0.5
213
+ d.run do
214
+ res = send_event_with_auth(valid_event_json, "auth_user", "auth_pass")
215
+ assert_equal("200", res.code)
216
+ end
217
+
218
+ assert_equal(3, d.emits.size)
219
+
220
+ assert_equal("sendgrid.event", d.emits[0][0])
221
+ assert_equal("sendgrid_internal_message_id", d.emits[0][2]["sg_message_id"])
222
+ assert_equal("john.doe@sendgrid.com", d.emits[0][2]["email"])
223
+ assert_equal(1337197600, d.emits[0][2]["timestamp"])
224
+ assert_equal("<4FB4041F.6080505@sendgrid.com>", d.emits[0][2]["smtp-id"])
225
+ assert_equal("processed", d.emits[0][2]["event"])
226
+
227
+ assert_equal("sendgrid.event", d.emits[1][0])
228
+ assert_equal("sendgrid_internal_message_id", d.emits[1][2]["sg_message_id"])
229
+ assert_equal("john.doe@sendgrid.com", d.emits[1][2]["email"])
230
+ assert_equal(1337966815, d.emits[1][2]["timestamp"])
231
+ assert_equal("newuser", d.emits[1][2]["category"])
232
+ assert_equal("click", d.emits[1][2]["event"])
233
+ assert_equal("https://sendgrid.com", d.emits[1][2]["url"])
234
+
235
+ assert_equal("sendgrid.event", d.emits[2][0])
236
+ assert_equal("sendgrid_internal_message_id", d.emits[2][2]["sg_message_id"])
237
+ assert_equal("john.doe@sendgrid.com", d.emits[2][2]["email"])
238
+ assert_equal(1337969592, d.emits[2][2]["timestamp"])
239
+ assert_equal("<20120525181309.C1A9B40405B3@Example-Mac.local>", d.emits[2][2]["smtp-id"])
240
+ assert_equal("group_unsubscribe", d.emits[2][2]["event"])
241
+ assert_equal(42, d.emits[2][2]["asm_group_id"])
242
+ end
243
+
244
+ def test_basic_auth_with_invalid_user
245
+ d = create_driver %[
246
+ type sendgrid_event
247
+ host 127.0.0.1
248
+ port 9191
249
+ tag sendgrid.event
250
+ username auth_user
251
+ password auth_pass
252
+ ]
253
+
254
+ sleep 0.5
255
+ d.run do
256
+ res = send_event_with_auth(valid_event_json, "xxxxxx", "xxxxx")
257
+ assert_equal("401", res.code)
258
+ end
259
+ assert_equal(0, d.emits.size)
260
+ end
190
261
  end
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-sendgrid-event
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroaki Sano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-14 00:00:00.000000000 Z
11
+ date: 2020-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.10'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.10'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: test-unit
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: fluentd
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  description:
@@ -73,7 +73,7 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
- - .gitignore
76
+ - ".gitignore"
77
77
  - Gemfile
78
78
  - README.md
79
79
  - Rakefile
@@ -91,17 +91,16 @@ require_paths:
91
91
  - lib
92
92
  required_ruby_version: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  requirements:
99
- - - '>='
99
+ - - ">="
100
100
  - !ruby/object:Gem::Version
101
101
  version: '0'
102
102
  requirements: []
103
- rubyforge_project:
104
- rubygems_version: 2.0.14
103
+ rubygems_version: 3.0.3
105
104
  signing_key:
106
105
  specification_version: 4
107
106
  summary: Fluent input plugin to receive sendgrid event.