elasticsearch-transport 7.11.1 → 7.11.2

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: a61db52575ad4a8669cbef5e60e6f90607f82155206c85e9e473835dfa35e0e5
4
- data.tar.gz: e8d2f1899f4ebf17cfafdfee98174f86ba52633f04d8fadd30ec9b4d31457546
3
+ metadata.gz: 07e3f02a3b166d00bcee76a0a39731ef5cc2c1aab442d4f6af2b4300a85661d6
4
+ data.tar.gz: 149090dcf60ef7f09637a42e23e33bcc78245872ff470bf064194fad59f2a19c
5
5
  SHA512:
6
- metadata.gz: 0ca54a9d0f096d1f8675ea7ef4d84da517f34ffeea31c9ce72f3c4a9257cfab33d6548582490ff7f87708a0ff3bc25a29c907274870d2ea22df34d7585c6d59e
7
- data.tar.gz: 854a17c7995ceede84fa87f73ccb7fafd8d57a8ff400429e8877258bd00e7cadbc69562400af8d682cb195b51599867bfce2fc84db151d3bff45c846844b188b
6
+ metadata.gz: a4919e34440ab8a91c2feafb2383e44b518b6b1f122ef59ddf26e35a93c2d1e23ef49f3b7f267eff7a51fd57de671cc66742358b1265ab5211362865ae40127f
7
+ data.tar.gz: b7b9f51e9232c29203cb110bf9e7b1002cffcaac4c583051795e83e590dc4c7a6ea3fd887d0a617f4ed0cb36e0d0e8593ed64c802894990b9c5dbf7eed657773
@@ -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
@@ -17,6 +17,6 @@
17
17
 
18
18
  module Elasticsearch
19
19
  module Transport
20
- VERSION = '7.11.1'.freeze
20
+ VERSION = '7.11.2'.freeze
21
21
  end
22
22
  end
@@ -32,7 +32,7 @@ describe Elasticsearch::Transport::Client do
32
32
  end
33
33
  end
34
34
 
35
- context 'client_meta_version_' do
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 defined?(JRUBY_VERSION)
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.11.1
4
+ version: 7.11.2
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-02-11 00:00:00.000000000 Z
11
+ date: 2021-02-25 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