fluent-plugin-out-http 1.0.1 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dafd3484539763a106d90e6bb4acf4ca7877a3734a0a256bfa5b614e0de16a15
4
- data.tar.gz: a1fc0b58b3d6adcb44c686715030710e2d96b188842eeb61e8f3eb0b9746b18a
3
+ metadata.gz: 6c9b48a2a4c29d1c6a8e7178fbe20a8a5f008c62ee2e8c143462d1a87cfe8abb
4
+ data.tar.gz: df8adcc79a9f7cadb17ea48884ca3c6505c45d09ea3cb8049cab53ed7d02624f
5
5
  SHA512:
6
- metadata.gz: 6f91c5e5737673625a691920e751e2e9e85e7b06aefbd2cddca85de54cdc19b01168ccbf746001b35a90cfeaa384cd7d5768f7e680bb4e0fa02c703131bb5374
7
- data.tar.gz: 1943958c63b8e7feb8f2c43a78875bb672eb33e38677328c9d268014a250ef5bab9c1180edfec892d0e278d2fd8cef54055525f2f59b5d2212b335b0e167cfad
6
+ metadata.gz: fce02600476eddabc19b92fa08bc5ef555e3c90b459ec999c8fa9ec8290e490c1039d7bc51e1614f28c1bf9b4628c50ff734eeec515fd371af259138a4c6f1ff
7
+ data.tar.gz: df0573593436717a393523cf7a10325e9d45dd72e04cb7ee7950c8871ffd6257b7ab4123942384cab33554657c48d7f8b8b17adbd932cf0aa65f9d2441f8442f
data/README.md CHANGED
@@ -17,6 +17,7 @@ A generic [fluentd][1] output plugin for sending logs to an HTTP endpoint.
17
17
  username alice # default: ''
18
18
  password bobpop # default: '', secret: true
19
19
  buffered true # default: false. Switch non-buffered/buffered mode
20
+ token tokent # default: ''
20
21
  </match>
21
22
 
22
23
  ## Usage notes
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = "fluent-plugin-out-http"
5
- gem.version = "1.0.1"
5
+ gem.version = "1.1.0"
6
6
  gem.authors = ["Marica Odagaki"]
7
7
  gem.email = ["ento.entotto@gmail.com"]
8
8
  gem.summary = %q{A generic Fluentd output plugin to send logs to an HTTP endpoint}
@@ -33,10 +33,11 @@ class Fluent::Plugin::HTTPOutput < Fluent::Plugin::Output
33
33
  # Raise errors that were rescued during HTTP requests?
34
34
  config_param :raise_on_error, :bool, :default => true
35
35
 
36
- # 'none' | 'basic'
37
- config_param :authentication, :enum, list: [:none, :basic], :default => :none
36
+ # 'none' | 'basic' | 'jwt' | 'bearer'
37
+ config_param :authentication, :enum, list: [:none, :basic, :jwt, :bearer], :default => :none
38
38
  config_param :username, :string, :default => ''
39
39
  config_param :password, :string, :default => '', :secret => true
40
+ config_param :token, :string, :default => ''
40
41
  # Switch non-buffered/buffered plugin
41
42
  config_param :buffered, :bool, :default => false
42
43
 
@@ -118,6 +119,10 @@ class Fluent::Plugin::HTTPOutput < Fluent::Plugin::Output
118
119
  begin
119
120
  if @authentication == :basic
120
121
  req.basic_auth(@username, @password)
122
+ elsif @authentication == :bearer
123
+ req['authorization'] = "bearer #{@token}"
124
+ elsif @authentication == :jwt
125
+ req['authorization'] = "jwt #{@token}"
121
126
  end
122
127
  @last_request_time = Time.now.to_f
123
128
  res = Net::HTTP.start(uri.host, uri.port, **http_opts(uri)) {|http| http.request(req) }
@@ -7,6 +7,24 @@ require 'fluent/plugin/out_http'
7
7
  require 'fluent/test/driver/output'
8
8
  require 'fluent/test/helpers'
9
9
 
10
+ module OS
11
+ # ref. http://stackoverflow.com/questions/170956/how-can-i-find-which-operating-system-my-ruby-program-is-running-on
12
+ def OS.windows?
13
+ (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
14
+ end
15
+
16
+ def OS.mac?
17
+ (/darwin/ =~ RUBY_PLATFORM) != nil
18
+ end
19
+
20
+ def OS.unix?
21
+ !OS.windows?
22
+ end
23
+
24
+ def OS.linux?
25
+ OS.unix? and not OS.mac?
26
+ end
27
+ end
10
28
 
11
29
  class HTTPOutputTestBase < Test::Unit::TestCase
12
30
  include Fluent::Test::Helpers
@@ -51,6 +69,22 @@ class HTTPOutputTestBase < Test::Unit::TestCase
51
69
  end
52
70
  if @auth and req.header['authorization'][0] == 'Basic YWxpY2U6c2VjcmV0IQ==' # pattern of user='alice' passwd='secret!'
53
71
  # ok, authorized
72
+ # pattern of bear #{Base64.encode64('secret token!')}
73
+ elsif @auth and req.header['authorization'][0] == 'bearer c2VjcmV0IHRva2VuIQ=='
74
+ # pattern of jwt
75
+ # header: {
76
+ # "alg": "HS256",
77
+ # "typ": "JWT"
78
+ # }
79
+ # payload: {
80
+ # "iss": "Hoge Publisher",
81
+ # "sub": "Hoge User"
82
+ # }
83
+ # signature:
84
+ # HS256(base64UrlEncode(header) + "." +
85
+ # base64UrlEncode(payload) + "." +
86
+ # secret)
87
+ elsif @auth and req.header['authorization'][0] == 'jwt eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJIb2dlIFB1Ymxpc2hlciIsInN1YiI6IkhvZ2UgVXNlciJ9.V2NL7YgCWNt5d3vTXFrcRLpRImO2cU2JZ4mQglqw3rE'
54
88
  elsif @auth
55
89
  res.status = 403
56
90
  @prohibited += 1
@@ -441,6 +475,29 @@ class HTTPOutputTest < HTTPOutputTestBase
441
475
 
442
476
  assert_equal 1, @posts.size
443
477
  assert_equal 2, @prohibited
478
+
479
+ require 'base64'
480
+ d = create_driver(CONFIG + %[
481
+ authentication bearer
482
+ token #{Base64.encode64('secret token!')}
483
+ ])
484
+ d.run(default_tag: 'test.metrics') do
485
+ d.feed({ 'field1' => 50, 'field2' => 20, 'field3' => 10, 'otherfield' => 1 })
486
+ end # failed in background, and output warn log
487
+
488
+ assert_equal 2, @posts.size
489
+ assert_equal 2, @prohibited
490
+
491
+ d = create_driver(CONFIG + %[
492
+ authentication jwt
493
+ token eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJIb2dlIFB1Ymxpc2hlciIsInN1YiI6IkhvZ2UgVXNlciJ9.V2NL7YgCWNt5d3vTXFrcRLpRImO2cU2JZ4mQglqw3rE
494
+ ])
495
+ d.run(default_tag: 'test.metrics') do
496
+ d.feed({ 'field1' => 50, 'field2' => 20, 'field3' => 10, 'otherfield' => 1 })
497
+ end # failed in background, and output warn log
498
+
499
+ assert_equal 3, @posts.size
500
+ assert_equal 2, @prohibited
444
501
  end
445
502
 
446
503
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-out-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marica Odagaki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-05 00:00:00.000000000 Z
11
+ date: 2018-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yajl-ruby