elastic-transport 8.0.0.pre2 → 8.0.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/.github/workflows/tests.yml +1 -1
- data/CHANGELOG.md +9 -5
- data/lib/elastic/transport/client.rb +0 -8
- data/lib/elastic/transport/meta_header.rb +1 -1
- data/lib/elastic/transport/transport/base.rb +1 -1
- data/lib/elastic/transport/transport/http/manticore.rb +31 -27
- data/lib/elastic/transport/version.rb +1 -1
- data/spec/elastic/transport/meta_header_spec.rb +24 -9
- data/test/unit/transport_manticore_test.rb +39 -22
- 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: 51e53310c92bb9b3e3cb43d0ffb2587e980218f6a4de9052f21fa1dee645b319
|
4
|
+
data.tar.gz: 960f931aff3f04f14d93c45d585b37e1bc23fcf6273d731c7c3ec3d7a217bea3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77748ed0f93bbf3c065331bb4d6bc2b76b5ee254a1412728b68feb4c7679277a3eafb39bfd3267a67374cc410b2f9277ceea42e899869624134af5cf7f8429e2
|
7
|
+
data.tar.gz: 645430db2265232b924d2c85877cde70d7e54d8c4ad5f2a0b98003419c61db42ffe0f1629a964436ca4fcbfb1bca5fe29b97f8991784170af6f8219ee83eaed4
|
data/.github/workflows/tests.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,13 +1,17 @@
|
|
1
|
-
## 8.0.
|
1
|
+
## 8.0.1
|
2
2
|
|
3
|
+
- Minor code cleanup
|
4
|
+
- Adds Elastic Transport service token, updates specs for meta header.
|
5
|
+
|
6
|
+
## 8.0.0
|
7
|
+
|
8
|
+
- Library renamed from [`elasticsearch-transport`](https://github.com/elastic/elasticsearch-ruby/tree/7.x/elasticsearch-transport) to `elastic-transport` and promoted to its own repository.
|
3
9
|
- Fixes tracing for Manticore [commit](https://github.com/elastic/elastic-transport-ruby/commit/98c81d19de4fee394f9c1a5079a1892ec951e0f9).
|
4
10
|
- Implements CA Fingerprinting [pull request](https://github.com/elastic/elastic-transport-ruby/pull/13)
|
5
11
|
- Adds `delay_on_retry` to wait between each failed connection, thanks @DinoPullerUqido! [commit](https://github.com/elastic/elastic-transport-ruby/commit/c2f8311409ca63a293588cb7eea5a0c672dbd436)
|
6
12
|
- Fixes compression, thanks @johnnyshields! [commit](https://github.com/elastic/elastic-transport-ruby/commit/8b326d643f76f037075500e19bbe096b2c298099)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
- Library renamed from [`elasticsearch-transport`](https://github.com/elastic/elasticsearch-ruby/tree/7.x/elasticsearch-transport) to `elastic-transport` and promoted to its own repository.
|
13
|
+
- Tested in Ruby 3.1, JRuby 9.3, drops Ruby 2.5 in test Matrix. Version 8.0.0 tested for Ruby (MRI) 2.6, 2.7, 3.0 and 3.1 and JRuby 9.3.
|
14
|
+
- Updates Manticore implementation headers setup. When using the Manticore HTTP implementation, adding a custom `User-Agent` value in the headers on initialization would get overwritten. [Pull Request](https://github.com/elastic/elastic-transport-ruby/pull/22) - [Issue reported in elastic/elasticsearch-ruby#1684](https://github.com/elastic/elasticsearch-ruby/issues/1684).
|
11
15
|
|
12
16
|
# Changes from elasticsearch-transport:
|
13
17
|
|
@@ -211,14 +211,6 @@ module Elastic
|
|
211
211
|
)
|
212
212
|
end
|
213
213
|
|
214
|
-
def add_header(header)
|
215
|
-
headers = @arguments[:transport_options]&.[](:headers) || {}
|
216
|
-
headers.merge!(header)
|
217
|
-
@arguments[:transport_options].merge!(
|
218
|
-
headers: headers
|
219
|
-
)
|
220
|
-
end
|
221
|
-
|
222
214
|
# Normalizes and returns hosts configuration.
|
223
215
|
#
|
224
216
|
# Arrayifies the `hosts_config` argument and extracts `host` and `port` info from strings.
|
@@ -62,14 +62,20 @@ module Elastic
|
|
62
62
|
class Manticore
|
63
63
|
include Base
|
64
64
|
|
65
|
-
def initialize(arguments={}, &block)
|
66
|
-
@request_options = {
|
65
|
+
def initialize(arguments = {}, &block)
|
66
|
+
@request_options = {
|
67
|
+
headers: (
|
68
|
+
arguments.dig(:transport_options, :headers) ||
|
69
|
+
arguments.dig(:options, :transport_options, :headers) ||
|
70
|
+
{}
|
71
|
+
)
|
72
|
+
}
|
67
73
|
@manticore = build_client(arguments[:options] || {})
|
68
74
|
super(arguments, &block)
|
69
75
|
end
|
70
76
|
|
71
77
|
# Should just be run once at startup
|
72
|
-
def build_client(options={})
|
78
|
+
def build_client(options = {})
|
73
79
|
client_options = options[:transport_options] || {}
|
74
80
|
client_options[:ssl] = options[:ssl] || {}
|
75
81
|
|
@@ -81,7 +87,7 @@ module Elastic
|
|
81
87
|
# @return [Response]
|
82
88
|
# @see Transport::Base#perform_request
|
83
89
|
#
|
84
|
-
def perform_request(method, path, params={}, body=nil, headers=nil, opts={})
|
90
|
+
def perform_request(method, path, params = {}, body = nil, headers = nil, opts = {})
|
85
91
|
super do |connection, url|
|
86
92
|
body = body ? __convert_to_json(body) : nil
|
87
93
|
body, headers = compress_request(body, @request_options[:headers])
|
@@ -90,20 +96,20 @@ module Elastic
|
|
90
96
|
params[:headers] = headers if headers
|
91
97
|
params = params.merge @request_options
|
92
98
|
case method
|
93
|
-
when
|
99
|
+
when 'GET'
|
94
100
|
resp = connection.connection.get(url, params)
|
95
|
-
when
|
101
|
+
when 'HEAD'
|
96
102
|
resp = connection.connection.head(url, params)
|
97
|
-
when
|
103
|
+
when 'PUT'
|
98
104
|
resp = connection.connection.put(url, params)
|
99
|
-
when
|
105
|
+
when 'POST'
|
100
106
|
resp = connection.connection.post(url, params)
|
101
|
-
when
|
107
|
+
when 'DELETE'
|
102
108
|
resp = connection.connection.delete(url, params)
|
103
109
|
else
|
104
110
|
raise ArgumentError.new "Method #{method} not supported"
|
105
111
|
end
|
106
|
-
Response.new
|
112
|
+
Response.new(resp.code, resp.read_body, resp.headers)
|
107
113
|
end
|
108
114
|
end
|
109
115
|
|
@@ -113,23 +119,21 @@ module Elastic
|
|
113
119
|
# @return [Connections::Collection]
|
114
120
|
#
|
115
121
|
def __build_connections
|
116
|
-
apply_headers(
|
117
|
-
apply_headers(@request_options, options)
|
122
|
+
apply_headers(options)
|
118
123
|
|
119
|
-
Connections::Collection.new
|
120
|
-
:
|
121
|
-
host[:protocol]
|
122
|
-
host[:port]
|
124
|
+
Connections::Collection.new(
|
125
|
+
connections: hosts.map do |host|
|
126
|
+
host[:protocol] = host[:scheme] || DEFAULT_PROTOCOL
|
127
|
+
host[:port] ||= DEFAULT_PORT
|
123
128
|
|
124
129
|
host.delete(:user) # auth is not supported here.
|
125
130
|
host.delete(:password) # use the headers
|
126
131
|
|
127
|
-
Connections::Connection.new
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
:selector => options[:selector]
|
132
|
+
Connections::Connection.new(host: host, connection: @manticore)
|
133
|
+
end,
|
134
|
+
selector_class: options[:selector_class],
|
135
|
+
selector: options[:selector]
|
136
|
+
)
|
133
137
|
end
|
134
138
|
|
135
139
|
# Closes all connections by marking them as dead
|
@@ -157,16 +161,16 @@ module Elastic
|
|
157
161
|
|
158
162
|
private
|
159
163
|
|
160
|
-
def apply_headers(
|
161
|
-
headers = options
|
164
|
+
def apply_headers(options)
|
165
|
+
headers = options[:headers] || options.dig(:transport_options, :headers) || {}
|
162
166
|
headers[CONTENT_TYPE_STR] = find_value(headers, CONTENT_TYPE_REGEX) || DEFAULT_CONTENT_TYPE
|
163
|
-
headers[USER_AGENT_STR] = find_value(headers, USER_AGENT_REGEX) || user_agent_header
|
167
|
+
headers[USER_AGENT_STR] = find_value(headers, USER_AGENT_REGEX) || find_value(@request_options[:headers], USER_AGENT_REGEX) || user_agent_header
|
164
168
|
headers[ACCEPT_ENCODING] = GZIP if use_compression?
|
165
|
-
request_options[:headers].merge!(headers)
|
169
|
+
@request_options[:headers].merge!(headers)
|
166
170
|
end
|
167
171
|
|
168
172
|
def user_agent_header
|
169
|
-
@
|
173
|
+
@user_agent_header ||= begin
|
170
174
|
meta = ["RUBY_VERSION: #{JRUBY_VERSION}"]
|
171
175
|
if RbConfig::CONFIG && RbConfig::CONFIG['host_os']
|
172
176
|
meta << "#{RbConfig::CONFIG['host_os'].split('_').first[/[a-z]+/i].downcase} #{RbConfig::CONFIG['target_cpu']}"
|
@@ -26,14 +26,14 @@ describe Elastic::Transport::Client do
|
|
26
26
|
let(:adapter_code) { "nh=#{defined?(Net::HTTP::VERSION) ? Net::HTTP::VERSION : Net::HTTP::HTTPVersion}" }
|
27
27
|
let(:meta_header) do
|
28
28
|
if jruby?
|
29
|
-
"
|
29
|
+
"et=#{meta_version},rb=#{RUBY_VERSION},t=#{Elastic::Transport::VERSION},jv=#{ENV_JAVA['java.version']},jr=#{JRUBY_VERSION},fd=#{Faraday::VERSION},#{adapter_code}"
|
30
30
|
else
|
31
|
-
"
|
31
|
+
"et=#{meta_version},rb=#{RUBY_VERSION},t=#{Elastic::Transport::VERSION},fd=#{Faraday::VERSION},#{adapter_code}"
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
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']}
|
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
|
39
39
|
expect(client.send(:client_meta_version, '7.0.0-alpha')).to eq('7.0.0p')
|
@@ -81,9 +81,9 @@ describe Elastic::Transport::Client do
|
|
81
81
|
context 'adapters' do
|
82
82
|
let(:meta_header) do
|
83
83
|
if jruby?
|
84
|
-
"
|
84
|
+
"et=#{meta_version},rb=#{RUBY_VERSION},t=#{Elastic::Transport::VERSION},jv=#{ENV_JAVA['java.version']},jr=#{JRUBY_VERSION},fd=#{Faraday::VERSION}"
|
85
85
|
else
|
86
|
-
"
|
86
|
+
"et=#{meta_version},rb=#{RUBY_VERSION},t=#{Elastic::Transport::VERSION},fd=#{Faraday::VERSION}"
|
87
87
|
end
|
88
88
|
end
|
89
89
|
let(:client) { described_class.new(adapter: adapter) }
|
@@ -246,9 +246,9 @@ describe Elastic::Transport::Client do
|
|
246
246
|
let(:subject) { client.instance_variable_get('@arguments')[:transport_options][:headers] }
|
247
247
|
let(:meta_header) do
|
248
248
|
if jruby?
|
249
|
-
"
|
249
|
+
"et=#{meta_version},rb=#{RUBY_VERSION},t=#{Elastic::Transport::VERSION},jv=#{ENV_JAVA['java.version']},jr=#{JRUBY_VERSION}"
|
250
250
|
else
|
251
|
-
"
|
251
|
+
"et=#{meta_version},rb=#{RUBY_VERSION},t=#{Elastic::Transport::VERSION}"
|
252
252
|
end
|
253
253
|
end
|
254
254
|
|
@@ -258,14 +258,29 @@ describe Elastic::Transport::Client do
|
|
258
258
|
end
|
259
259
|
end
|
260
260
|
|
261
|
-
context 'when
|
261
|
+
context 'when Elasticsearch is being used' do
|
262
262
|
before do
|
263
|
-
stub_const('Elastic::ELASTICSEARCH_SERVICE_VERSION', [:
|
263
|
+
stub_const('Elastic::ELASTICSEARCH_SERVICE_VERSION', [:es, '8.0.0'])
|
264
264
|
end
|
265
265
|
|
266
266
|
let(:client) { Elastic::Transport::Client.new }
|
267
267
|
|
268
268
|
it 'sets the service version in the metaheader' do
|
269
|
+
allow_any_instance_of(Kernel).to receive(:caller).and_return(['elasticsearch'])
|
270
|
+
expect(subject['x-elastic-client-meta']).to match(regexp)
|
271
|
+
expect(subject['x-elastic-client-meta']).to start_with('es=8.0.0')
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
context 'when Enterprise Search is being used' do
|
276
|
+
before do
|
277
|
+
stub_const('Elastic::ENTERPRISE_SERVICE_VERSION', [:ent, '8.0.0'])
|
278
|
+
end
|
279
|
+
|
280
|
+
let(:client) { Elastic::Transport::Client.new }
|
281
|
+
|
282
|
+
it 'sets the service version in the metaheader' do
|
283
|
+
allow_any_instance_of(Kernel).to receive(:caller).and_return(['enterprise-search-ruby'])
|
269
284
|
expect(subject['x-elastic-client-meta']).to match(regexp)
|
270
285
|
expect(subject['x-elastic-client-meta']).to start_with('ent=8.0.0')
|
271
286
|
end
|
@@ -209,28 +209,6 @@ if JRUBY
|
|
209
209
|
transport = Manticore.new hosts: [{ host: 'foobar', port: 1234 }], options: options
|
210
210
|
end
|
211
211
|
|
212
|
-
should 'allow custom headers' do
|
213
|
-
transport_options = { headers: { 'Authorization' => 'Basic token' } }
|
214
|
-
transport = Manticore.new(
|
215
|
-
hosts: [{ host: 'foobar', port: 1234 }],
|
216
|
-
transport_options: transport_options
|
217
|
-
)
|
218
|
-
|
219
|
-
assert_equal(
|
220
|
-
transport.instance_variable_get(:@request_options)[:headers]['Authorization'],
|
221
|
-
'Basic token'
|
222
|
-
)
|
223
|
-
transport.connections.first.connection
|
224
|
-
.expects(:get)
|
225
|
-
.with do |_host, _options|
|
226
|
-
assert_equal('Basic token', _options[:headers]['Authorization'])
|
227
|
-
true
|
228
|
-
end
|
229
|
-
.returns(stub_everything)
|
230
|
-
|
231
|
-
transport.perform_request('GET', '/', {})
|
232
|
-
end
|
233
|
-
|
234
212
|
should 'pass :transport_options to Manticore::Client' do
|
235
213
|
options = {
|
236
214
|
transport_options: { potatoes: 1 }
|
@@ -238,6 +216,45 @@ if JRUBY
|
|
238
216
|
|
239
217
|
::Manticore::Client.expects(:new).with(potatoes: 1, ssl: {})
|
240
218
|
transport = Manticore.new(hosts: [{ host: 'foobar', port: 1234 }], options: options)
|
219
|
+
assert_equal(transport.options[:transport_options][:potatoes], 1)
|
220
|
+
end
|
221
|
+
|
222
|
+
context 'custom headers' do
|
223
|
+
should 'allow authorization headers' do
|
224
|
+
transport_options = { headers: { 'Authorization' => 'Basic token' } }
|
225
|
+
transport = Manticore.new(
|
226
|
+
hosts: [{ host: 'foobar', port: 1234 }],
|
227
|
+
transport_options: transport_options
|
228
|
+
)
|
229
|
+
|
230
|
+
assert_equal(
|
231
|
+
transport.instance_variable_get(:@request_options)[:headers]['Authorization'],
|
232
|
+
'Basic token'
|
233
|
+
)
|
234
|
+
transport.connections.first.connection.expects(:get).with do |_host, options|
|
235
|
+
assert_equal('Basic token', options[:headers]['Authorization'])
|
236
|
+
true
|
237
|
+
end.returns(stub_everything)
|
238
|
+
transport.perform_request('GET', '/', {})
|
239
|
+
end
|
240
|
+
|
241
|
+
should 'allow user agent headers' do
|
242
|
+
transport_options = { headers: { 'User-Agent' => 'Custom UA' } }
|
243
|
+
transport = Manticore.new(
|
244
|
+
hosts: [{ host: 'localhost' }],
|
245
|
+
transport_options: transport_options
|
246
|
+
)
|
247
|
+
transport.connections.first.connection.expects(:get).with do |_host, options|
|
248
|
+
assert_equal('Custom UA', options[:headers]['User-Agent'])
|
249
|
+
true
|
250
|
+
end.returns(stub_everything)
|
251
|
+
transport.perform_request('GET', '/', {})
|
252
|
+
|
253
|
+
assert_equal(
|
254
|
+
transport.instance_variable_get('@request_options')[:headers]['User-Agent'],
|
255
|
+
'Custom UA'
|
256
|
+
)
|
257
|
+
end
|
241
258
|
end
|
242
259
|
end
|
243
260
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elastic-transport
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 8.0.
|
4
|
+
version: 8.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Karel Minarik
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2022-05-12 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: multi_json
|
@@ -388,11 +388,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
388
388
|
version: '2.5'
|
389
389
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
390
390
|
requirements:
|
391
|
-
- - "
|
391
|
+
- - ">="
|
392
392
|
- !ruby/object:Gem::Version
|
393
|
-
version:
|
393
|
+
version: '0'
|
394
394
|
requirements: []
|
395
|
-
rubygems_version: 3.
|
395
|
+
rubygems_version: 3.3.3
|
396
396
|
signing_key:
|
397
397
|
specification_version: 4
|
398
398
|
summary: Low level Ruby client for Elastic services.
|