elasticsearch-transport 1.0.13 → 1.0.14

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
  SHA1:
3
- metadata.gz: cfbb24f919ca5c508c660a9b121fb0937b16d5ab
4
- data.tar.gz: 2efeb80ae1defb9578b2b62d2834f61b86e75983
3
+ metadata.gz: a1c41acb9864d25738a29b7ced81856e5eea8660
4
+ data.tar.gz: 1675e534fedd834b107e51c620767f11e1b9327f
5
5
  SHA512:
6
- metadata.gz: aefe90beda8b000367535d535156786126c8f7b49d98cd637352a0cdc1a054f248fd7225973cc2b7a7be72207bfedf9b28bfd475f138144110b79082daa6c37b
7
- data.tar.gz: e959b3c3c12990b2280ac9ad3836c3cdfb7c63a90ca5a46f2c78c50d974c3de921602b6f927749a7cc5d29f71809706bfb1705cd643a3e2680e0e1c01bb95ad2
6
+ metadata.gz: 2473aa1f15584614fcf9c96e75030bd37979817ba4ddcce78134781b275deedd35cf1a62a46af649c704d2d84a247751fe680be1c111de8ac8d25e6c33316817
7
+ data.tar.gz: 18aa296103d2c29b5ae11a3258f7e9c5f97c6787ad061ad4d0713a9e7fb916d920fb0c92604065bbbedf6fd7e15f75d2a253238a7cb26de141e7c48f0727f616
data/README.md CHANGED
@@ -90,6 +90,9 @@ Instead of Strings, you can pass host information as an array of Hashes:
90
90
 
91
91
  Elasticsearch::Client.new hosts: [ { host: 'myhost1', port: 8080 }, { host: 'myhost2', port: 8080 } ]
92
92
 
93
+ **NOTE:** When specifying multiple hosts, you probably want to enable the `retry_on_failure` option to
94
+ perform a failed request on another node (see the _Retrying on Failures_ chapter).
95
+
93
96
  Common URL parts -- scheme, HTTP authentication credentials, URL prefixes, etc -- are handled automatically:
94
97
 
95
98
  Elasticsearch::Client.new url: 'https://username:password@api.server.org:4430/search'
@@ -34,8 +34,12 @@ module Elasticsearch
34
34
  def __build_connections
35
35
  Connections::Collection.new \
36
36
  :connections => hosts.map { |host|
37
- host[:protocol] = host[:scheme] || DEFAULT_PROTOCOL
38
- host[:port] ||= DEFAULT_PORT
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]
42
+ end
39
43
  url = __full_url(host)
40
44
 
41
45
  Connections::Connection.new \
@@ -2,16 +2,16 @@ module Elasticsearch
2
2
  module Transport
3
3
  module Transport
4
4
 
5
- # Handles node discovery ("sniffing").
5
+ # Handles node discovery ("sniffing")
6
6
  #
7
7
  class Sniffer
8
- ES1_RE_URL = /\/([^:]*):([0-9]+)\]/ # Use named groups on Ruby 1.9: /\/(?<host>[^:]*):(?<port>[0-9]+)\]/
9
- ES2_RE_URL = /([^:]*):([0-9]+)/
8
+ ES1_RE_URL = /\[([^\/]*)?\/?([^:]*):([0-9]+)\]/
9
+ ES2_RE_URL = /([^\/]*)?\/?([^:]*):([0-9]+)/
10
10
 
11
11
  attr_reader :transport
12
12
  attr_accessor :timeout
13
13
 
14
- # @param transport [Object] A transport instance.
14
+ # @param transport [Object] A transport instance
15
15
  #
16
16
  def initialize(transport)
17
17
  @transport = transport
@@ -34,8 +34,9 @@ module Elasticsearch
34
34
  addr_str = info["#{transport.protocol}_address"].to_s
35
35
  matches = addr_str.match(ES1_RE_URL) || addr_str.match(ES2_RE_URL)
36
36
  if matches
37
- # TODO: Implement lightweight "indifferent access" here
38
- info.merge :host => matches[1], :port => matches[2], :id => id
37
+ host = matches[1].empty? ? matches[2] : matches[1]
38
+ port = matches[3]
39
+ info.merge :host => host, :port => port, :id => id
39
40
  end
40
41
  end.compact
41
42
 
@@ -1,5 +1,5 @@
1
1
  module Elasticsearch
2
2
  module Transport
3
- VERSION = "1.0.13"
3
+ VERSION = "1.0.14"
4
4
  end
