elasticsearch-transport 7.17.0 → 7.17.1
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: 6ea7420173cd55a8274cf0ca677e18c70b8b0dc03b953a18d6188b00d998ad4d
|
4
|
+
data.tar.gz: 5f4931be00b530844479f5fba66256f69039096d59e452d150743a609193f624
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c6a925f6e13374a1e8c7d8a314d55866602debd782717a4d052a5e076a59f0b4320a98e5ba0b9a0f0695dedceca770fa0d911ceff99485803382f51480bed20
|
7
|
+
data.tar.gz: 13e5515c79629637dd1a4e300de065f11f12a7a4027bb0f088e3af1eaaa789f652fa31485d70942af57cd6386217ef65c88936c8d9cf7bb9d5ad254f26500551
|
@@ -18,7 +18,6 @@
|
|
18
18
|
module Elasticsearch
|
19
19
|
module Transport
|
20
20
|
module Transport
|
21
|
-
|
22
21
|
# @abstract Module with common functionality for transport implementations.
|
23
22
|
#
|
24
23
|
module Base
|
@@ -431,7 +430,7 @@ module Elasticsearch
|
|
431
430
|
end
|
432
431
|
|
433
432
|
def find_value(hash, regex)
|
434
|
-
key_value = hash.find { |k,
|
433
|
+
key_value = hash.find { |k, _| k.to_s.downcase =~ regex }
|
435
434
|
if key_value
|
436
435
|
hash.delete(key_value[0])
|
437
436
|
key_value[1]
|
@@ -62,14 +62,20 @@ module Elasticsearch
|
|
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
|
|
@@ -88,22 +94,22 @@ module Elasticsearch
|
|
88
94
|
|
89
95
|
params[:body] = body if body
|
90
96
|
params[:headers] = headers if headers
|
91
|
-
params = params.merge
|
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 Elasticsearch
|
|
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 Elasticsearch
|
|
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']}"
|
@@ -206,29 +206,8 @@ if JRUBY
|
|
206
206
|
}
|
207
207
|
|
208
208
|
::Manticore::Client.expects(:new).with(options)
|
209
|
-
transport = Manticore.new
|
210
|
-
|
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', '/', {})
|
209
|
+
transport = Manticore.new(hosts: [{ host: 'foobar', port: 1234 }], options: options)
|
210
|
+
assert_equal(transport.options[:ssl][:truststore_password], 'test')
|
232
211
|
end
|
233
212
|
|
234
213
|
should 'pass :transport_options to Manticore::Client' do
|
@@ -238,6 +217,45 @@ if JRUBY
|
|
238
217
|
|
239
218
|
::Manticore::Client.expects(:new).with(potatoes: 1, ssl: {})
|
240
219
|
transport = Manticore.new(hosts: [{ host: 'foobar', port: 1234 }], options: options)
|
220
|
+
assert_equal(transport.options[:transport_options][:potatoes], 1)
|
221
|
+
end
|
222
|
+
|
223
|
+
context 'custom headers' do
|
224
|
+
should 'allow authorization headers' do
|
225
|
+
transport_options = { headers: { 'Authorization' => 'Basic token' } }
|
226
|
+
transport = Manticore.new(
|
227
|
+
hosts: [{ host: 'foobar', port: 1234 }],
|
228
|
+
transport_options: transport_options
|
229
|
+
)
|
230
|
+
|
231
|
+
assert_equal(
|
232
|
+
transport.instance_variable_get(:@request_options)[:headers]['Authorization'],
|
233
|
+
'Basic token'
|
234
|
+
)
|
235
|
+
transport.connections.first.connection.expects(:get).with do |_host, options|
|
236
|
+
assert_equal('Basic token', options[:headers]['Authorization'])
|
237
|
+
true
|
238
|
+
end.returns(stub_everything)
|
239
|
+
transport.perform_request('GET', '/', {})
|
240
|
+
end
|
241
|
+
|
242
|
+
should 'allow user agent headers' do
|
243
|
+
transport_options = { headers: { 'User-Agent' => 'Custom UA' } }
|
244
|
+
transport = Manticore.new(
|
245
|
+
hosts: [{ host: 'localhost' }],
|
246
|
+
transport_options: transport_options
|
247
|
+
)
|
248
|
+
transport.connections.first.connection.expects(:get).with do |_host, options|
|
249
|
+
assert_equal('Custom UA', options[:headers]['User-Agent'])
|
250
|
+
true
|
251
|
+
end.returns(stub_everything)
|
252
|
+
transport.perform_request('GET', '/', {})
|
253
|
+
|
254
|
+
assert_equal(
|
255
|
+
transport.instance_variable_get('@request_options')[:headers]['User-Agent'],
|
256
|
+
'Custom UA'
|
257
|
+
)
|
258
|
+
end
|
241
259
|
end
|
242
260
|
end
|
243
261
|
end
|
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.17.
|
4
|
+
version: 7.17.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Karel Minarik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-02-
|
11
|
+
date: 2022-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -433,7 +433,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
433
433
|
- !ruby/object:Gem::Version
|
434
434
|
version: '0'
|
435
435
|
requirements: []
|
436
|
-
rubygems_version: 3.
|
436
|
+
rubygems_version: 3.3.3
|
437
437
|
signing_key:
|
438
438
|
specification_version: 4
|
439
439
|
summary: Ruby client for Elasticsearch.
|