fluent-plugin-sendgrid-event 0.0.1 → 0.0.6

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: af4ed2dd208e0d2ee36d2a06ff960dd1456cc82d
4
- data.tar.gz: db3a6d8ce63603e354f3248168f8f0214170f1c1
2
+ SHA256:
3
+ metadata.gz: 31ad691ad1105cd978679de781968e92820a0a5a2ef8d79cc7edf23c78cd266a
4
+ data.tar.gz: b3de0e5f08df61b4a74102a6c40db6c2592c281f254115d6c6a7d51231ee5a9c
5
5
  SHA512:
6
- metadata.gz: b9d8efaf4a385570a44231b0a244a21d3aaa94e23637a19acc58e511e365b8d0e5e605345fb3b23a7a01d222fe7e75f3fd4db2357c6c027a039d13f3899b1f09
7
- data.tar.gz: 89a2bb97ba30d6dec52de424e5b80dbf31bdd0a2e11ffa73539389189b48be9250c41834076803bdbec3e06b3dd094ecad909f2f3dc029ddf34020aa47dc813d
6
+ metadata.gz: ddf7b6ce9c69b202b8a4fea06e5d87b3b3f72f8a20ab68e2e9a385425078ca371265ed146f15650b5e34f8a3fd64504f70c826a288254e72246162b98374b2e1
7
+ data.tar.gz: c4c4a519faf25d25749d7670f059faed87c4cae07be3514e70246a431d7809832343172a94c00e8a07224933056e57d2e504baa612abf8652c5b8a375d57c91d
data/README.md CHANGED
@@ -34,6 +34,35 @@ 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
+ ```
51
+ If you would like to use ssl, you can enable as below.
52
+
53
+ ```
54
+ <source>
55
+ type sendgrid_event
56
+ host 127.0.0.1
57
+ port 9191
58
+ tag sendgrid
59
+
60
+ ssl true
61
+ certificate /path/to/certificate.pem
62
+ private_key /path/to/private_key.key
63
+ </source>
64
+ ```
65
+
37
66
  ## Contributing
38
67
 
39
68
  1. Fork it ( http://github.com/hiroakis/fluent-plugin-sendgrid-event/fork )
@@ -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.1"
7
+ spec.version = "0.0.6"
8
8
  spec.authors = ["Hiroaki Sano"]
9
9
  spec.email = ["hiroaki.sano.9stories@gmail.com"]
10
10
 
@@ -1,3 +1,6 @@
1
+ require 'webrick/https'
2
+ require 'fluent/input'
3
+
1
4
  module Fluent
2
5
  class SendGridEventInput < Input
3
6
  Plugin.register_input('sendgrid_event', self)
@@ -5,6 +8,11 @@ module Fluent
5
8
  config_param :tag, :string, :default => nil
6
9
  config_param :host, :string, :default => "0.0.0.0"
7
10
  config_param :port, :integer, :default => 9191
11
+ config_param :ssl, :bool, :default => false
12
+ config_param :certificate, :string, :default => nil
13
+ config_param :private_key, :string, :default => nil
14
+ config_param :username, :string, :default => nil
15
+ config_param :password, :string, :default => nil, :secret => true
8
16
  config_param :request_uri, :string, :default => "/"
9
17
 
10
18
  unless method_defined?(:log)
@@ -45,6 +53,22 @@ module Fluent
45
53
  :BindAddress => @host,
46
54
  :Port => @port
47
55
  }
56
+ if @ssl
57
+ if File.exists?(@certificate) && File.exists?(@private_key)
58
+ listen[:SSLEnable] = @ssl
59
+ listen[:SSLCertificate] = OpenSSL::X509::Certificate.new(open(@certificate).read)
60
+ listen[:SSLPrivateKey] = OpenSSL::PKey::RSA.new(open(@private_key).read)
61
+ else
62
+ log.error "in_sendgrid_event: couldn't find certificate: '#{@certificate}' or ssl key: '#{@private_key}'"
63
+ end
64
+ end
65
+ if @username && @password
66
+ listen[:RequestCallback] = lambda do |req, res|
67
+ WEBrick::HTTPAuth.basic_auth(req, res, "fluent-plugin-sendgrid-event") do |username, password|
68
+ username == @username && password == @password
69
+ end
70
+ end
71
+ end
48
72
 
49
73
  @server = WEBrick::HTTPServer.new(listen)
50
74
  @server.mount_proc(@request_uri) do |req, res|
@@ -39,27 +39,27 @@ class SendGridEventTest < Test::Unit::TestCase
39
39
  def valid_event_json
40
40
  [
41
41
  {
42
- "sg_message_id":"sendgrid_internal_message_id",
43
- "email": "john.doe@sendgrid.com",
44
- "timestamp": 1337197600,
45
- "smtp-id": "<4FB4041F.6080505@sendgrid.com>",
46
- "event": "processed"
42
+ "sg_message_id" => "sendgrid_internal_message_id",
43
+ "email" => "john.doe@sendgrid.com",
44
+ "timestamp" => 1337197600,
45
+ "smtp-id" => "<4FB4041F.6080505@sendgrid.com>",
46
+ "event" => "processed"
47
47
  },
48
48
  {
49
- "sg_message_id":"sendgrid_internal_message_id",
50
- "email": "john.doe@sendgrid.com",
51
- "timestamp": 1337966815,
52
- "category": "newuser",
53
- "event": "click",
54
- "url": "https://sendgrid.com"
49
+ "sg_message_id" => "sendgrid_internal_message_id",
50
+ "email" => "john.doe@sendgrid.com",
51
+ "timestamp" => 1337966815,
52
+ "category" => "newuser",
53
+ "event" => "click",
54
+ "url" => "https://sendgrid.com"
55
55
  },
56
56
  {
57
- "sg_message_id":"sendgrid_internal_message_id",
58
- "email": "john.doe@sendgrid.com",
59
- "timestamp": 1337969592,
60
- "smtp-id": "<20120525181309.C1A9B40405B3@Example-Mac.local>",
61
- "event": "group_unsubscribe",
62
- "asm_group_id": 42
57
+ "sg_message_id" => "sendgrid_internal_message_id",
58
+ "email" => "john.doe@sendgrid.com",
59
+ "timestamp" => 1337969592,
60
+ "smtp-id" => "<20120525181309.C1A9B40405B3@Example-Mac.local>",
61
+ "event" => "group_unsubscribe",
62
+ "asm_group_id" => 42
63
63
  }
64
64
  ].to_json
65
65
  end
@@ -78,6 +78,29 @@ class SendGridEventTest < Test::Unit::TestCase
78
78
  res
79
79
  end
80
80
 
81
+ def send_event_with_https(post_data)
82
+ require 'net/http'
83
+ http = Net::HTTP.new("hiroakis.com", 9191)
84
+ http.use_ssl = true
85
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
86
+ req = Net::HTTP::Post.new('/')
87
+ req.body = post_data
88
+ req["Content-Type"] = "application/json"
89
+ res = http.request(req)
90
+ res
91
+ end
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
+
81
104
  def test_with_valid_event_json
82
105
  d = create_driver %[
83
106
  type sendgrid_event
@@ -86,6 +109,7 @@ class SendGridEventTest < Test::Unit::TestCase
86
109
  tag sendgrid.event
87
110
  ]
88
111
 
112
+ sleep 0.5
89
113
  d.run do
90
114
  res = send_event(valid_event_json)
91
115
  assert_equal("200", res.code)
@@ -131,4 +155,107 @@ class SendGridEventTest < Test::Unit::TestCase
131
155
  end
132
156
  assert_equal(0, d.emits.size)
133
157
  end
158
+
159
+ # def test_https_with_valid_event_json
160
+ # d = create_driver %[
161
+ # type sendgrid_event
162
+ # host 127.0.0.1
163
+ # port 9191
164
+ # ssl true
165
+ # certificate /Users/hiroakis/work/hiroakis.com.pem
166
+ # private_key /Users/hiroakis/work/hiroakis.com.key
167
+ # tag sendgrid.event
168
+ # ]
169
+
170
+ # sleep 0.5
171
+ # d.run do
172
+ # res = send_event_with_https(valid_event_json)
173
+ # assert_equal("200", res.code)
174
+ # end
175
+
176
+ # assert_equal(3, d.emits.size)
177
+
178
+ # assert_equal("sendgrid.event", d.emits[0][0])
179
+ # assert_equal("sendgrid_internal_message_id", d.emits[0][2]["sg_message_id"])
180
+ # assert_equal("john.doe@sendgrid.com", d.emits[0][2]["email"])
181
+ # assert_equal(1337197600, d.emits[0][2]["timestamp"])
182
+ # assert_equal("<4FB4041F.6080505@sendgrid.com>", d.emits[0][2]["smtp-id"])
183
+ # assert_equal("processed", d.emits[0][2]["event"])
184
+
185
+ # assert_equal("sendgrid.event", d.emits[1][0])
186
+ # assert_equal("sendgrid_internal_message_id", d.emits[1][2]["sg_message_id"])
187
+ # assert_equal("john.doe@sendgrid.com", d.emits[1][2]["email"])
188
+ # assert_equal(1337966815, d.emits[1][2]["timestamp"])
189
+ # assert_equal("newuser", d.emits[1][2]["category"])
190
+ # assert_equal("click", d.emits[1][2]["event"])
191
+ # assert_equal("https://sendgrid.com", d.emits[1][2]["url"])
192
+
193
+ # assert_equal("sendgrid.event", d.emits[2][0])
194
+ # assert_equal("sendgrid_internal_message_id", d.emits[2][2]["sg_message_id"])
195
+ # assert_equal("john.doe@sendgrid.com", d.emits[2][2]["email"])
196
+ # assert_equal(1337969592, d.emits[2][2]["timestamp"])
197
+ # assert_equal("<20120525181309.C1A9B40405B3@Example-Mac.local>", d.emits[2][2]["smtp-id"])
198
+ # assert_equal("group_unsubscribe", d.emits[2][2]["event"])
199
+ # assert_equal(42, d.emits[2][2]["asm_group_id"])
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
134
261
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-sendgrid-event
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.6
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-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -100,8 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  - !ruby/object:Gem::Version
101
101
  version: '0'
102
102
  requirements: []
103
- rubyforge_project:
104
- rubygems_version: 2.4.5
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.