elasticsearch-transport 7.12.0 → 7.13.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 +4 -4
- data/lib/elasticsearch/transport/client.rb +17 -5
- data/lib/elasticsearch/transport/meta_header.rb +18 -3
- data/lib/elasticsearch/transport/version.rb +1 -1
- data/spec/elasticsearch/transport/client_spec.rb +42 -2
- data/spec/elasticsearch/transport/meta_header_spec.rb +1 -1
- data/test/integration/transport_test.rb +14 -1
- data/test/unit/connection_test.rb +2 -2
- data/test/unit/transport_base_test.rb +1 -1
- data/test/unit/transport_faraday_test.rb +2 -2
- data/test/unit/transport_manticore_test.rb +2 -2
- metadata +5 -5
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 2170038c55227e1ebc05cd17dd055ec0c8bd30b4f3cf7e2fb60ff527c768d693
         | 
| 4 | 
            +
              data.tar.gz: 7ab94a823a1e57348d6b4ef0b80d84cb958964cdd8ae8cd9a6464ca9fa477621
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: f34f54dbfee4ee6f8a4706d9e9634fa38fe96ceee74651b774fa243fe37f65b29608acfcc217bc10843a65c90daca17aaa6b5f8e7b21f1d9a77d0d87c43e04d0
         | 
| 7 | 
            +
              data.tar.gz: b1a5ce57f77c59f98a968bf22d79a182c14db2fb27bedf636d07602f6da384dc11d6b111ebd3967cb18c1481e8d4298715a0a45b66ad61d55a91e666accc0f4a
         | 
| @@ -145,14 +145,15 @@ module Elasticsearch | |
| 145 145 | 
             
                    @options[:http]                 ||= {}
         | 
| 146 146 |  | 
| 147 147 | 
             
                    set_api_key if (@api_key = @arguments[:api_key])
         | 
| 148 | 
            +
                    set_compatibility_header if ENV['ELASTIC_CLIENT_APIVERSIONING']
         | 
| 148 149 |  | 
| 149 150 | 
             
                    @seeds = extract_cloud_creds(@arguments)
         | 
| 150 151 | 
             
                    @seeds ||= __extract_hosts(@arguments[:hosts] ||
         | 
| 151 | 
            -
             | 
| 152 | 
            -
             | 
| 153 | 
            -
             | 
| 154 | 
            -
             | 
| 155 | 
            -
             | 
| 152 | 
            +
                                               @arguments[:host] ||
         | 
| 153 | 
            +
                                               @arguments[:url] ||
         | 
| 154 | 
            +
                                               @arguments[:urls] ||
         | 
| 155 | 
            +
                                               ENV['ELASTICSEARCH_URL'] ||
         | 
| 156 | 
            +
                                               DEFAULT_HOST)
         | 
| 156 157 |  | 
| 157 158 | 
             
                    @send_get_body_as = @arguments[:send_get_body_as] || 'GET'
         | 
| 158 159 | 
             
                    @opaque_id_prefix = @arguments[:opaque_id_prefix] || nil
         | 
| @@ -200,6 +201,17 @@ module Elasticsearch | |
| 200 201 | 
             
                    @arguments.delete(:password)
         | 
| 201 202 | 
             
                  end
         | 
| 202 203 |  | 
| 204 | 
            +
                  def set_compatibility_header
         | 
| 205 | 
            +
                    return unless ['1', 'true'].include?(ENV['ELASTIC_CLIENT_APIVERSIONING'])
         | 
| 206 | 
            +
             | 
| 207 | 
            +
                    add_header(
         | 
| 208 | 
            +
                      {
         | 
| 209 | 
            +
                        'Accept' => 'application/vnd.elasticsearch+json;compatible-with=7',
         | 
| 210 | 
            +
                        'Content-Type' => 'application/vnd.elasticsearch+json; compatible-with=7'
         | 
| 211 | 
            +
                      }
         | 
| 212 | 
            +
                    )
         | 
| 213 | 
            +
                  end
         | 
| 214 | 
            +
             | 
| 203 215 | 
             
                  def add_header(header)
         | 
| 204 216 | 
             
                    headers = @arguments[:transport_options]&.[](:headers) || {}
         | 
| 205 217 | 
             
                    headers.merge!(header)
         | 
| @@ -19,7 +19,6 @@ require 'base64' | |
| 19 19 |  | 
| 20 20 | 
             
            module Elasticsearch
         | 
| 21 21 | 
             
              module Transport
         | 
| 22 | 
            -
             | 
| 23 22 | 
             
                # Methods for the Elastic meta header used by Cloud.
         | 
| 24 23 | 
             
                # X-Elastic-Client-Meta HTTP header which is used by Elastic Cloud and can be disabled when
         | 
| 25 24 | 
             
                # instantiating the Client with the :enable_meta_header parameter set to `false`.
         | 
