fluent-plugin-convert-value-to-sha 0.1.0
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 +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +37 -0
- data/Rakefile +10 -0
- data/fluent-plugin-convert-value-to-sha.gemspec +24 -0
- data/lib/fluent/plugin/out_convert_to_sha.rb +60 -0
- data/test/helper.rb +12 -0
- data/test/test_out_convert_to_sha.rb +115 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ef33d0ffe37de08a5d0986f718011aa1867b8712
|
4
|
+
data.tar.gz: bf22d0c4fa594554d52e98870c12e450323c87c0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f6a3995812eecedcbec1c3ac48881b970b8a2d5449cffda7b16cfba67c776e32d00b0a2a7ee4e5d842cbcdcfb2f2d1c591bd40203837801988ac34b71753186a
|
7
|
+
data.tar.gz: a1e190ac272cd388cfe066b84bd1d11e476ad1039d04c0b8606cd63ed7e4f07bd3bcf952f706b64a8d69c4f53fdf223591624467e5f596059ba4a21a0bdeebab
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Aiming Inc.
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Fluent::Plugin::Convert::Value::To::Sha
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'fluent-plugin-convert-value-to-sha'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install fluent-plugin-convert-value-to-sha
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
30
|
+
|
31
|
+
## Copyright
|
32
|
+
|
33
|
+
Copyright (c) 2013 Aiming Inc.
|
34
|
+
|
35
|
+
## License
|
36
|
+
|
37
|
+
MIT.
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: 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 |spec|
|
6
|
+
spec.name = "fluent-plugin-convert-value-to-sha"
|
7
|
+
spec.version = "0.1.0"
|
8
|
+
spec.authors = ["Keiji Matsuzaki"]
|
9
|
+
spec.email = ["futoase@gmail.com"]
|
10
|
+
spec.description = %q{This plugin is convert value to sha.}
|
11
|
+
spec.summary = %q{fluentd convert value to sha plugin.}
|
12
|
+
spec.homepage = ""
|
13
|
+
spec.license = "Apache License v2.0"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
|
23
|
+
spec.add_dependency "fluentd"
|
24
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
#
|
3
|
+
|
4
|
+
require 'digest/sha2'
|
5
|
+
|
6
|
+
DIGEST = {
|
7
|
+
"256" => Digest::SHA256,
|
8
|
+
"384" => Digest::SHA384,
|
9
|
+
"512" => Digest::SHA512
|
10
|
+
}
|
11
|
+
|
12
|
+
class Fluent::ConvertToSha < Fluent::Output
|
13
|
+
Fluent::Plugin.register_output('convert_to_sha', self)
|
14
|
+
|
15
|
+
config_param :sha, :string, :default => '256'
|
16
|
+
config_param :salt, :string, :default => 'mako'
|
17
|
+
config_param :key, :string, :default => nil
|
18
|
+
|
19
|
+
def configure(conf)
|
20
|
+
super
|
21
|
+
|
22
|
+
if @salt.strip.length == 0
|
23
|
+
raise Fluent::ConfigError, "require salt"
|
24
|
+
end
|
25
|
+
|
26
|
+
if @sha.to_s == '1'
|
27
|
+
raise Fluent::ConfigError, "sha1 algorithm is vulnerable."
|
28
|
+
end
|
29
|
+
|
30
|
+
if @key.nil?
|
31
|
+
raise Fluent::ConfigError, "require key name."
|
32
|
+
end
|
33
|
+
|
34
|
+
@mutex = Mutex.new
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
def start
|
39
|
+
super
|
40
|
+
end
|
41
|
+
|
42
|
+
def shutdown
|
43
|
+
super
|
44
|
+
end
|
45
|
+
|
46
|
+
def emit(tag, es, chain)
|
47
|
+
es.each do |time, record|
|
48
|
+
Fluent::Engine.emit(tag, time, convert_to_sha(record))
|
49
|
+
end
|
50
|
+
|
51
|
+
chain.next
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
def convert_to_sha(record)
|
56
|
+
record[@key] = DIGEST[@sha].hexdigest(@salt + record[@key].to_s)
|
57
|
+
return record
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
|
3
|
+
Bundler.setup(:default, :test)
|
4
|
+
Bundler.require(:default, :test)
|
5
|
+
|
6
|
+
require 'fluent/test'
|
7
|
+
require 'test/unit'
|
8
|
+
|
9
|
+
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
10
|
+
$:.unshift(File.dirname(__FILE__))
|
11
|
+
|
12
|
+
require 'fluent/plugin/out_convert_to_sha'
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
class ConvertToShaTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
Fluent::Test.setup
|
7
|
+
end
|
8
|
+
|
9
|
+
CONFIG_256 = %[
|
10
|
+
sha 256
|
11
|
+
salt hoge
|
12
|
+
key uid
|
13
|
+
]
|
14
|
+
|
15
|
+
CONFIG_384 = %[
|
16
|
+
sha 384
|
17
|
+
salt hoge
|
18
|
+
key uid
|
19
|
+
]
|
20
|
+
|
21
|
+
CONFIG_512 = %[
|
22
|
+
sha 512
|
23
|
+
salt hoge
|
24
|
+
key uid
|
25
|
+
]
|
26
|
+
|
27
|
+
def create_driver(conf = CONFIG, tag = 'test')
|
28
|
+
Fluent::Test::OutputTestDriver.new(Fluent::ConvertToSha, tag).configure(conf)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_convert_to_sha256
|
32
|
+
d1 = create_driver(CONFIG_256, 'mako.mankanshoku')
|
33
|
+
|
34
|
+
d1.run do
|
35
|
+
d1.emit({"uid" => "10000", "nick" => "satsuki"})
|
36
|
+
d1.emit({"uid" => "12345", "nick" => "senketsu"})
|
37
|
+
d1.emit({"uid" => "33333", "nick" => "gamagori"})
|
38
|
+
end
|
39
|
+
|
40
|
+
emits = d1.emits
|
41
|
+
|
42
|
+
# uid is 10000
|
43
|
+
p emits[0]
|
44
|
+
assert_equal "mako.mankanshoku", emits[0][0]
|
45
|
+
assert_equal Digest::SHA256.hexdigest("hoge10000"), emits[0][2]["uid"]
|
46
|
+
|
47
|
+
# uid is 12345
|
48
|
+
p emits[1]
|
49
|
+
assert_equal "mako.mankanshoku", emits[1][0]
|
50
|
+
assert_equal Digest::SHA256.hexdigest("hoge12345"), emits[1][2]["uid"]
|
51
|
+
|
52
|
+
# uid is 33333
|
53
|
+
p emits[2]
|
54
|
+
assert_equal "mako.mankanshoku", emits[2][0]
|
55
|
+
assert_equal Digest::SHA256.hexdigest("hoge33333"), emits[2][2]["uid"]
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_convert_to_sha384
|
60
|
+
d1 = create_driver(CONFIG_384, 'mako.mankanshoku')
|
61
|
+
|
62
|
+
d1.run do
|
63
|
+
d1.emit({"uid" => "10000", "nick" => "satsuki"})
|
64
|
+
d1.emit({"uid" => "12345", "nick" => "senketsu"})
|
65
|
+
d1.emit({"uid" => "33333", "nick" => "gamagori"})
|
66
|
+
end
|
67
|
+
|
68
|
+
emits = d1.emits
|
69
|
+
|
70
|
+
# uid is 10000
|
71
|
+
p emits[0]
|
72
|
+
assert_equal "mako.mankanshoku", emits[0][0]
|
73
|
+
assert_equal Digest::SHA384.hexdigest("hoge10000"), emits[0][2]["uid"]
|
74
|
+
|
75
|
+
# uid is 12345
|
76
|
+
p emits[1]
|
77
|
+
assert_equal "mako.mankanshoku", emits[1][0]
|
78
|
+
assert_equal Digest::SHA384.hexdigest("hoge12345"), emits[1][2]["uid"]
|
79
|
+
|
80
|
+
# uid is 33333
|
81
|
+
p emits[2]
|
82
|
+
assert_equal "mako.mankanshoku", emits[2][0]
|
83
|
+
assert_equal Digest::SHA384.hexdigest("hoge33333"), emits[2][2]["uid"]
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_convert_to_sha512
|
88
|
+
d1 = create_driver(CONFIG_512, 'mako.mankanshoku')
|
89
|
+
|
90
|
+
d1.run do
|
91
|
+
d1.emit({"uid" => "10000", "nick" => "satsuki"})
|
92
|
+
d1.emit({"uid" => "12345", "nick" => "senketsu"})
|
93
|
+
d1.emit({"uid" => "33333", "nick" => "gamagori"})
|
94
|
+
end
|
95
|
+
|
96
|
+
emits = d1.emits
|
97
|
+
|
98
|
+
# uid is 10000
|
99
|
+
p emits[0]
|
100
|
+
assert_equal "mako.mankanshoku", emits[0][0]
|
101
|
+
assert_equal Digest::SHA512.hexdigest("hoge10000"), emits[0][2]["uid"]
|
102
|
+
|
103
|
+
# uid is 12345
|
104
|
+
p emits[1]
|
105
|
+
assert_equal "mako.mankanshoku", emits[1][0]
|
106
|
+
assert_equal Digest::SHA512.hexdigest("hoge12345"), emits[1][2]["uid"]
|
107
|
+
|
108
|
+
# uid is 33333
|
109
|
+
p emits[2]
|
110
|
+
assert_equal "mako.mankanshoku", emits[2][0]
|
111
|
+
assert_equal Digest::SHA512.hexdigest("hoge33333"), emits[2][2]["uid"]
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-convert-value-to-sha
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Keiji Matsuzaki
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
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: fluentd
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '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'
|
55
|
+
description: This plugin is convert value to sha.
|
56
|
+
email:
|
57
|
+
- futoase@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- fluent-plugin-convert-value-to-sha.gemspec
|
68
|
+
- lib/fluent/plugin/out_convert_to_sha.rb
|
69
|
+
- test/helper.rb
|
70
|
+
- test/test_out_convert_to_sha.rb
|
71
|
+
homepage: ''
|
72
|
+
licenses:
|
73
|
+
- Apache License v2.0
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.0.3
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: fluentd convert value to sha plugin.
|
95
|
+
test_files:
|
96
|
+
- test/helper.rb
|
97
|
+
- test/test_out_convert_to_sha.rb
|