elasticsearch-transport 1.0.15 → 1.0.16.pre

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: c8912230f142b53ab174f9cb27d98c3faa220517
4
- data.tar.gz: d561830a59e77b6daf839a4b7fef09394506ea98
3
+ metadata.gz: 9ed68a35342a6cb66f67c6bd8de44bbb21a4eea6
4
+ data.tar.gz: 8e7cb53702e1103a44555a3d6364aec3c759b2b4
5
5
  SHA512:
6
- metadata.gz: 6a41d9e20a098bb9731e7029daf96996c92e898b982fef262ac290cd680dde7a5d99d8d6134aaca5c9a1df31dc525aeee603e0881d80ae972315b7524579e7e6
7
- data.tar.gz: 83667f70dc3c27c925f63ec0def5400f292f60bfe4b9b83629c74a243adb8a0dd23ecd45dd247c9530da06bb7429411cddc10355b00c40a1e64e6250c21e9062
6
+ metadata.gz: 4927b38e7a37068ed3893fd4441e052d6c49cb8f5bbeb346400a5dd5fb58e75a6a31a1b7aae368e580bf63f20624ff4fcb9ede1db950feaeef954eabdd3f0707
7
+ data.tar.gz: fb1bd274b0d768529d453efa5b27194c61ff00b214c642818c9cb890ea2ca772772ec47e7cc04f8c5fc9a99222f8f25825d38b72bed1d91d8185d7aba5847f1e
data/Gemfile CHANGED
@@ -3,14 +3,14 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in elasticsearch-transport.gemspec
4
4
  gemspec
5
5
 
6
- if File.exists? File.expand_path("../../elasticsearch-api/elasticsearch-api.gemspec", __FILE__)
6
+ if File.exist? File.expand_path("../../elasticsearch-api/elasticsearch-api.gemspec", __FILE__)
7
7
  gem 'elasticsearch-api', :path => File.expand_path("../../elasticsearch-api", __FILE__), :require => false
8
8
  end
9
9
 
10
- if File.exists? File.expand_path("../../elasticsearch-extensions", __FILE__)
10
+ if File.exist? File.expand_path("../../elasticsearch-extensions", __FILE__)
11
11
  gem 'elasticsearch-extensions', :path => File.expand_path("../../elasticsearch-extensions", __FILE__), :require => false
12
12
  end
13
13
 
14
- if File.exists? File.expand_path("../../elasticsearch/elasticsearch.gemspec", __FILE__)
14
+ if File.exist? File.expand_path("../../elasticsearch/elasticsearch.gemspec", __FILE__)
15
15
  gem 'elasticsearch', :path => File.expand_path("../../elasticsearch", __FILE__), :require => false
16
16
  end
data/README.md CHANGED
@@ -295,7 +295,6 @@ To configure the _Faraday_ instance directly, use a block:
295
295
  You can use any standard Faraday middleware and plugins in the configuration block,
