logstash-mixin-http_client 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3be85aa47707c0efff5108ef847692de49ff1c2b
4
- data.tar.gz: 84c250cb85d7af53eff7c3e98c68ed0583b4e4be
3
+ metadata.gz: 866041325df6f6f569b40e8a0c44464f5d543c04
4
+ data.tar.gz: c911cdde46a537e2a87061b1439f357b01767fef
5
5
  SHA512:
6
- metadata.gz: ad251e9bd636dda5e6f6914967a2f965d183cb5aca111428d0cc6c5e3319e3a7d1fcbb4558ec687034a44fe7aa132dab2f8442babf740252a742a83b835727a9
7
- data.tar.gz: bb7c09d980bdf6dca16a3527184f679784aa6481099d9ff5ccce4f2d2a66de620636765e2222d3d8ae6a5cc3ce8b0d2358a4a12ff99876d5ae1da46ebacfed84
6
+ metadata.gz: d0f2a27414856acd2f5235ff7b9765baa5b2a8641f23f133c15fde9dc5b89d216e70bf3d0b65b043caccaefafffd25c452cf877688621cc9e252933f8f359754
7
+ data.tar.gz: 8f9e2b21bd8545a5723c4a0c57b3d13716dfec47457dfb81bb81581a520a3f309a5afa6083ed1d7148a48d88752a91dd4a4b96aa7fecbb230ab2266543ae023b
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
- # Usage
1
+ # Easily Add an HTTP Client to your Logstash Plugin!
2
+
3
+ HTTP clients have a lot of configurable options (proxies, certificates, headers, etc.), and specifying all of these with proper validation for a logstash plugin can be irritating. We built this plugin while building our [HTTP Poller Input](https://github.com/logstash-plugins/logstash-input-http_poller). If you need to build a plugin that works primarily based around HTTP this mixin makes it easy and consistent! It is based on [Manticore](https://github.com/cheald/manticore) a lightning quick, fully featured JRuby HTTP client based on Apache Commons HTTP Client.`
2
4
 
3
5
  This is a plugin for [Logstash](https://github.com/elasticsearch/logstash).
4
6
 
@@ -8,7 +10,7 @@ This plugin exposes the following options:
8
10
 
9
11
  ```ruby
10
12
  # Timeout (in seconds) for the entire request
11
- request_timeout, :validate => :number, :default => 60
13
+ config :request_timeout, :validate => :number, :default => 60
12
14
 
13
15
  # Timeout (in seconds) to wait for data on the socket. Default is 10s
14
16
  config :socket_timeout, :validate => :number, :default => 10
@@ -25,6 +27,9 @@ config :pool_max, :validate => :number, :default => 50
25
27
  # Max number of concurrent connections to a single host. Defaults to 25
26
28
  config :pool_max_per_route, :validate => :number, :default => 25
27
29
 
30
+ # Enable HTTP keepalive support, enabled by default
31
+ config :keepalive, :validate => :boolean, :default => true
32
+
28
33
  # How many times should the client retry a failing URL? Default is 3
29
34
  config :automatic_retries, :validate => :number, :default => 3
30
35
 
@@ -36,7 +41,10 @@ config :truststore_path, :validate => :path
36
41
 
37
42
  # Specify the keystore password here.
38
43
  # Note, most .jks files created with keytool require a password!
39
- config :truststore_password, :validate => :string
44
+ config :truststore_password, :validate => :password
45
+
46
+ # Specify the keystore type here. One of "JKS" or "PKCS12". Default is "JKS"
47
+ config :truststore_type, :validate => :string, :default => "JKS"
40
48
 
41
49
  # Enable cookie support. With this enabled the client will persist cookies
42
50
  # across requests as a normal web browser would. Enabled by default
@@ -47,6 +55,11 @@ config :cookies, :validate => :boolean, :default => true
47
55
  # 2. Proxy host in form: {host => "proxy.org", port => 80, scheme => 'http', user => 'username@host', password => 'password'}
48
56
  # 3. Proxy host in form: {url => 'http://proxy.org:1234', user => 'username@host', password => 'password'}
49
57
  config :proxy
58
+
59
+ # If you'd like to use a client certificate (note, most people don't want this) set the path to the x509 cert here
60
+ config :client_cert, :validate => :path
61
+ # If you'd like to use a client certificate (note, most people don't want this) set the path to the x509 key here
62
+ config :client_key, :validate => :path
50
63
  ```
51
64
 
52
65
  ## Documentation
@@ -1,10 +1,12 @@
1
1
  # encoding: utf-8
2
2
  require "logstash/config/mixin"
3
3
 
4
- # This module provides helper for the `AWS-SDK` v1,
5
- # and it will be deprecated in the near future, please use the V2 module
6
- # for any new development.
4
+ # This module makes it easy to add a very fully configured HTTP client to logstash
5
+ # based on [Manticore](https://github.com/cheald/manticore).
6
+ # For an example of its usage see https://github.com/logstash-plugins/logstash-input-http_poller
7
7
  module LogStash::PluginMixins::HttpClient
8
+ class InvalidHTTPConfigError < StandardError; end
9
+
8
10
  def self.included(base)
9
11
  require 'manticore'
10
12
  base.extend(self)
@@ -31,6 +33,9 @@ module LogStash::PluginMixins::HttpClient
31
33
  # Max number of concurrent connections to a single host. Defaults to 25
32
34
  config :pool_max_per_route, :validate => :number, :default => 25
33
35
 
36
+ # Turn this on to enable HTTP keepalive support
37
+ config :keepalive, :validate => :boolean, :default => true
38
+
34
39
  # How many times should the client retry a failing URL? Default is 3
35
40
  config :automatic_retries, :validate => :number, :default => 3
36
41
 
@@ -42,7 +47,10 @@ module LogStash::PluginMixins::HttpClient
42
47
 
43
48
  # Specify the keystore password here.
44
49
  # Note, most .jks files created with keytool require a password!
45
- config :truststore_password, :validate => :string
50
+ config :truststore_password, :validate => :password
51
+
52
+ # Specify the keystore type here. One of "JKS" or "PKCS12". Default is "JKS"
53
+ config :truststore_type, :validate => :string, :default => "JKS"
46
54
 
47
55
  # Enable cookie support. With this enabled the client will persist cookies
48
56
  # across requests as a normal web browser would. Enabled by default
@@ -53,6 +61,11 @@ module LogStash::PluginMixins::HttpClient
53
61
  # 2. Proxy host in form: {host => "proxy.org", port => 80, scheme => 'http', user => 'username@host', password => 'password'}
54
62
  # 3. Proxy host in form: {url => 'http://proxy.org:1234', user => 'username@host', password => 'password'}
55
63
  config :proxy
64
+
65
+ # If you'd like to use a client certificate (note, most people don't want this) set the path to the x509 cert here
66
+ config :client_cert, :validate => :path
67
+ # If you're using a client certificate specify the path to the encryption key here
68
+ config :client_key, :validate => :path
56
69
  end
57
70
 
58
71
  public
@@ -66,6 +79,7 @@ module LogStash::PluginMixins::HttpClient
66
79
  pool_max: @pool_max,
67
80
  pool_max_per_route: @pool_max_per_route,
68
81
  cookies: @cookies,
82
+ keepalive: @keepalive
69
83
  }
70
84
 
71
85
  if @proxy
@@ -81,14 +95,21 @@ module LogStash::PluginMixins::HttpClient
81
95
  end
82
96
  if (@truststore_path)
83
97
  c[:ssl].merge!(
84
- truststore: @truststore_path
98
+ :truststore => @truststore_path,
99
+ :truststore_type => @truststore_type
85
100
  )
86
101
 
87
102
  # JKS files have optional passwords if programatically created
88
103
  if (@truststore_password)
89
- c[:ssl].merge!(truststore_password: @truststore_password)
104
+ c[:ssl].merge!(truststore_password: @truststore_password.value)
90
105
  end
91
106
  end
107
+ if @client_cert && @client_key
108
+ c[:ssl][:client_cert] = @client_cert
109
+ c[:ssl][:client_key] = @client_key
110
+ elsif !!@client_cert ^ !!@client_key
111
+ raise InvalidHTTPConfigError, "You must specify both client_cert and client_key for an HTTP client, or neither!"
112
+ end
92
113
 
93
114
  c
94
115
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-mixin-http_client'
3
- s.version = '0.0.1'
3
+ s.version = '1.0.0'
4
4
  s.licenses = ['Apache License (2.0)']
5
5
  s.summary = "AWS mixins to provide a unified interface for Amazon Webservice"
6
6
  s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
@@ -9,7 +9,7 @@ end
9
9
 
10
10
  describe LogStash::PluginMixins::HttpClient do
11
11
  let(:basic_config) { {} }
12
- let(:impl) { Dummy.new(basic_config) }
12
+ let(:impl) { Dummy.new(basic_config) }
13
13
 
14
14
  it "should initialize with no extra settings" do
15
15
  expect {
@@ -22,15 +22,15 @@ describe LogStash::PluginMixins::HttpClient do
22
22
  end
23
23
 
24
24
  it "#client should return the client" do
25
- expect(impl.client).to be_a(Manticore::Client)
25
+ expect(impl.send(:client)).to be_a(Manticore::Client)
26
26
  end
27
27
 
28
28
  it "#client should return the same client" do
29
- expect(impl.client).to eql(impl.client)
29
+ expect(impl.send(:client)).to eql(impl.client)
30
30
  end
31
31
 
32
32
  shared_examples "setting ca bundles" do |key|
33
- subject { Dummy.new(conf).client_config }
33
+ subject { Dummy.new(conf).send(:client_config) }
34
34
 
35
35
  it "should correctly set the path" do
36
36
  expect(subject[:ssl][key]).to eql(path)
@@ -54,4 +54,41 @@ describe LogStash::PluginMixins::HttpClient do
54
54
  include_examples("setting ca bundles", :truststore)
55
55
  end
56
56
  end
57
+
58
+ describe "with a client cert" do
59
+ let(:file) { Stud::Temporary.file }
60
+ let(:path) { file.path }
61
+ after { File.unlink(path)}
62
+
63
+ context "with correct client certs" do
64
+ let(:conf) { basic_config.merge("client_cert" => path, "client_key" => path) }
65
+
66
+ it "should create without error" do
67
+ expect {
68
+ Dummy.new(conf).client_config
69
+ }.not_to raise_error
70
+ end
71
+ end
72
+
73
+ shared_examples("raising a configuration error") do
74
+ it "should raise an error error" do
75
+ expect {
76
+ Dummy.new(conf).client_config
77
+ }.to raise_error(LogStash::PluginMixins::HttpClient::InvalidHTTPConfigError)
78
+ end
79
+ end
80
+
81
+ context "without a key" do
82
+ let(:conf) { basic_config.merge("client_cert" => path) }
83
+
84
+ include_examples("raising a configuration error")
85
+ end
86
+
87
+ context "without a cert" do
88
+ let(:conf) { basic_config.merge("client_key" => path) }
89
+
90
+ include_examples("raising a configuration error")
91
+ end
92
+
93
+ end
57
94
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-mixin-http_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-29 00:00:00.000000000 Z
11
+ date: 2015-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstash-core