fluent-plugin-http 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/fluent/plugin/out_http.rb +19 -5
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a05bb6dde35957eb0441bae8de152a7388a6b109
4
- data.tar.gz: 64da30f0548d530bcdeca791bf3b7921931c7127
3
+ metadata.gz: d23fcad9c2b487dc5147ee19e50c353f1c3c5f1e
4
+ data.tar.gz: ffb550405925174a9c6a1dc0cfb5e9530035f908
5
5
  SHA512:
6
- metadata.gz: 6dc693aae20a9fc985b4d060ad7874e2043dc5be8f2dc0e46e041ee0477eded844f5ef530bbcc9662230b6d896437c593c0c6aee233e23976c5e486d7a8534fc
7
- data.tar.gz: 4c27023f556ad1a1750b050c2afc8226e6e32ae7cc3b36741fbea09f9b83d0ede74f6732d98bd4dfb6cb13921c1499f6cdbb4463681041dd42abcbf59a6e612d
6
+ metadata.gz: 45dd2f70ec71a9e3f00269da9c78785594948512561c3b2aaa9bfdc0586d263b0230a20ad92b0a620eab5af37c394f55e1f4dc63865b5706e248853cd4fbe56f
7
+ data.tar.gz: dbc22b3782ec9d0e21c709ca9032085d4c8d358e7908368a3d2fcb94f47af4c538bd313635b39c3fccaa91d5387c20f615e3cd1e100b2dfa86b3af60d972cf32
@@ -10,12 +10,15 @@ module Fluent
10
10
  class HTTPOutput < BufferedOutput
11
11
  Fluent::Plugin.register_output('http', self)
12
12
 
13
- desc 'The URL to send event records to'
13
+ desc 'URL to send event records to'
14
14
  config_param :url, :string
15
15
 
16
- desc 'The acceptable response status code'
16
+ desc 'Acceptable response status codes'
17
17
  config_param :accept_status_code, :array, default: ['200']
18
18
 
19
+ desc 'Authorization token'
20
+ config_param :authorization_token, :string, default: nil, secret: true
21
+
19
22
  def initialize
20
23
  require 'fluent/plugin/http/error'
21
24
 
@@ -31,6 +34,7 @@ module Fluent
31
34
 
32
35
  @url = validate_url(url)
33
36
  @accept_status_code = validate_accept_status_code(accept_status_code)
37
+ @authorization_token = validate_authorization_token(authorization_token)
34
38
  end
35
39
 
36
40
  # Hook method that is called at the startup
@@ -84,15 +88,18 @@ module Fluent
84
88
 
85
89
  JSON_MIME_TYPE = 'application/json'
86
90
  USER_AGENT = 'FluentPluginHTTP'
87
- SERIALIZER = JSON
88
91
 
89
- private_constant :USER_AGENT, :JSON_MIME_TYPE, :SERIALIZER
92
+ private_constant :USER_AGENT, :JSON_MIME_TYPE
90
93
 
91
94
  def post_records_request(records)
92
95
  Net::HTTP::Post.new(url).tap do |request|
93
- request.body = SERIALIZER.dump(records)
96
+ request.body = JSON.dump(records)
94
97
  request.content_type = JSON_MIME_TYPE
95
98
  request['User-Agent'] = USER_AGENT
99
+
100
+ if authorization_token
101
+ request['Authorization'] = "Token token=#{authorization_token}"
102
+ end
96
103
  end
97
104
  end
98
105
 
@@ -120,5 +127,12 @@ module Fluent
120
127
  def http_status_code?(code)
121
128
  HTTP_STATUS_CODE_RANGE.cover?(code.to_i)
122
129
  end
130
+
131
+ def validate_authorization_token(value)
132
+ return value if value.nil?
133
+ return value unless value.empty?
134
+
135
+ raise Fluent::ConfigError, "Invalid authorization token: #{value.inspect}"
136
+ end
123
137
  end
124
138
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Konstantin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-24 00:00:00.000000000 Z
11
+ date: 2017-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd