elasticsearch-transport 7.13.1 → 7.14.1.pre
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/Gemfile +4 -8
- data/README.md +3 -8
- data/Rakefile +9 -10
- data/elasticsearch-transport.gemspec +11 -11
- data/lib/elasticsearch/transport.rb +18 -30
- data/lib/elasticsearch/transport/client.rb +1 -2
- data/lib/elasticsearch/transport/transport/errors.rb +1 -0
- data/lib/elasticsearch/transport/transport/http/curb.rb +39 -29
- data/lib/elasticsearch/transport/transport/http/faraday.rb +6 -5
- data/lib/elasticsearch/transport/transport/http/manticore.rb +3 -3
- data/lib/elasticsearch/transport/version.rb +1 -1
- data/spec/elasticsearch/transport/base_spec.rb +46 -7
- data/spec/elasticsearch/transport/client_spec.rb +21 -33
- data/spec/elasticsearch/transport/meta_header_spec.rb +64 -28
- data/spec/spec_helper.rb +9 -5
- data/test/test_helper.rb +6 -22
- data/test/unit/response_test.rb +1 -1
- data/test/unit/transport_base_test.rb +16 -7
- data/test/unit/transport_curb_test.rb +0 -1
- data/test/unit/transport_manticore_test.rb +224 -155
- metadata +53 -53
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69804f86ed3bff5b4277e47adb97b727e3324cc2f5a7a7da2155266433d29b39
|
4
|
+
data.tar.gz: 4ed9685fca9531e8caff5396cfefe5b7f2e429b2b9b2a48dc325e73d3bae7c9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b958fb03c5494824be0c6683c751ec22cdac5d7cf270824ba62e746b93abbefc9ede940955408e8f228adb424f78364cd7452e28c965019476a65854026ad07a
|
7
|
+
data.tar.gz: b2f73320b43a84a8bb1de43c6afa9d37fa162d48fe587c7a9b8b78fd3c4a010c240f6f160ccbc596bb0e393d5279aa913fa930d46e6ced540ec2b5b6982c8781
|
data/Gemfile
CHANGED
@@ -20,16 +20,12 @@ source 'https://rubygems.org'
|
|
20
20
|
# Specify your gem's dependencies in elasticsearch-transport.gemspec
|
21
21
|
gemspec
|
22
22
|
|
23
|
-
if File.exist? File.expand_path('
|
24
|
-
gem 'elasticsearch-api', path: File.expand_path('
|
23
|
+
if File.exist? File.expand_path('../elasticsearch-api/elasticsearch-api.gemspec', __dir__)
|
24
|
+
gem 'elasticsearch-api', path: File.expand_path('../elasticsearch-api', __dir__), require: false
|
25
25
|
end
|
26
26
|
|
27
|
-
if File.exist? File.expand_path('
|
28
|
-
gem 'elasticsearch
|
29
|
-
end
|
30
|
-
|
31
|
-
if File.exist? File.expand_path('../../elasticsearch/elasticsearch.gemspec', __FILE__)
|
32
|
-
gem 'elasticsearch', path: File.expand_path('../../elasticsearch', __FILE__), require: false
|
27
|
+
if File.exist? File.expand_path('../elasticsearch/elasticsearch.gemspec', __dir__)
|
28
|
+
gem 'elasticsearch', path: File.expand_path('../elasticsearch', __dir__), require: false
|
33
29
|
end
|
34
30
|
|
35
31
|
group :development, :test do
|
data/README.md
CHANGED
@@ -424,10 +424,7 @@ To configure the _Faraday_ instance directly, use a block:
|
|
424
424
|
f.adapter :patron
|
425
425
|
end
|
426
426
|
|
427
|
-
You can use any standard Faraday middleware and plugins in the configuration block
|
428
|
-
|
429
|
-
You can also initialize the transport class yourself, and pass it to the client constructor
|
430
|
-
as the `transport` argument:
|
427
|
+
You can use any standard Faraday middleware and plugins in the configuration block. You can also initialize the transport class yourself, and pass it to the client constructor as the `transport` argument:
|
431
428
|
|
432
429
|
```ruby
|
433
430
|
require 'patron'
|
@@ -561,16 +558,14 @@ Github's pull requests and issues are used to communicate, send bug reports and
|
|
561
558
|
To work on the code, clone and bootstrap the main repository first --
|
562
559
|
please see instructions in the main [README](../README.md#development).
|
563
560
|
|
564
|
-
To run tests, launch a testing cluster
|
565
|
-
in the main [README](../README.md#development) -- and use the Rake tasks:
|
561
|
+
To run tests, launch a testing cluster and use the Rake tasks:
|
566
562
|
|
567
563
|
```
|
568
564
|
time rake test:unit
|
569
565
|
time rake test:integration
|
570
566
|
```
|
571
567
|
|
572
|
-
|
573
|
-
can use Ruby 2.x syntax and features.
|
568
|
+
Use `COVERAGE=true` before running a test task to check coverage with Simplecov.
|
574
569
|
|
575
570
|
## License
|
576
571
|
|
data/Rakefile
CHANGED
@@ -27,38 +27,37 @@ require 'rake/testtask'
|
|
27
27
|
require 'rspec/core/rake_task'
|
28
28
|
|
29
29
|
namespace :test do
|
30
|
-
|
31
|
-
desc "Wait for Elasticsearch to be in a green state"
|
30
|
+
desc 'Wait for Elasticsearch to be in a green state'
|
32
31
|
task :wait_for_green do
|
33
32
|
sh '../scripts/wait-cluster.sh'
|
34
33
|
end
|
35
34
|
|
36
|
-
task :spec => :wait_for_green
|
37
35
|
RSpec::Core::RakeTask.new(:spec)
|
38
36
|
|
39
37
|
Rake::TestTask.new(:unit) do |test|
|
40
38
|
test.libs << 'lib' << 'test'
|
41
|
-
test.test_files = FileList[
|
39
|
+
test.test_files = FileList['test/unit/**/*_test.rb']
|
42
40
|
test.verbose = false
|
43
41
|
test.warning = false
|
44
42
|
end
|
45
43
|
|
46
44
|
Rake::TestTask.new(:integration) do |test|
|
47
45
|
test.libs << 'lib' << 'test'
|
48
|
-
test.test_files = FileList[
|
49
|
-
test.deps = [
|
46
|
+
test.test_files = FileList['test/integration/**/*_test.rb']
|
47
|
+
test.deps = ['test:wait_for_green', 'test:spec']
|
50
48
|
test.verbose = false
|
51
49
|
test.warning = false
|
52
50
|
end
|
53
51
|
|
54
|
-
|
55
|
-
|
56
|
-
|
52
|
+
desc 'Run all tests'
|
53
|
+
task :all do
|
54
|
+
Rake::Task['test:unit'].invoke
|
55
|
+
Rake::Task['test:integration'].invoke
|
57
56
|
end
|
58
57
|
|
59
58
|
Rake::TestTask.new(:profile) do |test|
|
60
59
|
test.libs << 'lib' << 'test'
|
61
|
-
test.test_files = FileList[
|
60
|
+
test.test_files = FileList['test/profile/**/*_test.rb']
|
62
61
|
end
|
63
62
|
|
64
63
|
namespace :cluster do
|
@@ -47,29 +47,29 @@ Gem::Specification.new do |s|
|
|
47
47
|
s.add_dependency 'multi_json'
|
48
48
|
s.add_dependency 'faraday', '~> 1'
|
49
49
|
|
50
|
+
s.add_development_dependency 'ansi'
|
51
|
+
s.add_development_dependency 'bundler'
|
50
52
|
s.add_development_dependency 'cane'
|
51
|
-
s.add_development_dependency 'curb'
|
53
|
+
s.add_development_dependency 'curb' unless defined? JRUBY_VERSION
|
54
|
+
s.add_development_dependency 'elasticsearch', ['>= 7', '< 8.0.0']
|
52
55
|
s.add_development_dependency 'elasticsearch-extensions'
|
53
|
-
s.add_development_dependency 'minitest'
|
54
|
-
s.add_development_dependency 'minitest-reporters'
|
55
|
-
s.add_development_dependency 'rake', '~> 13'
|
56
|
-
s.add_development_dependency 'require-prof' unless defined?(JRUBY_VERSION) || defined?(Rubinius)
|
57
|
-
s.add_development_dependency 'ruby-prof' unless defined?(JRUBY_VERSION) || defined?(Rubinius)
|
58
|
-
s.add_development_dependency 'simplecov', '~> 0.17', '< 0.18'
|
59
|
-
s.add_development_dependency 'simplecov-rcov'
|
60
|
-
s.add_development_dependency 'ansi'
|
61
56
|
s.add_development_dependency 'hashie'
|
62
57
|
s.add_development_dependency 'httpclient'
|
63
|
-
s.add_development_dependency 'manticore'
|
58
|
+
s.add_development_dependency 'manticore' if defined? JRUBY_VERSION
|
59
|
+
s.add_development_dependency 'minitest'
|
60
|
+
s.add_development_dependency 'minitest-reporters'
|
64
61
|
s.add_development_dependency 'mocha'
|
65
62
|
s.add_development_dependency 'net-http-persistent'
|
66
63
|
s.add_development_dependency 'patron' unless defined? JRUBY_VERSION
|
67
64
|
s.add_development_dependency 'pry'
|
65
|
+
s.add_development_dependency 'rake', '~> 13'
|
66
|
+
s.add_development_dependency 'require-prof' unless defined?(JRUBY_VERSION) || defined?(Rubinius)
|
67
|
+
s.add_development_dependency 'ruby-prof' unless defined?(JRUBY_VERSION) || defined?(Rubinius)
|
68
68
|
s.add_development_dependency 'shoulda-context'
|
69
|
+
s.add_development_dependency 'simplecov'
|
69
70
|
s.add_development_dependency 'test-unit', '~> 2'
|
70
71
|
s.add_development_dependency 'typhoeus', '~> 1.4'
|
71
72
|
s.add_development_dependency 'yard'
|
72
|
-
s.add_development_dependency 'bundler'
|
73
73
|
|
74
74
|
s.description = <<-DESC.gsub(/^ /, '')
|
75
75
|
Ruby client for Elasticsearch. See the `elasticsearch` gem for full integration.
|
@@ -15,35 +15,23 @@
|
|
15
15
|
# specific language governing permissions and limitations
|
16
16
|
# under the License.
|
17
17
|
|
18
|
-
require
|
19
|
-
require
|
20
|
-
require
|
21
|
-
require
|
22
|
-
require
|
18
|
+
require 'uri'
|
19
|
+
require 'time'
|
20
|
+
require 'timeout'
|
21
|
+
require 'multi_json'
|
22
|
+
require 'faraday'
|
23
23
|
|
24
|
-
require
|
25
|
-
require
|
26
|
-
require
|
27
|
-
require
|
28
|
-
require
|
29
|
-
require
|
30
|
-
require
|
31
|
-
require
|
32
|
-
require
|
33
|
-
require
|
34
|
-
require
|
35
|
-
require
|
24
|
+
require 'elasticsearch/transport/transport/loggable'
|
25
|
+
require 'elasticsearch/transport/transport/serializer/multi_json'
|
26
|
+
require 'elasticsearch/transport/transport/sniffer'
|
27
|
+
require 'elasticsearch/transport/transport/response'
|
28
|
+
require 'elasticsearch/transport/transport/errors'
|
29
|
+
require 'elasticsearch/transport/transport/base'
|
30
|
+
require 'elasticsearch/transport/transport/connections/selector'
|
31
|
+
require 'elasticsearch/transport/transport/connections/connection'
|
32
|
+
require 'elasticsearch/transport/transport/connections/collection'
|
33
|
+
require 'elasticsearch/transport/transport/http/faraday'
|
34
|
+
require 'elasticsearch/transport/client'
|
35
|
+
require 'elasticsearch/transport/redacted'
|
36
36
|
|
37
|
-
require
|
38
|
-
|
39
|
-
module Elasticsearch
|
40
|
-
module Client
|
41
|
-
|
42
|
-
# A convenience wrapper for {::Elasticsearch::Transport::Client#initialize}.
|
43
|
-
#
|
44
|
-
def new(arguments={}, &block)
|
45
|
-
Elasticsearch::Transport::Client.new(arguments, &block)
|
46
|
-
end
|
47
|
-
extend self
|
48
|
-
end
|
49
|
-
end
|
37
|
+
require 'elasticsearch/transport/version'
|
@@ -20,14 +20,13 @@ require 'elasticsearch/transport/meta_header'
|
|
20
20
|
|
21
21
|
module Elasticsearch
|
22
22
|
module Transport
|
23
|
-
|
24
23
|
# Handles communication with an Elasticsearch cluster.
|
25
24
|
#
|
26
25
|
# See {file:README.md README} for usage and code examples.
|
27
26
|
#
|
28
27
|
class Client
|
29
28
|
include MetaHeader
|
30
|
-
DEFAULT_TRANSPORT_CLASS
|
29
|
+
DEFAULT_TRANSPORT_CLASS = Transport::HTTP::Faraday
|
31
30
|
|
32
31
|
DEFAULT_LOGGER = lambda do
|
33
32
|
require 'logger'
|
@@ -37,33 +37,44 @@ module Elasticsearch
|
|
37
37
|
connection.connection.url = connection.full_url(path, params)
|
38
38
|
|
39
39
|
case method
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
else
|
51
|
-
connection.connection.headers = headers
|
52
|
-
end
|
40
|
+
when 'HEAD'
|
41
|
+
connection.connection.set :nobody, true
|
42
|
+
when 'GET', 'POST', 'PUT', 'DELETE'
|
43
|
+
connection.connection.set :nobody, false
|
44
|
+
connection.connection.put_data = __convert_to_json(body) if body
|
45
|
+
if headers
|
46
|
+
if connection.connection.headers
|
47
|
+
connection.connection.headers.merge!(headers)
|
48
|
+
else
|
49
|
+
connection.connection.headers = headers
|
53
50
|
end
|
54
|
-
|
55
|
-
|
51
|
+
end
|
52
|
+
else
|
53
|
+
raise ArgumentError, "Unsupported HTTP method: #{method}"
|
56
54
|
end
|
57
55
|
|
58
56
|
connection.connection.http(method.to_sym)
|
59
57
|
|
60
|
-
|
61
|
-
|
58
|
+
Response.new(
|
59
|
+
connection.connection.response_code,
|
60
|
+
decompress_response(connection.connection.body_str),
|
61
|
+
headers(connection)
|
62
|
+
)
|
63
|
+
end
|
64
|
+
end
|
62
65
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
+
def headers(connection)
|
67
|
+
headers_string = connection.connection.header_str
|
68
|
+
return nil if headers_string.nil?
|
69
|
+
|
70
|
+
response_headers = headers_string&.split(/\\r\\n|\r\n/).reject(&:empty?)
|
71
|
+
response_headers.shift # Removes HTTP status string
|
72
|
+
processed_header = response_headers.flat_map { |s| s.scan(/^(\S+): (.+)/) }
|
73
|
+
headers_hash = Hash[processed_header].transform_keys(&:downcase)
|
74
|
+
if headers_hash['content-type']&.match?(/application\/json/)
|
75
|
+
headers_hash['content-type'] = 'application/json'
|
66
76
|
end
|
77
|
+
headers_hash
|
67
78
|
end
|
68
79
|
|
69
80
|
# Builds and returns a connection
|
@@ -72,9 +83,8 @@ module Elasticsearch
|
|
72
83
|
#
|
73
84
|
def __build_connection(host, options={}, block=nil)
|
74
85
|
client = ::Curl::Easy.new
|
75
|
-
|
76
86
|
apply_headers(client, options)
|
77
|
-
client.url
|
87
|
+
client.url = __full_url(host)
|
78
88
|
|
79
89
|
if host[:user]
|
80
90
|
client.http_auth_types = host[:auth_type] || :basic
|
@@ -106,13 +116,13 @@ module Elasticsearch
|
|
106
116
|
|
107
117
|
def user_agent_header(client)
|
108
118
|
@user_agent ||= begin
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
119
|
+
meta = ["RUBY_VERSION: #{RUBY_VERSION}"]
|
120
|
+
if RbConfig::CONFIG && RbConfig::CONFIG['host_os']
|
121
|
+
meta << "#{RbConfig::CONFIG['host_os'].split('_').first[/[a-z]+/i].downcase} #{RbConfig::CONFIG['target_cpu']}"
|
122
|
+
end
|
123
|
+
meta << "Curb #{Curl::CURB_VERSION}"
|
124
|
+
"elasticsearch-ruby/#{VERSION} (#{meta.join('; ')})"
|
125
|
+
end
|
116
126
|
end
|
117
127
|
end
|
118
128
|
end
|
@@ -19,7 +19,6 @@ module Elasticsearch
|
|
19
19
|
module Transport
|
20
20
|
module Transport
|
21
21
|
module HTTP
|
22
|
-
|
23
22
|
# The default transport implementation, using the [_Faraday_](https://rubygems.org/gems/faraday)
|
24
23
|
# library for abstracting the HTTP client.
|
25
24
|
#
|
@@ -45,10 +44,12 @@ module Elasticsearch
|
|
45
44
|
headers
|
46
45
|
end
|
47
46
|
|
48
|
-
response = connection.connection.run_request(
|
49
|
-
|
50
|
-
|
51
|
-
|
47
|
+
response = connection.connection.run_request(
|
48
|
+
method.downcase.to_sym,
|
49
|
+
url,
|
50
|
+
(body ? __convert_to_json(body) : nil),
|
51
|
+
headers
|
52
|
+
)
|
52
53
|
|
53
54
|
Response.new response.status, decompress_response(response.body), response.headers
|
54
55
|
end
|
@@ -63,6 +63,7 @@ module Elasticsearch
|
|
63
63
|
include Base
|
64
64
|
|
65
65
|
def initialize(arguments={}, &block)
|
66
|
+
@request_options = { headers: (arguments.dig(:transport_options, :headers) || {}) }
|
66
67
|
@manticore = build_client(arguments[:options] || {})
|
67
68
|
super(arguments, &block)
|
68
69
|
end
|
@@ -109,7 +110,6 @@ module Elasticsearch
|
|
109
110
|
# @return [Connections::Collection]
|
110
111
|
#
|
111
112
|
def __build_connections
|
112
|
-
@request_options = {}
|
113
113
|
apply_headers(@request_options, options[:transport_options])
|
114
114
|
apply_headers(@request_options, options)
|
115
115
|
|
@@ -155,11 +155,11 @@ module Elasticsearch
|
|
155
155
|
private
|
156
156
|
|
157
157
|
def apply_headers(request_options, options)
|
158
|
-
headers =
|
158
|
+
headers = options&.[](:headers) || {}
|
159
159
|
headers[CONTENT_TYPE_STR] = find_value(headers, CONTENT_TYPE_REGEX) || DEFAULT_CONTENT_TYPE
|
160
160
|
headers[USER_AGENT_STR] = find_value(headers, USER_AGENT_REGEX) || user_agent_header
|
161
161
|
headers[ACCEPT_ENCODING] = GZIP if use_compression?
|
162
|
-
request_options.merge!(headers
|
162
|
+
request_options[:headers].merge!(headers)
|
163
163
|
end
|
164
164
|
|
165
165
|
def user_agent_header
|
@@ -32,14 +32,14 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
32
32
|
expect(logger).not_to receive(:error).with(/secret_password/)
|
33
33
|
|
34
34
|
expect {
|
35
|
-
client.
|
35
|
+
client.perform_request('GET', '_cluster/stats')
|
36
36
|
}.to raise_exception(Faraday::ConnectionFailed)
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'replaces the password with the string \'REDACTED\'' do
|
40
40
|
expect(logger).to receive(:error).with(/REDACTED/)
|
41
41
|
expect {
|
42
|
-
client.
|
42
|
+
client.perform_request('GET', '_cluster/stats')
|
43
43
|
}.to raise_exception(Faraday::ConnectionFailed)
|
44
44
|
end
|
45
45
|
end
|
@@ -65,7 +65,27 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
65
65
|
}
|
66
66
|
end
|
67
67
|
|
68
|
-
|
68
|
+
if jruby?
|
69
|
+
let(:client) { Elasticsearch::Transport::Client.new(arguments) }
|
70
|
+
let(:logger) { double('logger', fatal?: true, fatal: '') }
|
71
|
+
|
72
|
+
it 'does not include the password in the logged string' do
|
73
|
+
expect(logger).not_to receive(:fatal).with(/secret_password/)
|
74
|
+
|
75
|
+
expect {
|
76
|
+
client.perform_request('GET', '_cluster/stats')
|
77
|
+
}.to raise_exception(Faraday::SSLError)
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'replaces the password with the string \'REDACTED\'' do
|
81
|
+
expect(logger).to receive(:fatal).with(/REDACTED/)
|
82
|
+
expect {
|
83
|
+
client.perform_request('GET', '_cluster/stats')
|
84
|
+
}.to raise_exception(Faraday::SSLError)
|
85
|
+
end
|
86
|
+
else
|
87
|
+
it_behaves_like 'a redacted string'
|
88
|
+
end
|
69
89
|
end
|
70
90
|
|
71
91
|
context 'when the user and password are provided in the URI object' do
|
@@ -75,8 +95,27 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
75
95
|
logger: logger
|
76
96
|
}
|
77
97
|
end
|
78
|
-
|
79
|
-
|
98
|
+
if jruby?
|
99
|
+
let(:client) { Elasticsearch::Transport::Client.new(arguments) }
|
100
|
+
let(:logger) { double('logger', fatal?: true, fatal: '') }
|
101
|
+
|
102
|
+
it 'does not include the password in the logged string' do
|
103
|
+
expect(logger).not_to receive(:fatal).with(/secret_password/)
|
104
|
+
|
105
|
+
expect {
|
106
|
+
client.perform_request('GET', '_cluster/stats')
|
107
|
+
}.to raise_exception(Faraday::SSLError)
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'replaces the password with the string \'REDACTED\'' do
|
111
|
+
expect(logger).to receive(:fatal).with(/REDACTED/)
|
112
|
+
expect {
|
113
|
+
client.perform_request('GET', '_cluster/stats')
|
114
|
+
}.to raise_exception(Faraday::SSLError)
|
115
|
+
end
|
116
|
+
else
|
117
|
+
it_behaves_like 'a redacted string'
|
118
|
+
end
|
80
119
|
end
|
81
120
|
end
|
82
121
|
|
@@ -94,7 +133,7 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
94
133
|
end
|
95
134
|
|
96
135
|
it 'raises an exception' do
|
97
|
-
expect { client.
|
136
|
+
expect { client.perform_request('GET', '/') }.to raise_exception(Faraday::ConnectionFailed)
|
98
137
|
end
|
99
138
|
end
|
100
139
|
|
@@ -129,7 +168,7 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
129
168
|
|
130
169
|
let(:arguments) do
|
131
170
|
{
|
132
|
-
hosts:
|
171
|
+
hosts: ELASTICSEARCH_HOSTS,
|
133
172
|
retry_on_status: ['404']
|
134
173
|
}
|
135
174
|
end
|