elasticsearch-transport 6.8.3 → 7.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +17 -0
- data/LICENSE.txt +199 -10
- data/README.md +32 -86
- data/Rakefile +23 -4
- data/elasticsearch-transport.gemspec +78 -45
- data/lib/elasticsearch-transport.rb +16 -3
- data/lib/elasticsearch/transport.rb +17 -3
- data/lib/elasticsearch/transport/client.rb +70 -174
- data/lib/elasticsearch/transport/redacted.rb +5 -9
- data/lib/elasticsearch/transport/transport/base.rb +63 -55
- data/lib/elasticsearch/transport/transport/connections/collection.rb +16 -3
- data/lib/elasticsearch/transport/transport/connections/connection.rb +16 -3
- data/lib/elasticsearch/transport/transport/connections/selector.rb +16 -3
- data/lib/elasticsearch/transport/transport/errors.rb +16 -3
- data/lib/elasticsearch/transport/transport/http/curb.rb +18 -5
- data/lib/elasticsearch/transport/transport/http/faraday.rb +18 -5
- data/lib/elasticsearch/transport/transport/http/manticore.rb +17 -4
- data/lib/elasticsearch/transport/transport/loggable.rb +85 -0
- data/lib/elasticsearch/transport/transport/response.rb +16 -3
- data/lib/elasticsearch/transport/transport/serializer/multi_json.rb +16 -3
- data/lib/elasticsearch/transport/transport/sniffer.rb +17 -5
- data/lib/elasticsearch/transport/version.rb +17 -4
- data/spec/elasticsearch/transport/base_spec.rb +8 -187
- data/spec/elasticsearch/transport/client_spec.rb +29 -163
- data/spec/elasticsearch/transport/sniffer_spec.rb +19 -0
- data/spec/spec_helper.rb +2 -11
- data/test/integration/transport_test.rb +18 -5
- data/test/profile/client_benchmark_test.rb +16 -3
- data/test/test_helper.rb +63 -14
- data/test/unit/connection_collection_test.rb +17 -4
- data/test/unit/connection_selector_test.rb +17 -4
- data/test/unit/connection_test.rb +17 -4
- data/test/unit/response_test.rb +18 -5
- data/test/unit/serializer_test.rb +17 -4
- data/test/unit/transport_base_test.rb +21 -8
- data/test/unit/transport_curb_test.rb +17 -4
- data/test/unit/transport_faraday_test.rb +17 -4
- data/test/unit/transport_manticore_test.rb +24 -6
- metadata +61 -86
- data/spec/elasticsearch/transport/meta_header_spec.rb +0 -214
@@ -1,59 +1,92 @@
|
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
6
|
+
# not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
17
|
+
|
1
18
|
# coding: utf-8
|
2
19
|
lib = File.expand_path('../lib', __FILE__)
|
3
20
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
21
|
require 'elasticsearch/transport/version'
|
5
22
|
|
6
23
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
24
|
+
s.name = "elasticsearch-transport"
|
8
25
|
s.version = Elasticsearch::Transport::VERSION
|
9
|
-
s.authors = [
|
10
|
-
s.email = [
|
11
|
-
s.summary =
|
12
|
-
s.homepage =
|
13
|
-
s.license =
|
14
|
-
|
15
|
-
'homepage_uri' => 'https://www.elastic.co/guide/en/elasticsearch/client/ruby-api/current/index.html',
|
16
|
-
'changelog_uri' => 'https://github.com/elastic/elasticsearch-ruby/blob/6.x/CHANGELOG.md',
|
17
|
-
'source_code_uri' => 'https://github.com/elastic/elasticsearch-ruby/tree/6.x/elasticsearch-transport',
|
18
|
-
'bug_tracker_uri' => 'https://github.com/elastic/elasticsearch-ruby/issues'
|
19
|
-
}
|
26
|
+
s.authors = ["Karel Minarik"]
|
27
|
+
s.email = ["karel.minarik@elasticsearch.org"]
|
28
|
+
s.summary = "Ruby client for Elasticsearch."
|
29
|
+
s.homepage = "https://github.com/elasticsearch/elasticsearch-ruby/tree/master/elasticsearch-transport"
|
30
|
+
s.license = "Apache-2.0"
|
31
|
+
|
20
32
|
s.files = `git ls-files`.split($/)
|
21
33
|
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
22
34
|
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
23
|
-
s.require_paths = [
|
24
|
-
|
25
|
-
s.extra_rdoc_files = [
|
26
|
-
s.rdoc_options = [
|
27
|
-
|
28
|
-
s.required_ruby_version = '>=
|
29
|
-
|
30
|
-
s.add_dependency
|
31
|
-
s.add_dependency
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
s.add_development_dependency
|
38
|
-
|
39
|
-
|
40
|
-
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
|
37
|
+
s.extra_rdoc_files = [ "README.md", "LICENSE.txt" ]
|
38
|
+
s.rdoc_options = [ "--charset=UTF-8" ]
|
39
|
+
|
40
|
+
s.required_ruby_version = '>= 1.9'
|
41
|
+
|
42
|
+
s.add_dependency "multi_json"
|
43
|
+
s.add_dependency "faraday"
|
44
|
+
|
45
|
+
if defined?(RUBY_VERSION) && RUBY_VERSION < '1.9'
|
46
|
+
s.add_dependency "system_timer"
|
47
|
+
end
|
48
|
+
|
49
|
+
s.add_development_dependency "bundler"
|
50
|
+
|
51
|
+
if defined?(RUBY_VERSION) && RUBY_VERSION > '1.9'
|
52
|
+
s.add_development_dependency "rake", "~> 11.1"
|
53
|
+
else
|
54
|
+
s.add_development_dependency "rake", "< 11.0"
|
55
|
+
end
|
56
|
+
|
57
|
+
s.add_development_dependency "ansi"
|
58
|
+
s.add_development_dependency "shoulda-context"
|
59
|
+
s.add_development_dependency "mocha"
|
60
|
+
s.add_development_dependency "yard"
|
61
|
+
s.add_development_dependency "pry"
|
62
|
+
|
41
63
|
# Gems for testing integrations
|
42
|
-
s.add_development_dependency
|
43
|
-
s.add_development_dependency
|
44
|
-
s.add_development_dependency '
|
45
|
-
s.add_development_dependency
|
46
|
-
s.add_development_dependency
|
47
|
-
s.add_development_dependency
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
s.add_development_dependency
|
64
|
+
s.add_development_dependency "curb" unless defined? JRUBY_VERSION
|
65
|
+
s.add_development_dependency "patron" unless defined? JRUBY_VERSION
|
66
|
+
s.add_development_dependency "typhoeus", '~> 0.6'
|
67
|
+
s.add_development_dependency "net-http-persistent"
|
68
|
+
s.add_development_dependency "manticore", '~> 0.6' if defined? JRUBY_VERSION
|
69
|
+
s.add_development_dependency "hashie"
|
70
|
+
|
71
|
+
# Prevent unit test failures on Ruby 1.8
|
72
|
+
if defined?(RUBY_VERSION) && RUBY_VERSION < '1.9'
|
73
|
+
s.add_development_dependency "test-unit", '~> 2'
|
74
|
+
s.add_development_dependency "json", '~> 1.8'
|
75
|
+
end
|
76
|
+
|
77
|
+
if defined?(RUBY_VERSION) && RUBY_VERSION > '1.9'
|
78
|
+
s.add_development_dependency "minitest"
|
79
|
+
s.add_development_dependency "minitest-reporters"
|
80
|
+
s.add_development_dependency "elasticsearch-extensions"
|
81
|
+
s.add_development_dependency "ruby-prof" unless defined?(JRUBY_VERSION) || defined?(Rubinius)
|
82
|
+
s.add_development_dependency "require-prof" unless defined?(JRUBY_VERSION) || defined?(Rubinius)
|
83
|
+
s.add_development_dependency "simplecov"
|
84
|
+
s.add_development_dependency "simplecov-rcov"
|
85
|
+
s.add_development_dependency "cane"
|
86
|
+
end
|
87
|
+
|
88
|
+
if defined?(RUBY_VERSION) && RUBY_VERSION > '2.2'
|
89
|
+
s.add_development_dependency "test-unit", '~> 2'
|
57
90
|
end
|
58
91
|
|
59
92
|
s.description = <<-DESC.gsub(/^ /, '')
|
@@ -1,5 +1,18 @@
|
|
1
|
-
# Licensed to Elasticsearch B.V under one or more
|
2
|
-
#
|
3
|
-
#
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
6
|
+
# not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
4
17
|
|
5
18
|
require 'elasticsearch/transport'
|
@@ -1,6 +1,19 @@
|
|
1
|
-
# Licensed to Elasticsearch B.V under one or more
|
2
|
-
#
|
3
|
-
#
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
6
|
+
# not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
4
17
|
|
5
18
|
require "uri"
|
6
19
|
require "time"
|
@@ -8,6 +21,7 @@ require "timeout"
|
|
8
21
|
require "multi_json"
|
9
22
|
require "faraday"
|
10
23
|
|
24
|
+
require "elasticsearch/transport/transport/loggable"
|
11
25
|
require "elasticsearch/transport/transport/serializer/multi_json"
|
12
26
|
require "elasticsearch/transport/transport/sniffer"
|
13
27
|
require "elasticsearch/transport/transport/response"
|
@@ -1,6 +1,19 @@
|
|
1
|
-
# Licensed to Elasticsearch B.V under one or more
|
2
|
-
#
|
3
|
-
#
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
6
|
+
# not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
4
17
|
|
5
18
|
module Elasticsearch
|
6
19
|
module Transport
|
@@ -89,19 +102,11 @@ module Elasticsearch
|
|
89
102
|
# @option arguments [String] :send_get_body_as Specify the HTTP method to use for GET requests with a body.
|
90
103
|
# (Default: GET)
|
91
104
|
#
|
92
|
-
# @option api_key [String, Hash] :api_key Use API Key Authentication, either the base64 encoding of `id` and `api_key`
|
93
|
-
# joined by a colon as a String, or a hash with the `id` and `api_key` values.
|
94
|
-
# @option opaque_id_prefix [String] :opaque_id_prefix set a prefix for X-Opaque-Id when initializing the client. This
|
95
|
-
# will be prepended to the id you set before each request if
|
96
|
-
# you're using X-Opaque-Id
|
97
|
-
# @option enable_meta_header [Boolean] :enable_meta_header Enable sending the meta data header to Cloud.
|
98
|
-
# (Default: true)
|
99
|
-
#
|
100
105
|
# @yield [faraday] Access and configure the `Faraday::Connection` instance directly with a block
|
101
106
|
#
|
102
|
-
def initialize(arguments
|
103
|
-
@options = arguments
|
104
|
-
@arguments =
|
107
|
+
def initialize(arguments={}, &block)
|
108
|
+
@options = arguments
|
109
|
+
@arguments = arguments
|
105
110
|
@arguments[:logger] ||= @arguments[:log] ? DEFAULT_LOGGER.call() : nil
|
106
111
|
@arguments[:tracer] ||= @arguments[:trace] ? DEFAULT_TRACER.call() : nil
|
107
112
|
@arguments[:reload_connections] ||= false
|
@@ -110,13 +115,9 @@ module Elasticsearch
|
|
110
115
|
@arguments[:randomize_hosts] ||= false
|
111
116
|
@arguments[:transport_options] ||= {}
|
112
117
|
@arguments[:http] ||= {}
|
113
|
-
@
|
114
|
-
@options[:http] ||= {}
|
115
|
-
|
116
|
-
set_api_key if (@api_key = @arguments[:api_key])
|
117
|
-
|
118
|
+
@options[:http] ||= {}
|
118
119
|
|
119
|
-
@seeds
|
120
|
+
@seeds = __extract_hosts(@arguments[:hosts] ||
|
120
121
|
@arguments[:host] ||
|
121
122
|
@arguments[:url] ||
|
122
123
|
@arguments[:urls] ||
|
@@ -124,10 +125,9 @@ module Elasticsearch
|
|
124
125
|
DEFAULT_HOST)
|
125
126
|
|
126
127
|
@send_get_body_as = @arguments[:send_get_body_as] || 'GET'
|
127
|
-
@opaque_id_prefix = @arguments[:opaque_id_prefix] || nil
|
128
128
|
|
129
129
|
if @arguments[:request_timeout]
|
130
|
-
@arguments[:transport_options][:request] = { timeout
|
130
|
+
@arguments[:transport_options][:request] = { :timeout => @arguments[:request_timeout] }
|
131
131
|
end
|
132
132
|
|
133
133
|
@arguments[:transport_options][:headers] ||= {}
|
@@ -139,120 +139,29 @@ module Elasticsearch
|
|
139
139
|
if @arguments[:transport]
|
140
140
|
@transport = @arguments[:transport]
|
141
141
|
else
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
end
|
142
|
+
transport_class = @arguments[:transport_class] || DEFAULT_TRANSPORT_CLASS
|
143
|
+
if transport_class == Transport::HTTP::Faraday
|
144
|
+
@transport = transport_class.new(:hosts => @seeds, :options => @arguments) do |faraday|
|
145
|
+
block.call faraday if block
|
146
|
+
unless (h = faraday.builder.handlers.last) && h.name.start_with?("Faraday::Adapter")
|
147
|
+
faraday.adapter(@arguments[:adapter] || __auto_detect_adapter)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
else
|
151
|
+
@transport = transport_class.new(:hosts => @seeds, :options => @arguments)
|
152
|
+
end
|
154
153
|
end
|
155
154
|
end
|
156
155
|
|
157
156
|
# Performs a request through delegation to {#transport}.
|
158
157
|
#
|
159
|
-
def perform_request(method, path, params
|
158
|
+
def perform_request(method, path, params={}, body=nil, headers=nil)
|
160
159
|
method = @send_get_body_as if 'GET' == method && body
|
161
|
-
if (opaque_id = params.delete(:opaque_id))
|
162
|
-
headers = {} if headers.nil?
|
163
|
-
opaque_id = @opaque_id_prefix ? "#{@opaque_id_prefix}#{opaque_id}" : opaque_id
|
164
|
-
headers.merge!('X-Opaque-Id' => opaque_id)
|
165
|
-
end
|
166
160
|
transport.perform_request(method, path, params, body, headers)
|
167
161
|
end
|
168
162
|
|
169
163
|
private
|
170
164
|
|
171
|
-
def set_api_key
|
172
|
-
@api_key = __encode(@api_key) if @api_key.is_a? Hash
|
173
|
-
add_header('Authorization' => "ApiKey #{@api_key}")
|
174
|
-
@arguments.delete(:user)
|
175
|
-
@arguments.delete(:password)
|
176
|
-
end
|
177
|
-
|
178
|
-
def add_header(header)
|
179
|
-
headers = @arguments[:transport_options]&.[](:headers) || {}
|
180
|
-
headers.merge!(header)
|
181
|
-
@arguments[:transport_options].merge!(
|
182
|
-
headers: headers
|
183
|
-
)
|
184
|
-
end
|
185
|
-
|
186
|
-
def set_meta_header
|
187
|
-
return if @arguments[:enable_meta_header] == false
|
188
|
-
|
189
|
-
service, version = meta_header_service_version
|
190
|
-
|
191
|
-
meta_headers = {
|
192
|
-
service.to_sym => version,
|
193
|
-
rb: RUBY_VERSION,
|
194
|
-
t: Elasticsearch::Transport::VERSION
|
195
|
-
}
|
196
|
-
meta_headers.merge!(meta_header_engine) if meta_header_engine
|
197
|
-
meta_headers.merge!(meta_header_adapter) if meta_header_adapter
|
198
|
-
|
199
|
-
add_header({ 'x-elastic-client-meta' => meta_headers.map { |k, v| "#{k}=#{v}" }.join(',') })
|
200
|
-
end
|
201
|
-
|
202
|
-
def meta_header_service_version
|
203
|
-
if defined?(Elastic::META_HEADER_SERVICE_VERSION)
|
204
|
-
Elastic::META_HEADER_SERVICE_VERSION
|
205
|
-
elsif defined?(Elasticsearch::VERSION)
|
206
|
-
[:es, client_meta_version(Elasticsearch::VERSION)]
|
207
|
-
else
|
208
|
-
[:es, client_meta_version(Elasticsearch::Transport::VERSION)]
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
def client_meta_version(version)
|
213
|
-
regexp = /^([0-9]+\.[0-9]+\.[0-9]+)(\.?[a-z0-9.-]+)?$/
|
214
|
-
match = version.match(regexp)
|
215
|
-
return "#{match[1]}p" if (match[2])
|
216
|
-
|
217
|
-
version
|
218
|
-
end
|
219
|
-
|
220
|
-
def meta_header_engine
|
221
|
-
case RUBY_ENGINE
|
222
|
-
when 'ruby'
|
223
|
-
{}
|
224
|
-
when 'jruby'
|
225
|
-
{ jv: ENV_JAVA['java.version'], jr: JRUBY_VERSION }
|
226
|
-
when 'rbx'
|
227
|
-
{ rbx: RUBY_VERSION }
|
228
|
-
else
|
229
|
-
{ RUBY_ENGINE.to_sym => RUBY_VERSION }
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
def meta_header_adapter
|
234
|
-
if @transport_class == Transport::HTTP::Faraday
|
235
|
-
{fd: Faraday::VERSION}.merge(
|
236
|
-
case @arguments[:adapter]
|
237
|
-
when :patron
|
238
|
-
{pt: Patron::VERSION}
|
239
|
-
when :net_http
|
240
|
-
{nh: defined?(Net::HTTP::VERSION) ? Net::HTTP::VERSION : Net::HTTP::HTTPVersion}
|
241
|
-
when :typhoeus
|
242
|
-
{ty: Typhoeus::VERSION}
|
243
|
-
when :httpclient
|
244
|
-
{hc: HTTPClient::VERSION}
|
245
|
-
when :net_http_persistent
|
246
|
-
{np: Net::HTTP::Persistent::VERSION}
|
247
|
-
end
|
248
|
-
)
|
249
|
-
elsif defined?(Transport::HTTP::Curb) && @transport_class == Transport::HTTP::Curb
|
250
|
-
{cl: Curl::CURB_VERSION}
|
251
|
-
elsif defined?(Transport::HTTP::Manticore) && @transport_class == Transport::HTTP::Manticore
|
252
|
-
{mc: Manticore::VERSION}
|
253
|
-
end
|
254
|
-
end
|
255
|
-
|
256
165
|
# Normalizes and returns hosts configuration.
|
257
166
|
#
|
258
167
|
# Arrayifies the `hosts_config` argument and extracts `host` and `port` info from strings.
|
@@ -267,15 +176,15 @@ module Elasticsearch
|
|
267
176
|
#
|
268
177
|
def __extract_hosts(hosts_config)
|
269
178
|
hosts = case hosts_config
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
179
|
+
when String
|
180
|
+
hosts_config.split(',').map { |h| h.strip! || h }
|
181
|
+
when Array
|
182
|
+
hosts_config
|
183
|
+
when Hash, URI
|
184
|
+
[ hosts_config ]
|
185
|
+
else
|
186
|
+
Array(hosts_config)
|
187
|
+
end
|
279
188
|
|
280
189
|
host_list = hosts.map { |host| __parse_host(host) }
|
281
190
|
@options[:randomize_hosts] ? host_list.shuffle! : host_list
|
@@ -283,42 +192,36 @@ module Elasticsearch
|
|
283
192
|
|
284
193
|
def __parse_host(host)
|
285
194
|
host_parts = case host
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
else
|
310
|
-
raise ArgumentError, "Please pass host as a String, URI or Hash -- #{host.class} given."
|
311
|
-
end
|
312
|
-
|
313
|
-
if @api_key
|
314
|
-
# Remove Basic Auth if using API KEY
|
315
|
-
host_parts.delete(:user)
|
316
|
-
host_parts.delete(:password)
|
195
|
+
when String
|
196
|
+
if host =~ /^[a-z]+\:\/\//
|
197
|
+
uri = URI.parse(host)
|
198
|
+
{ :scheme => uri.scheme,
|
199
|
+
:user => uri.user,
|
200
|
+
:password => uri.password,
|
201
|
+
:host => uri.host,
|
202
|
+
:path => uri.path,
|
203
|
+
:port => uri.port }
|
204
|
+
else
|
205
|
+
host, port = host.split(':')
|
206
|
+
{ :host => host,
|
207
|
+
:port => port }
|
208
|
+
end
|
209
|
+
when URI
|
210
|
+
{ :scheme => host.scheme,
|
211
|
+
:user => host.user,
|
212
|
+
:password => host.password,
|
213
|
+
:host => host.host,
|
214
|
+
:path => host.path,
|
215
|
+
:port => host.port }
|
216
|
+
when Hash
|
217
|
+
host
|
317
218
|
else
|
318
|
-
|
319
|
-
@options[:http][:password] ||= host_parts[:password]
|
219
|
+
raise ArgumentError, "Please pass host as a String, URI or Hash -- #{host.class} given."
|
320
220
|
end
|
321
221
|
|
222
|
+
@options[:http][:user] ||= host_parts[:user]
|
223
|
+
@options[:http][:password] ||= host_parts[:password]
|
224
|
+
|
322
225
|
host_parts[:port] = host_parts[:port].to_i if host_parts[:port]
|
323
226
|
host_parts[:path].chomp!('/') if host_parts[:path]
|
324
227
|
host_parts
|
@@ -346,13 +249,6 @@ module Elasticsearch
|
|
346
249
|
::Faraday.default_adapter
|
347
250
|
end
|
348
251
|
end
|
349
|
-
|
350
|
-
# Encode credentials for the Authorization Header
|
351
|
-
# Credentials is the base64 encoding of id and api_key joined by a colon
|
352
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-create-api-key.html
|
353
|
-
def __encode(api_key)
|
354
|
-
Base64.strict_encode64([api_key[:id], api_key[:api_key]].join(':'))
|
355
|
-
end
|
356
252
|
end
|
357
253
|
end
|
358
254
|
end
|