| @@ -42,8 +41,10 @@ module Elasticsearch | |
| 42 41 | 
             
                  end
         | 
| 43 42 |  | 
| 44 43 | 
             
                  def meta_header_service_version
         | 
| 45 | 
            -
                    if  | 
| 46 | 
            -
                      Elastic:: | 
| 44 | 
            +
                    if enterprise_search?
         | 
| 45 | 
            +
                      Elastic::ENTERPRISE_SERVICE_VERSION
         | 
| 46 | 
            +
                    elsif elasticsearch?
         | 
| 47 | 
            +
                      Elastic::ELASTICSEARCH_SERVICE_VERSION
         | 
| 47 48 | 
             
                    elsif defined?(Elasticsearch::VERSION)
         | 
| 48 49 | 
             
                      [:es, client_meta_version(Elasticsearch::VERSION)]
         | 
| 49 50 | 
             
                    else
         | 
| @@ -51,6 +52,20 @@ module Elasticsearch | |
| 51 52 | 
             
                    end
         | 
| 52 53 | 
             
                  end
         | 
| 53 54 |  | 
| 55 | 
            +
                  def enterprise_search?
         | 
| 56 | 
            +
                    defined?(Elastic::ENTERPRISE_SERVICE_VERSION) &&
         | 
| 57 | 
            +
                      called_from?('enterprise-search-ruby')
         | 
| 58 | 
            +
                  end
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                  def elasticsearch?
         | 
| 61 | 
            +
                    defined?(Elastic::ELASTICSEARCH_SERVICE_VERSION) &&
         | 
| 62 | 
            +
                      called_from?('elasticsearch')
         | 
| 63 | 
            +
                  end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                  def called_from?(service)
         | 
| 66 | 
            +
                    !caller.select { |c| c.match?(service) }.empty?
         | 
| 67 | 
            +
                  end
         | 
| 68 | 
            +
             | 
| 54 69 | 
             
                  # We return the current version if it's a release, but if it's a pre/alpha/beta release we
         | 
| 55 70 | 
             
                  # return <VERSION_NUMBER>p
         | 
| 56 71 | 
             
                  #
         | 
| @@ -266,7 +266,7 @@ describe Elasticsearch::Transport::Client do | |
| 266 266 | 
             
                  it 'uses Faraday with the adapter' do
         | 
| 267 267 | 
             
                    expect(adapter).to eq Faraday::Adapter::Typhoeus
         | 
| 268 268 | 
             
                  end
         | 
| 269 | 
            -
                end
         | 
| 269 | 
            +
                end unless jruby?
         | 
| 270 270 |  | 
| 271 271 | 
             
                context 'when the adapter is specified as a string key' do
         | 
| 272 272 | 
             
                  let(:adapter) do
         | 
| @@ -1428,6 +1428,46 @@ describe Elasticsearch::Transport::Client do | |
| 1428 1428 | 
             
                  end
         | 
| 1429 1429 | 
             
                end
         | 
| 1430 1430 |  | 
| 1431 | 
            +
                context 'when using the API Compatibility Header' do
         | 
| 1432 | 
            +
                  it 'sets the API compatibility headers' do
         | 
| 1433 | 
            +
                    ENV['ELASTIC_CLIENT_APIVERSIONING'] = 'true'
         | 
| 1434 | 
            +
                    client = described_class.new(host: hosts)
         | 
| 1435 | 
            +
                    headers = client.transport.connections.first.connection.headers
         | 
| 1436 | 
            +
             | 
| 1437 | 
            +
                    expect(headers['Content-Type']).to eq('application/vnd.elasticsearch+json; compatible-with=7')
         | 
| 1438 | 
            +
                    expect(headers['Accept']).to eq('application/vnd.elasticsearch+json;compatible-with=7')
         | 
| 1439 | 
            +
             | 
| 1440 | 
            +
                    response = client.perform_request('GET', '/')
         | 
| 1441 | 
            +
                    expect(response.headers['content-type']).to eq('application/json; charset=UTF-8')
         | 
| 1442 | 
            +
             | 
| 1443 | 
            +
                    ENV.delete('ELASTIC_CLIENT_APIVERSIONING')
         | 
| 1444 | 
            +
                  end
         | 
| 1445 | 
            +
             | 
| 1446 | 
            +
                  it 'does not use API compatibility headers' do
         | 
| 1447 | 
            +
                    val = ENV.delete('ELASTIC_CLIENT_APIVERSIONING')
         | 
| 1448 | 
            +
                    client = described_class.new(host: hosts)
         | 
| 1449 | 
            +
                    expect(client.transport.connections.first.connection.headers['Content-Type']).to eq('application/json')
         | 
| 1450 | 
            +
                    ENV['ELASTIC_CLIENT_APIVERSIONING'] = val
         | 
