opensearch-transport 1.0.0 → 1.0.1

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: b809e35525d32ad2894329c5ce3b8baf64d71642e757cc028d7349eca78767e0
4
- data.tar.gz: 02af151d8dbcfdc0e3d3fe7135c3e7cda0ea7d164d54288f719552b20dec80ab
3
+ metadata.gz: e414746942105120cd20aeda377568e039f869009de7d02de8162f70b8510d6d
4
+ data.tar.gz: fdca1d3e46fb709f3881732758af151223d796bcbbd5270527cdf39a0b164b4a
5
5
  SHA512:
6
- metadata.gz: 95a242a7809cefd6d62a1251251e555d7292868023bfc605ed50bfdb48d4e0718191f0b3f99f5c28318bd2b7669a54a3e8583127f34cb9f1fcdec1f2e54a9826
7
- data.tar.gz: eed74608e96e773770165a6e1a62889391ab14d5837640215e69e1f73bf10b748eeb34fa1e3010a6c84f8494b61291546e99d548a9ef9904b1cb5282808a7fe7
6
+ metadata.gz: 39aecd9063de2387b8defe7bd1ab2fa87e2545199b9c60ffeabd8e8febcd5350dec33990c5948994606757196284fe03fa56e060848026eb425a75fd2954b90d
7
+ data.tar.gz: 38a4f956daf5351aabb2ab2308ab93d35fa576feee35a6a554c6f5b5578f8c629c21ea1eb21eaea8299692ccc2f75c4d5fc3ab4628ff2e029c06729a7fd9b4f8
checksums.yaml.gz.sig CHANGED
Binary file
data/Gemfile CHANGED
@@ -37,6 +37,8 @@ if File.exist? File.expand_path('../opensearch/opensearch.gemspec', __dir__)
37
37
  gem 'opensearch-ruby', path: File.expand_path('../opensearch', __dir__), require: false
38
38
  end
39
39
 
40
+ gem 'faraday', ENV['FARADAY_VERSION'], require: false if ENV.key?('FARADAY_VERSION')
41
+
40
42
  group :development, :test do
41
43
  gem 'rspec'
42
44
  if defined?(JRUBY_VERSION)
data/README.md CHANGED
@@ -28,16 +28,22 @@ Features overview:
28
28
  * Node reloading (based on cluster state) on errors or on demand
29
29
 
30
30
  For optimal performance, use a HTTP library which supports persistent ("keep-alive") connections,
