elasticsearch-transport 1.0.6 → 1.0.7

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
  SHA1:
3
- metadata.gz: 87070e7148cced0a3dd781855400a2911737bbb7
4
- data.tar.gz: 9832698a4ff8193012e957d4e9246775b7968749
3
+ metadata.gz: ee365b72ccd59176d473e7cfd057d4f246eacd0f
4
+ data.tar.gz: 2b9ab7f0a21f779cc24957f0b1aad4b0a9c449c1
5
5
  SHA512:
6
- metadata.gz: a0297406975e141c2a9b4686ecad298cfdf1e444fb87261de335238b8fab42d0c9924c6b9b83ca1971a806e2b94c1d348bb4fe423e599692cf3b0d01560e20d4
7
- data.tar.gz: 94364828943fcc5576bdc95a83c398af30762d5dbc15b51872ecfa75f857a21bfbe4f531992b2f81abe2bb56b75656c2db570bb016042f45807ef1dbd97ef106
6
+ metadata.gz: 23ea14e8d2901165ac026bf0dd4c9e17c1b8560629bc946418d05f24321f31410389edc185cf06701e94b7fc915ac2031d988d35be0ba1b449cf0ff483afa56c
7
+ data.tar.gz: 7ea2f669de99b231e41e02db9b801bef7ec0a1753e796ad71da98095e5e56192cb3aa48d5600b050eb653bcf0c4e4badbd6f90853077641631db20ba942a504e
data/README.md CHANGED
@@ -89,6 +89,23 @@ Instead of Strings, you can pass host information as an array of Hashes:
89
89
 
90
90
  Elasticsearch::Client.new hosts: [ { host: 'myhost1', port: 8080 }, { host: 'myhost2', port: 8080 } ]
91
91
 