296
296
  for example sign the requests for the [AWS Elasticsearch service](https://aws.amazon.com/elasticsearch-service/):
297
297
 
298
- require 'patron'
299
298
  require 'faraday_middleware/aws_signers_v4'
300
299
 
301
300
  client = Elasticsearch::Client.new url: 'https://search-my-cluster-abc123....es.amazonaws.com' do |f|
@@ -28,7 +28,7 @@ Gem::Specification.new do |s|
28
28
  end
29
29
 
30
30
  s.add_development_dependency "bundler", "> 1"
31
- s.add_development_dependency "rake"
31
+ s.add_development_dependency "rake", "< 11.0"
32
32
 
33
33
  if defined?(RUBY_VERSION) && RUBY_VERSION > '1.9'
34
34
  s.add_development_dependency "elasticsearch-extensions"
@@ -47,7 +47,7 @@ Gem::Specification.new do |s|
47
47
  s.add_development_dependency "patron" unless defined? JRUBY_VERSION
48
48
  s.add_development_dependency "typhoeus", '~> 0.6'
49
49
  s.add_development_dependency "net-http-persistent"
50
- s.add_development_dependency "manticore", '~> 0.3.5' if defined? JRUBY_VERSION
50
+ s.add_development_dependency "manticore", '~> 0.5.2' if defined? JRUBY_VERSION
51
51
  s.add_development_dependency "hashie"
52
52
 
53
53
  # Prevent unit test failures on Ruby 1.8
@@ -11,6 +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(15)
14
15
 
15
16
  attr_reader :hosts, :options, :connections, :counter, :last_request_at, :protocol
16
17
  attr_accessor :serializer, :sniffer, :logger, :tracer,
@@ -28,6 +29,8 @@ module Elasticsearch
28
29
  # @see Client#initialize
29
30
  #
30
31
  def initialize(arguments={}, &block)
32
+ @state_mutex = Mutex.new
33
+
31
34
  @hosts = arguments[:hosts] || []
32
35
  @options = arguments[:options] || {}
33
36
  @block = block
@@ -94,10 +97,12 @@ module Elasticsearch
94
97
  # @api private
95
98
  #
96
99
  def __rebuild_connections(arguments={})
97
- @hosts = arguments[:hosts] || []
98
- @options = arguments[:options] || {}
99
- __close_connections
100
- @connections = __build_connections
100
+ @state_mutex.synchronize do
101
+ @hosts = arguments[:hosts] || []
102
+ @options = arguments[:options] || {}
103
+ __close_connections
104
+ @connections = __build_connections
105
+ end
101
106
  end
102
107
 
103
108
  # Closes the connections collection.
@@ -113,7 +118,8 @@ module Elasticsearch
113
118
  # @api private
114
119
  #
115
120
  def __log(method, path, params, body, url, response, json, took, duration)
116
- logger.info "#{method.to_s.upcase} #{url} " +
121
+ sanitized_url = url.to_s.gsub(/\/\/(.+):(.+)@/, '//' + '\1:' + SANITIZED_PASSWORD + '@')
122
+ logger.info "#{method.to_s.upcase} #{sanitized_url} " +
117
123
  "[status:#{response.status}, request:#{sprintf('%.3fs', duration)}, query:#{took}]"
118
124
  logger.debug "> #{__convert_to_json(body)}" if body
119
125
  logger.debug "< #{response.body}"
@@ -160,7 +166,7 @@ module Elasticsearch
160
166
  # @api private
161
167
  def __full_url(host)
162
168
  url = "#{host[:protocol]}://"
163
- url += "#{host[:user]}:#{host[:password]}@" if host[:user]
169
+ url += "#{CGI.escape(host[:user])}:#{CGI.escape(host[:password])}@" if host[:user]
164
170
  url += "#{host[:host]}:#{host[:port]}"
165
171
  url += "#{host[:path]}" if host[:path]
166
172
  url
@@ -29,6 +29,7 @@ module Elasticsearch
29
29
  @state_mutex = Mutex.new
30
30
 
31
31
  @options[:resurrect_timeout] ||= DEFAULT_RESURRECT_TIMEOUT
32
+ @dead = false
32
33
  @failures = 0
33
34
  end
34
35
 
@@ -50,7 +50,7 @@ module Elasticsearch
50
50
  #
51
51
  def select(options={})
52
52
  # On Ruby 1.9, Array#rotate could be used instead
53
- @current = @current.nil? ? 0 : @current+1
53
+ @current = !defined?(@current) || @current.nil? ? 0 : @current+1
54
54
  @current = 0 if @current >= connections.size
55
55
  connections[@current]
56
56
  end
@@ -57,7 +57,7 @@ module Elasticsearch
57
57
  client.password = host[:password]
58
58
  end
59
59
 
60
- client.instance_eval &@block if @block
60
+ client.instance_eval(&@block) if @block
61
61
 
62
62
  Connections::Connection.new :host => host, :connection => client
63
63
  },
@@ -45,6 +45,19 @@ module Elasticsearch
45
45
  class Manticore
