elasticsearch-transport 7.11.1 → 7.12.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc7f64d6af1a163b0f6a2fb2f95aaab42e8f797b998e4a3d34fed1bc21ea3ccb
|
4
|
+
data.tar.gz: 1b00c2e0cdd62483465ca14d093475a7ec2f9d976e2e50565c8e27b44b06634d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0899b3da62ed4fd0fd7d6d02defa75354d85fd05ed83c9ac3fa40e6ea597011620f84ad38c30273e7fb11deb4e34f2dd3a469407a6848f56ecdcdaf35fb53a8e'
|
7
|
+
data.tar.gz: 41e7690ac6a1d40f7632ae91a16bf707040bda14783074caceaa7f91ab1f66d4c3d58b6c5ec6b2a581c4f7d69e6db94f4e849c15f5d3b8db3bed584f943c655c
|
@@ -16,6 +16,7 @@
|
|
16
16
|
# under the License.
|
17
17
|
|
18
18
|
require 'base64'
|
19
|
+
require 'elasticsearch/transport/meta_header'
|
19
20
|
|
20
21
|
module Elasticsearch
|
21
22
|
module Transport
|
@@ -25,6 +26,7 @@ module Elasticsearch
|
|
25
26
|
# See {file:README.md README} for usage and code examples.
|
26
27
|
#
|
27
28
|
class Client
|
29
|
+
include MetaHeader
|
28
30
|
DEFAULT_TRANSPORT_CLASS = Transport::HTTP::Faraday
|
29
31
|
|
30
32
|
DEFAULT_LOGGER = lambda do
|
@@ -165,13 +167,13 @@ module Elasticsearch
|
|
165
167
|
@transport_class = @arguments[:transport_class] || DEFAULT_TRANSPORT_CLASS
|
166
168
|
@transport = if @transport_class == Transport::HTTP::Faraday
|
167
169
|
@arguments[:adapter] ||= __auto_detect_adapter
|
168
|
-
set_meta_header
|
170
|
+
set_meta_header # from include MetaHeader
|
169
171
|
@transport_class.new(hosts: @seeds, options: @arguments) do |faraday|
|
170
172
|
faraday.adapter(@arguments[:adapter])
|
171
173
|
block&.call faraday
|
172
174
|
end
|
173
175
|
else
|
174
|
-
set_meta_header
|
176
|
+
set_meta_header # from include MetaHeader
|
175
177
|
@transport_class.new(hosts: @seeds, options: @arguments)
|
176
178
|
end
|
177
179
|
end
|
@@ -206,78 +208,6 @@ module Elasticsearch
|
|
206
208
|
)
|
207
209
|
end
|
208
210
|
|
209
|
-
def set_meta_header
|
210
|
-
return if @arguments[:enable_meta_header] == false
|
211
|
-
|
212
|
-
service, version = meta_header_service_version
|
213
|
-
|
214
|
-
meta_headers = {
|
215
|
-
service.to_sym => version,
|
216
|
-
rb: RUBY_VERSION,
|
217
|
-
t: Elasticsearch::Transport::VERSION
|
218
|
-
}
|
219
|
-
meta_headers.merge!(meta_header_engine) if meta_header_engine
|
220
|
-
meta_headers.merge!(meta_header_adapter) if meta_header_adapter
|
221
|
-
|
222
|
-
add_header({ 'x-elastic-client-meta' => meta_headers.map { |k, v| "#{k}=#{v}" }.join(',') })
|
223
|
-
end
|
224
|
-
|
225
|
-
def meta_header_service_version
|
226
|
-
if defined?(Elastic::META_HEADER_SERVICE_VERSION)
|
227
|
-
Elastic::META_HEADER_SERVICE_VERSION
|
228
|
-
elsif defined?(Elasticsearch::VERSION)
|
229
|
-
[:es, client_meta_version(Elasticsearch::VERSION)]
|
230
|
-
else
|
231
|
-
[:es, client_meta_version(Elasticsearch::Transport::VERSION)]
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
def client_meta_version(version)
|
236
|
-
regexp = /^([0-9]+\.[0-9]+\.[0-9]+)(\.?[a-z0-9.-]+)?$/
|
237
|
-
match = version.match(regexp)
|
238
|
-
return "#{match[1]}p" if (match[2])
|
239
|
-
|
240
|
-
version
|
241
|
-
end
|
242
|
-
|
243
|
-
def meta_header_engine
|
244
|
-
case RUBY_ENGINE
|
245
|
-
when 'ruby'
|
246
|
-
{}
|
247
|
-
when 'jruby'
|
248
|
-
{ jv: ENV_JAVA['java.version'], jr: JRUBY_VERSION }
|
249
|
-
when 'rbx'
|
250
|
-
{ rbx: RUBY_VERSION }
|
251
|
-
else
|
252
|
-
{ RUBY_ENGINE.to_sym => RUBY_VERSION }
|
253
|
-
end
|
254
|
-
end
|
255
|
-
|
256
|
-
def meta_header_adapter
|
257
|
-
if @transport_class == Transport::HTTP::Faraday
|
258
|
-
{fd: Faraday::VERSION}.merge(
|
259
|
-
case @arguments[:adapter]
|
260
|
-
when :patron
|
261
|
-
{pt: Patron::VERSION}
|
262
|
-
when :net_http
|
263
|
-
{nh: defined?(Net::HTTP::VERSION) ? Net::HTTP::VERSION : Net::HTTP::HTTPVersion}
|
264
|
-
when :typhoeus
|
265
|
-
{ty: Typhoeus::VERSION}
|
266
|
-
when :httpclient
|
267
|
-
{hc: HTTPClient::VERSION}
|
268
|
-
when :net_http_persistent
|
269
|
-
{np: Net::HTTP::Persistent::VERSION}
|
270
|
-
else
|
271
|
-
{}
|
272
|
-
end
|
273
|
-
)
|
274
|
-
elsif defined?(Transport::HTTP::Curb) && @transport_class == Transport::HTTP::Curb
|
275
|
-
{cl: Curl::CURB_VERSION}
|
276
|
-
elsif defined?(Transport::HTTP::Manticore) && @transport_class == Transport::HTTP::Manticore
|
277
|
-
{mc: Manticore::VERSION}
|
278
|
-
end
|
279
|
-
end
|
280
|
-
|
281
211
|
def extract_cloud_creds(arguments)
|
282
212
|
return unless arguments[:cloud_id] && !arguments[:cloud_id].empty?
|
283
213
|
|
@@ -0,0 +1,120 @@
|
|
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 'base64'
|
19
|
+
|
20
|
+
module Elasticsearch
|
21
|
+
module Transport
|
22
|
+
|
23
|
+
# Methods for the Elastic meta header used by Cloud.
|
24
|
+
# X-Elastic-Client-Meta HTTP header which is used by Elastic Cloud and can be disabled when
|
25
|
+
# instantiating the Client with the :enable_meta_header parameter set to `false`.
|
26
|
+
#
|
27
|
+
module MetaHeader
|
28
|
+
def set_meta_header
|
29
|
+
return if @arguments[:enable_meta_header] == false
|
30
|
+
|
31
|
+
service, version = meta_header_service_version
|
32
|
+
|
33
|
+
meta_headers = {
|
34
|
+
service.to_sym => version,
|
35
|
+
rb: RUBY_VERSION,
|
36
|
+
t: Elasticsearch::Transport::VERSION
|
37
|
+
}
|
38
|
+
meta_headers.merge!(meta_header_engine) if meta_header_engine
|
39
|
+
meta_headers.merge!(meta_header_adapter) if meta_header_adapter
|
40
|
+
|
41
|
+
add_header({ 'x-elastic-client-meta' => meta_headers.map { |k, v| "#{k}=#{v}" }.join(',') })
|
42
|
+
end
|
43
|
+
|
44
|
+
def meta_header_service_version
|
45
|
+
if defined?(Elastic::META_HEADER_SERVICE_VERSION)
|
46
|
+
Elastic::META_HEADER_SERVICE_VERSION
|
47
|
+
elsif defined?(Elasticsearch::VERSION)
|
48
|
+
[:es, client_meta_version(Elasticsearch::VERSION)]
|
49
|
+
else
|
50
|
+
[:es, client_meta_version(Elasticsearch::Transport::VERSION)]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# We return the current version if it's a release, but if it's a pre/alpha/beta release we
|
55
|
+
# return <VERSION_NUMBER>p
|
56
|
+
#
|
57
|
+
def client_meta_version(version)
|
58
|
+
regexp = /^([0-9]+\.[0-9]+\.[0-9]+)(\.?[a-z0-9.-]+)?$/
|
59
|
+
match = version.match(regexp)
|
60
|
+
return "#{match[1]}p" if (match[2])
|
61
|
+
|
62
|
+
version
|
63
|
+
end
|
64
|
+
|
65
|
+
def meta_header_engine
|
66
|
+
case RUBY_ENGINE
|
67
|
+
when 'ruby'
|
68
|
+
{}
|
69
|
+
when 'jruby'
|
70
|
+
{ jv: ENV_JAVA['java.version'], jr: JRUBY_VERSION }
|
71
|
+
when 'rbx'
|
72
|
+
{ rbx: RUBY_VERSION }
|
73
|
+
else
|
74
|
+
{ RUBY_ENGINE.to_sym => RUBY_VERSION }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# This function tries to define the version for the Faraday adapter. If it hasn't been loaded
|
79
|
+
# by the time we're calling this method, it's going to report the adapter (if we know it) but
|
80
|
+
# return 0 as the version. It won't report anything when using a custom adapter we don't
|
81
|
+
# identify.
|
82
|
+
#
|
83
|
+
# Returns a Hash<adapter_alias, version>
|
84
|
+
#
|
85
|
+
def meta_header_adapter
|
86
|
+
if @transport_class == Transport::HTTP::Faraday
|
87
|
+
version = '0'
|
88
|
+
adapter_version = case @arguments[:adapter]
|
89
|
+
when :patron
|
90
|
+
version = Patron::VERSION if defined?(::Patron::VERSION)
|
91
|
+
{pt: version}
|
92
|
+
when :net_http
|
93
|
+
version = if defined?(Net::HTTP::VERSION)
|
94
|
+
Net::HTTP::VERSION
|
95
|
+
elsif defined?(Net::HTTP::HTTPVersion)
|
96
|
+
Net::HTTP::HTTPVersion
|
97
|
+
end
|
98
|
+
{nh: version}
|
99
|
+
when :typhoeus
|
100
|
+
version = Typhoeus::VERSION if defined?(::Typhoeus::VERSION)
|
101
|
+
{ty: version}
|
102
|
+
when :httpclient
|
103
|
+
version = HTTPClient::VERSION if defined?(HTTPClient::VERSION)
|
104
|
+
{hc: version}
|
105
|
+
when :net_http_persistent
|
106
|
+
version = Net::HTTP::Persistent::VERSION if defined?(Net::HTTP::Persistent::VERSION)
|
107
|
+
{np: version}
|
108
|
+
else
|
109
|
+
{}
|
110
|
+
end
|
111
|
+
{fd: Faraday::VERSION}.merge(adapter_version)
|
112
|
+
elsif defined?(Transport::HTTP::Curb) && @transport_class == Transport::HTTP::Curb
|
113
|
+
{cl: Curl::CURB_VERSION}
|
114
|
+
elsif defined?(Transport::HTTP::Manticore) && @transport_class == Transport::HTTP::Manticore
|
115
|
+
{mc: Manticore::VERSION}
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -32,7 +32,7 @@ describe Elasticsearch::Transport::Client do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
context '
|
35
|
+
context 'client_meta_version' do
|
36
36
|
let(:version) { ['7.1.0-alpha', '7.11.0.pre.1', '8.0.0-beta', '8.0.0.beta.2']}
|
37
37
|
|
38
38
|
it 'converts the version to X.X.Xp' do
|
@@ -108,6 +108,14 @@ describe Elasticsearch::Transport::Client do
|
|
108
108
|
context 'using net/http/persistent' do
|
109
109
|
let(:adapter) { :net_http_persistent }
|
110
110
|
|
111
|
+
it 'sets adapter in the meta header version to 0 when not loaded' do
|
112
|
+
fork {
|
113
|
+
expect(headers['x-elastic-client-meta']).to match(regexp)
|
114
|
+
meta = "#{meta_header},np=0"
|
115
|
+
expect(headers).to include('x-elastic-client-meta' => meta)
|
116
|
+
}
|
117
|
+
end unless jruby?
|
118
|
+
|
111
119
|
it 'sets adapter in the meta header' do
|
112
120
|
require 'net/http/persistent'
|
113
121
|
expect(headers['x-elastic-client-meta']).to match(regexp)
|
@@ -119,6 +127,14 @@ describe Elasticsearch::Transport::Client do
|
|
119
127
|
context 'using httpclient' do
|
120
128
|
let(:adapter) { :httpclient }
|
121
129
|
|
130
|
+
it 'sets adapter in the meta header version to 0 when not loaded' do
|
131
|
+
fork {
|
132
|
+
expect(headers['x-elastic-client-meta']).to match(regexp)
|
133
|
+
meta = "#{meta_header},hc=0"
|
134
|
+
expect(headers).to include('x-elastic-client-meta' => meta)
|
135
|
+
}
|
136
|
+
end unless jruby?
|
137
|
+
|
122
138
|
it 'sets adapter in the meta header' do
|
123
139
|
require 'httpclient'
|
124
140
|
expect(headers['x-elastic-client-meta']).to match(regexp)
|
@@ -130,6 +146,14 @@ describe Elasticsearch::Transport::Client do
|
|
130
146
|
context 'using typhoeus' do
|
131
147
|
let(:adapter) { :typhoeus }
|
132
148
|
|
149
|
+
it 'sets adapter in the meta header version to 0 when not loaded' do
|
150
|
+
fork {
|
151
|
+
expect(headers['x-elastic-client-meta']).to match(regexp)
|
152
|
+
meta = "#{meta_header},ty=0"
|
153
|
+
expect(headers).to include('x-elastic-client-meta' => meta)
|
154
|
+
}
|
155
|
+
end unless jruby?
|
156
|
+
|
133
157
|
it 'sets adapter in the meta header' do
|
134
158
|
require 'typhoeus'
|
135
159
|
expect(headers['x-elastic-client-meta']).to match(regexp)
|
@@ -138,9 +162,19 @@ describe Elasticsearch::Transport::Client do
|
|
138
162
|
end
|
139
163
|
end
|
140
164
|
|
141
|
-
unless
|
165
|
+
unless jruby?
|
142
166
|
let(:adapter) { :patron }
|
143
167
|
|
168
|
+
context 'using patron without requiring it' do
|
169
|
+
it 'sets adapter in the meta header version to 0 when not loaded' do
|
170
|
+
fork {
|
171
|
+
expect(headers['x-elastic-client-meta']).to match(regexp)
|
172
|
+
meta = "#{meta_header},pt=0"
|
173
|
+
expect(headers).to include('x-elastic-client-meta' => meta)
|
174
|
+
}
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
144
178
|
context 'using patron' do
|
145
179
|
it 'sets adapter in the meta header' do
|
146
180
|
require 'patron'
|
@@ -154,6 +188,12 @@ describe Elasticsearch::Transport::Client do
|
|
154
188
|
context 'using other' do
|
155
189
|
let(:adapter) { :some_other_adapter }
|
156
190
|
|
191
|
+
it 'sets adapter in the meta header without requiring' do
|
192
|
+
Faraday::Adapter.register_middleware some_other_adapter: Faraday::Adapter::NetHttpPersistent
|
193
|
+
expect(headers['x-elastic-client-meta']).to match(regexp)
|
194
|
+
expect(headers).to include('x-elastic-client-meta' => meta_header)
|
195
|
+
end
|
196
|
+
|
157
197
|
it 'sets adapter in the meta header' do
|
158
198
|
require 'net/http/persistent'
|
159
199
|
Faraday::Adapter.register_middleware some_other_adapter: Faraday::Adapter::NetHttpPersistent
|
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.12.0
|
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-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -373,6 +373,7 @@ files:
|
|
373
373
|
- lib/elasticsearch-transport.rb
|
374
374
|
- lib/elasticsearch/transport.rb
|
375
375
|
- lib/elasticsearch/transport/client.rb
|
376
|
+
- lib/elasticsearch/transport/meta_header.rb
|
376
377
|
- lib/elasticsearch/transport/redacted.rb
|
377
378
|
- lib/elasticsearch/transport/transport/base.rb
|
378
379
|
- lib/elasticsearch/transport/transport/connections/collection.rb
|