92
+ Common URL parts -- scheme, HTTP authentication credentials, URL prefixes, etc -- are handled automatically:
93
+
94
+ Elasticsearch::Client.new url: 'https://username:password@api.server.org:4430/search'
95
+
96
+ You can pass multiple URLs separated by a comma:
97
+
98
+ Elasticsearch::Client.new urls: 'http://localhost:9200,http://localhost:9201'
99
+
100
+ Another way to configure the URL(s) is to export the `ELASTICSEARCH_URL` variable.
101
+
102
+ The client will automatically round-robin across the hosts
103
+ (unless you select or implement a different [connection selector](#connection-selector)).
104
+
105
+ ### Authentication
106
+
107
+ You can pass the authentication credentials, scheme and port in the host configuration hash:
108
+
92
109
  Elasticsearch::Client.new hosts: [
93
110
  { host: 'my-protected-host',
94
111
  port: '443',
@@ -97,12 +114,15 @@ Instead of Strings, you can pass host information as an array of Hashes:
97
114
  scheme: 'https'
98
115
  } ]
99
116
 
100
- Scheme, HTTP authentication credentials and URL prefixes are handled automatically:
117
+ ... or simply use the common URL format:
101
118
 
102
- Elasticsearch::Client.new url: 'https://username:password@api.server.org:4430/search'
119
+ Elasticsearch::Client.new url: 'https://username:password@example.com:9200'
103
120
 
104
- The client will automatically round-robin across the hosts
105
- (unless you select or implement a different [connection selector](#connection-selector)).
121
+ To pass a custom certificate for SSL peer verification to Faraday-based clients,
122
+ use the `transport_options` option:
123
+
124
+ Elasticsearch::Client.new url: 'https://username:password@example.com:9200',
125
+ transport_options: { ssl: { ca_file: '/path/to/cacert.pem' } }
106
126
 
107
127
  ### Logging
108
128
 
@@ -262,7 +282,8 @@ constructor, use the `transport_options` key:
262
282
  client = Elasticsearch::Client.new transport_options: {
263
283
  request: { open_timeout: 1 },
264
284
  headers: { user_agent: 'MyApp' },
265
- params: { :format => 'yaml' }
285
+ params: { :format => 'yaml' },
286
+ ssl: { verify: false }
266
287
  }
267
288
 
268
289
  You can also use a bundled [_Curb_](https://rubygems.org/gems/curb) based transport implementation:
@@ -374,6 +395,22 @@ Github's pull requests and issues are used to communicate, send bug reports and
374
395
  * The {Elasticsearch::Transport::Transport::Connections::Selector::Base} implementations allow to choose connections
375
396
  from the pool, eg. in a round-robin or random fashion. You can implement your own selector strategy.
376
397
 
398
+ ## Development
399
+
400
+ To work on the code, clone and bootstrap the main repository first --
401
+ please see instructions in the main [README](../README.md#development).
402
+
403
+ To run tests, launch a testing cluster -- again, see instructions
404
+ in the main [README](../README.md#development) -- and use the Rake tasks:
405
+
406
+ ```
407
+ time rake test:unit
408
+ time rake test:integration
409
+ ```
410
+
411
+ Unit tests have to use Ruby 1.8 compatible syntax, integration tests
412
+ can use Ruby 2.x syntax and features.
413
+
377
414
  ## License
378
415
 
379
416
  This software is licensed under the Apache 2 license, quoted below.
@@ -63,6 +63,10 @@ Gem::Specification.new do |s|
63
63
  s.add_development_dependency "cane"
64
64
  end
65
65
 
66
+ if defined?(RUBY_VERSION) && RUBY_VERSION > '2.2'
67
+ s.add_development_dependency "test-unit", '~> 2'
68
+ end
69
+
66
70
  s.description = <<-DESC.gsub(/^ /, '')
67
71
  Ruby client for Elasticsearch. See the `elasticsearch` gem for full integration.
68
72
  DESC
@@ -78,7 +78,11 @@ module Elasticsearch
78
78
  # (Default: GET)
79
79
  #
80
80
  def initialize(arguments={})
81
- hosts = arguments[:hosts] || arguments[:host] || arguments[:url] || ENV.fetch('ELASTICSEARCH_URL', 'localhost:9200')
81
+ hosts = arguments[:hosts] || \
82
+ arguments[:host] || \
83
+ arguments[:url] || \
84
+ arguments[:urls] || \
85
+ ENV.fetch('ELASTICSEARCH_URL', 'localhost:9200')
82
86
 
83
87
  arguments[:logger] ||= arguments[:log] ? DEFAULT_LOGGER.call() : nil
84
88
  arguments[:tracer] ||= arguments[:trace] ? DEFAULT_TRACER.call() : nil
@@ -124,24 +128,32 @@ module Elasticsearch
124
128
  # @api private
125
129
  #
126
130
  def __extract_hosts(hosts_config, options={})
127
- hosts_config = Array(hosts_config)
131
+ if hosts_config.respond_to?(:to_hash)
132
+ hosts = [ hosts_config ]
133
+ else
134
+ if hosts_config.is_a?(String) && hosts_config.include?(',')
135
+ hosts = hosts_config.split(/\s*,\s*/)
136
+ else
137
+ hosts = Array(hosts_config)
138
+ end
128
139
 
129
- hosts = hosts_config.map do |host|
130
- case host
131
- when String
132
- if host =~ /^[a-z]+\:\/\//
133
- uri = URI.parse(host)
134
- { :scheme => uri.scheme, :user => uri.user, :password => uri.password, :host => uri.host, :path => uri.path, :port => uri.port.to_s }
140
+ hosts.map! do |host|
141
+ case host
142
+ when String
143
+ if host =~ /^[a-z]+\:\/\//
144
+ uri = URI.parse(host)
145
+ { :scheme => uri.scheme, :user => uri.user, :password => uri.password, :host => uri.host, :path => uri.path, :port => uri.port.to_s }
146
+ else
147
+ host, port = host.split(':')
148
+ { :host => host, :port => port }
149
+ end
150
+ when URI
151
+ { :scheme => host.scheme, :user => host.user, :password => host.password, :host => host.host, :path => host.path, :port => host.port.to_s }
152
+ when Hash
153
+ host
135
154
  else
136
- host, port = host.split(':')
137
- { :host => host, :port => port }
155
+ raise ArgumentError, "Please pass host as a String, URI or Hash -- #{host.class} given."
138
156
  end
139
- when URI
140
- { :scheme => host.scheme, :user => host.user, :password => host.password, :host => host.host, :path => host.path, :port => host.port.to_s }
141
- when Hash
142
- host
143
- else
144
- raise ArgumentError, "Please pass host as a String, URI or Hash -- #{host.class} given."
145
157
  end
146
158
  end
147
159
 
@@ -174,4 +186,3 @@ module Elasticsearch
174
186
  end
175
187
  end
176
188
  end
177
-
@@ -62,6 +62,7 @@ module Elasticsearch
62
62
 
63
63
  Connections::Connection.new :host => host, :connection => client
64
64
  },
65
+ :selector_class => options[:selector_class],
65
66
  :selector => options[:selector]
66
67
  end
67
68
 
@@ -70,7 +71,14 @@ module Elasticsearch
70
71
  # @return [Array]
71
72
  #
72
73
  def host_unreachable_exceptions
73
- [::Curl::Err::HostResolutionError, ::Curl::Err::ConnectionFailedError, ::Curl::Err::GotNothingError, ::Curl::Err::RecvError, ::Curl::Err::SendError]
74
+ [
75
+ ::Curl::Err::HostResolutionError,
76
+ ::Curl::Err::ConnectionFailedError,
77
+ ::Curl::Err::GotNothingError,
78
+ ::Curl::Err::RecvError,
79
+ ::Curl::Err::SendError,
80
+ ::Curl::Err::TimeoutError
81
+ ]
74
82
  end
75
83
  end
76
84
 
@@ -1,5 +1,5 @@
1
1
  module Elasticsearch
2
2
  module Transport
3
- VERSION = "1.0.6"
3
+ VERSION = "1.0.7"
4
4
  end
5
5
  end
@@ -65,7 +65,7 @@ class Elasticsearch::Transport::ClientIntegrationTest < Elasticsearch::Test::Int
65
65
  response = client.perform_request 'GET', ''
66
66
 
67
67
  assert_respond_to(response.body, :to_hash)
68
- assert_equal 200, response.body['status']
68
+ assert_not_nil response.body['cluster_name']
69
69
  assert_equal 'application/json', response.headers['content-type']
70
70
  end unless JRUBY
71
71
  end
@@ -69,13 +69,17 @@ class Elasticsearch::Transport::ClientTest < Test::Unit::TestCase
69
69
  assert_equal 'localhost', c.transport.hosts.first[:host]
70
70
  end
71
71
 
72
- should "take :hosts, :host or :url" do
72
+ should "take :hosts, :host, :url or :urls" do
73
73
  c1 = Elasticsearch::Transport::Client.new :hosts => ['foobar']
74
74
  c2 = Elasticsearch::Transport::Client.new :host => 'foobar'
75
75
  c3 = Elasticsearch::Transport::Client.new :url => 'foobar'
76
- assert_equal 'foobar', c1.transport.hosts.first[:host]
77
- assert_equal 'foobar', c2.transport.hosts.first[:host]
78
- assert_equal 'foobar', c3.transport.hosts.first[:host]
76
+ c4 = Elasticsearch::Transport::Client.new :urls => 'foo,bar'
77
+
78
+ assert_equal 'foobar', c1.transport.hosts[0][:host]
79
+ assert_equal 'foobar', c2.transport.hosts[0][:host]
80
+ assert_equal 'foobar', c3.transport.hosts[0][:host]
81
+ assert_equal 'foo', c4.transport.hosts[0][:host]
82
+ assert_equal 'bar', c4.transport.hosts[1][:host]
79
83
  end
80
84
 
81
85
  end
@@ -84,10 +88,21 @@ class Elasticsearch::Transport::ClientTest < Test::Unit::TestCase
84
88
  setup { ENV['ELASTICSEARCH_URL'] = 'foobar' }
85
89
  teardown { ENV.delete('ELASTICSEARCH_URL') }
86
90
 
87
- should "use it" do
91
+ should "use a single host" do
88
92
  c = Elasticsearch::Transport::Client.new
93
+
94
+ assert_equal 1, c.transport.hosts.size
89
95
  assert_equal 'foobar', c.transport.hosts.first[:host]
90
96
  end
97
+
98
+ should "use multiple hosts" do
99
+ ENV['ELASTICSEARCH_URL'] = 'foo, bar'
100
+ c = Elasticsearch::Transport::Client.new
101
+
102
+ assert_equal 2, c.transport.hosts.size
103
+ assert_equal 'foo', c.transport.hosts[0][:host]
104
+ assert_equal 'bar', c.transport.hosts[1][:host]
105
+ end
91
106
  end
92
107
 
93
108
  context "extracting hosts" do
@@ -98,6 +113,13 @@ class Elasticsearch::Transport::ClientTest < Test::Unit::TestCase
98
113
  assert_nil hosts[0][:port]
99
114
  end
100
115
 
116
+ should "extract from hash" do
117
+ hosts = @client.__extract_hosts( { :host => 'myhost', :scheme => 'https' } )
118
+
119
+ assert_equal 'myhost', hosts[0][:host]
120
+ assert_equal 'https', hosts[0][:scheme]
121
+ end
122
+
101
123
  should "extract from array" do
102
124
  hosts = @client.__extract_hosts ['myhost']
103
125
 
@@ -114,6 +136,8 @@ class Elasticsearch::Transport::ClientTest < Test::Unit::TestCase
114
136
  should "extract from array with ports" do
115
137
  hosts = @client.__extract_hosts ['host1:1000', 'host2:2000']
116
138
 
139
+ assert_equal 2, hosts.size
140
+
117
141
  assert_equal 'host1', hosts[0][:host]
118
142
  assert_equal '1000', hosts[0][:port]
119
143
 
@@ -145,7 +169,7 @@ class Elasticsearch::Transport::ClientTest < Test::Unit::TestCase
145
169
  assert_equal '8080', hosts[0][:port]
146
170
  end
147
171
 
148
- should "pass Hashes over" do
172
+ should "pass hashes over" do
149
173
  hosts = @client.__extract_hosts [{:host => 'myhost', :port => '1000', :foo => 'bar'}]
150
174
 
151
175
  assert_equal 'myhost', hosts[0][:host]
@@ -164,6 +188,15 @@ class Elasticsearch::Transport::ClientTest < Test::Unit::TestCase
164
188
  assert_equal '4430', hosts[0][:port]
165
189
  end
166
190
 
191
+ should "split comma-separated URLs" do
192
+ hosts = @client.__extract_hosts 'foo, bar'
193
+
194
+ assert_equal 2, hosts.size
195
+
196
+ assert_equal 'foo', hosts[0][:host]
197
+ assert_equal 'bar', hosts[1][:host]
198
+ end
199
+
167
200
  should "raise error for incompatible argument" do
168
201
  assert_raise ArgumentError do
169
202
  @client.__extract_hosts 123
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.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karel Minarik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-23 00:00:00.000000000 Z
11
+ date: 2015-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json