46
46
  include Base
47
47
 
48
+ def initialize(arguments={}, &block)
49
+ @manticore = build_client(arguments[:options] || {})
50
+ super(arguments, &block)
51
+ end
52
+
53
+ # Should just be run once at startup
54
+ def build_client(options={})
55
+ client_options = options[:transport_options] || {}
56
+ client_options[:ssl] = options[:ssl] || {}
57
+
58
+ @manticore = ::Manticore::Client.new(client_options)
59
+ end
60
+
48
61
  # Performs the request by invoking {Transport::Base#perform_request} with a block.
49
62
  #
50
63
  # @return [Response]
@@ -84,9 +97,6 @@ module Elasticsearch
84
97
  @request_options[:headers] = options[:headers]
85
98
  end
86
99
 
87
- client_options = options[:transport_options] || {}
88
- client_options[:ssl] = options[:ssl] || {}
89
-
90
100
  Connections::Collection.new \
91
101
  :connections => hosts.map { |host|
92
102
  host[:protocol] = host[:scheme] || DEFAULT_PROTOCOL
@@ -95,11 +105,9 @@ module Elasticsearch
95
105
  host.delete(:user) # auth is not supported here.
96
106
  host.delete(:password) # use the headers
97
107
 
98
- url = __full_url(host)
99
-
100
108
  Connections::Connection.new \
101
109
  :host => host,
102
- :connection => ::Manticore::Client.new(client_options)
110
+ :connection => @manticore
103
111
  },
104
112
  :selector_class => options[:selector_class],
105
113
  :selector => options[:selector]
@@ -1,5 +1,5 @@
1
1
  module Elasticsearch
2
2
  module Transport
3
- VERSION = "1.0.15"
3
+ VERSION = "1.0.16.pre"
4
4
  end
5
5
  end
@@ -75,6 +75,11 @@ class Elasticsearch::Transport::Transport::BaseTest < Test::Unit::TestCase
75
75
  should "combine authentication credentials" do
76
76
  assert_equal 'http://U:P@myhost:8080', @transport.__full_url(@basic_parts.merge :user => 'U', :password => 'P')
77
77
  end
78
+
79
+ should "escape the username and password" do
80
+ assert_equal 'http://user%40domain:foo%2Fbar@myhost:8080',
81
+ @transport.__full_url(@basic_parts.merge :user => 'user@domain', :password => 'foo/bar')
82
+ end
78
83
  end
79
84
  end
80
85
 
@@ -370,6 +375,23 @@ class Elasticsearch::Transport::Transport::BaseTest < Test::Unit::TestCase
370
375
  end
371
376
  end
372
377
 
378
+ should "sanitize password in the URL" do
379
+ fake_connection = stub :full_url => 'http://user:password@localhost:9200/_search?size=1',
380
+ :host => 'localhost',
381
+ :connection => stub_everything,
382
+ :failures => 0,
383
+ :healthy! => true
384
+ @transport.stubs(:get_connection).returns(fake_connection)
385
+
386
+ @transport.logger.expects(:info).with do |message|
387
+ assert_match /http:\/\/user:\*{1,15}@localhost\:9200/, message
388
+ true
389
+ end
390
+
391
+
392
+ @transport.perform_request('GET', '/') {Elasticsearch::Transport::Transport::Response.new 200, '{"foo":"bar"}' }
393
+ end
394
+
373
395
  should "log a failed Elasticsearch request" do
374
396
  @block = Proc.new { |c, u| puts "ERROR" }
375
397
  @block.expects(:call).returns(Elasticsearch::Transport::Transport::Response.new 500, 'ERROR')
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.15
4
+ version: 1.0.16.pre
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-12-04 00:00:00.000000000 Z
11
+ date: 2016-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "<"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '11.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "<"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '11.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: elasticsearch-extensions
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -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: '0'
399
+ version: 1.3.1
400
400
  requirements: []
401
401
  rubyforge_project:
402
402
  rubygems_version: 2.2.2