elasticsearch-transport 7.9.0 → 7.10.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9248a875060a4bd8e85ffb8f146beff61553150c155b0144e6c1c85112cdc640
4
- data.tar.gz: 517e365d3b98a44646daea7e89ae1d457220b2be00f5a432c780e6f556b36728
3
+ metadata.gz: 64ed0d4e52c93d1bfaabaef470e71308ac9961da744584f770283f605131e3ac
4
+ data.tar.gz: 40b0baa58407ef49ac9fac314fbd9f84df3c8408d7312132ebe8f19cb1f5e35c
5
5
  SHA512:
6
- metadata.gz: 4921027c53dcf8b98a0d7e2051c4dfe879f4d169f1e0d1c02c0aefe874f9f5b649f1ed6b6f82409e045582cccb8e69c87ab00dcd73a9e2f200f16ef07a04f59e
7
- data.tar.gz: 7951d5d57c08454ddaa514fb2af1e12703d4028149853d928609af9f3fae8d6252fd50f18514e78a9d335bf47da6660a272445d4cd4b5c93fe3f6ba71422808f
6
+ metadata.gz: 24eefe245bb7fc61431b6798d0898bbadc4c0fafbefa6303b61336e4673df8e37f6ae71e0dc107ea0c446821a0d8138ebad16380a13b8dcb2ce5ee3c762acd8f
7
+ data.tar.gz: 8b790e93528ae4c3db68a7f63272f2cf0eefc3e9a8b66d2e2d1b8b8bd6dea67cdb180789e2df824cdc50eb90c8ef669fb7968f370c13d34d27dc2f3329ca5e53
File without changes
data/README.md CHANGED
@@ -293,11 +293,16 @@ on a different host:
293
293
 
294
294
  Elasticsearch::Client.new hosts: ['localhost:9200', 'localhost:9201'], retry_on_failure: true
295
295
 
296
- You can specify how many times should the client retry the request before it raises an exception
297
- (the default is 3 times):
296
+ By default, the client will retry the request 3 times. You can specify how many times to retry before it raises an exception by passing a number to `retry_on_failure`:
298
297
 
299
298
  Elasticsearch::Client.new hosts: ['localhost:9200', 'localhost:9201'], retry_on_failure: 5
300
299
 
300
+ These two parameters can also be used together:
301
+
302
+ ```ruby
303
+ Elasticsearch::Client.new hosts: ['localhost:9200', 'localhost:9201'], retry_on_status: [502, 503], retry_on_failure: 10
304
+ ```
305
+
301
306
  ### Reloading Hosts
302
307
 
303
308
  Elasticsearch by default dynamically discovers new nodes in the cluster. You can leverage this
@@ -39,7 +39,7 @@ Gem::Specification.new do |s|
39
39
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
40
40
  s.require_paths = ['lib']
41
41
 
42
- s.extra_rdoc_files = [ 'README.md', 'LICENSE' ]
42
+ s.extra_rdoc_files = [ 'README.md', 'LICENSE.txt' ]
43
43
  s.rdoc_options = [ '--charset=UTF-8' ]
44
44
 
45
45
  s.required_ruby_version = '>= 2.4'
@@ -191,13 +191,18 @@ module Elasticsearch
191
191
 
192
192
  def extract_cloud_creds(arguments)
193
193
  return unless arguments[:cloud_id]
194
+
194
195
  name = arguments[:cloud_id].split(':')[0]
195
196
  cloud_url, elasticsearch_instance = Base64.decode64(arguments[:cloud_id].gsub("#{name}:", '')).split('$')
196
- [ { scheme: 'https',
197
+ [
198
+ {
199
+ scheme: 'https',
197
200
  user: arguments[:user],
198
201
  password: arguments[:password],
199
202
  host: "#{elasticsearch_instance}.#{cloud_url}",
200
- port: arguments[:port] || DEFAULT_CLOUD_PORT } ]
203
+ port: arguments[:port] || DEFAULT_CLOUD_PORT
204
+ }
205
+ ]
201
206
  end
202
207
 
203
208
  # Normalizes and returns hosts configuration.
@@ -19,7 +19,6 @@ module Elasticsearch
19
19
  module Transport
20
20
  module Transport
21
21
  module Connections
22
-
23
22
  # Wraps the connection information and logic.
24
23
  #
25
24
  # The Connection instance wraps the host information (hostname, port, attributes, etc),
@@ -54,12 +53,14 @@ module Elasticsearch
54
53
  #
55
54
  # @return [String]
56
55
  #
57
- def full_url(path, params={})
56
+ def full_url(path, params = {})
58
57
  url = "#{host[:protocol]}://"
