elasticsearch 8.17.2 → 9.0.0
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 +4 -4
- data/elasticsearch.gemspec +7 -6
- data/lib/elasticsearch/version.rb +1 -1
- data/lib/elasticsearch.rb +8 -6
- metadata +14 -48
- data/Gemfile +0 -35
- data/Rakefile +0 -54
- data/spec/integration/characters_escaping_spec.rb +0 -96
- data/spec/integration/client_integration_spec.rb +0 -64
- data/spec/integration/helpers/bulk_helper_spec.rb +0 -206
- data/spec/integration/helpers/esql_helper_spec.rb +0 -118
- data/spec/integration/helpers/helpers_spec_helper.rb +0 -29
- data/spec/integration/helpers/scroll_helper_spec.rb +0 -83
- data/spec/integration/opentelemetry_spec.rb +0 -55
- data/spec/spec_helper.rb +0 -43
- data/spec/unit/api_key_spec.rb +0 -138
- data/spec/unit/cloud_credentials_spec.rb +0 -167
- data/spec/unit/custom_transport_implementation_spec.rb +0 -43
- data/spec/unit/elasticsearch_product_validation_spec.rb +0 -148
- data/spec/unit/headers_spec.rb +0 -55
- data/spec/unit/opaque_id_spec.rb +0 -48
- data/spec/unit/user_agent_spec.rb +0 -69
- data/spec/unit/wrapper_gem_spec.rb +0 -33
@@ -1,118 +0,0 @@
|
|
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
|
-
require_relative 'helpers_spec_helper'
|
18
|
-
require 'elasticsearch/helpers/esql_helper'
|
19
|
-
require 'ipaddr'
|
20
|
-
|
21
|
-
context 'Elasticsearch client helpers' do
|
22
|
-
let(:index) { 'esql_helper_test' }
|
23
|
-
let(:body) { { size: 12, query: { match_all: {} } } }
|
24
|
-
let(:esql_helper) { Elasticsearch::Helpers::ESQLHelper }
|
25
|
-
let(:query) do
|
26
|
-
<<~ESQL
|
27
|
-
FROM #{index}
|
28
|
-
| EVAL duration_ms = ROUND(event.duration / 1000000.0, 1)
|
29
|
-
ESQL
|
30
|
-
end
|
31
|
-
|
32
|
-
before do
|
33
|
-
client.indices.create(
|
34
|
-
index: index,
|
35
|
-
body: {
|
36
|
-
mappings: {
|
37
|
-
properties: { 'client.ip' => { type: 'ip' }, message: { type: 'keyword' } }
|
38
|
-
}
|
39
|
-
}
|
40
|
-
)
|
41
|
-
client.bulk(
|
42
|
-
index: index,
|
43
|
-
body: [
|
44
|
-
{'index': {}},
|
45
|
-
{'@timestamp' => '2023-10-23T12:15:03.360Z', 'client.ip' => '172.21.2.162', message: 'Connected to 10.1.0.3', 'event.duration' => 3450233},
|
46
|
-
{'index': {}},
|
47
|
-
{'@timestamp' => '2023-10-23T12:27:28.948Z', 'client.ip' => '172.21.2.113', message: 'Connected to 10.1.0.2', 'event.duration' => 2764889},
|
48
|
-
{'index': {}},
|
49
|
-
{'@timestamp' => '2023-10-23T13:33:34.937Z', 'client.ip' => '172.21.0.5', message: 'Disconnected', 'event.duration' => 1232382},
|
50
|
-
{'index': {}},
|
51
|
-
{'@timestamp' => '2023-10-23T13:51:54.732Z', 'client.ip' => '172.21.3.15', message: 'Connection error', 'event.duration' => 725448},
|
52
|
-
{'index': {}},
|
53
|
-
{'@timestamp' => '2023-10-23T13:52:55.015Z', 'client.ip' => '172.21.3.15', message: 'Connection error', 'event.duration' => 8268153},
|
54
|
-
{'index': {}},
|
55
|
-
{'@timestamp' => '2023-10-23T13:53:55.832Z', 'client.ip' => '172.21.3.15', message: 'Connection error', 'event.duration' => 5033755},
|
56
|
-
{'index': {}},
|
57
|
-
{'@timestamp' => '2023-10-23T13:55:01.543Z', 'client.ip' => '172.21.3.15', message: 'Connected to 10.1.0.1', 'event.duration' => 1756467}
|
58
|
-
],
|
59
|
-
refresh: true
|
60
|
-
)
|
61
|
-
end
|
62
|
-
|
63
|
-
after do
|
64
|
-
client.indices.delete(index: index)
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'returns an ESQL response as a relational key/value object' do
|
68
|
-
response = esql_helper.query(client, query)
|
69
|
-
expect(response.count).to eq 7
|
70
|
-
expect(response.first.keys).to eq ['duration_ms', 'message', 'event.duration', 'client.ip', '@timestamp']
|
71
|
-
response.each do |r|
|
72
|
-
expect(r['@timestamp']).to be_a String
|
73
|
-
expect(r['client.ip']).to be_a String
|
74
|
-
expect(r['message']).to be_a String
|
75
|
-
expect(r['event.duration']).to be_a Integer
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'parses iterated objects when procs are passed in' do
|
80
|
-
parser = {
|
81
|
-
'@timestamp' => Proc.new { |t| DateTime.parse(t) },
|
82
|
-
'client.ip' => Proc.new { |i| IPAddr.new(i) },
|
83
|
-
'event.duration' => Proc.new { |d| d.to_s }
|
84
|
-
}
|
85
|
-
response = esql_helper.query(client, query, parser: parser)
|
86
|
-
response.each do |r|
|
87
|
-
expect(r['@timestamp']).to be_a DateTime
|
88
|
-
expect(r['client.ip']).to be_a IPAddr
|
89
|
-
expect(r['message']).to be_a String
|
90
|
-
expect(r['event.duration']).to be_a String
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'parser does not error when value is nil, leaves nil' do
|
95
|
-
client.index(
|
96
|
-
index: index,
|
97
|
-
body: {
|
98
|
-
'@timestamp' => nil,
|
99
|
-
'client.ip' => nil,
|
100
|
-
message: 'Connected to 10.1.0.1',
|
101
|
-
'event.duration' => 1756465
|
102
|
-
},
|
103
|
-
refresh: true
|
104
|
-
)
|
105
|
-
parser = {
|
106
|
-
'@timestamp' => Proc.new { |t| DateTime.parse(t) },
|
107
|
-
'client.ip' => Proc.new { |i| IPAddr.new(i) },
|
108
|
-
'event.duration' => Proc.new { |d| d.to_s }
|
109
|
-
}
|
110
|
-
response = esql_helper.query(client, query, parser: parser)
|
111
|
-
response.each do |r|
|
112
|
-
expect [DateTime, NilClass].include?(r['@timestamp'].class)
|
113
|
-
expect [IPAddr, NilClass].include?(r['client.ip'].class)
|
114
|
-
expect(r['message']).to be_a String
|
115
|
-
expect(r['event.duration']).to be_a String
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
@@ -1,29 +0,0 @@
|
|
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
|
-
|
18
|
-
require 'spec_helper'
|
19
|
-
|
20
|
-
ELASTICSEARCH_URL = ENV['TEST_ES_SERVER'] || "http://localhost:#{(ENV['PORT'] || 9200)}"
|
21
|
-
raise URI::InvalidURIError unless ELASTICSEARCH_URL =~ /\A#{URI::DEFAULT_PARSER.make_regexp}\z/
|
22
|
-
|
23
|
-
def client
|
24
|
-
@client ||= Elasticsearch::Client.new(
|
25
|
-
host: ELASTICSEARCH_URL,
|
26
|
-
user: 'elastic',
|
27
|
-
password: 'changeme'
|
28
|
-
)
|
29
|
-
end
|
@@ -1,83 +0,0 @@
|
|
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
|
-
require_relative 'helpers_spec_helper'
|
18
|
-
require 'elasticsearch/helpers/scroll_helper'
|
19
|
-
|
20
|
-
context 'Elasticsearch client helpers' do
|
21
|
-
context 'ScrollHelper' do
|
22
|
-
let(:index) { 'books' }
|
23
|
-
let(:body) { { size: 12, query: { match_all: {} } } }
|
24
|
-
let(:scroll_helper) { Elasticsearch::Helpers::ScrollHelper.new(client, index, body) }
|
25
|
-
|
26
|
-
before do
|
27
|
-
documents = [
|
28
|
-
{ index: { _index: index, data: {name: "Leviathan Wakes", "author": "James S.A. Corey", "release_date": "2011-06-02", "page_count": 561} } },
|
29
|
-
{ index: { _index: index, data: {name: "Hyperion", "author": "Dan Simmons", "release_date": "1989-05-26", "page_count": 482} } },
|
30
|
-
{ index: { _index: index, data: {name: "Dune", "author": "Frank Herbert", "release_date": "1965-06-01", "page_count": 604} } },
|
31
|
-
{ index: { _index: index, data: {name: "Dune Messiah", "author": "Frank Herbert", "release_date": "1969-10-15", "page_count": 331} } },
|
32
|
-
{ index: { _index: index, data: {name: "Children of Dune", "author": "Frank Herbert", "release_date": "1976-04-21", "page_count": 408} } },
|
33
|
-
{ index: { _index: index, data: {name: "God Emperor of Dune", "author": "Frank Herbert", "release_date": "1981-05-28", "page_count": 454} } },
|
34
|
-
{ index: { _index: index, data: {name: "Consider Phlebas", "author": "Iain M. Banks", "release_date": "1987-04-23", "page_count": 471} } },
|
35
|
-
{ index: { _index: index, data: {name: "Pandora's Star", "author": "Peter F. Hamilton", "release_date": "2004-03-02", "page_count": 768} } },
|
36
|
-
{ index: { _index: index, data: {name: "Revelation Space", "author": "Alastair Reynolds", "release_date": "2000-03-15", "page_count": 585} } },
|
37
|
-
{ index: { _index: index, data: {name: "A Fire Upon the Deep", "author": "Vernor Vinge", "release_date": "1992-06-01", "page_count": 613} } },
|
38
|
-
{ index: { _index: index, data: {name: "Ender's Game", "author": "Orson Scott Card", "release_date": "1985-06-01", "page_count": 324} } },
|
39
|
-
{ index: { _index: index, data: {name: "1984", "author": "George Orwell", "release_date": "1985-06-01", "page_count": 328} } },
|
40
|
-
{ index: { _index: index, data: {name: "Fahrenheit 451", "author": "Ray Bradbury", "release_date": "1953-10-15", "page_count": 227} } },
|
41
|
-
{ index: { _index: index, data: {name: "Brave New World", "author": "Aldous Huxley", "release_date": "1932-06-01", "page_count": 268} } },
|
42
|
-
{ index: { _index: index, data: {name: "Foundation", "author": "Isaac Asimov", "release_date": "1951-06-01", "page_count": 224} } },
|
43
|
-
{ index: { _index: index, data: {name: "The Giver", "author": "Lois Lowry", "release_date": "1993-04-26", "page_count": 208} } },
|
44
|
-
{ index: { _index: index, data: {name: "Slaughterhouse-Five", "author": "Kurt Vonnegut", "release_date": "1969-06-01", "page_count": 275} } },
|
45
|
-
{ index: { _index: index, data: {name: "The Hitchhiker's Guide to the Galaxy", "author": "Douglas Adams", "release_date": "1979-10-12", "page_count": 180} } },
|
46
|
-
{ index: { _index: index, data: {name: "Snow Crash", "author": "Neal Stephenson", "release_date": "1992-06-01", "page_count": 470} } },
|
47
|
-
{ index: { _index: index, data: {name: "Neuromancer", "author": "William Gibson", "release_date": "1984-07-01", "page_count": 271} } },
|
48
|
-
{ index: { _index: index, data: {name: "The Handmaid's Tale", "author": "Margaret Atwood", "release_date": "1985-06-01", "page_count": 311} } },
|
49
|
-
{ index: { _index: index, data: {name: "Starship Troopers", "author": "Robert A. Heinlein", "release_date": "1959-12-01", "page_count": 335} } },
|
50
|
-
{ index: { _index: index, data: {name: "The Left Hand of Darkness", "author": "Ursula K. Le Guin", "release_date": "1969-06-01", "page_count": 304} } },
|
51
|
-
{ index: { _index: index, data: {name: "The Moon is a Harsh Mistress", "author": "Robert A. Heinlein", "release_date": "1966-04-01", "page_count": 288 } } }
|
52
|
-
]
|
53
|
-
client.bulk(body: documents, refresh: 'wait_for')
|
54
|
-
end
|
55
|
-
|
56
|
-
after do
|
57
|
-
client.indices.delete(index: index)
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'instantiates a scroll helper' do
|
61
|
-
expect(scroll_helper).to be_an_instance_of Elasticsearch::Helpers::ScrollHelper
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'searches an index' do
|
65
|
-
my_documents = []
|
66
|
-
while !(documents = scroll_helper.results).empty?
|
67
|
-
my_documents << documents
|
68
|
-
end
|
69
|
-
|
70
|
-
expect(my_documents.flatten.size).to eq 24
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'uses enumerable' do
|
74
|
-
count = 0
|
75
|
-
scroll_helper.each { count += 1 }
|
76
|
-
expect(count).to eq 24
|
77
|
-
expect(scroll_helper).to respond_to(:count)
|
78
|
-
expect(scroll_helper).to respond_to(:reject)
|
79
|
-
expect(scroll_helper).to respond_to(:uniq)
|
80
|
-
expect(scroll_helper.map { |a| a['_id'] }.uniq.count).to eq 24
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
@@ -1,55 +0,0 @@
|
|
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
|
-
|
18
|
-
if ENV['TEST_WITH_OTEL'] == 'true'
|
19
|
-
ELASTICSEARCH_URL = ENV['TEST_ES_SERVER'] || "http://localhost:#{(ENV['PORT'] || 9200)}"
|
20
|
-
raise URI::InvalidURIError unless ELASTICSEARCH_URL =~ /\A#{URI::DEFAULT_PARSER.make_regexp}\z/
|
21
|
-
|
22
|
-
require 'spec_helper'
|
23
|
-
|
24
|
-
context 'OpenTelemetry' do
|
25
|
-
let(:exporter) { EXPORTER }
|
26
|
-
before { exporter.reset }
|
27
|
-
after { exporter.reset }
|
28
|
-
let(:span) { exporter.finished_spans[0] }
|
29
|
-
|
30
|
-
let(:client) do
|
31
|
-
Elasticsearch::Client.new(
|
32
|
-
host: ELASTICSEARCH_URL,
|
33
|
-
user: 'elastic',
|
34
|
-
password: 'changeme'
|
35
|
-
)
|
36
|
-
end
|
37
|
-
|
38
|
-
after do
|
39
|
-
client.delete(index: 'myindex', id: 1); rescue
|
40
|
-
end
|
41
|
-
|
42
|
-
context 'when a request is instrumented' do
|
43
|
-
it 'sets the span name to the endpoint id' do
|
44
|
-
client.search(body: { query: { match: { a: 1 } } })
|
45
|
-
expect(span.name).to eq 'search'
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'sets the path parts' do
|
49
|
-
client.index(index: 'myindex', id: 1, body: { title: 'Test' })
|
50
|
-
expect(span.attributes['db.elasticsearch.path_parts.index']).to eq 'myindex'
|
51
|
-
expect(span.attributes['db.elasticsearch.path_parts.id']).to eq 1
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,43 +0,0 @@
|
|
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
|
-
|
18
|
-
require 'elasticsearch'
|
19
|
-
require 'rspec'
|
20
|
-
|
21
|
-
RSpec.configure do |config|
|
22
|
-
config.formatter = :documentation
|
23
|
-
end
|
24
|
-
|
25
|
-
def meta_version
|
26
|
-
client.send(:client_meta_version, Elasticsearch::VERSION)
|
27
|
-
end
|
28
|
-
|
29
|
-
def jruby?
|
30
|
-
defined?(JRUBY_VERSION)
|
31
|
-
end
|
32
|
-
|
33
|
-
if ENV['TEST_WITH_OTEL'] == 'true'
|
34
|
-
require 'opentelemetry-sdk'
|
35
|
-
EXPORTER = OpenTelemetry::SDK::Trace::Export::InMemorySpanExporter.new
|
36
|
-
span_processor = OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor.new(EXPORTER)
|
37
|
-
|
38
|
-
OpenTelemetry::SDK.configure do |c|
|
39
|
-
c.error_handler = ->(exception:, message:) { raise(exception || message) }
|
40
|
-
c.logger = Logger.new($stderr, level: ENV.fetch('OTEL_LOG_LEVEL', 'fatal').to_sym)
|
41
|
-
c.add_span_processor span_processor
|
42
|
-
end
|
43
|
-
end
|
data/spec/unit/api_key_spec.rb
DELETED
@@ -1,138 +0,0 @@
|
|
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
|
-
|
18
|
-
require 'spec_helper'
|
19
|
-
require 'base64'
|
20
|
-
|
21
|
-
describe Elasticsearch::Client do
|
22
|
-
context 'when using API Key' do
|
23
|
-
let(:authorization_header) do
|
24
|
-
client.transport.connections.first.connection.headers['Authorization']
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'when an encoded api_key is provided' do
|
28
|
-
let(:client) do
|
29
|
-
described_class.new(api_key: 'an_api_key')
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'Adds the ApiKey header to the connection' do
|
33
|
-
expect(authorization_header).to eq('ApiKey an_api_key')
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context 'when an un-encoded api_key is provided' do
|
38
|
-
let(:client) do
|
39
|
-
described_class.new(api_key: { id: 'my_id', api_key: 'my_api_key' })
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'Adds the ApiKey header to the connection' do
|
43
|
-
expect(authorization_header).to eq("ApiKey #{Base64.strict_encode64('my_id:my_api_key')}")
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
context 'when basic auth and api_key are provided' do
|
48
|
-
let(:client) do
|
49
|
-
described_class.new(
|
50
|
-
api_key: { id: 'my_id', api_key: 'my_api_key' },
|
51
|
-
host: 'http://elastic:password@localhost:9200'
|
52
|
-
)
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'removes basic auth credentials' do
|
56
|
-
expect(authorization_header).not_to match(/^Basic/)
|
57
|
-
expect(authorization_header).to match(/^ApiKey/)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context 'when other headers were specified' do
|
62
|
-
let(:client) do
|
63
|
-
described_class.new(
|
64
|
-
api_key: 'elasticsearch_api_key',
|
65
|
-
transport_options: { headers: { 'x-test-header' => 'test' } }
|
66
|
-
)
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'Adds the ApiKey header to the connection and keeps the header' do
|
70
|
-
header = client.transport.connections.first.connection.headers
|
71
|
-
expect(header['Authorization']).to eq('ApiKey elasticsearch_api_key')
|
72
|
-
expect(header['X-Test-Header']).to eq('test')
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
context 'when sending transport_options but no headers were specified' do
|
77
|
-
let(:client) do
|
78
|
-
described_class.new(
|
79
|
-
api_key: 'elasticsearch_api_key',
|
80
|
-
transport_options: { ssl: { verify: false } }
|
81
|
-
)
|
82
|
-
end
|
83
|
-
|
84
|
-
it 'Adds the ApiKey header to the connection and keeps the options' do
|
85
|
-
header = client.transport.connections.first.connection.headers
|
86
|
-
expect(header['Authorization']).to eq('ApiKey elasticsearch_api_key')
|
87
|
-
expect(client.transport.options[:transport_options]).to include({ ssl: { verify: false } })
|
88
|
-
expect(client.transport.options[:transport_options][:headers]).to include('Authorization' => 'ApiKey elasticsearch_api_key')
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
context 'when other headers and options were specified' do
|
93
|
-
let(:client) do
|
94
|
-
described_class.new(
|
95
|
-
api_key: 'elasticsearch_api_key',
|
96
|
-
transport_options: {
|
97
|
-
headers: { 'x-test-header' => 'test' },
|
98
|
-
ssl: { verify: false }
|
99
|
-
}
|
100
|
-
)
|
101
|
-
end
|
102
|
-
|
103
|
-
it 'Adds the ApiKey header to the connection and keeps the header' do
|
104
|
-
header = client.transport.connections.first.connection.headers
|
105
|
-
expect(header['X-Test-Header']).to eq('test')
|
106
|
-
expect(header['Authorization']).to eq('ApiKey elasticsearch_api_key')
|
107
|
-
expect(client.transport.options[:transport_options]).to include({ ssl: { verify: false } })
|
108
|
-
expect(client.transport.options[:transport_options][:headers]).to include('Authorization' => 'ApiKey elasticsearch_api_key')
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
context 'Metaheader' do
|
113
|
-
let(:adapter_code) { "nh=#{defined?(Net::HTTP::VERSION) ? Net::HTTP::VERSION : Net::HTTP::HTTPVersion}" }
|
114
|
-
let(:meta_header) do
|
115
|
-
if jruby?
|
116
|
-
"es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elastic::Transport::VERSION},jv=#{ENV_JAVA['java.version']},jr=#{JRUBY_VERSION},fd=#{Faraday::VERSION},#{adapter_code}"
|
117
|
-
else
|
118
|
-
"es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elastic::Transport::VERSION},fd=#{Faraday::VERSION},#{adapter_code}"
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
context 'when using API Key' do
|
123
|
-
let(:client) do
|
124
|
-
described_class.new(api_key: 'an_api_key')
|
125
|
-
end
|
126
|
-
|
127
|
-
let(:headers) do
|
128
|
-
client.transport.connections.first.connection.headers
|
129
|
-
end
|
130
|
-
|
131
|
-
it 'adds the ApiKey header to the connection' do
|
132
|
-
expect(authorization_header).to eq('ApiKey an_api_key')
|
133
|
-
expect(headers).to include('x-elastic-client-meta' => meta_header)
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
@@ -1,167 +0,0 @@
|
|
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
|
-
|
18
|
-
require 'spec_helper'
|
19
|
-
|
20
|
-
describe Elasticsearch::Client do
|
21
|
-
context 'when cloud credentials are provided' do
|
22
|
-
let(:client) do
|
23
|
-
described_class.new(
|
24
|
-
cloud_id: 'name:bG9jYWxob3N0JGFiY2QkZWZnaA==',
|
25
|
-
user: 'elastic',
|
26
|
-
password: 'changeme'
|
27
|
-
)
|
28
|
-
end
|
29
|
-
|
30
|
-
let(:hosts) do
|
31
|
-
client.transport.hosts
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'extracts the cloud credentials' do
|
35
|
-
expect(hosts[0][:host]).to eq('abcd.localhost')
|
36
|
-
expect(hosts[0][:protocol]).to eq('https')
|
37
|
-
expect(hosts[0][:user]).to eq('elastic')
|
38
|
-
expect(hosts[0][:password]).to eq('changeme')
|
39
|
-
expect(hosts[0][:port]).to eq(443)
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'creates the correct full url' do
|
43
|
-
expect(
|
44
|
-
client.transport.__full_url(client.transport.hosts[0])
|
45
|
-
).to eq('https://elastic:changeme@abcd.localhost:443')
|
46
|
-
end
|
47
|
-
|
48
|
-
context 'when a port is specified' do
|
49
|
-
let(:client) do
|
50
|
-
described_class.new(cloud_id: 'name:bG9jYWxob3N0JGFiY2QkZWZnaA==', user: 'elastic', password: 'changeme', port: 9250)
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'sets the specified port along with the cloud credentials' do
|
54
|
-
expect(hosts[0][:host]).to eq('abcd.localhost')
|
55
|
-
expect(hosts[0][:protocol]).to eq('https')
|
56
|
-
expect(hosts[0][:user]).to eq('elastic')
|
57
|
-
expect(hosts[0][:password]).to eq('changeme')
|
58
|
-
expect(hosts[0][:port]).to eq(9250)
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'creates the correct full url' do
|
62
|
-
expect(client.transport.__full_url(client.transport.hosts[0])).to eq('https://elastic:changeme@abcd.localhost:9250')
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
context 'when the cluster has alternate names' do
|
67
|
-
let(:client) do
|
68
|
-
described_class.new(
|
69
|
-
cloud_id: 'myCluster:bG9jYWxob3N0JGFiY2QkZWZnaA==',
|
70
|
-
user: 'elasticfantastic',
|
71
|
-
password: 'tobechanged'
|
72
|
-
)
|
73
|
-
end
|
74
|
-
|
75
|
-
let(:hosts) do
|
76
|
-
client.transport.hosts
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'extracts the cloud credentials' do
|
80
|
-
expect(hosts[0][:host]).to eq('abcd.localhost')
|
81
|
-
expect(hosts[0][:protocol]).to eq('https')
|
82
|
-
expect(hosts[0][:user]).to eq('elasticfantastic')
|
83
|
-
expect(hosts[0][:password]).to eq('tobechanged')
|
84
|
-
expect(hosts[0][:port]).to eq(443)
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'creates the correct full url' do
|
88
|
-
expect(
|
89
|
-
client.transport.__full_url(client.transport.hosts[0])
|
90
|
-
).to eq('https://elasticfantastic:tobechanged@abcd.localhost:443')
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
context 'when decoded cloud id has a trailing dollar sign' do
|
95
|
-
let(:client) do
|
96
|
-
described_class.new(
|
97
|
-
cloud_id: 'a_cluster:bG9jYWxob3N0JGFiY2Qk',
|
98
|
-
user: 'elasticfantastic',
|
99
|
-
password: 'changeme'
|
100
|
-
)
|
101
|
-
end
|
102
|
-
|
103
|
-
let(:hosts) do
|
104
|
-
client.transport.hosts
|
105
|
-
end
|
106
|
-
|
107
|
-
it 'extracts the cloud credentials' do
|
108
|
-
expect(hosts[0][:host]).to eq('abcd.localhost')
|
109
|
-
expect(hosts[0][:protocol]).to eq('https')
|
110
|
-
expect(hosts[0][:user]).to eq('elasticfantastic')
|
111
|
-
expect(hosts[0][:password]).to eq('changeme')
|
112
|
-
expect(hosts[0][:port]).to eq(443)
|
113
|
-
end
|
114
|
-
|
115
|
-
it 'creates the correct full url' do
|
116
|
-
expect(
|
117
|
-
client.transport.__full_url(client.transport.hosts[0])
|
118
|
-
).to eq('https://elasticfantastic:changeme@abcd.localhost:443')
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
context 'when the cloud host provides a port' do
|
123
|
-
let(:client) do
|
124
|
-
described_class.new(
|
125
|
-
cloud_id: 'name:ZWxhc3RpY19zZXJ2ZXI6OTI0MyRlbGFzdGljX2lk',
|
126
|
-
user: 'elastic',
|
127
|
-
password: 'changeme'
|
128
|
-
)
|
129
|
-
end
|
130
|
-
|
131
|
-
let(:hosts) do
|
132
|
-
client.transport.hosts
|
133
|
-
end
|
134
|
-
|
135
|
-
it 'creates the correct full url' do
|
136
|
-
expect(hosts[0][:host]).to eq('elastic_id.elastic_server')
|
137
|
-
expect(hosts[0][:protocol]).to eq('https')
|
138
|
-
expect(hosts[0][:user]).to eq('elastic')
|
139
|
-
expect(hosts[0][:password]).to eq('changeme')
|
140
|
-
expect(hosts[0][:port]).to eq(9243)
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
context 'when the cloud host provides a port and the port is also specified' do
|
145
|
-
let(:client) do
|
146
|
-
described_class.new(
|
147
|
-
cloud_id: 'name:ZWxhc3RpY19zZXJ2ZXI6OTI0MyRlbGFzdGljX2lk',
|
148
|
-
user: 'elastic',
|
149
|
-
password: 'changeme',
|
150
|
-
port: 9200
|
151
|
-
)
|
152
|
-
end
|
153
|
-
|
154
|
-
let(:hosts) do
|
155
|
-
client.transport.hosts
|
156
|
-
end
|
157
|
-
|
158
|
-
it 'creates the correct full url' do
|
159
|
-
expect(hosts[0][:host]).to eq('elastic_id.elastic_server')
|
160
|
-
expect(hosts[0][:protocol]).to eq('https')
|
161
|
-
expect(hosts[0][:user]).to eq('elastic')
|
162
|
-
expect(hosts[0][:password]).to eq('changeme')
|
163
|
-
expect(hosts[0][:port]).to eq(9243)
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
167
|
-
end
|
@@ -1,43 +0,0 @@
|
|
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
|
-
require 'spec_helper'
|
18
|
-
|
19
|
-
describe Elasticsearch::Client do
|
20
|
-
context 'when using custom transport implementation' do
|
21
|
-
class MyTransport
|
22
|
-
include Elastic::Transport::Transport::Base
|
23
|
-
def initialize(args); end
|
24
|
-
end
|
25
|
-
let(:client) { Elasticsearch::Client.new(transport_class: MyTransport) }
|
26
|
-
let(:arguments) { client.instance_variable_get('@transport').instance_variable_get('@arguments') }
|
27
|
-
let(:subject) do
|
28
|
-
arguments[:transport_options][:headers]
|
29
|
-
end
|
30
|
-
|
31
|
-
let(:meta_header) do
|
32
|
-
if jruby?
|
33
|
-
"es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elastic::Transport::VERSION},jv=#{ENV_JAVA['java.version']},jr=#{JRUBY_VERSION}"
|
34
|
-
else
|
35
|
-
"es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elastic::Transport::VERSION}"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'doesnae set any info about the implementation in the metaheader' do
|
40
|
-
expect(subject).to include('x-elastic-client-meta' => meta_header)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|