fluent-plugin-sendgrid-event 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -0
- data/fluent-plugin-sendgrid-event.gemspec +1 -1
- data/lib/fluent/plugin/in_sendgrid_event.rb +9 -0
- data/test/plugin/test_in_sendgrid_event.rb +73 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf0161a106e981fff0e2a168fdcd9ffe3b9f1539
|
4
|
+
data.tar.gz: e951591ecda84b5cecdf677f7d0ba898dfaba540
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d2c63a9aa911dda27726741f5dc7928e82b6823de25a35af5781e84e6fce9f18ef40db73b2434da719db9d925116d090a726374b8c4446ae52f20b5bcfe0cd5
|
7
|
+
data.tar.gz: 9f46f7072a4953b8faef451a2c1009a46763bc044e656eae3cc5999edf6d6163e78460de80445ba1e317f2b9ae3313fee114e96583438fcebaa64a883ce2fe1e
|
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.
|
7
|
+
spec.version = "0.0.3"
|
8
8
|
spec.authors = ["Hiroaki Sano"]
|
9
9
|
spec.email = ["hiroaki.sano.9stories@gmail.com"]
|
10
10
|
|
@@ -10,6 +10,8 @@ module Fluent
|
|
10
10
|
config_param :ssl, :bool, :default => false
|
11
11
|
config_param :certificate, :string, :default => nil
|
12
12
|
config_param :private_key, :string, :default => nil
|
13
|
+
config_param :username, :string, :default => nil
|
14
|
+
config_param :password, :string, :default => nil
|
13
15
|
config_param :request_uri, :string, :default => "/"
|
14
16
|
|
15
17
|
unless method_defined?(:log)
|
@@ -59,6 +61,13 @@ module Fluent
|
|
59
61
|
log.error "in_sendgrid_event: couldn't find certificate: '#{@certificate}' or ssl key: '#{@private_key}'"
|
60
62
|
end
|
61
63
|
end
|
64
|
+
if @username && @password
|
65
|
+
listen[:RequestCallback] = lambda do |req, res|
|
66
|
+
WEBrick::HTTPAuth.basic_auth(req, res, "fluent-plugin-sendgrid-event") do |username, password|
|
67
|
+
username == @username && @password
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
62
71
|
|
63
72
|
@server = WEBrick::HTTPServer.new(listen)
|
64
73
|
@server.mount_proc(@request_uri) do |req, res|
|
@@ -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
|
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
|
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
|