fluent-plugin-ses 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 27a12dd8783090a218490d6ee9a0cc7d4cb20f63
4
+ data.tar.gz: cb71e8c0facfad3d8824fe98f2795c8890bf3748
5
+ SHA512:
6
+ metadata.gz: 50221194e43b3c6cc983a56b790c8d2eabdd50663720dcfb194ed32346af015285c738f719bfe21ec1c8eec07816f80efa58c7f3173c6b03070cd22e594f5aae
7
+ data.tar.gz: cb762d3785be4c3da2ffc39afebaa351124272d6e4bdd6805256562c2ce369b8531ba7cb71102587a5bf83208deb0a6ce9f96fe83f7de164513c1bd440e08065
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - 2.0.0
6
+ matrix:
7
+ allow_failures:
8
+ - rvm: 2.0.0
9
+
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-ses.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'rspec'
8
+ gem 'rspec-core'
9
+ gem 'rake'
10
+ end
11
+
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Spring_MT
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,42 @@
1
+ # Fluent::Plugin::SES [![Build Status](https://travis-ci.org/SpringMT/fluent-plugin-ses.png)](https://travis-ci.org/SpringMT/fluent-plugin-ses)
2
+
3
+ Fluent output plugin for AWS SES
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'fluent-plugin-ses'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install fluent-plugin-ses
18
+
19
+ ## Configuration
20
+
21
+ ```
22
+ <source>
23
+ aws_key_id YOUR_AWS_KEY
24
+ aws_sec_key YOUR_AWS_SECRET_KEY
25
+ from from@example.com
26
+ to to@example.com
27
+ cc a@example.com,b@example.com #optional
28
+ reply_to_addresses reply@example.com #optional
29
+ subject test
30
+ </source>
31
+ ```
32
+
33
+ Also see [AWS SDK for Ruby](http://docs.aws.amazon.com/AWSRubySDK/latest/frames.html).
34
+
35
+ ## Contributing
36
+
37
+ 1. Fork it
38
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
39
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
40
+ 4. Push to the branch (`git push origin my-new-feature`)
41
+ 5. Create new Pull Request
42
+
@@ -0,0 +1,12 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ task :default => :test
4
+
5
+ task :test do
6
+ require 'rspec/core'
7
+ require 'rspec/core/rake_task'
8
+ RSpec::Core::RakeTask.new(:test) do |spec|
9
+ spec.pattern = FileList['spec/**/*_spec.rb']
10
+ end
11
+ end
12
+
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "fluent-plugin-ses"
7
+ gem.version = "0.0.1"
8
+ gem.authors = ["Spring_MT"]
9
+ gem.email = ["today.is.sky.blue.sky@gmail.com"]
10
+ gem.summary = %q{Fluent output plugin for AWS SES}
11
+ gem.homepage = "https://github.com/SpringMT/fluent-plugin-ses"
12
+
13
+ gem.rubyforge_project = "fluent-plugin-ses"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_runtime_dependency "fluentd"
21
+ gem.add_runtime_dependency "aws-sdk"
22
+ gem.add_runtime_dependency "fluent-mixin-plaintextformatter", "0.2.0"
23
+ gem.description = <<description
24
+ Fluent output plugin for AWS SES
25
+ description
26
+ end
@@ -0,0 +1,88 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'fluent/mixin/plaintextformatter'
4
+
5
+ module Fluent
6
+ class SESOutput < Fluent::BufferedOutput
7
+ Fluent::Plugin.register_output('ses', self)
8
+
9
+ def initialize
10
+ super
11
+ require 'aws-sdk'
12
+ end
13
+
14
+ include SetTagKeyMixin
15
+ config_set_default :include_tag_key, false
16
+ include SetTimeKeyMixin
17
+ include Fluent::Mixin::PlainTextFormatter
18
+
19
+ config_param :aws_key_id, :string
20
+ config_param :aws_sec_key, :string
21
+
22
+ config_param :from, :string
23
+ config_param :to, :string, :default => ""
24
+ config_param :cc, :string, :default => ""
25
+ config_param :bcc, :string, :default => ""
26
+ config_param :subject, :string, :default => ""
27
+ config_param :reply_to_addresses, :string, :default => ""
28
+
29
+ def start
30
+ super
31
+ options = {}
32
+ if @aws_key_id && @aws_sec_key
33
+ options[:access_key_id] = @aws_key_id
34
+ options[:secret_access_key] = @aws_sec_key
35
+ end
36
+ @ses = AWS::SimpleEmailService.new options
37
+
38
+ to_addresses = @to.split ","
39
+ if to_addresses.empty?
40
+ raise Fluent::ConfigError, "To is not nil."
41
+ end
42
+
43
+ cc_addresses = @cc.split ","
44
+ bcc_addresses = @bcc.split ","
45
+
46
+ @destination = {:to_addresses => to_addresses}
47
+ unless cc_addresses.empty?
48
+ @destination[:cc_addresses] = cc_addresses
49
+ end
50
+ unless bcc_addresses.empty?
51
+ @destination[:bcc_addresses] = bcc_addresses
52
+ end
53
+ valid!
54
+ end
55
+
56
+ def write(chunk)
57
+ body_text = chunk.read
58
+
59
+ options = {
60
+ :source => @from,
61
+ :destination => @destination,
62
+ :message => {
63
+ :subject => { :data => @subject},
64
+ :body => {:text => {:data => body_text}},
65
+ },
66
+ }
67
+ reply_to_addresses = @reply_to_addresses.split ","
68
+ unless reply_to_addresses.empty?
69
+ options[:reply_to_addresses] = reply_to_addresses
70
+ end
71
+
72
+ begin
73
+ res = @ses.client.send_email options
74
+ rescue => e
75
+ $log.error e.message
76
+ end
77
+ end
78
+
79
+ private
80
+ def valid!
81
+ identity = @ses.identities[@from]
82
+ unless identity.verified?
83
+ raise Fluent::ConfigError, "From address is not verified. Please check AWS SES service."
84
+ end
85
+ end
86
+
87
+ end
88
+ end
@@ -0,0 +1,113 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.dirname(__FILE__) + '/spec_helper'
5
+ require 'aws-sdk'
6
+
7
+ DEFAULT_CONFIG = %[
8
+ aws_key_id foo
9
+ aws_sec_key bar
10
+ from spring
11
+ to mt
12
+ subject test
13
+ ]
14
+ INVALID_CONFIG_AWS_KEY_ID_NIL = %[
15
+ aws_sec_key bar
16
+ from spring
17
+ to mt
18
+ subject test
19
+ ]
20
+ INVALID_CONFIG_FROM_NIL = %[
21
+ aws_key_id foo
22
+ aws_sec_key bar
23
+ to mt
24
+ subject test
25
+ ]
26
+ INVALID_CONFIG_TO_BLANK = %[
27
+ aws_key_id foo
28
+ aws_sec_key bar
29
+ from spring
30
+ subject test
31
+ ]
32
+ TEST_CONFIG = %[
33
+ aws_key_id
34
+ aws_sec_key
35
+ from
36
+ to
37
+ cc
38
+ reply_to_addresses
39
+ subject test
40
+ ]
41
+
42
+ def create_driver(conf=DEFAULT_CONFIG)
43
+ Fluent::Test::BufferedOutputTestDriver.new(Fluent::SESOutput).configure(conf)
44
+ end
45
+
46
+ describe Fluent::SESOutput do
47
+ before { Fluent::Test.setup }
48
+ describe :configure do
49
+ before do
50
+ dummy_object = (Class.new { define_method :verified? do; true end }).new
51
+ AWS::SimpleEmailService.any_instance.stub(:identities).and_return({'spring' => dummy_object})
52
+ AWS::SimpleEmailService.any_instance.stub_chain(:client, :send_email).and_return(true)
53
+ end
54
+ context 'valid' do
55
+ it { d = create_driver }
56
+ end
57
+ context 'invalid aws_key_id is nil' do
58
+ it { expect{ d = create_driver INVALID_CONFIG_AWS_KEY_ID_NIL }.to raise_error(Fluent::ConfigError) }
59
+ end
60
+ context 'invalid from is nil' do
61
+ it { expect{ d = create_driver INVALID_CONFIG_FROM_NIL }.to raise_error(Fluent::ConfigError) }
62
+ end
63
+ end
64
+
65
+ describe :start do
66
+ context 'invalid from mail' do
67
+ before do
68
+ dummy_object = (Class.new { define_method :verified? do; false end }).new
69
+ AWS::SimpleEmailService.any_instance.stub(:identities).and_return({'spring' => dummy_object})
70
+ end
71
+ it { expect{ d = create_driver DEFAULT_CONFIG; d.run }.to raise_error(Fluent::ConfigError) }
72
+ end
73
+ context 'invalid to is blank' do
74
+ it { expect{ d = create_driver INVALID_CONFIG_TO_BLANK; d.run }.to raise_error(Fluent::ConfigError) }
75
+ end
76
+ end
77
+
78
+ describe :format do
79
+ context 'valid' do
80
+ before do
81
+ dummy_object = (Class.new { define_method :verified? do; true end }).new
82
+ AWS::SimpleEmailService.any_instance.stub(:identities).and_return({'spring' => dummy_object})
83
+ AWS::SimpleEmailService.any_instance.stub_chain(:client, :send_email).and_return(true)
84
+ end
85
+ it do
86
+ d = create_driver
87
+ time = Time.parse("2013-03-19 00:00:00 UTC").to_i
88
+ d.emit({"a"=>1}, time)
89
+ d.emit({"a"=>2}, time)
90
+ d.expect_format %[2013-03-19T00:00:00Z\ttest\t{"a":1}\n2013-03-19T00:00:00Z\ttest\t{"a":2}\n]
91
+ d.run
92
+ end
93
+ end
94
+ end
95
+
96
+ describe :write do
97
+ context 'test_write' do
98
+ it do
99
+ pending 'If sending email actually, remove pending' do
100
+ d = create_driver TEST_CONFIG
101
+ time = Time.parse("2013-03-19 00:00:00 UTC").to_i
102
+ d.emit({"a"=>1}, time)
103
+ d.emit({"a"=>2}, time)
104
+ d.run
105
+ end
106
+ end
107
+ end
108
+ end
109
+
110
+ end
111
+
112
+
113
+
@@ -0,0 +1,14 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ Bundler.setup(:default, :test)
6
+ Bundler.require(:default, :test)
7
+
8
+ require 'rspec'
9
+ require 'fluent/test'
10
+
11
+ $TESTING=true
12
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
13
+ require 'fluent/plugin/out_ses'
14
+
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-ses
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Spring_MT
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-03-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fluentd
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: aws-sdk
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: fluent-mixin-plaintextformatter
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.2.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.2.0
55
+ description: |
56
+ Fluent output plugin for AWS SES
57
+ email:
58
+ - today.is.sky.blue.sky@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - .travis.yml
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - fluent-plugin-ses.gemspec
70
+ - lib/fluent/plugin/out_ses.rb
71
+ - spec/out_ses_spec.rb
72
+ - spec/spec_helper.rb
73
+ homepage: https://github.com/SpringMT/fluent-plugin-ses
74
+ licenses: []
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project: fluent-plugin-ses
92
+ rubygems_version: 2.0.0
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Fluent output plugin for AWS SES
96
+ test_files:
97
+ - spec/out_ses_spec.rb
98
+ - spec/spec_helper.rb