logstash-filter-elasticsearch 3.10.0 → 3.12.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
  SHA256:
3
- metadata.gz: 8e04ff9ca7407b8404764623b42f7ce8e754fe9ceafc6bde7cc064bc13c30723
4
- data.tar.gz: 3b317df7d5bc1b11c912e8f9d6ec14c2ef260fa975412f2ebbf2baf84da547ba
3
+ metadata.gz: 7ecfb3d5b15acecc9b301e27f77f5170ead83708c2722db56324807e3663cc08
4
+ data.tar.gz: bd8798a9f82792afb79b1be85936bdf51967dd74c91d6b45bb24b7cadec16e1b
5
5
  SHA512:
6
- metadata.gz: 6dd245e044d1c06882885e776ba64463c1dbfc93d3c80ad03ad4009b6a3b6246e5a166dc11c09cafb58f2b05b3a6e485741aef6a2137edc227081b1e06bf9e3c
7
- data.tar.gz: b9b211e1bf50bcb18d028e5322e78eaa3e113a034550eaae4ee3550b941e74235b5ed672417759eb35709e46693f7f602b8106ce13beb17bc6937eacbd991514
6
+ metadata.gz: b76de8e2722b3b1c5cf11efd0a29cc827042e48d584215e14fb9272349bc5cb50aa04b763a52ff26800ad36f64f2c1870cab27a38dbf94776fde5a25f75a7e08
7
+ data.tar.gz: 9304e6e00443b13fe5888ae62d0f9c0610cb6917cf148b21373afae460602548172a61efa4fed287e085421c7e9ef26bcebaf7a8ec1aee70a12449942b226a3e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 3.12.0
2
+ - Added support for `ca_trusted_fingerprint` when run on Logstash 8.3+ [#158](https://github.com/logstash-plugins/logstash-filter-elasticsearch/pull/158)
3
+
4
+ ## 3.11.1
5
+ - Fix: hosts => "es_host:port" regression [#156](https://github.com/logstash-plugins/logstash-filter-elasticsearch/pull/156)
6
+
7
+ ## 3.11.0
8
+ - Feat: update Elasticsearch client to 7.14.0 [#150](https://github.com/logstash-plugins/logstash-filter-elasticsearch/pull/150)
9
+
1
10
  ## 3.10.0
2
11
  - Feat: add user-agent header passed to the Elasticsearch HTTP connection [#152](https://github.com/logstash-plugins/logstash-filter-elasticsearch/pull/152)
3
12
 
data/Gemfile CHANGED
@@ -9,3 +9,6 @@ if Dir.exist?(logstash_path) && use_logstash_source
9
9
  gem 'logstash-core', :path => "#{logstash_path}/logstash-core"
10
10
  gem 'logstash-core-plugin-api', :path => "#{logstash_path}/logstash-core-plugin-api"
11
11
  end
12
+
13
+ gem 'manticore', ENV['MANTICORE_VERSION'] if ENV['MANTICORE_VERSION']
14
+ gem 'elasticsearch', ENV['ELASTICSEARCH_VERSION'] if ENV['ELASTICSEARCH_VERSION']
data/docs/index.asciidoc CHANGED
@@ -128,6 +128,7 @@ This plugin supports the following configuration options plus the <<plugins-{typ
128
128
  | <<plugins-{type}s-{plugin}-aggregation_fields>> |<<hash,hash>>|No
129
129
  | <<plugins-{type}s-{plugin}-api_key>> |<<password,password>>|No
130
130
  | <<plugins-{type}s-{plugin}-ca_file>> |a valid filesystem path|No
131
+ | <<plugins-{type}s-{plugin}-ca_trusted_fingerprint>> |<<string,string>>|No
131
132
  | <<plugins-{type}s-{plugin}-cloud_auth>> |<<password,password>>|No
132
133
  | <<plugins-{type}s-{plugin}-cloud_id>> |<<string,string>>|No
133
134
  | <<plugins-{type}s-{plugin}-docinfo_fields>> |<<hash,hash>>|No
@@ -189,6 +190,15 @@ Elasticsearch {ref}/security-api-create-api-key.html[Create API key API].
189
190
 
190
191
  SSL Certificate Authority file
191
192
 
193
+ [id="plugins-{type}s-{plugin}-ca_trusted_fingerprint"]
194
+ ===== `ca_trusted_fingerprint`
195
+
196
+ * Value type is <<string,string>>, and must contain exactly 64 hexadecimal characters.
197
+ * There is no default value for this setting.
198
+ * Use of this option _requires_ Logstash 8.3+
199
+
200
+ The SHA-256 fingerprint of an SSL Certificate Authority to trust, such as the autogenerated self-signed CA for an Elasticsearch cluster.
201
+
192
202
  [id="plugins-{type}s-{plugin}-cloud_auth"]
193
203
  ===== `cloud_auth`
194
204
 
@@ -26,10 +26,12 @@ module LogStash
26
26
  logger.warn "Supplied proxy setting (proxy => '') has no effect" if @proxy.eql?('')
27
27
  transport_options[:proxy] = proxy.to_s if proxy && !proxy.eql?('')
28
28
 
29
- hosts = hosts.map { |host| { host: host, scheme: 'https' } } if ssl
29
+ hosts = setup_hosts(hosts, ssl)
30
+
31
+ ssl_options = {}
30
32
  # set ca_file even if ssl isn't on, since the host can be an https url
31
- ssl_options = { ssl: true, ca_file: options[:ca_file] } if options[:ca_file]
32
- ssl_options ||= {}
33
+ ssl_options.update(ssl: true, ca_file: options[:ca_file]) if options[:ca_file]
34
+ ssl_options.update(ssl: true, trust_strategy: options[:ssl_trust_strategy]) if options[:ssl_trust_strategy]
33
35
 
34
36
  logger.info("New ElasticSearch filter client", :hosts => hosts)
35
37
  @client = ::Elasticsearch::Client.new(hosts: hosts, transport_options: transport_options, transport_class: ::Elasticsearch::Transport::Transport::HTTP::Manticore, :ssl => ssl_options)
@@ -41,6 +43,17 @@ module LogStash
41
43
 
42
44
  private
43
45
 
46
+ def setup_hosts(hosts, ssl)
47
+ hosts.map do |h|
48
+ if h.start_with?('http:/', 'https:/')
49
+ h
50
+ else
51
+ host, port = h.split(':')
52
+ { host: host, port: port, scheme: (ssl ? 'https' : 'http') }
53
+ end
54
+ end
55
+ end
56
+
44
57
  def setup_basic_auth(user, password)
45
58
  return {} unless user && password && password.value
46
59
 
@@ -2,6 +2,8 @@
2
2
  require "logstash/filters/base"
3
3
  require "logstash/namespace"
4
4
  require "logstash/json"
5
+ require 'logstash/plugin_mixins/ca_trusted_fingerprint_support'
6
+
5
7
  require_relative "elasticsearch/client"
6
8
  require_relative "elasticsearch/patches/_elasticsearch_transport_http_manticore"
7
9
 
@@ -73,6 +75,9 @@ class LogStash::Filters::Elasticsearch < LogStash::Filters::Base
73
75
  # Tags the event on failure to look up geo information. This can be used in later analysis.
74
76
  config :tag_on_failure, :validate => :array, :default => ["_elasticsearch_lookup_failure"]
75
77
 
78
+ # config :ca_trusted_fingerprint, :validate => :sha_256_hex
79
+ include LogStash::PluginMixins::CATrustedFingerprintSupport
80
+
76
81
  attr_reader :clients_pool
77
82
 
78
83
  ##
@@ -199,6 +204,7 @@ class LogStash::Filters::Elasticsearch < LogStash::Filters::Base
199
204
  :proxy => @proxy,
200
205
  :ssl => @ssl,
201
206
  :ca_file => @ca_file,
207
+ :ssl_trust_strategy => trust_strategy_for_ca_trusted_fingerprint
202
208
  }
203
209
  end
204
210
 
@@ -320,6 +326,10 @@ class LogStash::Filters::Elasticsearch < LogStash::Filters::Base
320
326
  end
321
327
 
322
328
  def test_connection!
323
- get_client.client.ping
329
+ begin
330
+ get_client.client.ping
331
+ rescue Elasticsearch::UnsupportedProductError
332
+ raise LogStash::ConfigurationError, "Could not connect to a compatible version of Elasticsearch"
333
+ end
324
334
  end
325
335
  end #class LogStash::Filters::Elasticsearch
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-filter-elasticsearch'
4
- s.version = '3.10.0'
4
+ s.version = '3.12.0'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "Copies fields from previous log events in Elasticsearch to current events "
7
7
  s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
@@ -21,8 +21,9 @@ Gem::Specification.new do |s|
21
21
 
22
22
  # Gem dependencies
23
23
  s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
24
- s.add_runtime_dependency 'elasticsearch', ">= 5.0.5" # LS >= 6.7 and < 7.14 all used version 5.0.5
24
+ s.add_runtime_dependency 'elasticsearch', ">= 7.14.0" # LS >= 6.7 and < 7.14 all used version 5.0.5
25
25
  s.add_runtime_dependency 'manticore', ">= 0.7.1"
26
+ s.add_runtime_dependency 'logstash-mixin-ca_trusted_fingerprint_support', '~> 1.0'
26
27
  s.add_development_dependency 'cabin', ['~> 0.6']
27
28
  s.add_development_dependency 'webrick'
28
29
 
data/spec/es_helper.rb CHANGED
@@ -7,12 +7,26 @@ module ESHelper
7
7
  end
8
8
  end
9
9
 
10
- def self.get_client(credentials)
11
- require 'elasticsearch/transport/transport/http/faraday' # supports user/password options
12
- host, port = get_host_port.split(':')
13
- host_opts = credentials.inject({}) { |h, (k, v)| h[k.to_sym] = v; h } # user: _, password: _
14
- host_opts.merge! host: host, port: port, scheme: 'http'
15
- Elasticsearch::Client.new(hosts: [host_opts], transport_class: Elasticsearch::Transport::Transport::HTTP::Faraday)
10
+ def self.curl_and_get_json_response(url, method: :get, args: nil); require 'open3'
11
+ cmd = "curl -s -v --show-error #{args} -X #{method.to_s.upcase} -k #{url}"
12
+ begin
13
+ out, err, status = Open3.capture3(cmd)
14
+ rescue Errno::ENOENT
15
+ fail "curl not available, make sure curl binary is installed and available on $PATH"
16
+ end
17
+
18
+ if status.success?
19
+ http_status = err.match(/< HTTP\/1.1 (.*?)/)[1] || '0' # < HTTP/1.1 200 OK\r\n
20
+ if http_status.strip[0].to_i > 2
21
+ warn out
22
+ fail "#{cmd.inspect} unexpected response: #{http_status}\n\n#{err}"
23
+ end
24
+
25
+ LogStash::Json.load(out)
26
+ else
27
+ warn out
28
+ fail "#{cmd.inspect} process failed: #{status}\n\n#{err}"
29
+ end
16
30
  end
17
31
 
18
32
  def self.doc_type
@@ -25,12 +39,6 @@ module ESHelper
25
39
  end
26
40
  end
27
41
 
28
- def self.index_doc(es, params)
29
- type = doc_type
30
- params[:type] = doc_type unless type.nil?
31
- es.index(params)
32
- end
33
-
34
42
  def self.es_version
35
43
  ENV['ES_VERSION'] || ENV['ELASTIC_STACK_VERSION']
36
44
  end
@@ -9,15 +9,41 @@ require "uri"
9
9
 
10
10
  describe LogStash::Filters::Elasticsearch do
11
11
 
12
+ subject(:plugin) { described_class.new(config) }
13
+
14
+ let(:event) { LogStash::Event.new({}) }
15
+
12
16
  context "registration" do
13
17
 
14
18
  let(:plugin) { LogStash::Plugin.lookup("filter", "elasticsearch").new({}) }
15
- before do
16
- allow(plugin).to receive(:test_connection!)
19
+
20
+ context "against authentic Elasticsearch" do
21
+ before do
22
+ allow(plugin).to receive(:test_connection!)
23
+ end
24
+
25
+ it "should not raise an exception" do
26
+ expect {plugin.register}.to_not raise_error
27
+ end
17
28
  end
18
29
 
19
- it "should not raise an exception" do
20
- expect {plugin.register}.to_not raise_error
30
+ context "against not authentic Elasticsearch" do
31
+ let(:failing_client) do
32
+ client = double("client")
33
+ allow(client).to receive(:ping).and_raise Elasticsearch::UnsupportedProductError
34
+
35
+ client_wrapper = double("filter_client")
36
+ allow(client_wrapper).to receive(:client).and_return client
37
+ client_wrapper
38
+ end
39
+
40
+ before do
41
+ allow(plugin).to receive(:get_client).and_return(failing_client)
42
+ end
43
+
44
+ it "should raise ConfigurationError" do
45
+ expect {plugin.register}.to raise_error(LogStash::ConfigurationError)
46
+ end
21
47
  end
22
48
  end
23
49
 
@@ -31,8 +57,6 @@ describe LogStash::Filters::Elasticsearch do
31
57
  "aggregation_fields" => { "bytes_avg" => "bytes_avg_ls_field" }
32
58
  }
33
59
  end
34
- let(:plugin) { described_class.new(config) }
35
- let(:event) { LogStash::Event.new({}) }
36
60
 
37
61
  let(:response) do
38
62
  LogStash::Json.load(File.read(File.join(File.dirname(__FILE__), "fixtures", "request_x_1.json")))
@@ -537,6 +561,38 @@ describe LogStash::Filters::Elasticsearch do
537
561
  end
538
562
  end
539
563
 
564
+ describe "ca_trusted_fingerprint" do
565
+ let(:ca_trusted_fingerprint) { SecureRandom.hex(32) }
566
+ let(:config) { {"ca_trusted_fingerprint" => ca_trusted_fingerprint}}
567
+
568
+ subject(:plugin) { described_class.new(config) }
569
+
570
+ if Gem::Version.create(LOGSTASH_VERSION) >= Gem::Version.create("8.3.0")
571
+ context 'the generated trust_strategy' do
572
+ before(:each) { allow(plugin).to receive(:test_connection!) }
573
+
574
+ it 'is passed to the Manticore client' do
575
+ expect(Manticore::Client).to receive(:new)
576
+ .with(
577
+ a_hash_including(
578
+ ssl: a_hash_including(
579
+ trust_strategy: plugin.trust_strategy_for_ca_trusted_fingerprint
580
+ )
581
+ )
582
+ ).and_call_original
583
+ plugin.register
584
+
585
+ # the client is built lazily, so we need to get it explicitly
586
+ plugin.send(:get_client).client
587
+ end
588
+ end
589
+ else
590
+ it 'raises a configuration error' do
591
+ expect { plugin }.to raise_exception(LogStash::ConfigurationError, a_string_including("ca_trusted_fingerprint"))
592
+ end
593
+ end
594
+ end
595
+
540
596
  describe "defaults" do
541
597
 
542
598
  let(:config) { Hash.new }
@@ -547,7 +603,9 @@ describe LogStash::Filters::Elasticsearch do
547
603
  it "should set localhost:9200 as hosts" do
548
604
  plugin.register
549
605
  client = plugin.send(:get_client).client
550
- expect( extract_transport(client).hosts ).to eql [{ :host => "localhost", :port => 9200, :protocol => "http"}]
606
+ hosts = extract_transport(client).hosts
607
+ expect( hosts.size ).to be 1
608
+ expect( hosts[0] ).to include(:host => "localhost", :port => 9200, :scheme => "http")
551
609
  end
552
610
  end
553
611
 
@@ -0,0 +1,20 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDSTCCAjGgAwIBAgIUUcAg9c8B8jiliCkOEJyqoAHrmccwDQYJKoZIhvcNAQEL
3
+ BQAwNDEyMDAGA1UEAxMpRWxhc3RpYyBDZXJ0aWZpY2F0ZSBUb29sIEF1dG9nZW5l
4
+ cmF0ZWQgQ0EwHhcNMjEwODEyMDUxNDU1WhcNMjQwODExMDUxNDU1WjA0MTIwMAYD
5
+ VQQDEylFbGFzdGljIENlcnRpZmljYXRlIFRvb2wgQXV0b2dlbmVyYXRlZCBDQTCC
6
+ ASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAK1HuusRuGNsztd4EQvqwcMr
7
+ 8XvnNNaalerpMOorCGySEFrNf0HxDIVMGMCrOv1F8SvlcGq3XANs2MJ4F2xhhLZr
8
+ PpqVHx+QnSZ66lu5R89QVSuMh/dCMxhNBlOA/dDlvy+EJBl9H791UGy/ChhSgaBd
9
+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z
24
+ a0SZkQKBgCWixtUxiK8PAdWhyS++90WJeJn8eqjuSAz+VMtFQFRRWDUbkiHvGMRu
25
+ o/Hhk6zS46gSF2Evb1d26uUEenXnJlIp6YWzb0DLPrfy5P53kPA6YEvYq5MSAg3l
26
+ DZOJUF+ko7cWXSZkeTIBH/jrGOdP4tTALZt6DNt+Gz7xwPO5tGgV
27
+ -----END RSA PRIVATE KEY-----
@@ -7,11 +7,12 @@ require_relative "../../../spec/es_helper"
7
7
  describe LogStash::Filters::Elasticsearch, :integration => true do
8
8
 
9
9
  ELASTIC_SECURITY_ENABLED = ENV['ELASTIC_SECURITY_ENABLED'].eql? 'true'
10
+ SECURE_INTEGRATION = ENV['SECURE_INTEGRATION'].eql? 'true'
10
11
 
11
12
  let(:base_config) do
12
13
  {
13
14
  "index" => 'logs',
14
- "hosts" => [ESHelper.get_host_port],
15
+ "hosts" => ["http#{SECURE_INTEGRATION ? 's' : nil}://#{ESHelper.get_host_port}"],
15
16
  "query" => "response: 404",
16
17
  "sort" => "response",
17
18
  "fields" => [ ["response", "code"] ],
@@ -19,27 +20,40 @@ describe LogStash::Filters::Elasticsearch, :integration => true do
19
20
  end
20
21
 
21
22
  let(:credentials) do
22
- { 'user' => 'elastic', 'password' => ENV['ELASTIC_PASSWORD'] }
23
+ if SECURE_INTEGRATION
24
+ { 'user' => 'tests', 'password' => 'Tests123' } # added user
25
+ else
26
+ { 'user' => 'elastic', 'password' => ENV['ELASTIC_PASSWORD'] }
27
+ end
23
28
  end
24
29
 
25
30
  let(:config) do
26
- ELASTIC_SECURITY_ENABLED ? base_config.merge(credentials) : base_config
31
+ config = ELASTIC_SECURITY_ENABLED ? base_config.merge(credentials) : base_config
32
+ config = { 'ca_file' => ca_path }.merge(config) if SECURE_INTEGRATION
33
+ config
34
+ end
35
+
36
+ let(:ca_path) do
37
+ File.expand_path('../fixtures/test_certs/ca.crt', File.dirname(__FILE__))
27
38
  end
28
39
 
29
40
  let(:plugin) { described_class.new(config) }
30
41
  let(:event) { LogStash::Event.new({}) }
31
42
 
32
43
  before(:each) do
33
- @es = ESHelper.get_client(ELASTIC_SECURITY_ENABLED ? credentials : {})
34
- # Delete all templates first.
44
+ es_url = ESHelper.get_host_port
45
+ es_url = SECURE_INTEGRATION ? "https://#{es_url}" : "http://#{es_url}"
46
+ args = ELASTIC_SECURITY_ENABLED ? "-u #{credentials['user']}:#{credentials['password']}" : ''
35
47
  # Clean ES of data before we start.
36
- @es.indices.delete_template(:name => "*")
48
+ # Delete all templates first.
49
+ ESHelper.curl_and_get_json_response "#{es_url}/_index_template/*", method: 'DELETE', args: args
37
50
  # This can fail if there are no indexes, ignore failure.
38
- @es.indices.delete(:index => "*") rescue nil
51
+ ESHelper.curl_and_get_json_response "#{es_url}/_index/*", method: 'DELETE', args: args
52
+ doc_args = "#{args} -H 'Content-Type: application/json' -d '{\"response\": 404, \"this\":\"that\"}'"
39
53
  10.times do
40
- ESHelper.index_doc(@es, :index => 'logs', :body => { :response => 404, :this => 'that'})
54
+ ESHelper.curl_and_get_json_response "#{es_url}/logs/_doc", method: 'POST', args: doc_args
41
55
  end
42
- @es.indices.refresh
56
+ ESHelper.curl_and_get_json_response "#{es_url}/_refresh", method: 'POST', args: args
43
57
  end
44
58
 
45
59
  it "should enhance the current event with new data" do
@@ -69,10 +83,23 @@ describe LogStash::Filters::Elasticsearch, :integration => true do
69
83
  super().reject { |key, _| key == 'password' }
70
84
  end
71
85
 
72
- it "should enhance the current event with new data" do
86
+ it "fails to register plugin" do
73
87
  expect { plugin.register }.to raise_error Elasticsearch::Transport::Transport::Errors::Unauthorized
74
88
  end
75
89
 
76
90
  end if ELASTIC_SECURITY_ENABLED
77
91
 
92
+ context 'setting host:port (and ssl)' do # reproduces GH-155
93
+
94
+ let(:config) do
95
+ super().merge "hosts" => [ESHelper.get_host_port], "ssl" => SECURE_INTEGRATION
96
+ end
97
+
98
+ it "works" do
99
+ expect { plugin.register }.to_not raise_error
100
+ plugin.filter(event)
101
+ end
102
+
103
+ end
104
+
78
105
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-filter-elasticsearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.10.0
4
+ version: 3.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-27 00:00:00.000000000 Z
11
+ date: 2022-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -35,7 +35,7 @@ dependencies:
35
35
  requirements:
36
36
  - - ">="
37
37
  - !ruby/object:Gem::Version
38
- version: 5.0.5
38
+ version: 7.14.0
39
39
  name: elasticsearch
40
40
  prerelease: false
41
41
  type: :runtime
@@ -43,7 +43,7 @@ dependencies:
43
43
  requirements:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: 5.0.5
46
+ version: 7.14.0
47
47
  - !ruby/object:Gem::Dependency
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  requirements:
@@ -58,6 +58,20 @@ dependencies:
58
58
  - - ">="
59
59
  - !ruby/object:Gem::Version
60
60
  version: 0.7.1
61
+ - !ruby/object:Gem::Dependency
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '1.0'
67
+ name: logstash-mixin-ca_trusted_fingerprint_support
68
+ prerelease: false
69
+ type: :runtime
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '1.0'
61
75
  - !ruby/object:Gem::Dependency
62
76
  requirement: !ruby/object:Gem::Requirement
63
77
  requirements:
@@ -128,6 +142,10 @@ files:
128
142
  - spec/filters/fixtures/request_size0_agg.json
129
143
  - spec/filters/fixtures/request_x_1.json
130
144
  - spec/filters/fixtures/request_x_10.json
145
+ - spec/filters/fixtures/test_certs/ca.crt
146
+ - spec/filters/fixtures/test_certs/ca.key
147
+ - spec/filters/fixtures/test_certs/es.crt
148
+ - spec/filters/fixtures/test_certs/es.key
131
149
  - spec/filters/integration/elasticsearch_spec.rb
132
150
  homepage: http://www.elastic.co/guide/en/logstash/current/index.html
133
151
  licenses:
@@ -164,4 +182,8 @@ test_files:
164
182
  - spec/filters/fixtures/request_size0_agg.json
165
183
  - spec/filters/fixtures/request_x_1.json
166
184
  - spec/filters/fixtures/request_x_10.json
185
+ - spec/filters/fixtures/test_certs/ca.crt
186
+ - spec/filters/fixtures/test_certs/ca.key
187
+ - spec/filters/fixtures/test_certs/es.crt
188
+ - spec/filters/fixtures/test_certs/es.key
167
189
  - spec/filters/integration/elasticsearch_spec.rb