| 1451 | 
            +
                  end
         | 
| 1452 | 
            +
             | 
| 1453 | 
            +
                  it 'does not use API compatibility headers when it is set to unsupported values' do
         | 
| 1454 | 
            +
                    val = ENV.delete('ELASTIC_CLIENT_APIVERSIONING')
         | 
| 1455 | 
            +
             | 
| 1456 | 
            +
                    ENV['ELASTIC_CLIENT_APIVERSIONING'] = 'test'
         | 
| 1457 | 
            +
                    client = described_class.new(host: hosts)
         | 
| 1458 | 
            +
                    expect(client.transport.connections.first.connection.headers['Content-Type']).to eq('application/json')
         | 
| 1459 | 
            +
             | 
| 1460 | 
            +
                    ENV['ELASTIC_CLIENT_APIVERSIONING'] = 'false'
         | 
| 1461 | 
            +
                    client = described_class.new(host: hosts)
         | 
| 1462 | 
            +
                    expect(client.transport.connections.first.connection.headers['Content-Type']).to eq('application/json')
         | 
| 1463 | 
            +
             | 
| 1464 | 
            +
                    ENV['ELASTIC_CLIENT_APIVERSIONING'] = '3'
         | 
| 1465 | 
            +
                    client = described_class.new(host: hosts)
         | 
| 1466 | 
            +
                    expect(client.transport.connections.first.connection.headers['Content-Type']).to eq('application/json')
         | 
| 1467 | 
            +
                    ENV['ELASTIC_CLIENT_APIVERSIONING'] = val
         | 
| 1468 | 
            +
                  end
         | 
| 1469 | 
            +
                end
         | 
| 1470 | 
            +
             | 
| 1431 1471 | 
             
                context 'when Elasticsearch response includes a warning header' do
         | 
| 1432 1472 | 
             
                  let(:client) do
         | 
| 1433 1473 | 
             
                    Elasticsearch::Transport::Client.new(hosts: hosts)
         | 
| @@ -1776,7 +1816,7 @@ describe Elasticsearch::Transport::Client do | |
| 1776 1816 | 
             
                        it 'preserves the other headers' do
         | 
| 1777 1817 | 
             
                          expect(client.transport.connections[0].connection.headers['User-Agent'])
         | 
| 1778 1818 | 
             
                        end
         | 
| 1779 | 
            -
                      end
         | 
| 1819 | 
            +
                      end unless jruby?
         | 
| 1780 1820 | 
             
                    end
         | 
| 1781 1821 | 
             
                  end
         | 
| 1782 1822 |  | 
| @@ -251,7 +251,7 @@ describe Elasticsearch::Transport::Client do | |
| 251 251 |  | 
| 252 252 | 
             
                context 'when using a different service version' do
         | 
| 253 253 | 
             
                  before do
         | 
