Skip to content

Commit 6596369

Browse files
committed
[CLIENT] Cluster name is variable in cloud id
1 parent 4679145 commit 6596369

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

elasticsearch-transport/lib/elasticsearch/transport/client.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ def perform_request(method, path, params={}, body=nil, headers=nil)
156156

157157
def extract_cloud_creds(arguments)
158158
return unless arguments[:cloud_id]
159-
cloud_url, elasticsearch_instance = Base64.decode64(arguments[:cloud_id].gsub('name:', '')).split('$')
159+
name = arguments[:cloud_id].split(':')[0]
160+
cloud_url, elasticsearch_instance = Base64.decode64(arguments[:cloud_id].gsub("#{name}:", '')).split('$')
160161
[ { scheme: 'https',
161162
user: arguments[:user],
162163
password: arguments[:password],

elasticsearch-transport/spec/elasticsearch/transport/client_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,30 @@
297297
expect(client.transport.__full_url(client.transport.hosts[0])).to eq('https://elastic:changeme@abcd.localhost:9200')
298298
end
299299
end
300+
301+
context 'when the cluster has alternate names' do
302+
303+
let(:client) do
304+
described_class.new(cloud_id: 'myCluster:bG9jYWxob3N0JGFiY2QkZWZnaA==', user: 'elasticfantastic', password: 'tobechanged')
305+
end
306+
307+
let(:hosts) do
308+
client.transport.hosts
309+
end
310+
311+
it 'extracts the cloud credentials' do
312+
expect(hosts[0][:host]).to eq('abcd.localhost')
313+
expect(hosts[0][:protocol]).to eq('https')
314+
expect(hosts[0][:user]).to eq('elasticfantastic')
315+
expect(hosts[0][:password]).to eq('tobechanged')
316+
expect(hosts[0][:port]).to eq(9243)
317+
end
318+
319+
it 'creates the correct full url' do
320+
expect(client.transport.__full_url(client.transport.hosts[0])).to eq('https://elasticfantastic:tobechanged@abcd.localhost:9243')
321+
end
322+
323+
end
300324
end
301325

302326
shared_examples_for 'a client that extracts hosts' do

0 commit comments

Comments
 (0)