elasticsearch-transport 1.0.16.pre2 → 1.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -0
- data/lib/elasticsearch/transport/client.rb +29 -18
- data/lib/elasticsearch/transport/transport/base.rb +3 -1
- data/lib/elasticsearch/transport/transport/http/faraday.rb +7 -6
- data/lib/elasticsearch/transport/version.rb +1 -1
- data/test/unit/client_test.rb +54 -0
- data/test/unit/transport_curb_test.rb +7 -0
- data/test/unit/transport_faraday_test.rb +7 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 110c72e9d30c5a91ffd9e8f0910fb1c3bdb5b31c
|
4
|
+
data.tar.gz: 3f39c7af7cfe467c6ef5f755b8410a86898caa4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b070500608e152cf6a0d43a1a7ea6b7d1fe1b2db2f119e7be2b054a9c65097ef340f090b26e3f4210a231244e292c39db19ade36c34c9f1a0b0de04604fdde9
|
7
|
+
data.tar.gz: b61a1757529a8a82490c90852ca36bee8d3f662e04d40b2b9ffae25c41fab58b991c836786ef1fa327480b606f72ea555c7253153ee7cb07770694a05aafb58e
|
data/README.md
CHANGED
@@ -211,6 +211,14 @@ The reloading will timeout if not finished under 1 second by default. To change
|
|
211
211
|
|
212
212
|
Elasticsearch::Client.new hosts: ['localhost:9200', 'localhost:9201'], sniffer_timeout: 3
|
213
213
|
|
214
|
+
**NOTE:** When using reloading hosts ("sniffing") together with authentication, just pass the scheme,
|
215
|
+
user and password with the host info -- or, for more clarity, in the `http` options:
|
216
|
+
|
217
|
+
Elasticsearch::Client.new host: 'localhost:9200',
|
218
|
+
http: { scheme: 'https', user: 'U', password: 'P' },
|
219
|
+
reload_connections: true,
|
220
|
+
reload_on_failure: true
|
221
|
+
|
214
222
|
### Connection Selector
|
215
223
|
|
216
224
|
By default, the client will rotate the connections in a round-robin fashion, using the
|
@@ -83,36 +83,39 @@ module Elasticsearch
|
|
83
83
|
# @yield [faraday] Access and configure the `Faraday::Connection` instance directly with a block
|
84
84
|
#
|
85
85
|
def initialize(arguments={}, &block)
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
arguments[:
|
86
|
+
@arguments = arguments
|
87
|
+
|
88
|
+
hosts = @arguments[:hosts] || \
|
89
|
+
@arguments[:host] || \
|
90
|
+
@arguments[:url] || \
|
91
|
+
@arguments[:urls] || \
|
90
92
|
ENV.fetch('ELASTICSEARCH_URL', 'localhost:9200')
|
91
93
|
|
92
|
-
arguments[:logger] ||= arguments[:log] ? DEFAULT_LOGGER.call() : nil
|
93
|
-
arguments[:tracer] ||= arguments[:trace] ? DEFAULT_TRACER.call() : nil
|
94
|
-
arguments[:reload_connections] ||= false
|
95
|
-
arguments[:retry_on_failure] ||= false
|
96
|
-
arguments[:reload_on_failure] ||= false
|
97
|
-
arguments[:randomize_hosts] ||= false
|
98
|
-
arguments[:transport_options] ||= {}
|
94
|
+
@arguments[:logger] ||= @arguments[:log] ? DEFAULT_LOGGER.call() : nil
|
95
|
+
@arguments[:tracer] ||= @arguments[:trace] ? DEFAULT_TRACER.call() : nil
|
96
|
+
@arguments[:reload_connections] ||= false
|
97
|
+
@arguments[:retry_on_failure] ||= false
|
98
|
+
@arguments[:reload_on_failure] ||= false
|
99
|
+
@arguments[:randomize_hosts] ||= false
|
100
|
+
@arguments[:transport_options] ||= {}
|
101
|
+
@arguments[:http] ||= {}
|
99
102
|
|
100
|
-
arguments[:transport_options].update(:request => { :timeout => arguments[:request_timeout] } ) if arguments[:request_timeout]
|
103
|
+
@arguments[:transport_options].update(:request => { :timeout => @arguments[:request_timeout] } ) if @arguments[:request_timeout]
|
101
104
|
|
102
|
-
@send_get_body_as = arguments[:send_get_body_as] || 'GET'
|
105
|
+
@send_get_body_as = @arguments[:send_get_body_as] || 'GET'
|
103
106
|
|
104
|
-
transport_class = arguments[:transport_class] || DEFAULT_TRANSPORT_CLASS
|
107
|
+
transport_class = @arguments[:transport_class] || DEFAULT_TRANSPORT_CLASS
|
105
108
|
|
106
|
-
@transport = arguments[:transport] || begin
|
109
|
+
@transport = @arguments[:transport] || begin
|
107
110
|
if transport_class == Transport::HTTP::Faraday
|
108
|
-
transport_class.new(:hosts => __extract_hosts(hosts, arguments), :options => arguments) do |faraday|
|
111
|
+
transport_class.new(:hosts => __extract_hosts(hosts, @arguments), :options => @arguments) do |faraday|
|
109
112
|
block.call faraday if block
|
110
113
|
unless (h = faraday.builder.handlers.last) && h.name.start_with?("Faraday::Adapter")
|
111
|
-
faraday.adapter(arguments[:adapter] || __auto_detect_adapter)
|
114
|
+
faraday.adapter(@arguments[:adapter] || __auto_detect_adapter)
|
112
115
|
end
|
113
116
|
end
|
114
117
|
else
|
115
|
-
transport_class.new(:hosts => __extract_hosts(hosts, arguments), :options => arguments)
|
118
|
+
transport_class.new(:hosts => __extract_hosts(hosts, @arguments), :options => @arguments)
|
116
119
|
end
|
117
120
|
end
|
118
121
|
end
|
@@ -167,6 +170,14 @@ module Elasticsearch
|
|
167
170
|
end
|
168
171
|
|
169
172
|
host_parts[:port] = host_parts[:port].to_i unless host_parts[:port].nil?
|
173
|
+
|
174
|
+
# Transfer the selected host parts such as authentication credentials to `options`,
|
175
|
+
# so we can re-use them when reloading connections
|
176
|
+
#
|
177
|
+
host_parts.select { |k,v| [:scheme, :port, :user, :password].include?(k) }.each do |k,v|
|
178
|
+
@arguments[:http][k] ||= v
|
179
|
+
end
|
180
|
+
|
170
181
|
host_parts
|
171
182
|
end
|
172
183
|
|
@@ -11,7 +11,7 @@ module Elasticsearch
|
|
11
11
|
DEFAULT_RESURRECT_AFTER = 60 # Seconds
|
12
12
|
DEFAULT_MAX_RETRIES = 3 # Requests
|
13
13
|
DEFAULT_SERIALIZER_CLASS = Serializer::MultiJson
|
14
|
-
SANITIZED_PASSWORD = '*'*rand(
|
14
|
+
SANITIZED_PASSWORD = '*' * (rand(14)+1)
|
15
15
|
|
16
16
|
attr_reader :hosts, :options, :connections, :counter, :last_request_at, :protocol
|
17
17
|
attr_accessor :serializer, :sniffer, :logger, :tracer,
|
@@ -33,6 +33,8 @@ module Elasticsearch
|
|
33
33
|
|
34
34
|
@hosts = arguments[:hosts] || []
|
35
35
|
@options = arguments[:options] || {}
|
36
|
+
@options[:http] ||= {}
|
37
|
+
|
36
38
|
@block = block
|
37
39
|
@connections = __build_connections
|
38
40
|
|
@@ -34,13 +34,14 @@ module Elasticsearch
|
|
34
34
|
def __build_connections
|
35
35
|
Connections::Collection.new \
|
36
36
|
:connections => hosts.map { |host|
|
37
|
-
host[:protocol] = host[:scheme] || options[:scheme] || DEFAULT_PROTOCOL
|
38
|
-
host[:port] ||= options[:port] || DEFAULT_PORT
|
39
|
-
if options[:user] && !host[:user]
|
40
|
-
host[:user] ||= options[:user]
|
41
|
-
host[:password] ||= options[:password]
|
37
|
+
host[:protocol] = host[:scheme] || options[:scheme] || options[:http][:scheme] || DEFAULT_PROTOCOL
|
38
|
+
host[:port] ||= options[:port] || options[:http][:scheme] || DEFAULT_PORT
|
39
|
+
if (options[:user] || options[:http][:user]) && !host[:user]
|
40
|
+
host[:user] ||= options[:user] || options[:http][:user]
|
41
|
+
host[:password] ||= options[:password] || options[:http][:password]
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
|
+
url = __full_url(host)
|
44
45
|
|
45
46
|
Connections::Connection.new \
|
46
47
|
:host => host,
|
data/test/unit/client_test.rb
CHANGED
@@ -295,5 +295,59 @@ class Elasticsearch::Transport::ClientTest < Test::Unit::TestCase
|
|
295
295
|
end
|
296
296
|
end
|
297
297
|
|
298
|
+
context "when passed options" do
|
299
|
+
setup do
|
300
|
+
Elasticsearch::Transport::Client::DEFAULT_TRANSPORT_CLASS.any_instance.unstub(:__build_connections)
|
301
|
+
end
|
302
|
+
|
303
|
+
should "configure the HTTP scheme" do
|
304
|
+
c = Elasticsearch::Transport::Client.new \
|
305
|
+
:hosts => ['node1', 'node2'],
|
306
|
+
:port => 1234, :scheme => 'https', :user => 'USERNAME', :password => 'PASSWORD'
|
307
|
+
|
308
|
+
assert_equal 'https://USERNAME:PASSWORD@node1:1234/', c.transport.connections[0].full_url('')
|
309
|
+
assert_equal 'https://USERNAME:PASSWORD@node2:1234/', c.transport.connections[1].full_url('')
|
310
|
+
end
|
311
|
+
|
312
|
+
should "keep the credentials after reloading" do
|
313
|
+
Elasticsearch::Transport::Client::DEFAULT_TRANSPORT_CLASS.any_instance.
|
314
|
+
stubs(:sniffer).
|
315
|
+
returns( mock(:hosts => [ {:host => 'foobar', :port => 4567, :id => 'foobar4567'} ]) )
|
316
|
+
|
317
|
+
c = Elasticsearch::Transport::Client.new \
|
318
|
+
:url => 'http://foo:1234',
|
319
|
+
:user => 'USERNAME', :password => 'PASSWORD'
|
320
|
+
|
321
|
+
assert_equal 'http://USERNAME:PASSWORD@foo:1234/', c.transport.connections.first.full_url('')
|
322
|
+
|
323
|
+
c.transport.reload_connections!
|
324
|
+
|
325
|
+
assert_equal 'http://USERNAME:PASSWORD@foobar:4567/', c.transport.connections.first.full_url('')
|
326
|
+
end
|
327
|
+
|
328
|
+
should "transfer selected host parts into the 'http' options" do
|
329
|
+
c = Elasticsearch::Transport::Client.new \
|
330
|
+
:host => { :scheme => 'https', :port => '8080', :host => 'node1', :user => 'U', :password => 'P' }
|
331
|
+
|
332
|
+
assert_equal 'https://U:P@node1:8080/', c.transport.connections.first.full_url('')
|
333
|
+
|
334
|
+
assert_equal 'https', c.transport.options[:http][:scheme]
|
335
|
+
assert_equal 8080, c.transport.options[:http][:port]
|
336
|
+
assert_equal 'U', c.transport.options[:http][:user]
|
337
|
+
assert_equal 'P', c.transport.options[:http][:password]
|
338
|
+
end
|
339
|
+
|
340
|
+
should "transfer selected host parts from URL into the 'http' options" do
|
341
|
+
c = Elasticsearch::Transport::Client.new :url => 'https://U:P@node1:8080'
|
342
|
+
|
343
|
+
assert_equal 'https://U:P@node1:8080/', c.transport.connections.first.full_url('')
|
344
|
+
|
345
|
+
assert_equal 'https', c.transport.options[:http][:scheme]
|
346
|
+
assert_equal 8080, c.transport.options[:http][:port]
|
347
|
+
assert_equal 'U', c.transport.options[:http][:user]
|
348
|
+
assert_equal 'P', c.transport.options[:http][:password]
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
298
352
|
end
|
299
353
|
end
|
@@ -90,6 +90,13 @@ else
|
|
90
90
|
assert_equal 'foo', transport.connections.first.connection.username
|
91
91
|
assert_equal 'bar', transport.connections.first.connection.password
|
92
92
|
end
|
93
|
+
|
94
|
+
should "use global http configuration" do
|
95
|
+
transport = Faraday.new :hosts => [ { :host => 'foobar', :port => 1234 } ],
|
96
|
+
:options => { :http => { :scheme => 'https', :user => 'U', :password => 'P' } }
|
97
|
+
|
98
|
+
assert_equal 'https://U:P@foobar:1234/', transport.connections.first.full_url('')
|
99
|
+
end
|
93
100
|
end
|
94
101
|
|
95
102
|
end
|
@@ -172,6 +172,13 @@ class Elasticsearch::Transport::Transport::HTTP::FaradayTest < Test::Unit::TestC
|
|
172
172
|
assert_instance_of ::Faraday::Connection, transport.connections.first.connection
|
173
173
|
assert_equal 'http://foobar:1234/', transport.connections.first.connection.url_prefix.to_s
|
174
174
|
end
|
175
|
+
|
176
|
+
should "use global http configuration" do
|
177
|
+
transport = Faraday.new :hosts => [ { :host => 'foobar', :port => 1234 } ],
|
178
|
+
:options => { :http => { :scheme => 'https', :user => 'U', :password => 'P' } }
|
179
|
+
|
180
|
+
assert_equal 'https://U:P@foobar:1234/', transport.connections.first.full_url('')
|
181
|
+
end
|
175
182
|
end
|
176
183
|
|
177
184
|
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: 1.0.16
|
4
|
+
version: 1.0.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Karel Minarik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -394,9 +394,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
394
394
|
version: '0'
|
395
395
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
396
396
|
requirements:
|
397
|
-
- - "
|
397
|
+
- - ">="
|
398
398
|
- !ruby/object:Gem::Version
|
399
|
-
version:
|
399
|
+
version: '0'
|
400
400
|
requirements: []
|
401
401
|
rubyforge_project:
|
402
402
|
rubygems_version: 2.2.2
|