elastic-transport 8.0.0.pre2 → 8.0.0.pre3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +1 -1
- data/CHANGELOG.md +5 -0
- 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/test/unit/transport_manticore_test.rb +39 -22
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ac20ddaca0a85e68faf7974aad8896ec49b0174d9a4db5a1b8a738452e440db
|
4
|
+
data.tar.gz: 62013fc273fb5f114e5ec0c9fb7502ca522a7e5f2f1f29c3024443e24466dbbc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98d93a16dfb6cc0d31d3e25a3ec6af5f714c8e527a1729daa1930698875ffa153b688d5b4b3de189842f4258904e9dc84b14866163b094e1ec327a32038c1828
|
7
|
+
data.tar.gz: cc9bac99fe08e8a2db3f4ce697f550053c3f2b87d8157d5b0de3c9a5a9ef8168150b102ac9399d2c7e7497c663491c5c40bb160c0503ab175a57c2cb6cfd35a1
|
data/.github/workflows/tests.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
## 8.0.0.pre3
|
2
|
+
|
3
|
+
- Tested in Ruby 3.1, JRuby 9.3, drops Ruby 2.5 in test Matrix. Version 8.0.0.pre3 is being tested for Ruby (MRI) 2.6, 2.7, 3.0 and 3.1 and JRuby 9.3.
|
4
|
+
- 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).
|
5
|
+
|
1
6
|
## 8.0.0.pre2
|
2
7
|
|
3
8
|
- Fixes tracing for Manticore [commit](https://github.com/elastic/elastic-transport-ruby/commit/98c81d19de4fee394f9c1a5079a1892ec951e0f9).
|
@@ -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']}"
|
@@ -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.0.
|
4
|
+
version: 8.0.0.pre3
|
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-02-10 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: multi_json
|
@@ -392,7 +392,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
392
392
|
- !ruby/object:Gem::Version
|
393
393
|
version: 1.3.1
|
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.
|