elastic-transport 8.0.0.pre2 → 8.0.0.pre3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e2c04c9ca950389cb71ceda4d1fe1c7e4266c844ed95c73fd3b7815ea28c6134
4
- data.tar.gz: 07deccf3f9278235cb4989cfaada2be0e271d21615f72fac8eeaab00e81058c6
3
+ metadata.gz: 2ac20ddaca0a85e68faf7974aad8896ec49b0174d9a4db5a1b8a738452e440db
4
+ data.tar.gz: 62013fc273fb5f114e5ec0c9fb7502ca522a7e5f2f1f29c3024443e24466dbbc
5
5
  SHA512:
6
- metadata.gz: 3e27a172d2fa106208b210fd4ab1cdd1bc76f6ef49e4b7aefae6a6a525dd650478e21c1e173335733c703f0119ec5e3935fdd0f46eb477573ae6cbceccc2ff34
7
- data.tar.gz: a4cf7f2a840c75a43a6ed74d15f04fcab1c780fa9a2250892af38ca206c3eaa021f8548ed5a53f1339bb344bf41bc2225a92ed077ef227fdecd33d882b43f32e
6
+ metadata.gz: 98d93a16dfb6cc0d31d3e25a3ec6af5f714c8e527a1729daa1930698875ffa153b688d5b4b3de189842f4258904e9dc84b14866163b094e1ec327a32038c1828
7
+ data.tar.gz: cc9bac99fe08e8a2db3f4ce697f550053c3f2b87d8157d5b0de3c9a5a9ef8168150b102ac9399d2c7e7497c663491c5c40bb160c0503ab175a57c2cb6cfd35a1
@@ -14,7 +14,7 @@ jobs:
14
14
  strategy:
15
15
  fail-fast: false
16
16
  matrix:
17
- ruby: [ 2.5, 2.6, 2.7, 3.0, jruby-9.2 ]
17
+ ruby: [ '2.6', '2.7', '3.0', '3.1', 'jruby-9.3' ]
18
18
  runs-on: ubuntu-latest
19
19
  steps:
20
20
  - uses: actions/checkout@v2
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).
@@ -435,7 +435,7 @@ module Elastic
435
435
  end
436
436
 
437
437
  def find_value(hash, regex)
438
- key_value = hash.find { |k,v| k.to_s.downcase =~ regex }
438
+ key_value = hash.find { |k, _| k.to_s.downcase =~ regex }
439
439
  if key_value
440
440
  hash.delete(key_value[0])
441
441
  key_value[1]
@@ -62,14 +62,20 @@ module Elastic
62
62
  class Manticore
63
63
  include Base
64
64
 
65
- def initialize(arguments={}, &block)
66
- @request_options = { headers: (arguments.dig(:transport_options, :headers) || {}) }
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 "GET"
99
+ when 'GET'
94
100
  resp = connection.connection.get(url, params)
95
- when "HEAD"
101
+ when 'HEAD'
96
102
  resp = connection.connection.head(url, params)
97
- when "PUT"
103
+ when 'PUT'
98
104
  resp = connection.connection.put(url, params)
99
- when "POST"
105
+ when 'POST'
100
106
  resp = connection.connection.post(url, params)
101
- when "DELETE"
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 resp.code, resp.read_body, resp.headers
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(@request_options, options[:transport_options])
117
- apply_headers(@request_options, options)
122
+ apply_headers(options)
118
123
 
119
- Connections::Collection.new \
120
- :connections => hosts.map { |host|
121
- host[:protocol] = host[:scheme] || DEFAULT_PROTOCOL
122
- host[:port] ||= DEFAULT_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
- :host => host,
129
- :connection => @manticore
130
- },
131
- :selector_class => options[:selector_class],
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(request_options, options)
161
- headers = options&.[](:headers) || {}
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
- @user_agent ||= begin
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']}"
@@ -17,6 +17,6 @@
17
17
 
18
18
  module Elastic
19
19
  module Transport
20
- VERSION = '8.0.0.pre2'.freeze
20
+ VERSION = '8.0.0.pre3'.freeze
21
21
  end
22
22
  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.0.pre2
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: 2021-10-08 00:00:00.000000000 Z
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.2.22
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.