fluent-plugin-http_shadow 0.1.0 → 0.1.1
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 +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +12 -7
- data/Gemfile.fluentd.0.12 +8 -0
- data/README.md +37 -0
- data/fluent-plugin-http_shadow.gemspec +2 -1
- data/lib/fluent/plugin/out_http_shadow.rb +18 -1
- data/test/plugin/test_out_http_shadow.rb +131 -0
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd40eb5720f4b03216dc6640d8e2980c7cbf3700
|
4
|
+
data.tar.gz: 4e61d4e93b20fa2431e0217f070ed63cda1cfa8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1396a7f83d5362b9fa4dacc94a9c4bdaa9006526de8359b00a4a9692ad68475cca9a5bb12d0e748dc3e5496362c65fcad5722925d982b08afad1313691676561
|
7
|
+
data.tar.gz: 932b4de2cecf599822aa2630425a5bc1776a533852049747139e774269b6da6b5bca7142d6d672d8e4f9dd5998cfc1369b202d6eafba29333a02d7413a6f67a4
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,15 +1,20 @@
|
|
1
1
|
language: ruby
|
2
2
|
|
3
3
|
rvm:
|
4
|
-
-
|
5
|
-
- 2.
|
6
|
-
- 2.
|
7
|
-
|
8
|
-
os:
|
9
|
-
- linux
|
10
|
-
- osx
|
4
|
+
- 2.0.*
|
5
|
+
- 2.1.*
|
6
|
+
- 2.2.*
|
7
|
+
- 2.3.0
|
11
8
|
|
12
9
|
gemfile:
|
13
10
|
- Gemfile
|
11
|
+
- Gemfile.fluentd.0.12
|
12
|
+
|
13
|
+
matrix:
|
14
|
+
exclude:
|
15
|
+
- rvm: 2.0.*
|
16
|
+
gemfile: Gemfile
|
17
|
+
|
18
|
+
before_install: gem update bundler
|
14
19
|
|
15
20
|
script: 'bundle exec rake test'
|
data/README.md
CHANGED
@@ -88,6 +88,43 @@ GET http://staging.exsample.com/hoge/?id=1
|
|
88
88
|
</match>
|
89
89
|
```
|
90
90
|
|
91
|
+
## Examples(use rate_per_method_hash)
|
92
|
+
```
|
93
|
+
<match http_shadow.exsample>
|
94
|
+
type http_shadow
|
95
|
+
host_hash {
|
96
|
+
"www.example.com": "staging.example.com",
|
97
|
+
"api.example.com": "api-staging.example.com",
|
98
|
+
"blog.ipros.jp": "blog-staging.ipros.jp"
|
99
|
+
}
|
100
|
+
host_key host
|
101
|
+
path_format ${path}
|
102
|
+
method_key method
|
103
|
+
header_hash { "Referer": "${referer}", "User-Agent": "${user_agent}" }
|
104
|
+
rate_per_method_hash {
|
105
|
+
"get": 30, # This means 30% requests of GET will be sent. Default(when not defined) value is 100.
|
106
|
+
"post": 90
|
107
|
+
}
|
108
|
+
</match>
|
109
|
+
```
|
110
|
+
|
111
|
+
## Examples(use support_methods)
|
112
|
+
```
|
113
|
+
<match http_shadow.exsample>
|
114
|
+
type http_shadow
|
115
|
+
host_hash {
|
116
|
+
"www.example.com": "staging.example.com",
|
117
|
+
"api.example.com": "api-staging.example.com",
|
118
|
+
"blog.ipros.jp": "blog-staging.ipros.jp"
|
119
|
+
}
|
120
|
+
host_key host
|
121
|
+
path_format ${path}
|
122
|
+
method_key method
|
123
|
+
header_hash { "Referer": "${referer}", "User-Agent": "${user_agent}" }
|
124
|
+
support_methods [ "get", "post" ] # It means that only GET and POST are sent. By default all methods are sent.
|
125
|
+
</match>
|
126
|
+
```
|
127
|
+
|
91
128
|
## note
|
92
129
|
|
93
130
|
default GET Request.
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |gem|
|
4
4
|
gem.name = "fluent-plugin-http_shadow"
|
5
|
-
gem.version = "0.1.
|
5
|
+
gem.version = "0.1.1"
|
6
6
|
gem.summary = %q{copy http request. use shadow proxy server.}
|
7
7
|
gem.description = %q{copy http request. use shadow proxy server.}
|
8
8
|
gem.license = "MIT"
|
@@ -25,4 +25,5 @@ Gem::Specification.new do |gem|
|
|
25
25
|
gem.add_development_dependency 'rubocop', '~> 0.24.1'
|
26
26
|
gem.add_development_dependency 'rubygems-tasks', '~> 0.2'
|
27
27
|
gem.add_development_dependency 'yard', '~> 0.8'
|
28
|
+
gem.add_development_dependency 'test-unit'
|
28
29
|
end
|
@@ -26,9 +26,11 @@ module Fluent
|
|
26
26
|
config_param :username, :string, :default => nil
|
27
27
|
config_param :password, :string, :default => nil
|
28
28
|
config_param :rate, :integer, :default => 100
|
29
|
+
config_param :rate_per_method_hash, :hash, :default => nil
|
29
30
|
config_param :replace_hash, :hash, :default => nil
|
30
31
|
config_param :protocol_format, :string, :default => 'http'
|
31
32
|
config_param :no_send_header_pattern, :string, :default => nil
|
33
|
+
config_param :support_methods, :array, :default => nil, :value_type => :string
|
32
34
|
|
33
35
|
def configure(conf)
|
34
36
|
super
|
@@ -81,7 +83,10 @@ module Fluent
|
|
81
83
|
records.each do |record|
|
82
84
|
host = @host || @host_hash[record[@host_key]]
|
83
85
|
next if host.nil?
|
84
|
-
|
86
|
+
request = get_request(host, record)
|
87
|
+
method = request.options[:method]
|
88
|
+
next unless supported?(method)
|
89
|
+
hydra.queue(request) if rate_per_method(method)
|
85
90
|
end
|
86
91
|
hydra.run
|
87
92
|
end
|
@@ -161,5 +166,17 @@ module Fluent
|
|
161
166
|
end
|
162
167
|
cookie.join('; ')
|
163
168
|
end
|
169
|
+
|
170
|
+
def supported?(method)
|
171
|
+
return true unless @support_methods
|
172
|
+
return @support_methods.include?(method.to_s)
|
173
|
+
end
|
174
|
+
|
175
|
+
def rate_per_method(method)
|
176
|
+
return true unless @rate_per_method_hash
|
177
|
+
|
178
|
+
rate_per_method = @rate_per_method_hash[method.to_s] || 100
|
179
|
+
return Random.rand(100) < rate_per_method
|
180
|
+
end
|
164
181
|
end
|
165
182
|
end
|
@@ -37,6 +37,137 @@ class HttpShadowOutputTest < Test::Unit::TestCase
|
|
37
37
|
]
|
38
38
|
end
|
39
39
|
end
|
40
|
+
|
41
|
+
def test_get_cookie_string
|
42
|
+
d = create_driver %[
|
43
|
+
host google.com
|
44
|
+
path_format ${path}
|
45
|
+
method_key method
|
46
|
+
path_format ${url}
|
47
|
+
method_key method
|
48
|
+
header_hash { "Referer": "${referer}", "X-Forwarded-For": "${ip_address}" }
|
49
|
+
cookie_hash { "cookie1": "${cookie1}", "cookie2": "${cookie2}"}
|
50
|
+
flush_interval 10
|
51
|
+
]
|
52
|
+
d.instance.start
|
53
|
+
cookie_string = d.instance.send(:get_cookie_string, { 'cookie1' => 'value1'})
|
54
|
+
assert_equal cookie_string, "cookie1=value1; cookie2="
|
55
|
+
|
56
|
+
cookie_string = d.instance.send(:get_cookie_string, { 'cookie1' => 'value1', 'cookie2' => 'value2' })
|
57
|
+
assert_equal cookie_string, "cookie1=value1; cookie2=value2"
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_get_cookie_string_no_send_header_pattern
|
61
|
+
d = create_driver %[
|
62
|
+
host google.com
|
63
|
+
path_format ${path}
|
64
|
+
method_key method
|
65
|
+
path_format ${url}
|
66
|
+
method_key method
|
67
|
+
header_hash { "Referer": "${referer}", "X-Forwarded-For": "${ip_address}" }
|
68
|
+
cookie_hash { "cookie1": "${cookie1}", "cookie2": "${cookie2}", "cookie3": "${cookie3}" }
|
69
|
+
no_send_header_pattern ^(-|)$
|
70
|
+
flush_interval 10
|
71
|
+
]
|
72
|
+
d.instance.start
|
73
|
+
|
74
|
+
cookie_string = d.instance.send(:get_cookie_string, { 'cookie1' => '-', 'cookie2' => '', 'cookie3' => 'value3' })
|
75
|
+
assert_equal cookie_string, "cookie3=value3"
|
76
|
+
|
77
|
+
cookie_string = d.instance.send(:get_cookie_string, { 'cookie1' => '-', 'cookie2' => '', 'cookie3' => '' })
|
78
|
+
assert_equal cookie_string, ""
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_get_header
|
82
|
+
d = create_driver %[
|
83
|
+
host google.com
|
84
|
+
path_format ${path}
|
85
|
+
method_key method
|
86
|
+
path_format ${url}
|
87
|
+
method_key method
|
88
|
+
header_hash { "Referer": "${referer}?hub=param", "X-Forwarded-For": "${ip_address}", "User-Agent": "${user_agent}" }
|
89
|
+
cookie_hash { "cookie1": "${cookie1}"}
|
90
|
+
flush_interval 10
|
91
|
+
]
|
92
|
+
d.instance.start
|
93
|
+
header = d.instance.send(
|
94
|
+
:get_header,
|
95
|
+
{
|
96
|
+
'referer' => 'http://eetimes.jp/ee/articles/1407/30/news071.html',
|
97
|
+
'ip_address' => '10.10.10.10',
|
98
|
+
'user_agent' => 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36',
|
99
|
+
'cookie1' => 'value1'
|
100
|
+
}
|
101
|
+
)
|
102
|
+
assert_equal header['Referer'], "http://eetimes.jp/ee/articles/1407/30/news071.html?hub=param"
|
103
|
+
assert_equal header['X-Forwarded-For'], "10.10.10.10"
|
104
|
+
assert_equal header['User-Agent'], "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36"
|
105
|
+
assert_equal header['Cookie'], "cookie1=value1"
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_get_header_no_send_header_pattern
|
109
|
+
d = create_driver %[
|
110
|
+
host google.com
|
111
|
+
path_format ${path}
|
112
|
+
method_key method
|
113
|
+
path_format ${url}
|
114
|
+
method_key method
|
115
|
+
header_hash { "Referer": "${referer}", "X-Forwarded-For": "${ip_address}", "User-Agent": "${user_agent}" }
|
116
|
+
cookie_hash { "cookie1": "${cookie1}"}
|
117
|
+
no_send_header_pattern ^(-|)$
|
118
|
+
flush_interval 10
|
119
|
+
]
|
120
|
+
d.instance.start
|
121
|
+
header = d.instance.send(
|
122
|
+
:get_header,
|
123
|
+
{
|
124
|
+
'referer' => '-',
|
125
|
+
'ip_address' => '10.10.10.10',
|
126
|
+
'user_agent' => '',
|
127
|
+
'cookie1' => 'value1'
|
128
|
+
}
|
129
|
+
)
|
130
|
+
assert_equal header['Referer'], nil
|
131
|
+
assert_equal header['X-Forwarded-For'], "10.10.10.10"
|
132
|
+
assert_equal header['User-Agent'], nil
|
133
|
+
assert_equal header['Cookie'], "cookie1=value1"
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_supported?
|
137
|
+
d = create_driver %[
|
138
|
+
host google.com
|
139
|
+
path_format ${path}
|
140
|
+
method_key method
|
141
|
+
path_format ${url}
|
142
|
+
method_key method
|
143
|
+
header_hash { "Referer": "${referer}", "X-Forwarded-For": "${ip_address}" }
|
144
|
+
cookie_hash { "iij-stg1_session": "${session_id}", "___IPROS_UUID_": "${uuid}"}
|
145
|
+
flush_interval 10
|
146
|
+
support_methods [ "get", "post" ]
|
147
|
+
]
|
148
|
+
d.instance.start
|
149
|
+
assert_true d.instance.send(:supported?, :get)
|
150
|
+
assert_true d.instance.send(:supported?, :post)
|
151
|
+
assert_false d.instance.send(:supported?, :put)
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_rate_per_method
|
155
|
+
d = create_driver %[
|
156
|
+
host google.com
|
157
|
+
path_format ${path}
|
158
|
+
method_key method
|
159
|
+
path_format ${url}
|
160
|
+
method_key method
|
161
|
+
header_hash { "Referer": "${referer}", "X-Forwarded-For": "${ip_address}" }
|
162
|
+
cookie_hash { "iij-stg1_session": "${session_id}", "___IPROS_UUID_": "${uuid}"}
|
163
|
+
flush_interval 10
|
164
|
+
rate_per_method_hash { "get": 100, "post": 0 }
|
165
|
+
]
|
166
|
+
d.instance.start
|
167
|
+
assert_true d.instance.send(:rate_per_method, :get)
|
168
|
+
assert_false d.instance.send(:rate_per_method, :post)
|
169
|
+
assert_true d.instance.send(:rate_per_method, :put)
|
170
|
+
end
|
40
171
|
end
|
41
172
|
|
42
173
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-http_shadow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hiroshi Toyama
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typhoeus
|
@@ -136,6 +136,20 @@ dependencies:
|
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0.8'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: test-unit
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
139
153
|
description: copy http request. use shadow proxy server.
|
140
154
|
email: toyama0919@gmail.com
|
141
155
|
executables: []
|
@@ -147,6 +161,7 @@ files:
|
|
147
161
|
- ".travis.yml"
|
148
162
|
- ".yardopts"
|
149
163
|
- Gemfile
|
164
|
+
- Gemfile.fluentd.0.12
|
150
165
|
- README.md
|
151
166
|
- Rakefile
|
152
167
|
- exsample/exsample.conf
|
@@ -174,11 +189,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
174
189
|
version: '0'
|
175
190
|
requirements: []
|
176
191
|
rubyforge_project:
|
177
|
-
rubygems_version: 2.
|
192
|
+
rubygems_version: 2.6.11
|
178
193
|
signing_key:
|
179
194
|
specification_version: 4
|
180
195
|
summary: copy http request. use shadow proxy server.
|
181
196
|
test_files:
|
182
197
|
- test/helper.rb
|
183
198
|
- test/plugin/test_out_http_shadow.rb
|
184
|
-
has_rdoc:
|