fluent-plugin-redaction 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +57 -0
- data/.travis.yml +13 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/Makefile +13 -0
- data/README.md +31 -0
- data/Rakefile +14 -0
- data/VERSION +1 -0
- data/fluent-plugin-redaction.gemspec +23 -0
- data/lib/fluent/plugin/filter_redaction.rb +68 -0
- data/test/helper.rb +8 -0
- data/test/plugin/test_filter_redaction.rb +57 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3e4231227b1e13f09203ea14b382bc7291a0deb1
|
4
|
+
data.tar.gz: edfca6249b080274c4aa6b577938c75a38a4a5e6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7e476f6f06ee54bbdb503176cd84963185042d5ef27b201bfae62ba8c66bae877b0555ebcd44c74a072f25498680a80e4caf35e45d0e5813757edbf229515132
|
7
|
+
data.tar.gz: 23f7daf93b3887c49098914b10cbabf2a2f580968bd172d1517cd05427920dd19c14e963ce8a37907190c934bed012529e2e985240e57f266f2781174b3dd581
|
data/.gitignore
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
# Ignore Byebug command history file.
|
17
|
+
.byebug_history
|
18
|
+
|
19
|
+
## Specific to RubyMotion:
|
20
|
+
.dat*
|
21
|
+
.repl_history
|
22
|
+
build/
|
23
|
+
*.bridgesupport
|
24
|
+
build-iPhoneOS/
|
25
|
+
build-iPhoneSimulator/
|
26
|
+
|
27
|
+
## Specific to RubyMotion (use of CocoaPods):
|
28
|
+
#
|
29
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
30
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
31
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
32
|
+
#
|
33
|
+
# vendor/Pods/
|
34
|
+
|
35
|
+
## Documentation cache and generated files:
|
36
|
+
/.yardoc/
|
37
|
+
/_yardoc/
|
38
|
+
/doc/
|
39
|
+
/rdoc/
|
40
|
+
|
41
|
+
## Environment normalization:
|
42
|
+
/.bundle/
|
43
|
+
/vendor/bundle
|
44
|
+
/lib/bundler/man/
|
45
|
+
|
46
|
+
# for a library or gem, you might want to ignore these files since the code is
|
47
|
+
# intended to run in multiple environments; otherwise, check them in:
|
48
|
+
# Gemfile.lock
|
49
|
+
# .ruby-version
|
50
|
+
# .ruby-gemset
|
51
|
+
|
52
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
53
|
+
.rvmrc
|
54
|
+
|
55
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
56
|
+
# .rubocop-https?--*
|
57
|
+
Gemfile.lock
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020 Olivér Sz,
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/Makefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
gem:
|
2
|
+
rm -f fluent-plugin-redaction*.gem
|
3
|
+
gem build fluent-plugin-redaction.gemspec
|
4
|
+
|
5
|
+
install: gem
|
6
|
+
gem install fluent-plugin-redaction*.gem
|
7
|
+
|
8
|
+
push: gem
|
9
|
+
gem push fluent-plugin-redaction*.gem
|
10
|
+
|
11
|
+
tag:
|
12
|
+
git tag "v$$(cat VERSION)" $(RELEASE_COMMIT)
|
13
|
+
git push origin "v$$(cat VERSION)"
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Fluentd Filter Redaction Plugin
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/oleewere/fluent-plugin-redaction.svg?branch=master)](https://travis-ci.org/oleewere/fluent-plugin-redaction)
|
4
|
+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/fluent-plugin-redaction.svg)](http://badge.fury.io/rb/fluent-plugin-redaction)
|
6
|
+
![](https://ruby-gem-downloads-badge.herokuapp.com/fluent-plugin-redaction?type=total&metric=true)
|
7
|
+
|
8
|
+
## Requirements
|
9
|
+
|
10
|
+
| fluent-plugin-redaction | fluentd | ruby |
|
11
|
+
|------------------------|---------|------|
|
12
|
+
| >= 0.1.0 | >= v0.14.0 | >= 2.4 |
|
13
|
+
|
14
|
+
## Overview
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
Install from RubyGems:
|
19
|
+
```
|
20
|
+
$ gem install fluent-plugin-redaction
|
21
|
+
```
|
22
|
+
|
23
|
+
## Configuration
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
require 'bundler'
|
3
|
+
Bundler::GemHelper.install_tasks
|
4
|
+
|
5
|
+
require 'rake/testtask'
|
6
|
+
|
7
|
+
Rake::TestTask.new(:test) do |test|
|
8
|
+
test.libs << 'lib' << 'test'
|
9
|
+
test.test_files = FileList['test/plugin/test_*.rb']
|
10
|
+
test.verbose = true
|
11
|
+
end
|
12
|
+
|
13
|
+
task :default => [:build]
|
14
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = "fluent-plugin-redaction"
|
6
|
+
gem.description = "Fluentd redaction filter plugin for anonymize specific strings in text data."
|
7
|
+
gem.license = "MIT License"
|
8
|
+
gem.homepage = "https://github.com/oleewere/fluent-plugin-redaction"
|
9
|
+
gem.summary = gem.description
|
10
|
+
gem.version = File.read("VERSION").strip
|
11
|
+
gem.authors = ["Oliver Szabo"]
|
12
|
+
gem.email = ["oleewere@gmail.com"]
|
13
|
+
#gem.platform = Gem::Platform::RUBY
|
14
|
+
gem.files = `git ls-files`.split("\n")
|
15
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map {|f| File.basename(f)}
|
17
|
+
gem.require_paths = ['lib']
|
18
|
+
|
19
|
+
gem.add_runtime_dependency 'fluentd', ['>= 1.0', '< 2']
|
20
|
+
gem.add_development_dependency "rake", ["~> 11.0"]
|
21
|
+
gem.add_development_dependency 'test-unit', '~> 3.3', '>= 3.3.3'
|
22
|
+
gem.add_development_dependency 'test-unit-rr', '~> 1.0', '>= 1.0.5'
|
23
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Fluent
|
4
|
+
module Plugin
|
5
|
+
class RedactionFilter < Fluent::Plugin::Filter
|
6
|
+
Fluent::Plugin.register_filter("redaction", self)
|
7
|
+
|
8
|
+
helpers :record_accessor
|
9
|
+
|
10
|
+
config_section :rule, param_name: :rule_config_list, required: true, multi: true do
|
11
|
+
config_param :key, :string, default: nil
|
12
|
+
config_param :value, :string, default: nil
|
13
|
+
config_param :pattern, :regexp, default: nil
|
14
|
+
config_param :replacement, :string, default: "[REDACTED]"
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
@pattern_rules_map = {}
|
19
|
+
@accessors = {}
|
20
|
+
super
|
21
|
+
end
|
22
|
+
|
23
|
+
def configure(conf)
|
24
|
+
super
|
25
|
+
|
26
|
+
@rule_config_list.each do |c|
|
27
|
+
unless c.key
|
28
|
+
key_missing = true
|
29
|
+
end
|
30
|
+
if key_missing
|
31
|
+
raise Fluent::ConfigError, "Field 'key' is missing from rule section. #{c}"
|
32
|
+
end
|
33
|
+
unless c.value || c.pattern
|
34
|
+
value_missing = true
|
35
|
+
end
|
36
|
+
if value_missing
|
37
|
+
raise Fluent::ConfigError, "Field 'value' or 'pattern' is missing from rule section for key: #{c.key}."
|
38
|
+
end
|
39
|
+
record_accessor = record_accessor_create(c.key)
|
40
|
+
@accessors["#{c.key}"] = record_accessor
|
41
|
+
list = []
|
42
|
+
if @pattern_rules_map.key?(c.key)
|
43
|
+
list = @pattern_rules_map[c.key]
|
44
|
+
end
|
45
|
+
list << [c.value, c.pattern, c.replacement]
|
46
|
+
@pattern_rules_map[c.key] = list
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def filter(tag, time, record)
|
51
|
+
@pattern_rules_map.each do |key, rules|
|
52
|
+
record_value = @accessors[key].call(record)
|
53
|
+
if record_value
|
54
|
+
rules.each do | rule |
|
55
|
+
if rule[0]
|
56
|
+
record_value = record_value.gsub(rule[0], rule[2])
|
57
|
+
else
|
58
|
+
record_value = record_value.gsub(rule[1], rule[3])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
record[key] = record_value
|
62
|
+
end
|
63
|
+
end
|
64
|
+
record
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.expand_path("../../", __FILE__))
|
2
|
+
require "test-unit"
|
3
|
+
require "fluent/test"
|
4
|
+
require "fluent/test/driver/output"
|
5
|
+
require "fluent/test/helpers"
|
6
|
+
|
7
|
+
Test::Unit::TestCase.include(Fluent::Test::Helpers)
|
8
|
+
Test::Unit::TestCase.extend(Fluent::Test::Helpers)
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'fluent/log'
|
4
|
+
require 'fluent/test'
|
5
|
+
require 'fluent/test/driver/filter'
|
6
|
+
require 'fluent/plugin/filter_redaction'
|
7
|
+
|
8
|
+
class RubyFilterTest < Test::Unit::TestCase
|
9
|
+
include Fluent
|
10
|
+
|
11
|
+
CONFIG = %[
|
12
|
+
key message
|
13
|
+
value hell
|
14
|
+
<rule>
|
15
|
+
key message
|
16
|
+
value hell
|
17
|
+
</rule>
|
18
|
+
]
|
19
|
+
|
20
|
+
PATTERN_CONFIG = %[
|
21
|
+
key message
|
22
|
+
pattern /(hell)/
|
23
|
+
<rule>
|
24
|
+
key message
|
25
|
+
value hell
|
26
|
+
</rule>
|
27
|
+
]
|
28
|
+
|
29
|
+
setup do
|
30
|
+
Fluent::Test.setup
|
31
|
+
end
|
32
|
+
|
33
|
+
def emit(msg, conf='')
|
34
|
+
d = Test::Driver::Filter.new(Plugin::RedactionFilter).configure(conf)
|
35
|
+
d.run(default_tag: 'test') {
|
36
|
+
d.feed(msg)
|
37
|
+
}
|
38
|
+
d.filtered
|
39
|
+
end
|
40
|
+
|
41
|
+
sub_test_case 'filter' do
|
42
|
+
test 'Filter hell from hello messages with simple value' do
|
43
|
+
msg = {'message' => 'hello hello'}
|
44
|
+
es = emit(msg, CONFIG)
|
45
|
+
assert_equal("[REDACTED]o [REDACTED]o", "#{es[0][1]["message"]}")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
sub_test_case 'filter' do
|
50
|
+
test 'Filter hell from hello messages with pattern' do
|
51
|
+
msg = {'message' => 'hello hello'}
|
52
|
+
es = emit(msg, PATTERN_CONFIG)
|
53
|
+
assert_equal("[REDACTED]o [REDACTED]o", "#{es[0][1]["message"]}")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-redaction
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Oliver Szabo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-01-26 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: '1.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '2'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.0'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rake
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '11.0'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '11.0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: test-unit
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.3'
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 3.3.3
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '3.3'
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 3.3.3
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: test-unit-rr
|
69
|
+
requirement: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - "~>"
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '1.0'
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 1.0.5
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '1.0'
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 1.0.5
|
87
|
+
description: Fluentd redaction filter plugin for anonymize specific strings in text
|
88
|
+
data.
|
89
|
+
email:
|
90
|
+
- oleewere@gmail.com
|
91
|
+
executables: []
|
92
|
+
extensions: []
|
93
|
+
extra_rdoc_files: []
|
94
|
+
files:
|
95
|
+
- ".gitignore"
|
96
|
+
- ".travis.yml"
|
97
|
+
- Gemfile
|
98
|
+
- LICENSE
|
99
|
+
- Makefile
|
100
|
+
- README.md
|
101
|
+
- Rakefile
|
102
|
+
- VERSION
|
103
|
+
- fluent-plugin-redaction.gemspec
|
104
|
+
- lib/fluent/plugin/filter_redaction.rb
|
105
|
+
- test/helper.rb
|
106
|
+
- test/plugin/test_filter_redaction.rb
|
107
|
+
homepage: https://github.com/oleewere/fluent-plugin-redaction
|
108
|
+
licenses:
|
109
|
+
- MIT License
|
110
|
+
metadata: {}
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 2.5.1
|
128
|
+
signing_key:
|
129
|
+
specification_version: 4
|
130
|
+
summary: Fluentd redaction filter plugin for anonymize specific strings in text data.
|
131
|
+
test_files:
|
132
|
+
- test/helper.rb
|
133
|
+
- test/plugin/test_filter_redaction.rb
|