opensearch-transport 2.0.0 → 2.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: 486df12499ed36687f17b069b98ac2338d9d53f7f503923339b8f1dbfc7dfc09
4
- data.tar.gz: 1435b4c6d75c01b8a0f0fab36ba0edaae8b00ac189eadcc2c285f2e135a2bce7
3
+ metadata.gz: 2ea723d95ed023d7af8f508f878546881eb10328feaf200f29cad5c4383f61d7
4
+ data.tar.gz: 67ac7110c70970d03cb3c2473eeb9cc63333839ccf734eb26f0f91ae2e36159d
5
5
  SHA512:
6
- metadata.gz: e48408e4ba9d03b463f5b1364c905ca944806bb58d5b9274ded620e0bd6d746a1bdc8fe5f31eb0df3f83eb4b5b8201fda19ab7de26402e38bc8fb76906299180
7
- data.tar.gz: a48c523ccc5b575d9f97cc87367995d6f16ed83977b0634144a30a9d4384cc30ff998f628c7da2ad199caeb2b32ee7084ec6853386a4b1a5bca2a9b6f680211c
6
+ metadata.gz: e12f61be75109bc43eb8c248f50b8e1a2a561577e0f224a5bcbfb5f950133caabff8532a38c71e061abf8758ddaf2fae2a60c514792828899d78e3132ef8c250
7
+ data.tar.gz: 42dac019ee4af03992f80137e588aba00334984368ee4d721db6ce3677be2191db485fe69bd2b5d5b5e23aaf38727fe8a9fce356d8a1ddba9b4bf7ec54e70820
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 = '2.0.0'.freeze
29
+ VERSION = '2.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(/^ /, '')
@@ -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|
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: 2.0.0
4
+ version: 2.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: 2022-05-31 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
Binary file