| 254 | 
            -
                    stub_const( | 
| 254 | 
            +
                    stub_const('Elastic::ELASTICSEARCH_SERVICE_VERSION', [:ent, '8.0.0'])
         | 
| 255 255 | 
             
                  end
         | 
| 256 256 |  | 
| 257 257 | 
             
                  let(:client) { Elasticsearch::Client.new }
         | 
| @@ -32,7 +32,7 @@ class Elasticsearch::Transport::ClientIntegrationTest < Elasticsearch::Test::Int | |
| 32 32 | 
             
                  begin; Object.send(:remove_const, :Patron);   rescue NameError; end
         | 
| 33 33 | 
             
                end
         | 
| 34 34 |  | 
| 35 | 
            -
                should "allow to customize the Faraday adapter" do
         | 
| 35 | 
            +
                should "allow to customize the Faraday adapter to Typhoeus" do
         | 
| 36 36 | 
             
                  require 'typhoeus'
         | 
| 37 37 | 
             
                  require 'typhoeus/adapters/faraday'
         | 
| 38 38 |  | 
| @@ -42,6 +42,19 @@ class Elasticsearch::Transport::ClientIntegrationTest < Elasticsearch::Test::Int | |
| 42 42 | 
             
                      f.adapter  :typhoeus
         | 
| 43 43 | 
             
                    end
         | 
| 44 44 |  | 
| 45 | 
            +
                  client = Elasticsearch::Transport::Client.new transport: transport
         | 
| 46 | 
            +
                  client.perform_request 'GET', ''
         | 
| 47 | 
            +
                end unless jruby?
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                should "allow to customize the Faraday adapter to NetHttpPersistent" do
         | 
| 50 | 
            +
                  require 'net/http/persistent'
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                  transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new \
         | 
| 53 | 
            +
                                                                                   :hosts => [ { host: @host, port: @port } ] do |f|
         | 
| 54 | 
            +
                    f.response :logger
         | 
| 55 | 
            +
                    f.adapter  :net_http_persistent
         | 
| 56 | 
            +
                  end
         | 
| 57 | 
            +
             | 
| 45 58 | 
             
                  client = Elasticsearch::Transport::Client.new transport: transport
         | 
| 46 59 | 
             
                  client.perform_request 'GET', ''
         | 
| 47 60 | 
             
                end
         | 
| @@ -64,8 +64,8 @@ class Elasticsearch::Transport::Transport::Connections::ConnectionTest < Minites | |
| 64 64 |  | 
| 65 65 | 
             
                should "have a string representation" do
         | 
| 66 66 | 
             
                  c = Connection.new :host => 'x'
         | 
| 67 | 
            -
                  assert_match | 
| 68 | 
            -
                  assert_match | 
| 67 | 
            +
                  assert_match(/host: x/, c.to_s)
         | 
| 68 | 
            +
                  assert_match(/alive/,   c.to_s)
         | 
| 69 69 | 
             
                end
         | 
| 70 70 |  | 
| 71 71 | 
             
                should "not be dead by default" do
         | 
| @@ -429,7 +429,7 @@ class Elasticsearch::Transport::Transport::BaseTest < Minitest::Test | |
| 429 429 | 
             
                  @transport.stubs(:get_connection).returns(fake_connection)
         | 
| 430 430 |  | 
| 431 431 | 
             
                  @transport.logger.expects(:info).with do |message|
         | 
| 432 | 
            -
                    assert_match | 
| 432 | 
            +
                    assert_match(/http:\/\/user:\*{1,15}@localhost\:9200/, message)
         | 
| 433 433 | 
             
                    true
         | 
| 434 434 | 
             
                  end
         | 
| 435 435 |  | 
| @@ -149,7 +149,7 @@ class Elasticsearch::Transport::Transport::HTTP::FaradayTest < Minitest::Test | |
| 149 149 |  | 
| 150 150 | 
             
                  transport.connections.first.connection.expects(:run_request).
         | 
| 151 151 | 
             
                    with do |method, url, params, body|
         | 
| 152 | 
            -
                      assert_match | 
| 152 | 
            +
                      assert_match(/\?format=yaml/, url)
         | 
| 153 153 | 
             
                      true
         | 
| 154 154 | 
             
                    end.
         | 
| 155 155 | 
             
                    returns(stub_everything)
         | 
| @@ -167,7 +167,7 @@ class Elasticsearch::Transport::Transport::HTTP::FaradayTest < Minitest::Test | |
| 167 167 |  | 
| 168 168 | 
             
                  transport.connections.first.connection.expects(:run_request).
         | 
| 169 169 | 
             
                    with do |method, url, params, body|
         | 
| 170 | 
            -
                      assert_match | 
| 170 | 
            +
                      assert_match(/\?format=json/, url)
         | 
| 171 171 | 
             
                      true
         | 
| 172 172 | 
             
                    end.
         | 
| 173 173 | 
             
                    returns(stub_everything)
         | 
| @@ -145,8 +145,8 @@ else | |
| 145 145 | 
             
                    transport = Manticore.new :hosts => [ { :host => 'foobar', :port => 1234 } ], :options => options
         | 
| 146 146 | 
             
                    transport.connections.first.connection
         | 
| 147 147 | 
             
                      .expects(:get)
         | 
| 148 | 
            -
                      .with do |host,  | 
| 149 | 
            -
                        assert_equal 'myapp-0.0',  | 
| 148 | 
            +
                      .with do |host, _options|
         | 
| 149 | 
            +
                        assert_equal 'myapp-0.0', _options[:headers]['User-Agent']
         | 
| 150 150 | 
             
                        true
         | 
| 151 151 | 
             
                      end
         | 
| 152 152 | 
             
                      .returns(stub_everything)
         | 
    
        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. | 
| 4 | 
            +
              version: 7.13.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: 2021- | 
| 11 | 
            +
            date: 2021-05-11 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: multi_json
         | 
| @@ -425,11 +425,11 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 425 425 | 
             
                  version: '2.4'
         | 
| 426 426 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 427 427 | 
             
              requirements:
         | 
| 428 | 
            -
              - - " | 
| 428 | 
            +
              - - ">"
         | 
| 429 429 | 
             
                - !ruby/object:Gem::Version
         | 
| 430 | 
            -
                  version:  | 
| 430 | 
            +
                  version: 1.3.1
         | 
| 431 431 | 
             
            requirements: []
         | 
| 432 | 
            -
            rubygems_version: 3. | 
| 432 | 
            +
            rubygems_version: 3.2.16
         | 
| 433 433 | 
             
            signing_key: 
         | 
| 434 434 | 
             
            specification_version: 4
         | 
| 435 435 | 
             
            summary: Ruby client for Elasticsearch.
         |