elasticsearch-transport 7.10.0.pre → 7.11.1
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 +1 -1
- data/{LICENSE.txt → LICENSE} +0 -0
- data/README.md +13 -7
- data/elasticsearch-transport.gemspec +1 -1
- data/lib/elasticsearch/transport/client.rb +147 -48
- data/lib/elasticsearch/transport/transport/http/faraday.rb +10 -2
- data/lib/elasticsearch/transport/version.rb +1 -1
- data/spec/elasticsearch/transport/client_spec.rb +357 -110
- data/spec/elasticsearch/transport/meta_header_spec.rb +225 -0
- metadata +10 -8
@@ -0,0 +1,225 @@
|
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
6
|
+
# not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
17
|
+
|
18
|
+
require 'spec_helper'
|
19
|
+
|
20
|
+
describe Elasticsearch::Transport::Client do
|
21
|
+
context 'meta-header' do
|
22
|
+
let(:subject) { client.transport.connections.first.connection.headers }
|
23
|
+
let(:client) { described_class.new }
|
24
|
+
let(:regexp) { /^[a-z]{1,}=[a-z0-9.\-]{1,}(?:,[a-z]{1,}=[a-z0-9._\-]+)*$/ }
|
25
|
+
let(:adapter) { :net_http }
|
26
|
+
let(:adapter_code) { "nh=#{defined?(Net::HTTP::VERSION) ? Net::HTTP::VERSION : Net::HTTP::HTTPVersion}" }
|
27
|
+
let(:meta_header) do
|
28
|
+
if jruby?
|
29
|
+
"es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION},jv=#{ENV_JAVA['java.version']},jr=#{JRUBY_VERSION},fd=#{Faraday::VERSION},#{adapter_code}"
|
30
|
+
else
|
31
|
+
"es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION},fd=#{Faraday::VERSION},#{adapter_code}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'client_meta_version_' do
|
36
|
+
let(:version) { ['7.1.0-alpha', '7.11.0.pre.1', '8.0.0-beta', '8.0.0.beta.2']}
|
37
|
+
|
38
|
+
it 'converts the version to X.X.Xp' do
|
39
|
+
expect(client.send(:client_meta_version, '7.0.0-alpha')).to eq('7.0.0p')
|
40
|
+
expect(client.send(:client_meta_version, '7.11.0.pre.1')).to eq('7.11.0p')
|
41
|
+
expect(client.send(:client_meta_version, '8.1.0-beta')).to eq('8.1.0p')
|
42
|
+
expect(client.send(:client_meta_version, '8.0.0.beta.2')).to eq('8.0.0p')
|
43
|
+
expect(client.send(:client_meta_version, '12.16.4.pre')).to eq('12.16.4p')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# We are testing this method in the previous block, so now using it inside the test to make the
|
48
|
+
# Elasticsearch version in the meta header string dynamic
|
49
|
+
def meta_version
|
50
|
+
client.send(:client_meta_version, Elasticsearch::VERSION)
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'single use of meta header' do
|
54
|
+
let(:client) do
|
55
|
+
described_class.new(adapter: adapter).tap do |klient|
|
56
|
+
allow(klient).to receive(:__build_connections)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'x-elastic-client-header value matches regexp' do
|
61
|
+
expect(subject['x-elastic-client-meta']).to match(regexp)
|
62
|
+
expect(subject).to include('x-elastic-client-meta' => meta_header)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'when using user-agent headers' do
|
67
|
+
let(:client) do
|
68
|
+
transport_options = { headers: { user_agent: 'My Ruby App' } }
|
69
|
+
described_class.new(transport_options: transport_options, adapter: adapter).tap do |klient|
|
70
|
+
allow(klient).to receive(:__build_connections)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'is friendly to previously set headers' do
|
75
|
+
expect(subject).to include(user_agent: 'My Ruby App')
|
76
|
+
expect(subject['x-elastic-client-meta']).to match(regexp)
|
77
|
+
expect(subject).to include('x-elastic-client-meta' => meta_header)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'when using API Key' do
|
82
|
+
let(:client) do
|
83
|
+
described_class.new(api_key: 'an_api_key', adapter: adapter)
|
84
|
+
end
|
85
|
+
|
86
|
+
let(:authorization_header) do
|
87
|
+
client.transport.connections.first.connection.headers['Authorization']
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'adds the ApiKey header to the connection' do
|
91
|
+
expect(authorization_header).to eq('ApiKey an_api_key')
|
92
|
+
expect(subject['x-elastic-client-meta']).to match(regexp)
|
93
|
+
expect(subject).to include('x-elastic-client-meta' => meta_header)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context 'adapters' do
|
98
|
+
let(:meta_header) do
|
99
|
+
if jruby?
|
100
|
+
"es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION},jv=#{ENV_JAVA['java.version']},jr=#{JRUBY_VERSION},fd=#{Faraday::VERSION}"
|
101
|
+
else
|
102
|
+
"es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION},fd=#{Faraday::VERSION}"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
let(:client) { described_class.new(adapter: adapter) }
|
106
|
+
let(:headers) { client.transport.connections.first.connection.headers }
|
107
|
+
|
108
|
+
context 'using net/http/persistent' do
|
109
|
+
let(:adapter) { :net_http_persistent }
|
110
|
+
|
111
|
+
it 'sets adapter in the meta header' do
|
112
|
+
require 'net/http/persistent'
|
113
|
+
expect(headers['x-elastic-client-meta']).to match(regexp)
|
114
|
+
meta = "#{meta_header},np=#{Net::HTTP::Persistent::VERSION}"
|
115
|
+
expect(headers).to include('x-elastic-client-meta' => meta)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context 'using httpclient' do
|
120
|
+
let(:adapter) { :httpclient }
|
121
|
+
|
122
|
+
it 'sets adapter in the meta header' do
|
123
|
+
require 'httpclient'
|
124
|
+
expect(headers['x-elastic-client-meta']).to match(regexp)
|
125
|
+
meta = "#{meta_header},hc=#{HTTPClient::VERSION}"
|
126
|
+
expect(headers).to include('x-elastic-client-meta' => meta)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
context 'using typhoeus' do
|
131
|
+
let(:adapter) { :typhoeus }
|
132
|
+
|
133
|
+
it 'sets adapter in the meta header' do
|
134
|
+
require 'typhoeus'
|
135
|
+
expect(headers['x-elastic-client-meta']).to match(regexp)
|
136
|
+
meta = "#{meta_header},ty=#{Typhoeus::VERSION}"
|
137
|
+
expect(headers).to include('x-elastic-client-meta' => meta)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
unless defined?(JRUBY_VERSION)
|
142
|
+
let(:adapter) { :patron }
|
143
|
+
|
144
|
+
context 'using patron' do
|
145
|
+
it 'sets adapter in the meta header' do
|
146
|
+
require 'patron'
|
147
|
+
expect(headers['x-elastic-client-meta']).to match(regexp)
|
148
|
+
meta = "#{meta_header},pt=#{Patron::VERSION}"
|
149
|
+
expect(headers).to include('x-elastic-client-meta' => meta)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context 'using other' do
|
155
|
+
let(:adapter) { :some_other_adapter }
|
156
|
+
|
157
|
+
it 'sets adapter in the meta header' do
|
158
|
+
require 'net/http/persistent'
|
159
|
+
Faraday::Adapter.register_middleware some_other_adapter: Faraday::Adapter::NetHttpPersistent
|
160
|
+
expect(headers['x-elastic-client-meta']).to match(regexp)
|
161
|
+
expect(headers).to include('x-elastic-client-meta' => meta_header)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
if defined?(JRUBY_VERSION)
|
167
|
+
context 'when using manticore' do
|
168
|
+
let(:client) do
|
169
|
+
Elasticsearch::Client.new(transport_class: Elasticsearch::Transport::Transport::HTTP::Manticore)
|
170
|
+
end
|
171
|
+
let(:subject) { client.transport.connections.first.connection.instance_variable_get("@options")[:headers]}
|
172
|
+
|
173
|
+
it 'sets manticore in the metaheader' do
|
174
|
+
expect(subject['x-elastic-client-meta']).to match(regexp)
|
175
|
+
expect(subject['x-elastic-client-meta']).to match(/mc=[0-9.]+/)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
else
|
179
|
+
context 'when using curb' do
|
180
|
+
let(:client) do
|
181
|
+
Elasticsearch::Client.new(transport_class: Elasticsearch::Transport::Transport::HTTP::Curb)
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'sets curb in the metaheader' do
|
185
|
+
expect(subject['x-elastic-client-meta']).to match(regexp)
|
186
|
+
expect(subject['x-elastic-client-meta']).to match(/cl=[0-9.]+/)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
context 'when using custom transport implementation' do
|
192
|
+
class MyTransport
|
193
|
+
include Elasticsearch::Transport::Transport::Base
|
194
|
+
def initialize(args); end
|
195
|
+
end
|
196
|
+
let(:client) { Elasticsearch::Client.new(transport_class: MyTransport) }
|
197
|
+
let(:subject){ client.instance_variable_get("@arguments")[:transport_options][:headers] }
|
198
|
+
let(:meta_header) do
|
199
|
+
if jruby?
|
200
|
+
"es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION},jv=#{ENV_JAVA['java.version']},jr=#{JRUBY_VERSION}"
|
201
|
+
else
|
202
|
+
"es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION}"
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
it 'doesnae set any info about the implementation in the metaheader' do
|
207
|
+
expect(subject['x-elastic-client-meta']).to match(regexp)
|
208
|
+
expect(subject).to include('x-elastic-client-meta' => meta_header)
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
context 'when using a different service version' do
|
213
|
+
before do
|
214
|
+
stub_const("Elastic::META_HEADER_SERVICE_VERSION", [:ent, '8.0.0'])
|
215
|
+
end
|
216
|
+
|
217
|
+
let(:client) { Elasticsearch::Client.new }
|
218
|
+
|
219
|
+
it 'sets the service version in the metaheader' do
|
220
|
+
expect(subject['x-elastic-client-meta']).to match(regexp)
|
221
|
+
expect(subject['x-elastic-client-meta']).to start_with('ent=8.0.0')
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
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.11.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Karel Minarik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -355,18 +355,18 @@ dependencies:
|
|
355
355
|
description: 'Ruby client for Elasticsearch. See the `elasticsearch` gem for full
|
356
356
|
integration.
|
357
357
|
|
358
|
-
'
|
358
|
+
'
|
359
359
|
email:
|
360
360
|
- karel.minarik@elasticsearch.org
|
361
361
|
executables: []
|
362
362
|
extensions: []
|
363
363
|
extra_rdoc_files:
|
364
364
|
- README.md
|
365
|
-
- LICENSE
|
365
|
+
- LICENSE
|
366
366
|
files:
|
367
367
|
- ".gitignore"
|
368
368
|
- Gemfile
|
369
|
-
- LICENSE
|
369
|
+
- LICENSE
|
370
370
|
- README.md
|
371
371
|
- Rakefile
|
372
372
|
- elasticsearch-transport.gemspec
|
@@ -391,6 +391,7 @@ files:
|
|
391
391
|
- spec/elasticsearch/connections/selector_spec.rb
|
392
392
|
- spec/elasticsearch/transport/base_spec.rb
|
393
393
|
- spec/elasticsearch/transport/client_spec.rb
|
394
|
+
- spec/elasticsearch/transport/meta_header_spec.rb
|
394
395
|
- spec/elasticsearch/transport/sniffer_spec.rb
|
395
396
|
- spec/spec_helper.rb
|
396
397
|
- test/integration/transport_test.rb
|
@@ -423,11 +424,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
423
424
|
version: '2.4'
|
424
425
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
425
426
|
requirements:
|
426
|
-
- - "
|
427
|
+
- - ">="
|
427
428
|
- !ruby/object:Gem::Version
|
428
|
-
version:
|
429
|
+
version: '0'
|
429
430
|
requirements: []
|
430
|
-
rubygems_version: 3.1.
|
431
|
+
rubygems_version: 3.1.4
|
431
432
|
signing_key:
|
432
433
|
specification_version: 4
|
433
434
|
summary: Ruby client for Elasticsearch.
|
@@ -436,6 +437,7 @@ test_files:
|
|
436
437
|
- spec/elasticsearch/connections/selector_spec.rb
|
437
438
|
- spec/elasticsearch/transport/base_spec.rb
|
438
439
|
- spec/elasticsearch/transport/client_spec.rb
|
440
|
+
- spec/elasticsearch/transport/meta_header_spec.rb
|
439
441
|
- spec/elasticsearch/transport/sniffer_spec.rb
|
440
442
|
- spec/spec_helper.rb
|
441
443
|
- test/integration/transport_test.rb
|