5
5
  end
@@ -75,6 +75,33 @@ class Elasticsearch::Transport::Transport::SnifferTest < Test::Unit::TestCase
75
75
  assert_equal 'Node 1', hosts.first['name']
76
76
  end
77
77
 
78
+ should "return an array of hosts as hostnames when a hostname is returned" do
79
+ @transport.expects(:perform_request).returns __nodes_info <<-JSON
80
+ {
81
+ "ok" : true,
82
+ "cluster_name" : "elasticsearch_test",
83
+ "nodes" : {
84
+ "N1" : {
85
+ "name" : "Node 1",
86
+ "transport_address" : "inet[/192.168.1.23:9300]",
87
+ "hostname" : "testhost1",
88
+ "version" : "0.20.6",
89
+ "http_address" : "inet[testhost1.com/192.168.1.23:9200]",
90
+ "thrift_address" : "/192.168.1.23:9500",
91
+ "memcached_address" : "inet[/192.168.1.23:11211]"
92
+ }
93
+ }
94
+ }
95
+ JSON
96
+
97
+ hosts = @sniffer.hosts
98
+
99
+ assert_equal 1, hosts.size
100
+ assert_equal 'testhost1.com', hosts.first[:host]
101
+ assert_equal '9200', hosts.first[:port]
102
+ assert_equal 'Node 1', hosts.first['name']
103
+ end
104
+
78
105
  should "skip hosts without a matching transport protocol" do
79
106
  @transport = DummyTransport.new :options => { :protocol => 'memcached' }
80
107
  @sniffer = Elasticsearch::Transport::Transport::Sniffer.new @transport
@@ -135,6 +135,43 @@ class Elasticsearch::Transport::Transport::HTTP::FaradayTest < Test::Unit::TestC
135
135
  transport = Faraday.new :hosts => [ { :host => 'foobar', :port => 1234, :user => 'foo', :password => 'bar' } ]
136
136
  assert_equal 'Basic Zm9vOmJhcg==', transport.connections.first.connection.headers['Authorization']
137
137
  end
138
+
139
+ should "set the credentials if they exist in options" do
140
+ transport = Faraday.new :hosts => [ { :host => 'foobar', :port => 1234 } ],
141
+ :options => { :user => 'foo', :password => 'bar' }
142
+ assert_equal 'Basic Zm9vOmJhcg==', transport.connections.first.connection.headers['Authorization']
143
+ end
144
+
145
+ should "override options credentials if passed explicitly" do
146
+ transport = Faraday.new :hosts => [ { :host => 'foobar', :port => 1234, :user => 'foo', :password => 'bar' },
147
+ { :host => 'foobar2', :port => 1234 } ],
148
+ :options => { :user => 'foo2', :password => 'bar2' }
149
+ assert_equal 'Basic Zm9vOmJhcg==', transport.connections.first.connection.headers['Authorization']
150
+ assert_equal 'Basic Zm9vMjpiYXIy', transport.connections[1].connection.headers['Authorization']
151
+ end
152
+
153
+ should "set connection scheme to https if passed" do
154
+ transport = Faraday.new :hosts => [ { :host => 'foobar', :port => 1234, :scheme => 'https' } ]
155
+
156
+ assert_instance_of ::Faraday::Connection, transport.connections.first.connection
157
+ assert_equal 'https://foobar:1234/', transport.connections.first.connection.url_prefix.to_s
158
+ end
159
+
160
+ should "set connection scheme to https if it exist in options" do
161
+ transport = Faraday.new :hosts => [ { :host => 'foobar', :port => 1234} ],
162
+ :options => { :scheme => 'https' }
163
+
164
+ assert_instance_of ::Faraday::Connection, transport.connections.first.connection
165
+ assert_equal 'https://foobar:1234/', transport.connections.first.connection.url_prefix.to_s
166
+ end
167
+
168
+ should "override options scheme if passed explicitly" do
169
+ transport = Faraday.new :hosts => [ { :host => 'foobar', :port => 1234, :scheme => 'http'} ],
170
+ :options => { :scheme => 'https' }
171
+
172
+ assert_instance_of ::Faraday::Connection, transport.connections.first.connection
173
+ assert_equal 'http://foobar:1234/', transport.connections.first.connection.url_prefix.to_s
174
+ end
138
175
  end
139
176
 
140
177
  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.13
4
+ version: 1.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karel Minarik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-15 00:00:00.000000000 Z
11
+ date: 2015-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json