31
- such as [patron](https://github.com/toland/patron) or [Typhoeus](https://github.com/typhoeus/typhoeus).
32
- Just require the library (`require 'patron'`) in your code, and it will be automatically used.
31
+ such as [Patron](https://github.com/toland/patron) or [Typhoeus](https://github.com/typhoeus/typhoeus).
32
+ Most such HTTP libraries are used through the [Faraday](https://rubygems.org/gems/faraday) HTTP library
33
+ and its [adapters](https://github.com/lostisland/awesome-faraday/#adapters).
34
+
35
+ Include the library's gem and adapter gem, and require the library and adapter in your code, and it will be automatically used.
36
+ If you don't use Bundler, you may need to require the library explicitly (like `require 'faraday/patron'`).
33
37
 
34
38
  Currently these libraries will be automatically detected and used:
35
- - [Patron](https://github.com/toland/patron)
36
- - [Typhoeus](https://github.com/typhoeus/typhoeus)
37
- - [HTTPClient](https://rubygems.org/gems/httpclient)
38
- - [Net::HTTP::Persistent](https://rubygems.org/gems/net-http-persistent)
39
+ - [Patron](https://github.com/toland/patron) through [faraday-patron](https://github.com/lostisland/faraday-patron)
40
+ - [Typhoeus](https://github.com/typhoeus/typhoeus) through [faraday-typhoeus](https://github.com/dleavitt/faraday-typhoeus) for Faraday 2 or higher, or Faraday's built-in adapter for Faraday 1.
41
+ - [HTTPClient](https://rubygems.org/gems/httpclient) through [faraday-httpclient](https://github.com/lostisland/faraday-httpclient)
42
+ - [Net::HTTP::Persistent](https://rubygems.org/gems/net-http-persistent) through [faraday-net_http_persistent](https://github.com/lostisland/faraday-net_http_persistent)
43
+
44
+ **Note on [Typhoeus](https://github.com/typhoeus/typhoeus)**: You need to use v1.4.0 or up since older versions are not compatible with Faraday 1.0 or higher.
39
45
 
40
- **Note on [Typhoeus](https://github.com/typhoeus/typhoeus)**: You need to use v1.4.0 or up since older versions are not compatible with Faraday 1.0.
46
+ **Note on [Faraday](https://rubygems.org/gems/faraday)**: If you use Faraday 2.0 or higher, if the adapter is in a separate gem, you will likely need to declare that gem as well. Only the Net::HTTP adapter gem is included by default. Faraday 1.x includes most common adapter gems already.
41
47
 
42
48
  For detailed information, see example configurations [below](#transport-implementations).
43
49
 
@@ -350,10 +356,22 @@ as a transport implementation.
350
356
  It will auto-detect and use an _adapter_ for _Faraday_ based on gems loaded in your code,
351
357
  preferring HTTP clients with support for persistent connections.
352
358
 
353
- To use the [_Patron_](https://github.com/toland/patron) HTTP, for example, just require it:
359
+ Faraday uses adapters, usually in separate gems, to connect to the HTTP library. You need to
360
+ make sure that your code refers to both the HTTP library gem and the adapter gem. See this
361
+ list of [Faraday adapters](https://github.com/lostisland/awesome-faraday/#adapters) for details.
362
+
363
+ To use the [_Patron_](https://github.com/toland/patron) HTTP, for example, you need to refer to these gems:
364
+
365
+ ```ruby
366
+ gem 'patron'
367
+ gem 'faraday-patron'
368
+ ```
369
+
370
+ If you don't use Bundler, you may need to require the libraries explicitly in your code:
354
371
 
355
372
  ```ruby
356
373
  require 'patron'
374
+ require 'faraday/patron'
357
375
  ```
358
376
 
359
377
  Then, create a new client, and the _Patron_ gem will be used as the "driver":
@@ -396,8 +414,6 @@ constructor, use the `transport_options` key:
396
414
 
397
415
  To configure the _Faraday_ instance directly, use a block:
398
416
 
399
- require 'patron'
400
-
401
417
  client = OpenSearch::Client.new(host: 'localhost', port: '9200') do |f|
402
418
  f.response :logger
403
419
  f.adapter :patron
@@ -406,8 +422,6 @@ To configure the _Faraday_ instance directly, use a block:
406
422
  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:
407
423
 
408
424
  ```ruby
409
- require 'patron'
410
-
411
425
  transport_configuration = lambda do |f|
412
426
  f.response :logger
413
427
  f.adapter :patron
@@ -330,14 +330,23 @@ module OpenSearch
330
330
  # @api private
331
331
  #
332
332
  def __auto_detect_adapter
333
+ # Get the Faraday adapter list without initializing it.
334
+ if Faraday::Adapter.respond_to?(:registered_middleware) # Faraday 2.x
335
+ adapter = ->(name) { Faraday::Adapter.registered_middleware[name] }
336
+ elsif Faraday::Adapter.respond_to?(:fetch_middleware) # Faraday 1.x
337
+ adapter = ->(name) { Faraday::Adapter.fetch_middleware(name) }
338
+ else
339
+ adapter = {} # fallback behavior that should never happen
340
+ end
341
+ # Pick an adapter that has both the client and adapter defined.
333
342
  case
334
- when defined?(::Patron)
343
+ when defined?(::Patron) && adapter[:patron]
335
344
  :patron
336
- when defined?(::Typhoeus)
345
+ when defined?(::Typhoeus) && adapter[:typhoeus]
337
346
  :typhoeus
338
- when defined?(::HTTPClient)
347
+ when defined?(::HTTPClient) && adapter[:httpclient]
339
348
  :httpclient
340
- when defined?(::Net::HTTP::Persistent)
349
+ when defined?(::Net::HTTP::Persistent) && adapter[:net_http_persistent]
341
350
  :net_http_persistent
342
351
  else
343
352
  ::Faraday.default_adapter
@@ -26,6 +26,6 @@
26
26
 
27
27
  module OpenSearch
28
28
  module Transport
29
- VERSION = '1.0.0'.freeze
29
+ VERSION = '1.0.1'.freeze
30
30
  end
31
31
  end
@@ -61,7 +61,7 @@ Gem::Specification.new do |s|
61
61
  s.required_ruby_version = '>= 2.4'
62
62
 
63
63
  s.add_dependency 'multi_json'
64
- s.add_dependency 'faraday', '~> 1'
64
+ s.add_dependency 'faraday', '>= 1.0', '< 3'
65
65
 
66
66
  s.add_development_dependency 'ansi'
67
67
  s.add_development_dependency 'bundler'
@@ -70,12 +70,15 @@ Gem::Specification.new do |s|
70
70
  s.add_development_dependency 'opensearch-ruby'
71
71
  s.add_development_dependency 'hashie'
72
72
  s.add_development_dependency 'httpclient'
73
+ s.add_development_dependency 'faraday-httpclient'
73
74
  s.add_development_dependency 'manticore' if defined? JRUBY_VERSION
74
75
  s.add_development_dependency 'minitest'
75
76
  s.add_development_dependency 'minitest-reporters'
76
77
  s.add_development_dependency 'mocha'
77
78
  s.add_development_dependency 'net-http-persistent'
79
+ s.add_development_dependency 'faraday-net_http_persistent'
78
80
  s.add_development_dependency 'patron' unless defined? JRUBY_VERSION
81
+ s.add_development_dependency 'faraday-patron' unless defined? JRUBY_VERSION
79
82
  s.add_development_dependency 'pry'
80
83
  s.add_development_dependency 'rake', '~> 13'
81
84
  s.add_development_dependency 'require-prof' unless defined?(JRUBY_VERSION) || defined?(Rubinius)
@@ -84,6 +87,7 @@ Gem::Specification.new do |s|
84
87
  s.add_development_dependency 'simplecov'
85
88
  s.add_development_dependency 'test-unit', '~> 2'
86
89
  s.add_development_dependency 'typhoeus', '~> 1.4'
90
+ s.add_development_dependency 'faraday-typhoeus' if !ENV.key?('FARADAY_VERSION') && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.6')
87
91
  s.add_development_dependency 'yard'
88
92
 
89
93
  s.description = <<-DESC.gsub(/^ /, '')
@@ -184,7 +184,7 @@ describe OpenSearch::Transport::Transport::Base do
184
184
 
185
185
  it 'retries on 404 status the specified number of max_retries' do
186
186
  expect do
187
- client.transport.perform_request('GET', 'myindex/mydoc/1?routing=FOOBARBAZ', {}, nil, nil, retry_on_failure: 5)
187
+ client.transport.perform_request('GET', 'myindex/_doc/1?routing=FOOBARBAZ', {}, nil, nil, retry_on_failure: 5)
188
188
  end.to raise_exception(OpenSearch::Transport::Transport::Errors::NotFound)
189
189
  end
190
190
  end
@@ -247,7 +247,7 @@ describe OpenSearch::Transport::Client do
247
247
  end unless jruby?
248
248
  end
249
249
 
250
- context 'when the adapter is patron' do
250
+ context 'when the adapter is patron', unless: jruby? do
251
251
  let(:adapter) do
252
252
  client.transport.connections.all.first.connection.builder.adapter
253
253
  end
@@ -275,7 +275,7 @@ describe OpenSearch::Transport::Client do
275
275
  end
276
276
  end unless jruby?
277
277
 
278
- context 'when the adapter is specified as a string key' do
278
+ context 'when the adapter is specified as a string key', unless: jruby? do
279
279
  let(:adapter) do
280
280
  client.transport.connections.all.first.connection.builder.adapter
281
281
  end
@@ -305,7 +305,7 @@ describe OpenSearch::Transport::Client do
305
305
  end
306
306
  end
307
307
 
308
- context 'when the Faraday adapter is configured' do
308
+ context 'when the Faraday adapter is configured', unless: jruby? do
309
309
 
310
310
  let(:client) do
311
311
  described_class.new do |faraday|
@@ -1680,12 +1680,12 @@ describe OpenSearch::Transport::Client do
1680
1680
  client.perform_request('DELETE', '_all')
1681
1681
  client.perform_request('DELETE', 'myindex') rescue
1682
1682
  client.perform_request('PUT', 'myindex', {}, { settings: { number_of_shards: 2, number_of_replicas: 0 } })
1683
- client.perform_request('PUT', 'myindex/mydoc/1', { routing: 'XYZ', timeout: '1s' }, { foo: 'bar' })
1683
+ client.perform_request('PUT', 'myindex/_doc/1', { routing: 'XYZ', timeout: '1s' }, { foo: 'bar' })
1684
1684
  client.perform_request('GET', '_cluster/health?wait_for_status=green&timeout=2s', {})
1685
1685
  end
1686
1686
 
1687
1687
  let(:response) do
1688
- client.perform_request('GET', 'myindex/mydoc/1?routing=XYZ')
1688
+ client.perform_request('GET', 'myindex/_doc/1?routing=XYZ')
1689
1689
  end
1690
1690
 
1691
1691
  it 'handles paths and URL paramters' do
@@ -1700,7 +1700,7 @@ describe OpenSearch::Transport::Client do
1700
1700
  context 'when an invalid url is specified' do
1701
1701
  it 'raises an exception' do
1702
1702
  expect {
1703
- client.perform_request('GET', 'myindex/mydoc/1?routing=FOOBARBAZ')
1703
+ client.perform_request('GET', 'myindex/_doc/1?routing=FOOBARBAZ')
1704
1704
  }.to raise_exception(OpenSearch::Transport::Transport::Errors::NotFound)
1705
1705
  end
1706
1706
  end
data/spec/spec_helper.rb CHANGED
@@ -29,6 +29,8 @@ if ENV['COVERAGE'] && ENV['CI'].nil?
29
29
  end
30
30
 
31
31
  require 'opensearch-transport'
32
+ require 'faraday/httpclient'
33
+ require 'faraday/net_http_persistent'
32
34
  require 'logger'
33
35
  require 'ansi/code'
34
36
  require 'hashie/mash'
@@ -37,6 +39,8 @@ if defined?(JRUBY_VERSION)
37
39
  require 'pry-nav'
38
40
  else
39
41
  require 'pry-byebug'
42
+ require 'faraday/patron'
43
+ require 'faraday/typhoeus' if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2')
40
44
  require 'opensearch/transport/transport/http/curb'
41
45
  require 'curb'
42
46
  end
@@ -34,8 +34,10 @@ class OpenSearch::Transport::ClientIntegrationTest < Minitest::Test
34
34
  end
35
35
 
36
36
  should "allow to customize the Faraday adapter to Typhoeus" do
37
+ # Require the library so autodetection finds it.
37
38
  require 'typhoeus'
38
- require 'typhoeus/adapters/faraday'
39
+ # Require the adapter so autodetection finds it.
40
+ require 'faraday/typhoeus' if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2')
39
41
 
40
42
  transport = OpenSearch::Transport::Transport::HTTP::Faraday.new \
41
43
  :hosts => [ { host: @host, port: @port } ] do |f|
@@ -44,11 +46,18 @@ class OpenSearch::Transport::ClientIntegrationTest < Minitest::Test
44
46
  end
45
47
 
46
48
  client = OpenSearch::Transport::Client.new transport: transport
47
- client.perform_request 'GET', ''
49
+ response = client.perform_request 'GET', ''
50
+
51
+ assert_respond_to(response.body, :to_hash)
52
+ assert_not_nil response.body['name']
53
+ assert_equal 'application/json; charset=UTF-8', response.headers['content-type']
48
54
  end unless jruby?
49
55
 
50
56
  should "allow to customize the Faraday adapter to NetHttpPersistent" do
57
+ # Require the library so autodetection finds it.
51
58
  require 'net/http/persistent'
59
+ # Require the adapter so autodetection finds it.
60
+ require 'faraday/net_http_persistent'
52
61
 
53
62
  transport = OpenSearch::Transport::Transport::HTTP::Faraday.new \
54
63
  :hosts => [ { host: @host, port: @port } ] do |f|
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opensearch-transport
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jayesh Hathila
@@ -33,7 +33,7 @@ cert_chain:
33
33
  yXikuH6LEVykA8pgOcB9gKsB2/zMd2ZlSj2monM8Qw9EfB14ZSDTYS8VYuwWCeF0
34
34
  eFmXXk0ufQFKl1Yll7quHkmQ0PzKkvXTpONBT6qPkXE=
35
35
  -----END CERTIFICATE-----
36
- date: 2021-12-06 00:00:00.000000000 Z
36
+ date: 2022-07-26 00:00:00.000000000 Z
37
37
  dependencies:
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: multi_json
@@ -53,16 +53,22 @@ dependencies:
53
53
  name: faraday
54
54
  requirement: !ruby/object:Gem::Requirement
55
55
  requirements:
56
- - - "~>"
56
+ - - ">="
57
57
  - !ruby/object:Gem::Version
58
- version: '1'
58
+ version: '1.0'
59
+ - - "<"
60
+ - !ruby/object:Gem::Version
61
+ version: '3'
59
62
  type: :runtime
60
63
  prerelease: false
61
64
  version_requirements: !ruby/object:Gem::Requirement
62
65
  requirements:
63
- - - "~>"
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - - "<"
64
70
  - !ruby/object:Gem::Version
65
- version: '1'
71
+ version: '3'
66
72
  - !ruby/object:Gem::Dependency
67
73
  name: ansi
68
74
  requirement: !ruby/object:Gem::Requirement
@@ -161,6 +167,20 @@ dependencies:
161
167
  - - ">="
162
168
  - !ruby/object:Gem::Version
163
169
  version: '0'
170
+ - !ruby/object:Gem::Dependency
171
+ name: faraday-httpclient
172
+ requirement: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ type: :development
178
+ prerelease: false
179
+ version_requirements: !ruby/object:Gem::Requirement
180
+ requirements:
181
+ - - ">="
182
+ - !ruby/object:Gem::Version
183
+ version: '0'
164
184
  - !ruby/object:Gem::Dependency
165
185
  name: minitest
166
186
  requirement: !ruby/object:Gem::Requirement
@@ -217,6 +237,20 @@ dependencies:
217
237
  - - ">="
218
238
  - !ruby/object:Gem::Version
219
239
  version: '0'
240
+ - !ruby/object:Gem::Dependency
241
+ name: faraday-net_http_persistent
242
+ requirement: !ruby/object:Gem::Requirement
243
+ requirements:
244
+ - - ">="
245
+ - !ruby/object:Gem::Version
246
+ version: '0'
247
+ type: :development
248
+ prerelease: false
249
+ version_requirements: !ruby/object:Gem::Requirement
250
+ requirements:
251
+ - - ">="
252
+ - !ruby/object:Gem::Version
253
+ version: '0'
220
254
  - !ruby/object:Gem::Dependency
221
255
  name: patron
222
256
  requirement: !ruby/object:Gem::Requirement
@@ -231,6 +265,20 @@ dependencies:
231
265
  - - ">="
232
266
  - !ruby/object:Gem::Version
233
267
  version: '0'
268
+ - !ruby/object:Gem::Dependency
269
+ name: faraday-patron
270
+ requirement: !ruby/object:Gem::Requirement
271
+ requirements:
272
+ - - ">="
273
+ - !ruby/object:Gem::Version
274
+ version: '0'
275
+ type: :development
276
+ prerelease: false
277
+ version_requirements: !ruby/object:Gem::Requirement
278
+ requirements:
279
+ - - ">="
280
+ - !ruby/object:Gem::Version
281
+ version: '0'
234
282
  - !ruby/object:Gem::Dependency
235
283
  name: pry
236
284
  requirement: !ruby/object:Gem::Requirement
@@ -343,6 +391,20 @@ dependencies:
343
391
  - - "~>"
344
392
  - !ruby/object:Gem::Version
345
393
  version: '1.4'
394
+ - !ruby/object:Gem::Dependency
395
+ name: faraday-typhoeus
396
+ requirement: !ruby/object:Gem::Requirement
397
+ requirements:
398
+ - - ">="
399
+ - !ruby/object:Gem::Version
400
+ version: '0'
401
+ type: :development
402
+ prerelease: false
403
+ version_requirements: !ruby/object:Gem::Requirement
404
+ requirements:
405
+ - - ">="
406
+ - !ruby/object:Gem::Version
407
+ version: '0'
346
408
  - !ruby/object:Gem::Dependency
347
409
  name: yard
348
410
  requirement: !ruby/object:Gem::Requirement
metadata.gz.sig CHANGED
@@ -1 +1,2 @@
1
- a��v��]~������sTaH��ݠ\�,4��ߧ��]��1w����>#�Ӫe�#���~ �����K�d��ƯT�NjL8������t�/�j1�w+�Ɉ�������[����A�L���R�j;��D؉�S2����G�Ӌ�-�w�:�i ��__��B���U�u0��<�|_�{����3�e�yM~^$��sKs
1
+ VR$��+)b"w5)C�0��ldz�Ƭ���$��ڥd�d�`�s�7-�[+JͯTb��%�����7HӇ�7=8-��G��%�n�d�/bkA�!^���{�����&0)��֦~h_��w�+䝤�Et�3��ȁ����&c��˽�����oh��`�M�._�<����&�
2
+ ���0��m�d��#� �C�J�}V%�<�Og