59
58
  url += "#{CGI.escape(host[:user])}:#{CGI.escape(host[:password])}@" if host[:user]
60
59
  url += "#{host[:host]}:#{host[:port]}"
61
60
  url += "#{host[:path]}" if host[:path]
62
- url += "/#{full_path(path, params)}"
61
+ full_path = full_path(path, params)
62
+ url += '/' unless full_path.match?(/^\//)
63
+ url += full_path
63
64
  end
64
65
 
65
66
  # Returns the complete endpoint path with serialized parameters.
@@ -17,6 +17,6 @@
17
17
 
18
18
  module Elasticsearch
19
19
  module Transport
20
- VERSION = "7.9.0"
20
+ VERSION = "7.10.0.pre"
21
21
  end
22
22
  end
@@ -46,10 +46,12 @@ describe Elasticsearch::Transport::Transport::Base do
46
46
 
47
47
  context 'when the user and password are provided as separate arguments' do
48
48
  let(:arguments) do
49
- { hosts: 'fake',
49
+ {
50
+ hosts: 'fake',
50
51
  logger: logger,
51
52
  password: 'secret_password',
52
- user: 'test' }
53
+ user: 'test'
54
+ }
53
55
  end
54
56
 
55
57
  it_behaves_like 'a redacted string'
@@ -57,8 +59,10 @@ describe Elasticsearch::Transport::Transport::Base do
57
59
 
58
60
  context 'when the user and password are provided in the string URI' do
59
61
  let(:arguments) do
60
- { hosts: 'https://test:secret_password@fake_local_elasticsearch',
61
- logger: logger }
62
+ {
63
+ hosts: 'https://test:secret_password@fake_local_elasticsearch',
64
+ logger: logger
65
+ }
62
66
  end
63
67
 
64
68
  it_behaves_like 'a redacted string'
@@ -66,8 +70,10 @@ describe Elasticsearch::Transport::Transport::Base do
66
70
 
67
71
  context 'when the user and password are provided in the URI object' do
68
72
  let(:arguments) do
69
- { hosts: URI.parse('https://test:secret_password@fake_local_elasticsearch'),
70
- logger: logger }
73
+ {
74
+ hosts: URI.parse('https://test:secret_password@fake_local_elasticsearch'),
75
+ logger: logger
76
+ }
71
77
  end
72
78
 
73
79
  it_behaves_like 'a redacted string'
@@ -75,36 +81,32 @@ describe Elasticsearch::Transport::Transport::Base do
75
81
  end
76
82
 
77
83
  context 'when reload_on_failure is true and and hosts are unreachable' do
78
-
79
84
  let(:client) do
80
85
  Elasticsearch::Transport::Client.new(arguments)
81
86
  end
82
87
 
83
88
  let(:arguments) do
84
89
  {
85
- hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
86
- reload_on_failure: true,
87
- sniffer_timeout: 5
90
+ hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
91
+ reload_on_failure: true,
92
+ sniffer_timeout: 5
88
93
  }
89
94
  end
90
95
 
91
96
  it 'raises an exception' do
92
- expect {
93
- client.info
94
- }.to raise_exception(Faraday::ConnectionFailed)
97
+ expect { client.info }.to raise_exception(Faraday::ConnectionFailed)
95
98
  end
96
99
  end
97
100
 
98
101
  context 'when the client has `retry_on_failure` set to an integer' do
99
-
100
102
  let(:client) do
101
103
  Elasticsearch::Transport::Client.new(arguments)
102
104
  end
103
105
 
104
106
  let(:arguments) do
105
107
  {
106
- hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
107
- retry_on_failure: 2
108
+ hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
109
+ retry_on_failure: 2
108
110
  }
109
111
  end
110
112
 
@@ -120,15 +122,34 @@ describe Elasticsearch::Transport::Transport::Base do
120
122
  end
121
123
  end
122
124
 
125
+ context 'when `perform_request` is called with a `retry_on_status` option value' do
126
+ before do
127
+ expect(client.transport).to receive(:__raise_transport_error).exactly(6).times.and_call_original
128
+ end
129
+
130
+ let(:arguments) do
131
+ {
132
+ hosts: ['http://localhost:9250'],
133
+ retry_on_status: ['404']
134
+ }
135
+ end
136
+
137
+ it 'retries on 404 status the specified number of max_retries' do
138
+ expect do
139
+ client.transport.perform_request('GET', 'myindex/mydoc/1?routing=FOOBARBAZ', {}, nil, nil, retry_on_failure: 5)
140
+ end.to raise_exception(Elasticsearch::Transport::Transport::Errors::NotFound)
141
+ end
142
+ end
143
+
123
144
  context 'when `perform_request` is called with a `retry_on_failure` option value' do
124
145
  before do
125
146
  expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original
126
147
  end
127
148
 
128
149
  it 'uses the option `retry_on_failure` value' do
129
- expect {
150
+ expect do
130
151
  client.transport.perform_request('GET', '/info', {}, nil, nil, retry_on_failure: 5)
131
- }.to raise_exception(Faraday::ConnectionFailed)
152
+ end.to raise_exception(Faraday::ConnectionFailed)
132
153
  end
133
154
  end
134
155
  end
@@ -209,40 +230,35 @@ describe Elasticsearch::Transport::Transport::Base do
209
230
  end
210
231
 
211
232
  context 'when the client has no `retry_on_failure` set' do
212
-
213
233
  let(:client) do
214
234
  Elasticsearch::Transport::Client.new(arguments)
215
235
  end
216
236
 
217
237
  let(:arguments) do
218
- {
219
- hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
220
- }
238
+ { hosts: ['http://unavailable:9200', 'http://unavailable:9201'] }
221
239
  end
222
240
 
223
241
  context 'when `perform_request` is called without a `retry_on_failure` option value' do
224
-
225
242
  before do
226
243
  expect(client.transport).to receive(:get_connection).exactly(1).times.and_call_original
227
244
  end
228
245
 
229
246
  it 'does not retry' do
230
- expect {
247
+ expect do
231
248
  client.transport.perform_request('GET', '/info')
232
- }.to raise_exception(Faraday::ConnectionFailed)
249
+ end.to raise_exception(Faraday::ConnectionFailed)
233
250
  end
234
251
  end
235
252
 
236
253
  context 'when `perform_request` is called with a `retry_on_failure` option value' do
237
-
238
254
  before do
239
255
  expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original
240
256
  end
241
257
 
242
258
  it 'uses the option `retry_on_failure` value' do
243
- expect {
259
+ expect do
244
260
  client.transport.perform_request('GET', '/info', {}, nil, nil, retry_on_failure: 5)
245
- }.to raise_exception(Faraday::ConnectionFailed)
261
+ end.to raise_exception(Faraday::ConnectionFailed)
246
262
  end
247
263
  end
248
264
  end
@@ -328,7 +328,11 @@ describe Elasticsearch::Transport::Client do
328
328
  context 'when cloud credentials are provided' do
329
329
 
330
330
  let(:client) do
331
- described_class.new(cloud_id: 'name:bG9jYWxob3N0JGFiY2QkZWZnaA==', user: 'elastic', password: 'changeme')
331
+ described_class.new(
332
+ cloud_id: 'name:bG9jYWxob3N0JGFiY2QkZWZnaA==',
333
+ user: 'elastic',
334
+ password: 'changeme'
335
+ )
332
336
  end
333
337
 
334
338
  let(:hosts) do
@@ -344,13 +348,20 @@ describe Elasticsearch::Transport::Client do
344
348
  end
345
349
 
346
350
  it 'creates the correct full url' do
347
- expect(client.transport.__full_url(client.transport.hosts[0])).to eq('https://elastic:changeme@abcd.localhost:9243')
351
+ expect(
352
+ client.transport.__full_url(client.transport.hosts[0])
353
+ ).to eq('https://elastic:changeme@abcd.localhost:9243')
348
354
  end
349
355
 
350
356
  context 'when a port is specified' do
351
357
 
352
358
  let(:client) do
353
- described_class.new(cloud_id: 'name:bG9jYWxob3N0JGFiY2QkZWZnaA==', user: 'elastic', password: 'changeme', port: 9200 )
359
+ described_class.new(
360
+ cloud_id: 'name:bG9jYWxob3N0JGFiY2QkZWZnaA==',
361
+ user: 'elastic',
362
+ password: 'changeme',
363
+ port: 9200
364
+ )
354
365
  end
355
366
 
356
367
  it 'sets the specified port along with the cloud credentials' do
@@ -369,7 +380,11 @@ describe Elasticsearch::Transport::Client do
369
380
  context 'when the cluster has alternate names' do
370
381
 
371
382
  let(:client) do
372
- described_class.new(cloud_id: 'myCluster:bG9jYWxob3N0JGFiY2QkZWZnaA==', user: 'elasticfantastic', password: 'tobechanged')
383
+ described_class.new(
384
+ cloud_id: 'myCluster:bG9jYWxob3N0JGFiY2QkZWZnaA==',
385
+ user: 'elasticfantastic',
386
+ password: 'tobechanged'
387
+ )
373
388
  end
374
389
 
375
390
  let(:hosts) do
@@ -385,9 +400,38 @@ describe Elasticsearch::Transport::Client do
385
400
  end
386
401
 
387
402
  it 'creates the correct full url' do
388
- expect(client.transport.__full_url(client.transport.hosts[0])).to eq('https://elasticfantastic:tobechanged@abcd.localhost:9243')
403
+ expect(
404
+ client.transport.__full_url(client.transport.hosts[0])
405
+ ).to eq('https://elasticfantastic:tobechanged@abcd.localhost:9243')
406
+ end
407
+ end
408
+
409
+ context 'when decoded cloud id has a trailing dollar sign' do
410
+ let(:client) do
411
+ described_class.new(
412
+ cloud_id: 'a_cluster:bG9jYWxob3N0JGFiY2Qk',
413
+ user: 'elasticfantastic',
414
+ password: 'changeme'
415
+ )
416
+ end
417
+
418
+ let(:hosts) do
419
+ client.transport.hosts
389
420
  end
390
421
 
422
+ it 'extracts the cloud credentials' do
423
+ expect(hosts[0][:host]).to eq('abcd.localhost')
424
+ expect(hosts[0][:protocol]).to eq('https')
425
+ expect(hosts[0][:user]).to eq('elasticfantastic')
426
+ expect(hosts[0][:password]).to eq('changeme')
427
+ expect(hosts[0][:port]).to eq(9243)
428
+ end
429
+
430
+ it 'creates the correct full url' do
431
+ expect(
432
+ client.transport.__full_url(client.transport.hosts[0])
433
+ ).to eq('https://elasticfantastic:changeme@abcd.localhost:9243')
434
+ end
391
435
  end
392
436
  end
393
437
 
@@ -57,6 +57,11 @@ class Elasticsearch::Transport::Transport::Connections::ConnectionTest < Minites
57
57
  assert_equal 'http://localhost:9200/foo/_search?foo=bar', c.full_url('_search', {:foo => 'bar'})
58
58
  end
59
59
 
60
+ should "return right full url with path when path starts with /" do
61
+ c = Connection.new :host => { :protocol => 'http', :host => 'localhost', :port => '9200', :path => '/foo' }
62
+ assert_equal 'http://localhost:9200/foo/_search?foo=bar', c.full_url('/_search', {:foo => 'bar'})
63
+ end
64
+
60
65
  should "have a string representation" do
61
66
  c = Connection.new :host => 'x'
62
67
  assert_match /host: x/, c.to_s
@@ -56,7 +56,7 @@ else
56
56
 
57
57
  should "set body for GET request" do
58
58
  @transport.connections.first.connection.expects(:get).
59
- with('http://127.0.0.1:8080//', {:body => '{"foo":"bar"}',
59
+ with('http://127.0.0.1:8080/', {:body => '{"foo":"bar"}',
60
60
  :headers => {"Content-Type" => "application/json",
61
61
  "User-Agent" => @transport.send(:user_agent_header)}}).returns(stub_everything)
62
62
  @transport.perform_request 'GET', '/', {}, '{"foo":"bar"}'
@@ -64,7 +64,7 @@ else
64
64
 
65
65
  should "set body for PUT request" do
66
66
  @transport.connections.first.connection.expects(:put).
67
- with('http://127.0.0.1:8080//', {:body => '{"foo":"bar"}',
67
+ with('http://127.0.0.1:8080/', {:body => '{"foo":"bar"}',
68
68
  :headers => {"Content-Type" => "application/json",
69
69
  "User-Agent" => @transport.send(:user_agent_header)}}).returns(stub_everything)
70
70
  @transport.perform_request 'PUT', '/', {}, {:foo => 'bar'}
@@ -72,7 +72,7 @@ else
72
72
 
73
73
  should "serialize the request body" do
74
74
  @transport.connections.first.connection.expects(:post).
75
- with('http://127.0.0.1:8080//', {:body => '{"foo":"bar"}',
75
+ with('http://127.0.0.1:8080/', {:body => '{"foo":"bar"}',
76
76
  :headers => {"Content-Type" => "application/json",
77
77
  "User-Agent" => @transport.send(:user_agent_header)}}).returns(stub_everything)
78
78
  @transport.perform_request 'POST', '/', {}, {'foo' => 'bar'}
@@ -80,7 +80,7 @@ else
80
80
 
81
81
  should "set custom headers for PUT request" do
82
82
  @transport.connections.first.connection.expects(:put).
83
- with('http://127.0.0.1:8080//', {:body => '{"foo":"bar"}',
83
+ with('http://127.0.0.1:8080/', {:body => '{"foo":"bar"}',
84
84
  :headers => {"Content-Type" => "application/json",
85
85
  "User-Agent" => @transport.send(:user_agent_header)}})
86
86
  .returns(stub_everything)
@@ -89,7 +89,7 @@ else
89
89
 
90
90
  should "not serialize a String request body" do
91
91
  @transport.connections.first.connection.expects(:post).
92
- with('http://127.0.0.1:8080//', {:body => '{"foo":"bar"}',
92
+ with('http://127.0.0.1:8080/', {:body => '{"foo":"bar"}',
93
93
  :headers => {"Content-Type" => "application/json",
94
94
  "User-Agent" => @transport.send(:user_agent_header)}}).returns(stub_everything)
95
95
  @transport.serializer.expects(:dump).never
@@ -103,7 +103,7 @@ else
103
103
 
104
104
  transport = Manticore.new :hosts => [ { :host => 'localhost', :port => 8080 } ], :options => options
105
105
 
106
- transport.connections.first.connection.stub("http://localhost:8080//", :body => "\"\"", :headers => {"Content-Type" => "application/x-ndjson",
106
+ transport.connections.first.connection.stub("http://localhost:8080/", :body => "\"\"", :headers => {"Content-Type" => "application/x-ndjson",
107
107
  "User-Agent" => @transport.send(:user_agent_header)}, :code => 200 )
108
108
 
109
109
  response = transport.perform_request 'GET', '/', {}
@@ -124,15 +124,15 @@ else
124
124
  end
125
125
 
126
126
  should "handle HTTP methods" do
127
- @transport.connections.first.connection.expects(:delete).with('http://127.0.0.1:8080//', { headers: {"Content-Type" => "application/json",
127
+ @transport.connections.first.connection.expects(:delete).with('http://127.0.0.1:8080/', { headers: {"Content-Type" => "application/json",
128
128
  "User-Agent" => @transport.send(:user_agent_header)}}).returns(stub_everything)
129
- @transport.connections.first.connection.expects(:head).with('http://127.0.0.1:8080//', { headers: {"Content-Type" => "application/json",
129
+ @transport.connections.first.connection.expects(:head).with('http://127.0.0.1:8080/', { headers: {"Content-Type" => "application/json",
130
130
  "User-Agent" => @transport.send(:user_agent_header)}}).returns(stub_everything)
131
- @transport.connections.first.connection.expects(:get).with('http://127.0.0.1:8080//', { headers: {"Content-Type" => "application/json",
131
+ @transport.connections.first.connection.expects(:get).with('http://127.0.0.1:8080/', { headers: {"Content-Type" => "application/json",
132
132
  "User-Agent" => @transport.send(:user_agent_header)}}).returns(stub_everything)
133
- @transport.connections.first.connection.expects(:put).with('http://127.0.0.1:8080//', { headers: {"Content-Type" => "application/json",
133
+ @transport.connections.first.connection.expects(:put).with('http://127.0.0.1:8080/', { headers: {"Content-Type" => "application/json",
134
134
  "User-Agent" => @transport.send(:user_agent_header)}}).returns(stub_everything)
135
- @transport.connections.first.connection.expects(:post).with('http://127.0.0.1:8080//', { headers: {"Content-Type" => "application/json",
135
+ @transport.connections.first.connection.expects(:post).with('http://127.0.0.1:8080/', { headers: {"Content-Type" => "application/json",
136
136
  "User-Agent" => @transport.send(:user_agent_header)}}).returns(stub_everything)
137
137
 
138
138
  %w| HEAD GET PUT POST DELETE |.each { |method| @transport.perform_request method, '/' }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticsearch-transport
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.9.0
4
+ version: 7.10.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karel Minarik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-18 00:00:00.000000000 Z
11
+ date: 2020-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -362,11 +362,11 @@ executables: []
362
362
  extensions: []
363
363
  extra_rdoc_files:
364
364
  - README.md
365
- - LICENSE
365
+ - LICENSE.txt
366
366
  files:
367
367
  - ".gitignore"
368
368
  - Gemfile
369
- - LICENSE
369
+ - LICENSE.txt
370
370
  - README.md
371
371
  - Rakefile
372
372
  - elasticsearch-transport.gemspec
@@ -423,9 +423,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
423
423
  version: '2.4'
424
424
  required_rubygems_version: !ruby/object:Gem::Requirement
425
425
  requirements:
426
- - - ">="
426
+ - - ">"
427
427
  - !ruby/object:Gem::Version
428
- version: '0'
428
+ version: 1.3.1
429
429
  requirements: []
430
430
  rubygems_version: 3.1.2
431
431
  signing_key: